Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment to a Record with zero-width fields generates invalid Verilog #312

Closed
jfng opened this issue Jan 24, 2020 · 3 comments
Closed

Comments

@jfng
Copy link
Contributor

jfng commented Jan 24, 2020

Repro:

from nmigen import *
from nmigen.back import rtlil, verilog


class Top(Elaboratable):
    def elaborate(self, platform):
        m = Module()

        rec = Record([
            ("a", 1),
            ("b", 0),
        ])

        m.d.comb += rec.eq(1)

        return m


if __name__ == "__main__":
    top = Top()
    print(verilog.convert(top))
    # print(rtlil.convert(top))

Verilog output:

/* Generated by Yosys 0.9+1706 (git sha1 2bda51ac, clang 9.0.0 -fPIC -Os) */

(* generator = "nMigen" *)
(* top =  1  *)
(* \nmigen.hierarchy  = "top" *)
module top();
  (* src = "repro.py:9" *)
  wire rec__a;
  (* src = "repro.py:9" *)
  wire [-1:0] rec__b;
  assign "" = "";
  assign rec__a = 1'h1;
endmodule

RTLIL output:

attribute \top 1
attribute \nmigen.hierarchy "top"
module \top
  attribute \src "repro.py:9"
  wire width 1 \rec__a
  attribute \src "repro.py:9"
  wire width 0 \rec__b
  wire width 1 $verilog_initial_trigger
  process $group_0
    assign \rec__a 1'0
    assign \rec__b 0'0
    assign { \rec__b \rec__a } 1'1
    assign $verilog_initial_trigger $verilog_initial_trigger
    sync init
      update $verilog_initial_trigger 1'0
  end
  connect \rec__b 0'0
end
@whitequark
Copy link
Contributor

Hm, arguably this is a bug in Yosys, but I think we can just not generate assignments to zero width lvalues.

@whitequark
Copy link
Contributor

whitequark commented Jan 31, 2020

Fixed in my fork.

@sbourdeauducq
Copy link
Member

Fixed upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants