diff --git a/bin/verilator b/bin/verilator index 587a9b85f..5bab12f33 100755 --- a/bin/verilator +++ b/bin/verilator @@ -404,6 +404,7 @@ detailed descriptions of these arguments. --protect-key Key for symbol protection --protect-lib Create a DPI protected library --public Debugging; see docs + --public-params Mark all parameters as public_flat --public-flat-rw Mark all variables, etc as public_flat_rw -pvalue+= Overwrite toplevel parameter --quiet-exit Don't print the command on failure diff --git a/docs/guide/exe_verilator.rst b/docs/guide/exe_verilator.rst index 0a4b90249..ee14ca390 100644 --- a/docs/guide/exe_verilator.rst +++ b/docs/guide/exe_verilator.rst @@ -1101,6 +1101,12 @@ Summary: marking only those signals that need public_flat_rw is typically significantly better performing. +.. option:: --public-params + + Declares all parameters public as if they had + :code:`/*verilator public_flat_rd*/` + metacomments. + .. option:: -pvalue+= Overwrites the given parameter(s) of the top-level module. See diff --git a/src/V3LinkParse.cpp b/src/V3LinkParse.cpp index c0984fe98..ba3542ff6 100644 --- a/src/V3LinkParse.cpp +++ b/src/V3LinkParse.cpp @@ -259,6 +259,8 @@ private: } } + if (v3Global.opt.publicParams() && nodep->isParam()) nodep->sigUserRWPublic(true); + // We used modTrace before leveling, and we may now // want to turn it off now that we know the levelizations if (v3Global.opt.traceDepth() && m_modp diff --git a/src/V3Options.cpp b/src/V3Options.cpp index faec6ba50..6bcdabeec 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -1385,7 +1385,10 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char m_publicFlatRW = flag; v3Global.dpi(true); }); - + DECL_OPTION("-public-params", CbOnOff, [this](bool flag) { + m_public_params = flag; + v3Global.dpi(true); + }); DECL_OPTION("-quiet-exit", OnOff, &m_quietExit); DECL_OPTION("-relative-includes", OnOff, &m_relativeIncludes); diff --git a/src/V3Options.h b/src/V3Options.h index aa681b3ea..46ea949c8 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -262,6 +262,7 @@ private: bool m_protectIds = false; // main switch: --protect-ids bool m_public = false; // main switch: --public bool m_publicFlatRW = false; // main switch: --public-flat-rw + bool m_public_params = false; // main switch: --public-params bool m_quietExit = false; // main switch: --quiet-exit bool m_relativeIncludes = false; // main switch: --relative-includes bool m_reportUnoptflat = false; // main switch: --report-unoptflat @@ -492,6 +493,7 @@ public: bool usesProfiler() const { return profExec() || profPgo(); } bool protectIds() const VL_MT_SAFE { return m_protectIds; } bool allPublic() const { return m_public; } + bool publicParams() const { return m_public_params; } bool publicFlatRW() const { return m_publicFlatRW; } bool lintOnly() const VL_MT_SAFE { return m_lintOnly; } bool ignc() const { return m_ignc; } diff --git a/test_regress/t/t_vpi_param.cpp b/test_regress/t/t_vpi_param.cpp index 8d769ae26..1f2c5d434 100644 --- a/test_regress/t/t_vpi_param.cpp +++ b/test_regress/t/t_vpi_param.cpp @@ -21,9 +21,16 @@ #include "verilated_vcd_c.h" #include "verilated_vpi.h" +#include "svdpi.h" + +#ifdef T_VPI_PARAM #include "Vt_vpi_param.h" #include "Vt_vpi_param__Dpi.h" -#include "svdpi.h" +#elif defined(T_VPI_PUBLIC_PARAMS) +#include "Vt_vpi_public_params.h" +#else +#error "Bad test" +#endif #endif diff --git a/test_regress/t/t_vpi_public_params.pl b/test_regress/t/t_vpi_public_params.pl new file mode 100755 index 000000000..34224a797 --- /dev/null +++ b/test_regress/t/t_vpi_public_params.pl @@ -0,0 +1,34 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2010 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); + +# same vpi script should work with --public-params instead of inline publics +pli_filename("t_vpi_param.cpp"); + +skip("Known compiler limitation") + if $Self->cxx_version =~ /\(GCC\) 4.4/; + +compile( + make_top_shell => 0, + make_main => 0, + make_pli => 1, + iv_flags2 => ["-g2005-sv -D USE_VPI_NOT_DPI"], + v_flags2 => ["+define+USE_VPI_NOT_DPI"], + verilator_flags2 => ["--exe --vpi --no-l2name $Self->{t_dir}/t_vpi_param.cpp --public-params "], + ); + +execute( + use_libvpi => 1, + check_finished => 1 + ); + +ok(1); +1; diff --git a/test_regress/t/t_vpi_public_params.v b/test_regress/t/t_vpi_public_params.v new file mode 100644 index 000000000..6286e7481 --- /dev/null +++ b/test_regress/t/t_vpi_public_params.v @@ -0,0 +1,58 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// Copyright 2010 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 + +`ifdef USE_VPI_NOT_DPI +//We call it via $c so we can verify DPI isn't required - see bug572 +`else +import "DPI-C" context function int mon_check(); +`endif + +// Copy of t_vpi_public_params.v but with the inline public taken out +module t #( + parameter int WIDTH = 32 + ) (/*AUTOARG*/ + // Inputs + clk + ); + +`ifdef VERILATOR +`systemc_header +extern "C" int mon_check(); +`verilog +`endif + + input clk; + + localparam int DEPTH = 16; + localparam longint PARAM_LONG = 64'hFEDCBA9876543210; + localparam string PARAM_STR = "'some string value'"; + + reg [WIDTH-1:0] mem0 [DEPTH:1]; + integer i, status; + + // Test loop + initial begin +`ifdef VERILATOR + status = $c32("mon_check()"); +`endif +`ifdef IVERILOG + status = $mon_check(); +`endif +`ifndef USE_VPI_NOT_DPI + status = mon_check(); +`endif + + if (status!=0) begin + $write("%%Error: t_vpi_param.cpp:%0d: C Test failed\n", status); + $stop; + end + $write("*-* All Finished *-*\n"); + $finish; + end + +endmodule : t