Files
OpenSTA/util/Debug.cc
T

121 lines
2.6 KiB
C++
Raw Normal View History

2018-09-28 08:54:21 -07:00
// OpenSTA, Static Timing Analyzer
2023-02-18 17:55:40 -07:00
// Copyright (c) 2023, Parallax Software, Inc.
2018-09-28 08:54:21 -07:00
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
2022-01-04 10:17:08 -07:00
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2018-09-28 08:54:21 -07:00
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
2022-01-04 10:17:08 -07:00
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-09-28 08:54:21 -07:00
2020-04-05 14:53:44 -07:00
#include "Debug.hh"
2020-04-05 11:35:51 -07:00
2020-04-05 14:53:44 -07:00
#include "Report.hh"
2018-09-28 08:54:21 -07:00
namespace sta {
bool debug_on = false;
2020-12-29 11:13:12 -08:00
Debug::Debug(Report *report) :
2018-09-28 08:54:21 -07:00
report_(report),
2021-01-04 20:47:37 -08:00
debug_on_(false),
2019-03-12 17:25:53 -07:00
debug_map_(nullptr),
2018-09-28 08:54:21 -07:00
stats_level_(0)
{
}
Debug::~Debug()
{
if (debug_map_) {
DebugMap::Iterator debug_iter(debug_map_);
// Delete the debug map keys.
while (debug_iter.hasNext()) {
const char *what;
int level;
debug_iter.next(what, level);
delete [] what;
}
delete debug_map_;
}
}
bool
Debug::check(const char *what,
int level) const
{
2021-01-04 20:47:37 -08:00
if (debug_on_
&& debug_map_) {
2018-09-28 08:54:21 -07:00
int dbg_level;
bool exists;
debug_map_->findKey(what, dbg_level, exists);
if (exists)
return dbg_level >= level;
}
return false;
}
int
Debug::level(const char *what)
{
if (debug_map_) {
2020-12-28 09:04:57 -08:00
const char *key;
int dbg_level;
bool exists;
debug_map_->findKey(what, key, dbg_level, exists);
if (exists)
return dbg_level;
2018-09-28 08:54:21 -07:00
}
return 0;
}
void
Debug::setLevel(const char *what,
int level)
{
if (stringEq(what, "stats"))
stats_level_ = level;
else if (level == 0) {
if (debug_map_) {
int dbg_level;
bool exists;
const char *key;
debug_map_->findKey(what, key, dbg_level, exists);
if (exists) {
debug_map_->erase(what);
2018-09-28 08:54:21 -07:00
delete [] key;
}
2021-01-04 20:47:37 -08:00
debug_on_ = !debug_map_->empty();
2018-09-28 08:54:21 -07:00
}
}
else {
char *what_cpy = new char[strlen(what) + 1];
strcpy(what_cpy, what);
2019-03-12 17:25:53 -07:00
if (debug_map_ == nullptr)
2018-09-28 08:54:21 -07:00
debug_map_ = new DebugMap;
(*debug_map_)[what_cpy] = level;
2021-01-04 20:47:37 -08:00
debug_on_ = true;
2018-09-28 08:54:21 -07:00
}
}
2020-12-28 09:04:57 -08:00
void
Debug::reportLine(const char *what,
const char *fmt,
...) const
{
va_list args;
va_start(args, fmt);
2021-01-03 15:35:14 -08:00
report_->printToBuffer("%s", what);
2020-12-28 09:04:57 -08:00
report_->printToBufferAppend(": ");
report_->printToBufferAppend(fmt, args);
report_->printBufferLine();
va_end(args);
2020-12-28 09:04:57 -08:00
}
2018-09-28 08:54:21 -07:00
} // namespace