1 // RUN: llvm-tblgen -gen-searchable-tables -I %p/../../include %s | FileCheck %s
4 include "llvm/TableGen/SearchableTable.td"
6 // CHECK-LABEL: GET_BValues_DECL
7 // CHECK: enum BValues {
8 // CHECK: BAlice = 172,
10 // CHECK: BCharlie = 128,
14 // CHECK-LABEL: GET_CEnum_DECL
15 // CHECK: enum CEnum {
21 // CHECK-LABEL: GET_ATable_DECL
22 // CHECK: const AEntry *lookupATableByValues(uint8_t Val1, uint16_t Val2);
24 // CHECK-LABEL: GET_ATable_IMPL
25 // CHECK: const AEntry ATable[] = {
32 // CHECK: const AEntry *lookupATableByValues(uint8_t Val1, uint16_t Val2) {
33 // CHECK: return &*Idx;
36 class AEntry<string str, int val1, int val2> {
42 def : AEntry<"bar", 5, 3>;
43 def : AEntry<"baz", 2, 6>;
44 def : AEntry<"foo", 4, 4>;
45 def : AEntry<"foobar", 4, 5>;
47 def ATable : GenericTable {
48 let FilterClass = "AEntry";
49 let Fields = ["Str", "Val1", "Val2"];
51 let PrimaryKey = ["Val1", "Val2"];
52 let PrimaryKeyName = "lookupATableByValues";
56 // CHECK-LABEL: GET_BTable_IMPL
57 // CHECK: const BTypeName *lookupBTableByName(StringRef Name) {
58 // CHECK: return &BTable[Idx->_index];
61 class BEntry<bits<16> enc> {
63 bits<16> Encoding = enc;
66 def BAlice : BEntry<0xac>;
67 def BBob : BEntry<0x14>;
68 def BCharlie : BEntry<0x80>;
69 def BEve : BEntry<0x4c>;
71 def BValues : GenericEnum {
72 let FilterClass = "BEntry";
73 let NameField = "Name";
74 let ValueField = "Encoding";
77 def BTable : GenericTable {
78 let FilterClass = "BEntry";
79 string CppTypeName = "BTypeName";
80 let Fields = ["Name", "Encoding"];
83 def lookupBTableByName : SearchIndex {
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;
98 // CHECK: const CEntry *lookupCEntry(StringRef Name, unsigned Kind) {
100 // CHECK: { "ALICE", CBar, 1 },
101 // CHECK: { "ALICE", CFoo, 0 },
102 // CHECK: { "BOB", CBaz, 2 },
110 def CEnum : GenericEnum {
111 let FilterClass = "CEnum";
114 class CEntry<string name, CEnum kind, int enc> {
117 bits<16> Encoding = enc;
120 def : CEntry<"alice", CFoo, 10>;
121 def : CEntry<"alice", CBar, 13>;
122 def : CEntry<"bob", CBaz, 15>;
124 def CTable : GenericTable {
125 let FilterClass = "CEntry";
126 let Fields = ["Name", "Kind", "Encoding"];
128 GenericEnum TypeOf_Kind = CEnum;
130 let PrimaryKey = ["Encoding"];
131 let PrimaryKeyName = "lookupCEntryByEncoding";
132 let PrimaryKeyEarlyOut = 1;
135 def lookupCEntry : SearchIndex {
137 let Key = ["Name", "Kind"];