Factor code out into a new getAllDerivedDefinitions method, which is generally useful
authorChris Lattner <sabre@nondot.org>
Fri, 1 Aug 2003 04:09:58 +0000 (04:09 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 1 Aug 2003 04:09:58 +0000 (04:09 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7461 91177308-0d34-0410-b5e6-96231b3b80d8

support/tools/TableGen/CodeEmitterGen.cpp
support/tools/TableGen/Record.cpp
support/tools/TableGen/Record.h
utils/TableGen/CodeEmitterGen.cpp
utils/TableGen/Record.cpp
utils/TableGen/Record.h

index 87f3b87dbdf91b50deb3fe95ceb8806d6c767925..75303c4f60d2c4c6a92b8a498c4237b207357440 100644 (file)
@@ -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::";
index a54f8e238b13010ae12175e5ca8f57ff0e3245be..6dc409b1c2afc399b95b8e414d1ac43828848f48 100644 (file)
@@ -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;
+}
index cbc9cadd6659b841dd5cd0dd6be85b03fcdedfcd..7f703aaa9e665a469f81985b79d20ab0373a3330 100644 (file)
@@ -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;
 };
 
index 87f3b87dbdf91b50deb3fe95ceb8806d6c767925..75303c4f60d2c4c6a92b8a498c4237b207357440 100644 (file)
@@ -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::";
index a54f8e238b13010ae12175e5ca8f57ff0e3245be..6dc409b1c2afc399b95b8e414d1ac43828848f48 100644 (file)
@@ -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;
+}
index cbc9cadd6659b841dd5cd0dd6be85b03fcdedfcd..7f703aaa9e665a469f81985b79d20ab0373a3330 100644 (file)
@@ -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;
 };