Mercurial > lcfOS
comparison python/zcc.py @ 246:f254b87258e6
Added hexfile to zcc
author | Windel Bouwman |
---|---|
date | Thu, 25 Jul 2013 08:11:30 +0200 |
parents | 63bb40758066 |
children | e41e4109addd |
comparison
equal
deleted
inserted
replaced
245:66912720d712 | 246:f254b87258e6 |
---|---|
3 import sys, argparse | 3 import sys, argparse |
4 import c3, ppci, codegen | 4 import c3, ppci, codegen |
5 import codegenarm | 5 import codegenarm |
6 from transform import CleanPass, SameImmLoadDeletePass | 6 from transform import CleanPass, SameImmLoadDeletePass |
7 import outstream | 7 import outstream |
8 import hexfile | |
8 | 9 |
9 # Parse arguments: | 10 # Parse arguments: |
10 parser = argparse.ArgumentParser(description='lcfos Compiler') | 11 parser = argparse.ArgumentParser(description='lcfos Compiler') |
11 parser.add_argument('source', type=argparse.FileType('r'), \ | 12 parser.add_argument('source', type=argparse.FileType('r'), \ |
12 help='the source file to build') | 13 help='the source file to build') |
13 parser.add_argument('-d', '--dumpir', action='store_true', help="Dump IR-code") | 14 parser.add_argument('-d', '--dumpir', action='store_true', help="Dump IR-code") |
14 parser.add_argument('-o', '--output', help='Output file', metavar='filename') | 15 parser.add_argument('-o', '--output', help='Output file', metavar='filename') |
16 parser.add_argument('--hexfile', help='Output hexfile', type=argparse.FileType('w')) | |
15 | 17 |
16 def main(args): | 18 def main(args): |
17 # Front end: | 19 # Front end: |
18 src = args.source.read() | 20 src = args.source.read() |
19 args.source.close() | 21 args.source.close() |
53 else: | 55 else: |
54 output_filename = 'b.output' | 56 output_filename = 'b.output' |
55 with open(output_filename, 'wb') as f: | 57 with open(output_filename, 'wb') as f: |
56 f.write(code_bytes) | 58 f.write(code_bytes) |
57 | 59 |
60 if args.hexfile: | |
61 hf = hexfile.HexFile() | |
62 hf.addRegion(0x08000000, code_bytes) | |
63 hf.save(args.hexfile) | |
64 | |
58 if __name__ == '__main__': | 65 if __name__ == '__main__': |
59 arguments = parser.parse_args() | 66 arguments = parser.parse_args() |
60 main(arguments) | 67 main(arguments) |
61 | 68 |