Put instruction names into the first non TargetInstrInfo namespace found.
authorChris Lattner <sabre@nondot.org>
Mon, 1 May 2006 23:46:16 +0000 (23:46 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 1 May 2006 23:46:16 +0000 (23:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@28043 91177308-0d34-0410-b5e6-96231b3b80d8

utils/TableGen/InstrInfoEmitter.cpp

index 35fbed37931a4aa2f750df5ecd830ff0a6515322..d39a51f5e9093904b37cf40cf332c7e4b62c8be1 100644 (file)
@@ -28,23 +28,31 @@ void InstrInfoEmitter::runEnums(std::ostream &OS) {
   // We must emit the PHI opcode first...
   Record *InstrInfo = Target.getInstructionSet();
 
-  std::string Namespace = Target.inst_begin()->second.Namespace;
-
-  if (!Namespace.empty())
-    OS << "namespace " << Namespace << " {\n";
-  OS << "  enum {\n";
+  std::string Namespace;
+  for (CodeGenTarget::inst_iterator II = Target.inst_begin(), 
+       E = Target.inst_end(); II != E; ++II) {
+    if (II->second.Namespace != "TargetInstrInfo") {
+      Namespace = II->second.Namespace;
+      break;
+    }
+  }
+  
+  if (Namespace.empty()) {
+    std::cerr << "No instructions defined!\n";
+    exit(1);
+  }
 
   std::vector<const CodeGenInstruction*> NumberedInstructions;
   Target.getInstructionsByEnumValue(NumberedInstructions);
 
+  OS << "namespace " << Namespace << " {\n";
+  OS << "  enum {\n";
   for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
     OS << "    " << NumberedInstructions[i]->TheDef->getName()
-       << ", \t// " << i << "\n";
+       << "\t= " << i << ",\n";
   }
-  OS << "    INSTRUCTION_LIST_END\n";
-  OS << "  };\n";
-  if (!Namespace.empty())
-    OS << "}\n";
+  OS << "    INSTRUCTION_LIST_END = " << NumberedInstructions.size() << "\n";
+  OS << "  };\n}\n";
   OS << "} // End llvm namespace \n";
 }