[mlir] Add `parseSymbolName` that doesn't take an attribute list

This patch adds a version of `parseSymbolName` and
`parseOptionalSymbolName` to AsmParser that don't take an attribute name
and attribute list.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D136696
This commit is contained in:
Jeff Niu 2022-10-25 09:28:53 -07:00
parent ea1e767a06
commit c0095050da
2 changed files with 26 additions and 10 deletions

View File

@ -1010,20 +1010,38 @@ public:
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
/// Parse an @-identifier and store it (without the '@' symbol) in a string /// Parse an @-identifier and store it (without the '@' symbol) in a string
/// attribute named 'attrName'. /// attribute.
ParseResult parseSymbolName(StringAttr &result, StringRef attrName, ParseResult parseSymbolName(StringAttr &result) {
NamedAttrList &attrs) { if (failed(parseOptionalSymbolName(result)))
if (failed(parseOptionalSymbolName(result, attrName, attrs)))
return emitError(getCurrentLocation()) return emitError(getCurrentLocation())
<< "expected valid '@'-identifier for symbol name"; << "expected valid '@'-identifier for symbol name";
return success(); return success();
} }
/// Parse an @-identifier and store it (without the '@' symbol) in a string
/// attribute named 'attrName'.
ParseResult parseSymbolName(StringAttr &result, StringRef attrName,
NamedAttrList &attrs) {
if (parseSymbolName(result))
return failure();
attrs.append(attrName, result);
return success();
}
/// Parse an optional @-identifier and store it (without the '@' symbol) in a
/// string attribute.
virtual ParseResult parseOptionalSymbolName(StringAttr &result) = 0;
/// Parse an optional @-identifier and store it (without the '@' symbol) in a /// Parse an optional @-identifier and store it (without the '@' symbol) in a
/// string attribute named 'attrName'. /// string attribute named 'attrName'.
virtual ParseResult parseOptionalSymbolName(StringAttr &result, ParseResult parseOptionalSymbolName(StringAttr &result, StringRef attrName,
StringRef attrName, NamedAttrList &attrs) {
NamedAttrList &attrs) = 0; if (succeeded(parseOptionalSymbolName(result))) {
attrs.append(attrName, result);
return success();
}
return failure();
}
//===--------------------------------------------------------------------===// //===--------------------------------------------------------------------===//
// Resource Parsing // Resource Parsing

View File

@ -439,14 +439,12 @@ public:
/// Parse an optional @-identifier and store it (without the '@' symbol) in a /// Parse an optional @-identifier and store it (without the '@' symbol) in a
/// string attribute named 'attrName'. /// string attribute named 'attrName'.
ParseResult parseOptionalSymbolName(StringAttr &result, StringRef attrName, ParseResult parseOptionalSymbolName(StringAttr &result) override {
NamedAttrList &attrs) override {
Token atToken = parser.getToken(); Token atToken = parser.getToken();
if (atToken.isNot(Token::at_identifier)) if (atToken.isNot(Token::at_identifier))
return failure(); return failure();
result = getBuilder().getStringAttr(atToken.getSymbolReference()); result = getBuilder().getStringAttr(atToken.getSymbolReference());
attrs.push_back(getBuilder().getNamedAttr(attrName, result));
parser.consumeToken(); parser.consumeToken();
// If we are populating the assembly parser state, record this as a symbol // If we are populating the assembly parser state, record this as a symbol