Commit 4f65f3bc authored by John Zhang's avatar John Zhang

default opaque type to void; use NULL of ref<void> to compare nullity of pointer…

default opaque type to void; use NULL of ref<void> to compare nullity of pointer to reduce the number of NULL constants
parent 15c3a167
Pipeline #891 failed with stage
in 4 minutes and 13 seconds
......@@ -284,7 +284,7 @@ class LL2MuMapper:
try:
MuT = self.map_type(T)
except (NotImplementedError, CompilationError):
MuT = mutype.MU_INT64 # default to ref/uptr<int<64>>
MuT = mutype.MU_VOID # default to ref/uptr<void>
return cls(MuT)
......@@ -1109,16 +1109,22 @@ class LL2MuMapper:
return ops
def map_op_ptr_nonzero(self, llop):
ops = []
Ptr = llop.args[0].concretetype
NULL_c = Constant(Ptr._null(), Ptr)
llop.__init__('ptr_ne', [llop.args[0], NULL_c], llop.result)
return self.map_op(llop)
NULL_c = NULL_OF[type(Ptr)]
v = varof(Ptr)
ops = self.map_op(SpaceOperation('cast_pointer', [NULL_c], v))
ops.extend(self.map_op(SpaceOperation('ptr_ne', [llop.args[0], v], llop.result)))
return ops
def map_op_ptr_iszero(self, llop):
ops = []
Ptr = llop.args[0].concretetype
NULL_c = Constant(Ptr._null(), Ptr)
llop.__init__('ptr_eq', [llop.args[0], NULL_c], llop.result)
return self.map_op(llop)
NULL_c = NULL_OF[type(Ptr)]
v = varof(Ptr)
ops = self.map_op(SpaceOperation('cast_pointer', [NULL_c], v))
ops.extend(self.map_op(SpaceOperation('ptr_eq', [llop.args[0], v], llop.result)))
return ops
map_op_shrink_array = _same_as_false
......@@ -1993,6 +1999,21 @@ _prim_castop_map = {
'convert_longlong_bytes_to_float': 'BITCAST',
}
NULL_refvoid = Constant(mutype.MU_VOIDR._null(), mutype.MU_VOIDR)
NULL_ptrvoid = Constant(mutype.MU_VOIDP._null(), mutype.MU_VOIDP)
_sigvoid_void = mutype.MuFuncSig([mutype.MU_VOID], [mutype.MU_VOID])
_fnrsig_void_void = mutype.MuFuncRef(_sigvoid_void)
_fnpsig_void_void = mutype.MuUFuncPtr(_sigvoid_void)
NULL_fnrvoid = Constant(_fnrsig_void_void._null(), _fnrsig_void_void)
NULL_fnpvoid = Constant(_fnpsig_void_void._null(), _fnpsig_void_void)
NULL_OF = {
mutype.MuRef: NULL_refvoid,
mutype.MuUPtr: NULL_ptrvoid,
mutype.MuFuncRef: NULL_fnrvoid,
mutype.MuUFuncPtr: NULL_fnpvoid
}
from rpython.rlib.rposix import external, ExternalCompilationInfo
c_malloc = external("malloc", [rffi.SIZE_T], rffi.VOIDP, _nowrapper=True)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment