Skip to content

Commit f5a8c07

Browse files
wanda-phiwhitequark
authored andcommitted
sim: raise an exception on add_clock conflict with comb driver.
1 parent 66ad0a2 commit f5a8c07

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

amaranth/sim/pysim.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,10 @@ def reset(self):
616616
testbench.reset()
617617

618618
def add_clock_process(self, clock, *, phase, period):
619+
slot = self.state.get_signal(clock)
620+
if self.state.slots[slot].is_comb:
621+
raise DriverConflict("Clock signal is already driven by combinational logic")
622+
619623
self._processes.add(PyClockProcess(self._state, clock,
620624
phase=phase, period=period))
621625

tests/test_sim.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,15 @@ async def testbench(ctx):
14971497
sim.add_testbench(testbench)
14981498
sim.run()
14991499

1500+
def test_comb_clock_conflict(self):
1501+
c = Signal()
1502+
m = Module()
1503+
m.d.comb += ClockSignal().eq(c)
1504+
sim = Simulator(m)
1505+
with self.assertRaisesRegex(DriverConflict,
1506+
r"^Clock signal is already driven by combinational logic$"):
1507+
sim.add_clock(1e-6)
1508+
15001509
def test_sample(self):
15011510
m = Module()
15021511
m.domains.sync = cd_sync = ClockDomain()

0 commit comments

Comments
 (0)