msg: Make tclArgError use report logger, accept msg id and be parsed by FindMessages. (#216)

Signed-off-by: Christian Costa <titan.costa@gmail.com>
This commit is contained in:
Christian Costa 2025-02-15 00:33:16 +01:00 committed by GitHub
parent e7e80ca6c2
commit 591eb9b351
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 38 additions and 44 deletions

View File

@ -41,7 +41,7 @@ proc scan_file { file warn_regexp } {
set file_line 1 set file_line 1
while { ![eof $in_stream] } { while { ![eof $in_stream] } {
if { [regexp -- $warn_regexp $line ignore1 ignore2 msg_id msg] } { if { [regexp -- $warn_regexp $line ignore msg_id msg] } {
lappend msgs "$msg_id $file $file_line $msg" lappend msgs "$msg_id $file $file_line $msg"
} }
gets $in_stream line gets $in_stream line
@ -61,13 +61,13 @@ foreach subdir $subdirs {
set files [glob -nocomplain [file join $subdir "*.{cc,hh,yy,ll,i}"]] set files [glob -nocomplain [file join $subdir "*.{cc,hh,yy,ll,i}"]]
set files_c [concat $files_c $files] set files_c [concat $files_c $files]
} }
set warn_regexp_c {(criticalError|->warn|->fileWarn|->error|->fileError|libWarn|libError| warn)\(([0-9]+),.*(".+")} set warn_regexp_c {(?:(?:criticalError|->warn|->fileWarn|->error|->fileError|libWarn|libError| warn)\(|tclArgError\(interp,\s*)([0-9]+),.*(".+")}
set files_tcl {} set files_tcl {}
foreach subdir $subdirs { foreach subdir $subdirs {
set files_tcl [concat $files_tcl [glob -nocomplain [file join $subdir "*.tcl"]]] set files_tcl [concat $files_tcl [glob -nocomplain [file join $subdir "*.tcl"]]]
} }
set warn_regexp_tcl {(sta_warn|sta_error|sta_warn_error) ([0-9]+) (".+")} set warn_regexp_tcl {(?:sta_warn|sta_error|sta_warn_error) ([0-9]+) (".+")}
proc scan_files {files warn_regexp } { proc scan_files {files warn_regexp } {
foreach file $files { foreach file $files {

View File

@ -48,6 +48,7 @@ tclListSetStdString(Tcl_Obj *const source,
void void
tclArgError(Tcl_Interp *interp, tclArgError(Tcl_Interp *interp,
int id,
const char *msg, const char *msg,
const char *arg); const char *arg);

View File

@ -441,8 +441,7 @@ using namespace sta;
const char *arg = Tcl_GetStringFromObj($input, &length); const char *arg = Tcl_GetStringFromObj($input, &length);
Transition *tr = Transition::find(arg); Transition *tr = Transition::find(arg);
if (tr == nullptr) { if (tr == nullptr) {
Tcl_SetResult(interp,const_cast<char*>("Error: transition not found."), tclArgError(interp, 2150, "Unknown transition '%s'.", arg);
TCL_STATIC);
return TCL_ERROR; return TCL_ERROR;
} }
else else
@ -462,8 +461,7 @@ using namespace sta;
const char *arg = Tcl_GetStringFromObj($input, &length); const char *arg = Tcl_GetStringFromObj($input, &length);
RiseFall *rf = RiseFall::find(arg); RiseFall *rf = RiseFall::find(arg);
if (rf == nullptr) { if (rf == nullptr) {
Tcl_SetResult(interp,const_cast<char*>("Error: unknown rise/fall edge."), tclArgError(interp, 2151, "Unknown rise/fall edge '%s'.", arg);
TCL_STATIC);
return TCL_ERROR; return TCL_ERROR;
} }
$1 = rf; $1 = rf;
@ -482,8 +480,7 @@ using namespace sta;
const char *arg = Tcl_GetStringFromObj($input, &length); const char *arg = Tcl_GetStringFromObj($input, &length);
RiseFallBoth *tr = RiseFallBoth::find(arg); RiseFallBoth *tr = RiseFallBoth::find(arg);
if (tr == nullptr) { if (tr == nullptr) {
Tcl_SetResult(interp,const_cast<char*>("Error: unknown transition name."), tclArgError(interp, 2152, "Unknown transition name '%s'.", arg);
TCL_STATIC);
return TCL_ERROR; return TCL_ERROR;
} }
$1 = tr; $1 = tr;
@ -502,8 +499,7 @@ using namespace sta;
const char *arg = Tcl_GetStringFromObj($input, &length); const char *arg = Tcl_GetStringFromObj($input, &length);
PortDirection *dir = PortDirection::find(arg); PortDirection *dir = PortDirection::find(arg);
if (dir == nullptr) { if (dir == nullptr) {
Tcl_SetResult(interp,const_cast<char*>("Error: port direction not found."), tclArgError(interp, 2153, "Unknown port direction '%s'.", arg);
TCL_STATIC);
return TCL_ERROR; return TCL_ERROR;
} }
else else
@ -517,8 +513,7 @@ using namespace sta;
if (role) if (role)
$1 = TimingRole::find(arg); $1 = TimingRole::find(arg);
else { else {
Tcl_SetResult(interp,const_cast<char*>("Error: unknown timing role."), tclArgError(interp, 2154, "Unknown timing role '%s'.", arg);
TCL_STATIC);
return TCL_ERROR; return TCL_ERROR;
} }
} }
@ -541,8 +536,7 @@ using namespace sta;
else if (stringEq(arg, "fall") || stringEq(arg, "falling")) else if (stringEq(arg, "fall") || stringEq(arg, "falling"))
$1 = LogicValue::fall; $1 = LogicValue::fall;
else { else {
Tcl_SetResult(interp,const_cast<char*>("Error: unknown logic value."), tclArgError(interp, 2155, "Unknown logic value '%s'.", arg);
TCL_STATIC);
return TCL_ERROR; return TCL_ERROR;
} }
} }
@ -557,9 +551,7 @@ using namespace sta;
else if (stringEq(arg, "on_chip_variation")) else if (stringEq(arg, "on_chip_variation"))
$1 = AnalysisType::ocv; $1 = AnalysisType::ocv;
else { else {
Tcl_SetResult(interp,const_cast<char*>("Error: unknown analysis type."), tclArgError(interp, 2156, "Unknown analysis type '%s'.", arg);
TCL_STATIC);
return TCL_ERROR; return TCL_ERROR;
} }
} }
@ -757,11 +749,11 @@ using namespace sta;
char *arg = Tcl_GetString(argv[i]); char *arg = Tcl_GetString(argv[i]);
double value; double value;
if (Tcl_GetDouble(interp, arg, &value) == TCL_OK) if (Tcl_GetDouble(interp, arg, &value) == TCL_OK)
floats->push_back(static_cast<float>(value)); floats->push_back(static_cast<float>(value));
else { else {
delete floats; delete floats;
tclArgError(interp, "%s is not a floating point number.", arg); tclArgError(interp, 2157, "%s is not a floating point number.", arg);
return TCL_ERROR; return TCL_ERROR;
} }
} }
} }
@ -802,11 +794,11 @@ using namespace sta;
char *arg = Tcl_GetString(argv[i]); char *arg = Tcl_GetString(argv[i]);
int value; int value;
if (Tcl_GetInt(interp, arg, &value) == TCL_OK) if (Tcl_GetInt(interp, arg, &value) == TCL_OK)
ints->push_back(value); ints->push_back(value);
else { else {
delete ints; delete ints;
tclArgError(interp, "%s is not an integer.", arg); tclArgError(interp, 2158, "%s is not an integer.", arg);
return TCL_ERROR; return TCL_ERROR;
} }
} }
} }
@ -860,7 +852,7 @@ using namespace sta;
if (min_max) if (min_max)
$1 = min_max; $1 = min_max;
else { else {
tclArgError(interp, "%s not min or max.", arg); tclArgError(interp, 2159, "%s not min or max.", arg);
return TCL_ERROR; return TCL_ERROR;
} }
} }
@ -880,7 +872,7 @@ using namespace sta;
if (min_max) if (min_max)
$1 = min_max; $1 = min_max;
else { else {
tclArgError(interp, "%s not min, max or min_max.", arg); tclArgError(interp, 2160, "%s not min, max or min_max.", arg);
return TCL_ERROR; return TCL_ERROR;
} }
} }
@ -895,7 +887,7 @@ using namespace sta;
if (min_max) if (min_max)
$1 = min_max; $1 = min_max;
else { else {
tclArgError(interp, "%s not min, max or min_max.", arg); tclArgError(interp, 2161, "%s not min, max or min_max.", arg);
return TCL_ERROR; return TCL_ERROR;
} }
} }
@ -916,7 +908,7 @@ using namespace sta;
|| stringEqual(arg, "max")) || stringEqual(arg, "max"))
$1 = MinMax::max(); $1 = MinMax::max();
else { else {
tclArgError(interp, "%s not setup, hold, min or max.", arg); tclArgError(interp, 2162, "%s not setup, hold, min or max.", arg);
return TCL_ERROR; return TCL_ERROR;
} }
} }
@ -935,7 +927,7 @@ using namespace sta;
|| stringEqual(arg, "min_max")) || stringEqual(arg, "min_max"))
$1 = SetupHoldAll::all(); $1 = SetupHoldAll::all();
else { else {
tclArgError(interp, "%s not setup, hold, setup_hold, min, max or min_max.", arg); tclArgError(interp, 2163, "%s not setup, hold, setup_hold, min, max or min_max.", arg);
return TCL_ERROR; return TCL_ERROR;
} }
} }
@ -948,7 +940,7 @@ using namespace sta;
if (early_late) if (early_late)
$1 = early_late; $1 = early_late;
else { else {
tclArgError(interp, "%s not early/min, late/max or early_late/min_max.", arg); tclArgError(interp, 2164, "%s not early/min, late/max or early_late/min_max.", arg);
return TCL_ERROR; return TCL_ERROR;
} }
} }
@ -961,7 +953,7 @@ using namespace sta;
if (early_late) if (early_late)
$1 = early_late; $1 = early_late;
else { else {
tclArgError(interp, "%s not early/min, late/max or early_late/min_max.", arg); tclArgError(interp, 2165, "%s not early/min, late/max or early_late/min_max.", arg);
return TCL_ERROR; return TCL_ERROR;
} }
} }
@ -976,7 +968,7 @@ using namespace sta;
else if (stringEq(arg, "cell_check")) else if (stringEq(arg, "cell_check"))
$1 = TimingDerateType::cell_check; $1 = TimingDerateType::cell_check;
else { else {
tclArgError(interp, "%s not net_delay, cell_delay or cell_check.", arg); tclArgError(interp, 2166, "%s not net_delay, cell_delay or cell_check.", arg);
return TCL_ERROR; return TCL_ERROR;
} }
} }
@ -989,7 +981,7 @@ using namespace sta;
else if (stringEq(arg, "cell_check")) else if (stringEq(arg, "cell_check"))
$1 = TimingDerateCellType::cell_check; $1 = TimingDerateCellType::cell_check;
else { else {
tclArgError(interp, "%s not cell_delay or cell_check.", arg); tclArgError(interp, 2167, "%s not cell_delay or cell_check.", arg);
return TCL_ERROR; return TCL_ERROR;
} }
} }
@ -1002,7 +994,7 @@ using namespace sta;
else if (stringEq(arg, "data")) else if (stringEq(arg, "data"))
$1 = PathClkOrData::data; $1 = PathClkOrData::data;
else { else {
tclArgError(interp, "%s not clk or data.", arg); tclArgError(interp, 2168, "%s not clk or data.", arg);
return TCL_ERROR; return TCL_ERROR;
} }
} }
@ -1015,7 +1007,7 @@ using namespace sta;
else if (stringEq(arg, "slack")) else if (stringEq(arg, "slack"))
$1 = sort_by_slack; $1 = sort_by_slack;
else { else {
tclArgError(interp, "%s not group or slack.", arg); tclArgError(interp, 2169, "%s not group or slack.", arg);
return TCL_ERROR; return TCL_ERROR;
} }
} }
@ -1040,7 +1032,7 @@ using namespace sta;
else if (stringEq(arg, "json")) else if (stringEq(arg, "json"))
$1 = ReportPathFormat::json; $1 = ReportPathFormat::json;
else { else {
tclArgError(interp, "unknown path type %s.", arg); tclArgError(interp, 2170, "unknown path type %s.", arg);
return TCL_ERROR; return TCL_ERROR;
} }
} }
@ -1406,7 +1398,7 @@ using namespace sta;
else if (stringEq(arg, "xyce")) else if (stringEq(arg, "xyce"))
$1 = CircuitSim::xyce; $1 = CircuitSim::xyce;
else { else {
tclArgError(interp, "unknown circuit simulator %s.", arg); tclArgError(interp, 2171, "unknown circuit simulator %s.", arg);
return TCL_ERROR; return TCL_ERROR;
} }
} }

View File

@ -93,15 +93,16 @@ tclListSetStdString(Tcl_Obj *const source,
void void
tclArgError(Tcl_Interp *interp, tclArgError(Tcl_Interp *interp,
int id,
const char *msg, const char *msg,
const char *arg) const char *arg)
{ {
// Swig does not add try/catch around arg parsing so this cannot use Report::error. // Swig does not add try/catch around arg parsing so this cannot use Report::error.
string error_msg = "Error: "; try {
error_msg += msg; Sta::sta()->report()->error(id, msg, arg);
char *error = stringPrint(error_msg.c_str(), arg); } catch (const std::exception &e) {
Tcl_SetResult(interp, error, TCL_VOLATILE); Tcl_SetResult(interp, const_cast<char*>(e.what()), TCL_STATIC);
stringDelete(error); }
} }
void void