aboutsummaryrefslogtreecommitdiffstats
path: root/support/tools/TableGen
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-08-02 01:27:37 +0000
committerChris Lattner <sabre@nondot.org>2003-08-02 01:27:37 +0000
commitdbb295bd0d0e084ffbaae314026f389d83453619 (patch)
tree11c9ced91d948465b3415bf692f88cae1da4791b /support/tools/TableGen
parent14fef50bcf61d59493cb655b75fe21ed729bf73b (diff)
downloadexternal_llvm-dbb295bd0d0e084ffbaae314026f389d83453619.zip
external_llvm-dbb295bd0d0e084ffbaae314026f389d83453619.tar.gz
external_llvm-dbb295bd0d0e084ffbaae314026f389d83453619.tar.bz2
Add new method
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7502 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'support/tools/TableGen')
-rw-r--r--support/tools/TableGen/Record.cpp17
-rw-r--r--support/tools/TableGen/Record.h6
2 files changed, 23 insertions, 0 deletions
diff --git a/support/tools/TableGen/Record.cpp b/support/tools/TableGen/Record.cpp
index 7f81a38..309f386 100644
--- a/support/tools/TableGen/Record.cpp
+++ b/support/tools/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) {
diff --git a/support/tools/TableGen/Record.h b/support/tools/TableGen/Record.h
index 1729b02..1eedf43 100644
--- a/support/tools/TableGen/Record.h
+++ b/support/tools/TableGen/Record.h
@@ -626,6 +626,12 @@ public:
///
ListInit *getValueAsListInit(const std::string &FieldName) const;
+ /// 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 *getValueAsDef(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.