Add --public-params flag (#3990)

This commit is contained in:
Andrew Nolte 2023-03-08 17:38:26 -07:00 committed by GitHub
parent ff889fde18
commit 13c9877099
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 115 additions and 2 deletions

View File

@ -404,6 +404,7 @@ detailed descriptions of these arguments.
--protect-key <key> Key for symbol protection --protect-key <key> Key for symbol protection
--protect-lib <name> Create a DPI protected library --protect-lib <name> Create a DPI protected library
--public Debugging; see docs --public Debugging; see docs
--public-params Mark all parameters as public_flat
--public-flat-rw Mark all variables, etc as public_flat_rw --public-flat-rw Mark all variables, etc as public_flat_rw
-pvalue+<name>=<value> Overwrite toplevel parameter -pvalue+<name>=<value> Overwrite toplevel parameter
--quiet-exit Don't print the command on failure --quiet-exit Don't print the command on failure

View File

@ -1101,6 +1101,12 @@ Summary:
marking only those signals that need public_flat_rw is typically marking only those signals that need public_flat_rw is typically
significantly better performing. significantly better performing.
.. option:: --public-params
Declares all parameters public as if they had
:code:`/*verilator public_flat_rd*/`
metacomments.
.. option:: -pvalue+<name>=<value> .. option:: -pvalue+<name>=<value>
Overwrites the given parameter(s) of the top-level module. See Overwrites the given parameter(s) of the top-level module. See

View File

@ -259,6 +259,8 @@ private:
} }
} }
if (v3Global.opt.publicParams() && nodep->isParam()) nodep->sigUserRWPublic(true);
// We used modTrace before leveling, and we may now // We used modTrace before leveling, and we may now
// want to turn it off now that we know the levelizations // want to turn it off now that we know the levelizations
if (v3Global.opt.traceDepth() && m_modp if (v3Global.opt.traceDepth() && m_modp

View File

@ -1385,7 +1385,10 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char
m_publicFlatRW = flag; m_publicFlatRW = flag;
v3Global.dpi(true); 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("-quiet-exit", OnOff, &m_quietExit);
DECL_OPTION("-relative-includes", OnOff, &m_relativeIncludes); DECL_OPTION("-relative-includes", OnOff, &m_relativeIncludes);

View File

@ -262,6 +262,7 @@ private:
bool m_protectIds = false; // main switch: --protect-ids bool m_protectIds = false; // main switch: --protect-ids
bool m_public = false; // main switch: --public bool m_public = false; // main switch: --public
bool m_publicFlatRW = false; // main switch: --public-flat-rw 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_quietExit = false; // main switch: --quiet-exit
bool m_relativeIncludes = false; // main switch: --relative-includes bool m_relativeIncludes = false; // main switch: --relative-includes
bool m_reportUnoptflat = false; // main switch: --report-unoptflat bool m_reportUnoptflat = false; // main switch: --report-unoptflat
@ -492,6 +493,7 @@ public:
bool usesProfiler() const { return profExec() || profPgo(); } bool usesProfiler() const { return profExec() || profPgo(); }
bool protectIds() const VL_MT_SAFE { return m_protectIds; } bool protectIds() const VL_MT_SAFE { return m_protectIds; }
bool allPublic() const { return m_public; } bool allPublic() const { return m_public; }
bool publicParams() const { return m_public_params; }
bool publicFlatRW() const { return m_publicFlatRW; } bool publicFlatRW() const { return m_publicFlatRW; }
bool lintOnly() const VL_MT_SAFE { return m_lintOnly; } bool lintOnly() const VL_MT_SAFE { return m_lintOnly; }
bool ignc() const { return m_ignc; } bool ignc() const { return m_ignc; }

View File

@ -21,9 +21,16 @@
#include "verilated_vcd_c.h" #include "verilated_vcd_c.h"
#include "verilated_vpi.h" #include "verilated_vpi.h"
#include "svdpi.h"
#ifdef T_VPI_PARAM
#include "Vt_vpi_param.h" #include "Vt_vpi_param.h"
#include "Vt_vpi_param__Dpi.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 #endif

View File

@ -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;

View File

@ -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