diff options
author | Chris Lattner <sabre@nondot.org> | 2003-08-01 04:09:58 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-08-01 04:09:58 +0000 |
commit | ab47ae3381aa2372009a9054260461c20324b555 (patch) | |
tree | f5ccadad006085883dcc817623e97b79498d67da | |
parent | 7296fb04211123339473494d28807661b4fef9ff (diff) | |
download | llvm-ab47ae3381aa2372009a9054260461c20324b555.tar.gz llvm-ab47ae3381aa2372009a9054260461c20324b555.tar.bz2 llvm-ab47ae3381aa2372009a9054260461c20324b555.tar.xz |
Factor code out into a new getAllDerivedDefinitions method, which is generally useful
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7461 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | support/tools/TableGen/CodeEmitterGen.cpp | 7 | ||||
-rw-r--r-- | support/tools/TableGen/Record.cpp | 20 | ||||
-rw-r--r-- | support/tools/TableGen/Record.h | 10 | ||||
-rw-r--r-- | utils/TableGen/CodeEmitterGen.cpp | 7 | ||||
-rw-r--r-- | utils/TableGen/Record.cpp | 20 | ||||
-rw-r--r-- | utils/TableGen/Record.h | 10 |
6 files changed, 62 insertions, 12 deletions
diff --git a/support/tools/TableGen/CodeEmitterGen.cpp b/support/tools/TableGen/CodeEmitterGen.cpp index 87f3b87dbd..75303c4f60 100644 --- a/support/tools/TableGen/CodeEmitterGen.cpp +++ b/support/tools/TableGen/CodeEmitterGen.cpp @@ -12,13 +12,8 @@ bool CodeEmitterGen::run(std::ostream &o) { std::vector<Record*> Insts; const std::map<std::string, Record*> &Defs = Records.getDefs(); - Record *Inst = Records.getClass("Instruction"); - assert(Inst && "Couldn't find Instruction class!"); - for (std::map<std::string, Record*>::const_iterator I = Defs.begin(), - E = Defs.end(); I != E; ++I) - if (I->second->isSubClassOf(Inst)) - Insts.push_back(I->second); + Records.getAllDerivedDefinitions("Instruction", Insts); std::string Namespace = "V9::"; std::string ClassName = "SparcV9CodeEmitter::"; diff --git a/support/tools/TableGen/Record.cpp b/support/tools/TableGen/Record.cpp index a54f8e238b..6dc409b1c2 100644 --- a/support/tools/TableGen/Record.cpp +++ b/support/tools/TableGen/Record.cpp @@ -468,3 +468,23 @@ std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK) { OS << "def " << *I->second; return OS; } + + +/// getAllDerivedDefinitions - This method returns all concrete definitions +/// that derive from the specified class name. If a class with the specified +/// name does not exist, an error is printed and true is returned. +bool RecordKeeper::getAllDerivedDefinitions(const std::string &ClassName, + std::vector<Record*> &Defs) const { + Record *Class = Records.getClass(ClassName); + if (!Class) { + std::cerr << "ERROR: Couldn't find the '" << ClassName << "' class!\n"; + return true; + } + + for (std::map<std::string, Record*>::const_iterator I = getDefs().begin(), + E = getDefs().end(); I != E; ++I) + if (I->second->isSubClassOf(Class)) + Defs.push_back(I->second); + + return false; +} diff --git a/support/tools/TableGen/Record.h b/support/tools/TableGen/Record.h index cbc9cadd66..7f703aaa9e 100644 --- a/support/tools/TableGen/Record.h +++ b/support/tools/TableGen/Record.h @@ -628,6 +628,16 @@ public: Defs.insert(std::make_pair(R->getName(), R)); } + //===--------------------------------------------------------------------===// + // High-level helper methods, useful for tablegen backends... + + /// getAllDerivedDefinitions - This method returns all concrete definitions + /// that derive from the specified class name. If a class with the specified + /// name does not exist, an error is printed and true is returned. + bool getAllDerivedDefinitions(const std::string &ClassName, + std::vector<Record*> &ReturnDefs) const; + + void dump() const; }; diff --git a/utils/TableGen/CodeEmitterGen.cpp b/utils/TableGen/CodeEmitterGen.cpp index 87f3b87dbd..75303c4f60 100644 --- a/utils/TableGen/CodeEmitterGen.cpp +++ b/utils/TableGen/CodeEmitterGen.cpp @@ -12,13 +12,8 @@ bool CodeEmitterGen::run(std::ostream &o) { std::vector<Record*> Insts; const std::map<std::string, Record*> &Defs = Records.getDefs(); - Record *Inst = Records.getClass("Instruction"); - assert(Inst && "Couldn't find Instruction class!"); - for (std::map<std::string, Record*>::const_iterator I = Defs.begin(), - E = Defs.end(); I != E; ++I) - if (I->second->isSubClassOf(Inst)) - Insts.push_back(I->second); + Records.getAllDerivedDefinitions("Instruction", Insts); std::string Namespace = "V9::"; std::string ClassName = "SparcV9CodeEmitter::"; diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index a54f8e238b..6dc409b1c2 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -468,3 +468,23 @@ std::ostream &operator<<(std::ostream &OS, const RecordKeeper &RK) { OS << "def " << *I->second; return OS; } + + +/// getAllDerivedDefinitions - This method returns all concrete definitions +/// that derive from the specified class name. If a class with the specified +/// name does not exist, an error is printed and true is returned. +bool RecordKeeper::getAllDerivedDefinitions(const std::string &ClassName, + std::vector<Record*> &Defs) const { + Record *Class = Records.getClass(ClassName); + if (!Class) { + std::cerr << "ERROR: Couldn't find the '" << ClassName << "' class!\n"; + return true; + } + + for (std::map<std::string, Record*>::const_iterator I = getDefs().begin(), + E = getDefs().end(); I != E; ++I) + if (I->second->isSubClassOf(Class)) + Defs.push_back(I->second); + + return false; +} diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index cbc9cadd66..7f703aaa9e 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -628,6 +628,16 @@ public: Defs.insert(std::make_pair(R->getName(), R)); } + //===--------------------------------------------------------------------===// + // High-level helper methods, useful for tablegen backends... + + /// getAllDerivedDefinitions - This method returns all concrete definitions + /// that derive from the specified class name. If a class with the specified + /// name does not exist, an error is printed and true is returned. + bool getAllDerivedDefinitions(const std::string &ClassName, + std::vector<Record*> &ReturnDefs) const; + + void dump() const; }; |