Skip to content

Commit

Permalink
hdl.ir: bring new naming rules to top-level ports
Browse files Browse the repository at this point in the history
  • Loading branch information
tpwrules committed Mar 25, 2024
1 parent 1cab145 commit e0bbaca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions amaranth/hdl/_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ def _assign_port_names(self):
raise TypeError("Signals with private names cannot be used in unnamed top-level ports")
name = _add_name(assigned_names, conn.name)
assigned_names.add(name)
validate_name(name, "Top-level port name")
new_ports.append((name, conn, dir))
self.ports = new_ports

Expand Down
6 changes: 6 additions & 0 deletions tests/test_hdl_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,12 @@ def test_assign_names_to_fragments_duplicate(self):
self.assertEqual(design.fragments[a1_f].name, ("top", "a"))
self.assertEqual(design.fragments[a2_f].name, ("top", "a$1"))

def test_port_wrong_name(self):
f = Fragment()
with self.assertRaisesRegex(NameError,
r"^Top-level port name must be a non-empty string$"):
design = Design(f, ports=[("", Signal(), None)], hierarchy=("top",))


class ElaboratesTo(Elaboratable):
def __init__(self, lower):
Expand Down

0 comments on commit e0bbaca

Please sign in to comment.