2018-09-28 17:54:21 +02:00
|
|
|
// OpenSTA, Static Timing Analyzer
|
2020-03-07 03:50:37 +01:00
|
|
|
// Copyright (c) 2020, Parallax Software, Inc.
|
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.
|
|
|
|
|
//
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
2020-02-16 01:13:16 +01:00
|
|
|
#pragma once
|
2018-09-28 17:54:21 +02:00
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
#include <string>
|
2020-04-12 18:46:30 +02:00
|
|
|
#include <mutex>
|
2020-07-19 04:54:10 +02:00
|
|
|
#include "Machine.hh"
|
2018-09-28 17:54:21 +02:00
|
|
|
#include "DisallowCopyAssign.hh"
|
|
|
|
|
|
2020-04-07 23:37:52 +02:00
|
|
|
struct Tcl_Interp;
|
|
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
namespace sta {
|
|
|
|
|
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
2020-12-26 01:55:46 +01:00
|
|
|
// Print line with return.
|
2020-12-31 04:51:50 +01:00
|
|
|
virtual void reportLine(const char *fmt, ...)
|
|
|
|
|
__attribute__((format (printf, 2, 3)));
|
2020-12-28 18:04:57 +01:00
|
|
|
virtual void reportLineString(const char *line);
|
2020-12-29 20:49:30 +01:00
|
|
|
virtual void reportLine(const string &line);
|
2020-12-20 01:27:29 +01:00
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
// Report warning.
|
2020-12-20 01:27:29 +01:00
|
|
|
virtual void warn(int id,
|
|
|
|
|
const char *fmt, ...)
|
2020-12-14 02:21:35 +01:00
|
|
|
__attribute__((format (printf, 3, 4)));
|
2020-12-25 23:00:11 +01:00
|
|
|
virtual void vwarn(int id,
|
|
|
|
|
const char *fmt,
|
|
|
|
|
va_list args);
|
2018-09-28 17:54:21 +02:00
|
|
|
// Report warning in a file.
|
2020-12-20 01:27:29 +01:00
|
|
|
virtual void fileWarn(int id,
|
|
|
|
|
const char *filename,
|
|
|
|
|
int line,
|
|
|
|
|
const char *fmt, ...)
|
2020-12-14 02:21:35 +01:00
|
|
|
__attribute__((format (printf, 5, 6)));
|
2020-12-20 01:27:29 +01:00
|
|
|
virtual void vfileWarn(int id,
|
|
|
|
|
const char *filename,
|
|
|
|
|
int line,
|
|
|
|
|
const char *fmt,
|
2020-12-25 23:00:11 +01:00
|
|
|
va_list args);
|
2018-09-28 17:54:21 +02:00
|
|
|
|
2020-12-20 01:27:29 +01:00
|
|
|
virtual void error(int id,
|
|
|
|
|
const char *fmt, ...)
|
2020-12-14 02:21:35 +01:00
|
|
|
__attribute__((format (printf, 3, 4)));
|
2020-12-25 23:00:11 +01:00
|
|
|
virtual void verror(int id,
|
|
|
|
|
const char *fmt,
|
|
|
|
|
va_list args);
|
2020-12-20 01:27:29 +01:00
|
|
|
// Report error in a file.
|
|
|
|
|
virtual void fileError(int id,
|
|
|
|
|
const char *filename,
|
|
|
|
|
int line,
|
|
|
|
|
const char *fmt, ...)
|
2020-12-14 02:21:35 +01:00
|
|
|
__attribute__((format (printf, 5, 6)));
|
2020-12-20 01:27:29 +01:00
|
|
|
virtual void vfileError(int id,
|
|
|
|
|
const char *filename,
|
|
|
|
|
int line,
|
|
|
|
|
const char *fmt,
|
2020-12-25 23:00:11 +01:00
|
|
|
va_list args);
|
2020-12-14 02:21:35 +01:00
|
|
|
|
2020-12-20 01:27:29 +01:00
|
|
|
// Critical.
|
|
|
|
|
// Report error condition that should not be possible or that prevents execution.
|
|
|
|
|
// The default handler prints msg to stderr and exits.
|
|
|
|
|
virtual void critical(int id,
|
|
|
|
|
const char *fmt,
|
|
|
|
|
...)
|
2020-12-14 02:21:35 +01:00
|
|
|
__attribute__((format (printf, 3, 4)));
|
2020-12-20 01:27:29 +01:00
|
|
|
virtual void fileCritical(int id,
|
|
|
|
|
const char *filename,
|
|
|
|
|
int line,
|
|
|
|
|
const char *fmt,
|
|
|
|
|
...)
|
2020-12-14 02:21:35 +01:00
|
|
|
__attribute__((format (printf, 5, 6)));
|
|
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
// Log output to filename until logEnd is called.
|
|
|
|
|
virtual void logBegin(const char *filename);
|
|
|
|
|
virtual void logEnd();
|
|
|
|
|
|
|
|
|
|
// Redirect output to filename until redirectFileEnd is called.
|
|
|
|
|
virtual void redirectFileBegin(const char *filename);
|
|
|
|
|
// Redirect append output to filename until redirectFileEnd is called.
|
|
|
|
|
virtual void redirectFileAppendBegin(const char *filename);
|
|
|
|
|
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_; }
|
|
|
|
|
|
2018-09-28 17:54:21 +02:00
|
|
|
protected:
|
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,
|
|
|
|
|
size_t length) = 0;
|
2020-12-25 01:31:52 +01:00
|
|
|
void printToBuffer(const char *fmt,
|
|
|
|
|
...);
|
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_;
|
|
|
|
|
string redirect_string_;
|
|
|
|
|
// 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_;
|
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
|
|
|
private:
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(Report);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace
|