@@ -905,7 +905,8 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
905905 case tgtok::XTail:
906906 case tgtok::XSize:
907907 case tgtok::XEmpty:
908- case tgtok::XCast: { // Value ::= !unop '(' Value ')'
908+ case tgtok::XCast:
909+ case tgtok::XGetOp: { // Value ::= !unop '(' Value ')'
909910 UnOpInit::UnaryOp Code;
910911 RecTy *Type = nullptr ;
911912
@@ -941,6 +942,28 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
941942 Code = UnOpInit::EMPTY;
942943 Type = IntRecTy::get ();
943944 break ;
945+ case tgtok::XGetOp:
946+ Lex.Lex (); // eat the operation
947+ if (Lex.getCode () == tgtok::less) {
948+ // Parse an optional type suffix, so that you can say
949+ // !getop<BaseClass>(someDag) as a shorthand for
950+ // !cast<BaseClass>(!getop(someDag)).
951+ Type = ParseOperatorType ();
952+
953+ if (!Type) {
954+ TokError (" did not get type for unary operator" );
955+ return nullptr ;
956+ }
957+
958+ if (!isa<RecordRecTy>(Type)) {
959+ TokError (" type for !getop must be a record type" );
960+ // but keep parsing, to consume the operand
961+ }
962+ } else {
963+ Type = RecordRecTy::get ({});
964+ }
965+ Code = UnOpInit::GETOP;
966+ break ;
944967 }
945968 if (Lex.getCode () != tgtok::l_paren) {
946969 TokError (" expected '(' after unary operator" );
@@ -1055,7 +1078,8 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
10551078 case tgtok::XGt:
10561079 case tgtok::XListConcat:
10571080 case tgtok::XListSplat:
1058- case tgtok::XStrConcat: { // Value ::= !binop '(' Value ',' Value ')'
1081+ case tgtok::XStrConcat:
1082+ case tgtok::XSetOp: { // Value ::= !binop '(' Value ',' Value ')'
10591083 tgtok::TokKind OpTok = Lex.getCode ();
10601084 SMLoc OpLoc = Lex.getLoc ();
10611085 Lex.Lex (); // eat the operation
@@ -1080,6 +1104,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
10801104 case tgtok::XListConcat: Code = BinOpInit::LISTCONCAT; break ;
10811105 case tgtok::XListSplat: Code = BinOpInit::LISTSPLAT; break ;
10821106 case tgtok::XStrConcat: Code = BinOpInit::STRCONCAT; break ;
1107+ case tgtok::XSetOp: Code = BinOpInit::SETOP; break ;
10831108 }
10841109
10851110 RecTy *Type = nullptr ;
@@ -1088,6 +1113,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
10881113 default :
10891114 llvm_unreachable (" Unhandled code!" );
10901115 case tgtok::XConcat:
1116+ case tgtok::XSetOp:
10911117 Type = DagRecTy::get ();
10921118 ArgType = DagRecTy::get ();
10931119 break ;
@@ -1146,7 +1172,6 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
11461172 InitList.push_back (ParseValue (CurRec, ArgType));
11471173 if (!InitList.back ()) return nullptr ;
11481174
1149- // All BinOps require their arguments to be of compatible types.
11501175 RecTy *ListType = cast<TypedInit>(InitList.back ())->getType ();
11511176 if (!ArgType) {
11521177 ArgType = ListType;
@@ -1212,6 +1237,18 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
12121237 ArgType = Resolved;
12131238 }
12141239
1240+ // Deal with BinOps whose arguments have different types, by
1241+ // rewriting ArgType in between them.
1242+ switch (Code) {
1243+ case BinOpInit::SETOP:
1244+ // After parsing the first dag argument, switch to expecting
1245+ // a record, with no restriction on its superclasses.
1246+ ArgType = RecordRecTy::get ({});
1247+ break ;
1248+ default :
1249+ break ;
1250+ }
1251+
12151252 if (Lex.getCode () != tgtok::comma)
12161253 break ;
12171254 Lex.Lex (); // eat the ','
@@ -2025,7 +2062,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
20252062 case tgtok::l_paren: { // Value ::= '(' IDValue DagArgList ')'
20262063 Lex.Lex (); // eat the '('
20272064 if (Lex.getCode () != tgtok::Id && Lex.getCode () != tgtok::XCast &&
2028- Lex.getCode () != tgtok::question) {
2065+ Lex.getCode () != tgtok::question && Lex. getCode () != tgtok::XGetOp ) {
20292066 TokError (" expected identifier in dag init" );
20302067 return nullptr ;
20312068 }
@@ -2063,7 +2100,8 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
20632100 case tgtok::XTail:
20642101 case tgtok::XSize:
20652102 case tgtok::XEmpty:
2066- case tgtok::XCast: // Value ::= !unop '(' Value ')'
2103+ case tgtok::XCast:
2104+ case tgtok::XGetOp: // Value ::= !unop '(' Value ')'
20672105 case tgtok::XIsA:
20682106 case tgtok::XConcat:
20692107 case tgtok::XDag:
@@ -2082,7 +2120,8 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
20822120 case tgtok::XGt:
20832121 case tgtok::XListConcat:
20842122 case tgtok::XListSplat:
2085- case tgtok::XStrConcat: // Value ::= !binop '(' Value ',' Value ')'
2123+ case tgtok::XStrConcat:
2124+ case tgtok::XSetOp: // Value ::= !binop '(' Value ',' Value ')'
20862125 case tgtok::XIf:
20872126 case tgtok::XCond:
20882127 case tgtok::XFoldl:
0 commit comments