Commit 866da014 authored by John Zhang's avatar John Zhang

move get_typedescr_str to module scope, not as a method

parent 02d860ca
......@@ -296,32 +296,6 @@ class LL2MuMapper:
"""
return mutype.MuStruct('WeakRef', ('wref', mutype.MU_WEAKREF_VOID))
def get_typedescr_str(self, MuT): # JIT Mu back-end support
descr_dict = {
mutype.MuRef: 'r',
mutype.MuUPtr: 'p',
mutype.MuFuncRef: 'r', # assuming function ref/uptr has same size as ref/uptr
mutype.MuUFuncPtr: 'p',
mutype.MU_INT8: 'b',
mutype.MU_INT16: 's',
mutype.MU_INT32: 'i',
mutype.MU_INT64: 'l',
mutype.MU_FLOAT: 'f',
mutype.MU_DOUBLE: 'd'
}
if MuT.__class__ in descr_dict:
return descr_dict[MuT.__class__]
if MuT in descr_dict:
return descr_dict[MuT]
if isinstance(MuT, mutype.MuStruct):
return '(%s)' % ''.join(map(self.get_typedescr_str, [getattr(MuT, fld) for fld in MuT._names]))
if isinstance(MuT, mutype.MuHybrid):
fix = ''.join(map(self.get_typedescr_str, [getattr(MuT, fld) for fld in MuT._names[:-1]]))
var = self.get_typedescr_str(MuT._vartype.OF)
return '{%(fix)s|%(var)s}' % locals()
if isinstance(MuT, mutype.MuArray):
return '[%d|%s]' % (MuT.length, self.get_typedescr_str(MuT.OF))
# -----------------------------------------------------------------------------
def map_value(self, llv, **kwargs):
cache, v = (self._ptr_cache, llv._obj) \
......@@ -2011,3 +1985,30 @@ def ll2mu_value(llv):
muv = ll2mu.map_value(llv)
ll2mu.resolve_ptr_values()
return muv
def get_typedescr_str(MuT): # JIT Mu back-end support
descr_dict = {
mutype.MuRef: 'r',
mutype.MuUPtr: 'p',
mutype.MuFuncRef: 'r', # assuming function ref/uptr has same size as ref/uptr
mutype.MuUFuncPtr: 'p',
mutype.MU_INT8: 'b',
mutype.MU_INT16: 's',
mutype.MU_INT32: 'i',
mutype.MU_INT64: 'l',
mutype.MU_FLOAT: 'f',
mutype.MU_DOUBLE: 'd'
}
if MuT.__class__ in descr_dict:
return descr_dict[MuT.__class__]
if MuT in descr_dict:
return descr_dict[MuT]
if isinstance(MuT, mutype.MuStruct):
return '(%s)' % ''.join(map(get_typedescr_str, [getattr(MuT, fld) for fld in MuT._names]))
if isinstance(MuT, mutype.MuHybrid):
fix = ''.join(map(get_typedescr_str, [getattr(MuT, fld) for fld in MuT._names[:-1]]))
var = get_typedescr_str(MuT._vartype.OF)
return '{%(fix)s|%(var)s}' % locals()
if isinstance(MuT, mutype.MuArray):
return '[%d|%s]' % (MuT.length, get_typedescr_str(MuT.OF))
\ No newline at end of file
......@@ -675,16 +675,15 @@ def test_getsubstruct():
def test_typedescr_str():
ll2mu = LL2MuMapper()
S = mutype.MuStruct('S', ('x', mutype.MU_INT64), ('y', mutype.MU_FLOAT), ('z', mutype.MuRef(mutype.MU_INT64)))
assert ll2mu.get_typedescr_str(S) == '(lfr)'
assert get_typedescr_str(S) == '(lfr)'
from rpython.rtyper.lltypesystem.rstr import STR
H = ll2mu.map_type(STR)
assert ll2mu.get_typedescr_str(H) == '{lll|b}'
H = ll2mu_type(STR)
assert get_typedescr_str(H) == '{lll|b}'
A = mutype.MuArray(S, 10)
assert ll2mu.get_typedescr_str(A) == '[10|(lfr)]'
assert get_typedescr_str(A) == '[10|(lfr)]'
def test_cast_pointer_pin():
ll2mu = LL2MuMapper()
......
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