Beispiel #1
0
    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
Beispiel #2
0
    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()
Beispiel #3
0
    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))
Beispiel #4
0
    def _pyha_constructor(self):
        if is_constant(self._name):
            return ''

        name = self._pyha_name()
        return 'self.{} := {};'.format(name, name)
Beispiel #5
0
    def _pyha_constructor_arg(self):
        if is_constant(self._name):
            return ''

        name = self._pyha_name()
        return '{}: {}'.format(name, self._pyha_type())
Beispiel #6
0
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')
Beispiel #7
0
 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)