[llvm-commits] CVS: llvm/utils/TableGen/Record.cpp Record.h RegisterInfoEmitter.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Aug 1 01:29:01 PDT 2003


Changes in directory llvm/utils/TableGen:

Record.cpp updated: 1.16 -> 1.17
Record.h updated: 1.22 -> 1.23
RegisterInfoEmitter.cpp updated: 1.2 -> 1.3

---
Log message:

add support for emitting register classes


---
Diffs of the changes:

Index: llvm/utils/TableGen/Record.cpp
diff -u llvm/utils/TableGen/Record.cpp:1.16 llvm/utils/TableGen/Record.cpp:1.17
--- llvm/utils/TableGen/Record.cpp:1.16	Fri Aug  1 01:15:10 2003
+++ llvm/utils/TableGen/Record.cpp	Fri Aug  1 01:27:59 2003
@@ -460,6 +460,18 @@
   return OS << "}\n";
 }
 
+/// getValueInit - Return the initializer for a value with the specified name,
+/// or throw an exception if the field does not exist.
+///
+Init *Record::getValueInit(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";
+  return R->getValue();
+}
+
+
 /// getValueAsString - This method looks up the specified field and returns its
 /// value as a string, throwing an exception if the field does not exist or if
 /// the value is not a string.


Index: llvm/utils/TableGen/Record.h
diff -u llvm/utils/TableGen/Record.h:1.22 llvm/utils/TableGen/Record.h:1.23
--- llvm/utils/TableGen/Record.h:1.22	Fri Aug  1 01:15:09 2003
+++ llvm/utils/TableGen/Record.h	Fri Aug  1 01:27:59 2003
@@ -335,6 +335,8 @@
 public:
   CodeInit(const std::string &V) : Value(V) {}
 
+  const std::string getValue() const { return Value; }
+
   virtual Init *convertInitializerTo(RecTy *Ty) {
     return Ty->convertValue(this);
   }
@@ -600,6 +602,11 @@
   //===--------------------------------------------------------------------===//
   // High-level methods useful to tablegen back-ends
   //
+
+  /// getValueInit - Return the initializer for a value with the specified name,
+  /// or throw an exception if the field does not exist.
+  ///
+  Init *getValueInit(const std::string &FieldName) const;
 
   /// getValueAsString - This method looks up the specified field and returns
   /// its value as a string, throwing an exception if the field does not exist


Index: llvm/utils/TableGen/RegisterInfoEmitter.cpp
diff -u llvm/utils/TableGen/RegisterInfoEmitter.cpp:1.2 llvm/utils/TableGen/RegisterInfoEmitter.cpp:1.3
--- llvm/utils/TableGen/RegisterInfoEmitter.cpp:1.2	Fri Aug  1 00:59:20 2003
+++ llvm/utils/TableGen/RegisterInfoEmitter.cpp	Fri Aug  1 01:27:59 2003
@@ -8,6 +8,7 @@
 
 #include "RegisterInfoEmitter.h"
 #include "Record.h"
+#include "Support/StringExtras.h"
 #include <set>
 
 static void EmitSourceHeader(const std::string &Desc, std::ostream &o) {
@@ -59,6 +60,12 @@
      << "};\n\n";
 }
 
+static std::string getQualifiedRecordName(Record *R) {
+  std::string Namespace = R->getValueAsString("Namespace");
+  if (Namespace.empty()) return R->getName();
+  return Namespace + "::" + R->getName();
+}
+
 // RegisterInfoEmitter::run - Main register file description emitter.
 //
 void RegisterInfoEmitter::run(std::ostream &OS) {
@@ -71,6 +78,9 @@
   std::vector<Record*> RegisterClasses =
     Records.getAllDerivedDefinitions("RegisterClass");
 
+  std::vector<Record*> Registers = Records.getAllDerivedDefinitions("Register");
+  Record *RegisterClass = Records.getClass("Register");
+
   std::set<Record*> RegistersFound;
 
   // Loop over all of the register classes... emitting each one.
@@ -79,7 +89,40 @@
   for (unsigned rc = 0, e = RegisterClasses.size(); rc != e; ++rc) {
     Record *RC = RegisterClasses[rc];
     std::string Name = RC->getName();
-    //if (Name[
+    if (Name[9] == '.') {
+      static unsigned AnonCounter = 0;
+      Name = "AnonRegClass_"+utostr(AnonCounter++);
+    }
+
+    // Emit the register list now...
+    OS << "  // " << Name << " Register Class...\n  const unsigned " << Name
+       << "[] = {\n    ";
+    ListInit *RegList = RC->getValueAsListInit("MemberList");
+    for (unsigned i = 0, e = RegList->getSize(); i != e; ++i) {
+      Record *Reg = RegList->getElement(i);
+      if (!Reg->isSubClassOf(RegisterClass))
+        throw "Register Class member '" + Reg->getName() +
+              " does not derive from the Register class!";
+      if (RegistersFound.count(Reg))
+        throw "Register '" + Reg->getName() +
+              "' included in multiple register classes!";
+      OS << getQualifiedRecordName(Reg) << ", ";
+    }
+    OS << "\n  };\n\n";
+
+    OS << "  struct " << Name << "Class : public TargetRegisterClass {\n"
+       << "    " << Name << "Class() : TargetRegisterClass("
+       << RC->getValueAsInt("Size")/8 << ", " << RC->getValueAsInt("Alignment")
+       << ", " << Name << ", " << Name << " + " << RegList->getSize()
+       << ") {}\n";
+    
+    if (CodeInit *CI = dynamic_cast<CodeInit*>(RC->getValueInit("Methods")))
+      OS << CI->getValue();
+    else
+      throw "Expected 'code' fragment for 'Methods' value in register class '"+
+            RC->getName() + "'!";
+
+    OS << "  } " << Name << "Instance;\n\n";
 
   }
 





More information about the llvm-commits mailing list