1 // RUN: llvm-tblgen -dump-json %s | %python %S/JSON-check.py %s
3 // CHECK: data['!tablegen_json_version'] == 1
5 // CHECK: all(data[s]['!name'] == s for s in data if not s.startswith("!"))
8 class Intermediate : Base {}
9 class Derived : Intermediate {}
11 def D : Intermediate {}
12 // CHECK: 'D' in data['!instanceof']['Base']
13 // CHECK: 'D' in data['!instanceof']['Intermediate']
14 // CHECK: 'D' not in data['!instanceof']['Derived']
15 // CHECK: 'Base' in data['D']['!superclasses']
16 // CHECK: 'Intermediate' in data['D']['!superclasses']
17 // CHECK: 'Derived' not in data['D']['!superclasses']
21 def FieldKeywordTest {
24 // CHECK: 'a' not in data['FieldKeywordTest']['!fields']
25 // CHECK: 'b' in data['FieldKeywordTest']['!fields']
38 def VarNull : Variables {
39 // A variable not filled in at all has its value set to JSON
40 // 'null', which translates to Python None
41 // CHECK: data['VarNull']['i'] is None
43 def VarPrim : Variables {
44 // Test initializers that map to primitive JSON types
47 // CHECK: data['VarPrim']['i'] == 3
49 // Integer literals should be emitted in the JSON at full 64-bit
50 // precision, for the benefit of JSON readers that preserve that
51 // much information. Python's is one such.
52 int enormous_pos = 9123456789123456789;
53 int enormous_neg = -9123456789123456789;
54 // CHECK: data['VarPrim']['enormous_pos'] == 9123456789123456789
55 // CHECK: data['VarPrim']['enormous_neg'] == -9123456789123456789
57 string s = "hello, world";
58 // CHECK: data['VarPrim']['s'] == 'hello, world'
61 // CHECK: data['VarPrim']['b'] == 0
63 // bits<> arrays are stored in logical order (array[i] is the same
64 // bit identified in .td files as bs{i}), which means the _visual_
65 // order of the list (in default rendering) is reversed.
66 bits<8> bs = { 0,0,0,1,0,1,1,1 };
67 // CHECK: data['VarPrim']['bs'] == [ 1,1,1,0,1,0,0,0 ]
70 // CHECK: data['VarPrim']['c'] == r' \" '
72 list<int> li = [ 1, 2, 3, 4 ];
73 // CHECK: data['VarPrim']['li'] == [ 1, 2, 3, 4 ]
75 def VarObj : Variables {
76 // Test initializers that map to JSON objects containing a 'kind'
80 // CHECK: data['VarObj']['base']['kind'] == 'def'
81 // CHECK: data['VarObj']['base']['def'] == 'D'
82 // CHECK: data['VarObj']['base']['printable'] == 'D'
84 dag d = (ExampleDagOp 22, "hello":$foo);
85 // CHECK: data['VarObj']['d']['kind'] == 'dag'
86 // CHECK: data['VarObj']['d']['operator']['kind'] == 'def'
87 // CHECK: data['VarObj']['d']['operator']['def'] == 'ExampleDagOp'
88 // CHECK: data['VarObj']['d']['operator']['printable'] == 'ExampleDagOp'
89 // CHECK: data['VarObj']['d']['args'] == [[22, None], ["hello", "foo"]]
90 // CHECK: data['VarObj']['d']['printable'] == '(ExampleDagOp 22, "hello":$foo)'
93 field int ref_int = undef_int;
94 // CHECK: data['VarObj']['ref_int']['kind'] == 'var'
95 // CHECK: data['VarObj']['ref_int']['var'] == 'undef_int'
96 // CHECK: data['VarObj']['ref_int']['printable'] == 'undef_int'
100 let ref_bits{3-2} = 0b10;
101 let ref_bits{1-0} = undef_bits{1-0};
102 // CHECK: data['VarObj']['ref_bits'][3] == 1
103 // CHECK: data['VarObj']['ref_bits'][2] == 0
104 // CHECK: data['VarObj']['ref_bits'][1]['kind'] == 'varbit'
105 // CHECK: data['VarObj']['ref_bits'][1]['var'] == 'undef_bits'
106 // CHECK: data['VarObj']['ref_bits'][1]['index'] == 1
107 // CHECK: data['VarObj']['ref_bits'][1]['printable'] == 'undef_bits{1}'
108 // CHECK: data['VarObj']['ref_bits'][0]['kind'] == 'varbit'
109 // CHECK: data['VarObj']['ref_bits'][0]['var'] == 'undef_bits'
110 // CHECK: data['VarObj']['ref_bits'][0]['index'] == 0
111 // CHECK: data['VarObj']['ref_bits'][0]['printable'] == 'undef_bits{0}'
113 field int complex_ref_int = !add(undef_int, 2);
114 // CHECK: data['VarObj']['complex_ref_int']['kind'] == 'complex'
115 // CHECK: data['VarObj']['complex_ref_int']['printable'] == '!add(undef_int, 2)'
118 // Test the !anonymous member. This is tricky because when a def is
119 // anonymous, almost by definition, the test can't reliably predict
120 // the name it will be stored under! So we have to search all the defs
121 // in the JSON output looking for the one that has the test integer
122 // field set to the right value.
124 def Named { int AnonTestField = 1; }
125 // CHECK: data['Named']['AnonTestField'] == 1
126 // CHECK: data['Named']['!anonymous'] is False
128 def { int AnonTestField = 2; }
129 // CHECK: next(rec for rec in data.values() if isinstance(rec, dict) and rec.get('AnonTestField') == 2)['!anonymous'] is True
131 multiclass AnonTestMulticlass<int base> {
132 def _plus_one { int AnonTestField = !add(base,1); }
133 def { int AnonTestField = !add(base,2); }
136 defm NamedDefm : AnonTestMulticlass<10>;
137 // CHECK: data['NamedDefm_plus_one']['!anonymous'] is False
138 // CHECK: data['NamedDefm_plus_one']['AnonTestField'] == 11
139 // CHECK: next(rec for rec in data.values() if isinstance(rec, dict) and rec.get('AnonTestField') == 12)['!anonymous'] is True
141 // D47431 clarifies that a named def inside a multiclass gives a
142 // *non*-anonymous output record, even if the defm that instantiates
143 // that multiclass is anonymous.
144 defm : AnonTestMulticlass<20>;
145 // CHECK: next(rec for rec in data.values() if isinstance(rec, dict) and rec.get('AnonTestField') == 21)['!anonymous'] is False
146 // CHECK: next(rec for rec in data.values() if isinstance(rec, dict) and rec.get('AnonTestField') == 22)['!anonymous'] is True