コード例 #1
0
 def _doConnect(ctx, lref, rref, scopeId):
     if isinstance(lref.typ, low_ir.UIntType) and isinstance(
             rref.typ, low_ir.UIntType):
         if lref.typ.width.width is not None and rref.typ.width.width is not None:
             if lref.typ.width.width >= rref.typ.width.width:
                 Connect._unsafeConnect(lref, rref, ctx, scopeId)
             else:
                 bits = low_ir.DoPrim(low_ir.Bits(), [rref],
                                      [lref.typ.width.width - 1, 0],
                                      lref.typ)
                 Connect._unsafeConnect(lref, bits, ctx, scopeId)
         else:
             Connect._unsafeConnect(lref, rref, ctx, scopeId)
     elif isinstance(lref.typ, low_ir.SIntType) and isinstance(
             rref.typ, low_ir.SIntType):
         if lref.typ.width.width is not None and rref.typ.width.width is not None:
             if lref.typ.width.width >= rref.typ.width.width:
                 Connect._unsafeConnect(lref, rref, ctx, scopeId)
             else:
                 bits = low_ir.DoPrim(low_ir.Bits(), [rref],
                                      [lref.typ.width.width - 1, 0],
                                      lref.typ)
                 Connect._unsafeConnect(lref, bits, ctx, scopeId)
         else:
             Connect._unsafeConnect(lref, rref, ctx, scopeId)
     else:
         raise Exception("type does not match")
コード例 #2
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