summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Support
diff options
context:
space:
mode:
authorAlex Zinenko <zinenko@google.com>2019-11-07 11:42:11 -0800
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-11-07 11:42:46 -0800
commit09e8e7107aafcdc61632ed0aabfa63255859e87a (patch)
treef959bddf1f25131141c029205983d1233441efb1 /mlir/lib/Support
parenteb47d5ee66e2e3dc4d9f2fc7768c41f6b037f3db (diff)
downloadbcm5719-llvm-09e8e7107aafcdc61632ed0aabfa63255859e87a.tar.gz
bcm5719-llvm-09e8e7107aafcdc61632ed0aabfa63255859e87a.zip
mlir-translate: support -verify-diagnostics
MLIR translation tools can emit diagnostics and we want to be able to check if it is indeed the case in tests. Reuse the source manager error handlers provided for mlir-opt to support the verification in mlir-translate. This requires us to change the signature of the functions that are registered to translate sources to MLIR: it now takes a source manager instead of a memory buffer. PiperOrigin-RevId: 279132972
Diffstat (limited to 'mlir/lib/Support')
-rw-r--r--mlir/lib/Support/TranslateClParser.cpp38
1 files changed, 17 insertions, 21 deletions
diff --git a/mlir/lib/Support/TranslateClParser.cpp b/mlir/lib/Support/TranslateClParser.cpp
index 6a9f9d00898..dae0437813f 100644
--- a/mlir/lib/Support/TranslateClParser.cpp
+++ b/mlir/lib/Support/TranslateClParser.cpp
@@ -55,15 +55,15 @@ TranslationParser::TranslationParser(llvm::cl::Option &opt)
wrapperStorage.reserve(toMLIRRegistry.size() + fromMLIRRegistry.size() +
fileToFileRegistry.size());
for (const auto &kv : toMLIRRegistry) {
- TranslateToMLIRFunction function = kv.second;
- TranslateFunction wrapper =
- [function](std::unique_ptr<llvm::MemoryBuffer> input,
- llvm::raw_ostream &output, MLIRContext *context) {
- OwningModuleRef module = function(std::move(input), context);
- if (!module)
- return failure();
- return printMLIROutput(*module, output);
- };
+ TranslateSourceMgrToMLIRFunction function = kv.second;
+ TranslateFunction wrapper = [function](llvm::SourceMgr &sourceMgr,
+ llvm::raw_ostream &output,
+ MLIRContext *context) {
+ OwningModuleRef module = function(sourceMgr, context);
+ if (!module)
+ return failure();
+ return printMLIROutput(*module, output);
+ };
wrapperStorage.emplace_back(std::move(wrapper));
addLiteralOption(kv.first(), &wrapperStorage.back(), kv.first());
@@ -71,18 +71,14 @@ TranslationParser::TranslationParser(llvm::cl::Option &opt)
for (const auto &kv : fromMLIRRegistry) {
TranslateFromMLIRFunction function = kv.second;
- TranslateFunction wrapper =
- [function](std::unique_ptr<llvm::MemoryBuffer> input,
- llvm::raw_ostream &output, MLIRContext *context) {
- llvm::SourceMgr sourceMgr;
- sourceMgr.AddNewSourceBuffer(std::move(input), llvm::SMLoc());
- SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, context);
-
- auto module = OwningModuleRef(parseSourceFile(sourceMgr, context));
- if (!module)
- return failure();
- return function(module.get(), output);
- };
+ TranslateFunction wrapper = [function](llvm::SourceMgr &sourceMgr,
+ llvm::raw_ostream &output,
+ MLIRContext *context) {
+ auto module = OwningModuleRef(parseSourceFile(sourceMgr, context));
+ if (!module)
+ return failure();
+ return function(module.get(), output);
+ };
wrapperStorage.emplace_back(std::move(wrapper));
addLiteralOption(kv.first(), &wrapperStorage.back(), kv.first());
OpenPOWER on IntegriCloud