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
10 // This file tests that template arguments are type-checked and cast
13 // Class template arguments.
15 class Class1<string nm> {
20 // CHECK: string Name = "Alice"
21 // CHECK: string NameName = "AliceAlice"
23 def Rec1 : Class1<"Alice"> {
24 string NameName = Name # Name;
28 // ERROR1: Value specified for template argument 'Class1:nm' (#0) is of type int
30 def Rec2 : Class1<42> {
34 class Class2<bits<8> cd> {
39 // CHECK: int Code = 42
40 // CHECK: list<int> CodeList = [42]
42 def Rec3 : Class2<0b00101010> {
43 list<int> CodeList = [Code];
47 // CHECK: int Code = 42
48 // CHECK: list<int> CodeList = [42]
50 def Rec4 : Class2<42> {
51 list<int> CodeList = [Code];
55 // ERROR2: Value specified for template argument 'Class2:cd' (#0) is of type string
57 def Rec5 : Class2<"oops"> {
58 list<int> CodeList = [Code];
62 // Anonymous class instantiation template arguments.
65 // CHECK: string Name = "Ted"
68 string Name = Class1<"Ted">.Name;
72 // ERROR3: Value specified for template argument 'Class1:nm' (#0) is of type int
75 string Name = Class1<42>.Name;
80 // CHECK: list<int> CodeList = [42]
83 list<int> CodeList = [Class2<42>.Code];
87 // ERROR4: Value specified for template argument 'Class2:cd' (#0) is of type string
90 list<int> CodeList = [Class2<"huh?">.Code];
94 // Multiclass template arguments.
96 multiclass MC1<string nm> {
101 string NameNmae = nm # nm;
105 // CHECK: def RecMC1_1
106 // CHECK: string Name = "Carol"
107 // CHECK: def RecMC1_2
108 // CHECK: string NameNmae = "CarolCarol"
110 defm RecMC1 : MC1<"Carol">;
113 // ERROR5: Value specified for template argument 'MC1::nm' (#0) is of type int
115 defm RecMC2 : MC1<42>;
118 multiclass MC2<bits<8> cd> {
126 list<int> CodeList = [cd];
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]
137 defm RecMC3 : MC2<42>;
140 // ERROR6: Value specified for template argument 'MC2::cd' (#0) is of type string
142 defm RecMC4 : MC2<"Bob">;
146 multiclass TwoArgs<bits<8> a, string b> {
147 def _1 { bits<8> A = a; }
148 def _2 { string B = b; }
150 defm Good : TwoArgs<1, "one">;
151 defm MissingComma : TwoArgs<2 "two">;
152 // ERROR7: [[#@LINE-1]]:31: error: Expected comma before next argument