Commit 49ba1676 authored by John Zhang's avatar John Zhang

merge changes from debug-pypy-interp

parents c20c5683 a1f71b7f
......@@ -26,23 +26,51 @@ index af1d380..7a5c762 100644
got = rffi.cast(lltype.Signed, got)
if got > 0:
target_pos += got
diff --git a/pypy/module/array/interp_array.py b/pypy/module/array/interp_array.py
index fd29b2d..c1e9d98 100644
--- a/pypy/module/array/interp_array.py
+++ b/pypy/module/array/interp_array.py
@@ -839,7 +839,9 @@ def make_array(mytype):
return rffi.cast(lltype.Unsigned, self.buffer)
def _charbuf_stop(self):
- keepalive_until_here(self)
+ from rpython.rlib.objectmodel import we_are_translated_to_mu
+ if not we_are_translated_to_mu():
+ keepalive_until_here(self)
def w_getitem(self, space, idx):
item = self.buffer[idx]
diff --git a/rpython/rlib/jit.py b/rpython/rlib/jit.py
index e973a94..b9752e8 100644
index e973a94..46484e8 100644
--- a/rpython/rlib/jit.py
+++ b/rpython/rlib/jit.py
@@ -472,7 +472,7 @@ def virtual_ref(x):
@@ -472,8 +472,10 @@ def virtual_ref(x):
@specialize.argtype(1)
def virtual_ref_finish(vref, x):
"""See docstring in virtual_ref(x)"""
- keepalive_until_here(x) # otherwise the whole function call is removed
+ # keepalive_until_here(x) # otherwise the whole function call is removed
_virtual_ref_finish(vref, x)
- _virtual_ref_finish(vref, x)
+ from rpython.rlib.objectmodel import we_are_translated_to_mu
+ if not we_are_translated_to_mu():
+ keepalive_until_here(x) # otherwise the whole function call is removed
+ # _virtual_ref_finish(vref, x)
def non_virtual_ref(x):
"""Creates a 'vref' that just returns x when called; nothing more special.
diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
index f35e2b7..6aad4b8 100644
index f35e2b7..fd91235 100644
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -640,7 +640,7 @@ if not _WIN32:
DT_DIR = rffi_platform.ConstantInteger('DT_DIR')
DT_LNK = rffi_platform.ConstantInteger('DT_LNK')
- DIRP = rffi.COpaquePtr('DIR')
+ DIRP = rffi.COpaquePtr('DIR', compilation_info=eci)
dirent_config = rffi_platform.configure(CConfig)
DIRENT = dirent_config['DIRENT']
DIRENTP = lltype.Ptr(DIRENT)
@@ -1778,9 +1778,9 @@ def uname():
lltype.free(l_utsbuf, flavor='raw')
......@@ -109,6 +137,19 @@ index b3bc6ed..4edfcaa 100644
@py.test.mark.skipif("not hasattr(os, 'ttyname')")
class TestOsExpect(ExpectTest):
diff --git a/rpython/rtyper/lltypesystem/lltype.py b/rpython/rtyper/lltypesystem/lltype.py
index e6239b4..64a3490 100644
--- a/rpython/rtyper/lltypesystem/lltype.py
+++ b/rpython/rtyper/lltypesystem/lltype.py
@@ -1623,7 +1623,7 @@ class _interior_ptr(_abstract_ptr):
if ob is None:
raise RuntimeError
return InteriorPtr(typeOf(ob), self._T, self._offsets)
-## _TYPE = property(_get_TYPE)
+ _TYPE = property(_get_TYPE)
def _expose(self, offset, val):
"""XXX A nice docstring here"""
diff --git a/rpython/rtyper/lltypesystem/rffi.py b/rpython/rtyper/lltypesystem/rffi.py
index 1b7a007..48d04d5 100644
--- a/rpython/rtyper/lltypesystem/rffi.py
......@@ -200,16 +241,3 @@ index cafc9b1..380db0d 100644
self._execute_c_compiler(cc, args, exe_name,
cwd=str(exe_name.dirpath()))
return exe_name
diff --git a/rpython/rtyper/lltypesystem/lltype.py b/rpython/rtyper/lltypesystem/lltype.py
index e6239b4324..64a3490e32 100644
--- a/rpython/rtyper/lltypesystem/lltype.py
+++ b/rpython/rtyper/lltypesystem/lltype.py
@@ -1623,7 +1623,7 @@ class _interior_ptr(_abstract_ptr):
if ob is None:
raise RuntimeError
return InteriorPtr(typeOf(ob), self._T, self._offsets)
-## _TYPE = property(_get_TYPE)
+ _TYPE = property(_get_TYPE)
def _expose(self, offset, val):
"""XXX A nice docstring here"""
......@@ -83,6 +83,10 @@ def main_(argv=None):
config.objspace.suggest(allworkingmodules=False)
if config.objspace.allworkingmodules:
pypyoption.enable_allworkingmodules(config)
if config.objspace.pytestmodules:
pypyoption.enable_pytestmodules(config)
if config.objspace.pybenchmodules:
pypyoption.enable_pybenchmodules(config)
if config.objspace.usemodules._continuation:
config.translation.continuation = True
if config.objspace.usemodules.thread:
......
......@@ -56,6 +56,16 @@ translation_modules.update([
"termios", "_minimal_curses",
])
pytest_modules = translation_modules.copy()
pytest_modules.update([
'_collections', '_locale',
])
pybench_modules = pytest_modules.copy()
pybench_modules.update([
'unicodedata',
])
# XXX this should move somewhere else, maybe to platform ("is this posixish"
# check or something)
if sys.platform == "win32":
......@@ -163,6 +173,16 @@ pypy_optiondescription = OptionDescription("objspace", "Object Space Options", [
cmdline="--allworkingmodules",
negation=True),
BoolOption("pytestmodules", "modules needed to get basic pytest running",
default=False,
cmdline="--pytestmodules",
suggests=[("objspace.allworkingmodules", False)]),
BoolOption("pybenchmodules", "modules needed to run pybench",
default=False,
cmdline="--pybenchmodules",
suggests=[("objspace.allworkingmodules", False)]),
StrOption("extmodules",
"Comma-separated list of third-party builtin modules",
cmdline="--ext",
......@@ -295,6 +315,15 @@ def enable_translationmodules(config):
modules = [name for name in modules if name not in essential_modules]
config.objspace.usemodules.suggest(**dict.fromkeys(modules, True))
def enable_pytestmodules(config):
modules = pytest_modules
modules = [name for name in modules if name not in essential_modules]
config.objspace.usemodules.suggest(**dict.fromkeys(modules, True))
def enable_pybenchmodules(config):
modules = pybench_modules
modules = [name for name in modules if name not in essential_modules]
config.objspace.usemodules.suggest(**dict.fromkeys(modules, True))
if __name__ == '__main__':
config = get_pypy_config()
......
......@@ -231,6 +231,12 @@ class PyPyTarget(object):
if config.objspace.translationmodules:
from pypy.config.pypyoption import enable_translationmodules
enable_translationmodules(config)
if config.objspace.pytestmodules:
from pypy.config.pypyoption import enable_pytestmodules
enable_pytestmodules(config)
if config.objspace.pybenchmodules:
from pypy.config.pypyoption import enable_pybenchmodules
enable_pybenchmodules(config)
config.translation.suggest(check_str_without_nul=True)
config.translation.suggest(shared=True)
......
......@@ -308,6 +308,15 @@ def we_are_translated():
def sc_we_are_translated(ctx):
return Constant(True)
def we_are_translated_to_mu():
return False
@register_flow_sc(we_are_translated_to_mu)
def sc_we_are_translated_to_mu(ctx):
from rpython.config.translationoption import get_translation_config
config = get_translation_config()
return Constant(config.translation.backend == 'mu')
def register_replacement_for(replaced_function, sandboxed_name=None):
def wrap(func):
from rpython.rtyper.extregistry import ExtRegistryEntry
......
......@@ -53,12 +53,10 @@ class CArrayConst(object):
self.lst = lst
def __str__(self):
if self.c_elm_t == 'MuCString':
return '({type}){value}'.format(type='char*[%d]' % len(self.lst),
value='{%s}' % ', '.join(map(lambda s: str(CStr(s)), self.lst)))
else:
return '({type}){value}'.format(type='%s [%d]' % (self.c_elm_t, len(self.lst)),
value='{%s}' % ', '.join(map(str, self.lst)))
f = lambda s: str(CStr(s)) if self.c_elm_t == 'MuCString' else str(s)
return '({type}){value}'.format(
type='%s [%d]' % (self.c_elm_t, len(self.lst)),
value='{%s}' % ', '.join(map(f, self.lst)))
__repr__ = __str__
......
......@@ -10,7 +10,7 @@ from rpython.translator.tool.cbuild import ExternalCompilationInfo
from rpython.rlib.objectmodel import specialize
import os
zebu_build = os.environ.get('ZEBU_BUILD', 'debug')
zebu_build = os.environ.get('ZEBU_BUILD', 'release')
libmu_dir = os.path.join(os.getenv('MU_ZEBU'), 'target', zebu_build)
eci = ExternalCompilationInfo(libraries=['mu'],
library_dirs=[libmu_dir])
......
......@@ -55,12 +55,10 @@ class CArrayConst(object):
self.lst = lst
def __str__(self):
if self.c_elm_t == 'MuCString':
return '({type}){value}'.format(type='char*[%d]' % len(self.lst),
value='{%s}' % ', '.join(map(lambda s: str(CStr(s)), self.lst)))
else:
return '({type}){value}'.format(type='%s [%d]' % (self.c_elm_t, len(self.lst)),
value='{%s}' % ', '.join(map(str, self.lst)))
f = lambda s: str(CStr(s)) if self.c_elm_t == 'MuCString' else str(s)
return '({type}){value}'.format(
type='%s [%d]' % (self.c_elm_t, len(self.lst)),
value='{%s}' % ', '.join(map(f, self.lst)))
__repr__ = __str__
......@@ -228,7 +226,7 @@ class APILogger:
defs = [
('OBJECTS', ' '.join(['file_%d.o' % i for i in range(num_c_files)]) + ' main.o'),
('INCLUDEDIRS', '-I$(MU_ZEBU)/src/vm/api'),
('LIBDIRS', '-L$(MU_ZEBU)/target/%s' % os.environ.get('ZEBU_BUILD', 'debug')),
('LIBDIRS', '-L$(MU_ZEBU)/target/%s' % os.environ.get('ZEBU_BUILD', 'release')),
('LIBS', '-lmu'),
('TARGET', target),
('CC', platform.cc),
......
......@@ -66,6 +66,8 @@ class MuBundleGen:
config_items.append('automagicReloc=False') # use manual relocation
else:
sep = ' '
# if 'log-level' not in self.mu_config.vmargs:
# config_items.append('--log-level=' + os.environ.get('MU_LOG_LEVEL', 'none'))
if 'emit-dir' not in self.mu_config.vmargs:
config_items.append('--aot-emit-dir=' + 'emit')
for lib in self.db.merged_eci.libraries:
......
......@@ -8,6 +8,7 @@ from rpython.rlib.objectmodel import CDefinedIntSymbolic
from rpython.rlib import rarithmetic
from rpython.flowspace.model import Variable, Constant, SpaceOperation, Link
from rpython.translator.c.node import needs_gcheader
from rpython.translator.platform import CompilationError
from random import randint
import weakref
......@@ -66,7 +67,7 @@ class LL2MuMapper:
self.mlha.rtyper.annotator.translator.graphs)[0]
fnp = lltype.functionptr(lltype.FuncType(
[a.concretetype for a in g.startblock.inputargs], g.returnblock.inputargs[0].concretetype),
g.name, graph=g)
g.name, graph=g)
str2charp_c = Constant(fnp, lltype.typeOf(fnp))
except IndexError:
str2charp_c = self.mlha.constfunc(rffi.str2charp, [SomeString(), SomeBool()], l2a(rffi.CCHARP))
......@@ -125,8 +126,8 @@ class LL2MuMapper:
MuT = self.map_type_ptr(LLT)
elif isinstance(LLT, lltype.InteriorPtr):
MuT = self.map_type_iptr(LLT)
# elif isinstance(LLT, lltype.OpaqueType):
# MuT = self.map_type_opq(LLT)
elif isinstance(LLT, lltype.OpaqueType):
MuT = self.map_type_opq(LLT)
elif LLT is llmemory.WeakRef:
MuT = self.map_wref(LLT)
elif isinstance(LLT, lltype.Typedef):
......@@ -138,20 +139,20 @@ class LL2MuMapper:
def map_type_prim(self, LLT):
type_map = {
lltype.Signed: mutype.MU_INT64,
lltype.Unsigned: mutype.MU_INT64,
lltype.SignedLongLong: mutype.MU_INT64,
lltype.UnsignedLongLong: mutype.MU_INT64,
lltype.SignedLongLongLong: mutype.MU_INT128,
lltype.Float: mutype.MU_DOUBLE,
lltype.SingleFloat: mutype.MU_FLOAT,
lltype.LongFloat: mutype.MU_DOUBLE,
lltype.Char: mutype.MU_INT8,
lltype.Bool: mutype.MU_INT8,
lltype.Void: mutype.MU_VOID,
lltype.UniChar: mutype.MU_INT32, # wchar_t is 32-bits on OS X and Linux 64-bit machines
lltype.Signed: mutype.MU_INT64,
lltype.Unsigned: mutype.MU_INT64,
lltype.SignedLongLong: mutype.MU_INT64,
lltype.UnsignedLongLong: mutype.MU_INT64,
lltype.SignedLongLongLong: mutype.MU_INT128,
lltype.Float: mutype.MU_DOUBLE,
lltype.SingleFloat: mutype.MU_FLOAT,
lltype.LongFloat: mutype.MU_DOUBLE,
lltype.Char: mutype.MU_INT8,
lltype.Bool: mutype.MU_INT8,
lltype.Void: mutype.MU_VOID,
lltype.UniChar: mutype.MU_INT32, # wchar_t is 32-bits on OS X and Linux 64-bit machines
}
try:
return type_map[LLT]
......@@ -162,12 +163,12 @@ class LL2MuMapper:
return getattr(mutype, "MU_INT%d" % b)
else:
return mutype.MuIntType("MU_INT%d" % b,
rarithmetic.build_int('r_uint%d' % b, False, b)) # unsigned
rarithmetic.build_int('r_uint%d' % b, False, b)) # unsigned
raise NotImplementedError("Don't know how to specialise %s using MuTS." % LLT)
def map_type_arrfix(self, LLT):
if LLT.length == 1:
return self.map_type(LLT.OF) # consider length 1 fixed sized array transparent
return self.map_type(LLT.OF) # consider length 1 fixed sized array transparent
return mutype.MuArray(self.map_type(LLT.OF), LLT.length)
......@@ -280,7 +281,21 @@ class LL2MuMapper:
cls = mutype.MuRef
else:
cls = mutype.MuUPtr
return cls(mutype.MU_INT64) # default to ref/uptr<int<64>>
try:
MuT = self.map_type(T)
except (NotImplementedError, CompilationError):
MuT = mutype.MU_INT64 # default to ref/uptr<int<64>>
return cls(MuT)
def map_type_opq(self, LLT):
# sometimes we still need to map opaque types, such as fd_set (_rsocket_rffi.fd_set)
# translate to array with the same size
if 'getsize' in LLT.hints:
size = LLT.hints['getsize']()
MuT = mutype.MuArray(mutype.MU_INT8, size)
return MuT
raise NotImplementedError("don't know how to translate OpaqueType %s" % LLT)
def map_type_funcptr(self, LLT):
LLFnc = LLT.TO
......@@ -351,11 +366,11 @@ class LL2MuMapper:
elif isinstance(llv, CDefinedIntSymbolic):
from rpython.rlib import objectmodel, jit
if llv is objectmodel._translated_to_c:
llv = 1 # faking it to make it work
llv = 1 # faking it to make it work
elif llv is objectmodel.malloc_zero_filled:
llv = 1 # Mu NEW zeros memory
llv = 1 # Mu NEW zeros memory
elif llv is jit._we_are_jitted:
llv = 0 # this is AoT, not jitted
llv = 0 # this is AoT, not jitted
elif 'FinalizerQueue TAG' in llv.expr: # rgc.py:515
llv = 0
else:
......@@ -413,7 +428,7 @@ class LL2MuMapper:
return self.map_value_varstt(llv)
MuT = self.map_type(LLT)
if MuT is mutype.MU_VOID: # empty struct, struct<>
if MuT is mutype.MU_VOID: # empty struct, struct<>
return None
if topstt not in self._topstt_map:
......@@ -476,7 +491,7 @@ class LL2MuMapper:
hyb.length = mutype.mu_int64(llv.getlength())
_memarr = getattr(hyb, MuT._varfld)
for i in range(hyb.length):
for i in range(llv.getlength()):
_memarr[i] = self.map_value(llv.getitem(i))
return hyb
......@@ -491,7 +506,7 @@ class LL2MuMapper:
if isinstance(LLT.TO, lltype.FuncType):
return self.map_value_funcptr(llv)
ref = MuT._null() # set object later
ref = MuT._null() # set object later
self._pending_ptr_values.append((llv._obj, ref))
return ref
......@@ -510,7 +525,7 @@ class LL2MuMapper:
elif isinstance(ref, mutype._muweakref):
ref._obj = weakref.ref(obj)
else:
ref._store(obj) # otherwise (iref, uptr) call _store
ref._store(obj) # otherwise (iref, uptr) call _store
def map_value_funcptr(self, llv):
LLT = lltype.typeOf(llv)
......@@ -555,6 +570,7 @@ class LL2MuMapper:
return layout.mu_offsetOf(MuT, 'length')
else:
raise AssertionError("Value {:r} of type {:r} shouldn't appear.".format(llv, type(llv)))
MuT = self.map_type(lltype.typeOf(llv))
return MuT._val_type(rec(llv))
......@@ -606,7 +622,7 @@ class LL2MuMapper:
if hasattr(self, 'map_op_' + llop.opname):
return getattr(self, 'map_op_' + llop.opname)(llop)
elif llop.opname in _binop_map: # a binop
elif llop.opname in _binop_map: # a binop
if any(cmpop in llop.opname for cmpop in 'lt le eq ne ge gt'.split(' ')):
return self._map_cmpop(llop)
else:
......@@ -697,7 +713,7 @@ class LL2MuMapper:
Constant(MuT._val_type(0), MuT),
llop.args[0],
],
llop.result)
llop.result)
return self.map_op(llop)
map_op_llong_neg = map_op_int_neg
......@@ -828,7 +844,7 @@ class LL2MuMapper:
def _map_convop(self, llop):
return [self.gen_mu_convop(_prim_castop_map[llop.opname],
llop.result.concretetype, llop.args[0], llop.result)]
llop.result.concretetype, llop.args[0], llop.result)]
map_op_cast_int_to_uint = _rename_to_same_as
map_op_cast_uint_to_int = _rename_to_same_as
......@@ -864,21 +880,31 @@ class LL2MuMapper:
ops.append(self.gen_mu_newhybrid(MuT, n_c, llop.result))
else:
assert isinstance(llop.result.concretetype, mutype.MuUPtr)
if MuT == mutype.MU_VOID:
# there are a few places in RPython code (especially libffi, _rawffi)
# that does malloc(rffi.VOIDP.TO, size, flavor='raw').
# In these cases MuT == MU_VOIDP
# Thus directly allocate n_c bytes and return the pointer
ops.extend(self.map_op(SpaceOperation('raw_malloc', [n_c], llop.result)))
return ops
fix = layout.mu_hybsizeOf(MuT, 0)
itm = layout.mu_hybsizeOf(MuT, 1) - fix
# sz = fix + itm * n
v = varof(mutype.MU_INT64)
ops.extend(self.map_op(SpaceOperation('int_mul', [Constant(mutype.mu_int64(itm), mutype.MU_INT64), n_c], v)))
ops.extend(self.map_op(SpaceOperation(
'int_mul', [Constant(mutype.mu_int64(itm), mutype.MU_INT64), n_c], v)))
sz = varof(mutype.MU_INT64, 'sz')
ops.extend(self.map_op(SpaceOperation('int_add', [Constant(mutype.mu_int64(fix), mutype.MU_INT64), v], sz)))
ops.extend(self.map_op(SpaceOperation('raw_malloc', [sz], llop.result)))
ops.extend(self.map_op(SpaceOperation(
'int_add', [Constant(mutype.mu_int64(fix), mutype.MU_INT64), v], sz)))
ops.extend(self.map_op(SpaceOperation(
'raw_malloc', [sz], llop.result)))
if 'length' in MuT._names:
ops.extend(self.map_op(SpaceOperation('setfield', [
llop.result, Constant('length', mutype.MU_VOID), n_c
],
varof(mutype.MU_VOID, 'dummy'))))
ops.extend(self.map_op(SpaceOperation(
'setfield', [llop.result, Constant('length', mutype.MU_VOID), n_c],
varof(mutype.MU_VOID, 'dummy'))))
return ops
......@@ -894,7 +920,7 @@ class LL2MuMapper:
iref = var
assert isinstance(MuT.TO, (mutype.MuStruct, mutype.MuHybrid))
idx = MuT.TO._index_of(fldname) # NOTE: may throw AttributeError
idx = MuT.TO._index_of(fldname) # NOTE: may throw AttributeError
iref_fld = varof(cls(getattr(MuT.TO, fldname)), 'irf%s_%s' % (var.name, fldname))
ops.append(self.gen_mu_getfieldiref(iref, fldname, iref_fld))
return iref_fld, ops
......@@ -927,8 +953,8 @@ class LL2MuMapper:
RES_T = llop.result.concretetype.TO
assert isinstance(RES_T, mutype.MuHybrid)
if hasattr(RES_T, 'length'):
iref_fld, ops = self._getfieldiref(var, Constant('length')) # get the length field instead
ops.extend(self.map_op(SpaceOperation('cast_pointer', # cast to correct type
iref_fld, ops = self._getfieldiref(var, Constant('length')) # get the length field instead
ops.extend(self.map_op(SpaceOperation('cast_pointer', # cast to correct type
[Constant(llop.result.concretetype), iref_fld], llop.result)))
else:
iref_fld, ops = self._getinterioriref(var, [fldname_c])
......@@ -966,7 +992,13 @@ class LL2MuMapper:
def map_op_getarrayitem(self, llop):
var, idx_vc = llop.args
iref_itm, ops = self._getarrayitemiref(var, idx_vc)
ops = []
if var.concretetype.TO == mutype.MU_VOID: # cast void* to char*
buf = varof(type(var.concretetype)(self.map_type(rffi.CCHARP).TO))
ops = self.map_op(SpaceOperation('cast_pointer', [var], buf))
var = buf
iref_itm, _ops = self._getarrayitemiref(var, idx_vc)
ops.extend(_ops)
ops.append(self.gen_mu_load(iref_itm, llop.result))
return ops
......@@ -974,9 +1006,22 @@ class LL2MuMapper:
if len(llop.args) < 3:
MuT = llop.args[0].concretetype.TO
assert isinstance(MuT, mutype.MuStruct) and 'Void' in llop.args[0].concretetype.TO._name
return [] # setting Void type values to array of Voids; translate as no-op
return [] # setting Void type values to array of Voids; translate as no-op
var, idx_vc, val_vc = llop.args
iref_itm, ops = self._getarrayitemiref(var, idx_vc)
ops = []
if var.concretetype.TO == mutype.MU_VOID: # cast void* to char*
buf = varof(type(var.concretetype)(self.map_type(rffi.CCHARP).TO))
ops = self.map_op(SpaceOperation('cast_pointer', [var], buf))
var = buf
iref_itm, _ops = self._getarrayitemiref(var, idx_vc)
ops.extend(_ops)
if iref_itm.concretetype.TO != val_vc.concretetype:
if isinstance(iref_itm.concretetype.TO, mutype.MuReferenceType) and \
isinstance(val_vc.concretetype, mutype.MuReferenceType) and \
isinstance(val_vc.concretetype, type(iref_itm.concretetype.TO)):
casted = varof(type(iref_itm.concretetype.TO)(iref_itm.concretetype.TO.TO))
ops.extend(self.map_op(SpaceOperation('cast_pointer', [val_vc], casted)))
val_vc = casted
ops.append(self.gen_mu_store(iref_itm, val_vc, llop.result))
return ops
......@@ -1079,7 +1124,14 @@ class LL2MuMapper:
# TODO: reconsider direct_ptradd and direct_arrayitems, based on the semantic in lltype
def map_op_direct_ptradd(self, llop):
_, ops = self._getarrayitemiref(*llop.args)
var, idx_vc = llop.args
ops = []
if var.concretetype.TO == mutype.MU_VOID: # cast void* to char*
buf = varof(type(var.concretetype)(self.map_type(rffi.CCHARP).TO))
ops = self.map_op(SpaceOperation('cast_pointer', [var], buf))
var = buf
iref_itm, _ops = self._getarrayitemiref(var, idx_vc)
ops.extend(_ops)
ops[-1].result = llop.result
return ops
......@@ -1121,7 +1173,7 @@ class LL2MuMapper:
if llop.result.concretetype == mutype.MU_INT64:
ops.extend(self.map_op(SpaceOperation('int_sub', [adr1_i, adr2_i], llop.result)))
elif isinstance(llop.result.concretetype, mutype.MuUPtr): # not sure if this is ever the case though
elif isinstance(llop.result.concretetype, mutype.MuUPtr): # not sure if this is ever the case though
delta = varof(mutype.MU_INT64)
ops.extend(self.map_op(SpaceOperation('int_sub', [adr1_i, adr2_i], delta)))
ops.append(self.gen_mu_convop('PTRCAST', llop.result.concretetype, delta, llop.result))
......@@ -1189,17 +1241,14 @@ class LL2MuMapper:
# correct memcpy and memmove argument order
if mufnp._name in ('memcpy', 'memmove'):
args = [args[1], args[0], args[2]]
# NOTE: assume implicit casting to avoid
# adding extra operations at the end of a block
# which messes with block exit analysis
# if Sig.RESULTS[0] != llop.result.concretetype:
# malloc_res = varof(Sig.RESULTS[0])
# muops.append(self.gen_mu_ccall(callee, args, malloc_res))
# llop_fc = SpaceOperation('force_cast', [malloc_res], llop.result)
# muops += self.map_op(llop_fc)
# else:
# muops.append(self.gen_mu_ccall(callee, args, llop.result))
muops.append(self.gen_mu_ccall(callee, args, llop.result))
if llop.opname == 'raw_malloc' and Sig.RESULTS[0] != llop.result.concretetype:
malloc_res = varof(Sig.RESULTS[0])
muops.append(self.gen_mu_ccall(callee, args, malloc_res))
llop_fc = SpaceOperation('force_cast', [malloc_res], llop.result)
muops += self.map_op(llop_fc)
else:
muops.append(self.gen_mu_ccall(callee, args, llop.result))
return muops
map_op_raw_malloc = _map_rawmemop
......@@ -1215,7 +1264,8 @@ class LL2MuMapper:
return self.map_op_raw_free(llop)
def map_op_raw_memclear(self, llop):
llop.__init__('raw_memset', [llop.args[0], Constant(mutype.mu_int8(0), mutype.MU_INT8), llop.args[1]], llop.result)
llop.__init__('raw_memset', [llop.args[0], Constant(mutype.mu_int8(0), mutype.MU_INT8), llop.args[1]],
llop.result)
return self._map_rawmemop(llop)
def map_op_raw_load(self, llop):
......@@ -1289,7 +1339,7 @@ class LL2MuMapper:
def map_op_cast_ptr_to_int(self, llop):
llop.opname = 'cast_ptr_to_adr'
ops = self.map_op(llop)
if len(ops) == 2: # pinned
if len(ops) == 2: # pinned
ops.extend(self.map_op(SpaceOperation('keepalive', [llop.args[0]], varof(mutype.MU_VOID))))
return ops
......@@ -1308,7 +1358,7 @@ class LL2MuMapper:
if isinstance(SRC, mutype.MuObjectRef) and isinstance(RES, mutype.MuObjectRef):
llop.__init__('cast_pointer', [llop.args[0]], llop.result)
return self.map_op(llop) # does the reference class check in actual mapping function
return self.map_op(llop) # does the reference class check in actual mapping function
elif isinstance(SRC, mutype.MuObjectRef) and isinstance(RES, mutype.MuIntType):
llop.opname = 'cast_ptr_to_adr'
......@@ -1328,8 +1378,10 @@ class LL2MuMapper:
# of all the cases, we are casting unsigned integers in this module.
use_sext = False
optr = 'SEXT' if use_sext else 'ZEXT'
else:
elif SRC.BITS > RES.BITS:
optr = 'TRUNC'
else: # SRC.BITS == RES.BITS
return self._rename_to_same_as(llop)
return [self.gen_mu_convop(optr, RES, llop.args[0], llop.result)]
elif isinstance(SRC, mutype.MuFloatType) and isinstance(RES, mutype.MuIntType):
......@@ -1337,7 +1389,7 @@ class LL2MuMapper:
RES_LLT = llop._res_llt
opcode = 'FPTOSI' if is_signed_integer_type(RES_LLT) else 'FPTOUI'
else:
opcode = 'FPTOSI' # by default
opcode = 'FPTOSI' # by default
return [self.gen_mu_convop(opcode, RES, llop.args[0], llop.result)]
elif isinstance(SRC, mutype.MuIntType) and isinstance(RES, mutype.MuFloatType):
......@@ -1345,14 +1397,19 @@ class LL2MuMapper:
SRC_LLT = llop._src_llt
opcode = 'SITOFP' if is_signed_integer_type(SRC_LLT) else 'UITOFP'
else:
opcode = 'SITOFP' # by default
opcode = 'SITOFP' # by default
return [self.gen_mu_convop(opcode, RES, llop.args[0], llop.result)]
elif isinstance(SRC, mutype.MuFloatType) and isinstance(RES, mutype.MuFloatType):
if SRC == mutype.MU_FLOAT and RES == mutype.MU_DOUBLE:
optr = 'FPEXT'
else:
elif RES == mutype.MU_DOUBLE and SRC == mutype.MU_FLOAT:
optr = 'FPTRUNC'
else:
# this happens because rffi.LONGDOUBLE is translated as MU_DOUBLE
# in this case ignore the cast
return self._rename_to_same_as(llop)
return [self.gen_mu_convop(optr, RES, llop.args[0], llop.result)]
elif SRC == RES:
......@@ -1454,7 +1511,8 @@ class LL2MuMapper:
tlref_stt = varof(RefStt)
ops.extend(self.map_op(SpaceOperation('cast_pointer', [tlref_void], tlref_stt)))
fld = llop.args[0].value.expr[10:]
ops.extend(self.map_op(SpaceOperation('setfield', [tlref_stt, Constant(fld, mutype.MU_VOID), llop.args[1]], llop.result)))
ops.extend(self.map_op(
SpaceOperation('setfield', [tlref_stt, Constant(fld, mutype.MU_VOID), llop.args[1]], llop.result)))
return ops
map_op_threadlocalref_get = map_op_threadlocalref_load
......@@ -1531,6 +1589,7 @@ class LL2MuMapper:
MuT = llop.result.concretetype
llop.__init__('same_as', [Constant(MuT._val_type(-1), MuT)], llop.result)
return [llop]
map_op_gc_get_rpy_type_index = map_op_gc_get_rpy_memory_usage
map_op_gc_get_rpy_roots = _same_as_false
......@@ -1556,7 +1615,7 @@ class LL2MuMapper:
assert isinstance(Ref, mutype.MuRef)
Hyb = Ref.TO
assert isinstance(Hyb, mutype.MuHybrid)
assert len(Hyb._names) == 1 # fixed part empty
assert len(Hyb._names) == 1 # fixed part empty
assert Hyb._var_field_type() is mutype.MU_INT8
ops = []
......@@ -1800,7 +1859,7 @@ class LL2MuMapper:
res if res else varof(mutype.MU_VOID))
def gen_mu_ccall(self, callee, args, res=None, keepalive=None, excclause=None,
callconv='DEFAULT'):
callconv='DEFAULT'):
assert isinstance(callee.concretetype, mutype.MuUFuncPtr)
Sig = callee.concretetype.Sig
assert len(args) == len(Sig.ARGS)
......@@ -1834,6 +1893,7 @@ class LL2MuMapper:
return SpaceOperation('mu_comminst', [Constant(inst, mutype.MU_VOID)] + args +
[Constant(metainfo, mutype.MU_VOID)], res)
def varof(TYPE, name=None):
v = Variable(name)
v.concretetype = TYPE
......@@ -1897,7 +1957,7 @@ def _init_binop_map():
'llong': 'int',
'ullong': 'uint',
'lllong': 'int',
'char': 'uint', # it's okay to be a super set of llops
'char': 'uint', # it's okay to be a super set of llops
'unichar': 'uint'
}.items():
for op in "add sub mul floordiv mod and or lshift rshift xor".split(' '):
......@@ -1906,6 +1966,8 @@ def _init_binop_map():
__binop_map['%(org_type)s_%(cmp)s' % locals()] = __binop_map['%(coer_type)s_%(cmp)s' % locals()]
return __binop_map