class _RHSValueCompiler(ValueTransformer):
def __init__(self, sensitivity=None):
self.sensitivity = sensitivity
- self.signal_mode = "next"
def on_Const(self, value):
return lambda state: value.value
def on_Signal(self, value):
if self.sensitivity is not None:
self.sensitivity.add(value)
- if self.signal_mode == "curr":
- return lambda state: state.curr[value]
- if self.signal_mode == "next":
- return lambda state: state.next[value]
- raise NotImplementedError # :nocov:
+ return lambda state: state.curr[value]
def on_ClockSignal(self, value):
raise NotImplementedError # :nocov:
self.sensitivity = ValueSet()
self.rhs_compiler = _RHSValueCompiler(self.sensitivity)
- @contextmanager
- def initial(self):
- try:
- self.rhs_compiler.signal_mode = "curr"
- yield
- finally:
- self.rhs_compiler.signal_mode = "next"
-
def lhs_compiler(self, value):
# TODO
return lambda state, arg: state.set(value, arg)
self._sync_signals.update(signals)
self._domain_signals[domain].update(signals)
- initial_stmts = []
+ statements = []
for signal in fragment.iter_comb():
- initial_stmts.append(signal.eq(signal.reset))
+ statements.append(signal.eq(signal.reset))
for domain, signal in fragment.iter_sync():
- initial_stmts.append(signal.eq(signal))
+ statements.append(signal.eq(signal))
+ statements += fragment.statements
compiler = _StatementCompiler()
- def make_funclet():
- with compiler.initial():
- funclet_init = compiler(initial_stmts)
- funclet_frag = compiler(fragment.statements)
- def funclet(state):
- funclet_init(state)
- funclet_frag(state)
- return funclet
- funclet = make_funclet()
+ funclet = compiler(statements)
def add_funclet(signal, funclet):
if signal not in self._funclets:
self._passive.add(process)
elif isinstance(cmd, Value):
- funclet = _RHSValueCompiler()(cmd)
+ compiler = _RHSValueCompiler()
+ funclet = compiler(cmd)
cmd = process.send(funclet(self._state))
continue
"simulation"
.format(format_process(process), signal))
- funclet = _StatementCompiler()(cmd)
+ compiler = _StatementCompiler()
+ funclet = compiler(cmd)
funclet(self._state)
domains = set()