Add SourceMgrDiagnosticHandler to toy

PiperOrigin-RevId: 275659433
This commit is contained in:
Jacques Pienaar 2019-10-19 14:36:07 -07:00 committed by A. Unique TensorFlower
parent 305dafd3b1
commit 8317bd85e5
3 changed files with 15 additions and 9 deletions

View File

@ -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) {

View File

@ -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) {

View File

@ -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);