本文整理汇总了Python中rpython.translator.translator.TranslationContext.view方法的典型用法代码示例。如果您正苦于以下问题:Python TranslationContext.view方法的具体用法?Python TranslationContext.view怎么用?Python TranslationContext.view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rpython.translator.translator.TranslationContext
的用法示例。
在下文中一共展示了TranslationContext.view方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: translate
# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import view [as 别名]
def translate(self, func, sig):
t = TranslationContext()
t.buildannotator().build_types(func, sig)
t.buildrtyper().specialize()
if option.view:
t.view()
return t, self.Analyzer(t)
示例2: generate_source_for_function
# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import view [as 别名]
def generate_source_for_function(func, annotation, backendopt=False):
"""
Given a Python function and some hints about its argument types,
generates JVM sources that call it and print the result. Returns
the JvmGeneratedSource object.
"""
if hasattr(func, "im_func"):
func = func.im_func
t = TranslationContext()
ann = t.buildannotator()
ann.build_types(func, annotation)
t.buildrtyper(type_system="ootype").specialize()
if backendopt:
check_virtual_methods(ootype.ROOT)
backend_optimizations(t)
main_graph = t.graphs[0]
if getoption("view"):
t.view()
if getoption("wd"):
tmpdir = py.path.local(".")
else:
tmpdir = udir
jvm = GenJvm(tmpdir, t, EntryPoint(main_graph, True, True))
return jvm.generate_source()
示例3: compile
# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import view [as 别名]
def compile(self, entry_point, debug=True, shared=False,
stackcheck=False, entrypoints=None):
t = TranslationContext(self.config)
ann = t.buildannotator()
ann.build_types(entry_point, [s_list_of_strings])
if entrypoints is not None:
anns = {}
for func, annotation in secondary_entrypoints['test']:
anns[func] = annotation
for item in entrypoints:
ann.build_types(item, anns[item])
t.buildrtyper().specialize()
if stackcheck:
from rpython.translator.transform import insert_ll_stackcheck
insert_ll_stackcheck(t)
t.config.translation.shared = shared
if entrypoints is not None:
kwds = {'secondary_entrypoints': [(i, None) for i in entrypoints]}
else:
kwds = {}
cbuilder = CStandaloneBuilder(t, entry_point, t.config, **kwds)
if debug:
cbuilder.generate_source(defines=cbuilder.DEBUG_DEFINES)
else:
cbuilder.generate_source()
cbuilder.compile()
if option is not None and option.view:
t.view()
return t, cbuilder
示例4: gengraph
# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import view [as 别名]
def gengraph(func, argtypes=[], viewbefore='auto', policy=None,
backendopt=False, config=None, **extraconfigopts):
t = TranslationContext(config=config)
t.config.set(**extraconfigopts)
a = t.buildannotator(policy=policy)
a.build_types(func, argtypes, main_entry_point=True)
a.validate()
if viewbefore == 'auto':
viewbefore = getattr(option, 'view', False)
if viewbefore:
a.simplify()
t.view()
global typer # we need it for find_exception
typer = t.buildrtyper()
typer.backend = llinterp_backend
typer.specialize()
#t.view()
t.checkgraphs()
if backendopt:
from rpython.translator.backendopt.all import backend_optimizations
backend_optimizations(t)
t.checkgraphs()
if viewbefore:
t.view()
desc = t.annotator.bookkeeper.getdesc(func)
graph = desc.specialize(argtypes)
return t, typer, graph
示例5: check
# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import view [as 别名]
def check(self, fn, signature, args, expected_result, must_be_removed=True,
inline=None):
remover = self.MallocRemover()
t = TranslationContext()
t.buildannotator().build_types(fn, signature)
t.buildrtyper().specialize()
graph = graphof(t, fn)
if inline is not None:
from rpython.translator.backendopt.inline import auto_inline_graphs
auto_inline_graphs(t, t.graphs, inline)
if option.view:
t.view()
# to detect broken intermediate graphs,
# we do the loop ourselves instead of calling remove_simple_mallocs()
while True:
progress = remover.remove_mallocs_once(graph)
simplify.transform_dead_op_vars_in_blocks(list(graph.iterblocks()),
[graph])
if progress and option.view:
t.view()
if expected_result is not Ellipsis:
interp = LLInterpreter(t.rtyper)
res = interp.eval_graph(graph, args)
assert res == expected_result
if not progress:
break
if must_be_removed:
self.check_malloc_removed(graph)
return graph
示例6: check
# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import view [as 别名]
def check(self, fn, signature, args, expected_result, expected_mallocs=0, expected_calls=0):
t = TranslationContext()
self.translator = t
t.buildannotator().build_types(fn, signature)
t.buildrtyper().specialize()
graph = graphof(t, fn)
if option.view:
t.view()
self.original_graph_count = len(t.graphs)
# to detect broken intermediate graphs,
# we do the loop ourselves instead of calling remove_simple_mallocs()
maxiter = 100
mallocv = MallocVirtualizer(t.graphs, t.rtyper, verbose=True)
while True:
progress = mallocv.remove_mallocs_once()
if progress and option.view:
t.view()
t.checkgraphs()
if expected_result is not DONT_CHECK_RESULT:
interp = LLInterpreter(t.rtyper)
if not isinstance(expected_result, CHECK_RAISES):
res = interp.eval_graph(graph, args)
assert res == expected_result
else:
excinfo = py.test.raises(LLException, interp.eval_graph, graph, args)
assert expected_result.excname in str(excinfo.value)
if not progress:
break
maxiter -= 1
assert maxiter > 0, "infinite loop?"
self.check_malloc_removed(graph, expected_mallocs, expected_calls)
return graph
示例7: rtype
# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import view [as 别名]
def rtype(fn, signature):
t = TranslationContext()
t.buildannotator().build_types(fn, signature)
t.buildrtyper().specialize()
graph = graphof(t, fn)
if option.view:
t.view()
return t, graph
示例8: rtype
# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import view [as 别名]
def rtype(func, inputtypes, specialize=True):
t = TranslationContext()
t.buildannotator().build_types(func, inputtypes)
if specialize:
t.buildrtyper().specialize()
if option.view:
t.view()
return t
示例9: translate
# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import view [as 别名]
def translate(func, argtypes, backend_optimize=True):
t = TranslationContext()
t.buildannotator().build_types(func, argtypes)
t.buildrtyper().specialize()
if backend_optimize:
backend_optimizations(t)
if option.view:
t.view()
return graphof(t, func), t
示例10: gengraph
# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import view [as 别名]
def gengraph(f, args=[], viewBefore=False, viewAfter=False, mangle=True):
t = TranslationContext()
t.config.translation.ootype.mangle = mangle
t.buildannotator().build_types(f, args)
if viewBefore or option.view:
t.view()
t.buildrtyper(type_system="ootype").specialize()
if viewAfter or option.view:
t.view()
return graphof(t, f)
示例11: rtype
# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import view [as 别名]
def rtype(func, inputtypes, specialize=True):
t = TranslationContext()
t.buildannotator().build_types(func, inputtypes)
rtyper = t.buildrtyper()
rtyper.backend = llinterp_backend
if specialize:
rtyper.specialize()
if option.view:
t.view()
return t
示例12: get_graph
# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import view [as 别名]
def get_graph(fn, signature, all_opts=True):
t = TranslationContext()
t.buildannotator().build_types(fn, signature)
t.buildrtyper().specialize()
if all_opts:
backend_optimizations(t, inline_threshold=INLINE_THRESHOLD_FOR_TEST,
constfold=False)
graph = graphof(t, fn)
if option.view:
t.view()
return graph, t
示例13: translateopt
# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import view [as 别名]
def translateopt(self, func, sig, **optflags):
t = TranslationContext()
opts = {'translation.list_comprehension_operations': True}
t.config.set(**opts)
t.buildannotator().build_types(func, sig)
t.buildrtyper().specialize()
if option.view:
t.view()
backend_optimizations(t, **optflags)
if option.view:
t.view()
return t
示例14: specialize
# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import view [as 别名]
def specialize(self, func, argtypes):
from rpython.rtyper.llinterp import LLInterpreter
t = TranslationContext(list_comprehension_operations=True)
t.buildannotator().build_types(func, argtypes)
if option.view:
t.view()
t.buildrtyper().specialize()
backend_optimizations(t)
if option.view:
t.view()
graph = graphof(t, func)
interp = LLInterpreter(t.rtyper)
return interp, graph
示例15: analyze
# 需要导入模块: from rpython.translator.translator import TranslationContext [as 别名]
# 或者: from rpython.translator.translator.TranslationContext import view [as 别名]
def analyze(self, func, sig, func_to_analyze=None, backendopt=False):
if func_to_analyze is None:
func_to_analyze = func
t = TranslationContext()
t.buildannotator().build_types(func, sig)
t.buildrtyper().specialize()
if backendopt:
backend_optimizations(t)
if option.view:
t.view()
a = FinalizerAnalyzer(t)
fgraph = graphof(t, func_to_analyze)
result = a.analyze_light_finalizer(fgraph)
return result