blob: 06e75c5067dd45e48c1f0a2bb95be793f734b289 [file] [log] [blame]
Nicolai Haehnle2b1cd512018-06-21 13:36:22 +00001// RUN: llvm-tblgen -gen-searchable-tables -I %p/../../include %s | FileCheck %s
2// XFAIL: vg_leak
3
4include "llvm/TableGen/SearchableTable.td"
5
6// CHECK-LABEL: GET_BValues_DECL
7// CHECK: enum BValues {
8// CHECK: BAlice = 172,
9// CHECK: BBob = 20,
10// CHECK: BCharlie = 128,
11// CHECK: BEve = 76,
12// CHECK: }
13
14// CHECK-LABEL: GET_CEnum_DECL
15// CHECK: enum CEnum {
16// CHECK: CBar
17// CHECK: CBaz
18// CHECK: CFoo
19// CHECK: }
20
21// CHECK-LABEL: GET_ATable_DECL
22// CHECK: const AEntry *lookupATableByValues(uint8_t Val1, uint16_t Val2);
23
24// CHECK-LABEL: GET_ATable_IMPL
25// CHECK: const AEntry ATable[] = {
26// CHECK: { "baz"
27// CHECK: { "foo"
28// CHECK: { "foobar"
29// CHECK: { "bar"
30// CHECK: };
31
32// CHECK: const AEntry *lookupATableByValues(uint8_t Val1, uint16_t Val2) {
33// CHECK: return &*Idx;
34// CHECK: }
35
36class AEntry<string str, int val1, int val2> {
37 string Str = str;
38 bits<8> Val1 = val1;
39 bits<10> Val2 = val2;
40}
41
42def : AEntry<"bar", 5, 3>;
43def : AEntry<"baz", 2, 6>;
44def : AEntry<"foo", 4, 4>;
45def : AEntry<"foobar", 4, 5>;
46
47def ATable : GenericTable {
48 let FilterClass = "AEntry";
49 let Fields = ["Str", "Val1", "Val2"];
50
51 let PrimaryKey = ["Val1", "Val2"];
52 let PrimaryKeyName = "lookupATableByValues";
53}
54
55
56// CHECK-LABEL: GET_BTable_IMPL
57// CHECK: const BTypeName *lookupBTableByName(StringRef Name) {
58// CHECK: return &BTable[Idx->_index];
59// CHECK: }
60
61class BEntry<bits<16> enc> {
62 string Name = NAME;
63 bits<16> Encoding = enc;
64}
65
66def BAlice : BEntry<0xac>;
67def BBob : BEntry<0x14>;
68def BCharlie : BEntry<0x80>;
69def BEve : BEntry<0x4c>;
70
71def BValues : GenericEnum {
72 let FilterClass = "BEntry";
73 let NameField = "Name";
74 let ValueField = "Encoding";
75}
76
77def BTable : GenericTable {
78 let FilterClass = "BEntry";
79 string CppTypeName = "BTypeName";
80 let Fields = ["Name", "Encoding"];
81}
82
83def lookupBTableByName : SearchIndex {
84 let Table = BTable;
85 let Key = ["Name"];
86}
87
88
89// CHECK-LABEL: GET_CTable_DECL
90// CHECK: const CEntry *lookupCEntryByEncoding(uint16_t Encoding);
91// CHECK: const CEntry *lookupCEntry(StringRef Name, unsigned Kind);
92// CHECK-LABEL: GET_CTable_IMPL
93// CHECK: const CEntry *lookupCEntryByEncoding(uint16_t Encoding) {
94// CHECK: if ((Encoding < 0xA) ||
95// CHECK: (Encoding > 0xF))
96// CHECK: return nullptr;
97
98// CHECK: const CEntry *lookupCEntry(StringRef Name, unsigned Kind) {
99// CHECK: Index[] = {
100// CHECK: { "ALICE", CBar, 1 },
101// CHECK: { "ALICE", CFoo, 0 },
102// CHECK: { "BOB", CBaz, 2 },
103
104class CEnum;
105
106def CFoo : CEnum;
107def CBar : CEnum;
108def CBaz : CEnum;
109
110def CEnum : GenericEnum {
111 let FilterClass = "CEnum";
112}
113
114class CEntry<string name, CEnum kind, int enc> {
115 string Name = name;
116 CEnum Kind = kind;
117 bits<16> Encoding = enc;
118}
119
120def : CEntry<"alice", CFoo, 10>;
121def : CEntry<"alice", CBar, 13>;
122def : CEntry<"bob", CBaz, 15>;
123
124def CTable : GenericTable {
125 let FilterClass = "CEntry";
126 let Fields = ["Name", "Kind", "Encoding"];
127
128 GenericEnum TypeOf_Kind = CEnum;
129
130 let PrimaryKey = ["Encoding"];
131 let PrimaryKeyName = "lookupCEntryByEncoding";
132 let PrimaryKeyEarlyOut = 1;
133}
134
135def lookupCEntry : SearchIndex {
136 let Table = CTable;
137 let Key = ["Name", "Kind"];
138}