mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-05 14:34:55 +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";
|
O << " };\n\n";
|
||||||
|
|
||||||
// Emit the string itself.
|
// Emit the string itself.
|
||||||
O << " const char *AsmStrs = \n";
|
O << " const char *const AsmStrs = \n";
|
||||||
StringTable.EmitString(O);
|
StringTable.EmitString(O);
|
||||||
O << ";\n\n";
|
O << ";\n\n";
|
||||||
|
|
||||||
@ -504,17 +504,13 @@ emitRegisterNameString(raw_ostream &O, StringRef AltName,
|
|||||||
StringTable.emit(O, printChar);
|
StringTable.emit(O, printChar);
|
||||||
O << " };\n\n";
|
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) {
|
for (unsigned i = 0, e = Registers.size(); i != e; ++i) {
|
||||||
O << StringTable.get(AsmNames[i]);
|
if ((i % 14) == 0)
|
||||||
if (((i + 1) % 14) == 0)
|
O << "\n ";
|
||||||
O << ",\n ";
|
O << StringTable.get(AsmNames[i]) << ", ";
|
||||||
else
|
|
||||||
O << ", ";
|
|
||||||
|
|
||||||
}
|
}
|
||||||
O << "0\n"
|
O << " };\n"
|
||||||
<< " };\n"
|
|
||||||
<< "\n";
|
<< "\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,19 +573,30 @@ void AsmWriterEmitter::EmitGetInstructionName(raw_ostream &O) {
|
|||||||
const std::vector<const CodeGenInstruction*> &NumberedInstructions =
|
const std::vector<const CodeGenInstruction*> &NumberedInstructions =
|
||||||
Target.getInstructionsByEnumValue();
|
Target.getInstructionsByEnumValue();
|
||||||
|
|
||||||
StringToOffsetTable StringTable;
|
|
||||||
O <<
|
O <<
|
||||||
"\n\n#ifdef GET_INSTRUCTION_NAME\n"
|
"\n\n#ifdef GET_INSTRUCTION_NAME\n"
|
||||||
"#undef GET_INSTRUCTION_NAME\n\n"
|
"#undef GET_INSTRUCTION_NAME\n\n"
|
||||||
"/// getInstructionName: This method is automatically generated by tblgen\n"
|
"/// getInstructionName: This method is automatically generated by tblgen\n"
|
||||||
"/// from the instruction set description. This returns the enum name of the\n"
|
"/// from the instruction set description. This returns the enum name of the\n"
|
||||||
"/// specified instruction.\n"
|
"/// specified instruction.\n"
|
||||||
"const char *" << Target.getName() << ClassName
|
<< "const char *" << Target.getName() << ClassName
|
||||||
<< "::getInstructionName(unsigned Opcode) {\n"
|
<< "::getInstructionName(unsigned Opcode) {\n"
|
||||||
<< " assert(Opcode < " << NumberedInstructions.size()
|
<< " assert(Opcode < " << NumberedInstructions.size()
|
||||||
<< " && \"Invalid instruction number!\");\n"
|
<< " && \"Invalid instruction number!\");\n"
|
||||||
<< "\n"
|
<< "\n";
|
||||||
<< " static const unsigned InstAsmOffset[] = {";
|
|
||||||
|
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) {
|
for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
|
||||||
const CodeGenInstruction &Inst = *NumberedInstructions[i];
|
const CodeGenInstruction &Inst = *NumberedInstructions[i];
|
||||||
|
|
||||||
@ -597,15 +604,10 @@ void AsmWriterEmitter::EmitGetInstructionName(raw_ostream &O) {
|
|||||||
if ((i % 14) == 0)
|
if ((i % 14) == 0)
|
||||||
O << "\n ";
|
O << "\n ";
|
||||||
|
|
||||||
O << StringTable.GetOrAddStringOffset(AsmName) << ", ";
|
O << StringTable.get(AsmName) << ", ";
|
||||||
}
|
}
|
||||||
O << "0\n"
|
O << " };\n"
|
||||||
<< " };\n"
|
<< "\n";
|
||||||
<< "\n";
|
|
||||||
|
|
||||||
O << " const char *Strs =\n";
|
|
||||||
StringTable.EmitString(O);
|
|
||||||
O << ";\n";
|
|
||||||
|
|
||||||
O << " return Strs+InstAsmOffset[Opcode];\n"
|
O << " return Strs+InstAsmOffset[Opcode];\n"
|
||||||
<< "}\n\n#endif\n";
|
<< "}\n\n#endif\n";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user