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)
|
|
11 bb = ir.BasicBlock('entry')
|
|
12 f.addBasicBlock(bb)
|
|
13 return m, bb
|
|
14
|
209
|
15
|
|
16 class testCodeGeneration(unittest.TestCase):
|
|
17 def setUp(self):
|
218
|
18 self.cg = codegen.CodeGenerator(arm.armtarget)
|
209
|
19
|
|
20 def testFunction(self):
|
240
|
21 m, bb = genTestFunction()
|
209
|
22 v = ir.Value('tst')
|
|
23 bb.addInstruction(ir.ImmLoad(v, 123))
|
|
24 m.check()
|
|
25 obj = self.cg.generate(m)
|
|
26 self.assertTrue(obj)
|
|
27
|
243
|
28
|
240
|
29 class testArmCodeGeneration(unittest.TestCase):
|
|
30 def testStack(self):
|
|
31 s = outstream.OutputStream()
|
|
32 cg = codegenarm.ArmCodeGenerator(s)
|
|
33 m, bb = genTestFunction()
|
|
34 v = ir.Value('tst')
|
|
35 bb.addInstruction(ir.Alloc(v))
|
|
36 v2 = ir.Value('tst2')
|
|
37 bb.addInstruction(ir.ImmLoad(v2, 22))
|
|
38 bb.addInstruction(ir.Store(v, v2))
|
|
39 m.check()
|
|
40 cg.generate(m)
|
243
|
41 #s.dump()
|
240
|
42
|
209
|
43 if __name__ == '__main__':
|
240
|
44 unittest.main()
|
243
|
45
|