annotate python/testcg.py @ 271:cf7d5fb7d9c8

Reorganization
author Windel Bouwman
date Tue, 20 Aug 2013 18:56:02 +0200
parents 5ec7580976d9
children e64bae57cda8
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)
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 243
diff changeset
11 return m, 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):
240
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
19 m, bb = genTestFunction()
268
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 243
diff changeset
20 bb.addInstruction(ir.Const(123))
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 243
diff changeset
21 bb.addInstruction(ir.Return(ir.Const(0)))
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)
6259856841a0 Remove project
Windel Bouwman
parents: 218
diff changeset
31 m, 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)))
5ec7580976d9 Op naar tree-IR
Windel Bouwman
parents: 243
diff changeset
33 bb.addInstruction(ir.Return(ir.Const(0)))
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