diff --git a/docs/gen/ex_DIDNOTCONVERGE_msg.rst b/docs/gen/ex_DIDNOTCONVERGE_msg.rst index f86acce02..4c2167bc6 100644 --- a/docs/gen/ex_DIDNOTCONVERGE_msg.rst +++ b/docs/gen/ex_DIDNOTCONVERGE_msg.rst @@ -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 diff --git a/docs/gen/ex_DIDNOTCONVERGE_nodbg_msg.rst b/docs/gen/ex_DIDNOTCONVERGE_nodbg_msg.rst index 77abc8534..3ac0e9b0e 100644 --- a/docs/gen/ex_DIDNOTCONVERGE_nodbg_msg.rst +++ b/docs/gen/ex_DIDNOTCONVERGE_nodbg_msg.rst @@ -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 diff --git a/include/verilated.cpp b/include/verilated.cpp index 64d5f6736..f3fce0a10 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -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(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 diff --git a/src/V3SchedUtil.cpp b/src/V3SchedUtil.cpp index f773070ea..eb7f6b4f8 100644 --- a/src/V3SchedUtil.cpp +++ b/src/V3SchedUtil.cpp @@ -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; } diff --git a/test_regress/t/t_json_only_debugcheck.out b/test_regress/t/t_json_only_debugcheck.out index bd6608cac..7f7c2b3a2 100644 --- a/test_regress/t/t_json_only_debugcheck.out +++ b/test_regress/t/t_json_only_debugcheck.out @@ -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)", diff --git a/test_regress/t/t_lint_didnotconverge_bad.out b/test_regress/t/t_lint_didnotconverge_bad.out index 5133d97c7..eced481cb 100644 --- a/test_regress/t/t_lint_didnotconverge_bad.out +++ b/test_regress/t/t_lint_didnotconverge_bad.out @@ -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... diff --git a/test_regress/t/t_lint_didnotconverge_nodbg_bad.out b/test_regress/t/t_lint_didnotconverge_nodbg_bad.out index 3eb3339bd..2567a6d55 100644 --- a/test_regress/t/t_lint_didnotconverge_nodbg_bad.out +++ b/test_regress/t/t_lint_didnotconverge_nodbg_bad.out @@ -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... diff --git a/test_regress/t/t_unopt_converge_initial_run_bad.out b/test_regress/t/t_unopt_converge_initial_run_bad.out index 5c449acfb..ee51093f6 100644 --- a/test_regress/t/t_unopt_converge_initial_run_bad.out +++ b/test_regress/t/t_unopt_converge_initial_run_bad.out @@ -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... diff --git a/test_regress/t/t_unopt_converge_ndbg_bad.out b/test_regress/t/t_unopt_converge_ndbg_bad.out index d8b1afa04..bb60c4397 100644 --- a/test_regress/t/t_unopt_converge_ndbg_bad.out +++ b/test_regress/t/t_unopt_converge_ndbg_bad.out @@ -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... diff --git a/test_regress/t/t_unopt_converge_print_bad.out b/test_regress/t/t_unopt_converge_print_bad.out index 29a108c3c..cb163e048 100644 --- a/test_regress/t/t_unopt_converge_print_bad.out +++ b/test_regress/t/t_unopt_converge_print_bad.out @@ -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... diff --git a/test_regress/t/t_unopt_converge_run_bad.out b/test_regress/t/t_unopt_converge_run_bad.out index aad3c80e0..1dfd9880f 100644 --- a/test_regress/t/t_unopt_converge_run_bad.out +++ b/test_regress/t/t_unopt_converge_run_bad.out @@ -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...