comparison test/testcg.py @ 342:86b02c98a717 devel

Moved target directory
author Windel Bouwman
date Sat, 01 Mar 2014 15:40:31 +0100
parents 4d204f6f7d4e
children
comparison
equal deleted inserted replaced
341:4d204f6f7d4e 342:86b02c98a717
1 import unittest 1 import unittest
2 import ppci 2 import ppci
3 from ppci.codegen import CodeGenerator 3 from ppci.codegen import CodeGenerator
4 from ppci import ir 4 from ppci import ir
5 from target.target_list import thumb_target 5 from ppci.target.target_list import thumb_target
6 import outstream 6 from ppci.outstream import BinaryOutputStream
7 7
8 8
9 def genTestFunction(): 9 def genTestFunction():
10 m = ir.Module('tst') 10 m = ir.Module('tst')
11 f = ir.Function('tst') 11 f = ir.Function('tst')
16 class testCodeGeneration(unittest.TestCase): 16 class testCodeGeneration(unittest.TestCase):
17 def setUp(self): 17 def setUp(self):
18 self.cg = CodeGenerator(thumb_target) 18 self.cg = CodeGenerator(thumb_target)
19 19
20 def testFunction(self): 20 def testFunction(self):
21 s = outstream.BinaryOutputStream(ppci.objectfile.ObjectFile()) 21 s = BinaryOutputStream(ppci.objectfile.ObjectFile())
22 m, f, bb = genTestFunction() 22 m, f, bb = genTestFunction()
23 bb.addInstruction(ir.Exp(ir.Const(123))) 23 bb.addInstruction(ir.Exp(ir.Const(123)))
24 bb.addInstruction(ir.Jump(f.epiloog)) 24 bb.addInstruction(ir.Jump(f.epiloog))
25 obj = self.cg.generate(m, s) 25 obj = self.cg.generate(m, s)
26 self.assertTrue(obj) 26 self.assertTrue(obj)
27 27
28 28
29 class testArmCodeGeneration(unittest.TestCase): 29 class testArmCodeGeneration(unittest.TestCase):
30 def testStack(self): 30 def testStack(self):
31 s = outstream.BinaryOutputStream(ppci.objectfile.ObjectFile()) 31 s = BinaryOutputStream(ppci.objectfile.ObjectFile())
32 cg = CodeGenerator(thumb_target) 32 cg = CodeGenerator(thumb_target)
33 m, f, bb = genTestFunction() 33 m, f, bb = genTestFunction()
34 bb.addInstruction(ir.Move(ir.Mem(ir.Const(1)), ir.Const(22))) 34 bb.addInstruction(ir.Move(ir.Mem(ir.Const(1)), ir.Const(22)))
35 bb.addInstruction(ir.Jump(f.epiloog)) 35 bb.addInstruction(ir.Jump(f.epiloog))
36 cg.generate(m, s) 36 cg.generate(m, s)