Mercurial > lcfOS
comparison 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 |
comparison
equal
deleted
inserted
replaced
267:e7c8f7eb3f59 | 268:5ec7580976d9 |
---|---|
12 self.b.setModule(self.m) | 12 self.b.setModule(self.m) |
13 | 13 |
14 def testBuilder(self): | 14 def testBuilder(self): |
15 f = self.b.newFunction('add') | 15 f = self.b.newFunction('add') |
16 self.b.setFunction(f) | 16 self.b.setFunction(f) |
17 bb = self.b.newBB() | 17 bb = self.b.newBlock() |
18 self.b.setBB(bb) | 18 self.b.setBlock(bb) |
19 v1 = self.b.newTmp('t') | 19 self.b.emit(ir.Return(ir.Const(0))) |
20 self.b.addIns(ir.Return(v1)) | |
21 self.m.check() | 20 self.m.check() |
22 # Run interpreter: | 21 # Run interpreter: |
23 r = self.m.getFunction('add').call(1, 2) | 22 # r = self.m.getFunction('add').call(1, 2) |
24 #self.assertEqual(3, r) | 23 #self.assertEqual(3, r) |
25 | 24 |
26 class ConstantFolderTestCase(unittest.TestCase): | 25 class ConstantFolderTestCase(unittest.TestCase): |
27 def setUp(self): | 26 def setUp(self): |
28 self.b = ir.Builder() | 27 self.b = ir.Builder() |
31 self.b.setModule(self.m) | 30 self.b.setModule(self.m) |
32 | 31 |
33 def testBuilder(self): | 32 def testBuilder(self): |
34 f = self.b.newFunction('test') | 33 f = self.b.newFunction('test') |
35 self.b.setFunction(f) | 34 self.b.setFunction(f) |
36 bb = self.b.newBB() | 35 self.b.setBlock(self.b.newBlock()) |
37 self.b.setBB(bb) | 36 v1 = ir.Const(5) |
38 v1 = self.b.newTmp('t') | 37 v2 = ir.Const(7) |
39 v2 = self.b.newTmp('t') | 38 v3 = ir.Add(v1, v2) |
40 v3 = self.b.newTmp('t') | |
41 self.b.addIns(ir.ImmLoad(v1, 5)) | |
42 self.b.addIns(ir.ImmLoad(v2, 7)) | |
43 self.b.addIns(ir.BinaryOperator(v3, '+', v1, v2)) | |
44 self.assertEqual(3, len(self.m.Instructions)) | |
45 self.cf.run(self.m) | 39 self.cf.run(self.m) |
46 self.assertEqual(3, len(self.m.Instructions)) | |
47 self.assertIsInstance(self.m.Instructions[-1], ir.ImmLoad) | |
48 self.assertEqual(12, self.m.Instructions[-1].value) | |
49 | 40 |
50 def testAdd0(self): | 41 def testAdd0(self): |
51 f = self.b.newFunction('test') | 42 f = self.b.newFunction('test') |
52 self.b.setFunction(f) | 43 self.b.setFunction(f) |
53 bb = self.b.newBB() | 44 self.b.setBlock(self.b.newBlock()) |
54 self.b.setBB(bb) | 45 v1 = ir.Const(0) |
55 v1 = self.b.newTmp('t') | 46 v2 = ir.Const(0) |
56 v2 = self.b.newTmp('t') | 47 v3 = ir.Add(v1, v2) |
57 v3 = self.b.newTmp('t') | |
58 self.b.addIns(ir.ImmLoad(v2, 0)) | |
59 self.b.addIns(ir.BinaryOperator(v3, '+', v1, v2)) | |
60 | 48 |
61 | 49 |
62 testsrc = """ | 50 testsrc = """ |
63 package test2; | 51 package test2; |
64 | 52 |