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