mirror of
https://github.com/baldurk/renderdoc.git
synced 2026-05-13 13:30:44 +00:00
Emit global symbol table
This commit is contained in:
@@ -619,6 +619,39 @@ bytebuf DXIL::ProgramEditor::EncodeProgram() const
|
||||
writer.EndBlock();
|
||||
}
|
||||
|
||||
{
|
||||
writer.BeginBlock(LLVMBC::KnownBlock::VALUE_SYMTAB_BLOCK);
|
||||
|
||||
rdcarray<rdcpair<size_t, const rdcstr *>> entries;
|
||||
|
||||
for(size_t s = 0; s < m_Symbols.size(); s++)
|
||||
{
|
||||
bool symtab = false;
|
||||
switch(m_Symbols[s].type)
|
||||
{
|
||||
case SymbolType::GlobalVar:
|
||||
case SymbolType::Function:
|
||||
case SymbolType::Alias: symtab = true; break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
if(symtab)
|
||||
entries.push_back({s, &m_Constants[s].str});
|
||||
}
|
||||
|
||||
// sort the entries by string in order
|
||||
std::sort(entries.begin(), entries.end(),
|
||||
[](const rdcpair<size_t, const rdcstr *> &a,
|
||||
const rdcpair<size_t, const rdcstr *> &b) { return *a.second < *b.second; });
|
||||
|
||||
// we use a special function to record the entry so it can take the string as-is to check it for
|
||||
// validity
|
||||
for(const rdcpair<size_t, const rdcstr *> &it : entries)
|
||||
writer.RecordSymTabEntry(it.first, *it.second);
|
||||
|
||||
writer.EndBlock();
|
||||
}
|
||||
|
||||
writer.EndBlock();
|
||||
|
||||
ProgramHeader header;
|
||||
|
||||
@@ -733,6 +733,45 @@ void BitcodeWriter::AutoRecord(uint32_t record, const rdcarray<uint64_t> &vals)
|
||||
}
|
||||
}
|
||||
|
||||
void BitcodeWriter::RecordSymTabEntry(size_t id, const rdcstr &str, bool basicBlock)
|
||||
{
|
||||
bool c6 = true, c7 = true;
|
||||
for(size_t i = 0; (c6 || c7) && i < str.size(); i++)
|
||||
{
|
||||
if(!isChar6(str[i]))
|
||||
c6 = false;
|
||||
if((unsigned char)str[i] >= 128)
|
||||
c7 = false;
|
||||
}
|
||||
|
||||
ValueSymtabAbbrev abbrev = ValueSymtabAbbrev::Entry8;
|
||||
ValueSymtabRecord record = ValueSymtabRecord::ENTRY;
|
||||
|
||||
if(basicBlock)
|
||||
{
|
||||
record = ValueSymtabRecord::BBENTRY;
|
||||
if(c6)
|
||||
abbrev = ValueSymtabAbbrev::BBEntry6;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(c6)
|
||||
abbrev = ValueSymtabAbbrev::Entry6;
|
||||
else if(c7)
|
||||
abbrev = ValueSymtabAbbrev::Entry7;
|
||||
}
|
||||
|
||||
// write the abbrev ID
|
||||
b.fixed(abbrevSize, GetAbbrevID((uint32_t)abbrev));
|
||||
|
||||
rdcarray<uint64_t> vals;
|
||||
vals.resize(str.size() + 1);
|
||||
vals[0] = id;
|
||||
for(size_t i = 0; i < str.size(); i++)
|
||||
vals[i + 1] = str[i];
|
||||
Abbrev(ValueSymtabAbbrevDefs[(uint32_t)abbrev], (uint32_t)record, vals);
|
||||
}
|
||||
|
||||
void BitcodeWriter::Abbrev(AbbrevParam *abbr, uint32_t record, uint64_t val)
|
||||
{
|
||||
WriteAbbrevParam(abbr[0], record);
|
||||
|
||||
@@ -87,6 +87,8 @@ public:
|
||||
AutoRecord((uint32_t)record, vals);
|
||||
}
|
||||
|
||||
void RecordSymTabEntry(size_t id, const rdcstr &str, bool basicBlock = false);
|
||||
|
||||
private:
|
||||
void WriteAbbrevDefinition(AbbrevParam *abbrev);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user