Mercurial > lcfOS
comparison test/testcg.py @ 292:534b94b40aa8
Fixup reorganize
author | Windel Bouwman |
---|---|
date | Wed, 27 Nov 2013 08:06:42 +0100 |
parents | 7b38782ed496 |
children | 6753763d3bec |
comparison
equal
deleted
inserted
replaced
290:7b38782ed496 | 292:534b94b40aa8 |
---|---|
1 import unittest | 1 import unittest |
2 import ppci, codegen, ir | 2 import ppci |
3 import cortexm3 as arm | 3 from codegen import CodeGenerator |
4 import codegenarm | 4 import ir |
5 from target import armtarget | |
5 import outstream | 6 import outstream |
6 | 7 |
7 | 8 |
8 def genTestFunction(): | 9 def genTestFunction(): |
9 m = ir.Module('tst') | 10 m = ir.Module('tst') |
12 return m, f, f.entry | 13 return m, f, f.entry |
13 | 14 |
14 | 15 |
15 class testCodeGeneration(unittest.TestCase): | 16 class testCodeGeneration(unittest.TestCase): |
16 def setUp(self): | 17 def setUp(self): |
17 self.cg = codegen.CodeGenerator(arm.armtarget) | 18 self.cg = CodeGenerator(armtarget) |
18 | 19 |
19 def testFunction(self): | 20 def testFunction(self): |
21 s = outstream.OutputStream() | |
20 m, f, bb = genTestFunction() | 22 m, f, bb = genTestFunction() |
21 bb.addInstruction(ir.Const(123)) | 23 bb.addInstruction(ir.Exp(ir.Const(123))) |
22 bb.addInstruction(ir.Jump(f.epiloog)) | 24 bb.addInstruction(ir.Jump(f.epiloog)) |
23 m.check() | 25 m.check() |
24 obj = self.cg.generate(m) | 26 obj = self.cg.generate(m, s) |
25 self.assertTrue(obj) | 27 self.assertTrue(obj) |
26 | 28 |
27 | 29 |
28 class testArmCodeGeneration(unittest.TestCase): | 30 class testArmCodeGeneration(unittest.TestCase): |
29 def testStack(self): | 31 def testStack(self): |
30 s = outstream.OutputStream() | 32 s = outstream.OutputStream() |
31 cg = codegenarm.ArmCodeGenerator(s) | 33 cg = CodeGenerator(armtarget) |
32 m, f, bb = genTestFunction() | 34 m, f, bb = genTestFunction() |
33 bb.addInstruction(ir.Move(ir.Mem(ir.Const(1)), ir.Const(22))) | 35 bb.addInstruction(ir.Move(ir.Mem(ir.Const(1)), ir.Const(22))) |
34 bb.addInstruction(ir.Jump(f.epiloog)) | 36 bb.addInstruction(ir.Jump(f.epiloog)) |
35 m.check() | 37 m.check() |
36 cg.generate(m) | 38 cg.generate(m, s) |
37 #s.dump() | 39 #s.dump() |
38 | 40 |
39 | 41 |
40 if __name__ == '__main__': | 42 if __name__ == '__main__': |
41 unittest.main() | 43 unittest.main() |