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

Chris Lattner lattner at cs.uiuc.edu
Tue Dec 3 00:01:02 PST 2002


Changes in directory llvm/utils/TableGen:

Record.cpp updated: 1.4 -> 1.5
Record.h updated: 1.6 -> 1.7

---
Log message:

Continue implementing field initializers


---
Diffs of the changes:

Index: llvm/utils/TableGen/Record.cpp
diff -u llvm/utils/TableGen/Record.cpp:1.4 llvm/utils/TableGen/Record.cpp:1.5
--- llvm/utils/TableGen/Record.cpp:1.4	Mon Dec  2 11:53:54 2002
+++ llvm/utils/TableGen/Record.cpp	Tue Dec  3 00:00:33 2002
@@ -82,25 +82,6 @@
   return 0;
 }
 
-#if 0
-Init *BitsRecTy::convertValue(FieldInit *VI) {
-  if (BitsRecTy *BRT = dynamic_cast<BitsRecTy*>(VI->getType()))
-    if (BRT->Size == Size) {
-      BitsInit *Ret = new BitsInit(Size);
-      for (unsigned i = 0; i != Size; ++i)
-	Ret->setBit(i, new VarBitInit(VI, i));
-      return Ret;
-    }
-  if (Size == 1 && dynamic_cast<BitRecTy*>(VI->getType())) {
-    BitsInit *Ret = new BitsInit(1);
-    Ret->setBit(0, VI);
-    return Ret;
-  }
-  return 0;
-}
-#endif
-
-
 Init *IntRecTy::convertValue(BitsInit *BI) {
   int Result = 0;
   for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i) 
@@ -168,8 +149,8 @@
 
 void BitsInit::print(std::ostream &OS) const {
   //if (!printInHex(OS)) return;
-  if (!printAsVariable(OS)) return;
-  if (!printAsUnset(OS)) return;
+  //if (!printAsVariable(OS)) return;
+  //if (!printAsUnset(OS)) return;
 
   OS << "{ ";
   for (unsigned i = 0, e = getNumBits(); i != e; ++i) {
@@ -282,13 +263,6 @@
   return BI;
 }
 
-RecTy *VarInit::getFieldType(const std::string &FieldName) const {
-  if (RecordRecTy *RTy = dynamic_cast<RecordRecTy*>(getType()))
-    if (const RecordVal *RV = RTy->getRecord()->getValue(FieldName))
-      return RV->getType();
-  return 0;
-}
-
 Init *VarInit::resolveBitReference(Record &R, unsigned Bit) {
   if (R.isTemplateArg(getName()))
     return this;
@@ -306,16 +280,43 @@
   return this;
 }
 
+RecTy *VarInit::getFieldType(const std::string &FieldName) const {
+  if (RecordRecTy *RTy = dynamic_cast<RecordRecTy*>(getType()))
+    if (const RecordVal *RV = RTy->getRecord()->getValue(FieldName))
+      return RV->getType();
+  return 0;
+}
+
+Init *VarInit::getFieldInit(Record &R, const std::string &FieldName) const {
+  if (RecordRecTy *RTy = dynamic_cast<RecordRecTy*>(getType()))
+    if (const RecordVal *RV = R.getValue(VarName))
+      if (Init *I = RV->getValue()->getFieldInit(R, FieldName))
+        return I;
+      else
+        return (Init*)this;
+  return 0;
+}
+
 
 
 Init *VarBitInit::resolveReferences(Record &R) {
   Init *I = getVariable()->resolveBitReference(R, getBitNum());
-
   if (I != getVariable())
     return I;
   return this;
 }
 
+RecTy *DefInit::getFieldType(const std::string &FieldName) const {
+  if (const RecordVal *RV = Def->getValue(FieldName))
+    return RV->getType();
+  return 0;
+}
+
+Init *DefInit::getFieldInit(Record &R, const std::string &FieldName) const {
+  return Def->getValue(FieldName)->getValue();
+}
+
+
 void DefInit::print(std::ostream &OS) const {
   OS << Def->getName();
 }
@@ -337,7 +338,16 @@
 }
 
 Init *FieldInit::resolveBitReference(Record &R, unsigned Bit) {
-  // Can never be resolved yet.
+  Init *BitsVal = Rec->getFieldInit(R, FieldName);
+  assert(BitsVal && "No initializer found!");
+
+  if (BitsInit *BI = dynamic_cast<BitsInit*>(BitsVal)) {
+    assert(Bit < BI->getNumBits() && "Bit reference out of range!");
+    Init *B = BI->getBit(Bit);
+    
+    if (dynamic_cast<BitInit*>(B))  // If the bit is set...
+      return B;                     // Replace the VarBitInit with it.
+  }
   return this;
 }
 


Index: llvm/utils/TableGen/Record.h
diff -u llvm/utils/TableGen/Record.h:1.6 llvm/utils/TableGen/Record.h:1.7
--- llvm/utils/TableGen/Record.h:1.6	Mon Dec  2 11:53:54 2002
+++ llvm/utils/TableGen/Record.h	Tue Dec  3 00:00:33 2002
@@ -180,6 +180,14 @@
   ///
   virtual RecTy *getFieldType(const std::string &FieldName) const { return 0; }
 
+  /// getFieldInit - This method complements getFieldType to return the
+  /// initializer for the specified field.  If getFieldType returns non-null
+  /// this method should return non-null, otherwise it returns null.
+  ///
+  virtual Init *getFieldInit(Record &R, const std::string &FieldName) const {
+    return 0;
+  }
+
   /// resolveReferences - This method is used by classes that refer to other
   /// variables which may not be defined at the time they expression is formed.
   /// If a value is set for the variable later, this method will be called on
@@ -352,6 +360,7 @@
   virtual Init *resolveBitReference(Record &R, unsigned Bit);
 
   virtual RecTy *getFieldType(const std::string &FieldName) const;
+  virtual Init *getFieldInit(Record &R, const std::string &FieldName) const;
   
   virtual void print(std::ostream &OS) const { OS << VarName; }
 };
@@ -397,6 +406,9 @@
   Record *getDef() const { return Def; }
 
   //virtual Init *convertInitializerBitRange(const std::vector<unsigned> &Bits);
+
+  virtual RecTy *getFieldType(const std::string &FieldName) const;
+  virtual Init *getFieldInit(Record &R, const std::string &FieldName) const;
   
   virtual void print(std::ostream &OS) const;
 };





More information about the llvm-commits mailing list