aboutsummaryrefslogtreecommitdiff
path: root/utils/TableGen/Record.cpp
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2007-11-11 11:19:37 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2007-11-11 11:19:37 +0000
commitaf1b61debd9cb6570ed815a27cd94897f0dca3cf (patch)
treeb56dc328ea88700f9e7e92c50cc449363617ad65 /utils/TableGen/Record.cpp
parente3ef744d3e3557ee286d2ed3bf8306e5fbbd1ac4 (diff)
Add convenient helper to obtain list of ints
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@43993 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/Record.cpp')
-rw-r--r--utils/TableGen/Record.cpp19
1 files changed, 19 insertions, 0 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.