summaryrefslogtreecommitdiffstats
path: root/llvm/lib/TableGen/TGParser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/TableGen/TGParser.cpp')
-rw-r--r--llvm/lib/TableGen/TGParser.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index f9486d4469d..937de9e5c52 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -1042,6 +1042,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
case tgtok::XGe:
case tgtok::XGt:
case tgtok::XListConcat:
+ case tgtok::XListSplat:
case tgtok::XStrConcat: { // Value ::= !binop '(' Value ',' Value ')'
tgtok::TokKind OpTok = Lex.getCode();
SMLoc OpLoc = Lex.getLoc();
@@ -1065,6 +1066,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
case tgtok::XGe: Code = BinOpInit::GE; break;
case tgtok::XGt: Code = BinOpInit::GT; break;
case tgtok::XListConcat: Code = BinOpInit::LISTCONCAT; break;
+ case tgtok::XListSplat: Code = BinOpInit::LISTSPLAT; break;
case tgtok::XStrConcat: Code = BinOpInit::STRCONCAT; break;
}
@@ -1103,6 +1105,9 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
// We don't know the list type until we parse the first argument
ArgType = ItemType;
break;
+ case tgtok::XListSplat:
+ // Can't do any typechecking until we parse the first argument.
+ break;
case tgtok::XStrConcat:
Type = StringRecTy::get();
ArgType = StringRecTy::get();
@@ -1142,6 +1147,33 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
return nullptr;
}
break;
+ case BinOpInit::LISTSPLAT:
+ if (ItemType && InitList.size() == 1) {
+ if (!isa<ListRecTy>(ItemType)) {
+ Error(OpLoc,
+ Twine("expected output type to be a list, got type '") +
+ ItemType->getAsString() + "'");
+ return nullptr;
+ }
+ if (!ArgType->getListTy()->typeIsConvertibleTo(ItemType)) {
+ Error(OpLoc, Twine("expected first arg type to be '") +
+ ArgType->getAsString() +
+ "', got value of type '" +
+ cast<ListRecTy>(ItemType)
+ ->getElementType()
+ ->getAsString() +
+ "'");
+ return nullptr;
+ }
+ }
+ if (InitList.size() == 2 && !isa<IntRecTy>(ArgType)) {
+ Error(InitLoc, Twine("expected second parameter to be an int, got "
+ "value of type '") +
+ ArgType->getAsString() + "'");
+ return nullptr;
+ }
+ ArgType = nullptr; // Broken invariant: types not identical.
+ break;
case BinOpInit::EQ:
case BinOpInit::NE:
if (!ArgType->typeIsConvertibleTo(IntRecTy::get()) &&
@@ -1179,8 +1211,12 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
}
Lex.Lex(); // eat the ')'
+ // listconcat returns a list with type of the argument.
if (Code == BinOpInit::LISTCONCAT)
Type = ArgType;
+ // listsplat returns a list of type of the *first* argument.
+ if (Code == BinOpInit::LISTSPLAT)
+ Type = cast<TypedInit>(InitList.front())->getType()->getListTy();
// We allow multiple operands to associative operators like !strconcat as
// shorthand for nesting them.
@@ -1718,6 +1754,7 @@ Init *TGParser::ParseOperationCond(Record *CurRec, RecTy *ItemType) {
/// SimpleValue ::= SRATOK '(' Value ',' Value ')'
/// SimpleValue ::= SRLTOK '(' Value ',' Value ')'
/// SimpleValue ::= LISTCONCATTOK '(' Value ',' Value ')'
+/// SimpleValue ::= LISTSPLATTOK '(' Value ',' Value ')'
/// SimpleValue ::= STRCONCATTOK '(' Value ',' Value ')'
/// SimpleValue ::= COND '(' [Value ':' Value,]+ ')'
///
@@ -2031,6 +2068,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
case tgtok::XGe:
case tgtok::XGt:
case tgtok::XListConcat:
+ case tgtok::XListSplat:
case tgtok::XStrConcat: // Value ::= !binop '(' Value ',' Value ')'
case tgtok::XIf:
case tgtok::XCond:
OpenPOWER on IntegriCloud