def calldescrof(self, FUNC, ARGS, RESULT, extrainfo): arg_types = [] for ARG in ARGS: token = history.getkind(ARG) if token != "void": if token == "float" and longlong.is_longlong(ARG): token = "L" arg_types.append(token[0]) token = history.getkind(RESULT) if token == "float" and longlong.is_longlong(RESULT): token = "L" return self.getdescr(0, token[0], extrainfo=extrainfo, arg_types="".join(arg_types))
def calldescrof(self, FUNC, ARGS, RESULT, extrainfo=None): arg_types = [] for ARG in ARGS: token = history.getkind(ARG) if token != 'void': if token == 'float' and longlong.is_longlong(ARG): token = 'L' arg_types.append(token[0]) token = history.getkind(RESULT) if token == 'float' and longlong.is_longlong(RESULT): token = 'L' return self.getdescr(0, token[0], extrainfo=extrainfo, arg_types=''.join(arg_types))
def calldescrof(self, FUNC, ARGS, RESULT, extrainfo): arg_types = [] for ARG in ARGS: token = history.getkind(ARG) if token != 'void': if token == 'float' and longlong.is_longlong(ARG): token = 'L' arg_types.append(token[0]) token = history.getkind(RESULT) if token == 'float' and longlong.is_longlong(RESULT): token = 'L' return self.getdescr(0, token[0], extrainfo=extrainfo, arg_types=''.join(arg_types))
def map_type_to_argclass(ARG, accept_void=False): kind = getkind(ARG) if kind == 'int': if ARG is lltype.SingleFloat: return 'S' else: return 'i' elif kind == 'ref': return 'r' elif kind == 'float': if is_longlong(ARG): return 'L' else: return 'f' elif kind == 'void': if accept_void: return 'v' raise NotImplementedError('ARG = %r' % (ARG,))
def map_type_to_argclass(ARG, accept_void=False): kind = getkind(ARG) if kind == 'int': if ARG is lltype.SingleFloat: return 'S' else: return 'i' elif kind == 'ref': return 'r' elif kind == 'float': if is_longlong(ARG): return 'L' else: return 'f' elif kind == 'void': if accept_void: return 'v' raise NotImplementedError('ARG = %r' % (ARG, ))
def get_type_flag(TYPE): if isinstance(TYPE, lltype.Ptr): if TYPE.TO._gckind == "gc": return FLAG_POINTER else: return FLAG_UNSIGNED if isinstance(TYPE, lltype.Struct): return FLAG_STRUCT if TYPE is lltype.Float or is_longlong(TYPE): return FLAG_FLOAT if TYPE is not lltype.Bool and isinstance(TYPE, lltype.Number) and rffi.cast(TYPE, -1) == -1: return FLAG_SIGNED return FLAG_UNSIGNED
def get_type_flag(TYPE): if isinstance(TYPE, lltype.Ptr): if TYPE.TO._gckind == 'gc': return FLAG_POINTER else: return FLAG_UNSIGNED if isinstance(TYPE, lltype.Struct): return FLAG_STRUCT if TYPE is lltype.Float or is_longlong(TYPE): return FLAG_FLOAT if (TYPE is not lltype.Bool and isinstance(TYPE, lltype.Number) and rffi.cast(TYPE, -1) == -1): return FLAG_SIGNED return FLAG_UNSIGNED
def set_future_value(cpu, j, value, typecode): if typecode == 'ref': refvalue = cpu.ts.cast_to_ref(value) cpu.set_future_value_ref(j, refvalue) elif typecode == 'int': intvalue = lltype.cast_primitive(lltype.Signed, value) cpu.set_future_value_int(j, intvalue) elif typecode == 'float': if lltype.typeOf(value) is lltype.Float: value = longlong.getfloatstorage(value) else: assert longlong.is_longlong(lltype.typeOf(value)) value = rffi.cast(lltype.SignedLongLong, value) cpu.set_future_value_float(j, value) else: assert False
def emit_const(self, const, kind, allow_short=False): value = const.value if kind == 'int': TYPE = const.concretetype if isinstance(TYPE, lltype.Ptr): assert TYPE.TO._gckind == 'raw' self.see_raw_object(value) value = llmemory.cast_ptr_to_adr(value) TYPE = llmemory.Address if TYPE == llmemory.Address: value = heaptracker.adr2int(value) if TYPE is lltype.SingleFloat: value = longlong.singlefloat2int(value) if not isinstance(value, (llmemory.AddressAsInt, ComputedIntSymbolic)): value = lltype.cast_primitive(lltype.Signed, value) if allow_short: try: short_num = -128 <= value <= 127 except TypeError: # "Symbolics cannot be compared!" short_num = False if short_num: # emit the constant as a small integer self.code.append(chr(value & 0xFF)) return True constants = self.constants_i elif kind == 'ref': value = lltype.cast_opaque_ptr(llmemory.GCREF, value) constants = self.constants_r elif kind == 'float': if const.concretetype == lltype.Float: value = longlong.getfloatstorage(value) else: assert longlong.is_longlong(const.concretetype) value = rffi.cast(lltype.SignedLongLong, value) constants = self.constants_f else: raise AssemblerError('unimplemented %r in %r' % (const, self.ssareprname)) key = (kind, Constant(value)) if key not in self.constants_dict: constants.append(value) self.constants_dict[key] = 256 - len(constants) # emit the constant normally, as one byte that is an index in the # list of constants self.code.append(chr(self.constants_dict[key])) return False
def map_type_to_argclass(ARG, accept_void=False): kind = getkind(ARG) if kind == "int": if ARG is lltype.SingleFloat: return "S" else: return "i" elif kind == "ref": return "r" elif kind == "float": if is_longlong(ARG): return "L" else: return "f" elif kind == "void": if accept_void: return "v" raise NotImplementedError("ARG = %r" % (ARG,))
def specialize_value(TYPE, x): """'x' must be a Signed, a GCREF or a FLOATSTORAGE. This function casts it to a more specialized type, like Char or Ptr(..). """ INPUT = lltype.typeOf(x) if INPUT is lltype.Signed: if isinstance(TYPE, lltype.Ptr) and TYPE.TO._gckind == 'raw': # non-gc pointer return rffi.cast(TYPE, x) elif TYPE is lltype.SingleFloat: return longlong.int2singlefloat(x) else: return lltype.cast_primitive(TYPE, x) elif INPUT is longlong.FLOATSTORAGE: if longlong.is_longlong(TYPE): return rffi.cast(TYPE, x) assert TYPE is lltype.Float return longlong.getrealfloat(x) else: return lltype.cast_opaque_ptr(TYPE, x)
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(lltype.typeOf(value), ootype.OOType): value = ootype.cast_to_object(value) if in_const_box: return history.ConstObj(value) else: return history.BoxObj(value) 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)