[mlir] Provide CustomOpAsmParser::parseOptionalOperand

Summary:
Some operations have custom syntax where an operand is always followed by a
specific token of streams if the operand is present. Parsing such operations
requires the ability to optionally parse an operand. Provide a relevant
function in the custom Op parser.

Differential Revision: https://reviews.llvm.org/D76779
This commit is contained in:
Alex Zinenko 2020-03-25 16:25:52 +01:00
parent f1a9efabcb
commit ec74867c5e
2 changed files with 10 additions and 0 deletions

View File

@ -452,6 +452,9 @@ public:
/// Parse a single operand.
virtual ParseResult parseOperand(OperandType &result) = 0;
/// Parse a single operand if present.
virtual OptionalParseResult parseOptionalOperand(OperandType &result) = 0;
/// These are the supported delimiters around operand lists and region
/// argument lists, used by parseOperandList and parseRegionArgumentList.
enum class Delimiter {

View File

@ -4253,6 +4253,13 @@ public:
return success();
}
/// Parse a single operand if present.
OptionalParseResult parseOptionalOperand(OperandType &result) override {
if (parser.getToken().is(Token::percent_identifier))
return parseOperand(result);
return llvm::None;
}
/// Parse zero or more SSA comma-separated operand references with a specified
/// surrounding delimiter, and an optional required operand count.
ParseResult parseOperandList(SmallVectorImpl<OperandType> &result,