Mercurial > lcfOS
comparison python/testir.py @ 204:de3a68f677a5
Added long comment to c3 parser
author | Windel Bouwman |
---|---|
date | Fri, 21 Jun 2013 15:01:08 +0200 |
parents | 25a0753da4cf |
children | 81752b0f85a5 |
comparison
equal
deleted
inserted
replaced
203:ca1ea402f6a1 | 204:de3a68f677a5 |
---|---|
1 import unittest, os | |
1 import c3, ppci, ir, x86, transform | 2 import c3, ppci, ir, x86, transform |
2 import os | 3 |
4 class ConstantFolderTestCase(unittest.TestCase): | |
5 def setUp(self): | |
6 self.b = ir.Builder() | |
7 self.cf = transform.ConstantFolder() | |
8 | |
9 def testBuilder(self): | |
10 m = ir.Module('test') | |
11 self.b.setModule(m) | |
12 f = self.b.newFunction('test') | |
13 self.b.setFunction(f) | |
14 bb = self.b.newBB() | |
15 self.b.setBB(bb) | |
16 v1 = self.b.newTmp('t') | |
17 v2 = self.b.newTmp('t') | |
18 v3 = self.b.newTmp('t') | |
19 self.b.addIns(ir.ImmLoad(v1, 5)) | |
20 self.b.addIns(ir.ImmLoad(v2, 7)) | |
21 self.b.addIns(ir.BinaryOperator(v3, '+', v1, v2)) | |
22 self.assertEqual(3, len(m.Instructions)) | |
23 self.cf.run(m) | |
24 self.assertEqual(3, len(m.Instructions)) | |
25 self.assertIsInstance(m.Instructions[-1], ir.ImmLoad) | |
26 self.assertEqual(12, m.Instructions[-1].value) | |
27 | |
3 | 28 |
4 testsrc = """ | 29 testsrc = """ |
5 package test2; | 30 package test2; |
6 | 31 |
7 function void tesssst(int henkie) | 32 function void tesssst(int henkie) |
48 } | 73 } |
49 | 74 |
50 """ | 75 """ |
51 | 76 |
52 if __name__ == '__main__': | 77 if __name__ == '__main__': |
78 unittest.main() | |
79 sys.exit() | |
53 diag = ppci.DiagnosticsManager() | 80 diag = ppci.DiagnosticsManager() |
54 builder = c3.Builder(diag) | 81 builder = c3.Builder(diag) |
55 cgenx86 = x86.X86CodeGenSimple(diag) | 82 cgenx86 = x86.X86CodeGenSimple(diag) |
56 ir = builder.build(testsrc) | 83 ir = builder.build(testsrc) |
57 diag.printErrors(testsrc) | 84 diag.printErrors(testsrc) |