Tablegen fixes for new syntax when initializing bits from variables.
authorJean-Luc Duprat <jduprat@apple.com>
Fri, 29 Aug 2014 19:41:04 +0000 (19:41 +0000)
committerJean-Luc Duprat <jduprat@apple.com>
Fri, 29 Aug 2014 19:41:04 +0000 (19:41 +0000)
Followup to r215086.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216757 91177308-0d34-0410-b5e6-96231b3b80d8

lib/TableGen/TGParser.cpp
test/TableGen/BitsInit.td

index 9c061a8ae4cbc7c22f12ebfb55c5666184448fa0..7efaa66de27a4a9fcb8134d8b5a2976006f7229e 100644 (file)
@@ -1321,6 +1321,15 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
           NewBits.push_back(BI->getBit((e - i) - 1));
         continue;
       }
+      // bits<n> can also come from variable initializers.
+      if (VarInit *VI = dyn_cast<VarInit>(Vals[i])) {
+        if (BitsRecTy *BitsRec = dyn_cast<BitsRecTy>(VI->getType())) {
+          for (unsigned i = 0, e = BitsRec->getNumBits(); i != e; ++i)
+            NewBits.push_back(VI->getBit((e - i) - 1));
+          continue;
+        }
+        // Fallthrough to try convert this to a bit.
+      }
       // All other values must be convertible to just a single bit.
       Init *Bit = Vals[i]->convertInitializerTo(BitRecTy::get());
       if (!Bit) {
index 81cf77baa4566405c870bbe0d62a72c506d649e4..6aac3e41c6cbc4e12917591c123a14a5fa50e96e 100644 (file)
@@ -16,7 +16,7 @@ def a {
 // CHECK:   bits<2> opc = { 0, 1 };
 // CHECK:   bits<2> opc2 = { 1, 0 };
 // CHECK:   bits<1> opc3 = { 1 };
-// CHECK:   bits<2> a = { ?, ? };
+// CHECK:   bits<2> a;
 // CHECK:   bits<2> b = { 1, 0 };
 // CHECK:   bits<2> c = { 1, 1 };
 // CHECK: }
@@ -51,6 +51,7 @@ def {
 
   bits<16> H;
   let H{15-0} = { { 0b11001100 }, 0b00110011 };
+  bits<16> I = { G1, G2 };
 
   // Make sure we can initialise ints with bits<> values.
   int J = H;
@@ -78,6 +79,7 @@ def {
 // CHECK: bits<8> G2 = { 0, 1, 1, 0, 0, 1, 0, 0 };
 // CHECK: bits<8> G3 = { 0, 1, 1, 0, 0, 1, 0, 0 };
 // CHECK: bits<16> H = { 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 };
+// CHECK: bits<16> I = { 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0 };
 // CHECK: int J = 52275;
 // CHECK: int K = 1;
 // CHECK: }