llvm.org GIT mirror llvm / 64a334d
Change the { } expression in tablegen to accept sized binary literals which are not just 0 and 1. It also allows nested { } expressions, as now that they are sized, we can merge pull bits from the nested value. In the current behaviour, everything in { } must have been convertible to a single bit. However, now that binary literals are sized, its useful to be able to initialize a range of bits. So, for example, its now possible to do bits<8> x = { 0, 1, { 0b1001 }, 0, 0b0 } git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215086 91177308-0d34-0410-b5e6-96231b3b80d8 Pete Cooper 5 years ago
2 changed file(s) with 39 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
13011301 }
13021302 Lex.Lex(); // eat the '}'
13031303
1304 SmallVector NewBits(Vals.size());
1305
1304 SmallVector NewBits;
1305
1306 // As we parse { a, b, ... }, 'a' is the highest bit, but we parse it
1307 // first. We'll first read everything in to a vector, then we can reverse
1308 // it to get the bits in the correct order for the BitsInit value.
13061309 for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
1310 // bits values are allowed to initialize n bits.
1311 if (BitsInit *BI = dyn_cast(Vals[i])) {
1312 for (unsigned i = 0, e = BI->getNumBits(); i != e; ++i)
1313 NewBits.push_back(BI->getBit((e - i) - 1));
1314 continue;
1315 }
1316 // All other values must be convertible to just a single bit.
13071317 Init *Bit = Vals[i]->convertInitializerTo(BitRecTy::get());
13081318 if (!Bit) {
13091319 Error(BraceLoc, "Element #" + utostr(i) + " (" + Vals[i]->getAsString()+
13101320 ") is not convertable to a bit");
13111321 return nullptr;
13121322 }
1313 NewBits[Vals.size()-i-1] = Bit;
1314 }
1323 NewBits.push_back(Bit);
1324 }
1325 std::reverse(NewBits.begin(), NewBits.end());
13151326 return BitsInit::get(NewBits);
13161327 }
13171328 case tgtok::l_square: { // Value ::= '[' ValueList ']'
3939 bits<8> E;
4040 let E{7-0} = {0,0,1,?,?,?,?,?};
4141 let E{3-0} = 0b0010;
42
43 bits<8> F1 = { 0, 1, 0b1001, 0, 0b0 }; // ok
44 bits<7> F2 = { 0, 1, 0b1001, 0, 0b0 }; // LHS doesn't have enough bits
45 bits<9> F3 = { 0, 1, 0b1001, 0, 0b0 }; // RHS doesn't have enough bits
46
47 bits<8> G1 = { 0, { 1, 0b1001, 0 }, 0b0 }; // ok
48 bits<8> G2 = { 0, { 1, 0b1001 }, 0, 0b0 }; // ok
49 bits<8> G3 = { 0, 1, { 0b1001 }, 0, 0b0 }; // ok
50
51 bits<16> H;
52 let H{15-0} = { { 0b11001100 }, 0b00110011 };
53
54 // Make sure we can initialise ints with bits<> values.
55 int J = H;
56 int K = { 0, 1 };
4257 }
4358
4459 // CHECK: def {{.*}} {
5570 // CHECK: bits<1> D7 = { ? };
5671 // CHECK: bits<2> D8;
5772 // CHECK: bits<8> E = { 0, 0, 1, ?, 0, 0, 1, 0 };
73 // CHECK: bits<8> F1 = { 0, 1, 1, 0, 0, 1, 0, 0 };
74 // CHECK: bits<7> F2;
75 // CHECK: bits<9> F3;
76 // CHECK: bits<8> G1 = { 0, 1, 1, 0, 0, 1, 0, 0 };
77 // CHECK: bits<8> G2 = { 0, 1, 1, 0, 0, 1, 0, 0 };
78 // CHECK: bits<8> G3 = { 0, 1, 1, 0, 0, 1, 0, 0 };
79 // CHECK: bits<16> H = { 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 };
80 // CHECK: int J = 52275;
81 // CHECK: int K = 1;
5882 // CHECK: }