annotate python/zcc.py @ 323:e9fe6988497c

Used burg for generating expressions
author Windel Bouwman
date Thu, 30 Jan 2014 19:03:24 +0100
parents 44f336460c2a
children 8f6f3ace4e78
rev   line source
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
1 #!/usr/bin/env python
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
2
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
3 import sys
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
4 import argparse
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
5 import logging
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
6
313
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
7 from ppci.c3 import Builder, AstPrinter
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
8 import ppci
312
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
9 from ppci.irutils import Verifier, Writer
301
6753763d3bec merge codegen into ppci package
Windel Bouwman
parents: 300
diff changeset
10 from ppci.codegen import CodeGenerator
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
11 import outstream
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
12 from utils import HexFile
290
7b38782ed496 File moves
Windel Bouwman
parents: 289
diff changeset
13 import target
323
e9fe6988497c Used burg for generating expressions
Windel Bouwman
parents: 322
diff changeset
14 from target.target_list import target_list
311
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 306
diff changeset
15 from ppci import irutils
ff665880a6b0 Added testcase for kernel and userspace
Windel Bouwman
parents: 306
diff changeset
16 import io
317
e30a77ae359b Added glue blocks
Windel Bouwman
parents: 316
diff changeset
17 from ppci.transform import CleanPass, RemoveAddZero
253
74c6a20302d5 Added better logging
Windel Bouwman
parents: 252
diff changeset
18
289
bd2593de3ff8 Semifix burn2
Windel Bouwman
parents: 288
diff changeset
19
281
4496cae24d7f Improved logview
Windel Bouwman
parents: 276
diff changeset
20 logformat='%(asctime)s|%(levelname)s|%(name)s|%(message)s'
4496cae24d7f Improved logview
Windel Bouwman
parents: 276
diff changeset
21
289
bd2593de3ff8 Semifix burn2
Windel Bouwman
parents: 288
diff changeset
22
253
74c6a20302d5 Added better logging
Windel Bouwman
parents: 252
diff changeset
23 def logLevel(s):
312
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
24 """ Converts a string to a valid logging level """
253
74c6a20302d5 Added better logging
Windel Bouwman
parents: 252
diff changeset
25 numeric_level = getattr(logging, s.upper(), None)
74c6a20302d5 Added better logging
Windel Bouwman
parents: 252
diff changeset
26 if not isinstance(numeric_level, int):
74c6a20302d5 Added better logging
Windel Bouwman
parents: 252
diff changeset
27 raise ValueError('Invalid log level: {}'.format(s))
74c6a20302d5 Added better logging
Windel Bouwman
parents: 252
diff changeset
28 return numeric_level
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
29
289
bd2593de3ff8 Semifix burn2
Windel Bouwman
parents: 288
diff changeset
30
312
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
31 class RstFormatter(logging.Formatter):
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
32 """ Formatter that tries to create an rst document """
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
33 def __init__(self):
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
34 super().__init__(fmt=logformat)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
35
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
36 def format(self, record):
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
37 s = super().format(record)
314
38f5f298ce0e Add log for interference graph
Windel Bouwman
parents: 313
diff changeset
38 s += '\n'
313
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
39 if hasattr(record, 'c3_ast'):
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
40 f = io.StringIO()
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
41 print('', file=f)
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
42 print('', file=f)
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
43 print('.. code::', file=f)
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
44 print('', file=f)
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
45 AstPrinter().printAst(record.c3_ast, f)
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
46 print('', file=f)
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
47 s += '\n' + f.getvalue()
312
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
48 if hasattr(record, 'ircode'):
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
49 f = io.StringIO()
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
50 print('', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
51 print('', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
52 print('.. code::', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
53 print('', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
54 Writer(' ').write(record.ircode, f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
55 print('', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
56 s += '\n' + f.getvalue()
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
57 if hasattr(record, 'irfunc'):
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
58 f = io.StringIO()
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
59 print('', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
60 print('', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
61 print('.. code::', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
62 print('', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
63 Writer(' ').write_function(record.irfunc, f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
64 print('', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
65 s += '\n' + f.getvalue()
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
66 if hasattr(record, 'ppci_frame'):
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
67 f = io.StringIO()
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
68 frame = record.ppci_frame
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
69 print('', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
70 print('.. code::', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
71 print('', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
72 print(' {}'.format(frame.name), file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
73 for i in frame.instructions:
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
74 print(' {}'.format(i),file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
75 print('', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
76 s += '\n' + f.getvalue()
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
77 if hasattr(record, 'ra_cfg'):
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
78 f = io.StringIO()
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
79 print('', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
80 print('', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
81 print('.. graphviz::', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
82 print('', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
83 print(' digraph G {', file=f)
316
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
84 print(' size="8,80";', file=f)
312
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
85 cfg = record.ra_cfg
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
86 cfg.to_dot(f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
87 print(' }', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
88 print('', file=f)
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
89 s += '\n' + f.getvalue()
314
38f5f298ce0e Add log for interference graph
Windel Bouwman
parents: 313
diff changeset
90 if hasattr(record, 'ra_ig'):
38f5f298ce0e Add log for interference graph
Windel Bouwman
parents: 313
diff changeset
91 f = io.StringIO()
38f5f298ce0e Add log for interference graph
Windel Bouwman
parents: 313
diff changeset
92 print('', file=f)
38f5f298ce0e Add log for interference graph
Windel Bouwman
parents: 313
diff changeset
93 print('', file=f)
38f5f298ce0e Add log for interference graph
Windel Bouwman
parents: 313
diff changeset
94 print('.. graphviz::', file=f)
38f5f298ce0e Add log for interference graph
Windel Bouwman
parents: 313
diff changeset
95 print('', file=f)
38f5f298ce0e Add log for interference graph
Windel Bouwman
parents: 313
diff changeset
96 print(' digraph G {', file=f)
316
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
97 print(' ratio="compress";', file=f)
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
98 print(' size="8,80";', file=f)
314
38f5f298ce0e Add log for interference graph
Windel Bouwman
parents: 313
diff changeset
99 ig = record.ra_ig
38f5f298ce0e Add log for interference graph
Windel Bouwman
parents: 313
diff changeset
100 ig.to_dot(f)
38f5f298ce0e Add log for interference graph
Windel Bouwman
parents: 313
diff changeset
101 print(' }', file=f)
38f5f298ce0e Add log for interference graph
Windel Bouwman
parents: 313
diff changeset
102 print('', file=f)
38f5f298ce0e Add log for interference graph
Windel Bouwman
parents: 313
diff changeset
103 s += '\n' + f.getvalue()
316
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
104 if hasattr(record, 'zcc_outs'):
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
105 f = io.StringIO()
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
106 print('', file=f)
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
107 print('', file=f)
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
108 print('.. code::', file=f)
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
109 print('', file=f)
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
110 outstream.OutputStreamWriter(' ').dump(record.zcc_outs, f)
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
111 print('', file=f)
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
112 s += '\n' + f.getvalue()
312
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
113 return s
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
114
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
115
323
e9fe6988497c Used burg for generating expressions
Windel Bouwman
parents: 322
diff changeset
116 targets = {t.name: t for t in target_list}
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
117 targetnames = list(targets.keys())
290
7b38782ed496 File moves
Windel Bouwman
parents: 289
diff changeset
118
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
119 # Parse arguments:
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
120 parser = argparse.ArgumentParser(description='lcfos Compiler')
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 207
diff changeset
121 parser.add_argument('source', type=argparse.FileType('r'), \
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
122 help='the source file to build', nargs="+")
290
7b38782ed496 File moves
Windel Bouwman
parents: 289
diff changeset
123 parser.add_argument('-i', '--imp', type=argparse.FileType('r'), \
296
9417caea2eb3 Directorized some backend files
Windel Bouwman
parents: 293
diff changeset
124 help='Possible import module', action='append', default=[])
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
125
255
7416c923a02a Added more logging
Windel Bouwman
parents: 253
diff changeset
126 parser.add_argument('--optimize', action='store_true', help="Optimize")
290
7b38782ed496 File moves
Windel Bouwman
parents: 289
diff changeset
127 parser.add_argument('--target', help="Backend selection",
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
128 choices=targetnames, required=True)
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
129 parser.add_argument('-o', '--output', help='Output file', metavar='filename')
290
7b38782ed496 File moves
Windel Bouwman
parents: 289
diff changeset
130 parser.add_argument('--hexfile', help='Output hexfile',
7b38782ed496 File moves
Windel Bouwman
parents: 289
diff changeset
131 type=argparse.FileType('w'))
315
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
132 parser.add_argument('--log', help='Log level (INFO,DEBUG,[WARN])',
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
133 type=logLevel, default='WARN')
316
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
134 parser.add_argument('--report',
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
135 help='Specify a file to write the compile report to',
315
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
136 type=argparse.FileType('w'))
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
137
288
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
138
315
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
139 def zcc(srcs, imps, tg, outs, diag):
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
140 """
315
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
141 Compiler driver
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
142 Compile sources into output stream.
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
143 Sources is an iterable of open files.
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
144 """
316
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
145 logger = logging.getLogger('zcc')
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
146 logger.info('Zcc started {}'.format(srcs))
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
147 # Front end:
301
6753763d3bec merge codegen into ppci package
Windel Bouwman
parents: 300
diff changeset
148 c3b = Builder(diag, tg)
6753763d3bec merge codegen into ppci package
Windel Bouwman
parents: 300
diff changeset
149 cg = CodeGenerator(tg)
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
150
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
151 # TODO: remove this arm specifics:
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
152 outs.getSection('code').address = 0x08000000
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
153 outs.getSection('data').address = 0x20000000
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
154
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
155 # Emit some custom start code:
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
156 tg.startCode(outs)
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
157 for ircode in c3b.build(srcs, imps):
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
158 if not ircode:
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
159 return
313
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
160
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
161 d = {'ircode':ircode}
316
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
162 logger.info('Verifying code {}'.format(ircode), extra=d)
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
163 Verifier().verify(ircode)
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
164
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
165 # Optimization passes:
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
166 CleanPass().run(ircode)
312
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
167 Verifier().verify(ircode)
317
e30a77ae359b Added glue blocks
Windel Bouwman
parents: 316
diff changeset
168 RemoveAddZero().run(ircode)
e30a77ae359b Added glue blocks
Windel Bouwman
parents: 316
diff changeset
169 Verifier().verify(ircode)
e30a77ae359b Added glue blocks
Windel Bouwman
parents: 316
diff changeset
170 CleanPass().run(ircode)
e30a77ae359b Added glue blocks
Windel Bouwman
parents: 316
diff changeset
171 Verifier().verify(ircode)
289
bd2593de3ff8 Semifix burn2
Windel Bouwman
parents: 288
diff changeset
172
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
173 # Code generation:
312
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
174 d = {'ircode':ircode}
316
56e6ff84f646 Fixed burn led demo
Windel Bouwman
parents: 315
diff changeset
175 logger.info('Starting code generation for {}'.format(ircode), extra=d)
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
176 cg.generate(ircode, outs)
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
177 # TODO: fixup references, do this in another way?
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
178 outs.backpatch()
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
179 outs.backpatch() # Why two times?
288
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
180 return c3b.ok
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
181
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 246
diff changeset
182
e41e4109addd Added current position arrow
Windel Bouwman
parents: 246
diff changeset
183 def main(args):
315
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
184 # Configure some logging:
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
185 logging.getLogger().setLevel(logging.DEBUG)
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
186 ch = logging.StreamHandler()
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
187 ch.setFormatter(logging.Formatter(logformat))
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
188 ch.setLevel(args.log)
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
189 logging.getLogger().addHandler(ch)
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
190 if args.report:
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
191 fh = logging.StreamHandler(stream=args.report)
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
192 fh.setFormatter(RstFormatter())
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
193 logging.getLogger().addHandler(fh)
312
2c9768114877 Added cool logging formatter
Windel Bouwman
parents: 311
diff changeset
194
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
195 tg = targets[args.target]
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 246
diff changeset
196 diag = ppci.DiagnosticsManager()
e41e4109addd Added current position arrow
Windel Bouwman
parents: 246
diff changeset
197 outs = outstream.TextOutputStream()
e41e4109addd Added current position arrow
Windel Bouwman
parents: 246
diff changeset
198
315
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
199 res = zcc(args.source, args.imp, tg, outs, diag)
249
e41e4109addd Added current position arrow
Windel Bouwman
parents: 246
diff changeset
200 if not res:
293
6aa721e7b10b Try to improve build sequence
Windel Bouwman
parents: 292
diff changeset
201 diag.printErrors()
276
Windel Bouwman
parents: 272
diff changeset
202 return 1
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
203
313
04cf4d26a3bc Added constant function
Windel Bouwman
parents: 312
diff changeset
204 logging.info('Assembly created', extra={'zcc_outs':outs})
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
205
237
81752b0f85a5 Added burn led test program
Windel Bouwman
parents: 219
diff changeset
206 code_bytes = outs.sections['code'].to_bytes()
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
207 if args.output:
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
208 output_filename = args.output
287
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
209 with open(output_filename, 'wb') as f:
1c7c1e619be8 File movage
Windel Bouwman
parents: 281
diff changeset
210 f.write(code_bytes)
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
211
246
f254b87258e6 Added hexfile to zcc
Windel Bouwman
parents: 239
diff changeset
212 if args.hexfile:
255
7416c923a02a Added more logging
Windel Bouwman
parents: 253
diff changeset
213 logging.info('Creating hexfile')
292
534b94b40aa8 Fixup reorganize
Windel Bouwman
parents: 290
diff changeset
214 hf = HexFile()
246
f254b87258e6 Added hexfile to zcc
Windel Bouwman
parents: 239
diff changeset
215 hf.addRegion(0x08000000, code_bytes)
f254b87258e6 Added hexfile to zcc
Windel Bouwman
parents: 239
diff changeset
216 hf.save(args.hexfile)
315
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
217
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
218 if args.report:
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
219 logging.getLogger().removeHandler(fh)
084cccaa5deb Added console and screen
Windel Bouwman
parents: 314
diff changeset
220 logging.getLogger().removeHandler(ch)
276
Windel Bouwman
parents: 272
diff changeset
221 return 0
246
f254b87258e6 Added hexfile to zcc
Windel Bouwman
parents: 239
diff changeset
222
288
a747a45dcd78 Various styling work
Windel Bouwman
parents: 287
diff changeset
223
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
224 if __name__ == '__main__':
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 207
diff changeset
225 arguments = parser.parse_args()
276
Windel Bouwman
parents: 272
diff changeset
226 sys.exit(main(arguments))