[mlir] Add `parseEllipsis`

To `AsmParser` and also to the assembly format

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D134082
This commit is contained in:
Jeff Niu 2022-09-16 14:41:22 -07:00
parent 5d12e9a571
commit ac74c51c35
7 changed files with 26 additions and 1 deletions

View File

@ -593,6 +593,9 @@ public:
/// Parse a `]` token if present.
virtual ParseResult parseOptionalRSquare() = 0;
/// Parse a `...` token.
virtual ParseResult parseEllipsis() = 0;
/// Parse a `...` token if present;
virtual ParseResult parseOptionalEllipsis() = 0;

View File

@ -114,6 +114,11 @@ public:
return success(parser.consumeIf(Token::comma));
}
/// Parses a `...`.
ParseResult parseEllipsis() override {
return parser.parseToken(Token::ellipsis, "expected '...'");
}
/// Parses a `...` if present.
ParseResult parseOptionalEllipsis() override {
return success(parser.consumeIf(Token::ellipsis));

View File

@ -797,6 +797,13 @@ def OIListAllowedLiteral : TEST_Op<"oilist_allowed_literal"> {
}];
}
def TestEllipsisOp : TEST_Op<"ellipsis"> {
let arguments = (ins Variadic<AnyType>:$operands, UnitAttr:$variadic);
let assemblyFormat = [{
`(` $operands (`...` $variadic^)? `)` attr-dict `:` type($operands) `...`
}];
}
def ElseAnchorOp : TEST_Op<"else_anchor"> {
let arguments = (ins Optional<AnyType>:$a);
let assemblyFormat = "`(` (`?`) : (`` $a^ `:` type($a))? `)` attr-dict";

View File

@ -392,6 +392,12 @@ func.func @foo() {
// CHECK: test.format_literal_following_optional_group(5 : i32) : i32 {a}
test.format_literal_following_optional_group(5 : i32) : i32 {a}
func.func @variadic(%a: i32) {
// CHECK: test.ellipsis(%{{.*}} ...) : i32 ...
test.ellipsis(%a ...) : i32 ...
return
}
//===----------------------------------------------------------------------===//
// Format trait type inference
//===----------------------------------------------------------------------===//

View File

@ -392,6 +392,7 @@ void DefFormat::genLiteralParser(StringRef value, FmtContext &ctx,
.Case("?", "Question")
.Case("+", "Plus")
.Case("*", "Star")
.Case("...", "Ellipsis")
<< "()";
}
if (isOptional) {

View File

@ -483,6 +483,8 @@ bool mlir::tblgen::isValidLiteral(StringRef value,
// Check the punctuation that are larger than a single character.
if (value == "->")
return true;
if (value == "...")
return true;
// Otherwise, this must be an identifier.
return canFormatStringAsKeyword(value, emitError);

View File

@ -760,7 +760,8 @@ static void genLiteralParser(StringRef value, MethodBody &body) {
.Case("]", "RSquare()")
.Case("?", "Question()")
.Case("+", "Plus()")
.Case("*", "Star()");
.Case("*", "Star()")
.Case("...", "Ellipsis()");
}
/// Generate the storage code required for parsing the given element.