209
|
1 import unittest
|
292
|
2 import ppci
|
|
3 from codegen import CodeGenerator
|
|
4 import ir
|
|
5 from target import armtarget
|
240
|
6 import outstream
|
|
7
|
290
|
8
|
240
|
9 def genTestFunction():
|
|
10 m = ir.Module('tst')
|
|
11 f = ir.Function('tst')
|
|
12 m.addFunction(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):
|
292
|
21 s = outstream.OutputStream()
|
272
|
22 m, f, bb = genTestFunction()
|
292
|
23 bb.addInstruction(ir.Exp(ir.Const(123)))
|
272
|
24 bb.addInstruction(ir.Jump(f.epiloog))
|
209
|
25 m.check()
|
292
|
26 obj = self.cg.generate(m, s)
|
209
|
27 self.assertTrue(obj)
|
|
28
|
243
|
29
|
240
|
30 class testArmCodeGeneration(unittest.TestCase):
|
|
31 def testStack(self):
|
|
32 s = outstream.OutputStream()
|
292
|
33 cg = CodeGenerator(armtarget)
|
272
|
34 m, f, bb = genTestFunction()
|
268
|
35 bb.addInstruction(ir.Move(ir.Mem(ir.Const(1)), ir.Const(22)))
|
272
|
36 bb.addInstruction(ir.Jump(f.epiloog))
|
240
|
37 m.check()
|
292
|
38 cg.generate(m, s)
|
243
|
39 #s.dump()
|
240
|
40
|
268
|
41
|
209
|
42 if __name__ == '__main__':
|
240
|
43 unittest.main()
|