summaryrefslogtreecommitdiff
path: root/utils/TableGen/AsmWriterEmitter.cpp
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2012-04-02 00:47:39 +0000
committerCraig Topper <craig.topper@gmail.com>2012-04-02 00:47:39 +0000
commita4bd58b0f0d6ca33ff230aff450c9f2b94934bff (patch)
treeeff8386b540cb4fd16d9c97d481f45c3b5d3be81 /utils/TableGen/AsmWriterEmitter.cpp
parentcaa2c40a57040dc3e1a5e40401cd1e4ede845451 (diff)
downloadllvm-a4bd58b0f0d6ca33ff230aff450c9f2b94934bff.tar.gz
llvm-a4bd58b0f0d6ca33ff230aff450c9f2b94934bff.tar.bz2
llvm-a4bd58b0f0d6ca33ff230aff450c9f2b94934bff.tar.xz
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
Diffstat (limited to 'utils/TableGen/AsmWriterEmitter.cpp')
-rw-r--r--utils/TableGen/AsmWriterEmitter.cpp52
1 files changed, 27 insertions, 25 deletions
diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp
index 0844fc77d6..de2dc51250 100644
--- a/utils/TableGen/AsmWriterEmitter.cpp
+++ b/utils/TableGen/AsmWriterEmitter.cpp
@@ -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";