Skip to content

Commit

Permalink
hdl._dsl: use Enum for fsm state signal
Browse files Browse the repository at this point in the history
  • Loading branch information
rroohhh authored and whitequark committed Oct 20, 2024
1 parent b6bf515 commit ef4f68a
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions amaranth/hdl/_dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,17 +581,17 @@ 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))]
else:
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(
Expand Down

0 comments on commit ef4f68a

Please sign in to comment.