mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
43cf36bfce
This commit introduces `revng_log`, a macro analagous to `revng_assert`, which basically allows to have the benefit of the `Logger` class without having to compute the expression to log if the logger is disabled. This commit also completely dismisses the `DBG` macro, converting all the old code to `Logger` + `revng_log`.
48 lines
1020 B
C++
48 lines
1020 B
C++
/// \file debug.cpp
|
|
/// \brief Implementation of the debug framework
|
|
|
|
//
|
|
// This file is distributed under the MIT License. See LICENSE.md for details.
|
|
//
|
|
|
|
// Standard includes
|
|
#include <algorithm>
|
|
#include <iostream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
// LLVM includes
|
|
#include "llvm/IR/Value.h"
|
|
|
|
// Local libraries includes
|
|
#include "revng/Support/Debug.h"
|
|
|
|
size_t MaxLoggerNameLength = 0;
|
|
LogTerminator DoLog;
|
|
llvm::ManagedStatic<LoggersRegistry> Loggers;
|
|
|
|
std::ostream &dbg(std::cerr);
|
|
|
|
Logger<> PassesLog("passes");
|
|
Logger<> ReleaseLog("release");
|
|
|
|
template<bool X>
|
|
void Logger<X>::emit() {
|
|
if (X && Enabled) {
|
|
std::string Pad = std::string(MaxLoggerNameLength - Name.size(), ' ');
|
|
dbg << "[" << Name.data() << Pad << "] ";
|
|
for (unsigned I = 0; I < IndentLevel; I++)
|
|
dbg << " ";
|
|
dbg << Buffer.str() << "\n";
|
|
Buffer.str("");
|
|
Buffer.clear();
|
|
}
|
|
}
|
|
|
|
template<bool X>
|
|
unsigned Logger<X>::IndentLevel;
|
|
|
|
// Force instantiation
|
|
template class Logger<true>;
|
|
template class Logger<false>;
|