annotate python/testcg.py @ 213:003c8a976fff

Merge of semantics and parser again ..
author Windel Bouwman
date Fri, 05 Jul 2013 11:18:48 +0200
parents 07bfea4c1ed7
children 494828a7adf1
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
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
3 import arm_cm3
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
4
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
5 class testCodeGeneration(unittest.TestCase):
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
6 def setUp(self):
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
7 self.cg = codegen.CodeGenerator(arm_cm3.armtarget)
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
8
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
9 def testFunction(self):
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
10 m = ir.Module('tst')
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
11 f = ir.Function('tst')
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
12 m.addFunction(f)
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
13 bb = ir.BasicBlock('entry')
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
14 f.addBasicBlock(bb)
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
15 v = ir.Value('tst')
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
16 bb.addInstruction(ir.ImmLoad(v, 123))
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
17 m.check()
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
18 obj = self.cg.generate(m)
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
19 self.assertTrue(obj)
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
20
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
21 if __name__ == '__main__':
07bfea4c1ed7 Added codegen test
Windel Bouwman
parents:
diff changeset
22 unittest.main()