hdl.dsl: add signal decoder to FSM state signal.
authorwhitequark <cz@m-labs.hk>
Wed, 26 Dec 2018 09:45:12 +0000 (09:45 +0000)
committerwhitequark <cz@m-labs.hk>
Wed, 26 Dec 2018 09:45:12 +0000 (09:45 +0000)
nmigen/hdl/dsl.py

index cc16d16163b6fe9e304f5c6420bb137e8c5f61ae..7a531a7eeb0505d20574cf58bf7cb5206729ff86 100644 (file)
@@ -298,6 +298,8 @@ class Module(_ModuleBuilderRoot):
             fsm_signal, fsm_encoding, fsm_states = data["signal"], data["encoding"], data["states"]
             fsm_signal.nbits = bits_for(len(fsm_encoding) - 1)
             # The FSM is encoded such that the state with encoding 0 is always the reset state.
+            fsm_decoding = {n: s for s, n in fsm_encoding.items()}
+            fsm_signal.decoder = lambda v: "{}/{}".format(fsm_decoding[n], n)
             self._statements.append(Switch(fsm_signal,
                 OrderedDict((fsm_encoding[name], stmts) for name, stmts in fsm_states.items())))