Exemplo n.º 1
0
 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)])
Exemplo n.º 2
0
 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)])
Exemplo n.º 3
0
 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)])
Exemplo n.º 4
0
 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)])
Exemplo n.º 5
0
 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)
     ])
Exemplo n.º 6
0
 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)
     ])
Exemplo n.º 7
0
 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)])
Exemplo n.º 8
0
 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)
     ])