[llvm-commits] CVS: llvm/utils/TableGen/CodeEmitterGen.cpp Record.h Record.cpp
Chris Lattner
lattner at cs.uiuc.edu
Thu Jul 31 23:11:01 PDT 2003
Changes in directory llvm/utils/TableGen:
CodeEmitterGen.cpp updated: 1.16 -> 1.17
Record.h updated: 1.17 -> 1.18
Record.cpp updated: 1.11 -> 1.12
---
Log message:
Factor code out into a new getAllDerivedDefinitions method, which is generally useful
---
Diffs of the changes:
Index: llvm/utils/TableGen/CodeEmitterGen.cpp
diff -u llvm/utils/TableGen/CodeEmitterGen.cpp:1.16 llvm/utils/TableGen/CodeEmitterGen.cpp:1.17
--- llvm/utils/TableGen/CodeEmitterGen.cpp:1.16 Wed Jul 30 23:43:49 2003
+++ llvm/utils/TableGen/CodeEmitterGen.cpp Thu Jul 31 23:09:58 2003
@@ -12,13 +12,8 @@
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::";
Index: llvm/utils/TableGen/Record.h
diff -u llvm/utils/TableGen/Record.h:1.17 llvm/utils/TableGen/Record.h:1.18
--- llvm/utils/TableGen/Record.h:1.17 Wed Jul 30 23:37:57 2003
+++ llvm/utils/TableGen/Record.h Thu Jul 31 23:09:58 2003
@@ -628,6 +628,16 @@
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;
};
Index: llvm/utils/TableGen/Record.cpp
diff -u llvm/utils/TableGen/Record.cpp:1.11 llvm/utils/TableGen/Record.cpp:1.12
--- llvm/utils/TableGen/Record.cpp:1.11 Tue Jul 29 23:16:52 2003
+++ llvm/utils/TableGen/Record.cpp Thu Jul 31 23:09:58 2003
@@ -468,3 +468,23 @@
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;
+}
More information about the llvm-commits
mailing list