comparison python/testir.py @ 175:a51b3c956386

Added function call in expressions
author Windel Bouwman
date Fri, 19 Apr 2013 22:15:54 +0200
parents 3eb06f5fb987
children 5fd02aa38b42
comparison
equal deleted inserted replaced
174:3eb06f5fb987 175:a51b3c956386
2 import os 2 import os
3 3
4 testsrc = """ 4 testsrc = """
5 package test2; 5 package test2;
6 6
7 function void tst() 7 function void tesssst(int henkie)
8 { 8 {
9 var int a, b; 9 var int a, b, cee;
10 a = 2 * 33 - 12; 10 a = 2 * 33 - 12;
11 b = a * 2 + 13; 11 b = a * 2 + 13;
12 a = b + a; 12 a = b + a;
13 cee = a;
13 if (a > b and b *3 - a+8*b== 3*6-b) 14 if (a > b and b *3 - a+8*b== 3*6-b)
14 { 15 {
15 var int x = a; 16 var int x = a;
16 x = b * 2 - a; 17 x = b * 2 - a;
17 a = x * x; 18 a = x * x * add2(x, 22 - a);
18 } 19 }
19 else 20 else
20 { 21 {
21 a = b + a; 22 a = b + a + add2(a, b);
22 } 23 }
23 var int y; 24 var int y;
24 y = a - b * 53; 25 y = a - b * 53;
25 } 26 }
26 27
27 function int add2(int x, int y) 28 function int add2(int x, int y)
28 { 29 {
29 var int res; 30 var int res;
30 res = x + y + 2 - 7 + 2; 31 res = x + y + 2 - 7 + 2;
32 //if (y < 2)
33 //{
34 // return y - 33;
35 //}
36
31 if (x > 13) 37 if (x > 13)
32 { 38 {
33 res = res + 2; 39 res = res + 2;
34 } 40 }
35 return res; 41 return res;
44 ir = builder.build(testsrc) 50 ir = builder.build(testsrc)
45 diag.printErrors(testsrc) 51 diag.printErrors(testsrc)
46 #ir.dump() 52 #ir.dump()
47 cf = transform.ConstantFolder() 53 cf = transform.ConstantFolder()
48 dcd = transform.DeadCodeDeleter() 54 dcd = transform.DeadCodeDeleter()
55 m2r = transform.Mem2RegPromotor()
49 ir.check() 56 ir.check()
50 cf.run(ir) 57 cf.run(ir)
51 cf.run(ir) 58 dcd.run(ir)
52 #dcd.run(ir) 59 m2r.run(ir)
53 ir.dump() 60 #ir.dump()
54 asm = cgenx86.genBin(ir) 61 asm = cgenx86.genBin(ir)
55 for a in asm: 62 #for a in asm:
56 print(a) 63 # print(a)
57 with open('out.asm', 'w') as f: 64 with open('out.asm', 'w') as f:
58 f.write('BITS 64\n') 65 f.write('BITS 64\n')
59 for a in asm: 66 for a in asm:
60 f.write(str(a) + '\n') 67 f.write(str(a) + '\n')
61 68