forked from OSchip/llvm-project
Factor code out into a new getAllDerivedDefinitions method, which is generally useful
llvm-svn: 7461
This commit is contained in:
parent
238dadc37c
commit
f62c489e35
|
@ -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::";
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue