diff --git a/docs/CONTRIBUTORS b/docs/CONTRIBUTORS index 228787d5e..e16c20cb2 100644 --- a/docs/CONTRIBUTORS +++ b/docs/CONTRIBUTORS @@ -116,6 +116,7 @@ Tomasz Gorochowik Tymoteusz Blazejczyk Udi Finkelstein Unai Martinez-Corral +Varun Koyyalagunta Vassilis Papaefstathiou Veripool API Bot Victor Besyakov diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index de8be89b6..5193bd7e6 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -673,7 +673,35 @@ void EmitCSyms::emitSymImp() { puts("_vm_pgoProfiler.write(\"" + topClassName() + "\", _vm_contextp__->profVltFilename());\n"); } - puts("}\n\n"); + puts("}\n"); + + if (v3Global.needTraceDumper()) { + if (!optSystemC()) { + puts("\nvoid " + symClassName() + "::_traceDump() {\n"); + // Caller checked for __Vm_dumperp non-nullptr + puts("const VerilatedLockGuard lock(__Vm_dumperMutex);\n"); + puts("__Vm_dumperp->dump(VL_TIME_Q());\n"); + puts("}\n"); + } + + puts("\nvoid " + symClassName() + "::_traceDumpOpen() {\n"); + puts("const VerilatedLockGuard lock(__Vm_dumperMutex);\n"); + puts("if (VL_UNLIKELY(!__Vm_dumperp)) {\n"); + puts("__Vm_dumperp = new " + v3Global.opt.traceClassLang() + "();\n"); + puts("__Vm_modelp->trace(__Vm_dumperp, 0, 0);\n"); + puts("std::string dumpfile = _vm_contextp__->dumpfileCheck();\n"); + puts("__Vm_dumperp->open(dumpfile.c_str());\n"); + puts("__Vm_dumping = true;\n"); + puts("}\n"); + puts("}\n"); + + puts("\nvoid " + symClassName() + "::_traceDumpClose() {\n"); + puts("const VerilatedLockGuard lock(__Vm_dumperMutex);\n"); + puts("__Vm_dumping = false;\n"); + puts("VL_DO_CLEAR(delete __Vm_dumperp, __Vm_dumperp = nullptr);\n"); + puts("}\n"); + } + puts("\n"); // Constructor puts(symClassName() + "::" + symClassName() @@ -923,33 +951,6 @@ void EmitCSyms::emitSymImp() { m_ofpBase->puts("}\n"); - if (v3Global.needTraceDumper()) { - if (!optSystemC()) { - puts("\nvoid " + symClassName() + "::_traceDump() {\n"); - // Caller checked for __Vm_dumperp non-nullptr - puts("const VerilatedLockGuard lock(__Vm_dumperMutex);\n"); - puts("__Vm_dumperp->dump(VL_TIME_Q());\n"); - puts("}\n"); - } - - puts("\nvoid " + symClassName() + "::_traceDumpOpen() {\n"); - puts("const VerilatedLockGuard lock(__Vm_dumperMutex);\n"); - puts("if (VL_UNLIKELY(!__Vm_dumperp)) {\n"); - puts("__Vm_dumperp = new " + v3Global.opt.traceClassLang() + "();\n"); - puts("__Vm_modelp->trace(__Vm_dumperp, 0, 0);\n"); - puts("std::string dumpfile = _vm_contextp__->dumpfileCheck();\n"); - puts("__Vm_dumperp->open(dumpfile.c_str());\n"); - puts("__Vm_dumping = true;\n"); - puts("}\n"); - puts("}\n"); - - puts("\nvoid " + symClassName() + "::_traceDumpClose() {\n"); - puts("const VerilatedLockGuard lock(__Vm_dumperMutex);\n"); - puts("__Vm_dumping = false;\n"); - puts("VL_DO_CLEAR(delete __Vm_dumperp, __Vm_dumperp = nullptr);\n"); - puts("}\n"); - } - closeSplit(); m_ofp = nullptr; VL_DO_CLEAR(delete m_ofpBase, m_ofpBase = nullptr); diff --git a/test_regress/t/t_trace_split_cfuncs.pl b/test_regress/t/t_trace_split_cfuncs.pl new file mode 100755 index 000000000..4959ee710 --- /dev/null +++ b/test_regress/t/t_trace_split_cfuncs.pl @@ -0,0 +1,18 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(simulator => 1); + +compile( + v_flags2 => ["--trace", "--output-split-cfuncs", "1"] + ); + +ok(1); +1; diff --git a/test_regress/t/t_trace_split_cfuncs.v b/test_regress/t/t_trace_split_cfuncs.v new file mode 100644 index 000000000..cf364ad5a --- /dev/null +++ b/test_regress/t/t_trace_split_cfuncs.v @@ -0,0 +1,14 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2022 by Varun Koyyalagunta. +// SPDX-License-Identifier: CC0-1.0 + +module t (); + + initial begin + $dumpfile("dump.vcd"); + $dumpvars(); + end + +endmodule diff --git a/test_regress/t/t_trace_split_cfuncs_dpi_export.pl b/test_regress/t/t_trace_split_cfuncs_dpi_export.pl new file mode 100755 index 000000000..4959ee710 --- /dev/null +++ b/test_regress/t/t_trace_split_cfuncs_dpi_export.pl @@ -0,0 +1,18 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(simulator => 1); + +compile( + v_flags2 => ["--trace", "--output-split-cfuncs", "1"] + ); + +ok(1); +1; diff --git a/test_regress/t/t_trace_split_cfuncs_dpi_export.v b/test_regress/t/t_trace_split_cfuncs_dpi_export.v new file mode 100644 index 000000000..cec80cc3c --- /dev/null +++ b/test_regress/t/t_trace_split_cfuncs_dpi_export.v @@ -0,0 +1,18 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2022 by Varun Koyyalagunta. +// SPDX-License-Identifier: CC0-1.0 + +module t (); + + function automatic void func(); + endfunction + export "DPI-C" function func; + + initial begin + $dumpfile("dump.vcd"); + $dumpvars(); + end + +endmodule