[llvm-commits] CVS: llvm/utils/TableGen/CodeEmitterGen.cpp Record.cpp Record.h

Chris Lattner lattner at cs.uiuc.edu
Thu Jul 31 23:47:00 PDT 2003


Changes in directory llvm/utils/TableGen:

CodeEmitterGen.cpp updated: 1.19 -> 1.20
Record.cpp updated: 1.13 -> 1.14
Record.h updated: 1.19 -> 1.20

---
Log message:

Add new getValueAsBitsInit 'high-level' method


---
Diffs of the changes:

Index: llvm/utils/TableGen/CodeEmitterGen.cpp
diff -u llvm/utils/TableGen/CodeEmitterGen.cpp:1.19 llvm/utils/TableGen/CodeEmitterGen.cpp:1.20
--- llvm/utils/TableGen/CodeEmitterGen.cpp:1.19	Thu Jul 31 23:38:18 2003
+++ llvm/utils/TableGen/CodeEmitterGen.cpp	Thu Jul 31 23:46:24 2003
@@ -26,14 +26,7 @@
     o << "    case " << Namespace << R->getName() << ": {\n"
       << "      DEBUG(std::cerr << \"Emitting " << R->getName() << "\\n\");\n";
 
-    const RecordVal *InstVal = R->getValue("Inst");
-    if (!InstVal)
-      throw std::string("No 'Inst' record found in target description file!");
-
-    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();
@@ -50,7 +43,7 @@
     }
     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


Index: llvm/utils/TableGen/Record.cpp
diff -u llvm/utils/TableGen/Record.cpp:1.13 llvm/utils/TableGen/Record.cpp:1.14
--- llvm/utils/TableGen/Record.cpp:1.13	Thu Jul 31 23:37:57 2003
+++ llvm/utils/TableGen/Record.cpp	Thu Jul 31 23:46:24 2003
@@ -468,6 +468,23 @@
         "' does not have a string initializer!";
 }
 
+/// getValueAsBitsInit - This method looks up the specified field and returns
+/// its value as a BitsInit, throwing an exception if the field does not exist
+/// or if the value is not the right type.
+///
+BitsInit *Record::getValueAsBitsInit(const std::string &FieldName) const {
+  const RecordVal *R = getValue(FieldName);
+  if (R == 0 || R->getValue() == 0)
+    throw "Record '" + R->getName() + "' does not have a field named '" +
+          FieldName + "!\n";
+
+  if (BitsInit *BI = dynamic_cast<BitsInit*>(R->getValue()))
+    return BI;
+  throw "Record '" + R->getName() + "', field '" + FieldName +
+        "' does not have a BitsInit initializer!";
+}
+
+
 
 void RecordKeeper::dump() const { std::cerr << *this; }
 


Index: llvm/utils/TableGen/Record.h
diff -u llvm/utils/TableGen/Record.h:1.19 llvm/utils/TableGen/Record.h:1.20
--- llvm/utils/TableGen/Record.h:1.19	Thu Jul 31 23:37:57 2003
+++ llvm/utils/TableGen/Record.h	Thu Jul 31 23:46:24 2003
@@ -605,6 +605,12 @@
   ///
   std::string getValueAsString(const std::string &FieldName) const;
 
+  /// getValueAsBitsInit - This method looks up the specified field and returns
+  /// its value as a BitsInit, throwing an exception if the field does not exist
+  /// or if the value is not the right type.
+  ///
+  BitsInit *getValueAsBitsInit(const std::string &FieldName) const;
+
 };
 
 std::ostream &operator<<(std::ostream &OS, const Record &R);





More information about the llvm-commits mailing list