1 // RUN: llvm-tblgen %s | FileCheck %s
2 // RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
4 defvar EmptyList = []<string>;
5 defvar OneList = ["hello"];
6 defvar StringList = ["foo", "bar", "zoo", "snork", "quux"];
7 defvar IntList = [0, 1, 2, 3, 4, 5, 6, 7];
8 defvar BitsList = [ {0, 1, 0}, {1, 1, 1}, {0, 0, 1} ];
9 defvar BitList = [0, 1, 1, 0, 1]<bit>;
11 class Ishify<list<string> words> {
12 list<string> ret = !foreach(w, words, w # "ify");
17 // CHECK: Test2 = "hello";
18 // CHECK: Test3 = "foobarzoosnorkquux";
19 // CHECK: Test4 = "foo, bar, zoo, snork, quux";
20 // CHECK: Test5 = "foo & bar & zoo & snork & quux & grits";
23 string Test1 = !interleave(EmptyList, "/");
24 string Test2 = !interleave(OneList, ":");
25 string Test3 = !interleave(StringList, "");
26 string Test4 = !interleave(StringList, ", ");
27 string Test5 = !interleave(!listconcat(StringList, ["grits"]), " & ");
31 // CHECK: Test1 = "01234567";
32 // CHECK: Test2 = "0, 1, 2, 3, 4, 5, 6, 7";
33 // CHECK: Test3 = "0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 42";
36 string Test1 = !interleave(IntList, "");
37 string Test2 = !interleave(IntList, ", ");
38 string Test3 = !interleave(!listconcat(IntList, [42]), " & ");
42 // CHECK: Test1 = "271";
43 // CHECK: Test2 = "2, 7, 1";
44 // CHECK: Test3 = "2 & 7 & 1 & 0";
47 string Test1 = !interleave(BitsList, "");
48 string Test2 = !interleave(BitsList, ", ");
49 string Test3 = !interleave(!listconcat(BitsList, [ {0, 0, 0} ]), " & ");
53 // CHECK: Test1 = "01101";
54 // CHECK: Test2 = "0, 1, 1, 0, 1";
55 // CHECK: Test3 = "0 and 1 and 1 and 0 and 1 and 1";
58 string Test1 = !interleave(BitList, "");
59 string Test2 = !interleave(BitList, ", ");
60 string Test3 = !interleave(!listconcat(BitList, [1]), " and ");
64 // CHECK: Colors = ["red", "green", "yellow"];
65 // CHECK: ColorList = "redify, greenify, yellowify";
68 list<string> Colors = ["red", "green", "yellow"];
69 string ColorList = !interleave(Ishify<Colors>.ret, ", ");
73 // CHECK: code OperatorList = [{+, -, *, /, ?:, ;}];
76 list<string> Operators = ["+", "-", "*", "/", "?:"];
77 code OperatorList = !interleave(!listconcat(Operators, [[{;}]]), ", ");
81 // CHECK: str = "foo/bar/zoo";
85 string zoo = "oops, not zoo";
86 string str = !interleave([foo, "bar", zoo], "/");
93 // ERROR1: expected list of string, int, bits, or bit; got value of type
96 string Bad = !interleave([(op), (op "hello")], " = ");