Skip to content

Commit

Permalink
rm printError, Report::error throws exception
Browse files Browse the repository at this point in the history
  • Loading branch information
jjcherry56 committed Dec 25, 2020
1 parent 6fb6c93 commit 078d69f
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 186 deletions.
12 changes: 11 additions & 1 deletion include/sta/Error.hh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#pragma once

#include <exception>
#include "DisallowCopyAssign.hh"

#include "Report.hh"

namespace sta {
Expand All @@ -31,6 +31,16 @@ public:
virtual const char *what() const noexcept = 0;
};

class ExceptionMsg : public Exception
{
public:
ExceptionMsg(const char *msg);
virtual const char *what() const noexcept;

private:
string msg_;
};

class ExceptionLine : public Exception
{
public:
Expand Down
33 changes: 8 additions & 25 deletions include/sta/Report.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,7 @@ public:
va_list args);
void print(const string *str);
void print(const string &str);

// Print to debug stream (same as output stream).
virtual void printDebug(const char *fmt, ...)
__attribute__((format (printf, 2, 3)));
virtual void vprintDebug(const char *fmt,
va_list args);

// Print to error stream.
// Return the number of characters written.
virtual size_t printError(const char *buffer,
size_t length);
virtual void printError(const char *fmt, ...)
__attribute__((format (printf, 2, 3)));
virtual void vprintError(const char *fmt,
va_list args);

// Print to warning stream (same as error stream).
virtual void printWarn(const char *fmt, ...)
__attribute__((format (printf, 2, 3)));
virtual void vprintWarn(const char *fmt,
va_list args);
virtual void flush() {}

////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -137,12 +117,15 @@ protected:
// Return the number of characters written.
virtual size_t printConsole(const char *buffer,
size_t length) = 0;
// Primitive to print warning, error, critical and debug output.
// Return the number of characters written.
virtual size_t printErrorConsole(const char *buffer,
size_t length) = 0;
void printToBuffer(const char *fmt,
...);
void printToBuffer(const char *fmt,
va_list args);
void printToBufferAppend(const char *fmt,
...);
void printToBufferAppend(const char *fmt,
va_list args);
void printBuffer();
void redirectStringPrint(const char *buffer,
size_t length);

Expand Down
2 changes: 1 addition & 1 deletion include/sta/ReportTcl.hh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public:

protected:
virtual size_t printConsole(const char *buffer, size_t length);
virtual size_t printErrorConsole(const char *buffer, size_t length);
void flush();

