diff python/zcc.py @ 255:7416c923a02a

Added more logging
author Windel Bouwman
date Sun, 04 Aug 2013 15:10:10 +0200
parents 74c6a20302d5
children 04c19282a5aa
line wrap: on
line diff
--- a/python/zcc.py	Wed Jul 31 21:20:58 2013 +0200
+++ b/python/zcc.py	Sun Aug 04 15:10:10 2013 +0200
@@ -19,21 +19,23 @@
 parser.add_argument('source', type=argparse.FileType('r'), \
   help='the source file to build')
 parser.add_argument('--dumpir', action='store_true', help="Dump IR-code")
+parser.add_argument('--dumpasm', action='store_true', help="Dump ASM-code")
+parser.add_argument('--optimize', action='store_true', help="Optimize")
 parser.add_argument('-o', '--output', help='Output file', metavar='filename')
 parser.add_argument('--hexfile', help='Output hexfile', type=argparse.FileType('w'))
 parser.add_argument('--log', help='Log level (INFO,DEBUG)', type=logLevel)
 
-def zcc(src, outs, diag, dumpir=False):
+def zcc(src, outs, diag, dumpir=False, do_optimize=False):
+    logging.info('Zcc started')
     # Front end:
     c3b = c3.Builder(diag)
     ircode = c3b.build(src)
-    logging.info('Intermediate code generated')
     if not ircode:
         return
 
     # Optimization passes:
-    optimize(ircode)
-    logging.info('IR-code optimized')
+    if do_optimize:
+        optimize(ircode)
 
     if dumpir:
         ircode.dump()
@@ -44,21 +46,20 @@
     return True
 
 def main(args):
-    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=args.log)
+    logging.basicConfig(format='%(asctime)s %(levelname)s %(name)s %(message)s', level=args.log)
     src = args.source.read()
     args.source.close()
-    logging.info('Source loaded')
     diag = ppci.DiagnosticsManager()
     outs = outstream.TextOutputStream()
 
     # Invoke compiler:
-    res = zcc(src, outs, diag, dumpir=args.dumpir)
+    res = zcc(src, outs, diag, dumpir=args.dumpir, do_optimize=args.optimize)
     if not res:
         diag.printErrors(src)
         sys.exit(1)
 
-    #if args.dumpir:
-    #    outs.dump()
+    if args.dumpasm:
+        outs.dump()
 
     code_bytes = outs.sections['code'].to_bytes()
     #print('bytes:', code_bytes)
@@ -71,10 +72,10 @@
         f.write(code_bytes)
 
     if args.hexfile:
+        logging.info('Creating hexfile')
         hf = hexfile.HexFile()
         hf.addRegion(0x08000000, code_bytes)
         hf.save(args.hexfile)
-        logging.info('Hexfile created')
 
 if __name__ == '__main__':
     arguments = parser.parse_args()