Mercurial > lcfOS
comparison python/tcodegen.py @ 272:e64bae57cda8
refactor ir
author | Windel Bouwman |
---|---|
date | Sat, 31 Aug 2013 17:58:54 +0200 |
parents | 5f8c04a8d26b |
children | ea93e0a7a31e |
comparison
equal
deleted
inserted
replaced
271:cf7d5fb7d9c8 | 272:e64bae57cda8 |
---|---|
9 import outstream | 9 import outstream |
10 | 10 |
11 testsrc = """ | 11 testsrc = """ |
12 package test2; | 12 package test2; |
13 | 13 |
14 var int phaa, foo, bar; | |
15 | |
16 function int insanemath(int a, int b) | |
17 { | |
18 var int c; | |
19 c = a + b + 1; | |
20 return c; | |
21 } | |
22 | |
14 function void tesssst(int henkie) | 23 function void tesssst(int henkie) |
15 { | 24 { |
16 var int a, b, cee; | 25 var int a, b, cee; |
17 a = 2 * 33 - 12; | 26 a = 2 * 33 - 12; |
18 b = a * 2; | 27 b = a * 2; |
20 cee = a; | 29 cee = a; |
21 cee = cee * 2 + cee; | 30 cee = cee * 2 + cee; |
22 if (cee + a > b and b - a+b== 3*6-b) | 31 if (cee + a > b and b - a+b== 3*6-b) |
23 { | 32 { |
24 var int x = a; | 33 var int x = a; |
25 x = b - a; | 34 x = b - a + insanemath(3, 4); |
26 a = x * (x + a); | 35 a = x * (x + a); |
27 } | 36 } |
28 else | 37 else |
29 { | 38 { |
30 a = b + (a + b); | 39 a = b + (a + b); |
41 ir.dump() | 50 ir.dump() |
42 outs = outstream.TextOutputStream() | 51 outs = outstream.TextOutputStream() |
43 cga = codegenarm.ArmCodeGenerator(outs) | 52 cga = codegenarm.ArmCodeGenerator(outs) |
44 cfg_file = open('cfg.gv', 'w') | 53 cfg_file = open('cfg.gv', 'w') |
45 ig_file = open('ig.gv', 'w') | 54 ig_file = open('ig.gv', 'w') |
46 cga.generate(ir, cfg_file=cfg_file, ig_file=ig_file) | 55 ir2 = cga.generate(ir, cfg_file=cfg_file, ig_file=ig_file) |
47 cfg_file.close() | 56 cfg_file.close() |
48 ig_file.close() | 57 ig_file.close() |
58 for i in ir2: | |
59 print(i) | |
49 | 60 |