Example #1
0
 def compile(self, cx, out):
     psum, pside, p = cx.local(), cx.local(), cx.local()
     tp = self.type.llvm(cx)
     sst = lu.sumSideType(tp)
     return self.expr.compile(cx, psum) + [
         inst.bitcast('i1*', '%s*' % sst, psum, pside),
         inst.structGEP(pside, sst, p, 1),
         inst.load(tp, p, out)] + mem.reference(out, self.type, cx) + \
         mem.unreference(psum, self.expr.type, cx)
Example #2
0
def heapCreate(ltype, value, cx, out):
    voidp, rcp, rcval = cx.local(), cx.local(), cx.local()
    cx.useBuiltin('~malloc')
    rctype = mem.rctype(ltype, cx)
    return formAggregate(rctype, cx, rcval, 1, value) + [
        '%s = call %%voidptr @malloc(%%size_t %d)' % (voidp, rctype.size),
        inst.bitcast('%voidptr', lt.Pointer(rctype, cx), voidp, rcp),
        inst.store(rctype, rcval, rcp),
        inst.structGEP(rcp, rctype, out, 1)
    ]
Example #3
0
def createClosure(clType, clStuff, destructor, cx, out):
    t = closureTypeFull(clType, cx)
    voidp, rcp, rcval = cx.local(), cx.local(), cx.local()
    cx.useBuiltin('~malloc')
    return lu.formAggregate(t, cx, rcval, destructor, 1, clStuff) + [
        '%s = call %%voidptr @malloc(%%size_t %d)' % (voidp, t.size),
        inst.bitcast('%voidptr', lt.Pointer(t, cx), voidp, rcp),
        inst.store(t, rcval, rcp),
        inst.structGEP(rcp, t, out, 2)
    ]
Example #4
0
 def destroySide(i):
     lt_i = mtype.parms[i].llvm(cx)
     sst = lu.sumSideType(lt_i)
     r, sp, mp = cx.local(), cx.local(), cx.local()
     unrefCode = unreference(r, mtype.parms[i], cx)
     if not unrefCode: return []
     return [
         inst.bitcast('i1*', lt.Pointer(sst, cx), '%object', sp),
         inst.structGEP(sp, sst, mp, 1),
         inst.load(lt_i, mp, r)
     ] + unrefCode
Example #5
0
def closureDestructorDefinition(name, clType, items, cx):
    sig = 'void %s(%%voidptr %%cl)' % name
    clTypeFull = closureTypeFull(clType, cx)
    body = []
    for i, (ltype, unrefCode, reg) in enumerate(items):
        unrefCode = unrefCode(cx)
        if unrefCode:
            body += [inst.extractvalue(clType, '%stuff', i, reg)] + unrefCode
    if body:
        body = [
            inst.bitcast('%voidptr', lt.Pointer(clTypeFull, cx), '%cl', '%p'),
            inst.structGEP('%p', clTypeFull, '%stuffP', 2),
            inst.load(clType, '%stuffP', '%stuff')
        ] + body
    body += ['call void @free(%voidptr %cl)', inst.ret()]
    return lu.formatFunctionDef(sig, body, cx.llvmVersion)