Mercurial > lcfOS
diff 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 |
line wrap: on
line diff
--- a/python/testgraph.py Sun Sep 29 14:08:15 2013 +0200 +++ b/python/testgraph.py Sat Oct 12 09:56:23 2013 +0200 @@ -2,8 +2,14 @@ import unittest import graph +import interferencegraph +import flowgraph +import ir +import irmach + class GraphTestCase(unittest.TestCase): + def testEdge(self): g = graph.Graph() n1 = graph.Node(g) @@ -31,10 +37,48 @@ g.delNode(n2) self.assertEqual(1, n1.Degree) + class DigraphTestCase(unittest.TestCase): pass +class InterferenceGraphTestCase(unittest.TestCase): + def testNormalUse(self): + t1 = ir.Temp('t1') + t2 = ir.Temp('t2') + t3 = ir.Temp('t3') + t4 = ir.Temp('t4') + t5 = ir.Temp('t5') + t6 = ir.Temp('t6') + instrs = [] + instrs.append(irmach.makeIns('ld %d', dst=[t1])) + instrs.append(irmach.makeIns('ld %d', dst=[t2])) + instrs.append(irmach.makeIns('ld %d', dst=[t3])) + cfg = flowgraph.FlowGraph(instrs) + ig = interferencegraph.InterferenceGraph(cfg) + + def testCombine(self): + t1 = ir.Temp('t1') + t2 = ir.Temp('t2') + t3 = ir.Temp('t3') + t4 = ir.Temp('t4') + instrs = [] + instrs.append(irmach.makeIns('ld %d0', dst=[t1])) + instrs.append(irmach.makeIns('ld %d0', dst=[t2])) + instrs.append(irmach.makeIns('ld %d0', dst=[t3])) + instrs.append(irmach.makeIns('mov %d0, %s0', dst=[t4], src=[t3])) + instrs.append(irmach.makeIns('st %s0', src=[t4])) + instrs.append(irmach.makeIns('st %s0', src=[t1])) + instrs.append(irmach.makeIns('st %s0', src=[t2])) + cfg = flowgraph.FlowGraph(instrs) + ig = interferencegraph.InterferenceGraph(cfg) + ig.to_txt() + ig.Combine(ig.getNode(t4), ig.getNode(t3)) + self.assertIs(ig.getNode(t4), ig.getNode(t3)) + print('after') + ig.to_txt() + + if __name__ == '__main__': unittest.main()