diff options
author | Craig Topper <craig.topper@gmail.com> | 2012-04-02 00:47:39 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@gmail.com> | 2012-04-02 00:47:39 +0000 |
commit | a4bd58b0f0d6ca33ff230aff450c9f2b94934bff (patch) | |
tree | eff8386b540cb4fd16d9c97d481f45c3b5d3be81 /utils/TableGen | |
parent | caa2c40a57040dc3e1a5e40401cd1e4ede845451 (diff) | |
download | external_llvm-a4bd58b0f0d6ca33ff230aff450c9f2b94934bff.zip external_llvm-a4bd58b0f0d6ca33ff230aff450c9f2b94934bff.tar.gz external_llvm-a4bd58b0f0d6ca33ff230aff450c9f2b94934bff.tar.bz2 |
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')
-rw-r--r-- | utils/TableGen/AsmWriterEmitter.cpp | 52 |
1 files changed, 27 insertions, 25 deletions
diff --git a/utils/TableGen/AsmWriterEmitter.cpp b/utils/TableGen/AsmWriterEmitter.cpp index 0844fc7..de2dc51 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"; |