Ejemplo n.º 1
0
    def _doMap(self, ctx, idx, ref):
        rf = ctx.getRef(ref)

        if isinstance(idx, Node):
            idx = ctx.getRef(idx)

        v = rf.typ.irWithIndex(idx)(rf)
        ir = v["ir"]
        if "inNode" in v:
            # ground type
            name = ctx.getName(self)
            node = low_ir.DefNode(name, ir)
            ctx.appendFinalStatement(node, self.scopeId)
            ref = low_ir.Reference(name, ir.typ)
            ctx.updateRef(self, ref)
            return ref
        elif "inPort" in v:
            # memory type
            name = ctx.getName(self)
            memPort = ir(name, rf, ctx.getClock(),
                         self._mem_rw if has_attr(self, "_mem_rw") else True)
            ctx.appendFinalStatement(memPort, self.scopeId)
            ref = low_ir.Reference(name, rf.typ.typ)
            ctx.updateRef(self, ref)
            return ref
        else:
            return ir
Ejemplo n.º 2
0
    def mapToIR(self, ctx: EmitterContext):
        from pyhcl.dsl.vector import Vec

        if has_attr(self.lhs, "typ") and has_attr(self.rhs, "typ") \
                and (isinstance(self.lhs.typ, Vec) or isinstance(self.rhs.typ, Vec)):
            lhs = OneDimensionalization(self.lhs)
            rhs = OneDimensionalization(self.rhs)

            if len(lhs) != len(rhs):
                raise Exception("vector size does not match")

            for l, r in zip(lhs, rhs):
                Connect._doConnect(ctx, l.mapToIR(ctx), r.mapToIR(ctx),
                                   self.scopeId)
        else:
            Connect._doConnect(ctx, ctx.getRef(self.lhs), ctx.getRef(self.rhs),
                               self.scopeId)
Ejemplo n.º 3
0
    def mapToIR(self, ctx: EmitterContext):
        from pyhcl.dsl.vector import Vec
        from pyhcl import IO

        if has_attr(self.lhs, "typ") and has_attr(self.rhs, "typ") \
                and (isinstance(self.lhs.typ, Vec) or isinstance(self.rhs.typ, Vec)):
            lhs = OneDimensionalization(self.lhs)
            rhs = OneDimensionalization(self.rhs)

            if len(lhs) != len(rhs):
                raise Exception("vector size does not match")

            for l, r in zip(lhs, rhs):
                Connect._doConnect(ctx, l.mapToIR(ctx), r.mapToIR(ctx),
                                   self.scopeId)

        # A trick to do inheriting connect
        elif has_attr(self.lhs, "value") and has_attr(self.rhs, "value") \
                and (isinstance(self.lhs.value, IO) or isinstance(self.rhs.value, IO)):
            for (key_left, value_left) in self.lhs.value._ios.items():
                for (key_right, value_right) in self.rhs.value._ios.items():
                    from pyhcl import Input, Output
                    assert type(value_left) == Input or type(
                        value_left) == Output
                    assert type(value_right) == Input or type(
                        value_right) == Output

                    if key_left == key_right and type(value_left) == type(
                            value_right):
                        lhs = getattr(self.lhs, key_left)
                        rhs = getattr(self.rhs, key_right)
                        if type(value_left) == Output:
                            Connect(lhs, rhs).mapToIR(ctx)
                        else:
                            Connect(rhs, lhs).mapToIR(ctx)

        else:
            Connect._doConnect(ctx, ctx.getRef(self.lhs), ctx.getRef(self.rhs),
                               self.scopeId)
Ejemplo n.º 4
0
 def _transform(self):
     if has_attr(self.ref, "indexTransform"):
         index = get_attr(self.ref, "indexTransform")(self.index)
     else:
         index = self
     return index
Ejemplo n.º 5
0
 def __getattribute__(self, item):
     if has_attr(self, item):
         return get_attr(self, item)
     else:
         return getattr(self.public(), item)