forked from OSchip/llvm-project
Add a parserSourceFile function that takes a file path directly
This avoids adding boilerplate around the SourceMgr on the client. PiperOrigin-RevId: 239918122
This commit is contained in:
parent
94764ee036
commit
0f5602ae3d
|
@ -37,6 +37,11 @@ class MLIRContext;
|
|||
/// the error handler registered in the context, and a null pointer is returned.
|
||||
Module *parseSourceFile(const llvm::SourceMgr &sourceMgr, MLIRContext *context);
|
||||
|
||||
/// This parses the file specified by the indicated filename and returns an
|
||||
/// MLIR module if it was valid. If not, the error message is emitted through
|
||||
/// the error handler registered in the context, and a null pointer is returned.
|
||||
Module *parseSourceFile(llvm::StringRef filename, MLIRContext *context);
|
||||
|
||||
/// This parses the module string to a MLIR module if it was valid. If not, the
|
||||
/// error message is emitted through / the error handler registered in the
|
||||
/// context, and a null pointer is returned.
|
||||
|
|
|
@ -3743,6 +3743,23 @@ Module *mlir::parseSourceFile(const llvm::SourceMgr &sourceMgr,
|
|||
return module.release();
|
||||
}
|
||||
|
||||
/// This parses the file specified by the indicated filename and returns an
|
||||
/// MLIR module if it was valid. If not, the error message is emitted through
|
||||
/// the error handler registered in the context, and a null pointer is returned.
|
||||
Module *parseSourceFile(StringRef filename, MLIRContext *context) {
|
||||
auto file_or_err = llvm::MemoryBuffer::getFile(filename);
|
||||
if (std::error_code error = file_or_err.getError()) {
|
||||
context->emitError(mlir::UnknownLoc::get(context),
|
||||
"Could not open input file " + filename);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Load the MLIR module.
|
||||
llvm::SourceMgr source_mgr;
|
||||
source_mgr.AddNewSourceBuffer(std::move(*file_or_err), llvm::SMLoc());
|
||||
return parseSourceFile(source_mgr, context);
|
||||
}
|
||||
|
||||
/// This parses the program string to a MLIR module if it was valid. If not,
|
||||
/// it emits diagnostics and returns null.
|
||||
Module *mlir::parseSourceString(StringRef moduleStr, MLIRContext *context) {
|
||||
|
|
Loading…
Reference in New Issue