mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-10 04:35:03 -05:00
enhance(compiler): CompilerEngine: Forward parse errors instead of printing them
By default, `mlir::SourceMgrDiagnosticVerifierHandler` used by `CompilerEngine::compile()` prints parse errors to `llvm::errs()`. This makes it impossible for a caller of `CompilerEngine::compile()` to process parse errors or to suppress the emission of error messages to the standard error stream altogether. This change captures parse errors in a string via a string-backed output stream and forwards the error message in the `llvm::Error` instance of the return value.
This commit is contained in:
@@ -150,11 +150,15 @@ llvm::Error CompilerEngine::determineFHEParameters(CompilationResult &res) {
|
||||
// on the target dialect.
|
||||
llvm::Expected<CompilerEngine::CompilationResult>
|
||||
CompilerEngine::compile(llvm::SourceMgr &sm, Target target) {
|
||||
std::string diagnosticsMsg;
|
||||
llvm::raw_string_ostream diagnosticsOS(diagnosticsMsg);
|
||||
|
||||
CompilationResult res(this->compilationContext);
|
||||
|
||||
mlir::MLIRContext &mlirContext = *this->compilationContext->getMLIRContext();
|
||||
|
||||
mlir::SourceMgrDiagnosticVerifierHandler smHandler(sm, &mlirContext);
|
||||
mlir::SourceMgrDiagnosticVerifierHandler smHandler(sm, &mlirContext,
|
||||
diagnosticsOS);
|
||||
mlirContext.printOpOnDiagnostic(false);
|
||||
|
||||
mlir::OwningModuleRef mlirModuleRef =
|
||||
@@ -167,8 +171,11 @@ CompilerEngine::compile(llvm::SourceMgr &sm, Target target) {
|
||||
return res;
|
||||
}
|
||||
|
||||
if (!mlirModuleRef)
|
||||
return StreamStringError("Could not parse source");
|
||||
if (!mlirModuleRef) {
|
||||
diagnosticsOS.flush();
|
||||
return StreamStringError("Could not parse source")
|
||||
<< (diagnosticsMsg.empty() ? "" : ": ") << diagnosticsMsg;
|
||||
}
|
||||
|
||||
res.mlirModuleRef = std::move(mlirModuleRef);
|
||||
mlir::ModuleOp module = res.mlirModuleRef->get();
|
||||
|
||||
Reference in New Issue
Block a user