diff options
Diffstat (limited to 'utils/TableGen/Record.cpp')
| -rw-r--r-- | utils/TableGen/Record.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index 7f81a382bb..309f386e78 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -536,6 +536,23 @@ int Record::getValueAsInt(const std::string &FieldName) const { "' does not have a list initializer!"; } +/// 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. +/// +Record *Record::getValueAsDef(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 (DefInit *DI = dynamic_cast<DefInit*>(R->getValue())) + return DI->getDef(); + throw "Record '" + R->getName() + "', field '" + FieldName + + "' does not have a list initializer!"; +} + + void RecordKeeper::dump() const { std::cerr << *this; } std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK) { |
