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

Records with zero-width fields used as module ports break Yosys #335

Closed
jfng opened this issue Mar 16, 2020 · 0 comments
Closed

Records with zero-width fields used as module ports break Yosys #335

jfng opened this issue Mar 16, 2020 · 0 comments

Comments

@jfng
Copy link
Member

jfng commented Mar 16, 2020

Repro:

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


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

        r1 = Record([("addr", 0), ("data", 8)])
        r2 = Record([("addr", 0), ("data", 8)])
        r3 = Record([("addr", 0), ("data", 8)])

        m.submodules.a = a = Module()
        m.submodules.b = b = Module()

        a.d.comb += r1.eq(0)
        m.d.comb += r2.eq(r1)
        b.d.comb += r3.eq(r2)

        return m


print(verilog.convert(Top()))
# print(rtlil.convert(Top()))

This time Yosys chokes with a parser error:

Traceback (most recent call last):
  File "repro.py", line 23, in <module>
    print(verilog.convert(Top()))
  File "/home/jf/src/nmigen/nmigen/back/verilog.py", line 78, in convert
    return _convert_rtlil_text(rtlil_text, strip_internal_attrs=strip_internal_attrs)
  File "/home/jf/src/nmigen/nmigen/back/verilog.py", line 66, in _convert_rtlil_text
    raise YosysError(error.strip())
nmigen.back.verilog.YosysError: ERROR: Parser error in line 37: syntax error

RTLIL output:

attribute \generator "nMigen"
attribute \nmigen.hierarchy "top.a"
module \a
  attribute \src "repro.py:9"
  wire width 8 output 1 \r1__data
  wire width 1 $verilog_initial_trigger
  process $group_0
    assign { } 0'0
    assign \r1__data 8'00000000
    assign { \r1__data { } } 8'00000000
    assign $verilog_initial_trigger $verilog_initial_trigger
    sync init
      update $verilog_initial_trigger 1'0
  end
end
attribute \generator "nMigen"
attribute \nmigen.hierarchy "top.b"
module \b
  attribute \src "repro.py:10"
  wire width 8 input 1 \r2__data
  attribute \src "repro.py:11"
  wire width 8 \r3__data
  process $group_0
    assign { } 0'0
    assign \r3__data 8'00000000
    assign { \r3__data { } } { \r2__data { } }
    sync init
  end
end
attribute \generator "nMigen"
attribute \top 1
attribute \nmigen.hierarchy "top"
module \top
  attribute \src "repro.py:9"
  wire width 8 \a_r1__data
  cell \a \a
    connect { } { }
    connect \r1__data \a_r1__data
  end
  attribute \src "repro.py:10"
  wire width 8 \b_r2__data
  cell \b \b
    connect { } { }
    connect \r2__data \b_r2__data
  end
  process $group_0
    assign { } 0'0
    assign \b_r2__data 8'00000000
    assign { \b_r2__data { } } { \a_r1__data { } }
    sync init
  end
end

Originally posted by @jfng in #312 (comment)

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

No branches or pull requests

2 participants