blob: c5527aebb94177a37f80c70d3672aec85bcd9bce [file] [log] [blame]
Pete Cooper99ad2a32014-08-07 05:46:57 +00001
2// RUN: not llvm-tblgen %s 2>&1 > %t
3// RUN: FileCheck %s < %t
4
5def a {
6 bits<2> opc = { 0, 1 };
7 bits<2> opc2 = { 1, 0 };
8 bits<1> opc3 = { 1 };
9 bits<2> a = { opc, opc2 }; // error!
10 bits<2> b = { opc{0}, opc2{0} };
11 bits<2> c = { opc{1}, opc2{1} };
12 bits<2> c = { opc3{0}, opc3 };
13}
14
15// CHECK: def a {
16// CHECK: bits<2> opc = { 0, 1 };
17// CHECK: bits<2> opc2 = { 1, 0 };
18// CHECK: bits<1> opc3 = { 1 };
Jean-Luc Duprat6d7b4562014-08-29 19:41:04 +000019// CHECK: bits<2> a;
Pete Cooper99ad2a32014-08-07 05:46:57 +000020// CHECK: bits<2> b = { 1, 0 };
21// CHECK: bits<2> c = { 1, 1 };
22// CHECK: }
Pete Cooper25977642014-08-07 05:47:00 +000023
24def {
25 bits<2> B1 = 0b011; // bitfield is too small, reject
26 bits<3> B2 = 0b011; // ok
27
28 bits<2> C1 = 0b111; // bitfield is too small, reject
29 bits<3> C2 = 0b111; // ok
30
31 bits<2> D1 = { 0, 0 }; // ok
32 bits<2> D2 = { 0b00 }; // ok
33 bits<3> D3 = { 0, 0 }; // type mismatch. RHS doesn't have enough bits
34 bits<3> D4 = { 0b00 }; // type mismatch. RHS doesn't have enough bits
35 bits<1> D5 = { 0 }; // ok
36 bits<1> D6 = { 1 }; // ok
37 bits<1> D7 = { 3 }; // type mismatch. LHS doesn't have enough bits
38 bits<2> D8 = { 0 }; // type mismatch. RHS doesn't have enough bits
39
40 bits<8> E;
Paul C. Anagnostopoulos93b4f852020-09-11 10:26:26 -040041 let E{7...0} = {0,0,1,?,?,?,?,?};
42 let E{3...0} = 0b0010;
Pete Cooper0bf1ea72014-08-07 05:47:07 +000043
44 bits<8> F1 = { 0, 1, 0b1001, 0, 0b0 }; // ok
45 bits<7> F2 = { 0, 1, 0b1001, 0, 0b0 }; // LHS doesn't have enough bits
46 bits<9> F3 = { 0, 1, 0b1001, 0, 0b0 }; // RHS doesn't have enough bits
47
48 bits<8> G1 = { 0, { 1, 0b1001, 0 }, 0b0 }; // ok
49 bits<8> G2 = { 0, { 1, 0b1001 }, 0, 0b0 }; // ok
50 bits<8> G3 = { 0, 1, { 0b1001 }, 0, 0b0 }; // ok
51
52 bits<16> H;
Paul C. Anagnostopoulos93b4f852020-09-11 10:26:26 -040053 let H{15...0} = { { 0b11001100 }, 0b00110011 };
Jean-Luc Duprat6d7b4562014-08-29 19:41:04 +000054 bits<16> I = { G1, G2 };
Pete Cooper0bf1ea72014-08-07 05:47:07 +000055
56 // Make sure we can initialise ints with bits<> values.
57 int J = H;
58 int K = { 0, 1 };
Simon Tatham5c6b1a62020-02-07 14:59:00 +000059
60 bits<2> L;
61 let L{0} = 1;
62 let L{1} = !eq(L{0}, 0);
Pete Cooper25977642014-08-07 05:47:00 +000063}
64
65// CHECK: def {{.*}} {
66// CHECK: bits<2> B1;
67// CHECK: bits<3> B2 = { 0, 1, 1 };
68// CHECK: bits<2> C1;
69// CHECK: bits<3> C2 = { 1, 1, 1 };
70// CHECK: bits<2> D1 = { 0, 0 };
71// CHECK: bits<2> D2 = { 0, 0 };
72// CHECK: bits<3> D3;
73// CHECK: bits<3> D4;
74// CHECK: bits<1> D5 = { 0 };
75// CHECK: bits<1> D6 = { 1 };
Nicolai Haehnledfda9dc2018-03-06 13:48:39 +000076// CHECK: bits<1> D7 = { !cast<bit>(3) };
Pete Cooper25977642014-08-07 05:47:00 +000077// CHECK: bits<2> D8;
78// CHECK: bits<8> E = { 0, 0, 1, ?, 0, 0, 1, 0 };
Pete Cooper0bf1ea72014-08-07 05:47:07 +000079// CHECK: bits<8> F1 = { 0, 1, 1, 0, 0, 1, 0, 0 };
80// CHECK: bits<7> F2;
81// CHECK: bits<9> F3;
82// CHECK: bits<8> G1 = { 0, 1, 1, 0, 0, 1, 0, 0 };
83// CHECK: bits<8> G2 = { 0, 1, 1, 0, 0, 1, 0, 0 };
84// CHECK: bits<8> G3 = { 0, 1, 1, 0, 0, 1, 0, 0 };
85// CHECK: bits<16> H = { 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1 };
Jean-Luc Duprat6d7b4562014-08-29 19:41:04 +000086// CHECK: bits<16> I = { 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0 };
Pete Cooper0bf1ea72014-08-07 05:47:07 +000087// CHECK: int J = 52275;
88// CHECK: int K = 1;
Simon Tatham5c6b1a62020-02-07 14:59:00 +000089// CHECK: bits<2> L = { 0, 1 };
Pete Cooper25977642014-08-07 05:47:00 +000090// CHECK: }