DialectAsmParser already allows converting an llvm::SMLoc location to a
mlir::Location location. This commit adds the same functionality to OpAsmParser.
Implementation is copied from DialectAsmParser.
Reviewed By: rriddle
Differential Revision: https://reviews.llvm.org/D102165
/// Return the location of the original name token.
virtual llvm::SMLoc getNameLoc() const = 0;
+ /// Re-encode the given source location as an MLIR location and return it.
+ /// Note: This method should only be used when a `Location` is necessary, as
+ /// the encoding process is not efficient.
+ virtual Location getEncodedSourceLoc(llvm::SMLoc loc) = 0;
+
// These methods emit an error and return failure or success. This allows
// these to be chained together into a linear sequence of || expressions in
// many cases.
llvm::SMLoc getNameLoc() const override { return nameLoc; }
+ /// Re-encode the given source location as an MLIR location and return it.
+ Location getEncodedSourceLoc(llvm::SMLoc loc) override {
+ return parser.getEncodedSourceLocation(loc);
+ }
+
//===--------------------------------------------------------------------===//
// Token Parsing
//===--------------------------------------------------------------------===//