diff python/testir.py @ 268:5ec7580976d9

Op naar tree-IR
author Windel Bouwman
date Wed, 14 Aug 2013 20:12:40 +0200
parents 225f444019b1
children e64bae57cda8
line wrap: on
line diff
--- a/python/testir.py	Mon Aug 12 20:14:47 2013 +0200
+++ b/python/testir.py	Wed Aug 14 20:12:40 2013 +0200
@@ -14,13 +14,12 @@
     def testBuilder(self):
         f = self.b.newFunction('add')
         self.b.setFunction(f)
-        bb = self.b.newBB()
-        self.b.setBB(bb)
-        v1 = self.b.newTmp('t')
-        self.b.addIns(ir.Return(v1))
+        bb = self.b.newBlock()
+        self.b.setBlock(bb)
+        self.b.emit(ir.Return(ir.Const(0)))
         self.m.check()
         # Run interpreter:
-        r = self.m.getFunction('add').call(1, 2)
+        # r = self.m.getFunction('add').call(1, 2)
         #self.assertEqual(3, r)
 
 class ConstantFolderTestCase(unittest.TestCase):
@@ -33,30 +32,19 @@
     def testBuilder(self):
         f = self.b.newFunction('test')
         self.b.setFunction(f)
-        bb = self.b.newBB()
-        self.b.setBB(bb)
-        v1 = self.b.newTmp('t')
-        v2 = self.b.newTmp('t')
-        v3 = self.b.newTmp('t')
-        self.b.addIns(ir.ImmLoad(v1, 5))
-        self.b.addIns(ir.ImmLoad(v2, 7))
-        self.b.addIns(ir.BinaryOperator(v3, '+', v1, v2))
-        self.assertEqual(3, len(self.m.Instructions))
+        self.b.setBlock(self.b.newBlock())
+        v1 = ir.Const(5)
+        v2 = ir.Const(7)
+        v3 = ir.Add(v1, v2)
         self.cf.run(self.m)
-        self.assertEqual(3, len(self.m.Instructions))
-        self.assertIsInstance(self.m.Instructions[-1], ir.ImmLoad)
-        self.assertEqual(12, self.m.Instructions[-1].value)
 
     def testAdd0(self):
         f = self.b.newFunction('test')
         self.b.setFunction(f)
-        bb = self.b.newBB()
-        self.b.setBB(bb)
-        v1 = self.b.newTmp('t')
-        v2 = self.b.newTmp('t')
-        v3 = self.b.newTmp('t')
-        self.b.addIns(ir.ImmLoad(v2, 0))
-        self.b.addIns(ir.BinaryOperator(v3, '+', v1, v2))
+        self.b.setBlock(self.b.newBlock())
+        v1 = ir.Const(0)
+        v2 = ir.Const(0)
+        v3 = ir.Add(v1, v2)
 
 
 testsrc = """