diff 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
line wrap: on
line diff
--- a/python/zcc.py	Fri Jul 26 16:46:02 2013 +0200
+++ b/python/zcc.py	Fri Jul 26 20:26:05 2013 +0200
@@ -15,17 +15,12 @@
 parser.add_argument('-o', '--output', help='Output file', metavar='filename')
 parser.add_argument('--hexfile', help='Output hexfile', type=argparse.FileType('w'))
 
-def main(args):
+def zcc(src, outs, diag, dumpir=False):
     # 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)
+        return
 
     # Optimization passes:
     ircode.check()
@@ -36,14 +31,25 @@
     sidp.run(ircode)
     ircode.check()
 
-    if args.dumpir:
+    if dumpir:
         ircode.dump()
+
     # Code generation:
-
-    #cg = codegen.CodeGenerator(arm_cm3.armtarget)
-    outs = outstream.TextOutputStream()
     cg = codegenarm.ArmCodeGenerator(outs)
     obj = cg.generate(ircode)
+    return True
+
+def main(args):
+    src = args.source.read()
+    args.source.close()
+    diag = ppci.DiagnosticsManager()
+    outs = outstream.TextOutputStream()
+
+    # Invoke compiler:
+    res = zcc(src, outs, diag, dumpir=args.dumpir)
+    if not res:
+        diag.printErrors(src)
+        sys.exit(1)
 
     if args.dumpir:
         outs.dump()
@@ -54,6 +60,7 @@
         output_filename = args.output
     else:
         output_filename = 'b.output'
+
     with open(output_filename, 'wb') as f:
         f.write(code_bytes)