annotate test/testcg.py @ 409:8fe299cd2d55 devel

Close devel branch
author Windel Bouwman
date Sat, 21 Feb 2015 12:20:10 +0100
parents 86b02c98a717
children
rev   line source
209
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
1 import unittest
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
2 import ppci
301
6753763d3bec merge codegen into ppci package
Windel Bouwman
parents: 292
diff changeset
3 from ppci.codegen import CodeGenerator
6753763d3bec merge codegen into ppci package
Windel Bouwman
parents: 292
diff changeset
4 from ppci import ir
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
5 from ppci.target.target_list import thumb_target
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
6 from ppci.outstream import BinaryOutputStream
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
7
290
7b38782ed496 File moves
Windel Bouwman
parents: 284
diff changeset
8
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
9 def genTestFunction():
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
10 m = ir.Module('tst')
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
11 f = ir.Function('tst')
309
68b01c8abf8a Added start of ir read and write
Windel Bouwman
parents: 301
diff changeset
12 m.add_function(f)
272
e64bae57cda8 refactor ir
Windel Bouwman
parents: 268
diff changeset
13 return m, f, f.entry
240
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):
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 335
diff changeset
18 self.cg = CodeGenerator(thumb_target)
209
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
19
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
20 def testFunction(self):
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
21 s = BinaryOutputStream(ppci.objectfile.ObjectFile())
272
e64bae57cda8 refactor ir
Windel Bouwman
parents: 268
diff changeset
22 m, f, bb = genTestFunction()
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
23 bb.addInstruction(ir.Exp(ir.Const(123)))
272
e64bae57cda8 refactor ir
Windel Bouwman
parents: 268
diff changeset
24 bb.addInstruction(ir.Jump(f.epiloog))
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
25 obj = self.cg.generate(m, s)
209
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):
342
86b02c98a717 Moved target directory
Windel Bouwman
parents: 341
diff changeset
31 s = BinaryOutputStream(ppci.objectfile.ObjectFile())
341
4d204f6f7d4e Rewrite of assembler parts
Windel Bouwman
parents: 335
diff changeset
32 cg = CodeGenerator(thumb_target)
272
e64bae57cda8 refactor ir
Windel Bouwman
parents: 268
diff changeset
33 m, f, bb = genTestFunction()
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 243
diff changeset
34 bb.addInstruction(ir.Move(ir.Mem(ir.Const(1)), ir.Const(22)))
272
e64bae57cda8 refactor ir
Windel Bouwman
parents: 268
diff changeset
35 bb.addInstruction(ir.Jump(f.epiloog))
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
36 cg.generate(m, s)
243
ef683881c64e Remove various files
Windel Bouwman
parents: 240
diff changeset
37 #s.dump()
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
38
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 243
diff changeset
39
209
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
40 if __name__ == '__main__':
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
41 unittest.main()