本文整理匯總了Python中rpython.rtyper.annlowlevel.MixLevelHelperAnnotator.getgraph方法的典型用法代碼示例。如果您正苦於以下問題:Python MixLevelHelperAnnotator.getgraph方法的具體用法?Python MixLevelHelperAnnotator.getgraph怎麽用?Python MixLevelHelperAnnotator.getgraph使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rpython.rtyper.annlowlevel.MixLevelHelperAnnotator
的用法示例。
在下文中一共展示了MixLevelHelperAnnotator.getgraph方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _setup_frame_realloc
# 需要導入模塊: from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator [as 別名]
# 或者: from rpython.rtyper.annlowlevel.MixLevelHelperAnnotator import getgraph [as 別名]
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))
示例2: test_conditional_call
# 需要導入模塊: from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator [as 別名]
# 或者: from rpython.rtyper.annlowlevel.MixLevelHelperAnnotator import getgraph [as 別名]
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()
示例3: test_pseudohighlevelcallable
# 需要導入模塊: from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator [as 別名]
# 或者: from rpython.rtyper.annlowlevel.MixLevelHelperAnnotator import getgraph [as 別名]
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
示例4: test_secondary_backendopt
# 需要導入模塊: from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator [as 別名]
# 或者: from rpython.rtyper.annlowlevel.MixLevelHelperAnnotator import getgraph [as 別名]
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
示例5: getentrypointptr
# 需要導入模塊: from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator [as 別名]
# 或者: from rpython.rtyper.annlowlevel.MixLevelHelperAnnotator import getgraph [as 別名]
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
示例6: BaseGCTransformer
# 需要導入模塊: from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator [as 別名]
# 或者: from rpython.rtyper.annlowlevel.MixLevelHelperAnnotator import getgraph [as 別名]
#.........這裏部分代碼省略.........
for link, livecounts in self.links_to_split.iteritems():
llops = LowLevelOpList()
for var, livecount in livecounts.iteritems():
for i in range(livecount):
self.pop_alive(var, llops)
for i in range(-livecount):
self.push_alive(var, llops)
if llops:
if link.prevblock.exitswitch is None:
link.prevblock.operations.extend(llops)
else:
insert_empty_block(link, llops)
# remove the empty block at the start of the graph, which should
# still be empty (but let's check)
if starts_with_empty_block(graph) and inserted_empty_startblock:
old_startblock = graph.startblock
graph.startblock = graph.startblock.exits[0].target
checkgraph(graph)
self.links_to_split = None
v = Variable('vanishing_exc_value')
v.concretetype = self.get_lltype_of_exception_value()
llops = LowLevelOpList()
self.pop_alive(v, llops)
graph.exc_cleanup = (v, list(llops))
return is_borrowed # xxx for tests only
def annotate_helper(self, ll_helper, ll_args, ll_result, inline=False):
assert not self.finished_helpers
args_s = map(lltype_to_annotation, ll_args)
s_result = lltype_to_annotation(ll_result)
graph = self.mixlevelannotator.getgraph(ll_helper, args_s, s_result)
# the produced graphs does not need to be fully transformed
self.need_minimal_transform(graph)
if inline:
self.graphs_to_inline[graph] = True
FUNCTYPE = lltype.FuncType(ll_args, ll_result)
return self.mixlevelannotator.graph2delayed(graph, FUNCTYPE=FUNCTYPE)
def inittime_helper(self, ll_helper, ll_args, ll_result, inline=True):
ptr = self.annotate_helper(ll_helper, ll_args, ll_result, inline=inline)
return Constant(ptr, lltype.typeOf(ptr))
def annotate_finalizer(self, ll_finalizer, ll_args, ll_result):
fptr = self.annotate_helper(ll_finalizer, ll_args, ll_result)
self.ll_finalizers_ptrs.append(fptr)
return fptr
def finish_helpers(self, backendopt=True):
if self.translator is not None:
self.mixlevelannotator.finish_annotate()
if self.translator is not None:
self.mixlevelannotator.finish_rtype()
if backendopt:
self.mixlevelannotator.backend_optimize()
self.finished_helpers = True
# Make sure that the database also sees all finalizers now.
# It is likely that the finalizers need special support there
newgcdependencies = self.ll_finalizers_ptrs
return newgcdependencies
def get_finish_helpers(self):
return self.finish_helpers
示例7: ExceptionTransformer
# 需要導入模塊: from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator [as 別名]
# 或者: from rpython.rtyper.annlowlevel.MixLevelHelperAnnotator import getgraph [as 別名]
#.........這裏部分代碼省略.........
[self.lltype_of_exception_type, self.lltype_of_exception_value],
lltype.Void,
jitcallkind='rpyexc_raise') # for the JIT
self.rpyexc_reraise_ptr = self.build_func(
"RPyReRaiseException",
rpyexc_reraise,
[self.lltype_of_exception_type, self.lltype_of_exception_value],
lltype.Void,
jitcallkind='rpyexc_raise') # for the JIT
self.rpyexc_fetch_exception_ptr = self.build_func(
"RPyFetchException",
rpyexc_fetch_exception,
[], self.lltype_of_exception_value)
self.rpyexc_restore_exception_ptr = self.build_func(
"RPyRestoreException",
self.noinline(rpyexc_restore_exception),
[self.lltype_of_exception_value], lltype.Void)
self.build_extra_funcs()
self.mixlevelannotator.finish()
self.lltype_to_classdef = translator.rtyper.lltype_to_classdef_mapping()
def noinline(self, fn):
fn = func_with_new_name(fn, fn.__name__)
fn._dont_inline_ = True
return fn
def build_func(self, name, fn, inputtypes, rettype, **kwds):
l2a = lltype_to_annotation
graph = self.mixlevelannotator.getgraph(fn, map(l2a, inputtypes), l2a(rettype))
return self.constant_func(name, inputtypes, rettype, graph,
exception_policy="exc_helper", **kwds)
def get_builtin_exception(self, Class):
edata = self.translator.rtyper.exceptiondata
bk = self.translator.annotator.bookkeeper
error_def = bk.getuniqueclassdef(Class)
error_ll_exc = edata.get_standard_ll_exc_instance(
self.translator.rtyper, error_def)
error_ll_exc_type = ll_inst_type(error_ll_exc)
return error_ll_exc_type, error_ll_exc
def transform_completely(self):
for graph in self.translator.graphs:
self.create_exception_handling(graph)
def create_exception_handling(self, graph):
"""After an exception in a direct_call (or indirect_call), that is not caught
by an explicit
except statement, we need to reraise the exception. So after this
direct_call we need to test if an exception had occurred. If so, we return
from the current graph with a special value (False/-1/-1.0/null).
Because of the added exitswitch we need an additional block.
"""
if hasattr(graph, 'exceptiontransformed'):
assert self.same_obj(self.exc_data_ptr, graph.exceptiontransformed)
return
else:
self.raise_analyzer.analyze_direct_call(graph)
graph.exceptiontransformed = self.exc_data_ptr
join_blocks(graph)
示例8: except
# 需要導入模塊: from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator [as 別名]
# 或者: from rpython.rtyper.annlowlevel.MixLevelHelperAnnotator import getgraph [as 別名]
dump_arguments = rmarshal.get_marshaller(tuple(args_s))
load_result = rmarshal.get_loader(s_result)
except (NotImplementedError,
rmarshal.CannotMarshal,
rmarshal.CannotUnmarshall), e:
msg = 'Not Implemented: %s' % (e,)
log.WARNING(msg)
def execute(*args):
not_implemented_stub(msg)
else:
def execute(*args):
# marshal the function name and input arguments
buf = []
dump_string(buf, fnname)
dump_arguments(buf, args)
# send the buffer and wait for the answer
loader = sandboxed_io(buf)
# decode the answer
result = load_result(loader)
loader.check_finished()
return result
execute = func_with_new_name(execute, 'sandboxed_' + fnname)
ann = MixLevelHelperAnnotator(db.translator.rtyper)
graph = ann.getgraph(execute, args_s, s_result)
ann.finish()
return graph
示例9: _annotate
# 需要導入模塊: from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator [as 別名]
# 或者: from rpython.rtyper.annlowlevel.MixLevelHelperAnnotator import getgraph [as 別名]
def _annotate(rtyper, f, args_s, s_result):
ann = MixLevelHelperAnnotator(rtyper)
graph = ann.getgraph(f, args_s, s_result)
ann.finish()
return graph
示例10: WarmRunnerDesc
# 需要導入模塊: from rpython.rtyper.annlowlevel import MixLevelHelperAnnotator [as 別名]
# 或者: from rpython.rtyper.annlowlevel.MixLevelHelperAnnotator import getgraph [as 別名]
#.........這裏部分代碼省略.........
"""
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()
def _make_hook_graph(self, jitdriver_sd, annhelper, func,
s_result, s_first_arg=None, onlygreens=True):
if func is None:
return None
#
if not onlygreens:
assert not jitdriver_sd.jitdriver.autoreds, (
"reds='auto' is not compatible with JitDriver hooks such as "
"confirm_enter_jit")
extra_args_s = []
if s_first_arg is not None:
extra_args_s.append(s_first_arg)
#
args_s = jitdriver_sd._portal_args_s
if onlygreens:
args_s = args_s[:len(jitdriver_sd._green_args_spec)]
graph = annhelper.getgraph(func, extra_args_s + args_s, s_result)
funcptr = annhelper.graph2delayed(graph)
return funcptr
def make_args_specifications(self):
for jd in self.jitdrivers_sd:
self.make_args_specification(jd)
def make_args_specification(self, jd):
graph = jd._jit_merge_point_in
_, _, op = locate_jit_merge_point(graph)
greens_v, reds_v = support.decode_hp_hint_args(op)
ALLARGS = [v.concretetype for v in (greens_v + reds_v)]
jd._green_args_spec = [v.concretetype for v in greens_v]
jd.red_args_types = [history.getkind(v.concretetype) for v in reds_v]
jd.num_green_args = len(jd._green_args_spec)
jd.num_red_args = len(jd.red_args_types)
RESTYPE = graph.getreturnvar().concretetype
(jd._JIT_ENTER_FUNCTYPE,
jd._PTR_JIT_ENTER_FUNCTYPE) = self.cpu.ts.get_FuncType(ALLARGS, lltype.Void)
(jd._PORTAL_FUNCTYPE,
jd._PTR_PORTAL_FUNCTYPE) = self.cpu.ts.get_FuncType(ALLARGS, RESTYPE)
#
if jd.result_type == 'v':
ASMRESTYPE = lltype.Void
elif jd.result_type == history.INT:
ASMRESTYPE = lltype.Signed
elif jd.result_type == history.REF:
ASMRESTYPE = llmemory.GCREF
elif jd.result_type == history.FLOAT:
ASMRESTYPE = lltype.Float
else:
assert False