def setup_class(cls): if option.runappdirect: py.test.skip("Can't run this test with -A") space = gettestobjspace(usemodules=('pypyjit',)) cls.space = space w_f = space.appexec([], """(): def f(): pass return f """) ll_code = cast_instance_to_base_ptr(w_f.code) logger = Logger(MockSD()) oplist = parse(""" [i1, i2] i3 = int_add(i1, i2) guard_true(i3) [] """, namespace={'ptr0': 3}).operations def interp_on_compile(): pypyjitdriver.on_compile(logger, LoopToken(), oplist, 'loop', 0, False, ll_code) def interp_on_compile_bridge(): pypyjitdriver.on_compile_bridge(logger, LoopToken(), oplist, 0) cls.w_on_compile = space.wrap(interp2app(interp_on_compile)) cls.w_on_compile_bridge = space.wrap(interp2app(interp_on_compile_bridge))
def f(x, y): if x > 20: a = None else: a = A(x, y) a1 = cast_instance_to_base_ptr(a) return a1
def ll_start_new_thread(l_func, arg): l_arg = cast_instance_to_base_ptr(arg) l_arg = rffi.cast(rffi.VOIDP, l_arg) ident = c_thread_start(l_func, l_arg) if ident == -1: raise error("can't start new thread") return ident
def setup_class(cls): if option.runappdirect: py.test.skip("Can't run this test with -A") space = gettestobjspace(usemodules=('pypyjit',)) cls.space = space w_f = space.appexec([], """(): def function(): pass return function """) cls.w_f = w_f ll_code = cast_instance_to_base_ptr(w_f.code) code_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, ll_code) logger = Logger(MockSD()) oplist = parse(""" [i1, i2, p2] i3 = int_add(i1, i2) debug_merge_point(0, 0, 0, 0, 0, ConstPtr(ptr0)) guard_nonnull(p2) [] guard_true(i3) [] """, namespace={'ptr0': code_gcref}).operations greenkey = [ConstInt(0), ConstInt(0), ConstPtr(code_gcref)] offset = {} for i, op in enumerate(oplist): if i != 1: offset[op] = i di_loop = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(), oplist, 'loop', greenkey) di_loop_optimize = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(), oplist, 'loop', greenkey) di_loop.asminfo = AsmInfo(offset, 0, 0) di_bridge = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(), oplist, 'bridge', fail_descr_no=0) di_bridge.asminfo = AsmInfo(offset, 0, 0) def interp_on_compile(): di_loop.oplist = cls.oplist pypy_hooks.after_compile(di_loop) def interp_on_compile_bridge(): pypy_hooks.after_compile_bridge(di_bridge) def interp_on_optimize(): di_loop_optimize.oplist = cls.oplist pypy_hooks.before_compile(di_loop_optimize) def interp_on_abort(): pypy_hooks.on_abort(ABORT_TOO_LONG, pypyjitdriver, greenkey, 'blah') cls.w_on_compile = space.wrap(interp2app(interp_on_compile)) cls.w_on_compile_bridge = space.wrap(interp2app(interp_on_compile_bridge)) cls.w_on_abort = space.wrap(interp2app(interp_on_abort)) cls.w_int_add_num = space.wrap(rop.INT_ADD) cls.w_dmp_num = space.wrap(rop.DEBUG_MERGE_POINT) cls.w_on_optimize = space.wrap(interp2app(interp_on_optimize)) cls.orig_oplist = oplist
def f(): s = T() ls = cast_instance_to_base_ptr(s) as_num = rffi.cast(lltype.Signed, ls) # --- around this point, only 'as_num' is passed t = rffi.cast(rclass.OBJECTPTR, as_num) u = cast_base_ptr_to_instance(S, t) return u.x
def test_cast_instance_to_base_ptr(self): class X(object): pass x = X() ptr = annlowlevel.cast_instance_to_base_ptr(x) assert lltype.typeOf(ptr) == annlowlevel.base_ptr_lltype() y = annlowlevel.cast_base_ptr_to_instance(X, ptr) assert y is x
def f(x, y): if x > 20: a = None else: a = A(x, y) a1 = cast_instance_to_base_ptr(a) b = cast_base_ptr_to_instance(A, a1) return a is b
def save_exception_memoryerr(): from pypy.rpython.annlowlevel import cast_instance_to_base_ptr save_exception() if not self.saved_exc_value: exc = MemoryError() exc = cast_instance_to_base_ptr(exc) exc = lltype.cast_opaque_ptr(llmemory.GCREF, exc) self.saved_exc_value = exc
def get_llexception(cpu, e): if we_are_translated(): return cast_instance_to_base_ptr(e) assert not isinstance(e, JitException) if isinstance(e, LLException): return e.args[1] # ok if isinstance(e, OverflowError): return _get_standard_error(cpu.rtyper, OverflowError) raise # leave other exceptions to be propagated
def cast_instance_to_gcref(x): # Before translation, casts an RPython instance into a _GcRef. # After translation, it is a variant of cast_object_to_ptr(GCREF). if we_are_translated(): from pypy.rpython import annlowlevel x = annlowlevel.cast_instance_to_base_ptr(x) return lltype.cast_opaque_ptr(llmemory.GCREF, x) else: return _GcRef(x)
def f(v0, v1): B(0) vinst = C(v0, v1) vobj = cast_instance_to_base_ptr(vinst) gptr(vobj) x = vinst.v0 y = vinst.v1 vinst.x return x + y + len(vinst.x)
def f(v0, v1): B(0) vinst = C(v0, v1) vobj = cast_instance_to_base_ptr(vinst) gptr(vobj) x = vinst.v0 y = vinst.v1 vinst.x return x+y+len(vinst.x)
def f(n): s = S() s.x = n ls = cast_instance_to_base_ptr(s) as_num = rffi.cast(lltype.Signed, ls) # --- around this point, only 'as_num' is passed r = rffi.cast(llmemory.GCREF, as_num) t = lltype.cast_opaque_ptr(rclass.OBJECTPTR, r) u = cast_base_ptr_to_instance(S, t) return u.x
def prepare_for_residual_call(self, jitstate, gv_base, vable_rti): typedesc = self.typedesc assert isinstance(typedesc, VirtualizableStructTypeDesc) builder = jitstate.curbuilder gv_outside = self.content_boxes[-1].genvar base_desc = typedesc.base_desc base_token = base_desc.fieldtoken builder.genop_setfield(base_token, gv_outside, gv_base) vable_rti_ptr = cast_instance_to_base_ptr(vable_rti) gv_vable_rti = builder.rgenop.genconst(vable_rti_ptr) rti_token = typedesc.rti_desc.fieldtoken builder.genop_setfield(rti_token, gv_outside, gv_vable_rti) access_token = typedesc.access_desc.fieldtoken builder.genop_setfield(access_token, gv_outside, typedesc.gv_access)
def _add_pending_fields(self, pending_setfields): rd_pendingfields = lltype.nullptr(PENDINGFIELDSP.TO) if pending_setfields: n = len(pending_setfields) rd_pendingfields = lltype.malloc(PENDINGFIELDSP.TO, n) for i in range(n): descr, box, fieldbox, itemindex = pending_setfields[i] lldescr = annlowlevel.cast_instance_to_base_ptr(descr) num = self._gettagged(box) fieldnum = self._gettagged(fieldbox) # the index is limited to 2147483647 (64-bit machines only) if itemindex > 2147483647: from pypy.jit.metainterp import compile compile.giveup() itemindex = rffi.cast(rffi.INT, itemindex) # rd_pendingfields[i].lldescr = lldescr rd_pendingfields[i].num = num rd_pendingfields[i].fieldnum = fieldnum rd_pendingfields[i].itemindex= itemindex self.storage.rd_pendingfields = rd_pendingfields
def f(v): vinst = V(v) vobj = cast_instance_to_base_ptr(vinst) gptr(vobj) vinst.v = 33
def _cast_to_gcref(obj): return lltype.cast_opaque_ptr(llmemory.GCREF, cast_instance_to_base_ptr(obj))
def f(x, y): a = A(x, y) a1 = cast_instance_to_base_ptr(a) return a1
def g(): e = OverflowError() lle = cast_instance_to_base_ptr(e) raise lle # instead, must cast back from a base ptr to an instance
def hide(self): ptr = cast_instance_to_base_ptr(self) return lltype.cast_opaque_ptr(llmemory.GCREF, ptr)
def f(v): vinst = V(v) vobj = cast_instance_to_base_ptr(vinst) gptr(vobj) x = vinst.v return x
def setup_class(cls): if option.runappdirect: py.test.skip("Can't run this test with -A") space = gettestobjspace(usemodules=('pypyjit', )) cls.space = space w_f = space.appexec([], """(): def function(): pass return function """) cls.w_f = w_f ll_code = cast_instance_to_base_ptr(w_f.code) code_gcref = lltype.cast_opaque_ptr(llmemory.GCREF, ll_code) logger = Logger(MockSD()) oplist = parse(""" [i1, i2, p2] i3 = int_add(i1, i2) debug_merge_point(0, 0, 0, 0, ConstPtr(ptr0)) guard_nonnull(p2) [] guard_true(i3) [] """, namespace={ 'ptr0': code_gcref }).operations greenkey = [ConstInt(0), ConstInt(0), ConstPtr(code_gcref)] offset = {} for i, op in enumerate(oplist): if i != 1: offset[op] = i di_loop = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(), oplist, 'loop', greenkey) di_loop_optimize = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(), oplist, 'loop', greenkey) di_loop.asminfo = AsmInfo(offset, 0, 0) di_bridge = JitDebugInfo(MockJitDriverSD, logger, JitCellToken(), oplist, 'bridge', fail_descr_no=0) di_bridge.asminfo = AsmInfo(offset, 0, 0) def interp_on_compile(): di_loop.oplist = cls.oplist pypy_hooks.after_compile(di_loop) def interp_on_compile_bridge(): pypy_hooks.after_compile_bridge(di_bridge) def interp_on_optimize(): di_loop_optimize.oplist = cls.oplist pypy_hooks.before_compile(di_loop_optimize) def interp_on_abort(): pypy_hooks.on_abort(ABORT_TOO_LONG, pypyjitdriver, greenkey, 'blah') cls.w_on_compile = space.wrap(interp2app(interp_on_compile)) cls.w_on_compile_bridge = space.wrap( interp2app(interp_on_compile_bridge)) cls.w_on_abort = space.wrap(interp2app(interp_on_abort)) cls.w_int_add_num = space.wrap(rop.INT_ADD) cls.w_on_optimize = space.wrap(interp2app(interp_on_optimize)) cls.orig_oplist = oplist