def test_get_size_descr(): c0 = GcCache(False) c1 = GcCache(True) T = lltype.GcStruct('T') S = lltype.GcStruct('S', ('x', lltype.Char), ('y', lltype.Ptr(T))) descr_s = get_size_descr(c0, S) descr_t = get_size_descr(c0, T) assert descr_s.size == symbolic.get_size(S, False) assert descr_t.size == symbolic.get_size(T, False) assert descr_s.count_fields_if_immutable() == -1 assert descr_t.count_fields_if_immutable() == -1 assert descr_t.gc_fielddescrs == [] assert len(descr_s.gc_fielddescrs) == 1 assert descr_s == get_size_descr(c0, S) assert descr_s != get_size_descr(c1, S) # descr_s = get_size_descr(c1, S) assert isinstance(descr_s.size, Symbolic) assert descr_s.count_fields_if_immutable() == -1 PARENT = lltype.Struct('P', ('x', lltype.Ptr(T))) STRUCT = lltype.GcStruct('S', ('parent', PARENT), ('y', lltype.Ptr(T))) descr_struct = get_size_descr(c0, STRUCT) assert len(descr_struct.gc_fielddescrs) == 2
def test_get_size_descr(): c0 = GcCache(False) c1 = GcCache(True) T = lltype.GcStruct('T') S = lltype.GcStruct('S', ('x', lltype.Char), ('y', lltype.Ptr(T))) descr_s = get_size_descr(c0, S) descr_t = get_size_descr(c0, T) assert descr_s.size == symbolic.get_size(S, False) assert descr_t.size == symbolic.get_size(T, False) assert descr_s.is_immutable() == False assert descr_t.is_immutable() == False assert descr_t.gc_fielddescrs == [] assert len(descr_s.gc_fielddescrs) == 1 assert descr_s == get_size_descr(c0, S) assert descr_s != get_size_descr(c1, S) # descr_s = get_size_descr(c1, S) assert isinstance(descr_s.size, Symbolic) assert descr_s.is_immutable() == False PARENT = lltype.Struct('P', ('x', lltype.Ptr(T))) STRUCT = lltype.GcStruct('S', ('parent', PARENT), ('y', lltype.Ptr(T))) descr_struct = get_size_descr(c0, STRUCT) assert len(descr_struct.gc_fielddescrs) == 2
def get_call_descr(gccache, ARGS, RESULT, extrainfo=None): arg_classes = map(map_type_to_argclass, ARGS) arg_classes = ''.join(arg_classes) result_type = map_type_to_argclass(RESULT, accept_void=True) RESULT_ERASED = RESULT if RESULT is lltype.Void: result_size = 0 result_signed = False else: if isinstance(RESULT, lltype.Ptr): # avoid too many CallDescrs if result_type == 'r': RESULT_ERASED = llmemory.GCREF else: RESULT_ERASED = llmemory.Address result_size = symbolic.get_size(RESULT_ERASED, gccache.translate_support_code) result_signed = get_type_flag(RESULT) == FLAG_SIGNED key = (arg_classes, result_type, result_signed, RESULT_ERASED, extrainfo) cache = gccache._cache_call try: calldescr = cache[key] except KeyError: calldescr = CallDescr(arg_classes, result_type, result_signed, result_size, extrainfo) calldescr.create_call_stub(gccache.rtyper, RESULT_ERASED) cache[key] = calldescr assert repr(calldescr.result_size) == repr(result_size) return calldescr
def get_size_descr(gccache, STRUCT, vtable=lltype.nullptr(rclass.OBJECT_VTABLE)): cache = gccache._cache_size assert not isinstance(vtable, bool) try: return cache[STRUCT] except KeyError: size = symbolic.get_size(STRUCT, gccache.translate_support_code) immutable_flag = heaptracker.is_immutable_struct(STRUCT) if vtable: assert heaptracker.has_gcstruct_a_vtable(STRUCT) else: assert not heaptracker.has_gcstruct_a_vtable(STRUCT) sizedescr = SizeDescr(size, vtable=vtable, immutable_flag=immutable_flag) gccache.init_size_descr(STRUCT, sizedescr) cache[STRUCT] = sizedescr # XXX do we really need gc_fielddescrs if we also have # all_fielddescrs and can ask is_pointer_field() on them? gc_fielddescrs = heaptracker.gc_fielddescrs(gccache, STRUCT) sizedescr.gc_fielddescrs = gc_fielddescrs all_fielddescrs = heaptracker.all_fielddescrs(gccache, STRUCT) sizedescr.all_fielddescrs = all_fielddescrs return sizedescr
def test_get_size_descr(): c0 = GcCache(False) c1 = GcCache(True) T = lltype.GcStruct('T') S = lltype.GcStruct('S', ('x', lltype.Char), ('y', lltype.Ptr(T))) descr_s = get_size_descr(c0, S) descr_t = get_size_descr(c0, T) assert descr_s.size == symbolic.get_size(S, False) assert descr_t.size == symbolic.get_size(T, False) assert descr_s.count_fields_if_immutable() == -1 assert descr_t.count_fields_if_immutable() == -1 assert descr_s == get_size_descr(c0, S) assert descr_s != get_size_descr(c1, S) # descr_s = get_size_descr(c1, S) assert isinstance(descr_s.size, Symbolic) assert descr_s.count_fields_if_immutable() == -1
def get_field_arraylen_descr(gccache, ARRAY_OR_STRUCT): cache = gccache._cache_arraylen try: return cache[ARRAY_OR_STRUCT] except KeyError: tsc = gccache.translate_support_code (_, _, ofs) = symbolic.get_array_token(ARRAY_OR_STRUCT, tsc) size = symbolic.get_size(lltype.Signed, tsc) result = FieldDescr("len", ofs, size, get_type_flag(lltype.Signed)) cache[ARRAY_OR_STRUCT] = result return result
def test_repr_of_descr(): def repr_of_descr(descr): s = descr.repr_of_descr() assert ',' not in s # makes the life easier for pypy.tool.jitlogparser return s c0 = GcCache(False) T = lltype.GcStruct('T') S = lltype.GcStruct('S', ('x', lltype.Char), ('y', lltype.Ptr(T)), ('z', lltype.Ptr(T))) descr1 = get_size_descr(c0, S) s = symbolic.get_size(S, False) assert repr_of_descr(descr1) == '<SizeDescr %d>' % s # descr2 = get_field_descr(c0, S, 'y') o, _ = symbolic.get_field_token(S, 'y', False) assert repr_of_descr(descr2) == '<FieldP S.y %d>' % o # descr2i = get_field_descr(c0, S, 'x') o, _ = symbolic.get_field_token(S, 'x', False) assert repr_of_descr(descr2i) == '<FieldU S.x %d>' % o # descr3 = get_array_descr(c0, lltype.GcArray(lltype.Ptr(S))) o = symbolic.get_size(lltype.Ptr(S), False) assert repr_of_descr(descr3) == '<ArrayP %d>' % o # descr3i = get_array_descr(c0, lltype.GcArray(lltype.Char)) assert repr_of_descr(descr3i) == '<ArrayU 1>' # descr4 = get_call_descr(c0, [lltype.Char, lltype.Ptr(S)], lltype.Ptr(S)) assert repr_of_descr(descr4) == '<Callr %d ir>' % o # descr4i = get_call_descr(c0, [lltype.Char, lltype.Ptr(S)], lltype.Char) assert repr_of_descr(descr4i) == '<Calli 1 ir>' # descr4f = get_call_descr(c0, [lltype.Char, lltype.Ptr(S)], lltype.Float) assert repr_of_descr(descr4f) == '<Callf 8 ir>' # descr5f = get_call_descr(c0, [lltype.Char], lltype.SingleFloat) assert repr_of_descr(descr5f) == '<CallS 4 i>'
def get_size_descr(gccache, STRUCT): cache = gccache._cache_size try: return cache[STRUCT] except KeyError: size = symbolic.get_size(STRUCT, gccache.translate_support_code) count_fields_if_immut = heaptracker.count_fields_if_immutable(STRUCT) if heaptracker.has_gcstruct_a_vtable(STRUCT): sizedescr = SizeDescrWithVTable(size, count_fields_if_immut) else: sizedescr = SizeDescr(size, count_fields_if_immut) gccache.init_size_descr(STRUCT, sizedescr) cache[STRUCT] = sizedescr return sizedescr
def get_size_descr(gccache, STRUCT): cache = gccache._cache_size try: return cache[STRUCT] except KeyError: size = symbolic.get_size(STRUCT, gccache.translate_support_code) count_fields_if_immut = heaptracker.count_fields_if_immutable(STRUCT) gc_fielddescrs = heaptracker.gc_fielddescrs(gccache, STRUCT) if heaptracker.has_gcstruct_a_vtable(STRUCT): sizedescr = SizeDescrWithVTable(size, count_fields_if_immut, gc_fielddescrs) else: sizedescr = SizeDescr(size, count_fields_if_immut, gc_fielddescrs) gccache.init_size_descr(STRUCT, sizedescr) cache[STRUCT] = sizedescr return sizedescr