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 // RUN: not llvm-tblgen -DERROR8 %s 2>&1 | FileCheck --check-prefix=ERROR8 %s
10 // RUN: not llvm-tblgen -DERROR9 %s 2>&1 | FileCheck --check-prefix=ERROR9 %s
12 // !setop and !getop are deprecated in favor of !setdagop and !getdagop.
13 // Two tests retain the old names just to be sure they are still supported.
28 dag orig = (foo 1, 2:$a, $b);
29 dag another = (qux "hello", $world);
31 // CHECK: dag replaceWithBar = (bar 1, 2:$a, ?:$b);
32 dag replaceWithBar = !setop(orig, bar);
34 // CHECK: dag replaceWithBaz = (qux 1, 2:$a, ?:$b);
35 dag replaceWithBaz = !setdagop(orig, qux);
37 // CHECK: Base getopWithCast = foo;
38 Base getopWithCast = !getop<Base>(orig);
40 // CHECK: dag getopToSetop = (foo "hello", ?:$world);
41 dag getopToSetop = !setdagop(another, !getdagop(orig));
43 // CHECK: dag getopToBangDag = (foo 1:$a, 2:$b, 3:$c);
44 dag getopToBangDag = !dag(!getdagop(orig), [1, 2, 3], ["a", "b", "c"]);
46 // CHECK: dag getopToDagInit = (foo "it worked");
47 dag getopToDagInit = (!getdagop(orig) "it worked");
50 // !getdagop(...) has a static type of 'any record at all, with no
51 // required superclasses'. That's too general to use in an
52 // assignment whose LHS demands an instance of Base, so we expect a
53 // static (parse-time) type-checking error.
55 // ERROR1: error: Field 'noCast' of type 'Base' is incompatible with value '!getdagop(orig)' of type '{}'
56 Base noCast = !getdagop(orig);
60 // Here, we expect a _dynamic_ type error, when it turns out at
61 // evaluation time that the operator of 'another' is a record that
62 // isn't an instance of the specified base class.
64 // ERROR2: error: Expected type 'Base', got 'OtherBase' in: !getdagop((qux "hello", ?:$world))
65 Base badCast = !getdagop<Base>(another);
69 // Obviously, you shouldn't be able to give any type to !getdagop that
70 // isn't a class type.
72 // ERROR3: error: type for !getdagop must be a record type
73 int ridiculousCast = !getdagop<int>(orig);
76 dag in1 = (foo 1:$a, 2:$b, 3:$c);
77 // CHECK: list<string> in1Names = ["a", "b", "c"];
78 list<string> in1Names = !foreach(i, !range(!size(in1)), !getdagname(in1, i));
79 // CHECK: list<int> in1Args = [1, 2, 3];
80 list<int> in1Args = !foreach(i, !range(!size(in1)), !getdagarg<int>(in1, i));
82 dag in2 = (foo 1:$a, (bar "x":$x, (qux foo:$s1, bar:$s2):$y, 7:$z):$b, 3:$c);
83 // CHECK: dag in2NestedDag = (qux foo:$s1, bar:$s2);
84 dag in2NestedDag = !getdagarg<dag>(!getdagarg<dag>(in2, 1), "y");
85 // CHECK: Base in2NestedArg = foo;
86 Base in2NestedArg = !getdagarg<Base>(!getdagarg<dag>(!getdagarg<dag>(in2, 1), "y"), "s1");
88 dag in3 = (foo 1:$a, ?:$b, 3);
89 // CHECK: list<string> in3Names = ["a", "b", ?];
90 list<string> in3Names = !foreach(i, !range(!size(in3)), !getdagname(in3, i));
91 // CHECK: list<int> in3Args = [1, ?, 3];
92 list<int> in3Args = !foreach(i, !range(!size(in3)), !getdagarg<int>(in3, i));
95 // ERROR4: error: !getdagarg index -1 is negative
96 int outOfRange = !getdagarg<int>(in1, -1);
100 // ERROR5: error: !getdagarg index 3 is out of range (dag has 3 arguments)
101 int outOfRange = !getdagarg<int>(in1, 3);
105 // ERROR6: error: !getdagarg key 'x' is not found
106 int notFound = !getdagarg<int>(in1, "x");
109 dag in4 = (foo "arg1":$a, "arg2":$b, "arg3":$c);
110 // CHECK: int misMatchType1 = ?;
111 int misMatchType1 = !getdagarg<int>(in4, 0);
113 dag in5 = (foo foo:$a, bar:$b, foo:$c);
114 // CHECK: OtherBase misMatchType2 = ?;
115 OtherBase misMatchType2 = !getdagarg<OtherBase>(in5, 1);
117 dag in6 = (foo alice:$a, bob:$b);
118 // CHECK: Base base = bob;
119 Base base = !getdagarg<Base>(in6, 1);
121 // CHECK: dag orig_set_val = (foo 1, 2:$a, "val":$b);
122 dag orig_set_val = !setdagarg(orig, 2, "val");
123 // CHECK: dag orig_set_val_by_name = (foo 1, 2:$a, "aval":$b);
124 dag orig_set_val_by_name = !setdagarg(orig, "b", "aval");
125 // CHECK: dag orig_set_dag_val = (foo 1, 2:$a, (bar foo:$p, qux:$q):$b);
126 dag orig_set_dag_val = !setdagarg(orig, "b", (bar foo:$p, qux:$q));
127 // CHECK: dag orig_clr_val = (foo 1, ?:$a, ?:$b);
128 dag orig_clr_val = !setdagarg(orig, "a", ?);
129 // CHECK: dag orig_set_name = (foo 1:$c, 2:$a, ?:$b);
130 dag orig_set_name = !setdagname(orig, 0, "c");
131 // CHECK: dag orig_clr_name = (foo 1, 2, ?:$b);
132 dag orig_clr_name = !setdagname(orig, 1, ?);
133 // CHECK: dag orig_rename = (foo 1, 2:$x, ?:$y);
134 dag orig_rename = !setdagname(!setdagname(orig, "a", "x"), "b", "y");
137 // ERROR7: error: !setdagarg index -1 is negative
138 dag orig_negative = !setdagarg(orig, -1, "val");
142 // ERROR8: error: !setdagarg index 3 is out of range (dag has 3 arguments)
143 dag orig_out_of_range = !setdagarg(orig, 3, "val");
147 // ERROR9: error: expected integer index or string name, got type 'Base'
148 dag orig_out_of_range = !setdagarg(orig, foo, (foo qux:$a));