comparison python/zcc.py @ 207:8b2f20aae086

cleaning of files
author Windel Bouwman
date Sat, 29 Jun 2013 10:05:42 +0200
parents d77cb5962cc5
children 003c8a976fff
comparison
equal deleted inserted replaced
206:6c6bf8890d8a 207:8b2f20aae086
9 # Parse arguments: 9 # Parse arguments:
10 parser = argparse.ArgumentParser(description='lcfos Compiler') 10 parser = argparse.ArgumentParser(description='lcfos Compiler')
11 parser.add_argument('source', type=argparse.FileType('r'), help='the source file to build') 11 parser.add_argument('source', type=argparse.FileType('r'), help='the source file to build')
12 parser.add_argument('-d', '--dumpir', action='store_true', help="Dump IR-code") 12 parser.add_argument('-d', '--dumpir', action='store_true', help="Dump IR-code")
13 parser.add_argument('-o', '--output', help='Output file', metavar='filename') 13 parser.add_argument('-o', '--output', help='Output file', metavar='filename')
14 args = parser.parse_args()
15 14
16 # Front end: 15 def main(args):
17 src = args.source.read() 16 # Front end:
18 diag = ppci.DiagnosticsManager() 17 src = args.source.read()
19 c3b = c3.Builder(diag) 18 args.source.close()
19 diag = ppci.DiagnosticsManager()
20 c3b = c3.Builder(diag)
20 21
21 ircode = c3b.build(src) 22 ircode = c3b.build(src)
22 if not ircode: 23 if not ircode:
23 diag.printErrors(src) 24 diag.printErrors(src)
24 sys.exit(1) 25 sys.exit(1)
25 26
26 if args.dumpir: 27 if args.dumpir:
27 ircode.dump() 28 ircode.dump()
28 29
29 # Code generation: 30 # Code generation:
30 31
31 #cg = codegen.CodeGenerator(arm_cm3.armtarget) 32 #cg = codegen.CodeGenerator(arm_cm3.armtarget)
32 outs = outstream.TextOutputStream() 33 outs = outstream.TextOutputStream()
33 cg = codegenarm.ArmCodeGenerator(outs) 34 cg = codegenarm.ArmCodeGenerator(outs)
34 obj = cg.generate(ircode) 35 obj = cg.generate(ircode)
35 36
36 if args.dumpir: 37 if args.dumpir:
37 outs.dump() 38 outs.dump()
38 39
39 if args.output: 40 if args.output:
40 output_filename = args.output 41 output_filename = args.output
41 else: 42 else:
42 output_filename = 'lc.output' 43 output_filename = 'lc.output'
43 44
44 # TODO: store data 45 # TODO: store data
45 46
47 if __name__ == '__main__':
48 args = parser.parse_args()
49 print(args, type(args))
50 main(args)
51