Mercurial > lcfOS
view test/testcg.py @ 342:86b02c98a717 devel
Moved target directory
author | Windel Bouwman |
---|---|
date | Sat, 01 Mar 2014 15:40:31 +0100 |
parents | 4d204f6f7d4e |
children |
line wrap: on
line source
import unittest import ppci from ppci.codegen import CodeGenerator from ppci import ir from ppci.target.target_list import thumb_target from ppci.outstream import BinaryOutputStream 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(thumb_target) def testFunction(self): s = 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 = BinaryOutputStream(ppci.objectfile.ObjectFile()) cg = CodeGenerator(thumb_target) 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()