Mercurial > lcfOS
view test/testcg.py @ 318:e84047f29c78
Add burg and yacc initial attempts
author | Windel Bouwman |
---|---|
date | Tue, 31 Dec 2013 12:38:15 +0100 |
parents | e30a77ae359b |
children | 44f336460c2a |
line wrap: on
line source
import unittest import ppci from ppci.codegen import CodeGenerator from ppci import ir from target 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.OutputStream() 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.OutputStream() 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()