@@ -905,7 +905,8 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
905
905
case tgtok::XTail:
906
906
case tgtok::XSize:
907
907
case tgtok::XEmpty:
908
- case tgtok::XCast: { // Value ::= !unop '(' Value ')'
908
+ case tgtok::XCast:
909
+ case tgtok::XGetOp: { // Value ::= !unop '(' Value ')'
909
910
UnOpInit::UnaryOp Code;
910
911
RecTy *Type = nullptr ;
911
912
@@ -941,6 +942,28 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
941
942
Code = UnOpInit::EMPTY;
942
943
Type = IntRecTy::get ();
943
944
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 ;
944
967
}
945
968
if (Lex.getCode () != tgtok::l_paren) {
946
969
TokError (" expected '(' after unary operator" );
@@ -1055,7 +1078,8 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
1055
1078
case tgtok::XGt:
1056
1079
case tgtok::XListConcat:
1057
1080
case tgtok::XListSplat:
1058
- case tgtok::XStrConcat: { // Value ::= !binop '(' Value ',' Value ')'
1081
+ case tgtok::XStrConcat:
1082
+ case tgtok::XSetOp: { // Value ::= !binop '(' Value ',' Value ')'
1059
1083
tgtok::TokKind OpTok = Lex.getCode ();
1060
1084
SMLoc OpLoc = Lex.getLoc ();
1061
1085
Lex.Lex (); // eat the operation
@@ -1080,6 +1104,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
1080
1104
case tgtok::XListConcat: Code = BinOpInit::LISTCONCAT; break ;
1081
1105
case tgtok::XListSplat: Code = BinOpInit::LISTSPLAT; break ;
1082
1106
case tgtok::XStrConcat: Code = BinOpInit::STRCONCAT; break ;
1107
+ case tgtok::XSetOp: Code = BinOpInit::SETOP; break ;
1083
1108
}
1084
1109
1085
1110
RecTy *Type = nullptr ;
@@ -1088,6 +1113,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
1088
1113
default :
1089
1114
llvm_unreachable (" Unhandled code!" );
1090
1115
case tgtok::XConcat:
1116
+ case tgtok::XSetOp:
1091
1117
Type = DagRecTy::get ();
1092
1118
ArgType = DagRecTy::get ();
1093
1119
break ;
@@ -1146,7 +1172,6 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
1146
1172
InitList.push_back (ParseValue (CurRec, ArgType));
1147
1173
if (!InitList.back ()) return nullptr ;
1148
1174
1149
- // All BinOps require their arguments to be of compatible types.
1150
1175
RecTy *ListType = cast<TypedInit>(InitList.back ())->getType ();
1151
1176
if (!ArgType) {
1152
1177
ArgType = ListType;
@@ -1212,6 +1237,18 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
1212
1237
ArgType = Resolved;
1213
1238
}
1214
1239
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
+
1215
1252
if (Lex.getCode () != tgtok::comma)
1216
1253
break ;
1217
1254
Lex.Lex (); // eat the ','
@@ -2025,7 +2062,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
2025
2062
case tgtok::l_paren: { // Value ::= '(' IDValue DagArgList ')'
2026
2063
Lex.Lex (); // eat the '('
2027
2064
if (Lex.getCode () != tgtok::Id && Lex.getCode () != tgtok::XCast &&
2028
- Lex.getCode () != tgtok::question) {
2065
+ Lex.getCode () != tgtok::question && Lex. getCode () != tgtok::XGetOp ) {
2029
2066
TokError (" expected identifier in dag init" );
2030
2067
return nullptr ;
2031
2068
}
@@ -2063,7 +2100,8 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
2063
2100
case tgtok::XTail:
2064
2101
case tgtok::XSize:
2065
2102
case tgtok::XEmpty:
2066
- case tgtok::XCast: // Value ::= !unop '(' Value ')'
2103
+ case tgtok::XCast:
2104
+ case tgtok::XGetOp: // Value ::= !unop '(' Value ')'
2067
2105
case tgtok::XIsA:
2068
2106
case tgtok::XConcat:
2069
2107
case tgtok::XDag:
@@ -2082,7 +2120,8 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
2082
2120
case tgtok::XGt:
2083
2121
case tgtok::XListConcat:
2084
2122
case tgtok::XListSplat:
2085
- case tgtok::XStrConcat: // Value ::= !binop '(' Value ',' Value ')'
2123
+ case tgtok::XStrConcat:
2124
+ case tgtok::XSetOp: // Value ::= !binop '(' Value ',' Value ')'
2086
2125
case tgtok::XIf:
2087
2126
case tgtok::XCond:
2088
2127
case tgtok::XFoldl:
0 commit comments