To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit c24325ec authored by John Zhang's avatar John Zhang
Browse files

Finished binding.

fix: meta_id_of should pass a @uvm.meta.bytes, added support for it.
add type hack 'mu_render_as' to ll2mu(GcArray)
parent 8b345be8
......@@ -382,12 +382,12 @@ class Entry(ExtRegistryEntry):
def meta_id_of(name):
name_irstr = str2metacstr(name)
name_irstr = str2metabytes(name)
return ir_inst(MetaInst.ID_OF, name_irstr, restype=MuID)
def meta_name_of(id):
return ir_inst(MetaInst.NAME_OF, id, restype=MuMetaCStr)
return ir_inst(MetaInst.NAME_OF, id, restype=MuMetaBytes)
@specialize.arg(0)
def meta_const_by_id(TYPE, id):
......@@ -744,8 +744,11 @@ _StrBuf = lltype.GcArray(lltype.Char, hints={'nolength': True, 'mu_nohashfield':
_StrBufPtr = lltype.Ptr(_StrBuf)
MuMetaCStr = lltype.Ptr(lltype.GcOpaqueType('MuMetaCStr',
hints={'mu_render_ptr_as': mutype.META_CSTR}))
_BytesBuf = lltype.GcArray(lltype.Char, hints={'mu_nohashfield': True,
'mu_render_as': mutype.META_BYTES})
MuMetaBytes = lltype.Ptr(_BytesBuf)
def str2metacstr(str):
def str2metacstr(str=None):
if str:
n = len(str)
buf = lltype.malloc(_StrBuf, n + 1)
......@@ -763,6 +766,21 @@ def str2metacstr(str):
return lltype.nullptr(MuMetaCStr.TO)
def str2metabytes(str=None):
if str:
n = len(str)
buf = lltype.malloc(_BytesBuf, n) # length should have been set in ll2mu
adr_buf = llmemory.cast_ptr_to_adr(buf) + llmemory.itemoffsetof(_BytesBuf, 0)
adr_src = llmemory.cast_ptr_to_adr(str) + (llmemory.offsetof(rstr.STR, 'chars') +
llmemory.itemoffsetof(rstr.STR.chars, 0) +
llmemory.sizeof(rstr.Char) * 0)
llmemory.raw_memcopy(adr_src, adr_buf, llmemory.sizeof(rstr.Char) * n)
keepalive_until_here(buf)
keepalive_until_here(str)
return buf
else:
return lltype.nullptr(MuMetaBytes.TO)
@specialize.memo()
def _carriptr_type_of(ELM_T):
ELM_MuT = ll2mu_type(ELM_T)
......
......@@ -18,6 +18,16 @@ def test_str2metacstr():
assert isinstance(blk.operations[-3].result.concretetype, mutype.MuIRef)
def test_str2metabytes():
t = Translation(rmu.str2metabytes, [str], backend='mu')
t.backendopt(mallocs=True, inline=True)
g = graph_of(rmu.str2metabytes, t)
print_graph(g)
t.mutype()
print_graph(g)
assert g.returnblock.inputargs[0].concretetype == mutype.META_BYTES_REF
def test_lst2metaarr():
def f(lst):
return rmu.lst2metacarr(rmu.MuID, lst)
......@@ -79,7 +89,7 @@ def test_func_by_id():
assert meta_info['types'] == [ll2mu.ll2mu_type(FUNCPTR)]
def test_compile_calls():
def test_call_meta_compiled_func():
import py
def build_func(bldr):
......@@ -96,7 +106,9 @@ def test_compile_calls():
"""
i64 = rmu.meta_id_of("@i64")
c_1 = bldr.gen_sym("@c_1"); bldr.new_const_int(c_1, i64, 1)
sig_i64_i64 = bldr.gen_sym("@sig_i64_i64"); bldr.new_funcsig(sig_i64_i64, [i64], [i64])
sig_i64_i64 = rmu.meta_id_of("@sig_i64_i64") # assume known signature name
# sig_i64_i64 = bldr.gen_sym("@sig_i64_i64_meta") # alternate approach, redefine a signature with another name
# bldr.new_funcsig(sig_i64_i64, [i64], [i64])
stt = bldr.gen_sym(); bldr.new_type_struct(stt, [i64])
inc = bldr.gen_sym("@inc"); bldr.new_func(inc, sig_i64_i64)
......@@ -111,20 +123,19 @@ def test_compile_calls():
FUNCPTR = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Signed))
def main(argc, argv):
def main(args):
bldr = rmu.MuIRBuilder()
id_fnc = build_func(bldr)
bldr.load()
a = rffi.cast(lltype.Signed, argc)
a = int(args[1])
inc = rmu.meta_func_by_id(FUNCPTR, id_fnc)
a_inc = inc(a)
print a_inc
return 0
t = Translation(main, [rffi.INT, rffi.CCHARPP], backend='mu', impl='holstein', codegen='c')
t = Translation(main, None, backend='mu', impl='holstein', codegen='c')
t.driver.standalone = True # force standalone
t.driver.exe_name = '/tmp/test_compile_calls-mu'
t.driver.disable(['entrypoint_mu'])
t.annotate()
# t.backendopt(mallocs=True)
t.mutype()
......@@ -137,8 +148,8 @@ def test_compile_calls():
runmu = py.path.local(holstein.mu_dir).join('..', 'tools', 'runmu.sh')
flags = ['--vmLog=ERROR', '--losSize=780M', '--sosSize=780M']
args = ['1']
args = ['42']
log_platform.execute(' '.join([str(runmu)] + flags + [str(img)] + args))
res = platform.execute(runmu, flags + [str(img)] + args)
assert res.returncode == 0, res.err
assert res.out == '2\n'
assert res.out == '43\n'
......@@ -212,6 +212,9 @@ class LL2MuMapper:
return mutype.MuHybrid(name, *flds)
def map_type_arr(self, LLT):
if LLT._hints.get('mu_render_as', None):
return LLT._hints['mu_render_as']
name = "arr" + ("%s" % LLT.OF.__name__ if hasattr(LLT.OF, '__name__') else str(LLT.OF))
if LLT.OF is lltype.Void:
......
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