209
|
1 import unittest
|
292
|
2 import ppci
|
301
|
3 from ppci.codegen import CodeGenerator
|
|
4 from ppci import ir
|
322
|
5 from target.target_list import armtarget
|
240
|
6 import outstream
|
|
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):
|
292
|
18 self.cg = CodeGenerator(armtarget)
|
209
|
19
|
|
20 def testFunction(self):
|
335
|
21 s = outstream.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):
|
335
|
31 s = outstream.BinaryOutputStream(ppci.objectfile.ObjectFile())
|
292
|
32 cg = CodeGenerator(armtarget)
|
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()
|