本文整理匯總了Python中rpython.rtyper.annlowlevel.MixLevelHelperAnnotator類的典型用法代碼示例。如果您正苦於以下問題:Python MixLevelHelperAnnotator類的具體用法?Python MixLevelHelperAnnotator怎麽用?Python MixLevelHelperAnnotator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了MixLevelHelperAnnotator類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: call_final_function
def call_final_function(translator, final_func, annhelper=None):
"""When the program finishes normally, call 'final_func()'."""
from rpython.annotator import model as annmodel
from rpython.rtyper.lltypesystem import lltype
from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator
own_annhelper = (annhelper is None)
if own_annhelper:
annhelper = MixLevelHelperAnnotator(translator.rtyper)
c_final_func = annhelper.constfunc(final_func, [], annmodel.s_None)
if own_annhelper:
annhelper.finish()
entry_point = translator.entry_point_graph
v = copyvar(translator.annotator, entry_point.getreturnvar())
extrablock = Block([v])
v_none = varoftype(lltype.Void)
newop = SpaceOperation('direct_call', [c_final_func], v_none)
extrablock.operations = [newop]
extrablock.closeblock(Link([v], entry_point.returnblock))
for block in entry_point.iterblocks():
if block is not extrablock:
for link in block.exits:
if link.target is entry_point.returnblock:
link.target = extrablock
checkgraph(entry_point)
示例2: builtin_func_for_spec
def builtin_func_for_spec(rtyper, oopspec_name, ll_args, ll_res,
extra=None, extrakey=None):
assert (extra is None) == (extrakey is None)
key = (oopspec_name, tuple(ll_args), ll_res, extrakey)
try:
return rtyper._builtin_func_for_spec_cache[key]
except (KeyError, AttributeError):
pass
args_s = [lltype_to_annotation(v) for v in ll_args]
if '.' not in oopspec_name: # 'newxxx' operations
LIST_OR_DICT = ll_res
else:
LIST_OR_DICT = ll_args[0]
s_result = lltype_to_annotation(ll_res)
impl = setup_extra_builtin(rtyper, oopspec_name, len(args_s), extra)
if getattr(impl, 'need_result_type', False):
bk = rtyper.annotator.bookkeeper
args_s.insert(0, annmodel.SomePBC([bk.getdesc(deref(ll_res))]))
#
if hasattr(rtyper, 'annotator'): # regular case
mixlevelann = MixLevelHelperAnnotator(rtyper)
c_func = mixlevelann.constfunc(impl, args_s, s_result)
mixlevelann.finish()
else:
# for testing only
c_func = Constant(oopspec_name,
lltype.Ptr(lltype.FuncType(ll_args, ll_res)))
#
if not hasattr(rtyper, '_builtin_func_for_spec_cache'):
rtyper._builtin_func_for_spec_cache = {}
rtyper._builtin_func_for_spec_cache[key] = (c_func, LIST_OR_DICT)
#
return c_func, LIST_OR_DICT
示例3: make_driverhook_graphs
def make_driverhook_graphs(self):
from rpython.rlib.jit import BaseJitCell
bk = self.rtyper.annotator.bookkeeper
classdef = bk.getuniqueclassdef(BaseJitCell)
s_BaseJitCell_or_None = annmodel.SomeInstance(classdef,
can_be_None=True)
s_BaseJitCell_not_None = annmodel.SomeInstance(classdef)
s_Str = annmodel.SomeString()
#
annhelper = MixLevelHelperAnnotator(self.translator.rtyper)
for jd in self.jitdrivers_sd:
jd._set_jitcell_at_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.set_jitcell_at, annmodel.s_None,
s_BaseJitCell_not_None)
jd._get_jitcell_at_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.get_jitcell_at, s_BaseJitCell_or_None)
jd._get_printable_location_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.get_printable_location, s_Str)
jd._confirm_enter_jit_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.confirm_enter_jit, annmodel.s_Bool,
onlygreens=False)
jd._can_never_inline_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.can_never_inline, annmodel.s_Bool)
jd._should_unroll_one_iteration_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.should_unroll_one_iteration,
annmodel.s_Bool)
annhelper.finish()
示例4: complete_destrptr
def complete_destrptr(gctransformer):
translator = gctransformer.translator
mixlevelannotator = MixLevelHelperAnnotator(translator.rtyper)
args_s = [lltype_to_annotation(STACKLET_PTR)]
s_result = annmodel.s_None
destrptr = mixlevelannotator.delayedfunction(stacklet_destructor, args_s, s_result)
mixlevelannotator.finish()
lltype.attachRuntimeTypeInfo(STACKLET, destrptr=destrptr)
示例5: _setup_frame_realloc
def _setup_frame_realloc(self, translate_support_code):
FUNC_TP = lltype.Ptr(lltype.FuncType([llmemory.GCREF, lltype.Signed],
llmemory.GCREF))
base_ofs = self.get_baseofs_of_frame_field()
def realloc_frame(frame, size):
try:
if not we_are_translated():
assert not self._exception_emulator[0]
frame = lltype.cast_opaque_ptr(jitframe.JITFRAMEPTR, frame)
if size > frame.jf_frame_info.jfi_frame_depth:
# update the frame_info size, which is for whatever reason
# not up to date
frame.jf_frame_info.update_frame_depth(base_ofs, size)
new_frame = jitframe.JITFRAME.allocate(frame.jf_frame_info)
frame.jf_forward = new_frame
i = 0
while i < len(frame.jf_frame):
new_frame.jf_frame[i] = frame.jf_frame[i]
frame.jf_frame[i] = 0
i += 1
new_frame.jf_savedata = frame.jf_savedata
new_frame.jf_guard_exc = frame.jf_guard_exc
# all other fields are empty
llop.gc_writebarrier(lltype.Void, new_frame)
return lltype.cast_opaque_ptr(llmemory.GCREF, new_frame)
except Exception as e:
print "Unhandled exception", e, "in realloc_frame"
return lltype.nullptr(llmemory.GCREF.TO)
def realloc_frame_crash(frame, size):
print "frame", frame, "size", size
return lltype.nullptr(llmemory.GCREF.TO)
if not translate_support_code:
fptr = llhelper(FUNC_TP, realloc_frame)
else:
FUNC = FUNC_TP.TO
args_s = [lltype_to_annotation(ARG) for ARG in FUNC.ARGS]
s_result = lltype_to_annotation(FUNC.RESULT)
mixlevelann = MixLevelHelperAnnotator(self.rtyper)
graph = mixlevelann.getgraph(realloc_frame, args_s, s_result)
fptr = mixlevelann.graph2delayed(graph, FUNC)
mixlevelann.finish()
self.realloc_frame = heaptracker.adr2int(llmemory.cast_ptr_to_adr(fptr))
if not translate_support_code:
fptr = llhelper(FUNC_TP, realloc_frame_crash)
else:
FUNC = FUNC_TP.TO
args_s = [lltype_to_annotation(ARG) for ARG in FUNC.ARGS]
s_result = lltype_to_annotation(FUNC.RESULT)
mixlevelann = MixLevelHelperAnnotator(self.rtyper)
graph = mixlevelann.getgraph(realloc_frame_crash, args_s, s_result)
fptr = mixlevelann.graph2delayed(graph, FUNC)
mixlevelann.finish()
self.realloc_frame_crash = heaptracker.adr2int(llmemory.cast_ptr_to_adr(fptr))
示例6: test_conditional_call
def test_conditional_call(self):
def g():
pass
def f(n):
conditional_call(n >= 0, g)
def later(m):
conditional_call(m, g)
t = TranslationContext()
t.buildannotator().build_types(f, [int])
t.buildrtyper().specialize()
mix = MixLevelHelperAnnotator(t.rtyper)
mix.getgraph(later, [annmodel.s_Bool], annmodel.s_None)
mix.finish()
示例7: test_delayed_fnptr
def test_delayed_fnptr():
from rpython.flowspace.model import SpaceOperation
from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator
from rpython.translator.translator import TranslationContext
t = TranslationContext()
t.buildannotator()
t.buildrtyper()
annhelper = MixLevelHelperAnnotator(t.rtyper)
def f():
pass
c_f = annhelper.constfunc(f, [], None)
op = SpaceOperation('direct_call', [c_f], None)
analyzer = BoolGraphAnalyzer(t)
assert analyzer.analyze(op)
示例8: make_driverhook_graphs
def make_driverhook_graphs(self):
s_Str = annmodel.SomeString()
#
annhelper = MixLevelHelperAnnotator(self.translator.rtyper)
for jd in self.jitdrivers_sd:
jd._get_printable_location_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.get_printable_location, s_Str)
jd._confirm_enter_jit_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.confirm_enter_jit, annmodel.s_Bool,
onlygreens=False)
jd._can_never_inline_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.can_never_inline, annmodel.s_Bool)
jd._should_unroll_one_iteration_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.should_unroll_one_iteration,
annmodel.s_Bool)
annhelper.finish()
示例9: make_driverhook_graphs
def make_driverhook_graphs(self):
#
annhelper = MixLevelHelperAnnotator(self.translator.rtyper)
for jd in self.jitdrivers_sd:
jd._get_printable_location_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.get_printable_location,
annmodel.SomeString())
jd._get_unique_id_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.get_unique_id, annmodel.SomeInteger())
jd._confirm_enter_jit_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.confirm_enter_jit, annmodel.s_Bool,
onlygreens=False)
jd._can_never_inline_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.can_never_inline, annmodel.s_Bool)
jd._should_unroll_one_iteration_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.should_unroll_one_iteration,
annmodel.s_Bool)
#
items = []
types = ()
pos = ()
if jd.jitdriver.get_location:
assert hasattr(jd.jitdriver.get_location, '_loc_types'), """
You must decorate your get_location function:
from rpython.rlib.rjitlog import rjitlog as jl
@jl.returns(jl.MP_FILENAME, jl.MP_XXX, ...)
def get_loc(your, green, keys):
name = "x.txt" # extract it from your green keys
return (name, ...)
"""
types = jd.jitdriver.get_location._loc_types
del jd.jitdriver.get_location._loc_types
#
for _,type in types:
if type == 's':
items.append(annmodel.SomeString())
elif type == 'i':
items.append(annmodel.SomeInteger())
else:
raise NotImplementedError
s_Tuple = annmodel.SomeTuple(items)
jd._get_location_ptr = self._make_hook_graph(jd,
annhelper, jd.jitdriver.get_location, s_Tuple)
jd._get_loc_types = types
annhelper.finish()
示例10: replace_force_virtualizable
def replace_force_virtualizable(self, rtyper, graphs):
from rpython.annotator import model as annmodel
from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator
graph = graphs[0]
for block, op in graph.iterblockops():
if op.opname == 'jit_force_virtualizable':
v_inst_ll_type = op.args[0].concretetype
break
def mycall(vinst_ll):
if vinst_ll.vable_token:
raise ValueError
annhelper = MixLevelHelperAnnotator(rtyper)
s_vinst = SomePtr(v_inst_ll_type)
funcptr = annhelper.delayedfunction(mycall, [s_vinst], annmodel.s_None)
annhelper.finish()
replace_force_virtualizable_with_call(graphs, v_inst_ll_type, funcptr)
return funcptr
示例11: test_pseudohighlevelcallable
def test_pseudohighlevelcallable():
t = TranslationContext()
t.buildannotator()
rtyper = t.buildrtyper()
rtyper.specialize()
a = MixLevelHelperAnnotator(rtyper)
class A:
value = 5
def double(self):
return self.value * 2
def fn1(a):
a2 = A()
a2.value = a.double()
return a2
s_A, r_A = a.s_r_instanceof(A)
fn1ptr = a.delayedfunction(fn1, [s_A], s_A)
pseudo = PseudoHighLevelCallable(fn1ptr, [s_A], s_A)
def fn2(n):
a = A()
a.value = n
a2 = pseudo(a)
return a2.value
graph = a.getgraph(fn2, [annmodel.SomeInteger()], annmodel.SomeInteger())
a.finish()
llinterp = LLInterpreter(rtyper)
res = llinterp.eval_graph(graph, [21])
assert res == 42
示例12: call_initial_function
def call_initial_function(translator, initial_func, annhelper=None):
"""Before the program starts, call 'initial_func()'."""
from rpython.annotator import model as annmodel
from rpython.rtyper.lltypesystem import lltype
from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator
own_annhelper = (annhelper is None)
if own_annhelper:
annhelper = MixLevelHelperAnnotator(translator.rtyper)
c_initial_func = annhelper.constfunc(initial_func, [], annmodel.s_None)
if own_annhelper:
annhelper.finish()
entry_point = translator.entry_point_graph
args = [copyvar(translator.annotator, v) for v in entry_point.getargs()]
extrablock = Block(args)
v_none = varoftype(lltype.Void)
newop = SpaceOperation('direct_call', [c_initial_func], v_none)
extrablock.operations = [newop]
extrablock.closeblock(Link(args, entry_point.startblock))
entry_point.startblock = extrablock
checkgraph(entry_point)
示例13: getentrypointptr
def getentrypointptr(self):
# XXX check that the entrypoint has the correct
# signature: list-of-strings -> int
if not self.make_entrypoint_wrapper:
bk = self.translator.annotator.bookkeeper
return getfunctionptr(bk.getdesc(self.entrypoint).getuniquegraph())
if self._entrypoint_wrapper is not None:
return self._entrypoint_wrapper
#
from rpython.annotator import model as annmodel
from rpython.rtyper.lltypesystem import rffi
from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator
from rpython.rtyper.llannotation import lltype_to_annotation
entrypoint = self.entrypoint
#
def entrypoint_wrapper(argc, argv):
"""This is a wrapper that takes "Signed argc" and "char **argv"
like the C main function, and puts them inside an RPython list
of strings before invoking the real entrypoint() function.
"""
list = [""] * argc
i = 0
while i < argc:
list[i] = rffi.charp2str(argv[i])
i += 1
return entrypoint(list)
#
mix = MixLevelHelperAnnotator(self.translator.rtyper)
args_s = [annmodel.SomeInteger(),
lltype_to_annotation(rffi.CCHARPP)]
s_result = annmodel.SomeInteger()
graph = mix.getgraph(entrypoint_wrapper, args_s, s_result)
mix.finish()
res = getfunctionptr(graph)
self._entrypoint_wrapper = res
return res
示例14: __init__
def __init__(self, translator, inline=False):
self.translator = translator
self.seen_graphs = set()
self.prepared = False
self.minimal_transform = set()
if translator:
self.mixlevelannotator = MixLevelHelperAnnotator(translator.rtyper)
else:
self.mixlevelannotator = None
self.inline = inline
if translator and inline:
self.lltype_to_classdef = translator.rtyper.lltype_to_classdef_mapping()
self.graphs_to_inline = {}
self.graph_dependencies = {}
self.ll_finalizers_ptrs = []
if self.MinimalGCTransformer:
self.minimalgctransformer = self.MinimalGCTransformer(self)
else:
self.minimalgctransformer = None
示例15: test_secondary_backendopt
def test_secondary_backendopt(self):
# checks an issue with a newly added graph that calls an
# already-exception-transformed graph. This can occur e.g.
# from a late-seen destructor added by the GC transformer
# which ends up calling existing code.
def common(n):
if n > 5:
raise ValueError
def main(n):
common(n)
def later(n):
try:
common(n)
return 0
except ValueError:
return 1
t = TranslationContext()
t.buildannotator().build_types(main, [int])
t.buildrtyper().specialize()
exctransformer = t.getexceptiontransformer()
exctransformer.create_exception_handling(graphof(t, common))
from rpython.annotator import model as annmodel
from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator
annhelper = MixLevelHelperAnnotator(t.rtyper)
later_graph = annhelper.getgraph(later, [annmodel.SomeInteger()], annmodel.SomeInteger())
annhelper.finish()
annhelper.backend_optimize()
# ^^^ as the inliner can't handle exception-transformed graphs,
# this should *not* inline common() into later().
if option.view:
later_graph.show()
common_graph = graphof(t, common)
found = False
for block in later_graph.iterblocks():
for op in block.operations:
if op.opname == "direct_call" and op.args[0].value._obj.graph is common_graph:
found = True
assert found, "cannot find the call (buggily inlined?)"
from rpython.rtyper.llinterp import LLInterpreter
llinterp = LLInterpreter(t.rtyper)
res = llinterp.eval_graph(later_graph, [10])
assert res == 1