From d334f4dbb658da2150d4ddf2e9df4626563bda81 Mon Sep 17 00:00:00 2001 From: Robin Ole Heinemann Date: Thu, 17 Oct 2024 15:08:25 +0200 Subject: [PATCH] hdl._dsl: use Enum for fsm state signal --- amaranth/hdl/_dsl.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/amaranth/hdl/_dsl.py b/amaranth/hdl/_dsl.py index 9cf0b2b4b..cf5805b29 100644 --- a/amaranth/hdl/_dsl.py +++ b/amaranth/hdl/_dsl.py @@ -581,7 +581,7 @@ def _pop_ctrl(self): data["name"], data["init"], data["encoding"], data["decoding"], data["states"], data["ongoing"] fsm_state_src_locs = data["state_src_locs"] if not fsm_states: - data["signal"] = Signal(0, name=f"{fsm_name}_state", src_loc_at=2) + data["signal"] = Signal(0, name=f"{fsm_name}_state", src_loc_at=3) return if fsm_init is None: init = fsm_encoding[next(iter(fsm_states))] @@ -589,9 +589,9 @@ def _pop_ctrl(self): init = fsm_encoding[fsm_init] # The FSM is encoded such that the state with encoding 0 is always the init state. fsm_decoding.update((n, s) for s, n in fsm_encoding.items()) - data["signal"] = fsm_signal = Signal(range(len(fsm_encoding)), init=init, - name=f"{fsm_name}_state", src_loc_at=2, - decoder=lambda n: f"{fsm_decoding[n]}/{n}") + data["signal"] = fsm_signal = Signal( + Enum(f"{fsm_name}State", [(f"{fsm_decoding[n]}/{n}", n) for n in range(len(fsm_decoding))]), + init=init, name=f"{fsm_name}_state", src_loc_at=3) for name, sig in fsm_ongoing.items(): self._top_comb_statements.append(