diff options
author | Chris Lattner <sabre@nondot.org> | 2003-08-01 06:15:10 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-08-01 06:15:10 +0000 |
commit | 58c5de16927ea5ba1b454a69ce7ee4fdc371b9f7 (patch) | |
tree | 7a5d2f7f0996296b86861a304aca41dd0dfb80f5 /utils/TableGen/Record.cpp | |
parent | 54d156d33324b7715453993f21684915a28e310a (diff) | |
download | external_llvm-58c5de16927ea5ba1b454a69ce7ee4fdc371b9f7.zip external_llvm-58c5de16927ea5ba1b454a69ce7ee4fdc371b9f7.tar.gz external_llvm-58c5de16927ea5ba1b454a69ce7ee4fdc371b9f7.tar.bz2 |
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.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index fc035ac..8649b5f 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; } |