|
| 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 | +// XFAIL: vg_leak |
| 6 | + |
| 7 | +class A; |
| 8 | +def a0 : A; |
| 9 | +def a1 : A; |
| 10 | + |
| 11 | +class B : A; |
| 12 | +def b0 : B; |
| 13 | +def b1 : B; |
| 14 | + |
| 15 | +// CHECK-LABEL: def test0_instances_A { |
| 16 | +// CHECK-NEXT: list<A> instances = [a0, a1, b0, b1]; |
| 17 | +// CHECK-NEXT: } |
| 18 | +def test0_instances_A { |
| 19 | + list<A> instances = !instances<A>(); |
| 20 | +} |
| 21 | + |
| 22 | +// CHECK-LABEL: def test1_instances_A_x0 { |
| 23 | +// CHECK-NEXT: list<A> instances = [a0, b0]; |
| 24 | +// CHECK-NEXT: } |
| 25 | +def test1_instances_A_x0 { |
| 26 | + list<A> instances = !instances<A>(".*0"); |
| 27 | +} |
| 28 | + |
| 29 | +// CHECK-LABEL: def test2_instances_A_x1 { |
| 30 | +// CHECK-NEXT: list<A> instances = [a1, b1]; |
| 31 | +// CHECK-NEXT: } |
| 32 | +def test2_instances_A_x1 { |
| 33 | + list<A> instances = !instances<A>(".*1"); |
| 34 | +} |
| 35 | + |
| 36 | +// CHECK-LABEL: def test3_instances_B { |
| 37 | +// CHECK-NEXT: list<B> instances = [b0, b1]; |
| 38 | +// CHECK-NEXT: } |
| 39 | +def test3_instances_B { |
| 40 | + list<B> instances = !instances<B>(); |
| 41 | +} |
| 42 | + |
| 43 | +//-----------------------------------------------------------------------------// |
| 44 | + |
| 45 | +def a2 : A; |
| 46 | +def b2 : B; |
| 47 | + |
| 48 | +class ClassTest { |
| 49 | + list<A> instances_A = !instances<A>(); |
| 50 | + list<B> instances_B = !instances<B>(); |
| 51 | +} |
| 52 | + |
| 53 | +def a3 : A; |
| 54 | +def b3 : B; |
| 55 | + |
| 56 | +def test4_in_class_def : ClassTest; |
| 57 | +// CHECK-LABEL: def test4_in_class_def { |
| 58 | +// CHECK-NEXT: list<A> instances_A = [a0, a1, a2, a3, b0, b1, b2, b3]; |
| 59 | +// CHECK-NEXT: list<B> instances_B = [b0, b1, b2, b3]; |
| 60 | +// CHECK-NEXT: } |
| 61 | + |
| 62 | +//-----------------------------------------------------------------------------// |
| 63 | +// Self-recurrence is not supported, so it won't be count in. |
| 64 | + |
| 65 | +// CHECK-LABEL: def test5_self_recurrence { |
| 66 | +// CHECK-NEXT: list<A> instances_A = [a0, a1, a2, a3, b0, b1, b2, b3]; |
| 67 | +// CHECK-NEXT: } |
| 68 | +def test5_self_recurrence : A { |
| 69 | + list<A> instances_A = !instances<A>(); |
| 70 | +} |
| 71 | + |
| 72 | +//-----------------------------------------------------------------------------// |
| 73 | +// Test these in multiclasses/loops. |
| 74 | + |
| 75 | +class C { |
| 76 | + list<C> instances_C = !instances<C>(); |
| 77 | +} |
| 78 | + |
| 79 | +multiclass MultiClassTest { |
| 80 | + foreach i = 0-2 in { |
| 81 | + def "c"#i : C; |
| 82 | + } |
| 83 | +} |
| 84 | + |
| 85 | +// CHECK-LABEL: def test6_in_multiclass_def_c0 { |
| 86 | +// CHECK-NEXT: list<C> instances_C = []; |
| 87 | +// CHECK-NEXT: } |
| 88 | +// CHECK-LABEL: def test6_in_multiclass_def_c1 { |
| 89 | +// CHECK-NEXT: list<C> instances_C = [test6_in_multiclass_def_c0]; |
| 90 | +// CHECK-NEXT: } |
| 91 | +// CHECK-LABEL: def test6_in_multiclass_def_c2 { |
| 92 | +// CHECK-NEXT: list<C> instances_C = [test6_in_multiclass_def_c0, test6_in_multiclass_def_c1]; |
| 93 | +// CHECK-NEXT: } |
| 94 | +defm test6_in_multiclass_def_ : MultiClassTest; |
| 95 | + |
| 96 | +//-----------------------------------------------------------------------------// |
| 97 | +// Default argument will be considered as well. |
| 98 | + |
| 99 | +class TestArgument<B b = B<>> { |
| 100 | + list<B> instances_B = !instances<B>(); |
| 101 | +} |
| 102 | + |
| 103 | +// CHECK-LABEL: def test7_default_arg { |
| 104 | +// CHECK-NEXT: list<B> instances_B = [anonymous_0, b0, b1, b2, b3]; |
| 105 | +// CHECK-NEXT: } |
| 106 | +def test7_default_arg : TestArgument; |
| 107 | + |
| 108 | +// Temporary actual parameter won't be considered. |
| 109 | + |
| 110 | +// CHECK-LABEL: def test8_anonymous0_arg { |
| 111 | +// CHECK-NEXT: list<B> instances_B = [anonymous_0, b0, b1, b2, b3]; |
| 112 | +// CHECK-NEXT: } |
| 113 | +// CHECK-LABEL: def test8_anonymous1_arg { |
| 114 | +// CHECK-NEXT: list<B> instances_B = [anonymous_0, b0, b1, b2, b3]; |
| 115 | +// CHECK-NEXT: } |
| 116 | +def test8_anonymous0_arg : TestArgument<B<>>; |
| 117 | +def test8_anonymous1_arg : TestArgument<B<>>; |
| 118 | + |
| 119 | +//-----------------------------------------------------------------------------// |
| 120 | + |
| 121 | +#ifdef ERROR1 |
| 122 | +defvar error1 = !instances<A>(123); |
| 123 | +// ERROR1: error: expected string type argument in !instances operator |
| 124 | +#endif |
| 125 | + |
| 126 | +#ifdef ERROR2 |
| 127 | +defvar error2 = !instances<1>(""); |
| 128 | +// ERROR2: error: Unknown token when expecting a type |
| 129 | +#endif |
| 130 | + |
| 131 | +#ifdef ERROR3 |
| 132 | +defvar error3 = !instances<A>("([)]"); |
| 133 | +// ERROR3: error: invalid regex '([)]' |
| 134 | +#endif |
0 commit comments