comparison python/testcg.py @ 268:5ec7580976d9

Op naar tree-IR
author Windel Bouwman
date Wed, 14 Aug 2013 20:12:40 +0200
parents ef683881c64e
children e64bae57cda8
comparison
equal deleted inserted replaced
267:e7c8f7eb3f59 268:5ec7580976d9
6 6
7 def genTestFunction(): 7 def genTestFunction():
8 m = ir.Module('tst') 8 m = ir.Module('tst')
9 f = ir.Function('tst') 9 f = ir.Function('tst')
10 m.addFunction(f) 10 m.addFunction(f)
11 bb = ir.BasicBlock('entry') 11 return m, f.entry
12 f.addBasicBlock(bb)
13 return m, bb
14 12
15 13
16 class testCodeGeneration(unittest.TestCase): 14 class testCodeGeneration(unittest.TestCase):
17 def setUp(self): 15 def setUp(self):
18 self.cg = codegen.CodeGenerator(arm.armtarget) 16 self.cg = codegen.CodeGenerator(arm.armtarget)
19 17
20 def testFunction(self): 18 def testFunction(self):
21 m, bb = genTestFunction() 19 m, bb = genTestFunction()
22 v = ir.Value('tst') 20 bb.addInstruction(ir.Const(123))
23 bb.addInstruction(ir.ImmLoad(v, 123)) 21 bb.addInstruction(ir.Return(ir.Const(0)))
24 m.check() 22 m.check()
25 obj = self.cg.generate(m) 23 obj = self.cg.generate(m)
26 self.assertTrue(obj) 24 self.assertTrue(obj)
27 25
28 26
29 class testArmCodeGeneration(unittest.TestCase): 27 class testArmCodeGeneration(unittest.TestCase):
30 def testStack(self): 28 def testStack(self):
31 s = outstream.OutputStream() 29 s = outstream.OutputStream()
32 cg = codegenarm.ArmCodeGenerator(s) 30 cg = codegenarm.ArmCodeGenerator(s)
33 m, bb = genTestFunction() 31 m, bb = genTestFunction()
34 v = ir.Value('tst') 32 bb.addInstruction(ir.Move(ir.Mem(ir.Const(1)), ir.Const(22)))
35 bb.addInstruction(ir.Alloc(v)) 33 bb.addInstruction(ir.Return(ir.Const(0)))
36 v2 = ir.Value('tst2')
37 bb.addInstruction(ir.ImmLoad(v2, 22))
38 bb.addInstruction(ir.Store(v, v2))
39 m.check() 34 m.check()
40 cg.generate(m) 35 cg.generate(m)
41 #s.dump() 36 #s.dump()
42 37
38
43 if __name__ == '__main__': 39 if __name__ == '__main__':
44 unittest.main() 40 unittest.main()
45 41