Exemplo n.º 1
0
    def visit_Function(self, node):
        # to avoid to call self.add_object() for the current Module
        self.push_read_only_module()

        name = node.name
        width = self.visit(
            node.retwidth) if node.retwidth is not None else None
        func = function.Function(name, width)
        if node.retwidth is not None:
            func._set_raw_width(self.visit(node.retwidth.msb),
                                self.visit(node.retwidth.lsb))
        statement = [self.visit(s) for s in node.statement]
        body = []

        for s in statement:
            if isinstance(s, (tuple, list)):  # from the visitor result of decl
                for d in s:
                    if isinstance(d, vtypes.Input):
                        t = func.Input(d.name, d.width, d.length, d.signed,
                                       d.value)
                        if d.width_msb is not None and d.width_lsb is not None:
                            t._set_raw_width(d.width_msb, d.width_lsb)
                    elif isinstance(d, vtypes.Reg):
                        t = func.Reg(d.name, d.width, d.length, d.signed,
                                     d.value)
                        if d.width_msb is not None and d.width_lsb is not None:
                            t._set_raw_width(d.width_msb, d.width_lsb)
                    elif isinstance(d, vtypes.Integer):
                        t = func.Integer(d.name, d.width, d.length, d.signed,
                                         d.value)
                        if d.width_msb is not None and d.width_lsb is not None:
                            t._set_raw_width(d.width_msb, d.width_lsb)
                    else:
                        body.append(s)
            else:
                body.append(s)

        func.Body(*body)

        # to restore the current Module
        self.pop_module()

        self.add_object(func)
        return func
Exemplo n.º 2
0
    def visit_Function(self, node):
        # to avoid to call self.add_object() for the current Module
        self.push_read_only_module()

        name = node.name
        raw_width = (self.visit(node.retwidth)
                     if node.retwidth is not None else None)
        width = to_width(raw_width)
        func = function.Function(name, width, raw_width=raw_width)
        statement = [self.visit(s) for s in node.statement]
        body = []

        for s in statement:
            if isinstance(s, (tuple, list)):  # from the visitor result of decl
                for d in s:
                    if isinstance(d, vtypes.Input):
                        t = func.Input(d.name, d.width, d.dims, d.signed,
                                       d.value)
                        t.raw_width = d.raw_width
                        t.raw_dims = d.raw_dims
                    elif isinstance(d, vtypes.Reg):
                        t = func.Reg(d.name, d.width, d.dims, d.signed,
                                     d.value)
                        t.raw_width = d.raw_width
                        t.raw_dims = d.raw_dims
                    elif isinstance(d, vtypes.Integer):
                        t = func.Integer(d.name, d.width, d.dims, d.signed,
                                         d.value)
                        t.raw_width = d.raw_width
                        t.raw_dims = d.raw_dims
                    else:
                        body.append(s)
            else:
                body.append(s)

        func.Body(*body)

        # to restore the current Module
        self.pop_module()

        self.add_object(func)
        return func
Exemplo n.º 3
0
 def Function(self, name, width=1):
     t = function.Function(name, width)
     self.check_existing_identifier(name)
     self.function[name] = t
     self.items.append(t)
     return t