Mercurial > lcfOS
annotate test/testgraph.py @ 320:84d67cce67b7
Working burg
author | Windel Bouwman |
---|---|
date | Sun, 19 Jan 2014 16:09:44 +0100 |
parents | 6753763d3bec |
children | e9fe6988497c |
rev | line source |
---|---|
277 | 1 #!/usr/bin/python |
2 | |
3 import unittest | |
301 | 4 from ppci.codegen.graph import Graph, Node |
5 from ppci.codegen.interferencegraph import InterferenceGraph | |
6 from ppci.codegen.flowgraph import FlowGraph | |
7 from ppci import ir | |
8 from ppci.irmach import AbstractInstruction as AI | |
280
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
9 from target import Nop |
279 | 10 |
277 | 11 |
12 class GraphTestCase(unittest.TestCase): | |
13 def testEdge(self): | |
296 | 14 g = Graph() |
15 n1 = Node(g) | |
278
9fca39eebe50
First implementation of regalloc with coalsesc
Windel Bouwman
parents:
277
diff
changeset
|
16 g.addNode(n1) |
296 | 17 n2 = Node(g) |
278
9fca39eebe50
First implementation of regalloc with coalsesc
Windel Bouwman
parents:
277
diff
changeset
|
18 g.addNode(n2) |
277 | 19 g.addEdge(n1, n2) |
20 self.assertTrue(g.hasEdge(n2, n1)) | |
21 self.assertTrue(g.hasEdge(n1, n2)) | |
22 g.delNode(n1) | |
23 g.delNode(n2) | |
24 | |
25 def testDegree(self): | |
296 | 26 g = Graph() |
27 n1 = Node(g) | |
278
9fca39eebe50
First implementation of regalloc with coalsesc
Windel Bouwman
parents:
277
diff
changeset
|
28 g.addNode(n1) |
296 | 29 n2 = Node(g) |
278
9fca39eebe50
First implementation of regalloc with coalsesc
Windel Bouwman
parents:
277
diff
changeset
|
30 g.addNode(n2) |
296 | 31 n3 = Node(g) |
278
9fca39eebe50
First implementation of regalloc with coalsesc
Windel Bouwman
parents:
277
diff
changeset
|
32 g.addNode(n3) |
277 | 33 g.addEdge(n1, n2) |
34 g.addEdge(n1, n3) | |
35 self.assertEqual(2, n1.Degree) | |
36 self.assertEqual(1, n2.Degree) | |
37 g.delNode(n2) | |
38 self.assertEqual(1, n1.Degree) | |
39 | |
279 | 40 |
277 | 41 class DigraphTestCase(unittest.TestCase): |
42 pass | |
290 | 43 |
277 | 44 |
279 | 45 class InterferenceGraphTestCase(unittest.TestCase): |
46 def testNormalUse(self): | |
47 t1 = ir.Temp('t1') | |
48 t2 = ir.Temp('t2') | |
49 t3 = ir.Temp('t3') | |
50 t4 = ir.Temp('t4') | |
51 t5 = ir.Temp('t5') | |
52 t6 = ir.Temp('t6') | |
53 instrs = [] | |
280
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
54 instrs.append(AI(Nop, dst=[t1])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
55 instrs.append(AI(Nop, dst=[t2])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
56 instrs.append(AI(Nop, dst=[t3])) |
296 | 57 cfg = FlowGraph(instrs) |
58 ig = InterferenceGraph(cfg) | |
279 | 59 |
60 def testCombine(self): | |
61 t1 = ir.Temp('t1') | |
62 t2 = ir.Temp('t2') | |
63 t3 = ir.Temp('t3') | |
64 t4 = ir.Temp('t4') | |
65 instrs = [] | |
280
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
66 instrs.append(AI(Nop, dst=[t1])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
67 instrs.append(AI(Nop, dst=[t2])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
68 instrs.append(AI(Nop, dst=[t3])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
69 instrs.append(AI(Nop, dst=[t4], src=[t3])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
70 instrs.append(AI(Nop, src=[t4])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
71 instrs.append(AI(Nop, src=[t1])) |
02385f62f250
Rework from str interface to Instruction interface
Windel Bouwman
parents:
279
diff
changeset
|
72 instrs.append(AI(Nop, src=[t2])) |
296 | 73 cfg = FlowGraph(instrs) |
74 ig = InterferenceGraph(cfg) | |
279 | 75 ig.Combine(ig.getNode(t4), ig.getNode(t3)) |
76 self.assertIs(ig.getNode(t4), ig.getNode(t3)) | |
77 | |
78 | |
277 | 79 if __name__ == '__main__': |
80 unittest.main() |