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)
|
268
|
11 return m, 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):
|
240
|
19 m, bb = genTestFunction()
|
268
|
20 bb.addInstruction(ir.Const(123))
|
|
21 bb.addInstruction(ir.Return(ir.Const(0)))
|
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)
|
|
31 m, bb = genTestFunction()
|
268
|
32 bb.addInstruction(ir.Move(ir.Mem(ir.Const(1)), ir.Const(22)))
|
|
33 bb.addInstruction(ir.Return(ir.Const(0)))
|
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
|