Mercurial > lcfOS
comparison python/tcodegen.py @ 278:9fca39eebe50
First implementation of regalloc with coalsesc
author | Windel Bouwman |
---|---|
date | Sun, 29 Sep 2013 14:08:15 +0200 |
parents | 6f2423df0675 |
children | 2ccd57b1d78c |
comparison
equal
deleted
inserted
replaced
277:046017431c6a | 278:9fca39eebe50 |
---|---|
73 a = 2; | 73 a = 2; |
74 b = 3; | 74 b = 3; |
75 ab(ab(a, b) + ab(9,b), 0); | 75 ab(ab(a, b) + ab(9,b), 0); |
76 } | 76 } |
77 """ | 77 """ |
78 | |
79 testsrc = """ | |
80 package test3; | |
81 | |
82 function int ab(int a, int b) | |
83 { | |
84 var int c; | |
85 c = 0; | |
86 c = c + a + b; | |
87 return c; | |
88 } | |
89 | |
90 """ | |
78 def dump_cfg(cga, cfg_file): | 91 def dump_cfg(cga, cfg_file): |
79 print('digraph G {', file=cfg_file) | 92 print('digraph G {', file=cfg_file) |
80 #print('edge [constraint=none]', file=cfg_file) | 93 #print('edge [constraint=none]', file=cfg_file) |
81 print('rankdir=TB', file=cfg_file) | 94 print('rankdir=TB', file=cfg_file) |
82 for f in cga.frames: | 95 for f in cga.frames: |
105 builder = c3.Builder(diag) | 118 builder = c3.Builder(diag) |
106 irc = builder.build(testsrc) | 119 irc = builder.build(testsrc) |
107 if not irc: | 120 if not irc: |
108 diag.printErrors(testsrc) | 121 diag.printErrors(testsrc) |
109 irc.check() | 122 irc.check() |
110 irc.dump() | 123 #irc.dump() |
111 with open('ir.gv', 'w') as f: | 124 with open('ir.gv', 'w') as f: |
112 ir.dumpgv(irc, f) | 125 ir.dumpgv(irc, f) |
113 outs = outstream.TextOutputStream() | 126 outs = outstream.TextOutputStream() |
114 cga = codegenarm.ArmCodeGenerator(outs) | 127 cga = codegenarm.ArmCodeGenerator(outs) |
115 ir2 = cga.generate(irc) | 128 ir2 = cga.generate(irc) |
116 | 129 |
117 with open('cfg.gv', 'w') as cfg_file: | 130 #with open('cfg.gv', 'w') as cfg_file: |
118 dump_cfg(cga, cfg_file) | 131 # dump_cfg(cga, cfg_file) |
119 | 132 |
120 with open('ig.gv', 'w') as ig_file: | 133 #with open('ig.gv', 'w') as ig_file: |
121 dump_ig(cga, ig_file) | 134 # dump_ig(cga, ig_file) |
122 | 135 |
123 for f in ir2: | 136 #for f in ir2: |
124 print(f) | 137 # print(f) |
125 for i in f.instructions: | 138 # for i in f.instructions: |
126 print(' {}'.format(i)) | 139 # print(' {}'.format(i)) |
127 | 140 |
128 outs.dump() | 141 outs.dump() |
129 | 142 |