view python/testcg.py @ 243:ef683881c64e

Remove various files
author Windel Bouwman
date Tue, 23 Jul 2013 16:50:02 +0200
parents 6259856841a0
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()