diff options
| author | Jacques Pienaar <jpienaar@google.com> | 2019-10-19 14:36:07 -0700 |
|---|---|---|
| committer | A. Unique TensorFlower <gardener@tensorflow.org> | 2019-10-19 14:36:36 -0700 |
| commit | 8317bd85e5cccc8048cd1be1b3b17c19c953764d (patch) | |
| tree | dae22a112e54ea2e664de530da7edbdcd96430dc /mlir/examples | |
| parent | 305dafd3b1b05d88fe783b54f96bd01da0c87c78 (diff) | |
| download | bcm5719-llvm-8317bd85e5cccc8048cd1be1b3b17c19c953764d.tar.gz bcm5719-llvm-8317bd85e5cccc8048cd1be1b3b17c19c953764d.zip | |
Add SourceMgrDiagnosticHandler to toy
PiperOrigin-RevId: 275659433
Diffstat (limited to 'mlir/examples')
| -rw-r--r-- | mlir/examples/toy/Ch3/toyc.cpp | 8 | ||||
| -rw-r--r-- | mlir/examples/toy/Ch4/toyc.cpp | 8 | ||||
| -rw-r--r-- | mlir/examples/toy/Ch5/toyc.cpp | 8 |
3 files changed, 15 insertions, 9 deletions
diff --git a/mlir/examples/toy/Ch3/toyc.cpp b/mlir/examples/toy/Ch3/toyc.cpp index 01ebc7b2bf8..72e1c6f1966 100644 --- a/mlir/examples/toy/Ch3/toyc.cpp +++ b/mlir/examples/toy/Ch3/toyc.cpp @@ -79,7 +79,8 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) { return parser.ParseModule(); } -int loadMLIR(mlir::MLIRContext &context, mlir::OwningModuleRef &module) { +int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, + mlir::OwningModuleRef &module) { // Handle '.toy' input to the compiler. if (inputType != InputType::MLIR && !llvm::StringRef(inputFilename).endswith(".mlir")) { @@ -97,7 +98,6 @@ int loadMLIR(mlir::MLIRContext &context, mlir::OwningModuleRef &module) { } // Parse the input mlir. - llvm::SourceMgr sourceMgr; sourceMgr.AddNewSourceBuffer(std::move(*fileOrErr), llvm::SMLoc()); module = mlir::parseSourceFile(sourceMgr, &context); if (!module) { @@ -113,7 +113,9 @@ int dumpMLIR() { mlir::MLIRContext context; mlir::OwningModuleRef module; - if (int error = loadMLIR(context, module)) + llvm::SourceMgr sourceMgr; + mlir::SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, &context); + if (int error = loadMLIR(sourceMgr, context, module)) return error; if (EnableOpt) { diff --git a/mlir/examples/toy/Ch4/toyc.cpp b/mlir/examples/toy/Ch4/toyc.cpp index 1f535ec1757..ac73236fe31 100644 --- a/mlir/examples/toy/Ch4/toyc.cpp +++ b/mlir/examples/toy/Ch4/toyc.cpp @@ -80,7 +80,8 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) { return parser.ParseModule(); } -int loadMLIR(mlir::MLIRContext &context, mlir::OwningModuleRef &module) { +int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, + mlir::OwningModuleRef &module) { // Handle '.toy' input to the compiler. if (inputType != InputType::MLIR && !llvm::StringRef(inputFilename).endswith(".mlir")) { @@ -98,7 +99,6 @@ int loadMLIR(mlir::MLIRContext &context, mlir::OwningModuleRef &module) { } // Parse the input mlir. - llvm::SourceMgr sourceMgr; sourceMgr.AddNewSourceBuffer(std::move(*fileOrErr), llvm::SMLoc()); module = mlir::parseSourceFile(sourceMgr, &context); if (!module) { @@ -114,7 +114,9 @@ int dumpMLIR() { mlir::MLIRContext context; mlir::OwningModuleRef module; - if (int error = loadMLIR(context, module)) + llvm::SourceMgr sourceMgr; + mlir::SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, &context); + if (int error = loadMLIR(sourceMgr, context, module)) return error; if (EnableOpt) { diff --git a/mlir/examples/toy/Ch5/toyc.cpp b/mlir/examples/toy/Ch5/toyc.cpp index 2c3875fbcbc..e4157ea57c4 100644 --- a/mlir/examples/toy/Ch5/toyc.cpp +++ b/mlir/examples/toy/Ch5/toyc.cpp @@ -82,7 +82,8 @@ std::unique_ptr<toy::ModuleAST> parseInputFile(llvm::StringRef filename) { return parser.ParseModule(); } -int loadMLIR(mlir::MLIRContext &context, mlir::OwningModuleRef &module) { +int loadMLIR(llvm::SourceMgr &sourceMgr, mlir::MLIRContext &context, + mlir::OwningModuleRef &module) { // Handle '.toy' input to the compiler. if (inputType != InputType::MLIR && !llvm::StringRef(inputFilename).endswith(".mlir")) { @@ -100,7 +101,6 @@ int loadMLIR(mlir::MLIRContext &context, mlir::OwningModuleRef &module) { } // Parse the input mlir. - llvm::SourceMgr sourceMgr; sourceMgr.AddNewSourceBuffer(std::move(*fileOrErr), llvm::SMLoc()); module = mlir::parseSourceFile(sourceMgr, &context); if (!module) { @@ -116,7 +116,9 @@ int dumpMLIR() { mlir::MLIRContext context; mlir::OwningModuleRef module; - if (int error = loadMLIR(context, module)) + llvm::SourceMgr sourceMgr; + mlir::SourceMgrDiagnosticHandler sourceMgrHandler(sourceMgr, &context); + if (int error = loadMLIR(sourceMgr, context, module)) return error; mlir::PassManager pm(&context); |

