Commit 8b345be8 authored by John Zhang's avatar John Zhang

wip: towards a working binding.

- added support for other meta instructions
- included flags for COMMINST for meta-circular building other COMMINSTs
- added support for name=None in gen_sym
- added support for converting RPython list to meta C arrays
- updated some tests
parent 2b9cc393
......@@ -260,6 +260,10 @@ class MuCommInst:
META_ENABLE_WATCHPOINT = rffi.cast(MuFlag, 0x25e)
META_DISABLE_WATCHPOINT = rffi.cast(MuFlag, 0x25f)
META_SET_TRAP_HANDLER = rffi.cast(MuFlag, 0x260)
META_CONSTANT_BY_ID = rffi.cast(MuFlag, 0x268)
META_GLOBAL_BY_ID = rffi.cast(MuFlag, 0x269)
META_FUNC_BY_ID = rffi.cast(MuFlag, 0x26a)
META_EXPFUNC_BY_ID = rffi.cast(MuFlag, 0x26b)
IRBUILDER_NEW_IR_BUILDER = rffi.cast(MuFlag, 0x270)
IRBUILDER_LOAD = rffi.cast(MuFlag, 0x300)
IRBUILDER_ABORT = rffi.cast(MuFlag, 0x301)
......
......@@ -491,6 +491,10 @@ class MuCommInst:
META_ENABLE_WATCHPOINT = "MU_CI_UVM_META_ENABLE_WATCHPOINT"
META_DISABLE_WATCHPOINT = "MU_CI_UVM_META_DISABLE_WATCHPOINT"
META_SET_TRAP_HANDLER = "MU_CI_UVM_META_SET_TRAP_HANDLER"
META_CONSTANT_BY_ID = "MU_CI_UVM_META_CONSTANT_BY_ID"
META_GLOBAL_BY_ID = "MU_CI_UVM_META_GLOBAL_BY_ID"
META_FUNC_BY_ID = "MU_CI_UVM_META_FUNC_BY_ID"
META_EXPFUNC_BY_ID = "MU_CI_UVM_META_EXPFUNC_BY_ID"
IRBUILDER_NEW_IR_BUILDER = "MU_CI_UVM_IRBUILDER_NEW_IR_BUILDER"
IRBUILDER_LOAD = "MU_CI_UVM_IRBUILDER_LOAD"
IRBUILDER_ABORT = "MU_CI_UVM_IRBUILDER_ABORT"
......
This diff is collapsed.
......@@ -2,18 +2,20 @@ 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
from rpython.translator.mu import mutype, ll2mu
from rpython.rtyper.lltypesystem import lltype, rffi
def test_str2metacstr():
t = Translation(rmu.str2metacstr, [str], backend='mu')
t.backendopt(mallocs=True, inline=True)
g = graph_of(rmu.str2metacstr, t)
print_graph(g)
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)
blk = g.startblock.exits[1].target
assert [op.opname for op in blk.operations[-3:-1]] == ['mu_getiref', 'mu_getvarpartiref']
assert isinstance(blk.operations[-3].result.concretetype, mutype.MuIRef)
def test_lst2metaarr():
......@@ -58,58 +60,85 @@ def test_type_translation():
print_graph(g)
def test_compile_calls():
from rpython.translator.mu.tool.textgraph import save_graphs
from rpython.rlib.jit import hint
def main(argv):
"""
Builds the following test bundle.
.typedef @i8 = int<8>
.const @0xff_i8 <@i8> = 0xff
.const @0x0a_i8 <@i8> = 0x0a
.funcsig @sig__i8 = () -> (@i8)
.funcdecl @test_fnc <@fnrsig__i8>
.funcdef @test_fnc VERSION @test_fnc_v1 <@sig__i8> {
@test_fnc_v1.blk0():
@test_fnc_v1.blk0.res = ADD <@i8> @0xff_i8 @0x0a_i8
RET @test_fnc_v1.blk0.res
}
"""
hint(0, rmu_meta=True)
mu = rmu.MuVM()
ctx = mu.new_context()
bldr = ctx.new_ir_builder()
i8 = bldr.gen_sym("@i8")
bldr.new_type_int(i8, 8)
def test_func_by_id():
FUNCPTR = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Signed))
def f(id):
return rmu.meta_func_by_id(FUNCPTR, id)
c_0xff_i8 = bldr.gen_sym("@0xff_i8")
bldr.new_const_int(c_0xff_i8, i8, 0xff)
c_0x0a_i8 = bldr.gen_sym("@0x0a_i8")
bldr.new_const_int(c_0x0a_i8, i8, 0x0a)
t = Translation(f, [rmu.MuID], backend='mu')
t.rtype()
h = graph_of(rmu.meta_func_by_id, t)
assert h.startblock.operations[0].opname == 'mu_meta_xxx_by_id'
t.mutype()
g = graph_of(f, t)
print_graph(g)
sig__i8 = bldr.gen_sym("@sig__i8")
bldr.new_funcsig(sig__i8, [], [i8])
op = g.startblock.operations[0]
meta_info = op.args[-1].value
assert 'types' in meta_info
assert meta_info['types'] == [ll2mu.ll2mu_type(FUNCPTR)]
test_fnc = bldr.gen_sym("@test_fnc")
bldr.new_func(test_fnc, sig__i8)
# function body
v1 = bldr.gen_sym("@test_fnc_v1")
blk0 = bldr.gen_sym("@test_fnc_v1.blk0")
res = bldr.gen_sym("@test_fnc_v1.blk0.res")
op_binop = bldr.gen_sym()
bldr.new_binop(op_binop, res, rmu.MuBinOptr.ADD, i8, c_0xff_i8, c_0x0a_i8)
op_ret = bldr.gen_sym()
bldr.new_ret(op_ret, [res])
bldr.new_bb(blk0, [], [], rmu.MU_NO_ID, [op_binop, op_ret])
bldr.new_func_ver(v1, test_fnc, [blk0])
def test_compile_calls():
import py
def build_func(bldr):
"""
Builds the following test bundle.
.const @c_1 <@i64> = 1
.funcsig @sig_i64_i64 = (@i64) -> (i@64)
.func @inc VERSION @inc.v1 <@sig_i64_i64> {
%blk0(<@i64> %a):
%a_suc = ADD <@i64> %a @c_1
RET %a_suc
}
:type bldr: rpython.rlib.rmu.holstein_meta.MuIRBuilder
"""
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])
stt = bldr.gen_sym(); bldr.new_type_struct(stt, [i64])
inc = bldr.gen_sym("@inc"); bldr.new_func(inc, sig_i64_i64)
blk0 = bldr.gen_sym("@inc.blk0")
a = bldr.gen_sym("@inc.blk0.a")
a_suc = bldr.gen_sym("@inc.blk0.a_suc")
op_add = bldr.gen_sym(); bldr.new_binop(op_add, a_suc, rmu.MuBinOptr.ADD, i64, a, c_1)
op_ret = bldr.gen_sym(); bldr.new_ret(op_ret, [a_suc])
bldr.new_bb(blk0, [a], [i64], rmu.MU_NO_ID, [op_add, op_ret])
bldr.new_func_ver(bldr.gen_sym(), inc, [blk0])
return inc
FUNCPTR = lltype.Ptr(lltype.FuncType([lltype.Signed], lltype.Signed))
def main(argc, argv):
bldr = rmu.MuIRBuilder()
id_fnc = build_func(bldr)
bldr.load()
hint(0, rmu_meta=False)
a = rffi.cast(lltype.Signed, argc)
inc = rmu.meta_func_by_id(FUNCPTR, id_fnc)
a_inc = inc(a)
print a_inc
return 0
t = Translation(main, None, backend='mu')
t.backendopt(mallocs=True)
t = Translation(main, [rffi.INT, rffi.CCHARPP], 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()
t.compile_mu()
img = py.path.local(t.driver.exe_name)
from rpython.rlib.rmu import holstein
from rpython.translator.platform import platform, log as log_platform
save_graphs(t.context.graphs)
runmu = py.path.local(holstein.mu_dir).join('..', 'tools', 'runmu.sh')
flags = ['--vmLog=ERROR', '--losSize=780M', '--sosSize=780M']
args = ['1']
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'
......@@ -249,6 +249,9 @@ class MuBundleGen:
self.bdr.new_type_uptr(_id, self._id_of(T.TO))
elif isinstance(T, mutype.MuWeakRef):
self.bdr.new_type_weakref(_id, self._id_of(T.TO))
elif isinstance(T, mutype.MuOpaqueRef):
if T is mutype.MUTA_IRBUILDER_REF:
self.bdr.new_type_irbuilderref(_id)
def gen_consts(self):
self.log.gen_types("declaring %d constants..." % (len(self.db.consts) + len(self.db.extern_fncs)))
......@@ -479,6 +482,9 @@ class MuBundleGen:
flags, types, sigs,
self._ids_of(op.args[1:-1]))
def _genop_mu_meta_callinternal(self, op, op_id):
pass
def _id_of(self, entity):
# look up id of the entity, if non-existent, call gen_sym
_id = self.idmap[entity]
......
......@@ -1607,6 +1607,14 @@ class LL2MuMapper:
ops.extend(_ops)
return ops
def map_op_mu_meta_xxx_by_id(self, llop):
# set 'types' in metainfo, change opname back to mu_comminst
metainfo = llop.args[-1].value
RES_T = llop.result.concretetype
metainfo['types'] = [RES_T]
llop.opname = 'mu_comminst'
return [llop]
# -----------------------------------------------------------------------------
# helper functions for constructing muops
def gen_mu_binop(self, optr, opnd1, opnd2, res=None, status=None, status_results=None, excclause=None):
......
......@@ -204,6 +204,7 @@ class MuTyper:
'mu_threadlocalref_init',
'mu_meta_barebuf2cstriref',
'mu_meta_lst2carr',
'mu_meta_xxx_by_id'
))
llop.args = [self.specialise_arg(arg) for arg in llop.args]
......@@ -326,7 +327,7 @@ def prepare(graphs, entry_graph):
_OPS_KEEP_ALL_ARGS = ('setfield', 'setinteriorfield')
# Returns True if the argument/parameter is to be kept
if (opname == 'mu_comminst') or ('malloc' in opname) or \
if (opname in ('mu_comminst', 'mu_meta_xxx_by_id')) or ('malloc' in opname) or \
('setfield' in opname) or (arg.concretetype != lltype.Void):
return 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