Files
concrete/compiler/include/concretelang/Support/logging.h
youben11 2009ee1c94 chore: changing ref to repo after its renaming
also formatting and update the check_license script to match that
2022-01-06 12:40:10 +01:00

45 lines
1.3 KiB
C++

// Part of the Concrete Compiler Project, under the BSD3 License with Zama
// Exceptions. See
// https://github.com/zama-ai/concrete-compiler-internal/blob/master/LICENSE.txt
// for license information.
#ifndef CONCRETELANG_SUPPORT_LOGGING_H_
#define CONCRETELANG_SUPPORT_LOGGING_H_
#include <llvm/Support/raw_ostream.h>
namespace mlir {
namespace concretelang {
// 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);
bool isVerbose();
} // namespace concretelang
} // namespace mlir
#endif