diff --git a/support/tools/TableGen/Record.cpp b/support/tools/TableGen/Record.cpp index cf8aa40e226..781fecf8204 100644 --- a/support/tools/TableGen/Record.cpp +++ b/support/tools/TableGen/Record.cpp @@ -579,6 +579,22 @@ Record *Record::getValueAsDef(const std::string &FieldName) const { "' does not have a list initializer!"; } +/// getValueAsBit - This method looks up the specified field and returns its +/// value as a bit, throwing an exception if the field does not exist or if +/// the value is not the right type. +/// +bool Record::getValueAsBit(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 (BitInit *DI = dynamic_cast(R->getValue())) + return DI->getValue(); + throw "Record '" + R->getName() + "', field '" + FieldName + + "' does not have a list initializer!"; +} + void RecordKeeper::dump() const { std::cerr << *this; } diff --git a/support/tools/TableGen/Record.h b/support/tools/TableGen/Record.h index d841a2af055..f933d4ff526 100644 --- a/support/tools/TableGen/Record.h +++ b/support/tools/TableGen/Record.h @@ -707,6 +707,12 @@ public: /// Record *getValueAsDef(const std::string &FieldName) const; + /// getValueAsBit - This method looks up the specified field and returns its + /// value as a bit, throwing an exception if the field does not exist or if + /// the value is not the right type. + /// + bool getValueAsBit(const std::string &FieldName) const; + /// 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. diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index cf8aa40e226..781fecf8204 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -579,6 +579,22 @@ Record *Record::getValueAsDef(const std::string &FieldName) const { "' does not have a list initializer!"; } +/// getValueAsBit - This method looks up the specified field and returns its +/// value as a bit, throwing an exception if the field does not exist or if +/// the value is not the right type. +/// +bool Record::getValueAsBit(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 (BitInit *DI = dynamic_cast(R->getValue())) + return DI->getValue(); + throw "Record '" + R->getName() + "', field '" + FieldName + + "' does not have a list initializer!"; +} + void RecordKeeper::dump() const { std::cerr << *this; } diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index d841a2af055..f933d4ff526 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -707,6 +707,12 @@ public: /// Record *getValueAsDef(const std::string &FieldName) const; + /// getValueAsBit - This method looks up the specified field and returns its + /// value as a bit, throwing an exception if the field does not exist or if + /// the value is not the right type. + /// + bool getValueAsBit(const std::string &FieldName) const; + /// 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.