本文整理汇总了Python中pypy.translator.simplify.simplify_graph函数的典型用法代码示例。如果您正苦于以下问题:Python simplify_graph函数的具体用法?Python simplify_graph怎么用?Python simplify_graph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了simplify_graph函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: insert_resume_handling
def insert_resume_handling(self, graph):
old_start_block = graph.startblock
newinputargs = [unsimplify.copyvar(self.translator.annotator, v)
for v in old_start_block.inputargs]
new_start_block = model.Block(newinputargs)
v_resume_substate = varoftype(lltype.Signed)
new_start_block.operations.append(
model.SpaceOperation("getfield",
[self.ll_global_state,
self.c_restart_substate_name],
v_resume_substate))
not_resuming_link = model.Link(newinputargs, old_start_block, -1)
not_resuming_link.llexitcase = -1
resuming_links = []
for resume_index, resume_block in enumerate(self.resume_blocks):
resuming_links.append(
model.Link([v_resume_substate], resume_block, resume_index))
resuming_links[-1].llexitcase = resume_index
new_start_block.exitswitch = v_resume_substate
new_start_block.closeblock(not_resuming_link, *resuming_links)
old_start_block.isstartblock = False
new_start_block.isstartblock = True
graph.startblock = new_start_block
for block in graph.iterblocks():
if len(block.exits) == 1 and block.exitswitch is not None:
block.exitswitch = None
block.exits[0].exitcase = block.exits[0].llexitcase = None
simplify.simplify_graph(graph, [simplify.eliminate_empty_blocks,
simplify.join_blocks,
simplify.transform_dead_op_vars])
示例2: buildflowgraph
def buildflowgraph(self, func, mute_dot=False):
"""Get the flow graph for a function."""
if not isinstance(func, types.FunctionType):
raise TypeError("buildflowgraph() expects a function, "
"got %r" % (func,))
if func in self._prebuilt_graphs:
graph = self._prebuilt_graphs.pop(func)
else:
if self.config.translation.verbose:
log.start(nice_repr_for_func(func))
space = FlowObjSpace(self.flowconfig)
if self.annotator:
# ZZZ
self.annotator.policy._adjust_space_config(space)
elif hasattr(self, 'no_annotator_but_do_imports_immediately'):
space.do_imports_immediately = (
self.no_annotator_but_do_imports_immediately)
graph = space.build_flow(func)
if self.config.translation.simplifying:
simplify.simplify_graph(graph)
if self.config.translation.list_comprehension_operations:
simplify.detect_list_comprehension(graph)
if self.config.translation.verbose:
log.done(func.__name__)
elif not mute_dot:
log.dot()
self.graphs.append(graph) # store the graph in our list
return graph
示例3: test_implicitAttributeError
def test_implicitAttributeError(self):
x = self.codetest(self.implicitAttributeError)
simplify_graph(x)
self.show(x)
def cannot_reach_exceptblock(link):
if isinstance(link, Link):
assert link.target is not x.exceptblock
traverse(cannot_reach_exceptblock, x)
示例4: test_implicitException_os_stat
def test_implicitException_os_stat(self):
x = self.codetest(self.implicitException_os_stat)
simplify_graph(x)
self.show(x)
assert len(x.startblock.exits) == 3
d = {}
for link in x.startblock.exits:
d[link.exitcase] = True
assert d == {None: True, OSError: True, Exception: True}
示例5: test_reraiseAnything
def test_reraiseAnything(self):
x = self.codetest(self.reraiseAnything)
simplify_graph(x)
self.show(x)
found = {}
for link in x.iterlinks():
if link.target is x.exceptblock:
assert isinstance(link.args[0], Constant)
found[link.args[0].value] = True
assert found == {ValueError: True, ZeroDivisionError: True, OverflowError: True}
示例6: test_multiple_catch_simple_call
def test_multiple_catch_simple_call(self):
graph = self.codetest(self.multiple_catch_simple_call)
simplify_graph(graph)
assert self.all_operations(graph) == {"simple_call": 1}
entrymap = mkentrymap(graph)
links = entrymap[graph.returnblock]
assert len(links) == 3
assert dict.fromkeys([link.exitcase for link in links]) == dict.fromkeys([None, IndexError, OSError])
links = entrymap[graph.exceptblock]
assert len(links) == 1
assert links[0].exitcase is Exception
示例7: test_reraiseTypeError
def test_reraiseTypeError(self):
x = self.codetest(self.reraiseTypeError)
simplify_graph(x)
self.show(x)
found = []
def can_reach_exceptblock(link):
if isinstance(link, Link):
if link.target is x.exceptblock:
found.append(link)
traverse(can_reach_exceptblock, x)
assert found
示例8: test_unicode
def test_unicode(self):
def myfunc(n):
try:
return unicode(chr(n))
except UnicodeDecodeError:
return None
graph = self.codetest(myfunc)
simplify_graph(graph)
assert graph.startblock.exitswitch == c_last_exception
assert graph.startblock.exits[0].target is graph.returnblock
assert graph.startblock.exits[1].target is graph.returnblock
示例9: test_reraiseAnythingDicCase
def test_reraiseAnythingDicCase(self):
x = self.codetest(self.reraiseAnythingDicCase)
simplify_graph(x)
self.show(x)
found = {}
for link in x.iterlinks():
if link.target is x.exceptblock:
if isinstance(link.args[0], Constant):
found[link.args[0].value] = True
else:
found[link.exitcase] = None
assert found == {IndexError: True, KeyError: True, Exception: None}
示例10: test_raise1
def test_raise1(self):
x = self.codetest(self.raise1)
simplify_graph(x)
self.show(x)
ops = x.startblock.operations
assert len(ops) == 2
assert ops[0].opname == 'simple_call'
assert ops[0].args == [Constant(IndexError)]
assert ops[1].opname == 'type'
assert ops[1].args == [ops[0].result]
assert x.startblock.exits[0].args == [ops[1].result, ops[0].result]
assert x.startblock.exits[0].target is x.exceptblock
示例11: test_catch_importerror_2
def test_catch_importerror_2(self):
def f():
try:
from pypy import this_does_not_exist
except ImportError:
return 1
graph = self.codetest(f)
simplify_graph(graph)
self.show(graph)
assert not graph.startblock.operations
assert len(graph.startblock.exits) == 1
assert graph.startblock.exits[0].target is graph.returnblock
示例12: test_reraiseAnything
def test_reraiseAnything(self):
x = self.codetest(self.reraiseAnything)
simplify_graph(x)
self.show(x)
found = {}
def find_exceptions(link):
if isinstance(link, Link):
if link.target is x.exceptblock:
assert isinstance(link.args[0], Constant)
found[link.args[0].value] = True
traverse(find_exceptions, x)
assert found == {ValueError: True, ZeroDivisionError: True, OverflowError: True}
示例13: test_reraiseAttributeError
def test_reraiseAttributeError(self):
x = self.codetest(self.reraiseAttributeError)
simplify_graph(x)
self.show(x)
found_AttributeError = []
def only_raise_AttributeError(link):
if isinstance(link, Link):
if link.target is x.exceptblock:
assert link.args[0] == Constant(AttributeError)
found_AttributeError.append(link)
traverse(only_raise_AttributeError, x)
assert found_AttributeError
示例14: test_reraiseAttributeError
def test_reraiseAttributeError(self):
x = self.codetest(self.reraiseAttributeError)
simplify_graph(x)
self.show(x)
excfound = []
for link in x.iterlinks():
if link.target is x.exceptblock:
excfound.append(link.exitcase)
assert len(excfound) == 2
excfound.sort()
expected = [Exception, AttributeError]
expected.sort()
assert excfound == expected
示例15: test_reraiseTypeError
def test_reraiseTypeError(self):
x = self.codetest(self.reraiseTypeError)
simplify_graph(x)
self.show(x)
excfound = []
def check(link):
if isinstance(link, Link):
if link.target is x.exceptblock:
excfound.append(link.exitcase)
traverse(check, x)
assert len(excfound) == 2
excfound.sort()
expected = [Exception, TypeError]
expected.sort()
assert excfound == expected