diff options
author | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2010-06-16 23:24:12 +0000 |
---|---|---|
committer | Bruno Cardoso Lopes <bruno.cardoso@gmail.com> | 2010-06-16 23:24:12 +0000 |
commit | e87de41189b1591afd88e4dc12eeb17e06b77d3e (patch) | |
tree | 31621b77739ec01945f812c060d5e52df8ba5bee | |
parent | d0e8469ba65c54b593df15b7249d7fe12097c4cf (diff) | |
download | external_llvm-e87de41189b1591afd88e4dc12eeb17e06b77d3e.zip external_llvm-e87de41189b1591afd88e4dc12eeb17e06b77d3e.tar.gz external_llvm-e87de41189b1591afd88e4dc12eeb17e06b77d3e.tar.bz2 |
let the '!eq' expression support 'int' and 'bit' types
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@106171 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | docs/TableGenFundamentals.html | 4 | ||||
-rw-r--r-- | test/TableGen/eqbit.td | 11 | ||||
-rw-r--r-- | utils/TableGen/Record.cpp | 13 |
3 files changed, 25 insertions, 3 deletions
diff --git a/docs/TableGenFundamentals.html b/docs/TableGenFundamentals.html index e504a89..3410cac 100644 --- a/docs/TableGenFundamentals.html +++ b/docs/TableGenFundamentals.html @@ -425,8 +425,8 @@ class. This operation is analogous to $(foreach) in GNU make.</dd> <dd>'b' if the result of integer operator 'a' is nonzero, 'c' otherwise.</dd> <dt><tt>!eq(a,b)</tt></dt> <dd>Integer one if string a is equal to string b, zero otherwise. This - only operates on string objects. Use !cast<string> to compare other - types of objects.</dd> + only operates on string, int and bit objects. Use !cast<string> to + compare other types of objects.</dd> </dl> <p>Note that all of the values have rules specifying how they convert to values diff --git a/test/TableGen/eqbit.td b/test/TableGen/eqbit.td new file mode 100644 index 0000000..3953252 --- /dev/null +++ b/test/TableGen/eqbit.td @@ -0,0 +1,11 @@ +// RUN: tblgen %s | FileCheck %s +// XFAIL: vg_leak +// CHECK: a = 6 +// CHECK: a = 5 + +class A<bit b = 1> { + int a = !if(!eq(b, 1), 5, 6); +} + +def X : A<0>; +def Y : A; diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index 4f9f604..d9c5dd3 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -721,9 +721,20 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) { break; } case EQ: { - // Make sure we've resolved + // try to fold eq comparison for 'bit' and 'int', otherwise fallback + // to string objects. + IntInit* L = + dynamic_cast<IntInit*>(LHS->convertInitializerTo(new IntRecTy())); + IntInit* R = + dynamic_cast<IntInit*>(RHS->convertInitializerTo(new IntRecTy())); + + if (L && R) + return new IntInit(L->getValue() == R->getValue()); + StringInit *LHSs = dynamic_cast<StringInit*>(LHS); StringInit *RHSs = dynamic_cast<StringInit*>(RHS); + + // Make sure we've resolved if (LHSs && RHSs) return new IntInit(LHSs->getValue() == RHSs->getValue()); |