Fix --lib-create with multi-bit clocks (#6759)
This commit is contained in:
parent
e2c05ae15e
commit
18dd44e970
|
|
@ -443,7 +443,7 @@ class ProtectVisitor final : public VNVisitor {
|
|||
if (m_hasClk) {
|
||||
const std::string pname = varp->prettyName();
|
||||
m_seqParamsp->add(pname);
|
||||
m_clkSensp->add("posedge " + pname + " or negedge " + pname);
|
||||
m_clkSensp->add(pname);
|
||||
}
|
||||
m_cSeqParamsp->add(varp->dpiArgType(true, false));
|
||||
m_cSeqClksp->add(cInputConnection(varp));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env python3
|
||||
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||
#
|
||||
# Copyright 2025 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
|
||||
|
||||
import vltest_bootstrap
|
||||
|
||||
test.scenarios('vlt_all')
|
||||
|
||||
lib_dir = test.obj_dir + "/sub"
|
||||
test.mkdir_ok(lib_dir)
|
||||
|
||||
test.run(logfile=lib_dir + "/verilator.log",
|
||||
cmd=[
|
||||
"perl", os.environ["VERILATOR_ROOT"] + "/bin/verilator", "-cc", "-Mdir", lib_dir,
|
||||
"--lib-create", "sub", "--prefix", "Vsub", "+define+LIB_CREATE", test.top_filename
|
||||
],
|
||||
verilator_run=True)
|
||||
|
||||
test.run(logfile=lib_dir + "/make.log", cmd=[os.environ["MAKE"], "-C", lib_dir, "-f", "Vsub.mk"])
|
||||
|
||||
test.compile(verilator_flags2=["--binary", "-LDFLAGS", "sub/libsub.a", lib_dir + "/sub.sv"])
|
||||
|
||||
test.execute(xsim_run_flags2=["--sv_lib", lib_dir + "/libsecret", "--dpi_absolute"])
|
||||
|
||||
test.passes()
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
// DESCRIPTION: Verilator: Verilog Test module
|
||||
//
|
||||
// This file ONLY is placed under the Creative Commons Public Domain, for
|
||||
// any use, without warranty, 2025 by Wilson Snyder.
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
// The number of clocks in the clock vector
|
||||
|
||||
localparam int N = 5;
|
||||
|
||||
`ifdef LIB_CREATE
|
||||
// This is built with --lib-create
|
||||
|
||||
module sub(
|
||||
input logic [N-1:0] clkvec,
|
||||
output logic [7:0] cnt[N]
|
||||
);
|
||||
|
||||
for (genvar i = 0; i < N; ++i) begin : GEN
|
||||
logic [7:0] counter = 8'd0;
|
||||
always @(posedge clkvec[i]) counter <= counter + 8'd1;
|
||||
assign cnt[i] = counter;
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
||||
`else
|
||||
// This is built as the top level
|
||||
|
||||
module top;
|
||||
|
||||
logic [N-1:0] clkvec = N'(0);
|
||||
logic [7:0] cnt [N];
|
||||
|
||||
// Generate clocks by rotation
|
||||
always #5 clkvec = {clkvec[N-2:0], clkvec[N-1] | ~|clkvec};
|
||||
|
||||
sub sub_i(clkvec, cnt);
|
||||
|
||||
always @(clkvec) begin
|
||||
#1;
|
||||
$write("%10t %05b", $time, clkvec);
|
||||
for (int i = N-1; i >= 0; --i) begin
|
||||
$write(" cnt[%0d]=%02d", i, cnt[i]);
|
||||
end
|
||||
$write("\n");
|
||||
|
||||
// No counter should reach above 10
|
||||
for (int i = 0; i < N; ++i) begin
|
||||
if (cnt[i] > 10) $stop;
|
||||
end
|
||||
|
||||
// Conclude when all counters reach 10
|
||||
begin
|
||||
static bit done = 1'b1;
|
||||
for (int i = 0; i < N; ++i) begin
|
||||
if (cnt[i] != 10) done = 1'b0;
|
||||
end
|
||||
if (done) begin
|
||||
$write("*-* All Finished *-*\n");
|
||||
$finish;
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
|
||||
`endif
|
||||
Loading…
Reference in New Issue