Fix the way field bit references are resolved, also allow resolution of field referen...
authorChris Lattner <sabre@nondot.org>
Fri, 1 Aug 2003 05:58:58 +0000 (05:58 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 1 Aug 2003 05:58:58 +0000 (05:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7470 91177308-0d34-0410-b5e6-96231b3b80d8

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

index acb61ec18525386dcefd79a9f3d7e1245cd56d4e..fc035aceb3886248c3895d5abef0789243a59bf4 100644 (file)
@@ -316,7 +316,7 @@ Init *VarInit::getFieldInit(Record &R, const std::string &FieldName) const {
       if (Init *I = RV->getValue()->getFieldInit(R, FieldName))
         return I;
       else
-        return (Init*)this;
+        return 0;
   return 0;
 }
 
@@ -373,14 +373,22 @@ Init *FieldInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
 
 Init *FieldInit::resolveBitReference(Record &R, unsigned Bit) {
   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.
+  if (BitsVal)
+    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;
+}
+
+Init *FieldInit::resolveReferences(Record &R) {
+  Init *BitsVal = Rec->getFieldInit(R, FieldName);
+  if (BitsVal) {
+    Init *BVR = BitsVal->resolveReferences(R);
+    return BVR->isComplete() ? BVR : this;
   }
   return this;
 }
index 130bf5aa366f86409c8bfb12b95765090dacf9a0..5dbd9b9c56257b4886238c3f2eccd8dc13eed2aa 100644 (file)
@@ -480,6 +480,8 @@ public:
 
   virtual Init *resolveBitReference(Record &R, unsigned Bit);
 
+  virtual Init *resolveReferences(Record &R);
+
   virtual void print(std::ostream &OS) const {
     Rec->print(OS); OS << "." << FieldName;
   }
index acb61ec18525386dcefd79a9f3d7e1245cd56d4e..fc035aceb3886248c3895d5abef0789243a59bf4 100644 (file)
@@ -316,7 +316,7 @@ Init *VarInit::getFieldInit(Record &R, const std::string &FieldName) const {
       if (Init *I = RV->getValue()->getFieldInit(R, FieldName))
         return I;
       else
-        return (Init*)this;
+        return 0;
   return 0;
 }
 
@@ -373,14 +373,22 @@ Init *FieldInit::convertInitializerBitRange(const std::vector<unsigned> &Bits) {
 
 Init *FieldInit::resolveBitReference(Record &R, unsigned Bit) {
   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.
+  if (BitsVal)
+    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;
+}
+
+Init *FieldInit::resolveReferences(Record &R) {
+  Init *BitsVal = Rec->getFieldInit(R, FieldName);
+  if (BitsVal) {
+    Init *BVR = BitsVal->resolveReferences(R);
+    return BVR->isComplete() ? BVR : this;
   }
   return this;
 }
index 130bf5aa366f86409c8bfb12b95765090dacf9a0..5dbd9b9c56257b4886238c3f2eccd8dc13eed2aa 100644 (file)
@@ -480,6 +480,8 @@ public:
 
   virtual Init *resolveBitReference(Record &R, unsigned Bit);
 
+  virtual Init *resolveReferences(Record &R);
+
   virtual void print(std::ostream &OS) const {
     Rec->print(OS); OS << "." << FieldName;
   }