diff python/zcc.py @ 207:8b2f20aae086

cleaning of files
author Windel Bouwman
date Sat, 29 Jun 2013 10:05:42 +0200
parents d77cb5962cc5
children 003c8a976fff
line wrap: on
line diff
--- a/python/zcc.py	Fri Jun 28 16:49:38 2013 +0200
+++ b/python/zcc.py	Sat Jun 29 10:05:42 2013 +0200
@@ -11,35 +11,41 @@
 parser.add_argument('source', type=argparse.FileType('r'), help='the source file to build')
 parser.add_argument('-d', '--dumpir', action='store_true', help="Dump IR-code")
 parser.add_argument('-o', '--output', help='Output file', metavar='filename')
-args = parser.parse_args()
 
-# Front end:
-src = args.source.read()
-diag = ppci.DiagnosticsManager()
-c3b = c3.Builder(diag)
+def main(args):
+    # Front end:
+    src = args.source.read()
+    args.source.close()
+    diag = ppci.DiagnosticsManager()
+    c3b = c3.Builder(diag)
 
-ircode = c3b.build(src)
-if not ircode:
-    diag.printErrors(src)
-    sys.exit(1)
+    ircode = c3b.build(src)
+    if not ircode:
+        diag.printErrors(src)
+        sys.exit(1)
 
-if args.dumpir:
-    ircode.dump()
+    if args.dumpir:
+        ircode.dump()
+
+    # Code generation:
 
-# Code generation:
+    #cg = codegen.CodeGenerator(arm_cm3.armtarget)
+    outs = outstream.TextOutputStream()
+    cg = codegenarm.ArmCodeGenerator(outs)
+    obj = cg.generate(ircode)
 
-#cg = codegen.CodeGenerator(arm_cm3.armtarget)
-outs = outstream.TextOutputStream()
-cg = codegenarm.ArmCodeGenerator(outs)
-obj = cg.generate(ircode)
+    if args.dumpir:
+        outs.dump()
 
-if args.dumpir:
-    outs.dump()
+    if args.output:
+        output_filename = args.output
+    else:
+        output_filename = 'lc.output'
 
-if args.output:
-    output_filename = args.output
-else:
-    output_filename = 'lc.output'
+    # TODO: store data
 
-# TODO: store data
+if __name__ == '__main__':
+    args = parser.parse_args()
+    print(args, type(args))
+    main(args)