Refactor code for numbering instructions into CodeGenTarget.
authorChris Lattner <sabre@nondot.org>
Sat, 22 Jan 2005 18:58:51 +0000 (18:58 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 22 Jan 2005 18:58:51 +0000 (18:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@19758 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/CodeGenTarget.cpp
utils/TableGen/CodeGenTarget.h
utils/TableGen/InstrInfoEmitter.cpp

index b9c8bdbb9fa1be44e4bf4544005d59f34950100c..cb241aaf95f798a6f0979f5898c1b004e1bff9d6 100644 (file)
@@ -198,6 +198,22 @@ const CodeGenInstruction &CodeGenTarget::getPHIInstruction() const {
   return I->second;
 }
 
+/// getInstructionsByEnumValue - Return all of the instructions defined by the
+/// target, ordered by their enum value.
+void CodeGenTarget::
+getInstructionsByEnumValue(std::vector<const CodeGenInstruction*>
+                                                 &NumberedInstructions) {
+
+  // Print out the rest of the instructions now.
+  unsigned i = 0;
+  const CodeGenInstruction *PHI = &getPHIInstruction();
+  NumberedInstructions.push_back(PHI);
+  for (inst_iterator II = inst_begin(), E = inst_end(); II != E; ++II)
+    if (&II->second != PHI)
+      NumberedInstructions.push_back(&II->second);
+}
+
+
 /// isLittleEndianEncoding - Return whether this target encodes its instruction
 /// in little-endian format, i.e. bits laid out in the order [0..n]
 ///
index ac5306e4efbe5da8db38d8b9f9dccc035ba2c96e..2d899154473eb4fec4f3b696b7558fd7a7f66ff4 100644 (file)
@@ -93,6 +93,12 @@ public:
   inst_iterator inst_begin() const { return getInstructions().begin(); }
   inst_iterator inst_end() const { return Instructions.end(); }
 
+  /// getInstructionsByEnumValue - Return all of the instructions defined by the
+  /// target, ordered by their enum value.
+  void getInstructionsByEnumValue(std::vector<const CodeGenInstruction*>
+                                                &NumberedInstructions);
+
+
   /// getPHIInstruction - Return the designated PHI instruction.
   ///
   const CodeGenInstruction &getPHIInstruction() const;
index 113bc9839a00f84efceda9419902729fd7a92562..bde5fdc9591123e370adf48e2eb69d037eaf0590 100644 (file)
@@ -26,7 +26,6 @@ void InstrInfoEmitter::runEnums(std::ostream &OS) {
 
   // We must emit the PHI opcode first...
   Record *InstrInfo = Target.getInstructionSet();
-  Record *PHI = InstrInfo->getValueAsDef("PHIInst");
 
   std::string Namespace = Target.inst_begin()->second.Namespace;
 
@@ -34,15 +33,13 @@ void InstrInfoEmitter::runEnums(std::ostream &OS) {
     OS << "namespace " << Namespace << " {\n";
   OS << "  enum {\n";
 
-  OS << "    " << PHI->getName() << ", \t// 0 (fixed for all targets)\n";
-  
-  // Print out the rest of the instructions now.
-  unsigned i = 0;
-  for (CodeGenTarget::inst_iterator II = Target.inst_begin(),
-         E = Target.inst_end(); II != E; ++II)
-    if (II->second.TheDef != PHI)
-      OS << "    " << II->first << ", \t// " << ++i << "\n";
-  
+  std::vector<const CodeGenInstruction*> NumberedInstructions;
+  Target.getInstructionsByEnumValue(NumberedInstructions);
+
+  for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
+    OS << "    " << NumberedInstructions[i]->TheDef->getName()
+       << ", \t// " << i << "\n";
+  }
   OS << "  };\n";
   if (!Namespace.empty())
     OS << "}\n";