Add new Record::getValueAsBit method
authorChris Lattner <sabre@nondot.org>
Sun, 3 Aug 2003 21:58:13 +0000 (21:58 +0000)
committerChris Lattner <sabre@nondot.org>
Sun, 3 Aug 2003 21:58:13 +0000 (21:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7544 91177308-0d34-0410-b5e6-96231b3b80d8

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

index cf8aa40e226979b5499b61d69b7a1859eac54dfa..781fecf82048334de151924e3133a8ef1246ef5a 100644 (file)
@@ -579,6 +579,22 @@ Record *Record::getValueAsDef(const std::string &FieldName) const {
         "' does not have a list initializer!";
 }
 
+/// getValueAsBit - This method looks up the specified field and returns its
+/// value as a bit, throwing an exception if the field does not exist or if
+/// the value is not the right type.
+///
+bool Record::getValueAsBit(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 (BitInit *DI = dynamic_cast<BitInit*>(R->getValue()))
+    return DI->getValue();
+  throw "Record '" + R->getName() + "', field '" + FieldName +
+        "' does not have a list initializer!";
+}
+
 
 void RecordKeeper::dump() const { std::cerr << *this; }
 
index d841a2af055777af03d9e7097eeca9ecdfa7f92f..f933d4ff52693785a9e13cdb94c5f14b342b3b77 100644 (file)
@@ -707,6 +707,12 @@ public:
   ///
   Record *getValueAsDef(const std::string &FieldName) const;
 
+  /// getValueAsBit - This method looks up the specified field and returns its
+  /// value as a bit, throwing an exception if the field does not exist or if
+  /// the value is not the right type.
+  ///
+  bool getValueAsBit(const std::string &FieldName) const;
+
   /// getValueAsInt - This method looks up the specified field and returns its
   /// value as an int, throwing an exception if the field does not exist or if
   /// the value is not the right type.
index cf8aa40e226979b5499b61d69b7a1859eac54dfa..781fecf82048334de151924e3133a8ef1246ef5a 100644 (file)
@@ -579,6 +579,22 @@ Record *Record::getValueAsDef(const std::string &FieldName) const {
         "' does not have a list initializer!";
 }
 
+/// getValueAsBit - This method looks up the specified field and returns its
+/// value as a bit, throwing an exception if the field does not exist or if
+/// the value is not the right type.
+///
+bool Record::getValueAsBit(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 (BitInit *DI = dynamic_cast<BitInit*>(R->getValue()))
+    return DI->getValue();
+  throw "Record '" + R->getName() + "', field '" + FieldName +
+        "' does not have a list initializer!";
+}
+
 
 void RecordKeeper::dump() const { std::cerr << *this; }
 
index d841a2af055777af03d9e7097eeca9ecdfa7f92f..f933d4ff52693785a9e13cdb94c5f14b342b3b77 100644 (file)
@@ -707,6 +707,12 @@ public:
   ///
   Record *getValueAsDef(const std::string &FieldName) const;
 
+  /// getValueAsBit - This method looks up the specified field and returns its
+  /// value as a bit, throwing an exception if the field does not exist or if
+  /// the value is not the right type.
+  ///
+  bool getValueAsBit(const std::string &FieldName) const;
+
   /// getValueAsInt - This method looks up the specified field and returns its
   /// value as an int, throwing an exception if the field does not exist or if
   /// the value is not the right type.