mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 20:25:34 -05:00
feat(compiler): Add class StreamStringError with a stream interface for llvm::Error
Composing error messages for `llvm::Error` is either done by using
`llvm::createStringError()` with an appropriate format string and
arguments or by writing to a `std::string`-backed
`llvm::raw_string_ostream` and passing the result to
`llvm::make_error<llvm::StringError>()` verbatim.
The new class `StreamStringError` encapsulates the latter solution
into a class with an appropriate stream operator and implicit cast
operators to `llvm::Error` and `llvm::Expected`.
Example usage:
llvm::Error foo(int i, size_t s, ...) {
...
if(...) {
return StreamStringError()
<< "Some error message with an integer: "
<< i << " and a size_t: " << s;
}
...
}
This commit is contained in:
12
compiler/lib/Support/Error.cpp
Normal file
12
compiler/lib/Support/Error.cpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#include <zamalang/Support/Error.h>
|
||||
|
||||
namespace mlir {
|
||||
namespace zamalang {
|
||||
// Specialized `operator<<` for `llvm::Error` that marks the error
|
||||
// as checked through `std::move` and `llvm::toString`
|
||||
StreamStringError &operator<<(StreamStringError &se, llvm::Error &err) {
|
||||
se << llvm::toString(std::move(err));
|
||||
return se;
|
||||
}
|
||||
} // namespace zamalang
|
||||
} // namespace mlir
|
||||
Reference in New Issue
Block a user