209
|
1 import unittest
|
292
|
2 import ppci
|
301
|
3 from ppci.codegen import CodeGenerator
|
|
4 from ppci import ir
|
342
|
5 from ppci.target.target_list import thumb_target
|
|
6 from ppci.outstream import BinaryOutputStream
|
240
|
7
|
290
|
8
|
240
|
9 def genTestFunction():
|
|
10 m = ir.Module('tst')
|
|
11 f = ir.Function('tst')
|
309
|
12 m.add_function(f)
|
272
|
13 return m, f, f.entry
|
240
|
14
|
209
|
15
|
|
16 class testCodeGeneration(unittest.TestCase):
|
|
17 def setUp(self):
|
341
|
18 self.cg = CodeGenerator(thumb_target)
|
209
|
19
|
|
20 def testFunction(self):
|
342
|
21 s = BinaryOutputStream(ppci.objectfile.ObjectFile())
|
272
|
22 m, f, bb = genTestFunction()
|
292
|
23 bb.addInstruction(ir.Exp(ir.Const(123)))
|
272
|
24 bb.addInstruction(ir.Jump(f.epiloog))
|
292
|
25 obj = self.cg.generate(m, s)
|
209
|
26 self.assertTrue(obj)
|
|
27
|
243
|
28
|
240
|
29 class testArmCodeGeneration(unittest.TestCase):
|
|
30 def testStack(self):
|
342
|
31 s = BinaryOutputStream(ppci.objectfile.ObjectFile())
|
341
|
32 cg = CodeGenerator(thumb_target)
|
272
|
33 m, f, bb = genTestFunction()
|
268
|
34 bb.addInstruction(ir.Move(ir.Mem(ir.Const(1)), ir.Const(22)))
|
272
|
35 bb.addInstruction(ir.Jump(f.epiloog))
|
292
|
36 cg.generate(m, s)
|
243
|
37 #s.dump()
|
240
|
38
|
268
|
39
|
209
|
40 if __name__ == '__main__':
|
240
|
41 unittest.main()
|