1// RUN: llvm-tblgen %s | FileCheck %s 2// RUN: not llvm-tblgen -DERROR1 %s 2>&1 | FileCheck --check-prefix=ERROR1 %s 3// RUN: not llvm-tblgen -DERROR2 %s 2>&1 | FileCheck --check-prefix=ERROR2 %s 4 5// This file tests the comparison bang operators. 6 7class BitCompare<bit a, bit b> { 8 list<bit> compare = [!eq(a, b), !ne(a, b), 9 !lt(a, b), !le(a, b), 10 !gt(a, b), !ge(a, b)]; 11} 12 13class BitsCompare<bits<3> a, bits<3> b> { 14 list<bit> compare = [!eq(a, b), !ne(a, b), 15 !lt(a, b), !le(a, b), 16 !gt(a, b), !ge(a, b)]; 17} 18 19class IntCompare<int a, int b> { 20 list<bit> compare = [!eq(a, b), !ne(a, b), 21 !lt(a, b), !le(a, b), 22 !gt(a, b), !ge(a, b)]; 23} 24 25class StringCompare<string a, string b> { 26 list<bit> compare = [!eq(a, b), !ne(a, b), 27 !lt(a, b), !le(a, b), 28 !gt(a, b), !ge(a, b)]; 29} 30 31multiclass MC { 32 def _MC; 33} 34 35// CHECK: def Bit00 36// CHECK: compare = [1, 0, 0, 1, 0, 1]; 37// CHECK: def Bit01 38// CHECK: compare = [0, 1, 1, 1, 0, 0]; 39// CHECK: def Bit10 40// CHECK: compare = [0, 1, 0, 0, 1, 1]; 41// CHECK: def Bit11 42// CHECK: compare = [1, 0, 0, 1, 0, 1]; 43 44def Bit00 : BitCompare<0, 0>; 45def Bit01 : BitCompare<0, 1>; 46def Bit10 : BitCompare<1, 0>; 47def Bit11 : BitCompare<1, 1>; 48 49// CHECK: def Bits1 50// CHECK: compare = [0, 1, 1, 1, 0, 0]; 51// CHECK: def Bits2 52// CHECK: compare = [1, 0, 0, 1, 0, 1]; 53// CHECK: def Bits3 54// CHECK: compare = [0, 1, 0, 0, 1, 1]; 55 56def Bits1 : BitsCompare<{0, 1, 0}, {1, 0, 1}>; 57def Bits2 : BitsCompare<{0, 1, 1}, {0, 1, 1}>; 58def Bits3 : BitsCompare<{1, 1, 1}, {0, 1, 1}>; 59 60// CHECK: def Int1 61// CHECK: compare = [0, 1, 1, 1, 0, 0]; 62// CHECK: def Int2 63// CHECK: compare = [1, 0, 0, 1, 0, 1]; 64// CHECK: def Int3 65// CHECK: compare = [0, 1, 0, 0, 1, 1]; 66 67def Int1 : IntCompare<-7, 13>; 68def Int2 : IntCompare<42, 42>; 69def Int3 : IntCompare<108, 42>; 70 71// CHECK: def Record1 72// CHECK: compare1 = [1, 0]; 73// CHECK: compare2 = [0, 1]; 74// CHECK: compare3 = [1, 1]; 75 76defm foo : MC; 77defm bar : MC; 78 79def Record1 { 80 list<bit> compare1 = [!eq(Bit00, Bit00), !eq(Bit00, Bit01)]; 81 list<bit> compare2 = [!ne(Bit00, Bit00), !ne(Bit00, Int1)]; 82 list<bit> compare3 = [!eq(bar_MC, bar_MC), !ne(bar_MC, foo_MC)]; 83} 84 85// CHECK: def String1 86// CHECK: compare = [0, 1, 1, 1, 0, 0]; 87// CHECK: def String2 88// CHECK: compare = [1, 0, 0, 1, 0, 1]; 89// CHECK: def String3 90// CHECK: compare = [0, 1, 0, 0, 1, 1]; 91// CHECK: def String4 92// CHECK: compare = [0, 1, 0, 0, 1, 1]; 93def String1 : StringCompare<"bar", "foo">; 94def String2 : StringCompare<"foo", "foo">; 95def String3 : StringCompare<"foo", "bar">; 96def String4 : StringCompare<"foo", "Foo">; 97 98#ifdef ERROR1 99 100// ERROR1: expected bit, bits, int, string, or record; got value 101 102def Zerror1 { 103 bit compare1 = !eq([0, 1, 2], [0, 1, 2]); 104} 105 106#endif 107 108#ifdef ERROR2 109 110// ERROR2: expected bit, bits, int, or string; got value 111 112def Zerror2 { 113 bit compare1 = !lt(Bit00, Bit00); 114} 115 116#endif 117 118