207
|
1 // RUN: llvm-tblgen %s | FileCheck %s
|
|
2 // RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
|
|
3 // RUN: not llvm-tblgen -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s
|
|
4 // RUN: not llvm-tblgen -DERROR3 %s 2>&1 | FileCheck --check-prefix=ERROR3 %s
|
|
5 // RUN: not llvm-tblgen -DERROR4 %s 2>&1 | FileCheck --check-prefix=ERROR4 %s
|
|
6 // RUN: not llvm-tblgen -DERROR5 %s 2>&1 | FileCheck --check-prefix=ERROR5 %s
|
|
7 // RUN: not llvm-tblgen -DERROR6 %s 2>&1 | FileCheck --check-prefix=ERROR6 %s
|
|
8 // RUN: not llvm-tblgen -DERROR7 %s 2>&1 | FileCheck --check-prefix=ERROR7 %s
|
|
9
|
|
10 // This file tests that template arguments are type-checked and cast
|
|
11 // if necessary.
|
|
12
|
|
13 // Class template arguments.
|
|
14
|
|
15 class Class1<string nm> {
|
|
16 string Name = nm;
|
|
17 }
|
|
18
|
|
19 // CHECK: def Rec1
|
|
20 // CHECK: string Name = "Alice"
|
|
21 // CHECK: string NameName = "AliceAlice"
|
|
22
|
|
23 def Rec1 : Class1<"Alice"> {
|
|
24 string NameName = Name # Name;
|
|
25 }
|
|
26
|
|
27 #ifdef ERROR1
|
|
28 // ERROR1: Value specified for template argument 'Class1:nm' (#0) is of type int
|
|
29
|
|
30 def Rec2 : Class1<42> {
|
|
31 }
|
|
32 #endif
|
|
33
|
|
34 class Class2<bits<8> cd> {
|
|
35 int Code = cd;
|
|
36 }
|
|
37
|
|
38 // CHECK: def Rec3
|
|
39 // CHECK: int Code = 42
|
|
40 // CHECK: list<int> CodeList = [42]
|
|
41
|
|
42 def Rec3 : Class2<0b00101010> {
|
|
43 list<int> CodeList = [Code];
|
|
44 }
|
|
45
|
|
46 // CHECK: def Rec4
|
|
47 // CHECK: int Code = 42
|
|
48 // CHECK: list<int> CodeList = [42]
|
|
49
|
|
50 def Rec4 : Class2<42> {
|
|
51 list<int> CodeList = [Code];
|
|
52 }
|
|
53
|
|
54 #ifdef ERROR2
|
|
55 // ERROR2: Value specified for template argument 'Class2:cd' (#0) is of type string
|
|
56
|
|
57 def Rec5 : Class2<"oops"> {
|
|
58 list<int> CodeList = [Code];
|
|
59 }
|
|
60 #endif
|
|
61
|
|
62 // Anonymous class instantiation template arguments.
|
|
63
|
|
64 // CHECK: def Rec6
|
|
65 // CHECK: string Name = "Ted"
|
|
66
|
|
67 def Rec6 {
|
|
68 string Name = Class1<"Ted">.Name;
|
|
69 }
|
|
70
|
|
71 #ifdef ERROR3
|
|
72 // ERROR3: Value specified for template argument 'Class1:nm' (#0) is of type int
|
|
73
|
|
74 def Rec7 {
|
|
75 string Name = Class1<42>.Name;
|
|
76 }
|
|
77 #endif
|
|
78
|
|
79 // CHECK: def Rec8
|
|
80 // CHECK: list<int> CodeList = [42]
|
|
81
|
|
82 def Rec8 {
|
|
83 list<int> CodeList = [Class2<42>.Code];
|
|
84 }
|
|
85
|
|
86 #ifdef ERROR4
|
|
87 // ERROR4: Value specified for template argument 'Class2:cd' (#0) is of type string
|
|
88
|
|
89 def Rec9 {
|
|
90 list<int> CodeList = [Class2<"huh?">.Code];
|
|
91 }
|
|
92 #endif
|
|
93
|
|
94 // Multiclass template arguments.
|
|
95
|
|
96 multiclass MC1<string nm> {
|
|
97 def _1 {
|
|
98 string Name = nm;
|
|
99 }
|
|
100 def _2 {
|
|
101 string NameNmae = nm # nm;
|
|
102 }
|
|
103 }
|
|
104
|
|
105 // CHECK: def RecMC1_1
|
|
106 // CHECK: string Name = "Carol"
|
|
107 // CHECK: def RecMC1_2
|
|
108 // CHECK: string NameNmae = "CarolCarol"
|
|
109
|
|
110 defm RecMC1 : MC1<"Carol">;
|
|
111
|
|
112 #ifdef ERROR5
|
|
113 // ERROR5: Value specified for template argument 'MC1::nm' (#0) is of type int
|
|
114
|
|
115 defm RecMC2 : MC1<42>;
|
|
116 #endif
|
|
117
|
|
118 multiclass MC2<bits<8> cd> {
|
|
119 def _1 {
|
|
120 bits<8> Code = cd;
|
|
121 }
|
|
122 def _2 {
|
|
123 int Code = cd;
|
|
124 }
|
|
125 def _3 {
|
|
126 list<int> CodeList = [cd];
|
|
127 }
|
|
128 }
|
|
129
|
|
130 // CHECK: def RecMC3_1
|
|
131 // CHECK: bits<8> Code = { 0, 0, 1, 0, 1, 0, 1, 0 }
|
|
132 // CHECK: def RecMC3_2
|
|
133 // CHECK: int Code = 42
|
|
134 // CHECK: def RecMC3_3
|
|
135 // CHECK: list<int> CodeList = [42]
|
|
136
|
|
137 defm RecMC3 : MC2<42>;
|
|
138
|
|
139 #ifdef ERROR6
|
|
140 // ERROR6: Value specified for template argument 'MC2::cd' (#0) is of type string
|
|
141
|
|
142 defm RecMC4 : MC2<"Bob">;
|
|
143 #endif
|
|
144
|
|
145 #ifdef ERROR7
|
|
146 multiclass TwoArgs<bits<8> a, string b> {
|
|
147 def _1 { bits<8> A = a; }
|
|
148 def _2 { string B = b; }
|
|
149 }
|
|
150 defm Good : TwoArgs<1, "one">;
|
|
151 defm MissingComma : TwoArgs<2 "two">;
|
|
152 // ERROR7: [[#@LINE-1]]:31: error: Expected comma before next argument
|
|
153 #endif
|