Add new method getVAlueAsDag
authorChris Lattner <sabre@nondot.org>
Thu, 7 Aug 2003 06:00:43 +0000 (06:00 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 7 Aug 2003 06:00:43 +0000 (06:00 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7669 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 4032f40cdb8573eb87ac6f17c9a82ad5b6df6984..a76c55cfb67879c336a6a3f35c98d93e13e66aab 100644 (file)
@@ -613,10 +613,26 @@ bool Record::getValueAsBit(const std::string &FieldName) const {
     throw "Record '" + getName() + "' does not have a field named '" +
       FieldName + "!\n";
 
-  if (BitInit *DI = dynamic_cast<BitInit*>(R->getValue()))
-    return DI->getValue();
+  if (BitInit *BI = dynamic_cast<BitInit*>(R->getValue()))
+    return BI->getValue();
   throw "Record '" + getName() + "', field '" + FieldName +
-        "' does not have a list initializer!";
+        "' does not have a bit initializer!";
+}
+
+/// getValueAsDag - This method looks up the specified field and returns its
+/// value as an Dag, throwing an exception if the field does not exist or if
+/// the value is not the right type.
+///
+DagInit *Record::getValueAsDag(const std::string &FieldName) const {
+  const RecordVal *R = getValue(FieldName);
+  if (R == 0 || R->getValue() == 0)
+    throw "Record '" + getName() + "' does not have a field named '" +
+      FieldName + "!\n";
+
+  if (DagInit *DI = dynamic_cast<DagInit*>(R->getValue()))
+    return DI;
+  throw "Record '" + getName() + "', field '" + FieldName +
+        "' does not have a dag initializer!";
 }
 
 
index b26e13ec8c3c5f605260041e74b11298c7a8fdea..b6214516435786a258abfd28e6f5bdbe89f101b6 100644 (file)
@@ -759,6 +759,12 @@ public:
   /// the value is not the right type.
   ///
   int getValueAsInt(const std::string &FieldName) const;
+
+  /// getValueAsDag - This method looks up the specified field and returns its
+  /// value as an Dag, throwing an exception if the field does not exist or if
+  /// the value is not the right type.
+  ///
+  DagInit *getValueAsDag(const std::string &FieldName) const;
 };
 
 std::ostream &operator<<(std::ostream &OS, const Record &R);
index 4032f40cdb8573eb87ac6f17c9a82ad5b6df6984..a76c55cfb67879c336a6a3f35c98d93e13e66aab 100644 (file)
@@ -613,10 +613,26 @@ bool Record::getValueAsBit(const std::string &FieldName) const {
     throw "Record '" + getName() + "' does not have a field named '" +
       FieldName + "!\n";
 
-  if (BitInit *DI = dynamic_cast<BitInit*>(R->getValue()))
-    return DI->getValue();
+  if (BitInit *BI = dynamic_cast<BitInit*>(R->getValue()))
+    return BI->getValue();
   throw "Record '" + getName() + "', field '" + FieldName +
-        "' does not have a list initializer!";
+        "' does not have a bit initializer!";
+}
+
+/// getValueAsDag - This method looks up the specified field and returns its
+/// value as an Dag, throwing an exception if the field does not exist or if
+/// the value is not the right type.
+///
+DagInit *Record::getValueAsDag(const std::string &FieldName) const {
+  const RecordVal *R = getValue(FieldName);
+  if (R == 0 || R->getValue() == 0)
+    throw "Record '" + getName() + "' does not have a field named '" +
+      FieldName + "!\n";
+
+  if (DagInit *DI = dynamic_cast<DagInit*>(R->getValue()))
+    return DI;
+  throw "Record '" + getName() + "', field '" + FieldName +
+        "' does not have a dag initializer!";
 }
 
 
index b26e13ec8c3c5f605260041e74b11298c7a8fdea..b6214516435786a258abfd28e6f5bdbe89f101b6 100644 (file)
@@ -759,6 +759,12 @@ public:
   /// the value is not the right type.
   ///
   int getValueAsInt(const std::string &FieldName) const;
+
+  /// getValueAsDag - This method looks up the specified field and returns its
+  /// value as an Dag, throwing an exception if the field does not exist or if
+  /// the value is not the right type.
+  ///
+  DagInit *getValueAsDag(const std::string &FieldName) const;
 };
 
 std::ostream &operator<<(std::ostream &OS, const Record &R);