Mercurial > lcfOS
comparison python/testgraph.py @ 279:2ccd57b1d78c
Fix register allocator to do burn2 OK
author | Windel Bouwman |
---|---|
date | Sat, 12 Oct 2013 09:56:23 +0200 |
parents | 9fca39eebe50 |
children | 02385f62f250 |
comparison
equal
deleted
inserted
replaced
278:9fca39eebe50 | 279:2ccd57b1d78c |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 import unittest | 3 import unittest |
4 import graph | 4 import graph |
5 import interferencegraph | |
6 import flowgraph | |
7 import ir | |
8 import irmach | |
9 | |
5 | 10 |
6 class GraphTestCase(unittest.TestCase): | 11 class GraphTestCase(unittest.TestCase): |
12 | |
7 def testEdge(self): | 13 def testEdge(self): |
8 g = graph.Graph() | 14 g = graph.Graph() |
9 n1 = graph.Node(g) | 15 n1 = graph.Node(g) |
10 g.addNode(n1) | 16 g.addNode(n1) |
11 n2 = graph.Node(g) | 17 n2 = graph.Node(g) |
29 self.assertEqual(2, n1.Degree) | 35 self.assertEqual(2, n1.Degree) |
30 self.assertEqual(1, n2.Degree) | 36 self.assertEqual(1, n2.Degree) |
31 g.delNode(n2) | 37 g.delNode(n2) |
32 self.assertEqual(1, n1.Degree) | 38 self.assertEqual(1, n1.Degree) |
33 | 39 |
40 | |
34 class DigraphTestCase(unittest.TestCase): | 41 class DigraphTestCase(unittest.TestCase): |
35 pass | 42 pass |
36 | 43 |
37 | 44 |
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 = [] | |
54 instrs.append(irmach.makeIns('ld %d', dst=[t1])) | |
55 instrs.append(irmach.makeIns('ld %d', dst=[t2])) | |
56 instrs.append(irmach.makeIns('ld %d', dst=[t3])) | |
57 cfg = flowgraph.FlowGraph(instrs) | |
58 ig = interferencegraph.InterferenceGraph(cfg) | |
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 = [] | |
66 instrs.append(irmach.makeIns('ld %d0', dst=[t1])) | |
67 instrs.append(irmach.makeIns('ld %d0', dst=[t2])) | |
68 instrs.append(irmach.makeIns('ld %d0', dst=[t3])) | |
69 instrs.append(irmach.makeIns('mov %d0, %s0', dst=[t4], src=[t3])) | |
70 instrs.append(irmach.makeIns('st %s0', src=[t4])) | |
71 instrs.append(irmach.makeIns('st %s0', src=[t1])) | |
72 instrs.append(irmach.makeIns('st %s0', src=[t2])) | |
73 cfg = flowgraph.FlowGraph(instrs) | |
74 ig = interferencegraph.InterferenceGraph(cfg) | |
75 ig.to_txt() | |
76 ig.Combine(ig.getNode(t4), ig.getNode(t3)) | |
77 self.assertIs(ig.getNode(t4), ig.getNode(t3)) | |
78 print('after') | |
79 ig.to_txt() | |
80 | |
81 | |
38 if __name__ == '__main__': | 82 if __name__ == '__main__': |
39 unittest.main() | 83 unittest.main() |
40 | 84 |