Add new getValueAsBitsInit 'high-level' method
[oota-llvm.git] / utils / TableGen / CodeEmitterGen.cpp
index 87f3b87dbdf91b50deb3fe95ceb8806d6c767925..dc61f8f507fa441211d63b2a99a377e11d6f2824 100644 (file)
@@ -8,17 +8,8 @@
 #include "Record.h"
 #include "Support/Statistic.h"
 
-bool CodeEmitterGen::run(std::ostream &o) {
-  std::vector<Record*> Insts;
-
-  const std::map<std::string, Record*> &Defs = Records.getDefs();
-  Record *Inst = Records.getClass("Instruction");
-  assert(Inst && "Couldn't find Instruction class!");
-
-  for (std::map<std::string, Record*>::const_iterator I = Defs.begin(),
-        E = Defs.end(); I != E; ++I)
-    if (I->second->isSubClassOf(Inst))
-      Insts.push_back(I->second);
+void CodeEmitterGen::run(std::ostream &o) {
+  std::vector<Record*> Insts = Records.getAllDerivedDefinitions("Instruction");
 
   std::string Namespace = "V9::";
   std::string ClassName = "SparcV9CodeEmitter::";
@@ -30,22 +21,12 @@ bool CodeEmitterGen::run(std::ostream &o) {
     << "  DEBUG(std::cerr << MI);\n"
     << "  switch (MI.getOpcode()) {\n";
   for (std::vector<Record*>::iterator I = Insts.begin(), E = Insts.end();
-       I != E; ++I)
-  {
+       I != E; ++I) {
     Record *R = *I;
     o << "    case " << Namespace << R->getName() << ": {\n"
       << "      DEBUG(std::cerr << \"Emitting " << R->getName() << "\\n\");\n";
 
-    const RecordVal *InstVal = R->getValue("Inst");
-    if (!InstVal) {
-      std::cerr << "No 'Inst' record found in target description file!\n";
-      return true;
-    }
-
-    Init *InitVal = InstVal->getValue();
-    assert(dynamic_cast<BitsInit*>(InitVal) &&
-           "Can only handle undefined bits<> types!");
-    BitsInit *BI = (BitsInit*)InitVal;
+    BitsInit *BI = R->getValueAsBitsInit("Inst");
 
     unsigned Value = 0;
     const std::vector<RecordVal> &Vals = R->getValues();
@@ -62,7 +43,7 @@ bool CodeEmitterGen::run(std::ostream &o) {
     }
     DEBUG(o << "\n");
 
-    DEBUG(o << "      // " << *InstVal << "\n");
+    DEBUG(o << "      // " << *R->getValue("Inst") << "\n");
     o << "      Value = " << Value << "U;\n\n";
     
     // Loop over all of the fields in the instruction adding in any
@@ -235,5 +216,4 @@ bool CodeEmitterGen::run(std::ostream &o) {
     << "  }\n"
     << "  return Value;\n"
     << "}\n";
-  return false;
 }