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