hdl.dsl: gracefully handle FSM with no states.

This commit is contained in:
whitequark 2019-07-07 00:59:34 +00:00
parent 146f3cb684
commit 3388b5b085
2 changed files with 10 additions and 0 deletions

View file

@ -337,6 +337,8 @@ class Module(_ModuleBuilderRoot, Elaboratable):
if name == "FSM":
fsm_signal, fsm_reset, fsm_encoding, fsm_decoding, fsm_states = \
data["signal"], data["reset"], data["encoding"], data["decoding"], data["states"]
if not fsm_states:
return
fsm_signal.nbits = bits_for(len(fsm_encoding) - 1)
if fsm_reset is None:
fsm_signal.reset = fsm_encoding[next(iter(fsm_states))]

View file

@ -449,6 +449,14 @@ class DSLTestCase(FHDLTestCase):
)
""")
def test_FSM_empty(self):
m = Module()
with m.FSM():
pass
self.assertRepr(m._statements, """
()
""")
def test_FSM_wrong_redefined(self):
m = Module()
with m.FSM():