Mercurial > lcfOS
view python/testcg.py @ 245:66912720d712
Added grinder
author | Windel Bouwman |
---|---|
date | Wed, 24 Jul 2013 22:40:29 +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()