[llvm-commits] [llvm] r92754 - in /llvm/trunk: docs/TableGenFundamentals.html test/TableGen/eq.td utils/TableGen/Record.cpp utils/TableGen/Record.h utils/TableGen/TGLexer.cpp utils/TableGen/TGLexer.h utils/TableGen/TGParser.cpp
David Greene
greened at obbligato.org
Tue Jan 5 11:11:42 PST 2010
Author: greened
Date: Tue Jan 5 13:11:42 2010
New Revision: 92754
URL: http://llvm.org/viewvc/llvm-project?rev=92754&view=rev
Log:
Add an !eq() operator to TableGen. It operates on strings only.
Use !cast<string>() to compare other types of objects.
Added:
llvm/trunk/test/TableGen/eq.td
Modified:
llvm/trunk/docs/TableGenFundamentals.html
llvm/trunk/utils/TableGen/Record.cpp
llvm/trunk/utils/TableGen/Record.h
llvm/trunk/utils/TableGen/TGLexer.cpp
llvm/trunk/utils/TableGen/TGLexer.h
llvm/trunk/utils/TableGen/TGParser.cpp
Modified: llvm/trunk/docs/TableGenFundamentals.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/TableGenFundamentals.html?rev=92754&r1=92753&r2=92754&view=diff
==============================================================================
--- llvm/trunk/docs/TableGenFundamentals.html (original)
+++ llvm/trunk/docs/TableGenFundamentals.html Tue Jan 5 13:11:42 2010
@@ -423,6 +423,10 @@
<dd>An integer {0,1} indicating whether list 'a' is empty.</dd>
<dt><tt>!if(a,b,c)</tt></dt>
<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>
</dl>
<p>Note that all of the values have rules specifying how they convert to values
Added: llvm/trunk/test/TableGen/eq.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/TableGen/eq.td?rev=92754&view=auto
==============================================================================
--- llvm/trunk/test/TableGen/eq.td (added)
+++ llvm/trunk/test/TableGen/eq.td Tue Jan 5 13:11:42 2010
@@ -0,0 +1,13 @@
+// RUN: tblgen %s | FileCheck %s
+// CHECK: Value = 0
+// CHECK: Value = 1
+
+class Base<int V> {
+ int Value = V;
+}
+
+class Derived<string Truth> :
+ Base<!if(!eq(Truth, "true"), 1, 0)>;
+
+def TRUE : Derived<"true">;
+def FALSE : Derived<"false">;
Modified: llvm/trunk/utils/TableGen/Record.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.cpp?rev=92754&r1=92753&r2=92754&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/Record.cpp (original)
+++ llvm/trunk/utils/TableGen/Record.cpp Tue Jan 5 13:11:42 2010
@@ -730,6 +730,15 @@
}
break;
}
+ case EQ: {
+ // Make sure we've resolved
+ StringInit *LHSs = dynamic_cast<StringInit*>(LHS);
+ StringInit *RHSs = dynamic_cast<StringInit*>(RHS);
+ if (LHSs && RHSs)
+ return new IntInit(LHSs->getValue() == RHSs->getValue());
+
+ break;
+ }
case SHL:
case SRA:
case SRL: {
@@ -768,6 +777,7 @@
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;
Modified: llvm/trunk/utils/TableGen/Record.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/Record.h?rev=92754&r1=92753&r2=92754&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/Record.h (original)
+++ llvm/trunk/utils/TableGen/Record.h Tue Jan 5 13:11:42 2010
@@ -842,7 +842,7 @@
///
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;
Modified: llvm/trunk/utils/TableGen/TGLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/TGLexer.cpp?rev=92754&r1=92753&r2=92754&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/TGLexer.cpp (original)
+++ llvm/trunk/utils/TableGen/TGLexer.cpp Tue Jan 5 13:11:42 2010
@@ -434,6 +434,7 @@
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;
Modified: llvm/trunk/utils/TableGen/TGLexer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/TGLexer.h?rev=92754&r1=92753&r2=92754&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/TGLexer.h (original)
+++ llvm/trunk/utils/TableGen/TGLexer.h Tue Jan 5 13:11:42 2010
@@ -45,7 +45,7 @@
// !keywords.
XConcat, XSRA, XSRL, XSHL, XStrConcat, XNameConcat, XCast, XSubst,
- XForEach, XCar, XCdr, XNull, XIf,
+ XForEach, XCar, XCdr, XNull, XIf, XEq,
// Integer value.
IntVal,
Modified: llvm/trunk/utils/TableGen/TGParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/TGParser.cpp?rev=92754&r1=92753&r2=92754&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/TGParser.cpp (original)
+++ llvm/trunk/utils/TableGen/TGParser.cpp Tue Jan 5 13:11:42 2010
@@ -792,6 +792,7 @@
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 @@
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 @@
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:
More information about the llvm-commits
mailing list