2013-06-25 16:17:39 -04:00
|
|
|
from migen.genlib.fsm import FSM, NextState
|
2012-11-11 08:30:25 -05:00
|
|
|
|
2013-06-25 16:17:39 -04:00
|
|
|
def id_next_state(l):
|
|
|
|
return NextState(id(l))
|
2012-11-11 08:30:25 -05:00
|
|
|
|
|
|
|
# entry state is first state returned
|
|
|
|
class StateAssembler:
|
|
|
|
def __init__(self):
|
|
|
|
self.states = []
|
|
|
|
self.exit_states = []
|
|
|
|
|
|
|
|
def assemble(self, n_states, n_exit_states):
|
|
|
|
self.states += n_states
|
|
|
|
for exit_state in self.exit_states:
|
2013-06-25 16:17:39 -04:00
|
|
|
exit_state.insert(0, id_next_state(n_states[0]))
|
2012-11-11 08:30:25 -05:00
|
|
|
self.exit_states = n_exit_states
|
|
|
|
|
|
|
|
def ret(self):
|
|
|
|
return self.states, self.exit_states
|
|
|
|
|
|
|
|
def implement_fsm(states):
|
2013-06-25 16:17:39 -04:00
|
|
|
fsm = FSM()
|
|
|
|
for state in states:
|
|
|
|
fsm.act(id(state), state)
|
2012-11-11 08:30:25 -05:00
|
|
|
return fsm
|