llvm.org GIT mirror llvm / 6786d5e
Add an !eq() operator to TableGen. It operates on strings only. Use !cast<string>() to compare other types of objects. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92754 91177308-0d34-0410-b5e6-96231b3b80d8 David Greene 9 years ago
7 changed file(s) with 37 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
422422
An integer {0,1} indicating whether list 'a' is empty.
423423
!if(a,b,c)
424424
'b' if the result of integer operator 'a' is nonzero, 'c' otherwise.
425
!eq(a,b)
426
Integer one if string a is equal to string b, zero otherwise. This
427 only operates on string objects. Use !cast to compare other
428 types of objects.
425429
426430
427431

Note that all of the values have rules specifying how they convert to values

0 // RUN: tblgen %s | FileCheck %s
1 // CHECK: Value = 0
2 // CHECK: Value = 1
3
4 class Base {
5 int Value = V;
6 }
7
8 class Derived :
9 Base;
10
11 def TRUE : Derived<"true">;
12 def FALSE : Derived<"false">;
729729 }
730730 break;
731731 }
732 case EQ: {
733 // Make sure we've resolved
734 StringInit *LHSs = dynamic_cast(LHS);
735 StringInit *RHSs = dynamic_cast(RHS);
736 if (LHSs && RHSs)
737 return new IntInit(LHSs->getValue() == RHSs->getValue());
738
739 break;
740 }
732741 case SHL:
733742 case SRA:
734743 case SRL: {
767776 case SHL: Result = "!shl"; break;
768777 case SRA: Result = "!sra"; break;
769778 case SRL: Result = "!srl"; break;
779 case EQ: Result = "!eq"; break;
770780 case STRCONCAT: Result = "!strconcat"; break;
771781 case NAMECONCAT:
772782 Result = "!nameconcat<" + getType()->getAsString() + ">"; break;
841841 ///
842842 class BinOpInit : public OpInit {
843843 public:
844 enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, NAMECONCAT };
844 enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, NAMECONCAT, EQ };
845845 private:
846846 BinaryOp Opc;
847847 Init *LHS, *RHS;
433433 if (Len == 3 && !memcmp(Start, "sra", 3)) return tgtok::XSRA;
434434 if (Len == 3 && !memcmp(Start, "srl", 3)) return tgtok::XSRL;
435435 if (Len == 3 && !memcmp(Start, "shl", 3)) return tgtok::XSHL;
436 if (Len == 2 && !memcmp(Start, "eq", 2)) return tgtok::XEq;
436437 if (Len == 9 && !memcmp(Start, "strconcat", 9)) return tgtok::XStrConcat;
437438 if (Len == 10 && !memcmp(Start, "nameconcat", 10)) return tgtok::XNameConcat;
438439 if (Len == 5 && !memcmp(Start, "subst", 5)) return tgtok::XSubst;
4444
4545 // !keywords.
4646 XConcat, XSRA, XSRL, XSHL, XStrConcat, XNameConcat, XCast, XSubst,
47 XForEach, XCar, XCdr, XNull, XIf,
47 XForEach, XCar, XCdr, XNull, XIf, XEq,
4848
4949 // Integer value.
5050 IntVal,
791791 case tgtok::XSRA:
792792 case tgtok::XSRL:
793793 case tgtok::XSHL:
794 case tgtok::XEq:
794795 case tgtok::XStrConcat:
795796 case tgtok::XNameConcat: { // Value ::= !binop '(' Value ',' Value ')'
796797 BinOpInit::BinaryOp Code;
819820 Code = BinOpInit::SHL;
820821 Type = new IntRecTy();
821822 break;
823 case tgtok::XEq:
824 Lex.Lex(); // eat the operation
825 Code = BinOpInit::EQ;
826 Type = new IntRecTy();
827 break;
822828 case tgtok::XStrConcat:
823829 Lex.Lex(); // eat the operation
824830 Code = BinOpInit::STRCONCAT;
12561262 case tgtok::XSRA:
12571263 case tgtok::XSRL:
12581264 case tgtok::XSHL:
1265 case tgtok::XEq:
12591266 case tgtok::XStrConcat:
12601267 case tgtok::XNameConcat: // Value ::= !binop '(' Value ',' Value ')'
12611268 case tgtok::XIf: