Skip to content

Commit

Permalink
Merge pull request #4417 from kivikakk/cxxrtl-unused-output
Browse files Browse the repository at this point in the history
cxxrtl: don't emit invalid code on unconnected outputs.
  • Loading branch information
whitequark authored Jun 9, 2024
2 parents 078c14f + e97c36d commit 9f94ecf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backends/cxxrtl/cxxrtl_backend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ struct CxxrtlWorker {
f << indent << "// cell " << cell->name.str() << " syncs\n";
for (auto conn : cell->connections())
if (cell->output(conn.first))
if (is_cxxrtl_sync_port(cell, conn.first)) {
if (is_cxxrtl_sync_port(cell, conn.first) && !conn.second.empty()) {
f << indent;
dump_sigspec_lhs(conn.second, for_debug);
f << " = " << mangle(cell) << access << mangle_wire_name(conn.first) << ".curr;\n";
Expand Down
4 changes: 4 additions & 0 deletions tests/cxxrtl/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ run_subtest () {

run_subtest value
run_subtest value_fuzz

# Compile-only test.
../../yosys -p "read_verilog test_unconnected_output.v; proc; clean; write_cxxrtl cxxrtl-test-unconnected_output.cc"
${CC:-gcc} -std=c++11 -c -o cxxrtl-test-unconnected_output -I../../backends/cxxrtl/runtime cxxrtl-test-unconnected_output.cc
24 changes: 24 additions & 0 deletions tests/cxxrtl/test_unconnected_output.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(* cxxrtl_blackbox *)
module blackbox(...);
(* cxxrtl_edge = "p" *)
input clk;

(* cxxrtl_sync *)
output [7:0] out1;

(* cxxrtl_sync *)
output [7:0] out2;
endmodule

module unconnected_output(
input clk,
in,
output out
);
blackbox bb (
.clock (clock),
.in (in),
.out1 (out),
.out2 (/* unconnected */),
);
endmodule

0 comments on commit 9f94ecf

Please sign in to comment.