1 // RUN: llvm-tblgen -gen-searchable-tables -I %p/../../include %s | FileCheck %s
2 // RUN: not llvm-tblgen -gen-searchable-tables -I %p/../../include -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s
5 include "llvm/TableGen/SearchableTable.td"
7 // CHECK-LABEL: GET_BValues_DECL
8 // CHECK: enum BValues {
9 // CHECK: BAlice = 172,
11 // CHECK: BCharlie = 128,
15 // CHECK-LABEL: GET_CEnum_DECL
16 // CHECK: enum CEnum {
22 // CHECK-LABEL: GET_ATable_DECL
23 // CHECK: const AEntry *lookupATableByValues(uint8_t Val1, uint16_t Val2);
25 // CHECK-LABEL: GET_ATable_IMPL
26 // CHECK: constexpr AEntry ATable[] = {
33 // CHECK: const AEntry *lookupATableByValues(uint8_t Val1, uint16_t Val2) {
34 // CHECK: return &*Idx;
37 class AEntry<string str, int val1, int val2> {
43 def : AEntry<"bar", 5, 3>;
44 def : AEntry<"baz", 2, 6>;
45 def : AEntry<"foo", 4, 4>;
46 def : AEntry<"foobar", 4, 5>;
48 def ATable : GenericTable {
49 let FilterClass = "AEntry";
50 let Fields = ["Str", "Val1", "Val2"];
52 let PrimaryKey = ["Val1", "Val2"];
53 let PrimaryKeyName = "lookupATableByValues";
57 // CHECK-LABEL: GET_BTable_IMPL
58 // CHECK: constexpr BTypeName BTable[] = {
59 // CHECK: { "BAlice", 0xAC, },
60 // CHECK: { "BBob", 0x14, Bob == 13 },
61 // CHECK: { "BCharlie", 0x80, Charlie == 42 },
62 // CHECK: { "BEve", 0x4C, Eve == 108 },
64 // CHECK: const BTypeName *lookupBTableByName(StringRef Name) {
65 // CHECK: return &BTable[Idx->_index];
68 class BEntry<bits<16> enc, code test = [{}]> {
70 bits<16> Encoding = enc;
74 def BAlice : BEntry<0xac>;
75 def BBob : BEntry<0x14, [{Bob == 13}]>;
76 def BCharlie : BEntry<0x80, "Charlie == 42">;
77 def BEve : BEntry<0x4c, [{Eve == }] # 108>;
79 def BValues : GenericEnum {
80 let FilterClass = "BEntry";
81 let NameField = "Name";
82 let ValueField = "Encoding";
85 def BTable : GenericTable {
86 let FilterClass = "BEntry";
87 string CppTypeName = "BTypeName";
88 let Fields = ["Name", "Encoding", "Test"];
89 string TypeOf_Test = "code";
92 def lookupBTableByName : SearchIndex {
98 // CHECK-LABEL: GET_CTable_DECL
99 // CHECK: const CEntry *lookupCEntryByEncoding(uint16_t Encoding);
100 // CHECK: const CEntry *lookupCEntry(StringRef Name, unsigned Kind);
101 // CHECK-LABEL: GET_CTable_IMPL
102 // CHECK: const CEntry *lookupCEntryByEncoding(uint16_t Encoding) {
103 // CHECK: if ((Encoding < 0xA) ||
104 // CHECK: (Encoding > 0xF))
105 // CHECK: return nullptr;
107 // CHECK: const CEntry *lookupCEntry(StringRef Name, unsigned Kind) {
108 // CHECK: Index[] = {
109 // CHECK: { "ALICE", CBar, 1 },
110 // CHECK: { "ALICE", CFoo, 0 },
111 // CHECK: { "BOB", CBaz, 2 },
119 def CEnum : GenericEnum {
120 let FilterClass = "CEnum";
123 class CEntry<string name, CEnum kind, int enc> {
126 bits<16> Encoding = enc;
129 def : CEntry<"alice", CFoo, 10>;
130 def : CEntry<"alice", CBar, 13>;
131 def : CEntry<"bob", CBaz, 15>;
133 def CTable : GenericTable {
134 let FilterClass = "CEntry";
135 let Fields = ["Name", "Kind", "Encoding"];
137 string TypeOf_Kind = "CEnum";
139 let PrimaryKey = ["Encoding"];
140 let PrimaryKeyName = "lookupCEntryByEncoding";
141 let PrimaryKeyEarlyOut = 1;
144 def lookupCEntry : SearchIndex {
146 let Key = ["Name", "Kind"];
151 class DEntry<string str, int val1> {
156 def DFoo : DEntry<"foo", 1>;
157 // ERROR1: [[@LINE+1]]:1: error: Record 'DBar' for table 'DTable' is missing field 'Val1'
158 def DBar : DEntry<"bar", ?>;
160 def DTable : GenericTable {
161 let FilterClass = "DEntry";
162 let Fields = ["Str", "Val1"];