def _as_hdl_HdlModuleDef(self, new_m: HdlModuleDef) -> HdlModuleDef: # with WithNameScope(self, # self.name_scope.get_child(o.module_name.val)): hdl_types, hdl_variables, processes, component_insts = \ ToBasicHdlSimModel.split_HdlModuleDefObjs(self, new_m.objs) # [TODO] sorting not required as it should be done in _to_rtl() hdl_variables.sort(key=lambda x: (x.name, x.origin._instId)) processes.sort(key=lambda x: (x.name, maxStmId(x))) component_insts.sort(key=lambda x: x.name) types = set() _hdl_variables = [] extraVars = [] ns = self.name_scope def createTmpVarInCurrentModuleBody(suggestedName, dtype, const=False, def_val=None): # create a new tmp variable in current module s = RtlSignal(None, None, dtype, virtual_only=True) s.name = ns.checked_name(suggestedName, s) s.hidden = False s._const = const if def_val is not None: s.def_val = def_val s._set_def_val() as_hdl = self.as_hdl_SignalItem(s, declaration=True) extraVars.append(s) _hdl_variables.append(as_hdl) return s with CreateTmpVarFnSwap(self, createTmpVarInCurrentModuleBody): return self._as_hdl_HdlModuleDef_body(new_m, types, hdl_types, hdl_variables, _hdl_variables, processes, component_insts, extraVars)
def as_hdl_HdlStatementBlock(self, proc: HdlStatementBlock) -> iHdlStatement: """ Serialize HdlStatementBlock objects as process if top statement """ if isinstance(proc, HdlStmProcess): return proc assert proc.parentStm is None, proc body = proc.statements extraVars = [] extraVarsHdl = [] hasToBeVhdlProcess = self.has_to_be_process(proc) def createTmpVarInCurrentBlock(suggestedName, dtype, const=False, def_val=None): # create a new tmp variable in current process s = RtlSignal(None, None, dtype, virtual_only=True) s.name = self.name_scope.checked_name(suggestedName, s) s.hidden = False s._const = const if def_val is not None: s.def_val = def_val s._set_def_val() as_hdl = self.as_hdl_SignalItem(s, declaration=True) extraVars.append(s) extraVarsHdl.append(as_hdl) return s with WithNameScope(self, self.name_scope.level_push(proc.name)): with CreateTmpVarFnSwap(self, createTmpVarInCurrentBlock): statements = [self.as_hdl(s) for s in body] # create a initializer for tmp variables # :note: we need to do this here because now it is sure that # the drivers of tmp variable will not be modified extraVarsInit = self.as_hdl_extraVarsInit(extraVars) hasToBeVhdlProcess |= bool(extraVars) if hasToBeVhdlProcess: statements = extraVarsHdl + extraVarsInit + statements if self.can_pop_process_wrap(statements, hasToBeVhdlProcess): return statements[0] else: p = HdlStmProcess() p.labels.append(proc.name) if not statements: pass # no body elif len(statements) == 1: # body made of just a singe statement p.body = statements[0] else: p.body = HdlStmBlock() assert isinstance(statements, list) p.body.body = statements anyIsEventDependnt = arr_any( proc._sensitivity, lambda s: isinstance(s, Operator)) p.sensitivity = sorted([ self.sensitivityListItem(s, anyIsEventDependnt) for s in proc._sensitivity ]) return p