def __call__(cls, *args, **kwargs): cls._pyha_is_initialization = True # flag to avoid problems in __setattr__ ret = super(Meta, cls).__call__(*args, **kwargs) if not SimulationRunning.is_enabled(): # local objects are simplified, they need no reset or register behaviour ret._pyha_next = {} ret._pyha_updateable = [] for k, v in ret.__dict__.items(): if k.startswith('_pyha') or k == '__dict__': continue if isinstance(v, np.ndarray): v = np_to_py(v) from pyha.common.ram import RAM if isinstance(v, list) and not isinstance(ret, RAM): v = PyhaList(v, ret.__class__.__name__, k) ret.__dict__[k] = v if is_constant(k): continue if hasattr(v, '_pyha_update_registers'): ret._pyha_updateable.append(v) continue ret._pyha_next[k] = deepcopy(v) ret.__dict__['_pyha_initial_self'] = deepcopy(ret) # TODO: this exists only for initial values, deepcopy very slow on large objects! del cls._pyha_is_initialization return ret
def _pyha_constructor_arg(self): if is_constant(self._name): return '' if not self.elements_compatible_typed: return ';'.join(x._pyha_constructor_arg() for x in self.elems) return super()._pyha_constructor_arg()
def build_data_structs(self): template = textwrap.dedent("""\ type self_t is record {DATA} end record;""") data = [ x._pyha_definition() for x in self.data.elems if not is_constant(x._name) ] if not data: data = ['dummy: integer;'] return template.format(DATA=formatter(data))
def _pyha_constructor(self): if is_constant(self._name): return '' name = self._pyha_name() return 'self.{} := {};'.format(name, name)
def _pyha_constructor_arg(self): if is_constant(self._name): return '' name = self._pyha_name() return '{}: {}'.format(name, self._pyha_type())
def transform_constants(red_node): nodes = red_node.find_all('atomtrailers') for node in nodes: const = any([is_constant(x.dumps()) for x in node]) if const and node[0].dumps() == 'self': node[0].replace('self_const')
def make_reset(self): data = [ x._pyha_reset(filter_func=lambda x: not is_constant(x._name)) for x in self.simulated_object_vhdl.elems ] return formatter(data)