comparison python/testir.py @ 272:e64bae57cda8

refactor ir
author Windel Bouwman
date Sat, 31 Aug 2013 17:58:54 +0200
parents 5ec7580976d9
children ea93e0a7a31e
comparison
equal deleted inserted replaced
271:cf7d5fb7d9c8 272:e64bae57cda8
2 import sys 2 import sys
3 import c3 3 import c3
4 import ppci 4 import ppci
5 import ir, x86, transform 5 import ir, x86, transform
6 import optimize 6 import optimize
7
7 8
8 class IrCodeTestCase(unittest.TestCase): 9 class IrCodeTestCase(unittest.TestCase):
9 def setUp(self): 10 def setUp(self):
10 self.b = ir.Builder() 11 self.b = ir.Builder()
11 self.m = ir.Module('test') 12 self.m = ir.Module('test')
14 def testBuilder(self): 15 def testBuilder(self):
15 f = self.b.newFunction('add') 16 f = self.b.newFunction('add')
16 self.b.setFunction(f) 17 self.b.setFunction(f)
17 bb = self.b.newBlock() 18 bb = self.b.newBlock()
18 self.b.setBlock(bb) 19 self.b.setBlock(bb)
19 self.b.emit(ir.Return(ir.Const(0))) 20 self.b.emit(ir.Exp(ir.Const(0)))
20 self.m.check() 21 self.m.check()
21 # Run interpreter: 22 # Run interpreter:
22 # r = self.m.getFunction('add').call(1, 2) 23 # r = self.m.getFunction('add').call(1, 2)
23 #self.assertEqual(3, r) 24 #self.assertEqual(3, r)
25
24 26
25 class ConstantFolderTestCase(unittest.TestCase): 27 class ConstantFolderTestCase(unittest.TestCase):
26 def setUp(self): 28 def setUp(self):
27 self.b = ir.Builder() 29 self.b = ir.Builder()
28 self.cf = transform.ConstantFolder() 30 self.cf = transform.ConstantFolder()