Skip to content

Commit

Permalink
hdl._nir: AssignmentList: fix comb_edges_to
Browse files Browse the repository at this point in the history
Only include the condition of a assignment in the comb edges if the assignment assigns to the bit in question.
  • Loading branch information
rroohhh authored and whitequark committed Sep 19, 2024
1 parent 91233ef commit 067d652
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion amaranth/hdl/_nir.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,8 +921,8 @@ def __repr__(self):
def comb_edges_to(self, bit):
yield (self.default[bit], self.src_loc)
for assign in self.assignments:
yield (assign.cond, assign.src_loc)
if bit >= assign.start and bit < assign.start + len(assign.value):
yield (assign.cond, assign.src_loc)
yield (assign.value[bit - assign.start], assign.src_loc)


Expand Down
24 changes: 24 additions & 0 deletions tests/test_hdl_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -3678,6 +3678,30 @@ def test_cycle(self):
r"$"):
build_netlist(Fragment.get(m, None), [])

def test_assignment_cycle(self):
a = Signal(2)
m = Module()

with m.If(a[0]):
m.d.comb += a[0].eq(1)

with self.assertRaisesRegex(CombinationalCycle,
r"^Combinational cycle detected, path:\n"
r".*test_hdl_ir.py:\d+: cell Matches bit 0\n"
r".*test_hdl_ir.py:\d+: signal a bit 0\n"
r".*test_hdl_ir.py:\d+: cell AssignmentList bit 0\n"
r".*test_hdl_ir.py:\d+: cell PriorityMatch bit 0\n"
r"$"):
build_netlist(Fragment.get(m, None), [])

m = Module()

with m.If(a[0]):
m.d.comb += a[1].eq(1)

# no cycle here, a[1] gets assigned and a[0] gets checked
build_netlist(Fragment.get(m, None), [])


class DomainLookupTestCase(FHDLTestCase):
def test_domain_lookup(self):
Expand Down

0 comments on commit 067d652

Please sign in to comment.