From cd8534387af230d97b1669f814104709e8147afa Mon Sep 17 00:00:00 2001 From: Catherine Date: Wed, 3 Apr 2024 08:01:58 +0000 Subject: [PATCH] write_verilog: don't `assign` to a `reg`. Fixes #2035. --- backends/verilog/verilog_backend.cc | 23 +++++++++++++++-------- tests/simple/.gitignore | 1 + tests/verilog/.gitignore | 4 ++++ tests/verilog/assign_to_reg.ys | 22 ++++++++++++++++++++++ 4 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 tests/verilog/assign_to_reg.ys diff --git a/backends/verilog/verilog_backend.cc b/backends/verilog/verilog_backend.cc index a09ae984b3e..31bbc996ffa 100644 --- a/backends/verilog/verilog_backend.cc +++ b/backends/verilog/verilog_backend.cc @@ -2014,22 +2014,29 @@ void dump_sync_effect(std::ostream &f, std::string indent, const RTLIL::SigSpec void dump_conn(std::ostream &f, std::string indent, const RTLIL::SigSpec &left, const RTLIL::SigSpec &right) { - if (simple_lhs) { + bool all_chunks_wires = true; + for (auto &chunk : left.chunks()) + if (chunk.is_wire() && reg_wires.count(chunk.wire->name)) + all_chunks_wires = false; + if (!simple_lhs && all_chunks_wires) { + f << stringf("%s" "assign ", indent.c_str()); + dump_sigspec(f, left); + f << stringf(" = "); + dump_sigspec(f, right); + f << stringf(";\n"); + } else { int offset = 0; for (auto &chunk : left.chunks()) { - f << stringf("%s" "assign ", indent.c_str()); + if (chunk.is_wire() && reg_wires.count(chunk.wire->name)) + f << stringf("%s" "always%s\n%s ", indent.c_str(), systemverilog ? "_comb" : " @*", indent.c_str()); + else + f << stringf("%s" "assign ", indent.c_str()); dump_sigspec(f, chunk); f << stringf(" = "); dump_sigspec(f, right.extract(offset, GetSize(chunk))); f << stringf(";\n"); offset += GetSize(chunk); } - } else { - f << stringf("%s" "assign ", indent.c_str()); - dump_sigspec(f, left); - f << stringf(" = "); - dump_sigspec(f, right); - f << stringf(";\n"); } } diff --git a/tests/simple/.gitignore b/tests/simple/.gitignore index 073f46157e1..5daaadbd734 100644 --- a/tests/simple/.gitignore +++ b/tests/simple/.gitignore @@ -1,2 +1,3 @@ *.log *.out +*.err diff --git a/tests/verilog/.gitignore b/tests/verilog/.gitignore index 96ebe20ba26..cfd72076e4e 100644 --- a/tests/verilog/.gitignore +++ b/tests/verilog/.gitignore @@ -1,6 +1,10 @@ /*.log /*.out +/*.err /run-test.mk /const_arst.v /const_sr.v /doubleslash.v +/roundtrip_proc_1.v +/roundtrip_proc_2.v +/assign_to_reg.v diff --git a/tests/verilog/assign_to_reg.ys b/tests/verilog/assign_to_reg.ys new file mode 100644 index 00000000000..80080e9f372 --- /dev/null +++ b/tests/verilog/assign_to_reg.ys @@ -0,0 +1,22 @@ +# https://github.com/yosyshq/yosys/issues/2035 + +read_ilang <