2018-09-28 08:54:21 -07:00
|
|
|
// OpenSTA, Static Timing Analyzer
|
2026-03-10 13:21:17 -07:00
|
|
|
// Copyright (c) 2026, Parallax Software, Inc.
|
2026-03-15 14:35:24 -07:00
|
|
|
//
|
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.
|
2026-03-15 14:35:24 -07:00
|
|
|
//
|
2018-09-28 08:54:21 -07:00
|
|
|
// 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.
|
2026-03-15 14:35:24 -07:00
|
|
|
//
|
2018-09-28 08:54:21 -07:00
|
|
|
// 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/>.
|
2026-03-15 14:35:24 -07:00
|
|
|
//
|
2025-01-21 18:54:33 -07:00
|
|
|
// The origin of this software must not be misrepresented; you must not
|
|
|
|
|
// claim that you wrote the original software.
|
2026-03-15 14:35:24 -07:00
|
|
|
//
|
2025-01-21 18:54:33 -07:00
|
|
|
// Altered source versions must be plainly marked as such, and must not be
|
|
|
|
|
// misrepresented as being the original software.
|
2026-03-15 14:35:24 -07:00
|
|
|
//
|
2025-01-21 18:54:33 -07:00
|
|
|
// This notice may not be removed or altered from any source distribution.
|
2018-09-28 08:54:21 -07:00
|
|
|
|
2020-04-05 14:53:44 -07:00
|
|
|
#include "Report.hh"
|
2020-04-05 11:35:51 -07:00
|
|
|
|
2026-03-15 14:35:24 -07:00
|
|
|
#include <algorithm> // min
|
|
|
|
|
#include <cstdlib> // exit
|
|
|
|
|
#include <cstring> // strlen
|
2020-04-05 11:35:51 -07:00
|
|
|
|
2020-04-05 14:53:44 -07:00
|
|
|
#include "Error.hh"
|
2026-03-15 14:35:24 -07:00
|
|
|
#include "Format.hh"
|
2026-04-13 14:58:16 -07:00
|
|
|
#include "Machine.hh"
|
2018-09-28 08:54:21 -07:00
|
|
|
|
|
|
|
|
namespace sta {
|
|
|
|
|
|
2020-12-13 18:21:35 -07:00
|
|
|
Report *Report::default_ = nullptr;
|
|
|
|
|
|
2026-04-13 14:58:16 -07:00
|
|
|
Report::Report()
|
2018-09-28 08:54:21 -07:00
|
|
|
{
|
2020-12-13 18:21:35 -07:00
|
|
|
default_ = this;
|
2018-09-28 08:54:21 -07:00
|
|
|
}
|
|
|
|
|
|
2021-01-03 15:35:14 -08:00
|
|
|
size_t
|
|
|
|
|
Report::printConsole(const char *buffer,
|
|
|
|
|
size_t length)
|
|
|
|
|
{
|
|
|
|
|
printf("%s", buffer);
|
|
|
|
|
return length;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-30 19:51:50 -08:00
|
|
|
void
|
|
|
|
|
Report::printLine(const char *line,
|
|
|
|
|
size_t length)
|
|
|
|
|
{
|
|
|
|
|
printString(line, length);
|
|
|
|
|
printString("\n", 1);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-28 08:54:21 -07:00
|
|
|
size_t
|
2020-12-19 17:27:29 -07:00
|
|
|
Report::printString(const char *buffer,
|
|
|
|
|
size_t length)
|
2018-09-28 08:54:21 -07:00
|
|
|
{
|
|
|
|
|
size_t ret = length;
|
|
|
|
|
if (redirect_to_string_)
|
|
|
|
|
redirectStringPrint(buffer, length);
|
|
|
|
|
else {
|
|
|
|
|
if (redirect_stream_)
|
2026-03-02 12:13:13 -08:00
|
|
|
ret = std::min(ret, fwrite(buffer, sizeof(char), length, redirect_stream_));
|
2018-09-28 08:54:21 -07:00
|
|
|
else
|
2026-03-02 12:13:13 -08:00
|
|
|
ret = std::min(ret, printConsole(buffer, length));
|
2018-09-28 08:54:21 -07:00
|
|
|
if (log_stream_)
|
2026-03-02 12:13:13 -08:00
|
|
|
ret = std::min(ret, fwrite(buffer, sizeof(char), length, log_stream_));
|
2018-09-28 08:54:21 -07:00
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-04 18:14:04 -08:00
|
|
|
void
|
|
|
|
|
Report::reportBlankLine()
|
|
|
|
|
{
|
|
|
|
|
printLine("", 0);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-25 16:55:46 -08:00
|
|
|
void
|
2026-03-15 14:35:24 -07:00
|
|
|
Report::reportLine(const std::string &line)
|
2020-12-28 18:04:49 -08:00
|
|
|
{
|
2020-12-30 19:51:50 -08:00
|
|
|
printLine(line.c_str(), line.length());
|
2020-12-28 18:04:49 -08:00
|
|
|
}
|
|
|
|
|
|
2020-12-13 18:21:35 -07:00
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2018-09-28 08:54:21 -07:00
|
|
|
void
|
2026-03-15 14:35:24 -07:00
|
|
|
reportThrowExceptionMsg(const std::string &msg,
|
|
|
|
|
bool suppressed)
|
2018-09-28 08:54:21 -07:00
|
|
|
{
|
2026-03-15 14:35:24 -07:00
|
|
|
throw ExceptionMsg(msg, suppressed);
|
2018-09-28 08:54:21 -07:00
|
|
|
}
|
|
|
|
|
|
2020-12-13 18:21:35 -07:00
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2025-01-17 11:20:19 -08:00
|
|
|
void
|
|
|
|
|
Report::suppressMsgId(int id)
|
|
|
|
|
{
|
|
|
|
|
suppressed_msg_ids_.insert(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Report::unsuppressMsgId(int id)
|
|
|
|
|
{
|
|
|
|
|
suppressed_msg_ids_.erase(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
Report::isSuppressed(int id)
|
|
|
|
|
{
|
2026-01-03 16:59:35 -08:00
|
|
|
return suppressed_msg_ids_.contains(id);
|
2025-01-17 11:20:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2018-09-28 08:54:21 -07:00
|
|
|
void
|
2026-03-28 19:13:35 -07:00
|
|
|
Report::logBegin(std::string_view filename)
|
2018-09-28 08:54:21 -07:00
|
|
|
{
|
2026-03-28 19:13:35 -07:00
|
|
|
log_stream_ = fopen(std::string(filename).c_str(), "w");
|
2019-03-12 17:25:53 -07:00
|
|
|
if (log_stream_ == nullptr)
|
2026-03-28 19:13:35 -07:00
|
|
|
throw FileNotWritable(filename);
|
2018-09-28 08:54:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Report::logEnd()
|
|
|
|
|
{
|
|
|
|
|
if (log_stream_)
|
|
|
|
|
fclose(log_stream_);
|
2019-03-12 17:25:53 -07:00
|
|
|
log_stream_ = nullptr;
|
2018-09-28 08:54:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2026-03-28 19:13:35 -07:00
|
|
|
Report::redirectFileBegin(std::string_view filename)
|
2018-09-28 08:54:21 -07:00
|
|
|
{
|
2026-03-28 19:13:35 -07:00
|
|
|
redirect_stream_ = fopen(std::string(filename).c_str(), "w");
|
2019-03-12 17:25:53 -07:00
|
|
|
if (redirect_stream_ == nullptr)
|
2026-03-28 19:13:35 -07:00
|
|
|
throw FileNotWritable(filename);
|
2018-09-28 08:54:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2026-03-28 19:13:35 -07:00
|
|
|
Report::redirectFileAppendBegin(std::string_view filename)
|
2018-09-28 08:54:21 -07:00
|
|
|
{
|
2026-03-28 19:13:35 -07:00
|
|
|
redirect_stream_ = fopen(std::string(filename).c_str(), "a");
|
2019-03-12 17:25:53 -07:00
|
|
|
if (redirect_stream_ == nullptr)
|
2026-03-28 19:13:35 -07:00
|
|
|
throw FileNotWritable(filename);
|
2018-09-28 08:54:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Report::redirectFileEnd()
|
|
|
|
|
{
|
|
|
|
|
if (redirect_stream_)
|
|
|
|
|
fclose(redirect_stream_);
|
2019-03-12 17:25:53 -07:00
|
|
|
redirect_stream_ = nullptr;
|
2018-09-28 08:54:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
Report::redirectStringBegin()
|
|
|
|
|
{
|
|
|
|
|
redirect_to_string_ = true;
|
|
|
|
|
redirect_string_.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *
|
|
|
|
|
Report::redirectStringEnd()
|
|
|
|
|
{
|
|
|
|
|
redirect_to_string_ = false;
|
|
|
|
|
return redirect_string_.c_str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2020-12-19 17:27:29 -07:00
|
|
|
Report::redirectStringPrint(const char *buffer,
|
|
|
|
|
size_t length)
|
2018-09-28 08:54:21 -07:00
|
|
|
{
|
|
|
|
|
redirect_string_.append(buffer, length);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-15 14:35:24 -07:00
|
|
|
} // namespace sta
|