Mercurial > lcfOS
view test/testcg.py @ 384:94f5b719ad0b
Small refactor
author | Windel Bouwman |
---|---|
date | Sun, 27 Apr 2014 17:50:25 +0200 |
parents | 86b02c98a717 |
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()