From 784a793636b7e766e868822c213ca96b0755b5c1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 7 Aug 2003 06:00:43 +0000 Subject: [PATCH] Add new method getVAlueAsDag git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7669 91177308-0d34-0410-b5e6-96231b3b80d8 --- support/tools/TableGen/Record.cpp | 22 +++++++++++++++++++--- support/tools/TableGen/Record.h | 6 ++++++ utils/TableGen/Record.cpp | 22 +++++++++++++++++++--- utils/TableGen/Record.h | 6 ++++++ 4 files changed, 50 insertions(+), 6 deletions(-) diff --git a/support/tools/TableGen/Record.cpp b/support/tools/TableGen/Record.cpp index 4032f40cdb8..a76c55cfb67 100644 --- a/support/tools/TableGen/Record.cpp +++ b/support/tools/TableGen/Record.cpp @@ -613,10 +613,26 @@ bool Record::getValueAsBit(const std::string &FieldName) const { throw "Record '" + getName() + "' does not have a field named '" + FieldName + "!\n"; - if (BitInit *DI = dynamic_cast(R->getValue())) - return DI->getValue(); + if (BitInit *BI = dynamic_cast(R->getValue())) + return BI->getValue(); throw "Record '" + getName() + "', field '" + FieldName + - "' does not have a list initializer!"; + "' does not have a bit initializer!"; +} + +/// getValueAsDag - This method looks up the specified field and returns its +/// value as an Dag, throwing an exception if the field does not exist or if +/// the value is not the right type. +/// +DagInit *Record::getValueAsDag(const std::string &FieldName) const { + const RecordVal *R = getValue(FieldName); + if (R == 0 || R->getValue() == 0) + throw "Record '" + getName() + "' does not have a field named '" + + FieldName + "!\n"; + + if (DagInit *DI = dynamic_cast(R->getValue())) + return DI; + throw "Record '" + getName() + "', field '" + FieldName + + "' does not have a dag initializer!"; } diff --git a/support/tools/TableGen/Record.h b/support/tools/TableGen/Record.h index b26e13ec8c3..b6214516435 100644 --- a/support/tools/TableGen/Record.h +++ b/support/tools/TableGen/Record.h @@ -759,6 +759,12 @@ public: /// the value is not the right type. /// int getValueAsInt(const std::string &FieldName) const; + + /// getValueAsDag - This method looks up the specified field and returns its + /// value as an Dag, throwing an exception if the field does not exist or if + /// the value is not the right type. + /// + DagInit *getValueAsDag(const std::string &FieldName) const; }; std::ostream &operator<<(std::ostream &OS, const Record &R); diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index 4032f40cdb8..a76c55cfb67 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -613,10 +613,26 @@ bool Record::getValueAsBit(const std::string &FieldName) const { throw "Record '" + getName() + "' does not have a field named '" + FieldName + "!\n"; - if (BitInit *DI = dynamic_cast(R->getValue())) - return DI->getValue(); + if (BitInit *BI = dynamic_cast(R->getValue())) + return BI->getValue(); throw "Record '" + getName() + "', field '" + FieldName + - "' does not have a list initializer!"; + "' does not have a bit initializer!"; +} + +/// getValueAsDag - This method looks up the specified field and returns its +/// value as an Dag, throwing an exception if the field does not exist or if +/// the value is not the right type. +/// +DagInit *Record::getValueAsDag(const std::string &FieldName) const { + const RecordVal *R = getValue(FieldName); + if (R == 0 || R->getValue() == 0) + throw "Record '" + getName() + "' does not have a field named '" + + FieldName + "!\n"; + + if (DagInit *DI = dynamic_cast(R->getValue())) + return DI; + throw "Record '" + getName() + "', field '" + FieldName + + "' does not have a dag initializer!"; } diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index b26e13ec8c3..b6214516435 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -759,6 +759,12 @@ public: /// the value is not the right type. /// int getValueAsInt(const std::string &FieldName) const; + + /// getValueAsDag - This method looks up the specified field and returns its + /// value as an Dag, throwing an exception if the field does not exist or if + /// the value is not the right type. + /// + DagInit *getValueAsDag(const std::string &FieldName) const; }; std::ostream &operator<<(std::ostream &OS, const Record &R); -- 2.11.0