mv debug_on into Debug

This commit is contained in:
James Cherry 2021-01-04 20:47:37 -08:00
parent ff3a4b17a4
commit 54dbbf625e
3 changed files with 10 additions and 22 deletions

View File

@ -27,11 +27,6 @@ namespace sta {
class Report; class Report;
class Pin; class Pin;
// Flag that is set when any debug mode is enabled.
// Debug macros bypass Debug::check map lookup unless some debug mode
// is enabled.
extern bool debug_on;
typedef Map<const char *, int, CharPtrLess> DebugMap; typedef Map<const char *, int, CharPtrLess> DebugMap;
class Debug class Debug
@ -52,6 +47,7 @@ public:
protected: protected:
Report *report_; Report *report_;
bool debug_on_;
DebugMap *debug_map_; DebugMap *debug_map_;
int stats_level_; int stats_level_;
@ -59,22 +55,13 @@ private:
DISALLOW_COPY_AND_ASSIGN(Debug); DISALLOW_COPY_AND_ASSIGN(Debug);
}; };
// Low overhead predicate.
inline bool
debugCheck(const Debug *debug,
const char *what,
int level)
{
return debug_on && debug->check(what, level);
}
// Inlining a varargs function would eval the args, which can // Inlining a varargs function would eval the args, which can
// be expensive, so use a macro. // be expensive, so use a macro.
// Note that "##__VA_ARGS__" is a gcc extension to support zero arguments (no comma). // Note that "##__VA_ARGS__" is a gcc extension to support zero arguments (no comma).
// clang -Wno-gnu-zero-variadic-macro-arguments suppresses the warning. // clang -Wno-gnu-zero-variadic-macro-arguments suppresses the warning.
// c++20 has "__VA_OPT__" to deal with the zero arg case so this is temporary. // c++20 has "__VA_OPT__" to deal with the zero arg case so this is temporary.
#define debugPrint(debug, what, level, msg, ...) \ #define debugPrint(debug, what, level, msg, ...) \
if (sta::debug_on && debug->check(what, level)) { \ if (debug->check(what, level)) { \
debug->reportLine(what, msg, ##__VA_ARGS__); \ debug->reportLine(what, msg, ##__VA_ARGS__); \
} }

View File

@ -24,6 +24,7 @@ bool debug_on = false;
Debug::Debug(Report *report) : Debug::Debug(Report *report) :
report_(report), report_(report),
debug_on_(false),
debug_map_(nullptr), debug_map_(nullptr),
stats_level_(0) stats_level_(0)
{ {
@ -48,7 +49,8 @@ bool
Debug::check(const char *what, Debug::check(const char *what,
int level) const int level) const
{ {
if (debug_map_) { if (debug_on_
&& debug_map_) {
int dbg_level; int dbg_level;
bool exists; bool exists;
debug_map_->findKey(what, dbg_level, exists); debug_map_->findKey(what, dbg_level, exists);
@ -88,8 +90,7 @@ Debug::setLevel(const char *what,
debug_map_->erase(what); debug_map_->erase(what);
delete [] key; delete [] key;
} }
// debugCheck map lookup bypass debug_on_ = !debug_map_->empty();
debug_on = (debug_map_->size() != 0);
} }
} }
else { else {
@ -98,7 +99,7 @@ Debug::setLevel(const char *what,
if (debug_map_ == nullptr) if (debug_map_ == nullptr)
debug_map_ = new DebugMap; debug_map_ = new DebugMap;
(*debug_map_)[what_cpy] = level; (*debug_map_)[what_cpy] = level;
debug_on = true; debug_on_ = true;
} }
} }

View File

@ -206,7 +206,7 @@ VerilogReader::init(const char *filename)
if (library_ == nullptr) if (library_ == nullptr)
library_ = network_->makeLibrary("verilog", nullptr); library_ = network_->makeLibrary("verilog", nullptr);
report_stmt_stats_ = debugCheck(debug_, "verilog", 1); report_stmt_stats_ = debug_->check("verilog", 1);
module_count_ = 0; module_count_ = 0;
inst_mod_count_ = 0; inst_mod_count_ = 0;
inst_lib_count_ = 0; inst_lib_count_ = 0;
@ -694,7 +694,7 @@ VerilogReader::incrLine()
void void
VerilogReader::reportStmtCounts() VerilogReader::reportStmtCounts()
{ {
if (debugCheck(debug_, "verilog", 1)) { if (debug_->check("verilog", 1)) {
report_->reportLine("Verilog stats"); report_->reportLine("Verilog stats");
printClassMemory("modules", VerilogModule, module_count_); printClassMemory("modules", VerilogModule, module_count_);
printClassMemory("module insts", VerilogModuleInst, inst_mod_count_); printClassMemory("module insts", VerilogModuleInst, inst_mod_count_);