diff options
author | Chris Lattner <sabre@nondot.org> | 2003-08-01 04:46:24 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-08-01 04:46:24 +0000 |
commit | 6f334ad8f5c9319b334e2ba68b89d0dd46156788 (patch) | |
tree | 45f1dc9731297510db825f999a327b83a4e21a39 | |
parent | 1d1adea4937aa5c7b4bd0aa0463fe38fcdd22c7e (diff) | |
download | external_llvm-6f334ad8f5c9319b334e2ba68b89d0dd46156788.zip external_llvm-6f334ad8f5c9319b334e2ba68b89d0dd46156788.tar.gz external_llvm-6f334ad8f5c9319b334e2ba68b89d0dd46156788.tar.bz2 |
Add new getValueAsBitsInit 'high-level' method
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7467 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | support/tools/TableGen/CodeEmitterGen.cpp | 11 | ||||
-rw-r--r-- | support/tools/TableGen/Record.cpp | 17 | ||||
-rw-r--r-- | support/tools/TableGen/Record.h | 6 | ||||
-rw-r--r-- | utils/TableGen/CodeEmitterGen.cpp | 11 | ||||
-rw-r--r-- | utils/TableGen/Record.cpp | 17 | ||||
-rw-r--r-- | utils/TableGen/Record.h | 6 |
6 files changed, 50 insertions, 18 deletions
diff --git a/support/tools/TableGen/CodeEmitterGen.cpp b/support/tools/TableGen/CodeEmitterGen.cpp index 0619967..dc61f8f 100644 --- a/support/tools/TableGen/CodeEmitterGen.cpp +++ b/support/tools/TableGen/CodeEmitterGen.cpp @@ -26,14 +26,7 @@ void CodeEmitterGen::run(std::ostream &o) { o << " case " << Namespace << R->getName() << ": {\n" << " DEBUG(std::cerr << \"Emitting " << R->getName() << "\\n\");\n"; - const RecordVal *InstVal = R->getValue("Inst"); - if (!InstVal) - throw std::string("No 'Inst' record found in target description file!"); - - Init *InitVal = InstVal->getValue(); - assert(dynamic_cast<BitsInit*>(InitVal) && - "Can only handle undefined bits<> types!"); - BitsInit *BI = (BitsInit*)InitVal; + BitsInit *BI = R->getValueAsBitsInit("Inst"); unsigned Value = 0; const std::vector<RecordVal> &Vals = R->getValues(); @@ -50,7 +43,7 @@ void CodeEmitterGen::run(std::ostream &o) { } DEBUG(o << "\n"); - DEBUG(o << " // " << *InstVal << "\n"); + DEBUG(o << " // " << *R->getValue("Inst") << "\n"); o << " Value = " << Value << "U;\n\n"; // Loop over all of the fields in the instruction adding in any diff --git a/support/tools/TableGen/Record.cpp b/support/tools/TableGen/Record.cpp index f282e4b..acb61ec 100644 --- a/support/tools/TableGen/Record.cpp +++ b/support/tools/TableGen/Record.cpp @@ -468,6 +468,23 @@ std::string Record::getValueAsString(const std::string &FieldName) const { "' does not have a string initializer!"; } +/// getValueAsBitsInit - This method looks up the specified field and returns +/// its value as a BitsInit, throwing an exception if the field does not exist +/// or if the value is not the right type. +/// +BitsInit *Record::getValueAsBitsInit(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 (BitsInit *BI = dynamic_cast<BitsInit*>(R->getValue())) + return BI; + throw "Record '" + R->getName() + "', field '" + FieldName + + "' does not have a BitsInit initializer!"; +} + + void RecordKeeper::dump() const { std::cerr << *this; } diff --git a/support/tools/TableGen/Record.h b/support/tools/TableGen/Record.h index 467f12a..130bf5a 100644 --- a/support/tools/TableGen/Record.h +++ b/support/tools/TableGen/Record.h @@ -605,6 +605,12 @@ public: /// std::string getValueAsString(const std::string &FieldName) const; + /// getValueAsBitsInit - This method looks up the specified field and returns + /// its value as a BitsInit, throwing an exception if the field does not exist + /// or if the value is not the right type. + /// + BitsInit *getValueAsBitsInit(const std::string &FieldName) const; + }; std::ostream &operator<<(std::ostream &OS, const Record &R); diff --git a/utils/TableGen/CodeEmitterGen.cpp b/utils/TableGen/CodeEmitterGen.cpp index 0619967..dc61f8f 100644 --- a/utils/TableGen/CodeEmitterGen.cpp +++ b/utils/TableGen/CodeEmitterGen.cpp @@ -26,14 +26,7 @@ void CodeEmitterGen::run(std::ostream &o) { o << " case " << Namespace << R->getName() << ": {\n" << " DEBUG(std::cerr << \"Emitting " << R->getName() << "\\n\");\n"; - const RecordVal *InstVal = R->getValue("Inst"); - if (!InstVal) - throw std::string("No 'Inst' record found in target description file!"); - - Init *InitVal = InstVal->getValue(); - assert(dynamic_cast<BitsInit*>(InitVal) && - "Can only handle undefined bits<> types!"); - BitsInit *BI = (BitsInit*)InitVal; + BitsInit *BI = R->getValueAsBitsInit("Inst"); unsigned Value = 0; const std::vector<RecordVal> &Vals = R->getValues(); @@ -50,7 +43,7 @@ void CodeEmitterGen::run(std::ostream &o) { } DEBUG(o << "\n"); - DEBUG(o << " // " << *InstVal << "\n"); + DEBUG(o << " // " << *R->getValue("Inst") << "\n"); o << " Value = " << Value << "U;\n\n"; // Loop over all of the fields in the instruction adding in any diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index f282e4b..acb61ec 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -468,6 +468,23 @@ std::string Record::getValueAsString(const std::string &FieldName) const { "' does not have a string initializer!"; } +/// getValueAsBitsInit - This method looks up the specified field and returns +/// its value as a BitsInit, throwing an exception if the field does not exist +/// or if the value is not the right type. +/// +BitsInit *Record::getValueAsBitsInit(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 (BitsInit *BI = dynamic_cast<BitsInit*>(R->getValue())) + return BI; + throw "Record '" + R->getName() + "', field '" + FieldName + + "' does not have a BitsInit initializer!"; +} + + void RecordKeeper::dump() const { std::cerr << *this; } diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index 467f12a..130bf5a 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -605,6 +605,12 @@ public: /// std::string getValueAsString(const std::string &FieldName) const; + /// getValueAsBitsInit - This method looks up the specified field and returns + /// its value as a BitsInit, throwing an exception if the field does not exist + /// or if the value is not the right type. + /// + BitsInit *getValueAsBitsInit(const std::string &FieldName) const; + }; std::ostream &operator<<(std::ostream &OS, const Record &R); |