1 // RUN: llvm-tblgen %s | FileCheck %s
2 // RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
4 defvar claim = "This is the end of the world!";
7 // CHECK: fullNoLength = "This is the end of the world!";
8 // CHECK: fullLength = "This is the end of the world!";
9 // CHECK: thisIsTheEnd = "This is the end";
10 // CHECK: DoorsSong = "the end";
11 // CHECK: finalNoLength = "end of the world!";
12 // CHECK: finalLength = "end of the world!";
15 string fullNoLength = !substr(claim, 0);
16 string fullLength = !substr(claim, 0, 999);
17 string thisIsTheEnd = !substr(claim, 0, 15);
18 string DoorsSong = !substr(claim, 8, 7);
19 string finalNoLength = !substr(claim, 12);
20 string finalLength = !substr(claim, 12, !sub(!size(claim), 12));
24 // CHECK: lastName = "Flintstone";
27 string firstName = "Fred";
28 string name = firstName # " " # "Flintstone";
29 string lastName = !substr(name, !add(!size(firstName), 1));
36 // CHECK: test4 = "h";
37 // CHECK: test5 = "hello";
41 string test1 = !substr("", 0, 0);
42 string test2 = !substr("", 0, 9);
43 string test3 = !substr("hello", 0, 0);
44 string test4 = !substr("hello", 0, 1);
45 string test5 = !substr("hello", 0, 99);
46 string test6 = !substr("hello", 5, 99);
50 // CHECK: message = "This is the end of the world!";
51 // CHECK: messagePrefix = "This is th...";
52 // CHECK: warning = "Bad message: 'This is th...'";
56 string messagePrefix = !substr(message, 0, 10) # "...";
60 string warning = "Bad message: '" # messagePrefix # "'";
65 // ERROR1: expected string, got type 'int'
66 // ERROR1: expected int, got type 'bits<3>'
67 // ERROR1: expected int, got type 'string'
68 // ERROR1: !substr start position is out of range 0...29: 30
69 // ERROR1: !substr length must be nonnegative
72 string claim1 = !substr(42, 0, 3);
73 string claim2 = !substr(claim, 0b101);
74 string claim3 = !substr(claim, 0, "oops");
78 string claim1 = !substr(claim, !add(!size(claim), 1));
79 string claim2 = !substr(claim, 0, -13);