Mercurial > lcfOS
comparison test/testir.py @ 307:e609d5296ee9
Massive rewrite of codegenerator
author | Windel Bouwman |
---|---|
date | Thu, 12 Dec 2013 20:42:56 +0100 |
parents | 6753763d3bec |
children | 68b01c8abf8a |
comparison
equal
deleted
inserted
replaced
306:b145f8e6050b | 307:e609d5296ee9 |
---|---|
1 import unittest | 1 import unittest |
2 import os | 2 import os |
3 import sys | 3 import sys |
4 import ppci | 4 import ppci |
5 from ppci import ir | 5 from ppci import ir |
6 from ppci import irutils | |
6 from ppci.transform import ConstantFolder | 7 from ppci.transform import ConstantFolder |
7 | 8 |
8 | 9 |
9 class IrCodeTestCase(unittest.TestCase): | 10 class IrCodeTestCase(unittest.TestCase): |
11 def testAdd(self): | |
12 v = ir.Add(ir.Const(1), ir.Const(2)) | |
13 | |
14 | |
15 class IrBuilderTestCase(unittest.TestCase): | |
10 def setUp(self): | 16 def setUp(self): |
11 self.b = ir.Builder() | 17 self.b = irutils.Builder() |
12 self.m = ir.Module('test') | 18 self.m = ir.Module('test') |
13 self.b.setModule(self.m) | 19 self.b.setModule(self.m) |
14 | 20 |
15 def testBuilder(self): | 21 def testBuilder(self): |
16 f = self.b.newFunction('add') | 22 f = self.b.newFunction('add') |
49 self.assertFalse(res) | 55 self.assertFalse(res) |
50 | 56 |
51 | 57 |
52 class ConstantFolderTestCase(unittest.TestCase): | 58 class ConstantFolderTestCase(unittest.TestCase): |
53 def setUp(self): | 59 def setUp(self): |
54 self.b = ir.Builder() | 60 self.b = irutils.Builder() |
55 self.cf = ConstantFolder() | 61 self.cf = ConstantFolder() |
56 self.m = ir.Module('test') | 62 self.m = ir.Module('test') |
57 self.b.setModule(self.m) | 63 self.b.setModule(self.m) |
58 | 64 |
59 def testBuilder(self): | 65 def testBuilder(self): |
75 v1 = ir.Const(0) | 81 v1 = ir.Const(0) |
76 v2 = ir.Const(0) | 82 v2 = ir.Const(0) |
77 v3 = ir.Add(v1, v2) | 83 v3 = ir.Add(v1, v2) |
78 | 84 |
79 | 85 |
80 testsrc = """ | |
81 package test2; | |
82 | 86 |
83 function void tesssst(int henkie) | |
84 { | |
85 var int a, b, cee; | |
86 a = 2 * 33 - 12; | |
87 b = a * 2 + 13; | |
88 a = b + a; | |
89 cee = a; | |
90 cee = cee * 2 + a + cee * 2; | |
91 if (cee + a > b and b *3 - a+8*b== 3*6-b) | |
92 { | |
93 var int x = a; | |
94 x = b * 2 - a; | |
95 a = x * x * (x + 22 - a); | |
96 } | |
97 else | |
98 { | |
99 a = b + a + (a + b); | |
100 } | |
101 var int y; | |
102 y = a - b * 53; | |
103 } | |
104 """ | |
105 | |
106 testsrc2 = """ | |
107 function int add2(int x, int y) | |
108 { | |
109 var int res; | |
110 res = x + y + 2 - 7 + 2; | |
111 //if (y < 2) | |
112 //{ | |
113 // return y - 33; | |
114 //} | |
115 | |
116 res = res + (x + 2 * y) + (x + 2 * y) + (2*8) + (2*8); | |
117 | |
118 if (x > 13) | |
119 { | |
120 while (y > 1337) | |
121 { | |
122 res = res + 2; | |
123 y = y - 12; | |
124 } | |
125 } | |
126 return res; | |
127 } | |
128 | |
129 """ | |
130 | 87 |
131 if __name__ == '__main__': | 88 if __name__ == '__main__': |
132 unittest.main() | 89 unittest.main() |
133 sys.exit() | 90 sys.exit() |