summaryrefslogtreecommitdiffstats
path: root/llvm/utils/TableGen/TGParser.cpp
diff options
context:
space:
mode:
authorDavid Greene <greened@obbligato.org>2009-05-14 23:26:46 +0000
committerDavid Greene <greened@obbligato.org>2009-05-14 23:26:46 +0000
commit3587eed2c4abe5ab8a1b838d156512de5510e8a5 (patch)
tree4f0f394b739b677c117bdfe4588f4bc460db7769 /llvm/utils/TableGen/TGParser.cpp
parentb4850465b77f98dce508201c938b7222ed878331 (diff)
downloadbcm5719-llvm-3587eed2c4abe5ab8a1b838d156512de5510e8a5.tar.gz
bcm5719-llvm-3587eed2c4abe5ab8a1b838d156512de5510e8a5.zip
Implement !if, analogous to $(if) in GNU make.
llvm-svn: 71815
Diffstat (limited to 'llvm/utils/TableGen/TGParser.cpp')
-rw-r--r--llvm/utils/TableGen/TGParser.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/utils/TableGen/TGParser.cpp b/llvm/utils/TableGen/TGParser.cpp
index 8ff25a6186b..fc6f29fd9f1 100644
--- a/llvm/utils/TableGen/TGParser.cpp
+++ b/llvm/utils/TableGen/TGParser.cpp
@@ -862,6 +862,7 @@ Init *TGParser::ParseOperation(Record *CurRec) {
return (new BinOpInit(Code, LHS, RHS, Type))->Fold(CurRec, CurMultiClass);
}
+ case tgtok::XIf:
case tgtok::XForEach:
case tgtok::XSubst: { // Value ::= !ternop '(' Value ',' Value ',' Value ')'
TernOpInit::TernaryOp Code;
@@ -872,6 +873,9 @@ Init *TGParser::ParseOperation(Record *CurRec) {
Lex.Lex(); // eat the operation
switch (LexCode) {
default: assert(0 && "Unhandled code!");
+ case tgtok::XIf:
+ Code = TernOpInit::IF;
+ break;
case tgtok::XForEach:
Code = TernOpInit::FOREACH;
break;
@@ -914,6 +918,25 @@ Init *TGParser::ParseOperation(Record *CurRec) {
switch (LexCode) {
default: assert(0 && "Unhandled code!");
+ case tgtok::XIf: {
+ TypedInit *MHSt = dynamic_cast<TypedInit *>(MHS);
+ TypedInit *RHSt = dynamic_cast<TypedInit *>(RHS);
+ if (MHSt == 0 || RHSt == 0) {
+ TokError("could not get type for !if");
+ return 0;
+ }
+ if (MHSt->getType()->typeIsConvertibleTo(RHSt->getType())) {
+ Type = RHSt->getType();
+ }
+ else if (RHSt->getType()->typeIsConvertibleTo(MHSt->getType())) {
+ Type = MHSt->getType();
+ }
+ else {
+ TokError("inconsistent types for !if");
+ return 0;
+ }
+ break;
+ }
case tgtok::XForEach: {
TypedInit *MHSt = dynamic_cast<TypedInit *>(MHS);
if (MHSt == 0) {
@@ -1152,6 +1175,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec) {
case tgtok::XSHL:
case tgtok::XStrConcat:
case tgtok::XNameConcat: // Value ::= !binop '(' Value ',' Value ')'
+ case tgtok::XIf:
case tgtok::XForEach:
case tgtok::XSubst: { // Value ::= !ternop '(' Value ',' Value ',' Value ')'
return ParseOperation(CurRec);
OpenPOWER on IntegriCloud