예제 #1
0
파일: test_cfa.py 프로젝트: flypy/pykit
    def test_cfg(self):
        mod = from_c(source)
        f = mod.get_function('func_simple')
        verify(f)
        flow = cfa.cfg(f)

        cond_block = findop(f, 'cbranch').block
        self.assertEqual(len(flow[cond_block]), 2)
예제 #2
0
파일: test_cfa.py 프로젝트: inaimathi/pykit
    def test_cfg(self):
        mod = from_c(source)
        f = mod.get_function('func_simple')
        verify(f)
        flow = cfa.cfg(f)

        cond_block = findop(f, 'cbranch').block
        self.assertEqual(len(flow[cond_block]), 2)
예제 #3
0
파일: builder.py 프로젝트: flypy/pykit
 def _find_handler(self, exc, exc_setup):
     """
     Given an exception and an exception setup clause, generate
     exc_matches() checks
     """
     catch_sites = [findop(block, 'exc_catch') for block in exc_setup.args]
     for exc_catch in catch_sites:
         for exc_type in exc_catch.args:
             with self.if_(self.exc_matches(types.Bool, [exc, exc_type])):
                 self.jump(exc_catch.block)
                 block = self._curblock
             self.position_at_end(block)
예제 #4
0
파일: builder.py 프로젝트: YusufCakan/pykit
 def _find_handler(self, exc, exc_setup):
     """
     Given an exception and an exception setup clause, generate
     exc_matches() checks
     """
     catch_sites = [findop(block, 'exc_catch') for block in exc_setup.args]
     for exc_catch in catch_sites:
         for exc_type in exc_catch.args:
             with self.if_(self.exc_matches(types.Bool, [exc, exc_type])):
                 self.jump(exc_catch.block)
                 block = self._curblock
             self.position_at_end(block)
예제 #5
0
    def test_loop(self):
        def loop(a, b):
            result = a
            while a > b:
                result = b
            return result

        f, context, signature = get(loop, [int32, int32])
        self.assertEqual(signature, Function[int32, int32, int32])

        # TODO: Make blaze unit types instantiations of generic type constructors
        type = context[findop(f, 'call')]
        type = resolve(type, globals(), {})
예제 #6
0
    def test_loop(self):
        def loop(a, b):
            result = a
            while a > b:
                result = b
            return result

        f, context, signature = get(loop, [int32, int32])
        self.assertEqual(signature, Function[int32, int32, int32])

        # TODO: Make blaze unit types instantiations of generic type constructors
        type = context[findop(f, 'call')]
        type = resolve(type, globals(), {})
예제 #7
0
파일: builder.py 프로젝트: flypy/pykit
    def gen_error_propagation(self, exc=None):
        """
        Propagate an exception. If `exc` is not given it will be loaded
        to match in 'except' clauses.
        """
        assert self._curblock

        block = self._curblock
        exc_setup = findop(block.leaders, 'exc_setup')
        if exc_setup:
            exc = exc or self.load_tl_exc(types.Exception)
            self._find_handler(exc, exc_setup)
        else:
            self.gen_ret_undef()
예제 #8
0
파일: builder.py 프로젝트: YusufCakan/pykit
    def gen_error_propagation(self, exc=None):
        """
        Propagate an exception. If `exc` is not given it will be loaded
        to match in 'except' clauses.
        """
        assert self._curblock

        block = self._curblock
        exc_setup = findop(block.leaders, 'exc_setup')
        if exc_setup:
            exc = exc or self.load_tl_exc(types.Exception)
            self._find_handler(exc, exc_setup)
        else:
            self.gen_ret_undef()
예제 #9
0
파일: test_cfa.py 프로젝트: inaimathi/pykit
    def test_ssa(self):
        mod = from_c(source)
        f = mod.get_function('func_simple')
        verify(f)
        self.assertEqual(opcodes(f.startblock),
                         ['alloca', 'store', 'load', 'gt', 'cbranch'])

        # SSA
        CFG = cfa.cfg(f)
        cfa.ssa(f, CFG)

        assert len(f.blocks) == 4
        blocks = list(f.blocks)
        self.assertEqual(opcodes(blocks[0]), ['gt', 'cbranch'])
        self.assertEqual(opcodes(blocks[1]), ['jump'])
        self.assertEqual(opcodes(blocks[2]), ['jump'])
        self.assertEqual(opcodes(blocks[3]), ['phi', 'ret'])

        phi = findop(f, 'phi')
        iblocks, ivals = phi.args
        self.assertEqual(sorted(iblocks), sorted([blocks[1], blocks[2]]))
        self.assertEqual(len(ivals), 2)
예제 #10
0
파일: test_cfa.py 프로젝트: flypy/pykit
    def test_ssa(self):
        mod = from_c(source)
        f = mod.get_function('func_simple')
        verify(f)
        self.assertEqual(opcodes(f.startblock),
                         ['alloca', 'store', 'load', 'gt', 'cbranch'])

        # SSA
        CFG = cfa.cfg(f)
        cfa.ssa(f, CFG)

        assert len(f.blocks) == 4
        blocks = list(f.blocks)
        self.assertEqual(opcodes(blocks[0]), ['gt', 'cbranch'])
        self.assertEqual(opcodes(blocks[1]), ['jump'])
        self.assertEqual(opcodes(blocks[2]), ['jump'])
        self.assertEqual(opcodes(blocks[3]), ['phi', 'convert', 'ret'])

        phi = findop(f, 'phi')
        iblocks, ivals = phi.args
        self.assertEqual(sorted(iblocks), sorted([blocks[1], blocks[2]]))
        self.assertEqual(len(ivals), 2)