annotate test/testcg.py @ 333:dcae6574c974

Increment to qt5
author Windel Bouwman
date Sun, 09 Feb 2014 15:27:57 +0100
parents 44f336460c2a
children 582a1aaa3983
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
322
44f336460c2a Half of use of burg spec for arm
Windel Bouwman
parents: 317
diff changeset
5 from target.target_list 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')
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):
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))
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):
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
31 s = outstream.OutputStream()
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
32 cg = CodeGenerator(armtarget)
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()