mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-07-08 18:30:04 +00:00
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
This commit is contained in:
parent
5f7775c85e
commit
6786d5e183
@ -423,6 +423,10 @@ class. This operation is analogous to $(foreach) in GNU make.</dd>
|
|||||||
<dd>An integer {0,1} indicating whether list 'a' is empty.</dd>
|
<dd>An integer {0,1} indicating whether list 'a' is empty.</dd>
|
||||||
<dt><tt>!if(a,b,c)</tt></dt>
|
<dt><tt>!if(a,b,c)</tt></dt>
|
||||||
<dd>'b' if the result of integer operator 'a' is nonzero, 'c' otherwise.</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>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<p>Note that all of the values have rules specifying how they convert to values
|
<p>Note that all of the values have rules specifying how they convert to values
|
||||||
|
13
test/TableGen/eq.td
Normal file
13
test/TableGen/eq.td
Normal file
@ -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">;
|
@ -730,6 +730,15 @@ Init *BinOpInit::Fold(Record *CurRec, MultiClass *CurMultiClass) {
|
|||||||
}
|
}
|
||||||
break;
|
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 SHL:
|
||||||
case SRA:
|
case SRA:
|
||||||
case SRL: {
|
case SRL: {
|
||||||
@ -768,6 +777,7 @@ std::string BinOpInit::getAsString() const {
|
|||||||
case SHL: Result = "!shl"; break;
|
case SHL: Result = "!shl"; break;
|
||||||
case SRA: Result = "!sra"; break;
|
case SRA: Result = "!sra"; break;
|
||||||
case SRL: Result = "!srl"; break;
|
case SRL: Result = "!srl"; break;
|
||||||
|
case EQ: Result = "!eq"; break;
|
||||||
case STRCONCAT: Result = "!strconcat"; break;
|
case STRCONCAT: Result = "!strconcat"; break;
|
||||||
case NAMECONCAT:
|
case NAMECONCAT:
|
||||||
Result = "!nameconcat<" + getType()->getAsString() + ">"; break;
|
Result = "!nameconcat<" + getType()->getAsString() + ">"; break;
|
||||||
|
@ -842,7 +842,7 @@ public:
|
|||||||
///
|
///
|
||||||
class BinOpInit : public OpInit {
|
class BinOpInit : public OpInit {
|
||||||
public:
|
public:
|
||||||
enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, NAMECONCAT };
|
enum BinaryOp { SHL, SRA, SRL, STRCONCAT, CONCAT, NAMECONCAT, EQ };
|
||||||
private:
|
private:
|
||||||
BinaryOp Opc;
|
BinaryOp Opc;
|
||||||
Init *LHS, *RHS;
|
Init *LHS, *RHS;
|
||||||
|
@ -434,6 +434,7 @@ tgtok::TokKind TGLexer::LexExclaim() {
|
|||||||
if (Len == 3 && !memcmp(Start, "sra", 3)) return tgtok::XSRA;
|
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, "srl", 3)) return tgtok::XSRL;
|
||||||
if (Len == 3 && !memcmp(Start, "shl", 3)) return tgtok::XSHL;
|
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 == 9 && !memcmp(Start, "strconcat", 9)) return tgtok::XStrConcat;
|
||||||
if (Len == 10 && !memcmp(Start, "nameconcat", 10)) return tgtok::XNameConcat;
|
if (Len == 10 && !memcmp(Start, "nameconcat", 10)) return tgtok::XNameConcat;
|
||||||
if (Len == 5 && !memcmp(Start, "subst", 5)) return tgtok::XSubst;
|
if (Len == 5 && !memcmp(Start, "subst", 5)) return tgtok::XSubst;
|
||||||
|
@ -45,7 +45,7 @@ namespace tgtok {
|
|||||||
|
|
||||||
// !keywords.
|
// !keywords.
|
||||||
XConcat, XSRA, XSRL, XSHL, XStrConcat, XNameConcat, XCast, XSubst,
|
XConcat, XSRA, XSRL, XSHL, XStrConcat, XNameConcat, XCast, XSubst,
|
||||||
XForEach, XCar, XCdr, XNull, XIf,
|
XForEach, XCar, XCdr, XNull, XIf, XEq,
|
||||||
|
|
||||||
// Integer value.
|
// Integer value.
|
||||||
IntVal,
|
IntVal,
|
||||||
|
@ -792,6 +792,7 @@ Init *TGParser::ParseOperation(Record *CurRec) {
|
|||||||
case tgtok::XSRA:
|
case tgtok::XSRA:
|
||||||
case tgtok::XSRL:
|
case tgtok::XSRL:
|
||||||
case tgtok::XSHL:
|
case tgtok::XSHL:
|
||||||
|
case tgtok::XEq:
|
||||||
case tgtok::XStrConcat:
|
case tgtok::XStrConcat:
|
||||||
case tgtok::XNameConcat: { // Value ::= !binop '(' Value ',' Value ')'
|
case tgtok::XNameConcat: { // Value ::= !binop '(' Value ',' Value ')'
|
||||||
BinOpInit::BinaryOp Code;
|
BinOpInit::BinaryOp Code;
|
||||||
@ -820,6 +821,11 @@ Init *TGParser::ParseOperation(Record *CurRec) {
|
|||||||
Code = BinOpInit::SHL;
|
Code = BinOpInit::SHL;
|
||||||
Type = new IntRecTy();
|
Type = new IntRecTy();
|
||||||
break;
|
break;
|
||||||
|
case tgtok::XEq:
|
||||||
|
Lex.Lex(); // eat the operation
|
||||||
|
Code = BinOpInit::EQ;
|
||||||
|
Type = new IntRecTy();
|
||||||
|
break;
|
||||||
case tgtok::XStrConcat:
|
case tgtok::XStrConcat:
|
||||||
Lex.Lex(); // eat the operation
|
Lex.Lex(); // eat the operation
|
||||||
Code = BinOpInit::STRCONCAT;
|
Code = BinOpInit::STRCONCAT;
|
||||||
@ -1257,6 +1263,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) {
|
|||||||
case tgtok::XSRA:
|
case tgtok::XSRA:
|
||||||
case tgtok::XSRL:
|
case tgtok::XSRL:
|
||||||
case tgtok::XSHL:
|
case tgtok::XSHL:
|
||||||
|
case tgtok::XEq:
|
||||||
case tgtok::XStrConcat:
|
case tgtok::XStrConcat:
|
||||||
case tgtok::XNameConcat: // Value ::= !binop '(' Value ',' Value ')'
|
case tgtok::XNameConcat: // Value ::= !binop '(' Value ',' Value ')'
|
||||||
case tgtok::XIf:
|
case tgtok::XIf:
|
||||||
|
Loading…
Reference in New Issue
Block a user