Esempio 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
Esempio n. 2
0
 def mapToIR(self, ctx: EmitterContext):
     name = ctx.getName(self)
     mtyp = self.typ.mapToIR(ctx)
     defm = low_ir.DefMemory(name, mtyp)
     ctx.appendFinalStatement(defm, self.scopeId)
     ref = low_ir.Reference(name, mtyp)
     ctx.updateRef(self, ref)
     return ref
Esempio n. 3
0
def _mapToIR(io, ctx, lowIR):
    name = ctx.getName(io)
    typ = io.typ.mapToIR(ctx)
    port = low_ir.Port(name, lowIR, typ)
    ref = low_ir.Reference(name, typ)
    ctx.updateRef(io, ref)
    ctx.appendFinalPort(port)
    return ref
Esempio n. 4
0
    def mapToIR(self, ctx: EmitterContext):
        typ = self.typ.mapToIR(ctx)
        name = ctx.getName(self)

        w = low_ir.DefRegister(name, typ, ctx.getClock())
        ctx.appendFinalStatement(w, self.scopeId)
        ref = low_ir.Reference(name, typ)
        ctx.updateRef(self, ref)

        return ref
Esempio n. 5
0
    def mapToIR(self, ctx: EmitterContext):
        typ = ctx.getRef(self.typ)
        name = ctx.getName(self)

        w = low_ir.DefWire(name, typ)
        ctx.appendFinalStatement(w, self.scopeId)
        ref = low_ir.Reference(name, typ)
        ctx.updateRef(self, ref)

        return ref
Esempio n. 6
0
    def mapToIR(self, ctx: EmitterContext):
        val = ctx.getRef(self.initValue)
        name = ctx.getName(self)

        w = low_ir.DefRegister(name, val.typ, ctx.getClock(), ctx.getReset(),
                               val)
        ctx.appendFinalStatement(w, self.scopeId)
        ref = low_ir.Reference(name, val.typ)
        ctx.updateRef(self, ref)

        return ref
Esempio n. 7
0
    def mapToIR(self, ctx: EmitterContext):
        name = ctx.getName(self)
        fs = []
        for k, v in self._ios.items():
            f = v.mapToIOFieldIR(k, ctx)
            fs.append(f)

        typ = low_ir.BundleType(fs)
        port = low_ir.Port(name, low_ir.Output(), low_ir.BundleType(fs))
        ref = low_ir.Reference(name, typ)
        ctx.updateRef(self, ref)
        ctx.appendFinalPort(port)
        return ref
Esempio n. 8
0
    def mapToIR(self, ctx: EmitterContext):
        name = ctx.getName(self)

        cond = ctx.getRef(self.cond)
        conseq = ctx.getRef(self.conseq)
        alt = ctx.getRef(self.alt)

        m = low_ir.Mux(cond, conseq, alt, conseq.typ)
        n = low_ir.DefNode(name, m)
        ctx.appendFinalStatement(n, self.scopeId)
        ref = low_ir.Reference(name, conseq.typ)
        ctx.updateRef(self, ref)

        return ref
Esempio n. 9
0
def _primMap(ctx: EmitterContext, obj, op, args, consts, tranFormFunc):
    if consts is None:
        consts = []

    # get items' reference and do checking
    ars = [ctx.getRef(a) for a in args]
    newArgs, typ = tranFormFunc(*ars)

    e = low_ir.DoPrim(op, newArgs, consts, typ)
    name = ctx.getName(obj)
    node = low_ir.DefNode(name, e)
    ctx.appendFinalStatement(node, obj.scopeId)
    ref = low_ir.Reference(name, typ)
    ctx.updateRef(obj, ref)
    return ref
Esempio n. 10
0
    def mapToIR(self, ctx: EmitterContext):
        # Define Wire
        name = ctx.getName(self)
        typ = self.typ.mapToIR(ctx)
        wire = low_ir.DefWire(name, typ)
        ctx.appendFinalStatement(wire, self.scopeId)
        ref = low_ir.Reference(name, typ)
        ctx.updateRef(self, ref)

        # Connect Elements
        for i, node in enumerate(self.lst):
            for idx, elem in self.subIdxs(low_ir.SubIndex(ref, i, typ.typ),
                                          node, ctx):
                con = low_ir.Connect(idx, elem)
                ctx.appendFinalStatement(con, self.scopeId)

        return ref
Esempio n. 11
0
 def getReset(self):
     return low_ir.Reference("reset", low_ir.UIntType(low_ir.IntWidth(1)))
Esempio n. 12
0
 def getClock(self):
     return low_ir.Reference("clock", low_ir.ClockType())