Skip to content

Commit 6c08d6a

Browse files
committed
hdl.dsl: bring new naming rules to FSM
States are not "names" as such and still allowed to be (relatively) arbitrary objects.
1 parent 0c189d7 commit 6c08d6a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

amaranth/hdl/_dsl.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import warnings
66
import sys
77

8-
from .._utils import flatten
8+
from .._utils import flatten, validate_name
99
from ..utils import bits_for
1010
from .. import tracer
1111
from ._ast import *
@@ -426,6 +426,8 @@ def FSM(self, init=None, domain="sync", name="fsm", *, reset=None):
426426
warnings.warn("`reset=` is deprecated, use `init=` instead",
427427
DeprecationWarning, stacklevel=2)
428428
init = reset
429+
validate_name(name, "FSM name")
430+
validate_name(domain, "FSM clock domain")
429431
fsm_data = self._set_ctrl("FSM", {
430432
"name": name,
431433
"init": init,

tests/test_hdl_dsl.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,17 @@ def test_FSM_wrong_next(self):
792792
with m.FSM():
793793
m.next = "FOO"
794794

795+
def test_FSM_wrong_name(self):
796+
m = Module()
797+
with self.assertRaisesRegex(TypeError,
798+
r"^FSM name must be a string, not 1$"):
799+
with m.FSM(name=1):
800+
pass
801+
with self.assertRaisesRegex(TypeError,
802+
r"^FSM clock domain must be a string, not 1$"):
803+
with m.FSM(domain=1):
804+
pass
805+
795806
def test_If_inside_FSM_wrong(self):
796807
m = Module()
797808
with m.FSM():

0 commit comments

Comments
 (0)