diff --git a/docs/TableGenFundamentals.html b/docs/TableGenFundamentals.html index ade4bf67df5..457bb62060d 100644 --- a/docs/TableGenFundamentals.html +++ b/docs/TableGenFundamentals.html @@ -423,6 +423,10 @@ class. This operation is analogous to $(foreach) in GNU make.
An integer {0,1} indicating whether list 'a' is empty.
!if(a,b,c)
'b' if the result of integer operator 'a' is nonzero, 'c' otherwise.
+
!eq(a,b)
+
Integer one if string a is equal to string b, zero otherwise. This + only operates on string objects. Use !cast to compare other + types of objects.

Note that all of the values have rules specifying how they convert to values diff --git a/test/TableGen/eq.td b/test/TableGen/eq.td new file mode 100644 index 00000000000..8ba6d7ec833 --- /dev/null +++ b/test/TableGen/eq.td @@ -0,0 +1,13 @@ +// RUN: tblgen %s | FileCheck %s +// CHECK: Value = 0 +// CHECK: Value = 1 + +class Base { + int Value = V; +} + +class Derived : + Base; + +def TRUE : Derived<"true">; +def FALSE : Derived<"false">; diff --git a/utils/TableGen/Record.cpp b/utils/TableGen/Record.cpp index 542735e88b4..f9e2fe8a397 100644 --- a/utils/TableGen/Record.cpp +++ b/utils/TableGen/Record.cpp @@ -730,6 +730,15 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) { } break; } + case EQ: { + // Make sure we've resolved + StringInit *LHSs = dynamic_cast(LHS); + StringInit *RHSs = dynamic_cast(RHS); + if (LHSs && RHSs) + return new IntInit(LHSs->getValue() == RHSs->getValue()); + + break; + } case SHL: case SRA: case SRL: { @@ -768,6 +777,7 @@ std::string BinOpInit::getAsString() const { case SHL: Result = "!shl"; break; case SRA: Result = "!sra"; break; case SRL: Result = "!srl"; break; + case EQ: Result = "!eq"; break; case STRCONCAT: Result = "!strconcat"; break; case NAMECONCAT: Result = "!nameconcat<" + getType()->getAsString() + ">"; break; diff --git a/utils/TableGen/Record.h b/utils/TableGen/Record.h index 278c349dd65..45f3072ff0d 100644 --- a/utils/TableGen/Record.h +++ b/utils/TableGen/Record.h @@ -842,7 +842,7 @@ public: /// class BinOpInit : public OpInit { public: - enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, NAMECONCAT }; + enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, NAMECONCAT, EQ }; private: BinaryOp Opc; Init *LHS, *RHS; diff --git a/utils/TableGen/TGLexer.cpp b/utils/TableGen/TGLexer.cpp index 4498e305b02..2c7becc7182 100644 --- a/utils/TableGen/TGLexer.cpp +++ b/utils/TableGen/TGLexer.cpp @@ -434,6 +434,7 @@ tgtok::TokKind TGLexer::LexExclaim() { if (Len == 3 && !memcmp(Start, "sra", 3)) return tgtok::XSRA; if (Len == 3 && !memcmp(Start, "srl", 3)) return tgtok::XSRL; if (Len == 3 && !memcmp(Start, "shl", 3)) return tgtok::XSHL; + if (Len == 2 && !memcmp(Start, "eq", 2)) return tgtok::XEq; if (Len == 9 && !memcmp(Start, "strconcat", 9)) return tgtok::XStrConcat; if (Len == 10 && !memcmp(Start, "nameconcat", 10)) return tgtok::XNameConcat; if (Len == 5 && !memcmp(Start, "subst", 5)) return tgtok::XSubst; diff --git a/utils/TableGen/TGLexer.h b/utils/TableGen/TGLexer.h index 679020880dd..835f351d3d0 100644 --- a/utils/TableGen/TGLexer.h +++ b/utils/TableGen/TGLexer.h @@ -45,7 +45,7 @@ namespace tgtok { // !keywords. XConcat, XSRA, XSRL, XSHL, XStrConcat, XNameConcat, XCast, XSubst, - XForEach, XCar, XCdr, XNull, XIf, + XForEach, XCar, XCdr, XNull, XIf, XEq, // Integer value. IntVal, diff --git a/utils/TableGen/TGParser.cpp b/utils/TableGen/TGParser.cpp index b095a6c3014..8c158e0e4ee 100644 --- a/utils/TableGen/TGParser.cpp +++ b/utils/TableGen/TGParser.cpp @@ -792,6 +792,7 @@ Init *TGParser::ParseOperation(Record *CurRec) { case tgtok::XSRA: case tgtok::XSRL: case tgtok::XSHL: + case tgtok::XEq: case tgtok::XStrConcat: case tgtok::XNameConcat: { // Value ::= !binop '(' Value ',' Value ')' BinOpInit::BinaryOp Code; @@ -820,6 +821,11 @@ Init *TGParser::ParseOperation(Record *CurRec) { Code = BinOpInit::SHL; Type = new IntRecTy(); break; + case tgtok::XEq: + Lex.Lex(); // eat the operation + Code = BinOpInit::EQ; + Type = new IntRecTy(); + break; case tgtok::XStrConcat: Lex.Lex(); // eat the operation Code = BinOpInit::STRCONCAT; @@ -1257,6 +1263,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) { case tgtok::XSRA: case tgtok::XSRL: case tgtok::XSHL: + case tgtok::XEq: case tgtok::XStrConcat: case tgtok::XNameConcat: // Value ::= !binop '(' Value ',' Value ')' case tgtok::XIf: