Mercurial > lcfOS
comparison python/zcc.py @ 272:e64bae57cda8
refactor ir
author | Windel Bouwman |
---|---|
date | Sat, 31 Aug 2013 17:58:54 +0200 |
parents | 04c19282a5aa |
children | 56d37ed4b4d2 |
comparison
equal
deleted
inserted
replaced
271:cf7d5fb7d9c8 | 272:e64bae57cda8 |
---|---|
19 parser.add_argument('source', type=argparse.FileType('r'), \ | 19 parser.add_argument('source', type=argparse.FileType('r'), \ |
20 help='the source file to build') | 20 help='the source file to build') |
21 parser.add_argument('--dumpir', action='store_true', help="Dump IR-code") | 21 parser.add_argument('--dumpir', action='store_true', help="Dump IR-code") |
22 parser.add_argument('--dumpasm', action='store_true', help="Dump ASM-code") | 22 parser.add_argument('--dumpasm', action='store_true', help="Dump ASM-code") |
23 parser.add_argument('--optimize', action='store_true', help="Optimize") | 23 parser.add_argument('--optimize', action='store_true', help="Optimize") |
24 parser.add_argument('--package_dir', help="Look in this directory for packages") | |
24 parser.add_argument('-o', '--output', help='Output file', metavar='filename') | 25 parser.add_argument('-o', '--output', help='Output file', metavar='filename') |
25 parser.add_argument('--hexfile', help='Output hexfile', type=argparse.FileType('w')) | 26 parser.add_argument('--hexfile', help='Output hexfile', type=argparse.FileType('w')) |
26 parser.add_argument('--log', help='Log level (INFO,DEBUG)', type=logLevel) | 27 parser.add_argument('--log', help='Log level (INFO,DEBUG)', type=logLevel) |
27 | 28 |
28 def zcc(src, outs, diag, dumpir=False, do_optimize=False): | 29 def zcc(src, outs, diag, dumpir=False, do_optimize=False, pack_dir=None): |
29 logging.info('Zcc started') | 30 logging.info('Zcc started') |
30 # Front end: | 31 # Front end: |
31 c3b = c3.Builder(diag) | 32 c3b = c3.Builder(diag) |
32 ircode = c3b.build(src) | 33 ircode = c3b.build(src, pack_dir=pack_dir) |
33 if not ircode: | 34 if not ircode: |
34 return | 35 return |
35 | 36 |
36 # Optimization passes: | 37 # Optimization passes: |
37 if do_optimize: | 38 if do_optimize: |
53 args.source.close() | 54 args.source.close() |
54 diag = ppci.DiagnosticsManager() | 55 diag = ppci.DiagnosticsManager() |
55 outs = outstream.TextOutputStream() | 56 outs = outstream.TextOutputStream() |
56 | 57 |
57 # Invoke compiler: | 58 # Invoke compiler: |
58 res = zcc(src, outs, diag, dumpir=args.dumpir, do_optimize=args.optimize) | 59 res = zcc(src, outs, diag, dumpir=args.dumpir, do_optimize=args.optimize, pack_dir=args.package_dir) |
59 if not res: | 60 if not res: |
60 diag.printErrors(src) | 61 diag.printErrors(src) |
61 sys.exit(1) | 62 sys.exit(1) |
62 | 63 |
63 if args.dumpasm: | 64 if args.dumpasm: |