diff --git a/mlir/include/mlir/Tools/mlir-translate/Translation.h b/mlir/include/mlir/Tools/mlir-translate/Translation.h --- a/mlir/include/mlir/Tools/mlir-translate/Translation.h +++ b/mlir/include/mlir/Tools/mlir-translate/Translation.h @@ -106,6 +106,9 @@ size_t globalWidth) const override; }; +/// Register command-line options used by the translation registry. +void registerTranslationCLOptions(); + } // namespace mlir #endif // MLIR_TOOLS_MLIRTRANSLATE_TRANSLATION_H diff --git a/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp b/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp --- a/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp +++ b/mlir/lib/Tools/mlir-translate/MlirTranslateMain.cpp @@ -61,6 +61,7 @@ llvm::cl::Required); registerAsmPrinterCLOptions(); registerMLIRContextCLOptions(); + registerTranslationCLOptions(); llvm::cl::ParseCommandLineOptions(argc, argv, toolName); std::string errorMessage; diff --git a/mlir/lib/Tools/mlir-translate/Translation.cpp b/mlir/lib/Tools/mlir-translate/Translation.cpp --- a/mlir/lib/Tools/mlir-translate/Translation.cpp +++ b/mlir/lib/Tools/mlir-translate/Translation.cpp @@ -21,6 +21,21 @@ using namespace mlir; +//===----------------------------------------------------------------------===// +// Translation CommandLine Options +//===----------------------------------------------------------------------===// + +struct TranslationOptions { + llvm::cl::opt noImplicitModule{ + "no-implicit-module", + llvm::cl::desc("Disable the parsing of an implicit top-level module op"), + llvm::cl::init(false)}; +}; + +static llvm::ManagedStatic clOptions; + +void mlir::registerTranslationCLOptions() { *clOptions; } + //===----------------------------------------------------------------------===// // Translation Registry //===----------------------------------------------------------------------===// @@ -103,24 +118,22 @@ const TranslateFromMLIRFunction &function, const std::function &dialectRegistration) { - static llvm::cl::opt noImplicitModule{ - "no-implicit-module", - llvm::cl::desc("Disable the parsing of an implicit top-level module op"), - llvm::cl::init(false)}; - - registerTranslation(name, description, - [function, dialectRegistration]( - llvm::SourceMgr &sourceMgr, raw_ostream &output, - MLIRContext *context) { - DialectRegistry registry; - dialectRegistration(registry); - context->appendDialectRegistry(registry); - OwningOpRef op = parseSourceFileForTool( - sourceMgr, context, !noImplicitModule); - if (!op || failed(verify(*op))) - return failure(); - return function(op.get(), output); - }); + registerTranslation( + name, description, + [function, dialectRegistration](llvm::SourceMgr &sourceMgr, + raw_ostream &output, + MLIRContext *context) { + DialectRegistry registry; + dialectRegistration(registry); + context->appendDialectRegistry(registry); + bool implicitModule = + (!clOptions.isConstructed() || !clOptions->noImplicitModule); + OwningOpRef op = + parseSourceFileForTool(sourceMgr, context, implicitModule); + if (!op || failed(verify(*op))) + return failure(); + return function(op.get(), output); + }); } //===----------------------------------------------------------------------===//