comparison test/testcg.py @ 341:4d204f6f7d4e devel

Rewrite of assembler parts
author Windel Bouwman
date Fri, 28 Feb 2014 18:07:14 +0100
parents 582a1aaa3983
children 86b02c98a717
comparison
equal deleted inserted replaced
340:c7cc54c0dfdf 341:4d204f6f7d4e
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 armtarget 5 from target.target_list import thumb_target
6 import outstream 6 import outstream
7 7
8 8
9 def genTestFunction(): 9 def genTestFunction():
10 m = ir.Module('tst') 10 m = ir.Module('tst')
13 return m, f, f.entry 13 return m, f, f.entry
14 14
15 15
16 class testCodeGeneration(unittest.TestCase): 16 class testCodeGeneration(unittest.TestCase):
17 def setUp(self): 17 def setUp(self):
18 self.cg = CodeGenerator(armtarget) 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 = outstream.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)))
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 = outstream.BinaryOutputStream(ppci.objectfile.ObjectFile())
32 cg = CodeGenerator(armtarget) 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)
37 #s.dump() 37 #s.dump()