From 8317bd85e5cccc8048cd1be1b3b17c19c953764d Mon Sep 17 00:00:00 2001 From: Jacques Pienaar Date: Sat, 19 Oct 2019 14:36:07 -0700 Subject: [PATCH] Add SourceMgrDiagnosticHandler to toy PiperOrigin-RevId: 275659433 --- mlir/examples/toy/Ch3/toyc.cpp | 8 +++++--- mlir/examples/toy/Ch4/toyc.cpp | 8 +++++--- 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 01ebc7b..72e1c6f 100644 --- a/mlir/examples/toy/Ch3/toyc.cpp +++ b/mlir/examples/toy/Ch3/toyc.cpp @@ -79,7 +79,8 @@ std::unique_ptr 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 1f535ec..ac73236 100644 --- a/mlir/examples/toy/Ch4/toyc.cpp +++ b/mlir/examples/toy/Ch4/toyc.cpp @@ -80,7 +80,8 @@ std::unique_ptr 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 2c3875f..e4157ea 100644 --- a/mlir/examples/toy/Ch5/toyc.cpp +++ b/mlir/examples/toy/Ch5/toyc.cpp @@ -82,7 +82,8 @@ std::unique_ptr 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); -- 2.7.4