amaranth-lang / amaranth

A modern hardware definition language and toolchain based on Python
https://amaranth-lang.org/docs/amaranth/
BSD 2-Clause "Simplified" License
1.55k stars 170 forks source link

Running `simulate` without specifying a VCD file yields an unhelpful error message (AttributeError: 'NoneType' object has no attribute 'register_var') #319

Closed the6p4c closed 4 years ago

the6p4c commented 4 years ago

Issue This isn't hard to reproduce with any of the provided examples, say ctr.py. Running python ctr.py simulate -c 10, for example, produces a Python traceback rather than a friendly error message.

Traceback (most recent call last):
  File "ctr.py", line 19, in <module>
    main(ctr, ports=[ctr.o])
  File "/path-to-python/site-packages/nmigen/cli.py", line 76, in main
    main_runner(parser, parser.parse_args(), *args, **kwargs)
  File "/path-to-python/site-packages/nmigen/cli.py", line 69, in main_runner
    traces=ports) as sim:
  File "/path-to-python/site-packages/nmigen/back/pysim.py", line 915, in __init__
    self._state.start_waveform(_VCDWaveformWriter(self._signal_names, **kwargs))
  File "/path-to-python/nmigen/back/pysim.py", line 115, in __init__
    vcd_var = self.vcd_writer.register_var(
AttributeError: 'NoneType' object has no attribute 'register_var'

I can only assume it's down to this line (pysim.py:82):

self.vcd_writer = vcd_file and VCDWriter(self.vcd_file,
            timescale="100 ps", comment="Generated by nMigen")

Expected behaviour Either VCD_FILE is a required parameter, a default is specified or a more user-friendly error message is generated.

whitequark commented 4 years ago

(A broader question is, is nmigen.cli even useful beyond example code?)