Improve format of runtime errors, especially DIDNOTCONVERGE

This commit is contained in:
Wilson Snyder 2026-01-08 01:01:54 -05:00
parent da14e7c4bb
commit c75fb4cdae
11 changed files with 50 additions and 39 deletions

View File

@ -2,4 +2,4 @@
.. code-block::
-V{t#,#} 'stl' region trigger index 0 is active: @([hybrid] a)
%Error: t/t_lint_didnotconverge_bad.v:7: Settle region did not converge after 100 tries
%Error-DIDNOTCONVERGE: t/t_lint_didnotconverge_bad.v:7: Settle region did not converge after 100 tries

View File

@ -1,4 +1,4 @@
.. comment: generated by t_lint_didnotconverge_nodbg_bad
.. code-block::
%Error: t/t_lint_didnotconverge_bad.v:7: Settle region did not converge after 100 tries
%Error-DIDNOTCONVERGE: t/t_lint_didnotconverge_bad.v:7: Settle region did not converge after 100 tries

View File

@ -112,6 +112,36 @@ VerilatedContext* Verilated::s_lastContextp = nullptr;
// Internal note: Globals may multi-construct, see verilated.cpp top.
thread_local Verilated::ThreadLocal Verilated::t_s;
//===========================================================================
// Warning print helper
void vl_print_warn_error(const char* prefix, const char* filename, int linenum,
const char* msg) VL_MT_UNSAFE {
// A msg of "ERRORCODE: ..." is a code that changes to a prefix, e.g. "%Error-ERRORCODE: ..."
// This avoids changing public API of the vl_stop and related functions.
const char* msgNoCp = msg;
for (; isupper(*msgNoCp); ++msgNoCp);
if (msgNoCp[0] == ':' && msgNoCp[1] == ' ') {
const int codeWidth = static_cast<int>(msgNoCp - msg);
msgNoCp += 2;
if (filename && filename[0]) {
VL_PRINTF( // Not VL_PRINTF_MT, already on main thread
"%s-%.*s: %s:%d: %s\n", prefix, codeWidth, msg, filename, linenum, msgNoCp);
} else {
VL_PRINTF( // Not VL_PRINTF_MT, already on main thread
"%s-%.*s: %s\n", prefix, codeWidth, msg, msgNoCp);
}
} else {
if (filename && filename[0]) {
VL_PRINTF( // Not VL_PRINTF_MT, already on main thread
"%s: %s:%d: %s\n", prefix, filename, linenum, msg);
} else {
VL_PRINTF( // Not VL_PRINTF_MT, already on main thread
"%s: %s\n", prefix, msg);
}
}
}
//===========================================================================
// User definable functions
// Note a TODO is a future version of the API will pass a structure so that
@ -119,8 +149,7 @@ thread_local Verilated::ThreadLocal Verilated::t_s;
#ifndef VL_USER_FINISH ///< Define this to override the vl_finish function
void vl_finish(const char* filename, int linenum, const char* hier) VL_MT_UNSAFE {
// hier is unused in the default implementation.
(void)hier;
(void)hier; // hier is unused in the default implementation.
VL_PRINTF( // Not VL_PRINTF_MT, already on main thread
"- %s:%d: Verilog $finish\n", filename, linenum);
Verilated::threadContextp()->gotFinish(true);
@ -136,12 +165,7 @@ void vl_stop(const char* filename, int linenum, const char* hier) VL_MT_UNSAFE {
if (Verilated::threadContextp()->fatalOnError()) {
vl_fatal(filename, linenum, hier, msg);
} else {
if (filename && filename[0]) {
// Not VL_PRINTF_MT, already on main thread
VL_PRINTF("%%Error: %s:%d: %s\n", filename, linenum, msg);
} else {
VL_PRINTF("%%Error: %s\n", msg);
}
vl_print_warn_error("%Error", filename, linenum, msg);
Verilated::runFlushCallbacks();
}
}
@ -149,16 +173,10 @@ void vl_stop(const char* filename, int linenum, const char* hier) VL_MT_UNSAFE {
#ifndef VL_USER_FATAL ///< Define this to override the vl_fatal function
void vl_fatal(const char* filename, int linenum, const char* hier, const char* msg) VL_MT_UNSAFE {
// hier is unused in the default implementation.
(void)hier;
(void)hier; // hier is unused in the default implementation.
Verilated::threadContextp()->gotError(true);
Verilated::threadContextp()->gotFinish(true);
if (filename && filename[0]) {
// Not VL_PRINTF_MT, already on main thread
VL_PRINTF("%%Error: %s:%d: %s\n", filename, linenum, msg);
} else {
VL_PRINTF("%%Error: %s\n", msg);
}
vl_print_warn_error("%Error", filename, linenum, msg);
Verilated::runFlushCallbacks();
VL_PRINTF("Aborting...\n"); // Not VL_PRINTF_MT, already on main thread
@ -185,9 +203,8 @@ void vl_stop_maybe(const char* filename, int linenum, const char* hier, bool may
&& Verilated::threadContextp()->errorCount() < Verilated::threadContextp()->errorLimit()) {
// Do just once when cross error limit
if (Verilated::threadContextp()->errorCount() == 1) {
VL_PRINTF( // Not VL_PRINTF_MT, already on main thread
"-Info: %s:%d: %s\n", filename, linenum,
"Verilog $stop, ignored due to +verilator+error+limit");
vl_print_warn_error("-Info", filename, linenum,
"Verilog $stop, ignored due to +verilator+error+limit");
}
} else {
vl_stop(filename, linenum, hier);
@ -197,14 +214,8 @@ void vl_stop_maybe(const char* filename, int linenum, const char* hier, bool may
#ifndef VL_USER_WARN ///< Define this to override the vl_warn function
void vl_warn(const char* filename, int linenum, const char* hier, const char* msg) VL_MT_UNSAFE {
// hier is unused in the default implementation.
(void)hier;
if (filename && filename[0]) {
// Not VL_PRINTF_MT, already on main thread
VL_PRINTF("%%Warning: %s:%d: %s\n", filename, linenum, msg);
} else {
VL_PRINTF("%%Warning: %s\n", msg);
}
(void)hier; // hier is unused in the default implementation.
vl_print_warn_error("%Warning", filename, linenum, msg);
Verilated::runFlushCallbacks();
}
#endif

View File

@ -96,8 +96,8 @@ AstNodeStmt* checkIterationLimit(AstNetlist* netlistp, const string& name, AstVa
const std::string& file = VIdProtect::protect(locp->filename());
const std::string& line = std::to_string(locp->lineno());
stmtp->add("VL_FATAL_MT(\"" + V3OutFormatter::quoteNameControls(file) + "\", " + line
+ ", \"\", \"" + name + " region did not converge after " + std::to_string(limit)
+ " tries\");");
+ ", \"\", \"DIDNOTCONVERGE: " + name + " region did not converge after "
+ std::to_string(limit) + " tries\");");
return ifp;
}

View File

@ -2707,7 +2707,7 @@
]},
{"type":"CSTMT","name":"","addr":"(ONB)","loc":"a,0:0,0:0",
"nodesp": [
{"type":"TEXT","name":"","addr":"(PNB)","loc":"a,0:0,0:0","text":"VL_FATAL_MT(\"t/t_enum_type_methods.v\", 11, \"\", \"NBA region did not converge after 100 tries\");"}
{"type":"TEXT","name":"","addr":"(PNB)","loc":"a,0:0,0:0","text":"VL_FATAL_MT(\"t/t_enum_type_methods.v\", 11, \"\", \"DIDNOTCONVERGE: NBA region did not converge after 100 tries\");"}
]}
],"elsesp": []},
{"type":"ASSIGN","name":"","addr":"(QNB)","loc":"d,11:8,11:9","dtypep":"(R)",
@ -2761,7 +2761,7 @@
]},
{"type":"CSTMT","name":"","addr":"(LOB)","loc":"a,0:0,0:0",
"nodesp": [
{"type":"TEXT","name":"","addr":"(MOB)","loc":"a,0:0,0:0","text":"VL_FATAL_MT(\"t/t_enum_type_methods.v\", 11, \"\", \"Active region did not converge after 100 tries\");"}
{"type":"TEXT","name":"","addr":"(MOB)","loc":"a,0:0,0:0","text":"VL_FATAL_MT(\"t/t_enum_type_methods.v\", 11, \"\", \"DIDNOTCONVERGE: Active region did not converge after 100 tries\");"}
]}
],"elsesp": []},
{"type":"ASSIGN","name":"","addr":"(NOB)","loc":"d,11:8,11:9","dtypep":"(R)",

View File

@ -1,3 +1,3 @@
-V{t#,#} 'stl' region trigger index 0 is active: @([hybrid] a)
%Error: t/t_lint_didnotconverge_bad.v:7: Settle region did not converge after 100 tries
%Error-DIDNOTCONVERGE: t/t_lint_didnotconverge_bad.v:7: Settle region did not converge after 100 tries
Aborting...

View File

@ -1,2 +1,2 @@
%Error: t/t_lint_didnotconverge_bad.v:7: Settle region did not converge after 100 tries
%Error-DIDNOTCONVERGE: t/t_lint_didnotconverge_bad.v:7: Settle region did not converge after 100 tries
Aborting...

View File

@ -1,3 +1,3 @@
-V{t#,#} 'stl' region trigger index 0 is active: @([hybrid] x)
%Error: t/t_unopt_converge_initial.v:7: Settle region did not converge after 100 tries
%Error-DIDNOTCONVERGE: t/t_unopt_converge_initial.v:7: Settle region did not converge after 100 tries
Aborting...

View File

@ -1,2 +1,2 @@
%Error: t/t_unopt_converge.v:7: Settle region did not converge after 100 tries
%Error-DIDNOTCONVERGE: t/t_unopt_converge.v:7: Settle region did not converge after 100 tries
Aborting...

View File

@ -1,3 +1,3 @@
-V{t#,#} 'stl' region trigger index 0 is active: @([hybrid] x)
%Error: t/t_unopt_converge.v:7: Settle region did not converge after 100 tries
%Error-DIDNOTCONVERGE: t/t_unopt_converge.v:7: Settle region did not converge after 100 tries
Aborting...

View File

@ -1,3 +1,3 @@
-V{t#,#} 'stl' region trigger index 0 is active: @([hybrid] x)
%Error: t/t_unopt_converge.v:7: Settle region did not converge after 5 tries
%Error-DIDNOTCONVERGE: t/t_unopt_converge.v:7: Settle region did not converge after 5 tries
Aborting...