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

Jim Laskey jlaskey at apple.com
Fri Oct 28 14:46:42 PDT 2005



Changes in directory llvm/utils/TableGen:

Record.h updated: 1.52 -> 1.53
Record.cpp updated: 1.45 -> 1.46
---
Log message:

Added method to return a vector of records for a ListInit of Def field.  This
simplifies using list of records.


---
Diffs of the changes:  (+25 -0)

 Record.cpp |   19 +++++++++++++++++++
 Record.h   |    6 ++++++
 2 files changed, 25 insertions(+)


Index: llvm/utils/TableGen/Record.h
diff -u llvm/utils/TableGen/Record.h:1.52 llvm/utils/TableGen/Record.h:1.53
--- llvm/utils/TableGen/Record.h:1.52	Tue Sep 13 16:44:28 2005
+++ llvm/utils/TableGen/Record.h	Fri Oct 28 16:46:31 2005
@@ -1000,6 +1000,12 @@
   ///
   ListInit *getValueAsListInit(const std::string &FieldName) const;
 
+  /// getValueAsListDef - This method looks up the specified field and returns
+  /// its value as a vector of records, throwing an exception if the field does
+  /// not exist or if the value is not the right type.
+  ///
+  std::vector<Record*> getValueAsListDef(const std::string &FieldName) const;
+
   /// getValueAsDef - This method looks up the specified field and returns its
   /// value as a Record, throwing an exception if the field does not exist or if
   /// the value is not the right type.


Index: llvm/utils/TableGen/Record.cpp
diff -u llvm/utils/TableGen/Record.cpp:1.45 llvm/utils/TableGen/Record.cpp:1.46
--- llvm/utils/TableGen/Record.cpp:1.45	Tue Sep 13 16:44:28 2005
+++ llvm/utils/TableGen/Record.cpp	Fri Oct 28 16:46:31 2005
@@ -709,6 +709,25 @@
         "' does not have a list initializer!";
 }
 
+/// getValueAsListDef - This method looks up the specified field and returns
+/// its value as a vector of records, throwing an exception if the field does
+/// not exist or if the value is not the right type.
+///
+std::vector<Record*>  Record::getValueAsListDef(const std::string &FieldName)
+                                                                         const {
+  ListInit *List = getValueAsListInit(FieldName);
+  std::vector<Record*> Defs;
+  for (unsigned i = 0; i < List->getSize(); i++) {
+    if (DefInit *DI = dynamic_cast<DefInit*>(List->getElement(i))) {
+      Defs.push_back(DI->getDef());
+    } else {
+      throw "Record `" + getName() + "', field `" + FieldName +
+            "' list is not entirely DefInit!";
+    }
+  }
+  return Defs;
+}
+
 /// 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.






More information about the llvm-commits mailing list