Mercurial > lcfOS
comparison python/testir.py @ 237:81752b0f85a5
Added burn led test program
author | Windel Bouwman |
---|---|
date | Wed, 17 Jul 2013 22:31:54 +0200 |
parents | de3a68f677a5 |
children | ef683881c64e |
comparison
equal
deleted
inserted
replaced
236:8786811a5a59 | 237:81752b0f85a5 |
---|---|
3 | 3 |
4 class ConstantFolderTestCase(unittest.TestCase): | 4 class ConstantFolderTestCase(unittest.TestCase): |
5 def setUp(self): | 5 def setUp(self): |
6 self.b = ir.Builder() | 6 self.b = ir.Builder() |
7 self.cf = transform.ConstantFolder() | 7 self.cf = transform.ConstantFolder() |
8 self.m = ir.Module('test') | |
9 self.b.setModule(self.m) | |
8 | 10 |
9 def testBuilder(self): | 11 def testBuilder(self): |
10 m = ir.Module('test') | |
11 self.b.setModule(m) | |
12 f = self.b.newFunction('test') | 12 f = self.b.newFunction('test') |
13 self.b.setFunction(f) | 13 self.b.setFunction(f) |
14 bb = self.b.newBB() | 14 bb = self.b.newBB() |
15 self.b.setBB(bb) | 15 self.b.setBB(bb) |
16 v1 = self.b.newTmp('t') | 16 v1 = self.b.newTmp('t') |
17 v2 = self.b.newTmp('t') | 17 v2 = self.b.newTmp('t') |
18 v3 = self.b.newTmp('t') | 18 v3 = self.b.newTmp('t') |
19 self.b.addIns(ir.ImmLoad(v1, 5)) | 19 self.b.addIns(ir.ImmLoad(v1, 5)) |
20 self.b.addIns(ir.ImmLoad(v2, 7)) | 20 self.b.addIns(ir.ImmLoad(v2, 7)) |
21 self.b.addIns(ir.BinaryOperator(v3, '+', v1, v2)) | 21 self.b.addIns(ir.BinaryOperator(v3, '+', v1, v2)) |
22 self.assertEqual(3, len(m.Instructions)) | 22 self.assertEqual(3, len(self.m.Instructions)) |
23 self.cf.run(m) | 23 self.cf.run(self.m) |
24 self.assertEqual(3, len(m.Instructions)) | 24 self.assertEqual(3, len(self.m.Instructions)) |
25 self.assertIsInstance(m.Instructions[-1], ir.ImmLoad) | 25 self.assertIsInstance(self.m.Instructions[-1], ir.ImmLoad) |
26 self.assertEqual(12, m.Instructions[-1].value) | 26 self.assertEqual(12, self.m.Instructions[-1].value) |
27 | |
28 def testAdd0(self): | |
29 f = self.b.newFunction('test') | |
30 self.b.setFunction(f) | |
31 bb = self.b.newBB() | |
32 self.b.setBB(bb) | |
33 v1 = self.b.newTmp('t') | |
34 v2 = self.b.newTmp('t') | |
35 v3 = self.b.newTmp('t') | |
36 self.b.addIns(ir.ImmLoad(v2, 0)) | |
37 self.b.addIns(ir.BinaryOperator(v3, '+', v1, v2)) | |
27 | 38 |
28 | 39 |
29 testsrc = """ | 40 testsrc = """ |
30 package test2; | 41 package test2; |
31 | 42 |
73 } | 84 } |
74 | 85 |
75 """ | 86 """ |
76 | 87 |
77 if __name__ == '__main__': | 88 if __name__ == '__main__': |
78 unittest.main() | 89 #unittest.main() |
79 sys.exit() | 90 #sys.exit() |
80 diag = ppci.DiagnosticsManager() | 91 diag = ppci.DiagnosticsManager() |
81 builder = c3.Builder(diag) | 92 builder = c3.Builder(diag) |
82 cgenx86 = x86.X86CodeGenSimple(diag) | 93 cgenx86 = x86.X86CodeGenSimple(diag) |
83 ir = builder.build(testsrc) | 94 ir = builder.build(testsrc) |
84 diag.printErrors(testsrc) | 95 diag.printErrors(testsrc) |