Mercurial > lcfOS
view test/testcg.py @ 337:b00219172a42
Added cool lm3s811 qemu project
author | Windel Bouwman |
---|---|
date | Thu, 20 Feb 2014 20:04:52 +0100 |
parents | 582a1aaa3983 |
children | 4d204f6f7d4e |
line wrap: on
line source
import unittest import ppci from ppci.codegen import CodeGenerator from ppci import ir from target.target_list import armtarget import outstream def genTestFunction(): m = ir.Module('tst') f = ir.Function('tst') m.add_function(f) return m, f, f.entry class testCodeGeneration(unittest.TestCase): def setUp(self): self.cg = CodeGenerator(armtarget) def testFunction(self): s = outstream.BinaryOutputStream(ppci.objectfile.ObjectFile()) m, f, bb = genTestFunction() bb.addInstruction(ir.Exp(ir.Const(123))) bb.addInstruction(ir.Jump(f.epiloog)) obj = self.cg.generate(m, s) self.assertTrue(obj) class testArmCodeGeneration(unittest.TestCase): def testStack(self): s = outstream.BinaryOutputStream(ppci.objectfile.ObjectFile()) cg = CodeGenerator(armtarget) m, f, bb = genTestFunction() bb.addInstruction(ir.Move(ir.Mem(ir.Const(1)), ir.Const(22))) bb.addInstruction(ir.Jump(f.epiloog)) cg.generate(m, s) #s.dump() if __name__ == '__main__': unittest.main()