82 lines · plain
1// RUN: llvm-tblgen %s | FileCheck %s2// RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s3 4defvar claim = "This is the end of the world!";5 6// CHECK: def Rec17// 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!";13 14def Rec1 {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));21}22 23// CHECK: def Rec2 {24// CHECK: lastName = "Flintstone";25 26def Rec2 {27 string firstName = "Fred";28 string name = firstName # " " # "Flintstone";29 string lastName = !substr(name, !add(!size(firstName), 1));30}31 32// CHECK: def Rec3 {33// CHECK: test1 = "";34// CHECK: test2 = "";35// CHECK: test3 = "";36// CHECK: test4 = "h";37// CHECK: test5 = "hello";38// CHECK: test6 = "";39 40def Rec3 {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);47}48 49// CHECK: def Rec450// CHECK: message = "This is the end of the world!";51// CHECK: messagePrefix = "This is th...";52// CHECK: warning = "Bad message: 'This is th...'";53 54class C<string msg> {55 string message = msg;56 string messagePrefix = !substr(message, 0, 10) # "...";57}58 59def Rec4 : C<claim> {60 string warning = "Bad message: '" # messagePrefix # "'";61}62 63#ifdef ERROR164 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: 3069// ERROR1: !substr length must be nonnegative70 71def Rec8 {72 string claim1 = !substr(42, 0, 3);73 string claim2 = !substr(claim, 0b101);74 string claim3 = !substr(claim, 0, "oops");75}76 77def Rec9 {78 string claim1 = !substr(claim, !add(!size(claim), 1));79 string claim2 = !substr(claim, 0, -13);80}81#endif82