Skip to content

Commit 067d652

Browse files
rroohhhwhitequark
authored andcommitted
hdl._nir: AssignmentList: fix comb_edges_to
Only include the condition of a assignment in the comb edges if the assignment assigns to the bit in question.
1 parent 91233ef commit 067d652

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

amaranth/hdl/_nir.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,8 +921,8 @@ def __repr__(self):
921921
def comb_edges_to(self, bit):
922922
yield (self.default[bit], self.src_loc)
923923
for assign in self.assignments:
924-
yield (assign.cond, assign.src_loc)
925924
if bit >= assign.start and bit < assign.start + len(assign.value):
925+
yield (assign.cond, assign.src_loc)
926926
yield (assign.value[bit - assign.start], assign.src_loc)
927927

928928

tests/test_hdl_ir.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3678,6 +3678,30 @@ def test_cycle(self):
36783678
r"$"):
36793679
build_netlist(Fragment.get(m, None), [])
36803680

3681+
def test_assignment_cycle(self):
3682+
a = Signal(2)
3683+
m = Module()
3684+
3685+
with m.If(a[0]):
3686+
m.d.comb += a[0].eq(1)
3687+
3688+
with self.assertRaisesRegex(CombinationalCycle,
3689+
r"^Combinational cycle detected, path:\n"
3690+
r".*test_hdl_ir.py:\d+: cell Matches bit 0\n"
3691+
r".*test_hdl_ir.py:\d+: signal a bit 0\n"
3692+
r".*test_hdl_ir.py:\d+: cell AssignmentList bit 0\n"
3693+
r".*test_hdl_ir.py:\d+: cell PriorityMatch bit 0\n"
3694+
r"$"):
3695+
build_netlist(Fragment.get(m, None), [])
3696+
3697+
m = Module()
3698+
3699+
with m.If(a[0]):
3700+
m.d.comb += a[1].eq(1)
3701+
3702+
# no cycle here, a[1] gets assigned and a[0] gets checked
3703+
build_netlist(Fragment.get(m, None), [])
3704+
36813705

36823706
class DomainLookupTestCase(FHDLTestCase):
36833707
def test_domain_lookup(self):

0 commit comments

Comments
 (0)