Mercurial > lcfOS
view python/testregalloc.py @ 279:2ccd57b1d78c
Fix register allocator to do burn2 OK
author | Windel Bouwman |
---|---|
date | Sat, 12 Oct 2013 09:56:23 +0200 |
parents | |
children | 02385f62f250 |
line wrap: on
line source
import unittest import os import sys import irmach import registerallocator import ir class RegAllocTestCase(unittest.TestCase): def setUp(self): self.ra = registerallocator.RegisterAllocator() def testRegAlloc(self): f = irmach.Frame('tst') f.regs = [1,2,3,4,5,6] # for test use numbers! f.tempMap = {} t1 = ir.Temp('t1') t2 = ir.Temp('t2') t3 = ir.Temp('t3') t4 = ir.Temp('t4') t5 = ir.Temp('t5') f.instructions.append(irmach.makeIns('ld %d0', dst=[t1])) f.instructions.append(irmach.makeIns('ld %d0', dst=[t2])) f.instructions.append(irmach.makeIns('ld %d0', dst=[t3])) f.instructions.append(irmach.makeIns('add %d0, %s0, %s1', dst=[t4], src=[t1, t2])) f.instructions.append(irmach.makeIns('add %d0, %s0, %s1', dst=[t5], src=[t4, t3])) f.instructions.append(irmach.makeIns('st %s0', src=[t5])) self.ra.allocFrame(f) self.conflict(t1, t2) self.conflict(t2, t3) def conflict(self, ta, tb): self.assertNotEqual(self.ra.Node(ta).color, self.ra.Node(tb).color) def testRegCoalesc(self): f = irmach.Frame('tst') f.regs = [1,2,3,4,5,6] # for test use numbers! f.tempMap = {} t1 = ir.Temp('t1') t2 = ir.Temp('t2') t3 = ir.Temp('t3') t4 = ir.Temp('t4') t5 = ir.Temp('t5') t6 = ir.Temp('t6') f.instructions.append(irmach.makeIns('ld %d0', dst=[t1])) f.instructions.append(irmach.makeIns('ld %d0', dst=[t2])) f.instructions.append(irmach.makeIns('ld %d0', dst=[t3])) f.instructions.append(irmach.makeIns('lsl %s0, %s1', dst=[t4], src=[t2, t1])) f.instructions.append(irmach.makeIns('mov %d0, %s0', dst=[t5], src=[t3])) f.instructions.append(irmach.makeIns('orr %s0, %s1', dst=[t5], src=[t4, t5])) f.instructions.append(irmach.makeIns('mov %d0, %s0', dst=[t6], src=[t5])) f.instructions.append(irmach.makeIns('st %s0', src=[t6])) self.ra.allocFrame(f) f.ig.to_txt() for i in f.instructions: print(i) self.conflict(t1, t2) self.conflict(t2, t3) self.conflict(t1, t3) if __name__ == '__main__': unittest.main()