diff --git a/lib/TableGen/TGParser.cpp b/lib/TableGen/TGParser.cpp index 9c061a8ae4c..7efaa66de27 100644 --- a/lib/TableGen/TGParser.cpp +++ b/lib/TableGen/TGParser.cpp @@ -1321,6 +1321,15 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType, NewBits.push_back(BI->getBit((e - i) - 1)); continue; } + // bits can also come from variable initializers. + if (VarInit *VI = dyn_cast(Vals[i])) { + if (BitsRecTy *BitsRec = dyn_cast(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) { diff --git a/test/TableGen/BitsInit.td b/test/TableGen/BitsInit.td index 81cf77baa45..6aac3e41c6c 100644 --- a/test/TableGen/BitsInit.td +++ b/test/TableGen/BitsInit.td @@ -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: }