Mercurial > lcfOS
comparison python/tcodegen.py @ 275:6f2423df0675
Fixed serve arm-as
author | Windel Bouwman |
---|---|
date | Sat, 14 Sep 2013 17:29:10 +0200 |
parents | ea93e0a7a31e |
children | 9fca39eebe50 |
comparison
equal
deleted
inserted
replaced
274:ea93e0a7a31e | 275:6f2423df0675 |
---|---|
38 a = 2 * 33 - 12; | 38 a = 2 * 33 - 12; |
39 b = a * 2; | 39 b = a * 2; |
40 a = b + a; | 40 a = b + a; |
41 cee = a; | 41 cee = a; |
42 cee = cee * 2 + cee; | 42 cee = cee * 2 + cee; |
43 if (cee + a > b and b - a+b== 3*6-b) | 43 insanemath(2, 3); |
44 if (cee + a > b and b - a+b== 3*6-insanemath(b, 2)) | |
44 { | 45 { |
45 var int x = a; | 46 var int x = a; |
46 x = b - a + insanemath(3, 4) - insanemath(33,2); | 47 x = b - a + insanemath(3, 4) - insanemath(33, insanemath(2, 0)); |
47 a = x * (x + a); | 48 a = x * (x + a); |
48 } | 49 } |
49 else | 50 else |
50 { | 51 { |
51 a = b + (a + b); | 52 a = b + (a + b); |
52 } | 53 } |
53 var int y; | 54 var int y; |
54 y = a - b * 53; | 55 y = a - b * 53; |
55 } | 56 } |
56 """ | 57 """ |
58 | |
59 testsrc = """ | |
60 package test3; | |
61 | |
62 function int ab(int a, int b) | |
63 { | |
64 var int c; | |
65 c = 0; | |
66 c = c + a + b; | |
67 return c; | |
68 } | |
69 | |
70 function void tesssst() | |
71 { | |
72 var int a, b; | |
73 a = 2; | |
74 b = 3; | |
75 ab(ab(a, b) + ab(9,b), 0); | |
76 } | |
77 """ | |
78 def dump_cfg(cga, cfg_file): | |
79 print('digraph G {', file=cfg_file) | |
80 #print('edge [constraint=none]', file=cfg_file) | |
81 print('rankdir=TB', file=cfg_file) | |
82 for f in cga.frames: | |
83 print('subgraph cluster_{} {{'.format(f.name), file=cfg_file) | |
84 print('label={};'.format(f.name), file=cfg_file) | |
85 print('color=lightgrey;', file=cfg_file) | |
86 print('style=filled;', file=cfg_file) | |
87 f.cfg.to_dot(cfg_file) | |
88 print('}', file=cfg_file) | |
89 print('}', file=cfg_file) | |
90 | |
91 def dump_ig(cga, ig_file): | |
92 print('digraph G {', file=ig_file) | |
93 print('edge [arrowhead=none]', file=ig_file) | |
94 for f in cga.frames: | |
95 print('subgraph cluster_{} {{'.format(f.name), file=ig_file) | |
96 print('label={};'.format(f.name), file=ig_file) | |
97 print('color=lightgrey;', file=ig_file) | |
98 print('style=filled;', file=ig_file) | |
99 f.ig.to_dot(ig_file) | |
100 print('}', file=ig_file) | |
101 print('}', file=ig_file) | |
57 | 102 |
58 if __name__ == '__main__': | 103 if __name__ == '__main__': |
59 diag = ppci.DiagnosticsManager() | 104 diag = ppci.DiagnosticsManager() |
60 builder = c3.Builder(diag) | 105 builder = c3.Builder(diag) |
61 irc = builder.build(testsrc) | 106 irc = builder.build(testsrc) |
68 outs = outstream.TextOutputStream() | 113 outs = outstream.TextOutputStream() |
69 cga = codegenarm.ArmCodeGenerator(outs) | 114 cga = codegenarm.ArmCodeGenerator(outs) |
70 ir2 = cga.generate(irc) | 115 ir2 = cga.generate(irc) |
71 | 116 |
72 with open('cfg.gv', 'w') as cfg_file: | 117 with open('cfg.gv', 'w') as cfg_file: |
73 print('digraph G {', file=cfg_file) | 118 dump_cfg(cga, cfg_file) |
74 #print('edge [constraint=none]', file=cfg_file) | |
75 print('rankdir=TB', file=cfg_file) | |
76 for f in cga.frames: | |
77 print('subgraph cluster_{} {{'.format(f.name), file=cfg_file) | |
78 print('label={};'.format(f.name), file=cfg_file) | |
79 print('color=lightgrey;', file=cfg_file) | |
80 print('style=filled;', file=cfg_file) | |
81 f.cfg.to_dot(cfg_file) | |
82 print('}', file=cfg_file) | |
83 print('}', file=cfg_file) | |
84 | 119 |
85 with open('ig.gv', 'w') as ig_file: | 120 with open('ig.gv', 'w') as ig_file: |
86 print('digraph G {', file=ig_file) | 121 dump_ig(cga, ig_file) |
87 print('edge [arrowhead=none]', file=ig_file) | |
88 for f in cga.frames: | |
89 print('subgraph cluster_{} {{'.format(f.name), file=ig_file) | |
90 print('label={};'.format(f.name), file=ig_file) | |
91 print('color=lightgrey;', file=ig_file) | |
92 print('style=filled;', file=ig_file) | |
93 f.ig.to_dot(ig_file) | |
94 print('}', file=ig_file) | |
95 print('}', file=ig_file) | |
96 | 122 |
97 for f in ir2: | 123 for f in ir2: |
98 print(f) | 124 print(f) |
99 for i in f.instructions: | 125 for i in f.instructions: |
100 print(' {}'.format(i)) | 126 print(' {}'.format(i)) |
101 | 127 |
128 outs.dump() | |
129 |