Mercurial > lcfOS
comparison python/zcc.py @ 249:e41e4109addd
Added current position arrow
author | Windel Bouwman |
---|---|
date | Fri, 26 Jul 2013 20:26:05 +0200 |
parents | f254b87258e6 |
children | c4370696ccc7 |
comparison
equal
deleted
inserted
replaced
248:b10d46e5c8dd | 249:e41e4109addd |
---|---|
13 help='the source file to build') | 13 help='the source file to build') |
14 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") |
15 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')) | 16 parser.add_argument('--hexfile', help='Output hexfile', type=argparse.FileType('w')) |
17 | 17 |
18 def main(args): | 18 def zcc(src, outs, diag, dumpir=False): |
19 # Front end: | 19 # Front end: |
20 src = args.source.read() | |
21 args.source.close() | |
22 diag = ppci.DiagnosticsManager() | |
23 c3b = c3.Builder(diag) | 20 c3b = c3.Builder(diag) |
24 | |
25 ircode = c3b.build(src) | 21 ircode = c3b.build(src) |
26 if not ircode: | 22 if not ircode: |
27 diag.printErrors(src) | 23 return |
28 sys.exit(1) | |
29 | 24 |
30 # Optimization passes: | 25 # Optimization passes: |
31 ircode.check() | 26 ircode.check() |
32 cp = CleanPass() | 27 cp = CleanPass() |
33 cp.run(ircode) | 28 cp.run(ircode) |
34 ircode.check() | 29 ircode.check() |
35 sidp = SameImmLoadDeletePass() | 30 sidp = SameImmLoadDeletePass() |
36 sidp.run(ircode) | 31 sidp.run(ircode) |
37 ircode.check() | 32 ircode.check() |
38 | 33 |
39 if args.dumpir: | 34 if dumpir: |
40 ircode.dump() | 35 ircode.dump() |
36 | |
41 # Code generation: | 37 # Code generation: |
42 | |
43 #cg = codegen.CodeGenerator(arm_cm3.armtarget) | |
44 outs = outstream.TextOutputStream() | |
45 cg = codegenarm.ArmCodeGenerator(outs) | 38 cg = codegenarm.ArmCodeGenerator(outs) |
46 obj = cg.generate(ircode) | 39 obj = cg.generate(ircode) |
40 return True | |
41 | |
42 def main(args): | |
43 src = args.source.read() | |
44 args.source.close() | |
45 diag = ppci.DiagnosticsManager() | |
46 outs = outstream.TextOutputStream() | |
47 | |
48 # Invoke compiler: | |
49 res = zcc(src, outs, diag, dumpir=args.dumpir) | |
50 if not res: | |
51 diag.printErrors(src) | |
52 sys.exit(1) | |
47 | 53 |
48 if args.dumpir: | 54 if args.dumpir: |
49 outs.dump() | 55 outs.dump() |
50 | 56 |
51 code_bytes = outs.sections['code'].to_bytes() | 57 code_bytes = outs.sections['code'].to_bytes() |
52 #print('bytes:', code_bytes) | 58 #print('bytes:', code_bytes) |
53 if args.output: | 59 if args.output: |
54 output_filename = args.output | 60 output_filename = args.output |
55 else: | 61 else: |
56 output_filename = 'b.output' | 62 output_filename = 'b.output' |
63 | |
57 with open(output_filename, 'wb') as f: | 64 with open(output_filename, 'wb') as f: |
58 f.write(code_bytes) | 65 f.write(code_bytes) |
59 | 66 |
60 if args.hexfile: | 67 if args.hexfile: |
61 hf = hexfile.HexFile() | 68 hf = hexfile.HexFile() |