From 98ed3c7273cbccb69ed322fe2223f3bccd5b7850 Mon Sep 17 00:00:00 2001 From: David Greene Date: Thu, 14 May 2009 21:54:42 +0000 Subject: Implement a !subst operation simmilar to $(subst) in GNU make to do def/var/string substitution on generic pattern templates. For example: def Type; def v4f32 : Type; def TYPE : Type; class GenType { let type = !(subst TYPE, v4f32, t); } def TheType : GenType; llvm-svn: 71801 --- llvm/utils/TableGen/TGParser.cpp | 144 +++++++++++++++++++-------------------- 1 file changed, 72 insertions(+), 72 deletions(-) (limited to 'llvm/utils/TableGen/TGParser.cpp') diff --git a/llvm/utils/TableGen/TGParser.cpp b/llvm/utils/TableGen/TGParser.cpp index 6b4c431635c..967f5d0d5dd 100644 --- a/llvm/utils/TableGen/TGParser.cpp +++ b/llvm/utils/TableGen/TGParser.cpp @@ -793,78 +793,78 @@ Init *TGParser::ParseOperation(Record *CurRec) { } // case tgtok::XForEach: -// case tgtok::XSubst: { // Value ::= !ternop '(' Value ',' Value ',' Value ')' -// TernOpInit::TernaryOp Code; -// RecTy *Type = 0; - - -// tgtok::TokKind LexCode = Lex.getCode(); -// Lex.Lex(); // eat the operation -// switch (LexCode) { -// default: assert(0 && "Unhandled code!"); -// case tgtok::XForEach: -// Code = TernOpInit::FOREACH; -// break; -// case tgtok::XSubst: -// Code = TernOpInit::SUBST; -// break; -// } -// if (Lex.getCode() != tgtok::l_paren) { -// TokError("expected '(' after ternary operator"); -// return 0; -// } -// Lex.Lex(); // eat the '(' - -// Init *LHS = ParseValue(CurRec); -// if (LHS == 0) return 0; - -// if (Lex.getCode() != tgtok::comma) { -// TokError("expected ',' in ternary operator"); -// return 0; -// } -// Lex.Lex(); // eat the ',' + case tgtok::XSubst: { // Value ::= !ternop '(' Value ',' Value ',' Value ')' + TernOpInit::TernaryOp Code; + RecTy *Type = 0; + + + tgtok::TokKind LexCode = Lex.getCode(); + Lex.Lex(); // eat the operation + switch (LexCode) { + default: assert(0 && "Unhandled code!"); + //case tgtok::XForEach: + //Code = TernOpInit::FOREACH; + //break; + case tgtok::XSubst: + Code = TernOpInit::SUBST; + break; + } + if (Lex.getCode() != tgtok::l_paren) { + TokError("expected '(' after ternary operator"); + return 0; + } + Lex.Lex(); // eat the '(' + + Init *LHS = ParseValue(CurRec); + if (LHS == 0) return 0; + + if (Lex.getCode() != tgtok::comma) { + TokError("expected ',' in ternary operator"); + return 0; + } + Lex.Lex(); // eat the ',' -// Init *MHS = ParseValue(CurRec); -// if (MHS == 0) return 0; - -// if (Lex.getCode() != tgtok::comma) { -// TokError("expected ',' in ternary operator"); -// return 0; -// } -// Lex.Lex(); // eat the ',' + Init *MHS = ParseValue(CurRec); + if (MHS == 0) return 0; + + if (Lex.getCode() != tgtok::comma) { + TokError("expected ',' in ternary operator"); + return 0; + } + Lex.Lex(); // eat the ',' -// Init *RHS = ParseValue(CurRec); -// if (RHS == 0) return 0; - -// if (Lex.getCode() != tgtok::r_paren) { -// TokError("expected ')' in binary operator"); -// return 0; -// } -// Lex.Lex(); // eat the ')' - -// switch (LexCode) { -// default: assert(0 && "Unhandled code!"); -// case tgtok::XForEach: { -// TypedInit *MHSt = dynamic_cast(MHS); -// if (MHSt == 0) { -// TokError("could not get type for !foreach"); -// return 0; -// } -// Type = MHSt->getType(); -// break; -// } -// case tgtok::XSubst: { -// TypedInit *RHSt = dynamic_cast(RHS); -// if (RHSt == 0) { -// TokError("could not get type for !subst"); -// return 0; -// } -// Type = RHSt->getType(); -// break; -// } -// } -// return (new TernOpInit(Code, LHS, MHS, RHS, Type))->Fold(CurRec, CurMultiClass); -// } + Init *RHS = ParseValue(CurRec); + if (RHS == 0) return 0; + + if (Lex.getCode() != tgtok::r_paren) { + TokError("expected ')' in binary operator"); + return 0; + } + Lex.Lex(); // eat the ')' + + switch (LexCode) { + default: assert(0 && "Unhandled code!"); + //case tgtok::XForEach: { + //TypedInit *MHSt = dynamic_cast(MHS); + //if (MHSt == 0) { + // TokError("could not get type for !foreach"); + // return 0; + //} + //Type = MHSt->getType(); + //break; + //} + case tgtok::XSubst: { + TypedInit *RHSt = dynamic_cast(RHS); + if (RHSt == 0) { + TokError("could not get type for !subst"); + return 0; + } + Type = RHSt->getType(); + break; + } + } + return (new TernOpInit(Code, LHS, MHS, RHS, Type))->Fold(CurRec, CurMultiClass); + } } TokError("could not parse operation"); return 0; @@ -1078,9 +1078,9 @@ Init *TGParser::ParseSimpleValue(Record *CurRec) { case tgtok::XSRL: case tgtok::XSHL: case tgtok::XStrConcat: - case tgtok::XNameConcat: { // Value ::= !binop '(' Value ',' Value ')' + case tgtok::XNameConcat: // Value ::= !binop '(' Value ',' Value ')' // case tgtok::XForEach: - // case tgtok::XSubst: { // Value ::= !ternop '(' Value ',' Value ',' Value ')' + case tgtok::XSubst: { // Value ::= !ternop '(' Value ',' Value ',' Value ')' return ParseOperation(CurRec); break; } -- cgit v1.2.3