Skip to content

cxxsim: synchronous assignment inside If statement is not executed #455

@megng1

Description

@megng1

(with the cxxsim branch checked out at 060ad25)

Repro:

from nmigen import *
from nmigen.sim.cxxsim import *

m = Module()
i = Signal()
o = Signal()
x = Signal()

m.d.comb += x.eq(i)
with m.If(x):
    m.d.sync += o.eq(1)


def process():
    yield i.eq(1)
    yield Delay()
    yield
    yield Delay()
    assert (yield o) == 1

sim = Simulator(m)
sim.add_sync_process(process)
sim.add_clock(1e-6)
with sim.write_vcd("repro.vcd"):
    sim.run()

Output:

Traceback (most recent call last):
  File "repro.py", line 26, in <module>
    sim.run()
  File "/home/jf/src/nmigen/nmigen/sim/_core.py", line 202, in run
    while self.advance():
  File "/home/jf/src/nmigen/nmigen/sim/_core.py", line 191, in advance
    self._real_step()
  File "/home/jf/src/nmigen/nmigen/sim/cxxsim.py", line 124, in _real_step
    process.run()
  File "/home/jf/src/nmigen/nmigen/sim/_pycoro.py", line 121, in run
    self.coroutine.throw(exn)
  File "/home/jf/src/nmigen/nmigen/sim/_pycoro.py", line 62, in run
    command = self.coroutine.send(response)
  File "/home/jf/src/nmigen/nmigen/sim/_core.py", line 102, in wrapper
    yield from process()
  File "repro.py", line 21, in process
    assert (yield o) == 1
AssertionError

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions