view python/testcg.py @ 254:bd26dc13f270

Added logger
author Windel Bouwman
date Wed, 31 Jul 2013 21:20:58 +0200
parents ef683881c64e
children 5ec7580976d9
line wrap: on
line source

import unittest
import ppci, codegen, ir
import cortexm3 as arm
import codegenarm
import outstream

def genTestFunction():
    m = ir.Module('tst')
    f = ir.Function('tst')
    m.addFunction(f)
    bb = ir.BasicBlock('entry')
    f.addBasicBlock(bb)
    return m, bb


class testCodeGeneration(unittest.TestCase):
    def setUp(self):
        self.cg = codegen.CodeGenerator(arm.armtarget)

    def testFunction(self):
        m, bb = genTestFunction()
        v = ir.Value('tst')
        bb.addInstruction(ir.ImmLoad(v, 123))
        m.check()
        obj = self.cg.generate(m)
        self.assertTrue(obj)


class testArmCodeGeneration(unittest.TestCase):
    def testStack(self):
        s = outstream.OutputStream()
        cg = codegenarm.ArmCodeGenerator(s)
        m, bb = genTestFunction()
        v = ir.Value('tst')
        bb.addInstruction(ir.Alloc(v))
        v2 = ir.Value('tst2')
        bb.addInstruction(ir.ImmLoad(v2, 22))
        bb.addInstruction(ir.Store(v, v2))
        m.check()
        cg.generate(m)
        #s.dump()

if __name__ == '__main__':
    unittest.main()