view test/testcg.py @ 284:05184b95fa16

Moved tests to seperate folder
author Windel Bouwman
date Fri, 15 Nov 2013 13:43:22 +0100
parents python/testcg.py@e64bae57cda8
children 7b38782ed496
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, f.entry


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

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


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