def testEmpty(self): function = FunctionDecl(void_type, 'f', [], Block([])) cfg = CFG('f') cfg.connect(cfg.entry, cfg.exit) function.cfg = cfg program = Program([function]) lines = self.assertSuccess(program) self.assertEquals(lines, [Label('f', public=True), Label('f$exit', public=True)])
def testInfiniteLoop(self): function = FunctionDecl(void_type, 'f', [], Block([])) cfg = CFG('f') node = cfg.add(Operation(42)) cfg.connect(cfg.entry, node, node) function.cfg = cfg program = Program([function]) lines = self.assertSuccess(program) self.assertEquals(lines, [Label('f', public=True), Label(2), Instruction(42), Jump(2), Label('f$exit', public=True)])
def testEmpty(self): function = FunctionDecl(void_type, 'f', [], Block([])) cfg = CFG('f') cfg.connect(cfg.entry, cfg.exit) function.cfg = cfg program = Program([function]) lines = self.assertSuccess(program) self.assertEquals( lines, [Label('f', public=True), Label('f$exit', public=True)])
def testOneStatement(self): function = FunctionDecl(void_type, 'f', [], Block([])) cfg = CFG('f') stmt = cfg.add(Operation(42)) cfg.connect(cfg.entry, stmt) cfg.connect(stmt, cfg.exit) function.cfg = cfg program = Program([function]) lines = self.assertSuccess(program) self.assertEquals(lines, [Label('f', public=True), Instruction(42), Label('f$exit', public=True)])
def testOneStatement(self): function = FunctionDecl(void_type, 'f', [], Block([])) cfg = CFG('f') stmt = cfg.add(Operation(42)) cfg.connect(cfg.entry, stmt) cfg.connect(stmt, cfg.exit) function.cfg = cfg program = Program([function]) lines = self.assertSuccess(program) self.assertEquals(lines, [ Label('f', public=True), Instruction(42), Label('f$exit', public=True) ])
def testInfiniteLoop(self): function = FunctionDecl(void_type, 'f', [], Block([])) cfg = CFG('f') node = cfg.add(Operation(42)) cfg.connect(cfg.entry, node, node) function.cfg = cfg program = Program([function]) lines = self.assertSuccess(program) self.assertEquals(lines, [ Label('f', public=True), Label(2), Instruction(42), Jump(2), Label('f$exit', public=True) ])
def testTest(self): function = FunctionDecl(void_type, 'f', [], Block([])) cfg = CFG('f') test_node = cfg.add(Test(42)) cfg.connect(cfg.entry, test_node) true_node = cfg.add(Operation(100)) cfg.connect(test_node, TrueEdge(), true_node, cfg.exit) false_node = cfg.add(Operation(200)) cfg.connect(test_node, FalseEdge(), false_node, cfg.exit) function.cfg = cfg program = Program([function]) lines = self.assertSuccess(program) self.assertEquals(lines, [Label('f', public=True), Branch(42, 3), Label(4), Instruction(200), Jump('f$exit'), Label(3), Instruction(100), Label('f$exit', public=True)])
def testTest(self): function = FunctionDecl(void_type, 'f', [], Block([])) cfg = CFG('f') test_node = cfg.add(Test(42)) cfg.connect(cfg.entry, test_node) true_node = cfg.add(Operation(100)) cfg.connect(test_node, TrueEdge(), true_node, cfg.exit) false_node = cfg.add(Operation(200)) cfg.connect(test_node, FalseEdge(), false_node, cfg.exit) function.cfg = cfg program = Program([function]) lines = self.assertSuccess(program) self.assertEquals(lines, [ Label('f', public=True), Branch(42, 3), Label(4), Instruction(200), Jump('f$exit'), Label(3), Instruction(100), Label('f$exit', public=True) ])