annotate test/testcg.py @ 284:05184b95fa16

Moved tests to seperate folder
author Windel Bouwman
date Fri, 15 Nov 2013 13:43:22 +0100
parents python/testcg.py@e64bae57cda8
children 7b38782ed496
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)
272
e64bae57cda8 refactor ir
Windel Bouwman
parents: 268
diff changeset
11 return m, f, f.entry
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
12
209
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
13
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
14 class testCodeGeneration(unittest.TestCase):
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
15 def setUp(self):
218
494828a7adf1 added some sort of cache to assembler
Windel Bouwman
parents: 209
diff changeset
16 self.cg = codegen.CodeGenerator(arm.armtarget)
209
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
17
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
18 def testFunction(self):
272
e64bae57cda8 refactor ir
Windel Bouwman
parents: 268
diff changeset
19 m, f, bb = genTestFunction()
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 243
diff changeset
20 bb.addInstruction(ir.Const(123))
272
e64bae57cda8 refactor ir
Windel Bouwman
parents: 268
diff changeset
21 bb.addInstruction(ir.Jump(f.epiloog))
209
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
22 m.check()
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
23 obj = self.cg.generate(m)
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
24 self.assertTrue(obj)
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
25
243
ef683881c64e Remove various files
Windel Bouwman
parents: 240
diff changeset
26
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
27 class testArmCodeGeneration(unittest.TestCase):
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
28 def testStack(self):
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
29 s = outstream.OutputStream()
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
30 cg = codegenarm.ArmCodeGenerator(s)
272
e64bae57cda8 refactor ir
Windel Bouwman
parents: 268
diff changeset
31 m, f, bb = genTestFunction()
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 243
diff changeset
32 bb.addInstruction(ir.Move(ir.Mem(ir.Const(1)), ir.Const(22)))
272
e64bae57cda8 refactor ir
Windel Bouwman
parents: 268
diff changeset
33 bb.addInstruction(ir.Jump(f.epiloog))
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
34 m.check()
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
35 cg.generate(m)
243
ef683881c64e Remove various files
Windel Bouwman
parents: 240
diff changeset
36 #s.dump()
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
37
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 243
diff changeset
38
209
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
39 if __name__ == '__main__':
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
40 unittest.main()
243
ef683881c64e Remove various files
Windel Bouwman
parents: 240
diff changeset
41