xref: /llvm-project/llvm/test/TableGen/find.td (revision 952c6ddd8b32a0dc4a65147e20999428191950f0)
1// RUN: llvm-tblgen %s | FileCheck %s
2// RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
3
4// This file contains tests for the !find bang operator.
5
6defvar Sentence = "This is the end of the world.";
7
8// CHECK: def Rec01
9// CHECK-NEXT:   int FirstThe = 8
10// CHECK-NEXT:   int SameThe = 8
11// CHECK-NEXT:   int SecondThe = 19
12// CHECK-NEXT:   int ThirdThe = -1
13
14def Rec01 {
15  int FirstThe = !find(Sentence, "the");
16  int SameThe = !find(Sentence, "the", FirstThe);
17  int SecondThe = !find(Sentence, "the", !add(FirstThe, 1));
18  int ThirdThe = !find(Sentence, "the", !add(SecondThe, 1));
19}
20
21class C1<string name> {
22  string Name = name;
23  bit IsJr = !ne(!find(name, "Jr"), -1);
24}
25
26// CHECK: def Rec02
27// CHECK-NEXT:   string Name = "Sally Smith"
28// CHECK-NEXT:   bit IsJr = 0
29// CHECK: def Rec03
30// CHECK-NEXT:   string Name = "Fred Jones, Jr."
31// CHECK-NEXT:   bit IsJr = 1
32
33def Rec02 : C1<"Sally Smith">;
34def Rec03 : C1<"Fred Jones, Jr.">;
35
36// CHECK: def Rec04
37// CHECK-NEXT:   int ThisPos = 0
38// CHECK-NEXT:   int WorldPos = 23
39// CHECK-NEXT:   int TooLong = -1
40
41def Rec04 {
42  int ThisPos = !find(Sentence, "This");
43  int WorldPos = !find(Sentence, "world.");
44  int TooLong = !find(Sentence, "world.country");
45}
46
47// CHECK: def Rec05
48// CHECK-NEXT:   string Name = "Pat Snork"
49// CHECK-NEXT:   bit IsJr = 0
50// CHECK-NEXT:   bit JrOrSnork = 1
51
52def Rec05 : C1<"Pat Snork"> {
53  bit JrOrSnork = !or(IsJr, !ne(!find(Name, "Snork"), -1));
54}
55
56#ifdef ERROR1
57
58// ERROR1: !find start position is out of range 0...29: 100
59
60def Rec06 {
61  int Test1 = !find(Sentence, "the", 100);
62}
63#endif
64
65