Mercurial > lcfOS
comparison python/zcc.py @ 288:a747a45dcd78
Various styling work
author | Windel Bouwman |
---|---|
date | Thu, 21 Nov 2013 14:26:13 +0100 |
parents | 1c7c1e619be8 |
children | bd2593de3ff8 |
comparison
equal
deleted
inserted
replaced
287:1c7c1e619be8 | 288:a747a45dcd78 |
---|---|
34 parser.add_argument('--target', help="Backend selection") | 34 parser.add_argument('--target', help="Backend selection") |
35 parser.add_argument('-o', '--output', help='Output file', metavar='filename') | 35 parser.add_argument('-o', '--output', help='Output file', metavar='filename') |
36 parser.add_argument('--hexfile', help='Output hexfile', type=argparse.FileType('w')) | 36 parser.add_argument('--hexfile', help='Output hexfile', type=argparse.FileType('w')) |
37 parser.add_argument('--log', help='Log level (INFO,DEBUG)', type=logLevel) | 37 parser.add_argument('--log', help='Log level (INFO,DEBUG)', type=logLevel) |
38 | 38 |
39 def zcc(srcs, outs, diag, dumpir=False, do_optimize=False): | 39 |
40 def zcc(srcs, imps, outs, diag, dumpir=False): | |
40 """ | 41 """ |
41 Compile sources into output stream. | 42 Compile sources into output stream. |
42 Sources is an iterable of open files. | 43 Sources is an iterable of open files. |
43 """ | 44 """ |
44 logging.info('Zcc started') | 45 logging.info('Zcc started') |
45 # Front end: | 46 # Front end: |
46 c3b = c3.Builder(diag) | 47 c3b = c3.Builder(diag) |
47 imps = [] | |
48 for ircode in c3b.build(srcs, imps): | 48 for ircode in c3b.build(srcs, imps): |
49 print(ircode) | |
50 if not ircode: | 49 if not ircode: |
51 return | 50 return |
52 | 51 |
53 # Optimization passes: | 52 # Optimization passes: |
54 if do_optimize: | 53 optimize(ircode) |
55 optimize(ircode) | 54 |
56 | |
57 if dumpir: | 55 if dumpir: |
58 ircode.dump() | 56 ircode.dump() |
59 | 57 |
58 # TODO select target here! | |
60 # Code generation: | 59 # Code generation: |
61 cg = codegenarm.ArmCodeGenerator(outs) | 60 codegenarm.ArmCodeGenerator(outs).generate(ircode) |
62 obj = cg.generate(ircode) | 61 return c3b.ok |
63 return True | 62 |
64 | 63 |
65 def main(args): | 64 def main(args): |
66 logging.basicConfig(format=logformat, level=args.log) | 65 logging.basicConfig(format=logformat, level=args.log) |
67 src = args.source | 66 src = args.source |
67 imps = getattr(args, 'import') | |
68 diag = ppci.DiagnosticsManager() | 68 diag = ppci.DiagnosticsManager() |
69 outs = outstream.TextOutputStream() | 69 outs = outstream.TextOutputStream() |
70 | 70 |
71 # Invoke compiler: | 71 # Invoke compiler: |
72 res = zcc(src, outs, diag, dumpir=args.dumpir, do_optimize=args.optimize) | 72 res = zcc(src, imps, outs, diag, dumpir=args.dumpir) |
73 if not res: | 73 if not res: |
74 diag.printErrors(src) | 74 diag.printErrors(src) |
75 return 1 | 75 return 1 |
76 | 76 |
77 if args.dumpasm: | 77 if args.dumpasm: |
88 hf = hexfile.HexFile() | 88 hf = hexfile.HexFile() |
89 hf.addRegion(0x08000000, code_bytes) | 89 hf.addRegion(0x08000000, code_bytes) |
90 hf.save(args.hexfile) | 90 hf.save(args.hexfile) |
91 return 0 | 91 return 0 |
92 | 92 |
93 | |
93 if __name__ == '__main__': | 94 if __name__ == '__main__': |
94 arguments = parser.parse_args() | 95 arguments = parser.parse_args() |
95 print(arguments) | |
96 sys.exit(main(arguments)) | 96 sys.exit(main(arguments)) |
97 |