view test/testcg.py @ 299:674789d9ff37

Added a doc
author Windel Bouwman
date Sun, 01 Dec 2013 18:37:23 +0100
parents 534b94b40aa8
children 6753763d3bec
line wrap: on
line source

import unittest
import ppci
from codegen import CodeGenerator
import ir
from target import armtarget
import outstream


def genTestFunction():
    m = ir.Module('tst')
    f = ir.Function('tst')
    m.addFunction(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))
        m.check()
        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))
        m.check()
        cg.generate(m, s)
        #s.dump()


if __name__ == '__main__':
    unittest.main()