Esempio n. 1
0
def test_simple_loop():
    def snippet_fn(x, y):
        while y > 0:
            y -= x
        return y
    t = TranslationContext()
    graph = t.buildflowgraph(snippet_fn)
    if option.view:
        t.view()
    loops = find_inner_loops(graph)
    assert len(loops) == 1
    loop = loops[0]
    assert loop.headblock.operations[0].opname == 'gt'
    assert len(loop.links) == 2
    assert loop.links[0] in loop.headblock.exits
    assert loop.links[1] in loop.links[0].target.exits
    assert loop.links[1].target is loop.headblock
Esempio n. 2
0
 def implementation_begin(self):
     self.oldgraph = self.graph
     self.graph = self.patch_graph(copy_graph=True)
     SSI_to_SSA(self.graph)
     self.collect_var_and_types()
     self.blocknum = {}
     for block in self.graph.iterblocks():
         self.blocknum[block] = len(self.blocknum)
     db = self.db
     lltypes = identity_dict()
     for v in self.vars:
         T = getattr(v, 'concretetype', PyObjPtr)
         typename = db.gettype(T)
         lltypes[v] = T, typename
     self.illtypes = lltypes
     self.innerloops = {}    # maps the loop's header block to a Loop()
     for loop in find_inner_loops(self.graph, Bool):
         self.innerloops[loop.headblock] = loop
Esempio n. 3
0
 def implementation_begin(self):
     self.oldgraph = self.graph
     self.graph = self.patch_graph(copy_graph=True)
     SSI_to_SSA(self.graph)
     self.collect_var_and_types()
     self.blocknum = {}
     for block in self.graph.iterblocks():
         self.blocknum[block] = len(self.blocknum)
     db = self.db
     lltypes = identity_dict()
     for v in self.vars:
         T = getattr(v, 'concretetype', PyObjPtr)
         typename = db.gettype(T)
         lltypes[v] = T, typename
     self.illtypes = lltypes
     self.innerloops = {}    # maps the loop's header block to a Loop()
     for loop in find_inner_loops(self.graph, Bool):
         self.innerloops[loop.headblock] = loop
Esempio n. 4
0
def test_simple_loop():
    def snippet_fn(x, y):
        while y > 0:
            y -= x
        return y

    t = TranslationContext()
    graph = t.buildflowgraph(snippet_fn)
    if option.view:
        t.view()
    loops = find_inner_loops(graph)
    assert len(loops) == 1
    loop = loops[0]
    assert loop.headblock.operations[0].opname == 'gt'
    assert len(loop.links) == 2
    assert loop.links[0] in loop.headblock.exits
    assert loop.links[1] in loop.links[0].target.exits
    assert loop.links[1].target is loop.headblock
Esempio n. 5
0
def test_nested_loops():
    def snippet_fn(x, z):
        y = 0
        while y <= 10:
            while z < y:
                z += y
            y += 1
        return z
    t = TranslationContext()
    graph = t.buildflowgraph(snippet_fn)
    if option.view:
        t.view()
    loops = find_inner_loops(graph)
    assert len(loops) == 1
    loop = loops[0]
    assert loop.headblock.operations[0].opname == 'lt'
    assert len(loop.links) == 2
    assert loop.links[0] in loop.headblock.exits
    assert loop.links[1] in loop.links[0].target.exits
    assert loop.links[1].target is loop.headblock
Esempio n. 6
0
def test_two_loops():
    def snippet_fn(x, y):
        while y > 0:
            y -= x
        while y < 0:
            y += x
        return y
    t = TranslationContext()
    graph = t.buildflowgraph(snippet_fn)
    if option.view:
        t.view()
    loops = find_inner_loops(graph)
    assert len(loops) == 2
    assert loops[0].headblock is not loops[1].headblock
    for loop in loops:
        assert loop.headblock.operations[0].opname in ('gt', 'lt')
        assert len(loop.links) == 2
        assert loop.links[0] in loop.headblock.exits
        assert loop.links[1] in loop.links[0].target.exits
        assert loop.links[1].target is loop.headblock
Esempio n. 7
0
def test_nested_loops():
    def snippet_fn(x, z):
        y = 0
        while y <= 10:
            while z < y:
                z += y
            y += 1
        return z

    t = TranslationContext()
    graph = t.buildflowgraph(snippet_fn)
    if option.view:
        t.view()
    loops = find_inner_loops(graph)
    assert len(loops) == 1
    loop = loops[0]
    assert loop.headblock.operations[0].opname == 'lt'
    assert len(loop.links) == 2
    assert loop.links[0] in loop.headblock.exits
    assert loop.links[1] in loop.links[0].target.exits
    assert loop.links[1].target is loop.headblock
Esempio n. 8
0
def test_two_loops():
    def snippet_fn(x, y):
        while y > 0:
            y -= x
        while y < 0:
            y += x
        return y

    t = TranslationContext()
    graph = t.buildflowgraph(snippet_fn)
    if option.view:
        t.view()
    loops = find_inner_loops(graph)
    assert len(loops) == 2
    assert loops[0].headblock is not loops[1].headblock
    for loop in loops:
        assert loop.headblock.operations[0].opname in ('gt', 'lt')
        assert len(loop.links) == 2
        assert loop.links[0] in loop.headblock.exits
        assert loop.links[1] in loop.links[0].target.exits
        assert loop.links[1].target is loop.headblock