Skip to content

Commit 8c5ed40

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 c609025 commit 8c5ed40

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
@@ -3571,6 +3571,30 @@ def test_cycle(self):
35713571
r"$"):
35723572
build_netlist(Fragment.get(m, None), [])
35733573

3574+
def test_assignment_cycle(self):
3575+
a = Signal(2)
3576+
m = Module()
3577+
3578+
with m.If(a[0]):
3579+
m.d.comb += a[0].eq(1)
3580+
3581+
with self.assertRaisesRegex(CombinationalCycle,
3582+
r"^Combinational cycle detected, path:\n"
3583+
r".*test_hdl_ir.py:\d+: cell Matches bit 0\n"
3584+
r".*test_hdl_ir.py:\d+: signal a bit 0\n"
3585+
r".*test_hdl_ir.py:\d+: cell AssignmentList bit 0\n"
3586+
r".*test_hdl_ir.py:\d+: cell PriorityMatch bit 0\n"
3587+
r"$"):
3588+
build_netlist(Fragment.get(m, None), [])
3589+
3590+
m = Module()
3591+
3592+
with m.If(a[0]):
3593+
m.d.comb += a[1].eq(1)
3594+
3595+
# no cycle here, a[1] gets assigned and a[0] gets checked
3596+
build_netlist(Fragment.get(m, None), [])
3597+
35743598

35753599
class DomainLookupTestCase(FHDLTestCase):
35763600
def test_domain_lookup(self):

0 commit comments

Comments
 (0)