[llvm-commits] [llvm] r43993 - in /llvm/trunk/utils/TableGen: Record.cpp Record.h

Anton Korobeynikov asl at math.spbu.ru
Sun Nov 11 03:19:39 PST 2007


Author: asl
Date: Sun Nov 11 05:19:37 2007
New Revision: 43993

URL: http://llvm.org/viewvc/llvm-project?rev=43993&view=rev
Log:
Add convenient helper to obtain list of ints

Modified:
    llvm/trunk/utils/TableGen/Record.cpp
    llvm/trunk/utils/TableGen/Record.h

Modified: llvm/trunk/utils/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.cpp?rev=43993&r1=43992&r2=43993&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/Record.cpp (original)
+++ llvm/trunk/utils/TableGen/Record.cpp Sun Nov 11 05:19:37 2007
@@ -866,6 +866,25 @@
         "' does not have an int initializer!";
 }
 
+/// getValueAsListOfInts - This method looks up the specified field and returns
+/// its value as a vector of integers, throwing an exception if the field does
+/// not exist or if the value is not the right type.
+///
+std::vector<int> 
+Record::getValueAsListOfInts(const std::string &FieldName) const {
+  ListInit *List = getValueAsListInit(FieldName);
+  std::vector<int> Ints;
+  for (unsigned i = 0; i < List->getSize(); i++) {
+    if (IntInit *II = dynamic_cast<IntInit*>(List->getElement(i))) {
+      Ints.push_back(II->getValue());
+    } else {
+      throw "Record `" + getName() + "', field `" + FieldName +
+            "' does not have a list of ints initializer!";
+    }
+  }
+  return Ints;
+}
+
 /// 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.

Modified: llvm/trunk/utils/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.h?rev=43993&r1=43992&r2=43993&view=diff

==============================================================================
--- llvm/trunk/utils/TableGen/Record.h (original)
+++ llvm/trunk/utils/TableGen/Record.h Sun Nov 11 05:19:37 2007
@@ -1042,11 +1042,17 @@
   ListInit *getValueAsListInit(const std::string &FieldName) const;
 
   /// getValueAsListOfDefs - This method looks up the specified field and
-  /// returnsits value as a vector of records, throwing an exception if the
+  /// 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*> getValueAsListOfDefs(const std::string &FieldName) const;
 
+  /// getValueAsListOfInts - This method looks up the specified field and returns
+  /// its value as a vector of integers, throwing an exception if the field does
+  /// not exist or if the value is not the right type.
+  ///
+  std::vector<int> getValueAsListOfInts(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.





More information about the llvm-commits mailing list