[MLIR] Enable conversion from llvm::SMLoc to mlir::Location with OpAsmParser.
authorUlysse Beaugnon <ulysse@google.com>
Wed, 12 May 2021 07:07:44 +0000 (09:07 +0200)
committerAlex Zinenko <zinenko@google.com>
Wed, 12 May 2021 07:08:32 +0000 (09:08 +0200)
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

mlir/include/mlir/IR/OpImplementation.h
mlir/lib/Parser/Parser.cpp

index fb4f1a8..db1e98d 100644 (file)
@@ -287,6 +287,11 @@ public:
   /// 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.
index b3c66b2..fea26bc 100644 (file)
@@ -1066,6 +1066,11 @@ public:
 
   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
   //===--------------------------------------------------------------------===//