1 // RUN: llvm-tblgen -gen-searchable-tables -I %p/../../include %s | FileCheck %s 2 // XFAIL: vg_leak 3 4 include "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 36 class AEntry<string str, int val1, int val2> { 37 string Str = str; 38 bits<8> Val1 = val1; 39 bits<10> Val2 = val2; 40 } 41 42 def : AEntry<"bar", 5, 3>; 43 def : AEntry<"baz", 2, 6>; 44 def : AEntry<"foo", 4, 4>; 45 def : AEntry<"foobar", 4, 5>; 46 47 def 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 61 class BEntry<bits<16> enc> { 62 string Name = NAME; 63 bits<16> Encoding = enc; 64 } 65 66 def BAlice : BEntry<0xac>; 67 def BBob : BEntry<0x14>; 68 def BCharlie : BEntry<0x80>; 69 def BEve : BEntry<0x4c>; 70 71 def BValues : GenericEnum { 72 let FilterClass = "BEntry"; 73 let NameField = "Name"; 74 let ValueField = "Encoding"; 75 } 76 77 def BTable : GenericTable { 78 let FilterClass = "BEntry"; 79 string CppTypeName = "BTypeName"; 80 let Fields = ["Name", "Encoding"]; 81 } 82 83 def 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 104 class CEnum; 105 106 def CFoo : CEnum; 107 def CBar : CEnum; 108 def CBaz : CEnum; 109 110 def CEnum : GenericEnum { 111 let FilterClass = "CEnum"; 112 } 113 114 class CEntry<string name, CEnum kind, int enc> { 115 string Name = name; 116 CEnum Kind = kind; 117 bits<16> Encoding = enc; 118 } 119 120 def : CEntry<"alice", CFoo, 10>; 121 def : CEntry<"alice", CBar, 13>; 122 def : CEntry<"bob", CBaz, 15>; 123 124 def 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 135 def lookupCEntry : SearchIndex { 136 let Table = CTable; 137 let Key = ["Name", "Kind"]; 138 } 139