From 1012c054e65486336508c179aeb2096f95792de6 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 11 Apr 2024 17:31:14 -0400 Subject: [PATCH] Fix `$system` with string argument (#5042). --- Changes | 1 + include/verilated.cpp | 5 ++++- include/verilated_funcs.h | 1 + test_regress/t/t_sys_system.v | 4 ++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Changes b/Changes index 101265a91..2c7c0de76 100644 --- a/Changes +++ b/Changes @@ -13,6 +13,7 @@ Verilator 5.025 devel **Minor:** +* Fix `$system` with string argument (#5042). Verilator 5.024 2024-04-05 diff --git a/include/verilated.cpp b/include/verilated.cpp index ab08b7285..de9dbc438 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -1749,7 +1749,10 @@ IData VL_SYSTEM_IQ(QData lhs) VL_MT_SAFE { IData VL_SYSTEM_IW(int lhswords, const WDataInP lhsp) VL_MT_SAFE { char filenamez[VL_VALUE_STRING_MAX_CHARS + 1]; _vl_vint_to_string(lhswords * VL_EDATASIZE, filenamez, lhsp); - const int code = std::system(filenamez); // Yes, std::system() is threadsafe + return VL_SYSTEM_IN(filenamez); +} +IData VL_SYSTEM_IN(const std::string& lhs) VL_MT_SAFE { + const int code = std::system(lhs.c_str()); // Yes, std::system() is threadsafe return code >> 8; // Want exit status } diff --git a/include/verilated_funcs.h b/include/verilated_funcs.h index 76a8fd67f..7a1b15b03 100644 --- a/include/verilated_funcs.h +++ b/include/verilated_funcs.h @@ -152,6 +152,7 @@ extern std::string VL_STACKTRACE_N() VL_MT_SAFE; extern IData VL_SYSTEM_IW(int lhswords, WDataInP const lhsp) VL_MT_SAFE; extern IData VL_SYSTEM_IQ(QData lhs) VL_MT_SAFE; inline IData VL_SYSTEM_II(IData lhs) VL_MT_SAFE { return VL_SYSTEM_IQ(lhs); } +extern IData VL_SYSTEM_IN(const std::string& lhs) VL_MT_SAFE; extern IData VL_TESTPLUSARGS_I(const std::string& format) VL_MT_SAFE; extern const char* vl_mc_scan_plusargs(const char* prefixp) VL_MT_SAFE; // PLIish diff --git a/test_regress/t/t_sys_system.v b/test_regress/t/t_sys_system.v index 54f4468af..fc3bc66bc 100644 --- a/test_regress/t/t_sys_system.v +++ b/test_regress/t/t_sys_system.v @@ -7,6 +7,7 @@ module t; integer i; + string s; initial begin `ifndef VERILATOR @@ -26,6 +27,9 @@ module t; if (i!==10) $stop; i = $system("exit 20"); // Wide if (i!==20) $stop; + s = "exit 10"; + i = $system(s); // String + if (i!==10) $stop; `endif $write("*-* All Finished *-*\n");