annotate test/testcg.py @ 292:534b94b40aa8

Fixup reorganize
author Windel Bouwman
date Wed, 27 Nov 2013 08:06:42 +0100
parents 7b38782ed496
children 6753763d3bec
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
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
3 from codegen import CodeGenerator
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
4 import ir
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
5 from target import armtarget
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
6 import outstream
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')
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
12 m.addFunction(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):
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
18 self.cg = CodeGenerator(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):
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
21 s = outstream.OutputStream()
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))
209
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
25 m.check()
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
26 obj = self.cg.generate(m, s)
209
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
27 self.assertTrue(obj)
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
28
243
ef683881c64e Remove various files
Windel Bouwman
parents: 240
diff changeset
29
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
30 class testArmCodeGeneration(unittest.TestCase):
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
31 def testStack(self):
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
32 s = outstream.OutputStream()
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
33 cg = CodeGenerator(armtarget)
272
e64bae57cda8 refactor ir
Windel Bouwman
parents: 268
diff changeset
34 m, f, bb = genTestFunction()
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 243
diff changeset
35 bb.addInstruction(ir.Move(ir.Mem(ir.Const(1)), ir.Const(22)))
272
e64bae57cda8 refactor ir
Windel Bouwman
parents: 268
diff changeset
36 bb.addInstruction(ir.Jump(f.epiloog))
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
37 m.check()
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
38 cg.generate(m, s)
243
ef683881c64e Remove various files
Windel Bouwman
parents: 240
diff changeset
39 #s.dump()
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
40
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 243
diff changeset
41
209
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
42 if __name__ == '__main__':
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
43 unittest.main()