2018-09-28 17:54:21 +02:00
|
|
|
// OpenSTA, Static Timing Analyzer
|
2026-03-10 21:21:17 +01:00
|
|
|
// Copyright (c) 2026, Parallax Software, Inc.
|
2026-03-15 22:35:24 +01:00
|
|
|
//
|
2018-09-28 17:54:21 +02: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 22:35:24 +01:00
|
|
|
//
|
2018-09-28 17:54:21 +02: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 18:17:08 +01:00
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2018-09-28 17:54:21 +02:00
|
|
|
// GNU General Public License for more details.
|
2026-03-15 22:35:24 +01:00
|
|
|
//
|
2018-09-28 17:54:21 +02:00
|
|
|
// You should have received a copy of the GNU General Public License
|
2022-01-04 18:17:08 +01:00
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2026-03-15 22:35:24 +01:00
|
|
|
//
|
2025-01-22 02:54:33 +01:00
|
|
|
// The origin of this software must not be misrepresented; you must not
|
|
|
|
|
// claim that you wrote the original software.
|
2026-03-15 22:35:24 +01:00
|
|
|
//
|
2025-01-22 02:54:33 +01:00
|
|
|
// Altered source versions must be plainly marked as such, and must not be
|
|
|
|
|
// misrepresented as being the original software.
|
2026-03-15 22:35:24 +01:00
|
|
|
//
|
2025-01-22 02:54:33 +01:00
|
|
|
// This notice may not be removed or altered from any source distribution.
|
2018-09-28 17:54:21 +02:00
|
|
|
|
2020-02-16 01:13:16 +01:00
|
|
|
#pragma once
|
2018-09-28 17:54:21 +02:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2023-06-15 17:59:56 +02:00
|
|
|
#include <cstdarg>
|
2018-09-28 17:54:21 +02:00
|
|
|
#include <string>
|
2026-03-15 22:35:24 +01:00
|
|
|
#include <string_view>
|
2020-04-12 18:46:30 +02:00
|
|
|
#include <mutex>
|
2025-01-17 20:20:19 +01:00
|
|
|
#include <set>
|
2023-06-15 17:59:56 +02:00
|
|
|
|
2026-03-15 22:35:24 +01:00
|
|
|
#include "Machine.hh" // __attribute__
|
|
|
|
|
#include "Format.hh"
|
2018-09-28 17:54:21 +02:00
|
|
|
|
2020-04-07 23:37:52 +02:00
|
|
|
struct Tcl_Interp;
|
|
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
namespace sta {
|
|
|
|
|
|
2026-03-15 22:35:24 +01:00
|
|
|
// Throws ExceptionMsg - implemented in Report.cc to avoid circular include with
|
|
|
|
|
// Error.hh
|
|
|
|
|
void
|
|
|
|
|
reportThrowExceptionMsg(const std::string &msg,
|
|
|
|
|
bool suppressed);
|
|
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
// Output streams used for printing.
|
|
|
|
|
// This is a wrapper for all printing. It supports logging output to
|
|
|
|
|
// a file and redirection of command output to a file.
|
|
|
|
|
class Report
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
Report();
|
|
|
|
|
virtual ~Report();
|
|
|
|
|
|
2026-03-15 22:35:24 +01:00
|
|
|
virtual void reportLine(const std::string &line);
|
2021-01-05 03:14:04 +01:00
|
|
|
virtual void reportBlankLine();
|
2020-12-20 01:27:29 +01:00
|
|
|
|
2026-03-15 22:35:24 +01:00
|
|
|
// Print formatted line using std::format (C++20).
|
|
|
|
|
template <typename... Args>
|
|
|
|
|
void report(std::string_view fmt,
|
|
|
|
|
Args &&...args)
|
|
|
|
|
{
|
|
|
|
|
reportLine(sta::vformat(fmt, sta::make_format_args(args...)));
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-20 01:27:29 +01:00
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
// Report warning.
|
2026-03-15 22:35:24 +01:00
|
|
|
template <typename... Args>
|
|
|
|
|
void warn(int id,
|
|
|
|
|
std::string_view fmt,
|
|
|
|
|
Args &&...args)
|
|
|
|
|
{
|
|
|
|
|
if (!isSuppressed(id)) {
|
|
|
|
|
reportLine(sta::format(
|
|
|
|
|
"Warning {}: {}", id, sta::vformat(fmt, sta::make_format_args(args...))));
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-09-28 17:54:21 +02:00
|
|
|
// Report warning in a file.
|
2026-03-15 22:35:24 +01:00
|
|
|
template <typename... Args>
|
|
|
|
|
void fileWarn(int id,
|
|
|
|
|
std::string_view filename,
|
|
|
|
|
int line,
|
|
|
|
|
std::string_view fmt,
|
|
|
|
|
Args &&...args)
|
|
|
|
|
{
|
|
|
|
|
if (!isSuppressed(id)) {
|
|
|
|
|
reportLine(
|
|
|
|
|
sta::format("Warning {}: {} line {}, {}", id, filename, line,
|
|
|
|
|
sta::vformat(fmt, sta::make_format_args(args...))));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
|
void error(int id,
|
|
|
|
|
std::string_view fmt,
|
|
|
|
|
Args &&...args)
|
|
|
|
|
{
|
|
|
|
|
std::string msg = sta::vformat(fmt, sta::make_format_args(args...));
|
|
|
|
|
reportThrowExceptionMsg(sta::format("{} {}", id, msg), isSuppressed(id));
|
|
|
|
|
}
|
2020-12-20 01:27:29 +01:00
|
|
|
// Report error in a file.
|
2026-03-15 22:35:24 +01:00
|
|
|
template <typename... Args>
|
|
|
|
|
void fileError(int id,
|
|
|
|
|
std::string_view filename,
|
|
|
|
|
int line,
|
|
|
|
|
std::string_view fmt,
|
|
|
|
|
Args &&...args)
|
|
|
|
|
{
|
|
|
|
|
const std::string msg = sta::vformat(fmt, sta::make_format_args(args...));
|
|
|
|
|
reportThrowExceptionMsg(sta::format("{} {} line {}, {}", id, filename, line, msg),
|
|
|
|
|
isSuppressed(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Critical.
|
2020-12-20 01:27:29 +01:00
|
|
|
// Report error condition that should not be possible or that prevents execution.
|
|
|
|
|
// The default handler prints msg to stderr and exits.
|
2026-03-15 22:35:24 +01:00
|
|
|
template <typename... Args>
|
|
|
|
|
void critical(int id,
|
|
|
|
|
std::string_view fmt,
|
|
|
|
|
Args &&...args)
|
|
|
|
|
{
|
|
|
|
|
reportLine(sta::format("Critical {}: {}", id,
|
|
|
|
|
sta::vformat(fmt, sta::make_format_args(args...))));
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
template <typename... Args>
|
|
|
|
|
void fileCritical(int id,
|
|
|
|
|
std::string_view filename,
|
|
|
|
|
int line,
|
|
|
|
|
std::string_view fmt,
|
|
|
|
|
Args &&...args)
|
|
|
|
|
{
|
|
|
|
|
reportLine(sta::format("Critical {}: {} line {}, {}", id, filename, line,
|
|
|
|
|
sta::vformat(fmt, sta::make_format_args(args...))));
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2020-12-14 02:21:35 +01:00
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
// Log output to filename until logEnd is called.
|
2026-03-18 21:01:05 +01:00
|
|
|
virtual void logBegin(std::string filename);
|
2018-09-28 17:54:21 +02:00
|
|
|
virtual void logEnd();
|
|
|
|
|
|
|
|
|
|
// Redirect output to filename until redirectFileEnd is called.
|
2026-03-18 21:01:05 +01:00
|
|
|
virtual void redirectFileBegin(std::string filename);
|
2018-09-28 17:54:21 +02:00
|
|
|
// Redirect append output to filename until redirectFileEnd is called.
|
2026-03-18 21:01:05 +01:00
|
|
|
virtual void redirectFileAppendBegin(std::string filename);
|
2018-09-28 17:54:21 +02:00
|
|
|
virtual void redirectFileEnd();
|
|
|
|
|
// Redirect output to a string until redirectStringEnd is called.
|
|
|
|
|
virtual void redirectStringBegin();
|
|
|
|
|
virtual const char *redirectStringEnd();
|
|
|
|
|
virtual void setTclInterp(Tcl_Interp *) {}
|
|
|
|
|
|
2020-12-31 04:51:50 +01:00
|
|
|
// Primitive to print output.
|
|
|
|
|
// Return the number of characters written.
|
|
|
|
|
// public for use by ReportTcl encapsulated channel functions.
|
|
|
|
|
virtual size_t printString(const char *buffer,
|
|
|
|
|
size_t length);
|
2020-12-14 02:21:35 +01:00
|
|
|
static Report *defaultReport() { return default_; }
|
|
|
|
|
|
2025-01-17 20:20:19 +01:00
|
|
|
// Suppress message by id.
|
|
|
|
|
void suppressMsgId(int id);
|
|
|
|
|
void unsuppressMsgId(int id);
|
2026-01-04 01:59:35 +01:00
|
|
|
[[nodiscard]] bool isSuppressed(int id);
|
2025-01-17 20:20:19 +01:00
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
protected:
|
2021-01-01 20:46:51 +01:00
|
|
|
// All sta print functions have an implicit return printed by this function.
|
2020-12-31 04:51:50 +01:00
|
|
|
virtual void printLine(const char *line,
|
|
|
|
|
size_t length);
|
2018-09-28 17:54:21 +02:00
|
|
|
// Primitive to print output on the console.
|
|
|
|
|
// Return the number of characters written.
|
2020-12-20 01:27:29 +01:00
|
|
|
virtual size_t printConsole(const char *buffer,
|
2021-01-04 00:35:14 +01:00
|
|
|
size_t length);
|
2026-03-15 22:35:24 +01:00
|
|
|
void printToBuffer(const char *fmt, ...) __attribute__((format(printf, 2, 3)));
|
2021-01-01 20:46:51 +01:00
|
|
|
|
2020-12-20 01:27:29 +01:00
|
|
|
void printToBuffer(const char *fmt,
|
|
|
|
|
va_list args);
|
2020-12-25 01:31:52 +01:00
|
|
|
void printToBufferAppend(const char *fmt,
|
|
|
|
|
...);
|
|
|
|
|
void printToBufferAppend(const char *fmt,
|
|
|
|
|
va_list args);
|
2020-12-31 04:51:50 +01:00
|
|
|
void printBufferLine();
|
2020-12-20 01:27:29 +01:00
|
|
|
void redirectStringPrint(const char *buffer,
|
|
|
|
|
size_t length);
|
2018-09-28 17:54:21 +02:00
|
|
|
|
|
|
|
|
FILE *log_stream_;
|
|
|
|
|
FILE *redirect_stream_;
|
|
|
|
|
bool redirect_to_string_;
|
2025-04-12 01:59:48 +02:00
|
|
|
std::string redirect_string_;
|
2018-09-28 17:54:21 +02:00
|
|
|
// Buffer to support printf style arguments.
|
|
|
|
|
size_t buffer_size_;
|
|
|
|
|
char *buffer_;
|
|
|
|
|
// Length of string in buffer.
|
|
|
|
|
size_t buffer_length_;
|
2020-04-12 18:46:30 +02:00
|
|
|
std::mutex buffer_lock_;
|
2020-12-14 02:21:35 +01:00
|
|
|
static Report *default_;
|
2025-01-17 20:20:19 +01:00
|
|
|
std::set<int> suppressed_msg_ids_;
|
2018-09-28 17:54:21 +02:00
|
|
|
|
2020-12-28 18:04:57 +01:00
|
|
|
friend class Debug;
|
2018-09-28 17:54:21 +02:00
|
|
|
};
|
|
|
|
|
|
2026-03-15 22:35:24 +01:00
|
|
|
} // namespace sta
|