Add new getValueAsBitsInit 'high-level' method
authorChris Lattner <sabre@nondot.org>
Fri, 1 Aug 2003 04:46:24 +0000 (04:46 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 1 Aug 2003 04:46:24 +0000 (04:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7467 91177308-0d34-0410-b5e6-96231b3b80d8

support/tools/TableGen/CodeEmitterGen.cpp
support/tools/TableGen/Record.cpp
support/tools/TableGen/Record.h
utils/TableGen/CodeEmitterGen.cpp
utils/TableGen/Record.cpp
utils/TableGen/Record.h

index 0619967f7708d0dddf47096b91fa69f664d3daee..dc61f8f507fa441211d63b2a99a377e11d6f2824 100644 (file)
@@ -26,14 +26,7 @@ void CodeEmitterGen::run(std::ostream &o) {
     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 @@ void 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
index f282e4b0d6055f1c468d2ea9214c9f67c9d2b47b..acb61ec18525386dcefd79a9f3d7e1245cd56d4e 100644 (file)
@@ -468,6 +468,23 @@ std::string Record::getValueAsString(const std::string &FieldName) const {
         "' 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 467f12a6ab368ba3a86735da11294427831ef21e..130bf5aa366f86409c8bfb12b95765090dacf9a0 100644 (file)
@@ -605,6 +605,12 @@ public:
   ///
   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);
index 0619967f7708d0dddf47096b91fa69f664d3daee..dc61f8f507fa441211d63b2a99a377e11d6f2824 100644 (file)
@@ -26,14 +26,7 @@ void CodeEmitterGen::run(std::ostream &o) {
     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 @@ void 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
index f282e4b0d6055f1c468d2ea9214c9f67c9d2b47b..acb61ec18525386dcefd79a9f3d7e1245cd56d4e 100644 (file)
@@ -468,6 +468,23 @@ std::string Record::getValueAsString(const std::string &FieldName) const {
         "' 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 467f12a6ab368ba3a86735da11294427831ef21e..130bf5aa366f86409c8bfb12b95765090dacf9a0 100644 (file)
@@ -605,6 +605,12 @@ public:
   ///
   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);