Skip to content

Commit

Permalink
mv debug_on into Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
jjcherry56 committed Jan 5, 2021
1 parent ff3a4b1 commit 54dbbf6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
19 changes: 3 additions & 16 deletions include/sta/Debug.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ namespace sta {
class Report;
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;

class Debug
Expand All @@ -52,29 +47,21 @@ public:

protected:
Report *report_;
bool debug_on_;
DebugMap *debug_map_;
int stats_level_;

private:
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
// be expensive, so use a macro.
// Note that "##__VA_ARGS__" is a gcc extension to support zero arguments (no comma).
// 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.
#define debugPrint(debug, what, level, msg, ...) \
if (sta::debug_on && debug->check(what, level)) { \
#define debugPrint(debug, what, level, msg, ...) \
if (debug->check(what, level)) { \
debug->reportLine(what, msg, ##__VA_ARGS__); \
}

Expand Down
9 changes: 5 additions & 4 deletions util/Debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ bool debug_on = false;

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

Expand Down
4 changes: 2 additions & 2 deletions verilog/VerilogReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ VerilogReader::init(const char *filename)
if (library_ == nullptr)
library_ = network_->makeLibrary("verilog", nullptr);

report_stmt_stats_ = debugCheck(debug_, "verilog", 1);
report_stmt_stats_ = debug_->check("verilog", 1);
module_count_ = 0;
inst_mod_count_ = 0;
inst_lib_count_ = 0;
Expand Down Expand Up @@ -694,7 +694,7 @@ VerilogReader::incrLine()
void
VerilogReader::reportStmtCounts()
{
if (debugCheck(debug_, "verilog", 1)) {
if (debug_->check("verilog", 1)) {
report_->reportLine("Verilog stats");
printClassMemory("modules", VerilogModule, module_count_);
printClassMemory("module insts", VerilogModuleInst, inst_mod_count_);
Expand Down

0 comments on commit 54dbbf6

Please sign in to comment.