Commit 50e74b3c authored by John Zhang's avatar John Zhang

fix: InteriorPtr doesn't work because rtyper translates it down to Ptr....

fix: InteriorPtr doesn't work because rtyper translates it down to Ptr. Therefore iref type translation is done by using hints to opaque type hack.
Added translation support for converting RPython list struct/array to meta-circular array. Implemented compiler intrinsic llops 'mu_meta_barebuf2cstriref' and 'mu_meta_lst2metacarr' in ll2mu.
Small tests for the meta-circular binding seems okay.
parent 312f3b54
......@@ -4,103 +4,96 @@ Meta-circular bundle building interface
from rpython.rtyper.lltypesystem import rffi, lltype, llmemory, rstr
from rpython.rtyper.lltypesystem.lloperation import llop
from rpython.annotator.bookkeeper import analyzer_for
from rpython.rtyper.rbuiltin import parse_kwds, typer_for
from rpython.annotator import model as annmodel
from rpython.flowspace.model import Constant, Variable
from rpython.translator.tool.cbuild import ExternalCompilationInfo
from rpython.rlib.objectmodel import specialize, always_inline, ExtRegistryEntry, keepalive_until_here
from rpython.translator.mu import mutype
import os
IRBuilderRef = lltype.Ptr(lltype.GcOpaqueType('irbuilderref', hints={'mu_render_ptr_as': mutype.MUTA_IRBUILDER_REF}))
MuID = rffi.UINT # MU_INT32
MuMetaCStr = lltype.InteriorPtr(lltype.GcOpaqueType('MuMetaCStr'),
lltype.FixedSizeArray(lltype.Char, 1), []) # will be translated as iref<int<8>>
class MetaIRBuilderInst:
NEW_IR_BUILDER = "MU_CI_UVM_IRBUILDER_NEW_IR_BUILDER"
LOAD = "MU_CI_UVM_IRBUILDER_LOAD"
ABORT = "MU_CI_UVM_IRBUILDER_ABORT"
GEN_SYM = "MU_CI_UVM_IRBUILDER_GEN_SYM"
NEW_TYPE_INT = "MU_CI_UVM_IRBUILDER_NEW_TYPE_INT"
NEW_TYPE_FLOAT = "MU_CI_UVM_IRBUILDER_NEW_TYPE_FLOAT"
NEW_TYPE_DOUBLE = "MU_CI_UVM_IRBUILDER_NEW_TYPE_DOUBLE"
NEW_TYPE_UPTR = "MU_CI_UVM_IRBUILDER_NEW_TYPE_UPTR"
NEW_TYPE_UFUNCPTR = "MU_CI_UVM_IRBUILDER_NEW_TYPE_UFUNCPTR"
NEW_TYPE_STRUCT = "MU_CI_UVM_IRBUILDER_NEW_TYPE_STRUCT"
NEW_TYPE_HYBRID = "MU_CI_UVM_IRBUILDER_NEW_TYPE_HYBRID"
NEW_TYPE_ARRAY = "MU_CI_UVM_IRBUILDER_NEW_TYPE_ARRAY"
NEW_TYPE_VECTOR = "MU_CI_UVM_IRBUILDER_NEW_TYPE_VECTOR"
NEW_TYPE_VOID = "MU_CI_UVM_IRBUILDER_NEW_TYPE_VOID"
NEW_TYPE_REF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_REF"
NEW_TYPE_IREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_IREF"
NEW_TYPE_WEAKREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_WEAKREF"
NEW_TYPE_FUNCREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_FUNCREF"
NEW_TYPE_TAGREF64 = "MU_CI_UVM_IRBUILDER_NEW_TYPE_TAGREF64"
NEW_TYPE_THREADREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_THREADREF"
NEW_TYPE_STACKREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_STACKREF"
NEW_TYPE_FRAMECURSORREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_FRAMECURSORREF"
NEW_TYPE_IRBUILDERREF = "MU_CI_UVM_IRBUILDER_NEW_TYPE_IRBUILDERREF"
NEW_FUNCSIG = "MU_CI_UVM_IRBUILDER_NEW_FUNCSIG"
NEW_CONST_INT = "MU_CI_UVM_IRBUILDER_NEW_CONST_INT"
NEW_CONST_INT_EX = "MU_CI_UVM_IRBUILDER_NEW_CONST_INT_EX"
NEW_CONST_FLOAT = "MU_CI_UVM_IRBUILDER_NEW_CONST_FLOAT"
NEW_CONST_DOUBLE = "MU_CI_UVM_IRBUILDER_NEW_CONST_DOUBLE"
NEW_CONST_NULL = "MU_CI_UVM_IRBUILDER_NEW_CONST_NULL"
NEW_CONST_SEQ = "MU_CI_UVM_IRBUILDER_NEW_CONST_SEQ"
NEW_CONST_EXTERN = "MU_CI_UVM_IRBUILDER_NEW_CONST_EXTERN"
NEW_GLOBAL_CELL = "MU_CI_UVM_IRBUILDER_NEW_GLOBAL_CELL"
NEW_FUNC = "MU_CI_UVM_IRBUILDER_NEW_FUNC"
NEW_EXP_FUNC = "MU_CI_UVM_IRBUILDER_NEW_EXP_FUNC"
NEW_FUNC_VER = "MU_CI_UVM_IRBUILDER_NEW_FUNC_VER"
NEW_BB = "MU_CI_UVM_IRBUILDER_NEW_BB"
NEW_DEST_CLAUSE = "MU_CI_UVM_IRBUILDER_NEW_DEST_CLAUSE"
NEW_EXC_CLAUSE = "MU_CI_UVM_IRBUILDER_NEW_EXC_CLAUSE"
NEW_KEEPALIVE_CLAUSE = "MU_CI_UVM_IRBUILDER_NEW_KEEPALIVE_CLAUSE"
NEW_CSC_RET_WITH = "MU_CI_UVM_IRBUILDER_NEW_CSC_RET_WITH"
NEW_CSC_KILL_OLD = "MU_CI_UVM_IRBUILDER_NEW_CSC_KILL_OLD"
NEW_NSC_PASS_VALUES = "MU_CI_UVM_IRBUILDER_NEW_NSC_PASS_VALUES"
NEW_NSC_THROW_EXC = "MU_CI_UVM_IRBUILDER_NEW_NSC_THROW_EXC"
NEW_BINOP = "MU_CI_UVM_IRBUILDER_NEW_BINOP"
NEW_BINOP_WITH_STATUS = "MU_CI_UVM_IRBUILDER_NEW_BINOP_WITH_STATUS"
NEW_CMP = "MU_CI_UVM_IRBUILDER_NEW_CMP"
NEW_CONV = "MU_CI_UVM_IRBUILDER_NEW_CONV"
NEW_SELECT = "MU_CI_UVM_IRBUILDER_NEW_SELECT"
NEW_BRANCH = "MU_CI_UVM_IRBUILDER_NEW_BRANCH"
NEW_BRANCH2 = "MU_CI_UVM_IRBUILDER_NEW_BRANCH2"
NEW_SWITCH = "MU_CI_UVM_IRBUILDER_NEW_SWITCH"
NEW_CALL = "MU_CI_UVM_IRBUILDER_NEW_CALL"
NEW_TAILCALL = "MU_CI_UVM_IRBUILDER_NEW_TAILCALL"
NEW_RET = "MU_CI_UVM_IRBUILDER_NEW_RET"
NEW_THROW = "MU_CI_UVM_IRBUILDER_NEW_THROW"
NEW_EXTRACTVALUE = "MU_CI_UVM_IRBUILDER_NEW_EXTRACTVALUE"
NEW_INSERTVALUE = "MU_CI_UVM_IRBUILDER_NEW_INSERTVALUE"
NEW_EXTRACTELEMENT = "MU_CI_UVM_IRBUILDER_NEW_EXTRACTELEMENT"
NEW_INSERTELEMENT = "MU_CI_UVM_IRBUILDER_NEW_INSERTELEMENT"
NEW_SHUFFLEVECTOR = "MU_CI_UVM_IRBUILDER_NEW_SHUFFLEVECTOR"
NEW_NEW = "MU_CI_UVM_IRBUILDER_NEW_NEW"
NEW_NEWHYBRID = "MU_CI_UVM_IRBUILDER_NEW_NEWHYBRID"
NEW_ALLOCA = "MU_CI_UVM_IRBUILDER_NEW_ALLOCA"
NEW_ALLOCAHYBRID = "MU_CI_UVM_IRBUILDER_NEW_ALLOCAHYBRID"
NEW_GETIREF = "MU_CI_UVM_IRBUILDER_NEW_GETIREF"
NEW_GETFIELDIREF = "MU_CI_UVM_IRBUILDER_NEW_GETFIELDIREF"
NEW_GETELEMIREF = "MU_CI_UVM_IRBUILDER_NEW_GETELEMIREF"
NEW_SHIFTIREF = "MU_CI_UVM_IRBUILDER_NEW_SHIFTIREF"
NEW_GETVARPARTIREF = "MU_CI_UVM_IRBUILDER_NEW_GETVARPARTIREF"
NEW_LOAD = "MU_CI_UVM_IRBUILDER_NEW_LOAD"
NEW_STORE = "MU_CI_UVM_IRBUILDER_NEW_STORE"
NEW_CMPXCHG = "MU_CI_UVM_IRBUILDER_NEW_CMPXCHG"
NEW_ATOMICRMW = "MU_CI_UVM_IRBUILDER_NEW_ATOMICRMW"
NEW_FENCE = "MU_CI_UVM_IRBUILDER_NEW_FENCE"
NEW_TRAP = "MU_CI_UVM_IRBUILDER_NEW_TRAP"
NEW_WATCHPOINT = "MU_CI_UVM_IRBUILDER_NEW_WATCHPOINT"
NEW_WPBRANCH = "MU_CI_UVM_IRBUILDER_NEW_WPBRANCH"
NEW_CCALL = "MU_CI_UVM_IRBUILDER_NEW_CCALL"
NEW_NEWTHREAD = "MU_CI_UVM_IRBUILDER_NEW_NEWTHREAD"
NEW_SWAPSTACK = "MU_CI_UVM_IRBUILDER_NEW_SWAPSTACK"
NEW_COMMINST = "MU_CI_UVM_IRBUILDER_NEW_COMMINST"
NEW_IR_BUILDER = "IRBUILDER_NEW_IR_BUILDER"
LOAD = "IRBUILDER_LOAD"
ABORT = "IRBUILDER_ABORT"
GEN_SYM = "IRBUILDER_GEN_SYM"
NEW_TYPE_INT = "IRBUILDER_NEW_TYPE_INT"
NEW_TYPE_FLOAT = "IRBUILDER_NEW_TYPE_FLOAT"
NEW_TYPE_DOUBLE = "IRBUILDER_NEW_TYPE_DOUBLE"
NEW_TYPE_UPTR = "IRBUILDER_NEW_TYPE_UPTR"
NEW_TYPE_UFUNCPTR = "IRBUILDER_NEW_TYPE_UFUNCPTR"
NEW_TYPE_STRUCT = "IRBUILDER_NEW_TYPE_STRUCT"
NEW_TYPE_HYBRID = "IRBUILDER_NEW_TYPE_HYBRID"
NEW_TYPE_ARRAY = "IRBUILDER_NEW_TYPE_ARRAY"
NEW_TYPE_VECTOR = "IRBUILDER_NEW_TYPE_VECTOR"
NEW_TYPE_VOID = "IRBUILDER_NEW_TYPE_VOID"
NEW_TYPE_REF = "IRBUILDER_NEW_TYPE_REF"
NEW_TYPE_IREF = "IRBUILDER_NEW_TYPE_IREF"
NEW_TYPE_WEAKREF = "IRBUILDER_NEW_TYPE_WEAKREF"
NEW_TYPE_FUNCREF = "IRBUILDER_NEW_TYPE_FUNCREF"
NEW_TYPE_TAGREF64 = "IRBUILDER_NEW_TYPE_TAGREF64"
NEW_TYPE_THREADREF = "IRBUILDER_NEW_TYPE_THREADREF"
NEW_TYPE_STACKREF = "IRBUILDER_NEW_TYPE_STACKREF"
NEW_TYPE_FRAMECURSORREF = "IRBUILDER_NEW_TYPE_FRAMECURSORREF"
NEW_TYPE_IRBUILDERREF = "IRBUILDER_NEW_TYPE_IRBUILDERREF"
NEW_FUNCSIG = "IRBUILDER_NEW_FUNCSIG"
NEW_CONST_INT = "IRBUILDER_NEW_CONST_INT"
NEW_CONST_INT_EX = "IRBUILDER_NEW_CONST_INT_EX"
NEW_CONST_FLOAT = "IRBUILDER_NEW_CONST_FLOAT"
NEW_CONST_DOUBLE = "IRBUILDER_NEW_CONST_DOUBLE"
NEW_CONST_NULL = "IRBUILDER_NEW_CONST_NULL"
NEW_CONST_SEQ = "IRBUILDER_NEW_CONST_SEQ"
NEW_CONST_EXTERN = "IRBUILDER_NEW_CONST_EXTERN"
NEW_GLOBAL_CELL = "IRBUILDER_NEW_GLOBAL_CELL"
NEW_FUNC = "IRBUILDER_NEW_FUNC"
NEW_EXP_FUNC = "IRBUILDER_NEW_EXP_FUNC"
NEW_FUNC_VER = "IRBUILDER_NEW_FUNC_VER"
NEW_BB = "IRBUILDER_NEW_BB"
NEW_DEST_CLAUSE = "IRBUILDER_NEW_DEST_CLAUSE"
NEW_EXC_CLAUSE = "IRBUILDER_NEW_EXC_CLAUSE"
NEW_KEEPALIVE_CLAUSE = "IRBUILDER_NEW_KEEPALIVE_CLAUSE"
NEW_CSC_RET_WITH = "IRBUILDER_NEW_CSC_RET_WITH"
NEW_CSC_KILL_OLD = "IRBUILDER_NEW_CSC_KILL_OLD"
NEW_NSC_PASS_VALUES = "IRBUILDER_NEW_NSC_PASS_VALUES"
NEW_NSC_THROW_EXC = "IRBUILDER_NEW_NSC_THROW_EXC"
NEW_BINOP = "IRBUILDER_NEW_BINOP"
NEW_BINOP_WITH_STATUS = "IRBUILDER_NEW_BINOP_WITH_STATUS"
NEW_CMP = "IRBUILDER_NEW_CMP"
NEW_CONV = "IRBUILDER_NEW_CONV"
NEW_SELECT = "IRBUILDER_NEW_SELECT"
NEW_BRANCH = "IRBUILDER_NEW_BRANCH"
NEW_BRANCH2 = "IRBUILDER_NEW_BRANCH2"
NEW_SWITCH = "IRBUILDER_NEW_SWITCH"
NEW_CALL = "IRBUILDER_NEW_CALL"
NEW_TAILCALL = "IRBUILDER_NEW_TAILCALL"
NEW_RET = "IRBUILDER_NEW_RET"
NEW_THROW = "IRBUILDER_NEW_THROW"
NEW_EXTRACTVALUE = "IRBUILDER_NEW_EXTRACTVALUE"
NEW_INSERTVALUE = "IRBUILDER_NEW_INSERTVALUE"
NEW_EXTRACTELEMENT = "IRBUILDER_NEW_EXTRACTELEMENT"
NEW_INSERTELEMENT = "IRBUILDER_NEW_INSERTELEMENT"
NEW_SHUFFLEVECTOR = "IRBUILDER_NEW_SHUFFLEVECTOR"
NEW_NEW = "IRBUILDER_NEW_NEW"
NEW_NEWHYBRID = "IRBUILDER_NEW_NEWHYBRID"
NEW_ALLOCA = "IRBUILDER_NEW_ALLOCA"
NEW_ALLOCAHYBRID = "IRBUILDER_NEW_ALLOCAHYBRID"
NEW_GETIREF = "IRBUILDER_NEW_GETIREF"
NEW_GETFIELDIREF = "IRBUILDER_NEW_GETFIELDIREF"
NEW_GETELEMIREF = "IRBUILDER_NEW_GETELEMIREF"
NEW_SHIFTIREF = "IRBUILDER_NEW_SHIFTIREF"
NEW_GETVARPARTIREF = "IRBUILDER_NEW_GETVARPARTIREF"
NEW_LOAD = "IRBUILDER_NEW_LOAD"
NEW_STORE = "IRBUILDER_NEW_STORE"
NEW_CMPXCHG = "IRBUILDER_NEW_CMPXCHG"
NEW_ATOMICRMW = "IRBUILDER_NEW_ATOMICRMW"
NEW_FENCE = "IRBUILDER_NEW_FENCE"
NEW_TRAP = "IRBUILDER_NEW_TRAP"
NEW_WATCHPOINT = "IRBUILDER_NEW_WATCHPOINT"
NEW_WPBRANCH = "IRBUILDER_NEW_WPBRANCH"
NEW_CCALL = "IRBUILDER_NEW_CCALL"
NEW_NEWTHREAD = "IRBUILDER_NEW_NEWTHREAD"
NEW_SWAPSTACK = "IRBUILDER_NEW_SWAPSTACK"
NEW_COMMINST = "IRBUILDER_NEW_COMMINST"
@always_inline
......@@ -125,7 +118,7 @@ class Entry(ExtRegistryEntry):
def specialize_call(self, hop, **i_kwds):
hop.exception_cannot_occur()
inst = hop.args_v[0].value
idx_kwds_start = min(min(i_kwds.values()), len(hop.args_v))
idx_kwds_start = len(hop.args_v) if len(i_kwds) == 0 else min(i_kwds.values())
i_args = range(1, idx_kwds_start)
args = [hop.inputconst(lltype.Void, inst)]
for idx in i_args:
......@@ -143,9 +136,79 @@ class MuIRBuilder:
def __init__(self):
self._bldr = ir_inst(MetaIRBuilderInst.NEW_IR_BUILDER, restype=IRBuilderRef)
def load(self):
ir_inst(MetaIRBuilderInst.LOAD, self._bldr)
def abort(self):
ir_inst(MetaIRBuilderInst.ABORT, self._bldr)
def gen_sym(self, name):
_name = str2metacstr(name)
return ir_inst(MetaIRBuilderInst.GEN_SYM, _name, restype=MuID)
return ir_inst(MetaIRBuilderInst.GEN_SYM, self._bldr, _name, restype=MuID)
def new_type_int(self, id, len):
len_c = rffi.cast(rffi.INT, len)
ir_inst(MetaIRBuilderInst.NEW_TYPE_INT, self._bldr, id, len_c)
def new_type_float(self, id):
ir_inst(MetaIRBuilderInst.NEW_TYPE_FLOAT, self._bldr, id)
def new_type_double(self, id):
ir_inst(MetaIRBuilderInst.NEW_TYPE_DOUBLE, self._bldr, id)
def new_type_uptr(self, id, ty):
ir_inst(MetaIRBuilderInst.NEW_TYPE_UPTR, self._bldr, id, ty)
def new_type_ufuncptr(self, id, sig):
ir_inst(MetaIRBuilderInst.NEW_TYPE_UFUNCPTR, self._bldr, id, sig)
def new_type_struct(self, id, fieldtys):
fieldtys_arr = lst2metacarr(MuID, fieldtys)
fieldtys_sz = len(fieldtys)
ir_inst(MetaIRBuilderInst.NEW_TYPE_STRUCT, self._bldr, id, fieldtys_arr, fieldtys_sz)
def new_type_hybrid(self, id, fixedtys, varty):
fixedtys_arr = lst2metacarr(MuID, fixedtys)
fixedtys_sz = len(fixedtys)
ir_inst(MetaIRBuilderInst.NEW_TYPE_HYBRID, self._bldr, id, fixedtys_arr, fixedtys_sz, varty)
def new_type_array(self, id, elemty, len):
len_c = rffi.cast(rffi.ULONG, len)
ir_inst(MetaIRBuilderInst.NEW_TYPE_ARRAY, self._bldr, id, elemty, len_c)
def new_type_vector(self, id, elemty, len):
len_c = rffi.cast(rffi.ULONG, len)
ir_inst(MetaIRBuilderInst.NEW_TYPE_VECTOR, self._bldr, id, elemty, len_c)
def new_type_void(self, id):
ir_inst(MetaIRBuilderInst.NEW_TYPE_VOID, self._bldr, id)
def new_type_ref(self, id, ty):
ir_inst(MetaIRBuilderInst.NEW_TYPE_REF, self._bldr, id, ty)
def new_type_iref(self, id, ty):
ir_inst(MetaIRBuilderInst.NEW_TYPE_IREF, self._bldr, id, ty)
def new_type_weakref(self, id, ty):
ir_inst(MetaIRBuilderInst.NEW_TYPE_WEAKREF, self._bldr, id, ty)
def new_type_funcref(self, id, sig):
ir_inst(MetaIRBuilderInst.NEW_TYPE_FUNCREF, self._bldr, id, sig)
def new_type_tagref64(self, id):
ir_inst(MetaIRBuilderInst.NEW_TYPE_TAGREF64, self._bldr, id)
def new_type_threadref(self, id):
ir_inst(MetaIRBuilderInst.NEW_TYPE_THREADREF, self._bldr, id)
def new_type_stackref(self, id):
ir_inst(MetaIRBuilderInst.NEW_TYPE_STACKREF, self._bldr, id)
def new_type_framecursorref(self, id):
ir_inst(MetaIRBuilderInst.NEW_TYPE_FRAMECURSORREF, self._bldr, id)
def new_type_irbuilderref(self, id):
ir_inst(MetaIRBuilderInst.NEW_TYPE_IRBUILDERREF, self._bldr, id)
# ----------------
......@@ -153,7 +216,8 @@ class MuIRBuilder:
_StrBuf = lltype.GcArray(lltype.Char, hints={'nolength': True, 'mu_nohashfield': True})
_StrBufPtr = lltype.Ptr(_StrBuf)
_StrBufIPtr = lltype.InteriorPtr(_StrBuf, _StrBuf, [])
MuMetaCStr = lltype.Ptr(lltype.GcOpaqueType('MuMetaCStr',
hints={'mu_render_ptr_as': mutype.META_CSTR}))
def str2metacstr(str):
n = len(str)
......@@ -161,11 +225,20 @@ def str2metacstr(str):
adr_buf = llmemory.cast_ptr_to_adr(buf) + llmemory.itemoffsetof(_StrBuf, 0)
adr_src = llmemory.cast_ptr_to_adr(str) + (llmemory.offsetof(rstr.STR, 'chars') +
llmemory.itemoffsetof(rstr.STR.chars, 0) +
llmemory.sizeof(rstr.Char) * n)
llmemory.sizeof(rstr.Char) * 0)
llmemory.raw_memcopy(adr_src, adr_buf, llmemory.sizeof(rstr.Char) * n)
buf[n] = '\x00'
keepalive_until_here(buf)
keepalive_until_here(str)
iptr_buf = llop.mu_getiref(_StrBufIPtr, buf)
iptr = llop.mu_getvarpartiref(MuMetaCStr, iptr_buf)
return iptr
ircstr = llop.mu_meta_barebuf2cstriref(MuMetaCStr, buf) # handled in ll2mu
return ircstr
@specialize.memo()
def _carriptr_type_of(ELM_T):
from rpython.translator.mu.ll2mu import ll2mu_type
ELM_MuT = ll2mu_type(ELM_T)
return lltype.Ptr(lltype.GcOpaqueType('itemarray', hints={'mu_render_ptr_as': mutype.MuIRef(ELM_MuT)}))
def lst2metacarr(ELM_T, lst):
IPtrBuf = _carriptr_type_of(ELM_T)
return llop.mu_meta_lst2carr(IPtrBuf, lst) # handled in ll2mu
......@@ -2,33 +2,60 @@ from rpython.rlib.rmu import holstein_meta as rmu
from rpython.translator.interactive import Translation
from rpython.translator.mu.tool.textgraph import print_graph
from rpython.translator.mu.test.test_mutyper import graph_of
from rpython.translator.mu import mutype
from rpython.rtyper.lltypesystem import lltype
def test_str2metacstr():
t = Translation(rmu.str2metacstr, [str], backend='mu')
# t.backendopt(mallocs=True, inline=True)
t.mutype()
t.backendopt(mallocs=True, inline=True)
g = graph_of(rmu.str2metacstr, t)
t.mutype()
print_graph(g)
assert [op.opname for op in g.startblock.operations[-3:-1]] == ['mu_getiref', 'mu_getvarpartiref']
assert isinstance(g.startblock.operations[-3].result.concretetype, mutype.MuIRef)
def test_lst2metaarr():
def f(lst):
return rmu.lst2metacarr(rmu.MuID, lst)
t = Translation(f, [[rmu.MuID]], backend='mu')
t.annotate()
g = graph_of(f, t)
t.backendopt(mallocs=True, inline=True)
t.mutype()
print_graph(g)
t.compile_mu() # passes the Mu static checker
assert [op.opname for op in g.startblock.operations[:-1]] == \
['mu_getiref',
'mu_getfieldiref',
'mu_load',
'mu_getiref',
'mu_getvarpartiref',
'mu_shiftiref']
def test_type_translation():
def main(argv):
bldr = rmu.MuIRBuilder()
# i8 = bldr.gen_sym("@i8")
# bldr.new_type_int(i8, 8)
# stt = bldr.gen_sym("@stt")
# bldr.new_type_struct(stt, [i8], 1)
i8 = bldr.gen_sym("@i8")
bldr.new_type_int(i8, 8)
stt = bldr.gen_sym("@stt")
bldr.new_type_struct(stt, [i8])
bldr.load()
return 0
t = Translation(main, None, backend='mu')
t.annotate()
# t.view()
t.rtype()
t.view()
# t.mutype()
# t.view()
t.backendopt(mallocs=True, inline=True)
g = graph_of(main, t)
g.view()
print_graph(g)
t.mutype()
g.view()
print_graph(g)
def test_compile_calls():
......
......@@ -603,6 +603,9 @@ LL_OPERATIONS = {
# entry point hacks
'mu_thread_exit': LLOp(),
'mu_threadlocalref_init': LLOp(),
# hacks for meta-circular ir building instructions
'mu_meta_barebuf2cstriref': LLOp(),
'mu_meta_lst2carr': LLOp(),
}
# ***** Run test_lloperation after changes. *****
......
......@@ -1571,6 +1571,42 @@ class LL2MuMapper:
def map_op_mu_sizedescr2tid(self, llop):
sd = llop.args[0]
# ----------------
# Meta-circular bundle building API binding support (rmu.*_meta)
def map_op_mu_meta_barebuf2cstriref(self, llop):
# check if arg is ref<hybrid<int<8>>>
Ref = llop.args[0].concretetype
assert isinstance(Ref, mutype.MuRef)
Hyb = Ref.TO
assert isinstance(Hyb, mutype.MuHybrid)
assert len(Hyb._names) == 1 # fixed part empty
assert Hyb._var_field_type() is mutype.MU_INT8
ops = []
iref = varof(mutype.MuIRef(Hyb))
ops.append(self.gen_mu_getiref(llop.args[0], iref))
ops.append(self.gen_mu_getvarpartiref(iref, llop.result))
return ops
def map_op_mu_meta_lst2carr(self, llop):
LIST = llop.args[0].concretetype.TO
if isinstance(LIST, mutype.MuStruct):
REFARR = getattr(LIST, 'items', None)
assert isinstance(REFARR, mutype.MuRef)
assert isinstance(REFARR.TO, mutype.MuHybrid)
refarr = varof(REFARR)
ops = self.map_op(SpaceOperation('getfield', [llop.args[0], Constant('items', mutype.MU_VOID)], refarr))
else:
assert isinstance(LIST, mutype.MuHybrid)
ops = []
refarr = llop.args[0]
iref_itm, _ops = self._getarrayitemiref(refarr, Constant(mutype.mu_int64(0), mutype.MU_INT64))
assert iref_itm.concretetype == llop.result.concretetype
_ops[-1].result = llop.result
ops.extend(_ops)
return ops
# -----------------------------------------------------------------------------
# helper functions for constructing muops
def gen_mu_binop(self, optr, opnd1, opnd2, res=None, status=None, status_results=None, excclause=None):
......@@ -1948,4 +1984,19 @@ _lldebugop_c_externfncs = {
'debug_forked': c_debug_forked,
'debug_flush': c_debug_flush,
'have_debug_prints': c_have_debug_prints
}
\ No newline at end of file
}
# conversion functions that can be called without supplying a LL2MuMapper instance
def ll2mu_type(LLT):
ll2mu = LL2MuMapper()
MuT = ll2mu.map_type(LLT)
ll2mu.resolve_ptr_types()
return MuT
def ll2mu_value(llv):
ll2mu = LL2MuMapper()
muv = ll2mu.map_value(llv)
ll2mu.resolve_ptr_values()
return muv
......@@ -202,6 +202,8 @@ class MuTyper:
'mu_setgcidhash',
'mu_thread_exit',
'mu_threadlocalref_init',
'mu_meta_barebuf2cstriref',
'mu_meta_lst2carr',
))
llop.args = [self.specialise_arg(arg) for arg in llop.args]
......
......@@ -694,3 +694,37 @@ def test_cast_pointer_pin():
ll2mu.resolve_ptr_types()
muops = ll2mu.map_op(llop)
assert [op.opname for op in muops] == ['mu_comminst', 'mu_convop']
def test_map_op_mu_meta_barebuf2cstriref():
ll2mu = LL2MuMapper()
llop = SpaceOperation('mu_meta_barebuf2cstriref',
[varof(mutype.MuRef(mutype.MuHybrid('dummy', ('varpart', mutype.MU_INT8))))],
varof(mutype.META_CSTR))
muops = ll2mu.map_op(llop)
assert [op.opname for op in muops] == ['mu_getiref', 'mu_getvarpartiref']
def test_map_op_mu_meta_lst2carr():
ll2mu = LL2MuMapper()
ELM_LLT = lltype.Signed
ARR_LLT = lltype.GcArray(lltype.Signed)
LIST_LLT = lltype.GcStruct('list', ('length', lltype.Signed), ('items', lltype.Ptr(ARR_LLT)))
ELM_MuT = ll2mu.map_type(ELM_LLT)
ARR_MuT = ll2mu.map_type(ARR_LLT)
LIST_MuT = ll2mu.map_type(LIST_LLT)
ll2mu.resolve_ptr_types()
# array case
res = varof(mutype.MuIRef(ELM_MuT))
llop = SpaceOperation('mu_meta_lst2carr', [varof(mutype.MuRef(ARR_MuT))], res)
muops = ll2mu.map_op(llop)
assert [op.opname for op in muops] == ['mu_getiref', 'mu_getvarpartiref', 'mu_shiftiref']
assert muops[-1].result is res
# struct list case
llop = SpaceOperation('mu_meta_lst2carr', [varof(mutype.MuRef(LIST_MuT))], res)
muops = ll2mu.map_op(llop)
assert [op.opname for op in muops] == ['mu_getiref', 'mu_getfieldiref', 'mu_load',
'mu_getiref', 'mu_getvarpartiref', 'mu_shiftiref']
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