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

Chris Lattner lattner at cs.uiuc.edu
Fri Aug 1 01:16:01 PDT 2003


Changes in directory llvm/utils/TableGen:

Record.h updated: 1.21 -> 1.22
Record.cpp updated: 1.15 -> 1.16

---
Log message:

Add new getValueAsListInit and getValueAsInt methods


---
Diffs of the changes:

Index: llvm/utils/TableGen/Record.h
diff -u llvm/utils/TableGen/Record.h:1.21 llvm/utils/TableGen/Record.h:1.22
--- llvm/utils/TableGen/Record.h:1.21	Fri Aug  1 00:58:58 2003
+++ llvm/utils/TableGen/Record.h	Fri Aug  1 01:15:09 2003
@@ -613,6 +613,17 @@
   ///
   BitsInit *getValueAsBitsInit(const std::string &FieldName) const;
 
+  /// getValueAsListInit - This method looks up the specified field and returns
+  /// its value as a ListInit, throwing an exception if the field does not exist
+  /// or if the value is not the right type.
+  ///
+  ListInit *getValueAsListInit(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.
+  ///
+  int getValueAsInt(const std::string &FieldName) const;
 };
 
 std::ostream &operator<<(std::ostream &OS, const Record &R);


Index: llvm/utils/TableGen/Record.cpp
diff -u llvm/utils/TableGen/Record.cpp:1.15 llvm/utils/TableGen/Record.cpp:1.16
--- llvm/utils/TableGen/Record.cpp:1.15	Fri Aug  1 00:58:58 2003
+++ llvm/utils/TableGen/Record.cpp	Fri Aug  1 01:15:10 2003
@@ -492,7 +492,37 @@
         "' does not have a BitsInit initializer!";
 }
 
+/// getValueAsListInit - This method looks up the specified field and returns
+/// its value as a ListInit, throwing an exception if the field does not exist
+/// or if the value is not the right type.
+///
+ListInit *Record::getValueAsListInit(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 (ListInit *LI = dynamic_cast<ListInit*>(R->getValue()))
+    return LI;
+  throw "Record '" + R->getName() + "', field '" + FieldName +
+        "' does not have a list initializer!";
+}
+
+/// 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.
+///
+int Record::getValueAsInt(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 (IntInit *II = dynamic_cast<IntInit*>(R->getValue()))
+    return II->getValue();
+  throw "Record '" + R->getName() + "', field '" + FieldName +
+        "' does not have a list initializer!";
+}
 
 void RecordKeeper::dump() const { std::cerr << *this; }
 





More information about the llvm-commits mailing list