mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-10 04:35:03 -05:00
Replace the macros `LOG_VERBOSE` and `LOG_ERROR` with C++-style streams retrieved through `log_verbose()` and `log_error()`. This aligns with the `MLIR` infrastructure and avoids pollution of the global namespace through a common header file in subsequent refactoring commits splitting the functionality of `src/main.cpp` into multiple files.
39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
#ifndef ZAMALANG_SUPPORT_LOGGING_H_
|
|
#define ZAMALANG_SUPPORT_LOGGING_H_
|
|
|
|
#include <llvm/Support/raw_ostream.h>
|
|
|
|
namespace mlir {
|
|
namespace zamalang {
|
|
|
|
// Returning references to instances of different classes `S` and `T`
|
|
// is prohibited, even if `T` inherits from `S`. The wrapper class
|
|
// `StreamWrap` can be initialized with a pointer to an instance of
|
|
// `S` or any of its subclasses and acts as a proxy transparently
|
|
// forwarding all calls to `S::operator<<`. The class thus hides the
|
|
// dereferencing of the pointer and a reference to it can be used as a
|
|
// replacement for a reference to `S`.
|
|
template <class S> class StreamWrap {
|
|
public:
|
|
StreamWrap() = delete;
|
|
StreamWrap(S *s) : s(s) {}
|
|
|
|
// Forward all invocations of
|
|
// `StreamWrap<S>::operator<<` to S::operator<<`.
|
|
template <class T> StreamWrap<S> &operator<<(const T &v) {
|
|
*this->s << v;
|
|
return *this;
|
|
}
|
|
|
|
private:
|
|
S *s = nullptr;
|
|
};
|
|
|
|
StreamWrap<llvm::raw_ostream> &log_error(void);
|
|
StreamWrap<llvm::raw_ostream> &log_verbose(void);
|
|
void setupLogging(bool verbose);
|
|
} // namespace zamalang
|
|
} // namespace mlir
|
|
|
|
#endif
|