示例#1
0
def wrap(cpu, value, in_const_box=False):
    if isinstance(lltype.typeOf(value), lltype.Ptr):
        if lltype.typeOf(value).TO._gckind == 'gc':
            value = lltype.cast_opaque_ptr(llmemory.GCREF, value)
            if in_const_box:
                return history.ConstPtr(value)
            else:
                return history.BoxPtr(value)
        else:
            adr = llmemory.cast_ptr_to_adr(value)
            value = heaptracker.adr2int(adr)
            # fall through to the end of the function
    elif (isinstance(value, float)
          or longlong.is_longlong(lltype.typeOf(value))):
        if isinstance(value, float):
            value = longlong.getfloatstorage(value)
        else:
            value = rffi.cast(lltype.SignedLongLong, value)
        if in_const_box:
            return history.ConstFloat(value)
        else:
            return history.BoxFloat(value)
    elif isinstance(value, str) or isinstance(value, unicode):
        assert len(value) == 1  # must be a character
        value = ord(value)
    elif lltype.typeOf(value) is lltype.SingleFloat:
        value = longlong.singlefloat2int(value)
    else:
        value = intmask(value)
    if in_const_box:
        return history.ConstInt(value)
    else:
        return history.BoxInt(value)
示例#2
0
 def handle_call_assembler(self, op):
     descrs = self.gc_ll_descr.getframedescrs(self.cpu)
     loop_token = op.getdescr()
     assert isinstance(loop_token, history.JitCellToken)
     jfi = loop_token.compiled_loop_token.frame_info
     llfi = heaptracker.adr2int(llmemory.cast_ptr_to_adr(jfi))
     size_box = history.BoxInt()
     frame = history.BoxPtr()
     self.gen_malloc_frame(llfi, frame, size_box)
     op2 = ResOperation(rop.SETFIELD_GC,
                        [frame, history.ConstInt(llfi)],
                        None,
                        descr=descrs.jf_frame_info)
     self.newops.append(op2)
     arglist = op.getarglist()
     index_list = loop_token.compiled_loop_token._ll_initial_locs
     for i, arg in enumerate(arglist):
         descr = self.cpu.getarraydescr_for_frame(arg.type)
         assert self.cpu.JITFRAME_FIXED_SIZE & 1 == 0
         _, itemsize, _ = self.cpu.unpack_arraydescr_size(descr)
         index = index_list[i] // itemsize  # index is in bytes
         self.newops.append(
             ResOperation(rop.SETARRAYITEM_GC,
                          [frame, ConstInt(index), arg], None, descr))
     descr = op.getdescr()
     assert isinstance(descr, JitCellToken)
     jd = descr.outermost_jitdriver_sd
     args = [frame]
     if jd and jd.index_of_virtualizable >= 0:
         args = [frame, arglist[jd.index_of_virtualizable]]
     else:
         args = [frame]
     self.newops.append(
         ResOperation(rop.CALL_ASSEMBLER, args, op.result, op.getdescr()))
示例#3
0
 class MyMIFrame:
     jitcode = JitCode("test")
     jitcode.setup(
         "\xFF"  # illegal instruction
         "\x00\x00\x01\x02"  # int_add/ii>i
         "\x01\x02",  # int_return/i
         [],
         num_regs_i=3,
         num_regs_r=0,
         num_regs_f=0)
     jitcode.jitdriver_sd = "foo"  # not none
     pc = 1
     registers_i = [history.BoxInt(40), history.ConstInt(2), None]
示例#4
0
 def gen_malloc_frame(self, frame_info, frame, size_box):
     descrs = self.gc_ll_descr.getframedescrs(self.cpu)
     if self.gc_ll_descr.kind == 'boehm':
         op0 = ResOperation(rop.GETFIELD_RAW,
                            [history.ConstInt(frame_info)],
                            size_box,
                            descr=descrs.jfi_frame_depth)
         self.newops.append(op0)
         op1 = ResOperation(rop.NEW_ARRAY, [size_box],
                            frame,
                            descr=descrs.arraydescr)
         self.handle_new_array(descrs.arraydescr, op1)
     else:
         # we read size in bytes here, not the length
         op0 = ResOperation(rop.GETFIELD_RAW,
                            [history.ConstInt(frame_info)],
                            size_box,
                            descr=descrs.jfi_frame_size)
         self.newops.append(op0)
         self.gen_malloc_nursery_varsize_frame(size_box, frame)
         self.gen_initialize_tid(frame, descrs.arraydescr.tid)
         length_box = history.BoxInt()
         # we need to explicitely zero all the gc fields, because
         # of the unusal malloc pattern
         extra_ops = [
             ResOperation(rop.GETFIELD_RAW, [history.ConstInt(frame_info)],
                          length_box,
                          descr=descrs.jfi_frame_depth),
             ResOperation(rop.SETFIELD_GC, [frame, self.c_zero],
                          None,
                          descr=descrs.jf_extra_stack_depth),
             ResOperation(rop.SETFIELD_GC, [frame, self.c_null],
                          None,
                          descr=descrs.jf_savedata),
             ResOperation(rop.SETFIELD_GC, [frame, self.c_null],
                          None,
                          descr=descrs.jf_force_descr),
             ResOperation(rop.SETFIELD_GC, [frame, self.c_null],
                          None,
                          descr=descrs.jf_descr),
             ResOperation(rop.SETFIELD_GC, [frame, self.c_null],
                          None,
                          descr=descrs.jf_guard_exc),
             ResOperation(rop.SETFIELD_GC, [frame, self.c_null],
                          None,
                          descr=descrs.jf_forward),
         ]
         self.newops += extra_ops
         self.gen_initialize_len(frame, length_box,
                                 descrs.arraydescr.lendescr)