mirror of
https://github.com/RPCSX/llvm.git
synced 2024-11-28 14:10:41 +00:00
Use SequenceToOffsetTable to generate instruction name table for AsmWriter.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153857 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
caa2c40a57
commit
a4bd58b0f0
@ -374,7 +374,7 @@ void AsmWriterEmitter::EmitPrintInstruction(raw_ostream &O) {
|
||||
O << " };\n\n";
|
||||
|
||||
// Emit the string itself.
|
||||
O << " const char *AsmStrs = \n";
|
||||
O << " const char *const AsmStrs = \n";
|
||||
StringTable.EmitString(O);
|
||||
O << ";\n\n";
|
||||
|
||||
@ -504,17 +504,13 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName,
|
||||
StringTable.emit(O, printChar);
|
||||
O << " };\n\n";
|
||||
|
||||
O << " static const unsigned RegAsmOffset" << AltName << "[] = {\n ";
|
||||
O << " static const unsigned RegAsmOffset" << AltName << "[] = {";
|
||||
for (unsigned i = 0, e = Registers.size(); i != e; ++i) {
|
||||
O << StringTable.get(AsmNames[i]);
|
||||
if (((i + 1) % 14) == 0)
|
||||
O << ",\n ";
|
||||
else
|
||||
O << ", ";
|
||||
|
||||
if ((i % 14) == 0)
|
||||
O << "\n ";
|
||||
O << StringTable.get(AsmNames[i]) << ", ";
|
||||
}
|
||||
O << "0\n"
|
||||
<< " };\n"
|
||||
O << " };\n"
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
@ -577,19 +573,30 @@ void AsmWriterEmitter::EmitGetInstructionName(raw_ostream &O) {
|
||||
const std::vector<const CodeGenInstruction*> &NumberedInstructions =
|
||||
Target.getInstructionsByEnumValue();
|
||||
|
||||
StringToOffsetTable StringTable;
|
||||
O <<
|
||||
"\n\n#ifdef GET_INSTRUCTION_NAME\n"
|
||||
"#undef GET_INSTRUCTION_NAME\n\n"
|
||||
"/// getInstructionName: This method is automatically generated by tblgen\n"
|
||||
"/// from the instruction set description. This returns the enum name of the\n"
|
||||
"/// specified instruction.\n"
|
||||
"const char *" << Target.getName() << ClassName
|
||||
<< "::getInstructionName(unsigned Opcode) {\n"
|
||||
<< " assert(Opcode < " << NumberedInstructions.size()
|
||||
<< " && \"Invalid instruction number!\");\n"
|
||||
<< "\n"
|
||||
<< " static const unsigned InstAsmOffset[] = {";
|
||||
<< "const char *" << Target.getName() << ClassName
|
||||
<< "::getInstructionName(unsigned Opcode) {\n"
|
||||
<< " assert(Opcode < " << NumberedInstructions.size()
|
||||
<< " && \"Invalid instruction number!\");\n"
|
||||
<< "\n";
|
||||
|
||||
SequenceToOffsetTable<std::string> StringTable;
|
||||
for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
|
||||
const CodeGenInstruction &Inst = *NumberedInstructions[i];
|
||||
StringTable.add(Inst.TheDef->getName());
|
||||
}
|
||||
|
||||
StringTable.layout();
|
||||
O << " static const char Strs[] = {\n";
|
||||
StringTable.emit(O, printChar);
|
||||
O << " };\n\n";
|
||||
|
||||
O << " static const unsigned InstAsmOffset[] = {";
|
||||
for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
|
||||
const CodeGenInstruction &Inst = *NumberedInstructions[i];
|
||||
|
||||
@ -597,15 +604,10 @@ void AsmWriterEmitter::EmitGetInstructionName(raw_ostream &O) {
|
||||
if ((i % 14) == 0)
|
||||
O << "\n ";
|
||||
|
||||
O << StringTable.GetOrAddStringOffset(AsmName) << ", ";
|
||||
O << StringTable.get(AsmName) << ", ";
|
||||
}
|
||||
O << "0\n"
|
||||
<< " };\n"
|
||||
<< "\n";
|
||||
|
||||
O << " const char *Strs =\n";
|
||||
StringTable.EmitString(O);
|
||||
O << ";\n";
|
||||
O << " };\n"
|
||||
<< "\n";
|
||||
|
||||
O << " return Strs+InstAsmOffset[Opcode];\n"
|
||||
<< "}\n\n#endif\n";
|
||||
|
Loading…
Reference in New Issue
Block a user