summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--utils/TableGen/Record.cpp19
-rw-r--r--utils/TableGen/Record.h8
2 files changed, 26 insertions, 1 deletions
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp
index 75583bb1d1..4cba8891c3 100644
--- a/utils/TableGen/Record.cpp
+++ b/utils/TableGen/Record.cpp
@@ -866,6 +866,25 @@ int Record::getValueAsInt(const std::string &FieldName) const {
"' 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.
diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h
index d419f0b629..5e88e50d3e 100644
--- a/utils/TableGen/Record.h
+++ b/utils/TableGen/Record.h
@@ -1042,11 +1042,17 @@ public:
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.