blob: e5a8d8aeef649077d7bb1239d0eaa5373f156672 [file] [log] [blame]
// RUN: llvm-tblgen %s | FileCheck %s
// RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
// RUN: not llvm-tblgen -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s
// RUN: not llvm-tblgen -DERROR3 %s 2>&1 | FileCheck --check-prefix=ERROR3 %s
// RUN: not llvm-tblgen -DERROR4 %s 2>&1 | FileCheck --check-prefix=ERROR4 %s
// RUN: not llvm-tblgen -DERROR5 %s 2>&1 | FileCheck --check-prefix=ERROR5 %s
// RUN: not llvm-tblgen -DERROR6 %s 2>&1 | FileCheck --check-prefix=ERROR6 %s
// !setop and !getop are deprecated in favor of !setdagop and !getdagop.
// Two tests retain the old names just to be sure they are still supported.
class Base;
class OtherBase;
class Super : Base;
def foo: Base;
def bar: Base;
def qux: OtherBase;
def alice : Super;
def bob : Super;
def test {
dag orig = (foo 1, 2:$a, $b);
dag another = (qux "hello", $world);
// CHECK: dag replaceWithBar = (bar 1, 2:$a, ?:$b);
dag replaceWithBar = !setop(orig, bar);
// CHECK: dag replaceWithBaz = (qux 1, 2:$a, ?:$b);
dag replaceWithBaz = !setdagop(orig, qux);
// CHECK: Base getopWithCast = foo;
Base getopWithCast = !getop<Base>(orig);
// CHECK: dag getopToSetop = (foo "hello", ?:$world);
dag getopToSetop = !setdagop(another, !getdagop(orig));
// CHECK: dag getopToBangDag = (foo 1:$a, 2:$b, 3:$c);
dag getopToBangDag = !dag(!getdagop(orig), [1, 2, 3], ["a", "b", "c"]);
// CHECK: dag getopToDagInit = (foo "it worked");
dag getopToDagInit = (!getdagop(orig) "it worked");
#ifdef ERROR1
// !getdagop(...) has a static type of 'any record at all, with no
// required superclasses'. That's too general to use in an
// assignment whose LHS demands an instance of Base, so we expect a
// static (parse-time) type-checking error.
// ERROR1: error: Field 'noCast' of type 'Base' is incompatible with value '!getdagop(orig)' of type '{}'
Base noCast = !getdagop(orig);
#endif
#ifdef ERROR2
// Here, we expect a _dynamic_ type error, when it turns out at
// evaluation time that the operator of 'another' is a record that
// isn't an instance of the specified base class.
// ERROR2: error: Expected type 'Base', got 'OtherBase' in: !getdagop((qux "hello", ?:$world))
Base badCast = !getdagop<Base>(another);
#endif
#ifdef ERROR3
// Obviously, you shouldn't be able to give any type to !getdagop that
// isn't a class type.
// ERROR3: error: type for !getdagop must be a record type
int ridiculousCast = !getdagop<int>(orig);
#endif
dag in1 = (foo 1:$a, 2:$b, 3:$c);
// CHECK: list<string> in1Names = ["a", "b", "c"];
list<string> in1Names = !foreach(i, !range(!size(in1)), !getdagname(in1, i));
// CHECK: list<int> in1Args = [1, 2, 3];
list<int> in1Args = !foreach(i, !range(!size(in1)), !getdagarg<int>(in1, i));
dag in2 = (foo 1:$a, (bar "x":$x, (qux foo:$s1, bar:$s2):$y, 7:$z):$b, 3:$c);
// CHECK: dag in2NestedDag = (qux foo:$s1, bar:$s2);
dag in2NestedDag = !getdagarg<dag>(!getdagarg<dag>(in2, 1), "y");
// CHECK: Base in2NestedArg = foo;
Base in2NestedArg = !getdagarg<Base>(!getdagarg<dag>(!getdagarg<dag>(in2, 1), "y"), "s1");
dag in3 = (foo 1:$a, ?:$b, 3);
// CHECK: list<string> in3Names = ["a", "b", ?];
list<string> in3Names = !foreach(i, !range(!size(in3)), !getdagname(in3, i));
// CHECK: list<int> in3Args = [1, ?, 3];
list<int> in3Args = !foreach(i, !range(!size(in3)), !getdagarg<int>(in3, i));
#ifdef ERROR4
// ERROR4: error: !getdagarg index -1 is negative
int outOfRange = !getdagarg<int>(in1, -1);
#endif
#ifdef ERROR5
// ERROR5: error: !getdagarg index 3 is out of range (dag has 3 arguments)
int outOfRange = !getdagarg<int>(in1, 3);
#endif
#ifdef ERROR6
// ERROR6: error: !getdagarg key 'x' is not found
int notFound = !getdagarg<int>(in1, "x");
#endif
dag in4 = (foo "arg1":$a, "arg2":$b, "arg3":$c);
// CHECK: int misMatchType1 = ?;
int misMatchType1 = !getdagarg<int>(in4, 0);
dag in5 = (foo foo:$a, bar:$b, foo:$c);
// CHECK: OtherBase misMatchType2 = ?;
OtherBase misMatchType2 = !getdagarg<OtherBase>(in5, 1);
dag in6 = (foo alice:$a, bob:$b);
// CHECK: Base base = bob;
Base base = !getdagarg<Base>(in6, 1);
}