[llvm-commits] [llvm] r153857 - /llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp

Craig Topper craig.topper at gmail.com
Sun Apr 1 17:47:39 PDT 2012


Author: ctopper
Date: Sun Apr  1 19:47:39 2012
New Revision: 153857

URL: http://llvm.org/viewvc/llvm-project?rev=153857&view=rev
Log:
Use SequenceToOffsetTable to generate instruction name table for AsmWriter.

Modified:
    llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp

Modified: llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp?rev=153857&r1=153856&r2=153857&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/AsmWriterEmitter.cpp Sun Apr  1 19:47:39 2012
@@ -374,7 +374,7 @@
   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 @@
   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 @@
   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 @@
     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";





More information about the llvm-commits mailing list