write_verilog: don't `assign` to a `reg`.

Fixes #2035.
This commit is contained in:
Catherine 2024-04-03 08:01:58 +00:00 committed by Marcelina Kościelnicka
parent 040605b047
commit d9a4a42389
4 changed files with 42 additions and 8 deletions

View File

@ -2014,9 +2014,22 @@ 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) 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; int offset = 0;
for (auto &chunk : left.chunks()) { for (auto &chunk : left.chunks()) {
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()); f << stringf("%s" "assign ", indent.c_str());
dump_sigspec(f, chunk); dump_sigspec(f, chunk);
f << stringf(" = "); f << stringf(" = ");
@ -2024,12 +2037,6 @@ void dump_conn(std::ostream &f, std::string indent, const RTLIL::SigSpec &left,
f << stringf(";\n"); f << stringf(";\n");
offset += GetSize(chunk); offset += GetSize(chunk);
} }
} else {
f << stringf("%s" "assign ", indent.c_str());
dump_sigspec(f, left);
f << stringf(" = ");
dump_sigspec(f, right);
f << stringf(";\n");
} }
} }

View File

@ -1,2 +1,3 @@
*.log *.log
*.out *.out
*.err

View File

@ -1,6 +1,10 @@
/*.log /*.log
/*.out /*.out
/*.err
/run-test.mk /run-test.mk
/const_arst.v /const_arst.v
/const_sr.v /const_sr.v
/doubleslash.v /doubleslash.v
/roundtrip_proc_1.v
/roundtrip_proc_2.v
/assign_to_reg.v

View File

@ -0,0 +1,22 @@
# https://github.com/yosyshq/yosys/issues/2035
read_ilang <<END
module \top
wire width 1 input 0 \halfbrite
wire width 2 output 1 \r_on
process $1
assign \r_on [1:0] 2'00
assign \r_on [1:0] 2'11
switch \halfbrite [0]
case 1'1
assign \r_on [1] 1'0
end
end
end
END
proc_prune
write_verilog assign_to_reg.v
design -reset
logger -expect-no-warnings
read_verilog assign_to_reg.v