diff --git a/doc/ChangeLog.txt b/doc/ChangeLog.txt index 1e3ab820..41a1c6a3 100644 --- a/doc/ChangeLog.txt +++ b/doc/ChangeLog.txt @@ -31,11 +31,14 @@ is now supported by the the read_saif command. read_saif [-scope scope] filename The report_checks -group_count option has been renamed to -group_path_count. -The report_checks -endpoing_count option has been renamed to -endpoint_path_count. +The report_checks -endpoint_count option has been renamed to -endpoint_path_count. -The report_checks -field hierarchical_pins field reports hierarical pins between +The report_checks -field hierarchical_pins field reports hierarchical pins between a driver and a load in the path report. +The suppress_msg and unsuppress_msg commands allow suppression/unsuppression of +warnings/errors by ID. Message IDs can be found in doc/messages.txt. + Release 2.5.0 2024/01/17 ------------------------- diff --git a/doc/OpenSTA.odt b/doc/OpenSTA.odt index 4f46ae8c..6753d508 100644 Binary files a/doc/OpenSTA.odt and b/doc/OpenSTA.odt differ diff --git a/doc/OpenSTA.pdf b/doc/OpenSTA.pdf index b4f81586..1b00712c 100644 Binary files a/doc/OpenSTA.pdf and b/doc/OpenSTA.pdf differ diff --git a/include/sta/Error.hh b/include/sta/Error.hh index 8111c58a..11acb441 100644 --- a/include/sta/Error.hh +++ b/include/sta/Error.hh @@ -34,11 +34,14 @@ public: class ExceptionMsg : public Exception { public: - ExceptionMsg(const char *msg); + ExceptionMsg(const char *msg, + const bool suppressed); virtual const char *what() const noexcept; + virtual bool suppressed() const { return suppressed_; } private: string msg_; + bool suppressed_; }; class ExceptionLine : public Exception diff --git a/include/sta/Report.hh b/include/sta/Report.hh index 8e74494d..3cb5766e 100644 --- a/include/sta/Report.hh +++ b/include/sta/Report.hh @@ -20,6 +20,7 @@ #include #include #include +#include #include "Machine.hh" // __attribute__ @@ -119,6 +120,11 @@ public: size_t length); static Report *defaultReport() { return default_; } + // Suppress message by id. + void suppressMsgId(int id); + void unsuppressMsgId(int id); + bool isSuppressed(int id); + protected: // All sta print functions have an implicit return printed by this function. virtual void printLine(const char *line, @@ -152,6 +158,7 @@ protected: size_t buffer_length_; std::mutex buffer_lock_; static Report *default_; + std::set suppressed_msg_ids_; friend class Debug; }; diff --git a/tcl/Exception.i b/tcl/Exception.i index 1f4cfdc3..2211c529 100644 --- a/tcl/Exception.i +++ b/tcl/Exception.i @@ -20,6 +20,13 @@ fprintf(stderr, "Error: out of memory.\n"); exit(1); } + catch (ExceptionMsg &excp) { + if (!excp.suppressed()) { + Tcl_ResetResult(interp); + Tcl_AppendResult(interp, "Error: ", excp.what(), nullptr); + } + return TCL_ERROR; + } catch (std::exception &excp) { Tcl_ResetResult(interp); Tcl_AppendResult(interp, "Error: ", excp.what(), nullptr); diff --git a/tcl/Util.tcl b/tcl/Util.tcl index f233bf47..5f35d8a7 100644 --- a/tcl/Util.tcl +++ b/tcl/Util.tcl @@ -192,10 +192,13 @@ proc sta_warn { msg_id msg } { proc sta_error { msg_id msg } { variable sdc_file variable sdc_line - if { [info exists sdc_file] } { - error "Error: [file tail $sdc_file] line $sdc_line, $msg" - } else { - error "Error: $msg" + + if { ! [is_suppressed $msg_id] } { + if { [info exists sdc_file] } { + error "Error: [file tail $sdc_file] line $sdc_line, $msg" + } else { + error "Error: $msg" + } } } @@ -207,6 +210,24 @@ proc sta_warn_error { msg_id warn_error msg } { } } +define_cmd_args "suppress_msg" msg_ids + +proc suppress_msg { args } { + foreach msg_id $args { + check_integer "msg_id" $msg_id + suppress_msg_id $msg_id + } +} + +define_cmd_args "unsuppress_msg" msg_ids + +proc unsuppress_msg { args } { + foreach msg_id $args { + check_integer "msg_id" $msg_id + unsuppress_msg_id $msg_id + } +} + # Defined by StaTcl.i define_cmd_args "elapsed_run_time" {} define_cmd_args "user_run_time" {} diff --git a/test/regression_vars.tcl b/test/regression_vars.tcl index b400634a..40f08d79 100644 --- a/test/regression_vars.tcl +++ b/test/regression_vars.tcl @@ -135,6 +135,7 @@ record_sta_tests { report_checks_src_attr report_json1 report_json2 + suppress_msg verilog_attribute } diff --git a/test/suppress_msg.ok b/test/suppress_msg.ok new file mode 100644 index 00000000..1e892fe8 --- /dev/null +++ b/test/suppress_msg.ok @@ -0,0 +1,12 @@ +Warning: suppress_msg.tcl line 18, cmd warn 1 +caught Error: suppress_msg.tcl line 18, cmd error 1 +Warning: cmd warn 2 +caught Error: cmd error 2 +after error +caught +caught +after error +Warning: suppress_msg.tcl line 51, cmd warn 7 +caught Error: suppress_msg.tcl line 51, cmd error 7 +Warning: cmd warn 8 +caught Error: cmd error 8 diff --git a/test/suppress_msg.tcl b/test/suppress_msg.tcl new file mode 100644 index 00000000..3f4585a3 --- /dev/null +++ b/test/suppress_msg.tcl @@ -0,0 +1,56 @@ +# suppress and unsuppress message ids + +# Run sta_warn/sta_error to test TCL side suppression +proc sta_cmd { msg } { + sta::sta_warn 1 "cmd warn $msg" + sta::sta_error 2 "cmd error $msg" + puts "after error" +} + +# Run report_warn/report_error to test C++ side suppression +proc report_cmd { msg } { + sta::report_warn 1 "cmd warn $msg" + sta::report_error 2 "cmd error $msg" + puts "after error" +} + +# Ensure that TCL side messages are displayed as usual +catch { sta_cmd 1 } error +puts "caught $error" + +# Ensure that C++ side messages are displayed as usual +catch { report_cmd 2 } error +puts "caught $error" + +# Suppress messages +suppress_msg 1 2 + +# Ensure that TCL side messages are suppressed +catch { sta_cmd 3 } error +puts "caught $error" + +# Ensure that C++ side messages are suppressed +catch { report_cmd 4 } error +puts "caught $error" + +# Continue on error to avoid having to catch +set sta_continue_on_error 1 + +# Ensure that TCL side messages are suppressed +# TCL side will make it to "after error" +sta_cmd 5 + +# Ensure that C++ side messages are suppressed +# C++ will not make it to "after error" as the whole cmd is cancelled +report_cmd 6 + +# Unsuppress messages +unsuppress_msg 1 2 + +# Ensure that TCL side messages are displayed as usual +catch { sta_cmd 7 } error +puts "caught $error" + +# Ensure that C++ side messages are displayed as usual +catch { report_cmd 8 } error +puts "caught $error" diff --git a/util/Error.cc b/util/Error.cc index f1738904..06d24073 100644 --- a/util/Error.cc +++ b/util/Error.cc @@ -28,9 +28,11 @@ Exception::Exception() : { } -ExceptionMsg::ExceptionMsg(const char *msg) : +ExceptionMsg::ExceptionMsg(const char *msg, + const bool suppressed) : Exception(), - msg_(msg) + msg_(msg), + suppressed_(suppressed) { } diff --git a/util/Report.cc b/util/Report.cc index 3b203ad6..2c2f0b4e 100644 --- a/util/Report.cc +++ b/util/Report.cc @@ -169,59 +169,71 @@ Report::printBufferLine() //////////////////////////////////////////////////////////////// void -Report::warn(int /* id */, +Report::warn(int id, const char *fmt, ...) { - va_list args; - va_start(args, fmt); - printToBuffer("Warning: "); - printToBufferAppend(fmt, args); - printBufferLine(); - va_end(args); + // Skip suppressed messages. + if (!isSuppressed(id)) { + va_list args; + va_start(args, fmt); + printToBuffer("Warning: "); + printToBufferAppend(fmt, args); + printBufferLine(); + va_end(args); + } } void -Report::vwarn(int /* id */, +Report::vwarn(int id, const char *fmt, va_list args) { - printToBuffer("Warning: "); - printToBufferAppend(fmt, args); - printBufferLine(); + // Skip suppressed messages. + if (!isSuppressed(id)) { + printToBuffer("Warning: "); + printToBufferAppend(fmt, args); + printBufferLine(); + } } void -Report::fileWarn(int /* id */, +Report::fileWarn(int id, const char *filename, int line, const char *fmt, ...) { - va_list args; - va_start(args, fmt); - printToBuffer("Warning: %s line %d, ", filename, line); - printToBufferAppend(fmt, args); - printBufferLine(); - va_end(args); + // Skip suppressed messages. + if (!isSuppressed(id)) { + va_list args; + va_start(args, fmt); + printToBuffer("Warning: %s line %d, ", filename, line); + printToBufferAppend(fmt, args); + printBufferLine(); + va_end(args); + } } void -Report::vfileWarn(int /* id */, +Report::vfileWarn(int id, const char *filename, int line, const char *fmt, va_list args) { - printToBuffer("Warning: %s line %d, ", filename, line); - printToBufferAppend(fmt, args); - printBufferLine(); + // Skip suppressed messages. + if (!isSuppressed(id)) { + printToBuffer("Warning: %s line %d, ", filename, line); + printToBufferAppend(fmt, args); + printBufferLine(); + } } //////////////////////////////////////////////////////////////// void -Report::error(int /* id */, +Report::error(int id, const char *fmt, ...) { va_list args; @@ -229,21 +241,21 @@ Report::error(int /* id */, // No prefix msg, no \n. printToBuffer(fmt, args); va_end(args); - throw ExceptionMsg(buffer_); + throw ExceptionMsg(buffer_, isSuppressed(id)); } void -Report::verror(int /* id */, +Report::verror(int id, const char *fmt, va_list args) { // No prefix msg, no \n. printToBuffer(fmt, args); - throw ExceptionMsg(buffer_); + throw ExceptionMsg(buffer_, isSuppressed(id)); } void -Report::fileError(int /* id */, +Report::fileError(int id, const char *filename, int line, const char *fmt, @@ -255,11 +267,11 @@ Report::fileError(int /* id */, printToBuffer("%s line %d, ", filename, line); printToBufferAppend(fmt, args); va_end(args); - throw ExceptionMsg(buffer_); + throw ExceptionMsg(buffer_, isSuppressed(id)); } void -Report::vfileError(int /* id */, +Report::vfileError(int id, const char *filename, int line, const char *fmt, @@ -268,7 +280,7 @@ Report::vfileError(int /* id */, // No prefix msg, no \n. printToBuffer("%s line %d, ", filename, line); printToBufferAppend(fmt, args); - throw ExceptionMsg(buffer_); + throw ExceptionMsg(buffer_, isSuppressed(id)); } //////////////////////////////////////////////////////////////// @@ -304,6 +316,26 @@ Report::fileCritical(int /* id */, //////////////////////////////////////////////////////////////// +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) +{ + return suppressed_msg_ids_.find(id) != suppressed_msg_ids_.end(); +} + +//////////////////////////////////////////////////////////////// + void Report::logBegin(const char *filename) { diff --git a/util/Util.i b/util/Util.i index e149c2f6..5ae1f6c6 100644 --- a/util/Util.i +++ b/util/Util.i @@ -148,6 +148,24 @@ report_line(const char *msg) printf("%s\n", msg); } +void +suppress_msg_id(int id) +{ + Sta::sta()->report()->suppressMsgId(id); +} + +void +unsuppress_msg_id(int id) +{ + Sta::sta()->report()->unsuppressMsgId(id); +} + +int +is_suppressed(int id) +{ + return Sta::sta()->report()->isSuppressed(id); +} + void fflush() {