Mercurial > lcfOS
comparison python/zcc.py @ 316:56e6ff84f646
Fixed burn led demo
author | Windel Bouwman |
---|---|
date | Sat, 21 Dec 2013 13:13:26 +0100 |
parents | 084cccaa5deb |
children | e30a77ae359b |
comparison
equal
deleted
inserted
replaced
315:084cccaa5deb | 316:56e6ff84f646 |
---|---|
11 import outstream | 11 import outstream |
12 from utils import HexFile | 12 from utils import HexFile |
13 import target | 13 import target |
14 from ppci import irutils | 14 from ppci import irutils |
15 import io | 15 import io |
16 from ppci.transform import CleanPass | |
16 | 17 |
17 | 18 |
18 logformat='%(asctime)s|%(levelname)s|%(name)s|%(message)s' | 19 logformat='%(asctime)s|%(levelname)s|%(name)s|%(message)s' |
19 | 20 |
20 | 21 |
77 print('', file=f) | 78 print('', file=f) |
78 print('', file=f) | 79 print('', file=f) |
79 print('.. graphviz::', file=f) | 80 print('.. graphviz::', file=f) |
80 print('', file=f) | 81 print('', file=f) |
81 print(' digraph G {', file=f) | 82 print(' digraph G {', file=f) |
83 print(' size="8,80";', file=f) | |
82 cfg = record.ra_cfg | 84 cfg = record.ra_cfg |
83 cfg.to_dot(f) | 85 cfg.to_dot(f) |
84 print(' }', file=f) | 86 print(' }', file=f) |
85 print('', file=f) | 87 print('', file=f) |
86 s += '\n' + f.getvalue() | 88 s += '\n' + f.getvalue() |
89 print('', file=f) | 91 print('', file=f) |
90 print('', file=f) | 92 print('', file=f) |
91 print('.. graphviz::', file=f) | 93 print('.. graphviz::', file=f) |
92 print('', file=f) | 94 print('', file=f) |
93 print(' digraph G {', file=f) | 95 print(' digraph G {', file=f) |
96 print(' ratio="compress";', file=f) | |
97 print(' size="8,80";', file=f) | |
94 ig = record.ra_ig | 98 ig = record.ra_ig |
95 ig.to_dot(f) | 99 ig.to_dot(f) |
96 print(' }', file=f) | 100 print(' }', file=f) |
101 print('', file=f) | |
102 s += '\n' + f.getvalue() | |
103 if hasattr(record, 'zcc_outs'): | |
104 f = io.StringIO() | |
105 print('', file=f) | |
106 print('', file=f) | |
107 print('.. code::', file=f) | |
108 print('', file=f) | |
109 outstream.OutputStreamWriter(' ').dump(record.zcc_outs, f) | |
97 print('', file=f) | 110 print('', file=f) |
98 s += '\n' + f.getvalue() | 111 s += '\n' + f.getvalue() |
99 return s | 112 return s |
100 | 113 |
101 | 114 |
117 parser.add_argument('-o', '--output', help='Output file', metavar='filename') | 130 parser.add_argument('-o', '--output', help='Output file', metavar='filename') |
118 parser.add_argument('--hexfile', help='Output hexfile', | 131 parser.add_argument('--hexfile', help='Output hexfile', |
119 type=argparse.FileType('w')) | 132 type=argparse.FileType('w')) |
120 parser.add_argument('--log', help='Log level (INFO,DEBUG,[WARN])', | 133 parser.add_argument('--log', help='Log level (INFO,DEBUG,[WARN])', |
121 type=logLevel, default='WARN') | 134 type=logLevel, default='WARN') |
122 parser.add_argument('--report', help='Specify a file to write the compile report to', | 135 parser.add_argument('--report', |
136 help='Specify a file to write the compile report to', | |
123 type=argparse.FileType('w')) | 137 type=argparse.FileType('w')) |
124 | 138 |
125 | 139 |
126 def zcc(srcs, imps, tg, outs, diag): | 140 def zcc(srcs, imps, tg, outs, diag): |
127 """ | 141 """ |
128 Compiler driver | 142 Compiler driver |
129 Compile sources into output stream. | 143 Compile sources into output stream. |
130 Sources is an iterable of open files. | 144 Sources is an iterable of open files. |
131 """ | 145 """ |
132 logging.info('Zcc started {}'.format(srcs)) | 146 logger = logging.getLogger('zcc') |
147 logger.info('Zcc started {}'.format(srcs)) | |
133 # Front end: | 148 # Front end: |
134 c3b = Builder(diag, tg) | 149 c3b = Builder(diag, tg) |
135 cg = CodeGenerator(tg) | 150 cg = CodeGenerator(tg) |
136 | 151 |
137 # TODO: remove this arm specifics: | 152 # TODO: remove this arm specifics: |
143 for ircode in c3b.build(srcs, imps): | 158 for ircode in c3b.build(srcs, imps): |
144 if not ircode: | 159 if not ircode: |
145 return | 160 return |
146 | 161 |
147 d = {'ircode':ircode} | 162 d = {'ircode':ircode} |
148 logging.info('Verifying code {}'.format(ircode), extra=d) | 163 logger.info('Verifying code {}'.format(ircode), extra=d) |
149 # Optimization passes, TODO | 164 Verifier().verify(ircode) |
165 | |
166 # Optimization passes: | |
167 CleanPass().run(ircode) | |
150 Verifier().verify(ircode) | 168 Verifier().verify(ircode) |
151 | 169 |
152 # Code generation: | 170 # Code generation: |
153 d = {'ircode':ircode} | 171 d = {'ircode':ircode} |
154 logging.info('Starting code generation for {}'.format(ircode), extra=d) | 172 logger.info('Starting code generation for {}'.format(ircode), extra=d) |
155 cg.generate(ircode, outs) | 173 cg.generate(ircode, outs) |
156 # TODO: fixup references, do this in another way? | 174 # TODO: fixup references, do this in another way? |
157 outs.backpatch() | 175 outs.backpatch() |
158 outs.backpatch() # Why two times? | 176 outs.backpatch() # Why two times? |
159 return c3b.ok | 177 return c3b.ok |