diff --git a/mlir/include/mlir/Parser/Parser.h b/mlir/include/mlir/Parser/Parser.h index ae59ea2896c72..52b7b49e2a7b8 100644 --- a/mlir/include/mlir/Parser/Parser.h +++ b/mlir/include/mlir/Parser/Parser.h @@ -126,6 +126,22 @@ LogicalResult parseSourceString(llvm::StringRef sourceStr, Block *block, MLIRContext *context, LocationAttr *sourceFileLoc = nullptr); +namespace detail { +/// The internal implementation of the templated `parseSourceFile` methods +/// below, that simply forwards to the non-templated version. +template +inline OwningOpRef parseSourceFile(MLIRContext *ctx, + ParserArgs &&...args) { + LocationAttr sourceFileLoc; + Block block; + if (failed(parseSourceFile(std::forward(args)..., &block, ctx, + &sourceFileLoc))) + return OwningOpRef(); + return detail::constructContainerOpForParserIfNecessary( + &block, ctx, sourceFileLoc); +} +} // namespace detail + /// This parses the file specified by the indicated SourceMgr. If the source IR /// contained a single instance of `ContainerOpT`, it is returned. Otherwise, a /// new instance of `ContainerOpT` is constructed containing all of the parsed @@ -137,12 +153,7 @@ LogicalResult parseSourceString(llvm::StringRef sourceStr, Block *block, template inline OwningOpRef parseSourceFile(const llvm::SourceMgr &sourceMgr, MLIRContext *context) { - LocationAttr sourceFileLoc; - Block block; - if (failed(parseSourceFile(sourceMgr, &block, context, &sourceFileLoc))) - return OwningOpRef(); - return detail::constructContainerOpForParserIfNecessary( - &block, context, sourceFileLoc); + return detail::parseSourceFile(context, sourceMgr); } /// This parses the file specified by the indicated filename. If the source IR @@ -154,14 +165,9 @@ parseSourceFile(const llvm::SourceMgr &sourceMgr, MLIRContext *context) { /// containing a single block, and must implement the /// `SingleBlockImplicitTerminator` trait. template -inline OwningOpRef parseSourceFile(llvm::StringRef filename, +inline OwningOpRef parseSourceFile(StringRef filename, MLIRContext *context) { - LocationAttr sourceFileLoc; - Block block; - if (failed(parseSourceFile(filename, &block, context, &sourceFileLoc))) - return OwningOpRef(); - return detail::constructContainerOpForParserIfNecessary( - &block, context, sourceFileLoc); + return detail::parseSourceFile(context, filename); } /// This parses the file specified by the indicated filename using the provided @@ -176,13 +182,7 @@ template inline OwningOpRef parseSourceFile(llvm::StringRef filename, llvm::SourceMgr &sourceMgr, MLIRContext *context) { - LocationAttr sourceFileLoc; - Block block; - if (failed(parseSourceFile(filename, sourceMgr, &block, context, - &sourceFileLoc))) - return OwningOpRef(); - return detail::constructContainerOpForParserIfNecessary( - &block, context, sourceFileLoc); + return detail::parseSourceFile(context, filename, sourceMgr); } /// This parses the provided string containing MLIR. If the source IR contained