[Mlir-commits] [mlir] c009505 - [mlir] Add `parseSymbolName` that doesn't take an attribute list
Jeff Niu
llvmlistbot at llvm.org
Thu Oct 27 12:07:51 PDT 2022
Author: Jeff Niu
Date: 2022-10-27T12:07:43-07:00
New Revision: c0095050dacff8a7b0e9066cfd1c37c684bc4fa3
URL: https://github.com/llvm/llvm-project/commit/c0095050dacff8a7b0e9066cfd1c37c684bc4fa3
DIFF: https://github.com/llvm/llvm-project/commit/c0095050dacff8a7b0e9066cfd1c37c684bc4fa3.diff
LOG: [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
Added:
Modified:
mlir/include/mlir/IR/OpImplementation.h
mlir/lib/AsmParser/AsmParserImpl.h
Removed:
################################################################################
diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h
index 524c72d239cf6..0c74af3508aef 100644
--- a/mlir/include/mlir/IR/OpImplementation.h
+++ b/mlir/include/mlir/IR/OpImplementation.h
@@ -1009,21 +1009,39 @@ class AsmParser {
// Identifier Parsing
//===--------------------------------------------------------------------===//
+ /// Parse an @-identifier and store it (without the '@' symbol) in a string
+ /// attribute.
+ ParseResult parseSymbolName(StringAttr &result) {
+ if (failed(parseOptionalSymbolName(result)))
+ return emitError(getCurrentLocation())
+ << "expected valid '@'-identifier for symbol name";
+ 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 (failed(parseOptionalSymbolName(result, attrName, attrs)))
- return emitError(getCurrentLocation())
- << "expected valid '@'-identifier for symbol name";
+ 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
/// string attribute named 'attrName'.
- virtual ParseResult parseOptionalSymbolName(StringAttr &result,
- StringRef attrName,
- NamedAttrList &attrs) = 0;
+ ParseResult parseOptionalSymbolName(StringAttr &result, StringRef attrName,
+ NamedAttrList &attrs) {
+ if (succeeded(parseOptionalSymbolName(result))) {
+ attrs.append(attrName, result);
+ return success();
+ }
+ return failure();
+ }
//===--------------------------------------------------------------------===//
// Resource Parsing
diff --git a/mlir/lib/AsmParser/AsmParserImpl.h b/mlir/lib/AsmParser/AsmParserImpl.h
index bb0fe5c56df0d..d7e8a55089d33 100644
--- a/mlir/lib/AsmParser/AsmParserImpl.h
+++ b/mlir/lib/AsmParser/AsmParserImpl.h
@@ -439,14 +439,12 @@ class AsmParserImpl : public BaseT {
/// Parse an optional @-identifier and store it (without the '@' symbol) in a
/// string attribute named 'attrName'.
- ParseResult parseOptionalSymbolName(StringAttr &result, StringRef attrName,
- NamedAttrList &attrs) override {
+ ParseResult parseOptionalSymbolName(StringAttr &result) override {
Token atToken = parser.getToken();
if (atToken.isNot(Token::at_identifier))
return failure();
result = getBuilder().getStringAttr(atToken.getSymbolReference());
- attrs.push_back(getBuilder().getNamedAttr(attrName, result));
parser.consumeToken();
// If we are populating the assembly parser state, record this as a symbol
More information about the Mlir-commits
mailing list