comparison test/testregalloc.py @ 284:05184b95fa16

Moved tests to seperate folder
author Windel Bouwman
date Fri, 15 Nov 2013 13:43:22 +0100
parents python/testregalloc.py@02385f62f250
children 9417caea2eb3
comparison
equal deleted inserted replaced
283:c9781c73e7e2 284:05184b95fa16
1 import unittest
2 import os
3 import sys
4 from irmach import AbstractInstruction as makeIns, Frame
5 import registerallocator
6 import ir
7 from target import Nop
8
9
10 class RegAllocTestCase(unittest.TestCase):
11 def setUp(self):
12 self.ra = registerallocator.RegisterAllocator()
13
14 def testRegAlloc(self):
15 f = Frame('tst')
16 f.regs = [1,2,3,4,5,6] # for test use numbers!
17 f.tempMap = {}
18 t1 = ir.Temp('t1')
19 t2 = ir.Temp('t2')
20 t3 = ir.Temp('t3')
21 t4 = ir.Temp('t4')
22 t5 = ir.Temp('t5')
23 f.instructions.append(makeIns(Nop, dst=[t1]))
24 f.instructions.append(makeIns(Nop, dst=[t2]))
25 f.instructions.append(makeIns(Nop, dst=[t3]))
26 f.instructions.append(makeIns(Nop, dst=[t4], src=[t1, t2]))
27 f.instructions.append(makeIns(Nop, dst=[t5], src=[t4, t3]))
28 f.instructions.append(makeIns(Nop, src=[t5]))
29 self.ra.allocFrame(f)
30 self.conflict(t1, t2)
31 self.conflict(t2, t3)
32
33 def conflict(self, ta, tb):
34 self.assertNotEqual(self.ra.Node(ta).color, self.ra.Node(tb).color)
35
36 def testRegCoalesc(self):
37 f = Frame('tst')
38 f.regs = [1,2,3,4,5,6] # for test use numbers!
39 f.tempMap = {}
40 t1 = ir.Temp('t1')
41 t2 = ir.Temp('t2')
42 t3 = ir.Temp('t3')
43 t4 = ir.Temp('t4')
44 t5 = ir.Temp('t5')
45 t6 = ir.Temp('t6')
46 f.instructions.append(makeIns(Nop, dst=[t1]))
47 f.instructions.append(makeIns(Nop, dst=[t2]))
48 f.instructions.append(makeIns(Nop, dst=[t3]))
49 f.instructions.append(makeIns(Nop, dst=[t4], src=[t2, t1]))
50 f.instructions.append(makeIns(Nop, dst=[t5], src=[t3]))
51 f.instructions.append(makeIns(Nop, dst=[t5], src=[t4, t5]))
52 f.instructions.append(makeIns(Nop, dst=[t6], src=[t5]))
53 f.instructions.append(makeIns(Nop, src=[t6]))
54 self.ra.allocFrame(f)
55 self.conflict(t1, t2)
56 self.conflict(t2, t3)
57 self.conflict(t1, t3)
58
59 if __name__ == '__main__':
60 unittest.main()
61