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, break_target=None) if prev_node is not None: cfg.connect(prev_node, cfg.exit) cfg.remove_pass_nodes()
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(AssignStatement(Name('$t0'), Numeral(5))), Operation(AssignStatement(Name('$t1'), Numeral(1))), Operation(FunctionCall(Name('__out__'), [Name('$t0'), Name('$t1')])), function.cfg.exit))
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(AssignStatement(Name("$t0"), Numeral(5))), Operation(AssignStatement(Name("$t1"), Numeral(1))), Operation(FunctionCall(Name("__out__"), [Name("$t0"), Name("$t1")])), function.cfg.exit, ) )