summaryrefslogtreecommitdiff
path: root/utils/TableGen/Record.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-08-01 06:15:10 +0000
committerChris Lattner <sabre@nondot.org>2003-08-01 06:15:10 +0000
commit58c5de16927ea5ba1b454a69ce7ee4fdc371b9f7 (patch)
tree7a5d2f7f0996296b86861a304aca41dd0dfb80f5 /utils/TableGen/Record.cpp
parent54d156d33324b7715453993f21684915a28e310a (diff)
downloadllvm-58c5de16927ea5ba1b454a69ce7ee4fdc371b9f7.tar.gz
llvm-58c5de16927ea5ba1b454a69ce7ee4fdc371b9f7.tar.bz2
llvm-58c5de16927ea5ba1b454a69ce7ee4fdc371b9f7.tar.xz
Add new getValueAsListInit and getValueAsInt methods
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7472 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/Record.cpp')
-rw-r--r--utils/TableGen/Record.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp
index fc035aceb3..8649b5fe4c 100644
--- a/utils/TableGen/Record.cpp
+++ b/utils/TableGen/Record.cpp
@@ -492,7 +492,37 @@ BitsInit *Record::getValueAsBitsInit(const std::string &FieldName) const {
"' 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; }