Exemplo n.º 1
0
 def visit_FunctionDecl(self, func):
     cfg = CFG(func.name)
     func.cfg = cfg
     
     if hasattr(func, 'symbol_table'):
         cfg.symbol_table = SymbolTable(func.symbol_table.parent)
         cfg.symbol_table.embed(func.symbol_table)
     else:
         cfg.symbol_table = SymbolTable()
     
     prev_node = self.visit(func.body, cfg=cfg, entry=cfg.entry, exit=cfg.exit)
     if prev_node is not None:
         cfg.connect(prev_node, cfg.exit)
Exemplo n.º 2
0
 def testOut(self):
     function = FunctionDecl(void_type, 'f', [], Block([]))
     cfg = CFG('f')
     n5 = Numeral(5)
     n5.type = int_type
     n1 = Numeral(1)
     n1.type = int_type
     stmt = Operation(FunctionCall(Name('__out__'), [n5, n1]))
     cfg.connect(cfg.entry, stmt, cfg.exit)
     function.cfg = cfg
     function.symbol_table = SymbolTable()
     cfg.symbol_table = SymbolTable(function.symbol_table)
     program = Program([function])
     self.assertSuccess(program)
     self.assertTrue(
         function.cfg.has_path(
             function.cfg.entry,
             Operation(BinaryOperation([Name('$t0'), '=',
                                        Numeral(5)])),
             Operation(BinaryOperation([Name('$t1'), '=',
                                        Numeral(1)])),
             Operation(
                 FunctionCall(Name('__out__'),
                              [Name('$t0'), Name('$t1')])),
             function.cfg.exit))
Exemplo n.º 3
0
    def visit_FunctionDecl(self, func):
        cfg = CFG(func.name)
        func.cfg = cfg

        if hasattr(func, 'symbol_table'):
            cfg.symbol_table = SymbolTable(func.symbol_table.parent)
            cfg.symbol_table.embed(func.symbol_table)
        else:
            cfg.symbol_table = SymbolTable()

        prev_node = self.visit(func.body,
                               cfg=cfg,
                               entry=cfg.entry,
                               exit=cfg.exit)
        if prev_node is not None:
            cfg.connect(prev_node, cfg.exit)
Exemplo n.º 4
0
 def testOut(self):
     function = FunctionDecl(void_type, 'f', [], Block([]))
     cfg = CFG('f')
     n5 = Numeral(5)
     n5.type = int_type
     n1 = Numeral(1)
     n1.type = int_type
     stmt = Operation(FunctionCall(Name('__out__'), [n5, n1]))
     cfg.connect(cfg.entry, stmt, cfg.exit)
     function.cfg = cfg
     function.symbol_table = SymbolTable()
     cfg.symbol_table = SymbolTable(function.symbol_table)
     program = Program([function])
     self.assertSuccess(program)
     self.assertTrue(function.cfg.has_path(function.cfg.entry,
         Operation(BinaryOperation([Name('$t0'), '=', Numeral(5)])),
         Operation(BinaryOperation([Name('$t1'), '=', Numeral(1)])),
         Operation(FunctionCall(Name('__out__'), [Name('$t0'), Name('$t1')])),
         function.cfg.exit))