Mercurial > lcfOS
comparison python/testc3.py @ 252:c4370696ccc7
added optimize function
author | Windel Bouwman |
---|---|
date | Tue, 30 Jul 2013 17:57:46 +0200 |
parents | 6ed3d3a82a63 |
children | 5ec7580976d9 |
comparison
equal
deleted
inserted
replaced
251:6ed3d3a82a63 | 252:c4370696ccc7 |
---|---|
172 } | 172 } |
173 """ | 173 """ |
174 block_code = """ a0 = alloc | 174 block_code = """ a0 = alloc |
175 b1 = alloc | 175 b1 = alloc |
176 c2 = alloc | 176 c2 = alloc |
177 t3 = 1 | 177 const3 = 1 |
178 [a0] = t3 | 178 [a0] = const3 |
179 t4 = [a0] | 179 t4 = [a0] |
180 t5 = 2 | 180 const5 = 2 |
181 mul6 = t4 * t5 | 181 mul6 = t4 * const5 |
182 t7 = [a0] | 182 t7 = [a0] |
183 t8 = [a0] | 183 t8 = [a0] |
184 mul9 = t7 * t8 | 184 mul9 = t7 * t8 |
185 add10 = mul6 + mul9 | 185 add10 = mul6 + mul9 |
186 [b1] = add10 | 186 [b1] = add10 |
187 t11 = [b1] | 187 t11 = [b1] |
188 t12 = [a0] | 188 t12 = [a0] |
189 mul13 = t11 * t12 | 189 mul13 = t11 * t12 |
190 t14 = 3 | 190 const14 = 3 |
191 sub15 = mul13 - t14 | 191 sub15 = mul13 - const14 |
192 [c2] = sub15 | 192 [c2] = sub15 |
193 ret """ | 193 ret """ |
194 self.expectIR(snippet, block_code) | 194 self.expectIR(snippet, block_code) |
195 | 195 |
196 def testEmpty(self): | 196 def testEmpty(self): |
284 b = a + 2; | 284 b = a + 2; |
285 } | 285 } |
286 """ | 286 """ |
287 block_code = """a0 = alloc | 287 block_code = """a0 = alloc |
288 b1 = alloc | 288 b1 = alloc |
289 t2 = 2 | 289 const2 = 2 |
290 [a0] = t2 | 290 [a0] = const2 |
291 t3 = [a0] | 291 t3 = [a0] |
292 t4 = 2 | 292 const4 = 2 |
293 add5 = t3 + t4 | 293 add5 = t3 + const4 |
294 [b1] = add5 | 294 [b1] = add5 |
295 ret """ | 295 ret """ |
296 self.expectIR(snippet, block_code) | 296 self.expectIR(snippet, block_code) |
297 | 297 |
298 def testUnknownType(self): | 298 def testUnknownType(self): |
313 a.x = 2; | 313 a.x = 2; |
314 a.y = a.x + 2; | 314 a.y = a.x + 2; |
315 } | 315 } |
316 """ | 316 """ |
317 block_code = """a0 = alloc | 317 block_code = """a0 = alloc |
318 t1 = 2 | 318 const1 = 2 |
319 off_x2 = 0 | 319 off_x2 = 0 |
320 adr_x3 = a0 + off_x2 | 320 adr_x3 = a0 + off_x2 |
321 [adr_x3] = t1 | 321 [adr_x3] = const1 |
322 off_x4 = 0 | 322 off_x4 = 0 |
323 adr_x5 = a0 + off_x4 | 323 adr_x5 = a0 + off_x4 |
324 t6 = [adr_x5] | 324 t6 = [adr_x5] |
325 t7 = 2 | 325 const7 = 2 |
326 add8 = t6 + t7 | 326 add8 = t6 + const7 |
327 off_y9 = 4 | 327 off_y9 = 4 |
328 adr_y10 = a0 + off_y9 | 328 adr_y10 = a0 + off_y9 |
329 [adr_y10] = add8 | 329 [adr_y10] = add8 |
330 ret """ | 330 ret """ |
331 self.expectIR(snippet, block_code) | 331 self.expectIR(snippet, block_code) |
380 a = cast<int*>(40); | 380 a = cast<int*>(40); |
381 *a = 2; | 381 *a = 2; |
382 } | 382 } |
383 """ | 383 """ |
384 block_code = """a0 = alloc | 384 block_code = """a0 = alloc |
385 t1 = 40 | 385 const1 = 40 |
386 [a0] = t1 | 386 [a0] = const1 |
387 t2 = 2 | 387 const2 = 2 |
388 deref3 = [a0] | 388 deref3 = [a0] |
389 [deref3] = t2 | 389 [deref3] = const2 |
390 ret """ | 390 ret """ |
391 self.expectIR(snippet, block_code) | 391 self.expectIR(snippet, block_code) |
392 | 392 |
393 def testPointerTypeIr2(self): | 393 def testPointerTypeIr2(self): |
394 snippet = """ | 394 snippet = """ |
401 a->x = 2; | 401 a->x = 2; |
402 a->y = a->x - 14; | 402 a->y = a->x - 14; |
403 } | 403 } |
404 """ | 404 """ |
405 block_code = """a0 = alloc | 405 block_code = """a0 = alloc |
406 t1 = 40 | 406 const1 = 40 |
407 [a0] = t1 | 407 [a0] = const1 |
408 t2 = 2 | 408 const2 = 2 |
409 deref3 = [a0] | 409 deref3 = [a0] |
410 off_x4 = 0 | 410 off_x4 = 0 |
411 adr_x5 = deref3 + off_x4 | 411 adr_x5 = deref3 + off_x4 |
412 [adr_x5] = t2 | 412 [adr_x5] = const2 |
413 deref6 = [a0] | 413 deref6 = [a0] |
414 off_x7 = 0 | 414 off_x7 = 0 |
415 adr_x8 = deref6 + off_x7 | 415 adr_x8 = deref6 + off_x7 |
416 t9 = [adr_x8] | 416 t9 = [adr_x8] |
417 t10 = 14 | 417 const10 = 14 |
418 sub11 = t9 - t10 | 418 sub11 = t9 - const10 |
419 deref12 = [a0] | 419 deref12 = [a0] |
420 off_y13 = 4 | 420 off_y13 = 4 |
421 adr_y14 = deref12 + off_y13 | 421 adr_y14 = deref12 + off_y13 |
422 [adr_y14] = sub11 | 422 [adr_y14] = sub11 |
423 ret """ | 423 ret """ |