Mercurial > hg > CbC > CbC_llvm
comparison llvm/test/TableGen/substr.td @ 207:2e18cbf3894f
LLVM12
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 08 Jun 2021 06:07:14 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
173:0572611fdcc8 | 207:2e18cbf3894f |
---|---|
1 // RUN: llvm-tblgen %s | FileCheck %s | |
2 // RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s | |
3 | |
4 defvar claim = "This is the end of the world!"; | |
5 | |
6 // CHECK: def Rec1 | |
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!"; | |
13 | |
14 def 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 | |
26 def 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 | |
40 def 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 Rec4 | |
50 // CHECK: message = "This is the end of the world!"; | |
51 // CHECK: messagePrefix = "This is th..."; | |
52 // CHECK: warning = "Bad message: 'This is th...'"; | |
53 | |
54 class C<string msg> { | |
55 string message = msg; | |
56 string messagePrefix = !substr(message, 0, 10) # "..."; | |
57 } | |
58 | |
59 def Rec4 : C<claim> { | |
60 string warning = "Bad message: '" # messagePrefix # "'"; | |
61 } | |
62 | |
63 #ifdef ERROR1 | |
64 | |
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 | |
70 | |
71 def Rec8 { | |
72 string claim1 = !substr(42, 0, 3); | |
73 string claim2 = !substr(claim, 0b101); | |
74 string claim3 = !substr(claim, 0, "oops"); | |
75 } | |
76 | |
77 def Rec9 { | |
78 string claim1 = !substr(claim, !add(!size(claim), 1)); | |
79 string claim2 = !substr(claim, 0, -13); | |
80 } | |
81 #endif |