private:
DISALLOW_COPY_AND_ASSIGN(ReportTcl);
Expand Down
12 changes: 6 additions & 6 deletions search/Genclks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ Genclks::ensureMaster(Clock *gclk)
iter.enqueueAdjacentVertices(vertex);
}
if (master_clk_count > 1)
report_->error(11, "generated clock %s is in the fanout of multiple clocks.",
gclk->name());
report_->warn(11, "generated clock %s is in the fanout of multiple clocks.",
gclk->name());
}
else {
Pin *src_pin = gclk->srcPin();
Expand Down Expand Up @@ -379,10 +379,10 @@ Genclks::ensureMaster(Clock *gclk)
}
}
if (master_clk_count > 1)
report_->error(12,
"generated clock %s pin %s is in the fanout of multiple clocks.",
gclk->name(),
network_->pathName(src_pin));
report_->warn(12,
"generated clock %s pin %s is in the fanout of multiple clocks.",
gclk->name(),
network_->pathName(src_pin));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion search/WritePathSpice.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,7 @@ WritePathSpice::writeSubckts()
report_->error(28, "The following subkcts are missing from %s",
lib_subckt_filename_);
for (const char *cell_name : path_cell_names)
report_->printError(" %s\n", cell_name);
report_->print(" %s\n", cell_name);
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion tcl/Exception.i
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
try { $function }
catch (std::bad_alloc &) {
fprintf(stderr, "Error: out of memory.\n");
exit(0);
exit(1);
}
catch (std::exception &excp) {
Tcl_ResetResult(interp);
Expand Down
43 changes: 23 additions & 20 deletions tcl/StaTcl.i
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,14 @@ pushPowerResultFloats(PowerResult &power,
////////////////////////////////////////////////////////////////

void
tclError(Tcl_Interp *interp,
const char *msg,
const char *arg)
{
char *error = stringPrint(msg, arg);
tclArgError(Tcl_Interp *interp,
const char *msg,
const char *arg)
{
// Swig does not add try/catch around arg parsing so this cannot use Report::error.
string error_msg = "Error: ";
error_msg += msg;
char *error = stringPrint(error_msg.c_str(), arg);
Tcl_SetResult(interp, error, TCL_VOLATILE);
stringDelete(error);
}
Expand Down Expand Up @@ -867,7 +870,7 @@ using namespace sta;
floats->push_back(static_cast<float>(value));
else {
delete floats;
tclError(interp, "Error: %s is not a floating point number.", arg);
tclArgError(interp, "%s is not a floating point number.", arg);
return TCL_ERROR;
}
}
Expand Down Expand Up @@ -915,7 +918,7 @@ using namespace sta;
ints->push_back(value);
else {
delete ints;
tclError(interp, "Error: %s is not an integer.", arg);
tclArgError(interp, "%s is not an integer.", arg);
return TCL_ERROR;
}
}
Expand All @@ -930,7 +933,7 @@ using namespace sta;
if (min_max)
$1 = min_max;
else {
tclError(interp, "Error: %s not min or max.", arg);
tclArgError(interp, "%s not min or max.", arg);
return TCL_ERROR;
}
}
Expand All @@ -950,7 +953,7 @@ using namespace sta;
if (min_max)
$1 = min_max;
else {
tclError(interp, "Error: %s not min, max or min_max.", arg);
tclArgError(interp, "%s not min, max or min_max.", arg);
return TCL_ERROR;
}
}
Expand All @@ -965,7 +968,7 @@ using namespace sta;
if (min_max)
$1 = min_max;
else {
tclError(interp, "Error: %s not min, max or min_max.", arg);
tclArgError(interp, "%s not min, max or min_max.", arg);
return TCL_ERROR;
}
}
Expand All @@ -986,7 +989,7 @@ using namespace sta;
|| stringEqual(arg, "max"))
$1 = MinMax::max();
else {
tclError(interp, "Error: %s not setup, hold, min or max.", arg);
tclArgError(interp, "%s not setup, hold, min or max.", arg);
return TCL_ERROR;
}
}
Expand All @@ -1005,7 +1008,7 @@ using namespace sta;
|| stringEqual(arg, "min_max"))
$1 = SetupHoldAll::all();
else {
tclError(interp, "Error: %s not setup, hold, setup_hold, min, max or min_max.", arg);
tclArgError(interp, "%s not setup, hold, setup_hold, min, max or min_max.", arg);
return TCL_ERROR;
}
}
Expand All @@ -1018,7 +1021,7 @@ using namespace sta;
if (early_late)
$1 = early_late;
else {
tclError(interp, "Error: %s not early/min or late/max.", arg);
tclArgError(interp, "%s not early/min, late/max or early_late/min_max.", arg);
return TCL_ERROR;
}
}
Expand All @@ -1031,7 +1034,7 @@ using namespace sta;
if (early_late)
$1 = early_late;
else {
tclError(interp, "Error: %s not early/min, late/max or early_late/min_max.", arg);
tclArgError(interp, "%s not early/min, late/max or early_late/min_max.", arg);
return TCL_ERROR;
}
}
Expand All @@ -1046,7 +1049,7 @@ using namespace sta;
else if (stringEq(arg, "cell_check"))
$1 = TimingDerateType::cell_check;
else {
tclError(interp, "Error: %s not clk or data.", arg);
tclArgError(interp, "%s not clk or data.", arg);
return TCL_ERROR;
}
}
Expand All @@ -1059,7 +1062,7 @@ using namespace sta;
else if (stringEq(arg, "data"))
$1 = PathClkOrData::data;
else {
tclError(interp, "Error: %s not clk or data.", arg);
tclArgError(interp, "%s not clk or data.", arg);
return TCL_ERROR;
}
}
Expand All @@ -1072,7 +1075,7 @@ using namespace sta;
else if (stringEq(arg, "slack"))
$1 = sort_by_slack;
else {
tclError(interp, "Error: %s not group or slack.", arg);
tclArgError(interp, "%s not group or slack.", arg);
return TCL_ERROR;
}
}
Expand All @@ -1097,7 +1100,7 @@ using namespace sta;
else if (stringEq(arg, "json"))
$1 = ReportPathFormat::json;
else {
tclError(interp, "Error: unknown path type %s.", arg);
tclArgError(interp, "unknown path type %s.", arg);
return TCL_ERROR;
}
}
Expand Down Expand Up @@ -1375,7 +1378,7 @@ using namespace sta;
else if (stringEq(arg, "none"))
$1 = ReducedParasiticType::none;
else {
tclError(interp, "Error: %s pi_elmore, pi_pole_residue2, or none.", arg);
tclArgError(interp, "%s pi_elmore, pi_pole_residue2, or none.", arg);
return TCL_ERROR;
}
}
Expand Down Expand Up @@ -1978,7 +1981,7 @@ redirect_string_end()
}

void
log_begin(const char *filename)
log_begin_cmd(const char *filename)
{
Sta::sta()->report()->logBegin(filename);
}
Expand Down
7 changes: 6 additions & 1 deletion tcl/Util.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,13 @@ proc write_stats { filename } {
################################################################

# Begin/end logging all output to a file.
define_cmd_args "log_begin" { filename }

proc log_begin { filename } {
log_begin_cmd [file nativename $filename]
}

# Defined by StaTcl.i
define_cmd_args "log_begin" {filename}
define_cmd_args "log_end" {}

# set_debug is NOT in the global namespace
Expand Down
4 changes: 2 additions & 2 deletions test/regression.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ proc run_test { test } {
incr errors(error)

# For some reason seg faults aren't echoed in the log - add them.
if [file exists $log_file] {
if { [llength $test_errors] > 1 && [file exists $log_file] } {
set log_ch [open $log_file "a"]
puts $log_ch "$test_errors"
puts $log_ch $test_errors
close $log_ch
}

Expand Down
2 changes: 1 addition & 1 deletion util/Debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Debug::print(const char *fmt,
{
va_list args;
va_start(args, fmt);
report_->vprintError(fmt, args);
report_->vprint(fmt, args);
va_end(args);
}

Expand Down
12 changes: 12 additions & 0 deletions util/Error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ Exception::Exception() :
{
}

ExceptionMsg::ExceptionMsg(const char *msg) :
Exception(),
msg_(msg)
{
}

const char *
ExceptionMsg::what() const noexcept
{
return msg_.c_str();
}

ExceptionLine::ExceptionLine(const char *filename,
int line) :
Exception(),
Expand Down
Loading

0 comments on commit 078d69f

Please sign in to comment.