annotate python/testcg.py @ 259:ac603eb66b63

Added function call
author Windel Bouwman
date Mon, 05 Aug 2013 20:41:25 +0200
parents ef683881c64e
children 5ec7580976d9
rev   line source
209
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
1 import unittest
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
2 import ppci, codegen, ir
218
494828a7adf1 added some sort of cache to assembler
Windel Bouwman
parents: 209
diff changeset
3 import cortexm3 as arm
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
4 import codegenarm
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
5 import outstream
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
6
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
7 def genTestFunction():
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
8 m = ir.Module('tst')
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
9 f = ir.Function('tst')
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
10 m.addFunction(f)
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
11 bb = ir.BasicBlock('entry')
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
12 f.addBasicBlock(bb)
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
13 return m, bb
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
14
209
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
15
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
16 class testCodeGeneration(unittest.TestCase):
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
17 def setUp(self):
218
494828a7adf1 added some sort of cache to assembler
Windel Bouwman
parents: 209
diff changeset
18 self.cg = codegen.CodeGenerator(arm.armtarget)
209
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
19
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
20 def testFunction(self):
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
21 m, bb = genTestFunction()
209
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
22 v = ir.Value('tst')
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
23 bb.addInstruction(ir.ImmLoad(v, 123))
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
24 m.check()
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
25 obj = self.cg.generate(m)
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
26 self.assertTrue(obj)
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
27
243
ef683881c64e Remove various files
Windel Bouwman
parents: 240
diff changeset
28
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
29 class testArmCodeGeneration(unittest.TestCase):
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
30 def testStack(self):
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
31 s = outstream.OutputStream()
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
32 cg = codegenarm.ArmCodeGenerator(s)
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
33 m, bb = genTestFunction()
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
34 v = ir.Value('tst')
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
35 bb.addInstruction(ir.Alloc(v))
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
36 v2 = ir.Value('tst2')
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
37 bb.addInstruction(ir.ImmLoad(v2, 22))
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
38 bb.addInstruction(ir.Store(v, v2))
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
39 m.check()
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
40 cg.generate(m)
243
ef683881c64e Remove various files
Windel Bouwman
parents: 240
diff changeset
41 #s.dump()
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
42
209
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
43 if __name__ == '__main__':
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
44 unittest.main()
243
ef683881c64e Remove various files
Windel Bouwman
parents: 240
diff changeset
45