view python/testcg.py @ 271:cf7d5fb7d9c8

Reorganization
author Windel Bouwman
date Tue, 20 Aug 2013 18:56:02 +0200
parents 5ec7580976d9
children e64bae57cda8
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)
    return m, f.entry


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

    def testFunction(self):
        m, bb = genTestFunction()
        bb.addInstruction(ir.Const(123))
        bb.addInstruction(ir.Return(ir.Const(0)))
        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()
        bb.addInstruction(ir.Move(ir.Mem(ir.Const(1)), ir.Const(22)))
        bb.addInstruction(ir.Return(ir.Const(0)))
        m.check()
        cg.generate(m)
        #s.dump()


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