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