diff python/zcc.py @ 313:04cf4d26a3bc

Added constant function
author Windel Bouwman
date Wed, 18 Dec 2013 18:02:26 +0100
parents 2c9768114877
children 38f5f298ce0e
line wrap: on
line diff
--- a/python/zcc.py	Mon Dec 16 17:58:15 2013 +0100
+++ b/python/zcc.py	Wed Dec 18 18:02:26 2013 +0100
@@ -4,7 +4,7 @@
 import argparse
 import logging
 
-from ppci.c3 import Builder
+from ppci.c3 import Builder, AstPrinter
 import ppci
 from ppci.irutils import Verifier, Writer
 from ppci.codegen import CodeGenerator
@@ -33,6 +33,16 @@
 
     def format(self, record):
         s = super().format(record)
+        if hasattr(record, 'c3_ast'):
+            f = io.StringIO()
+            print('', file=f)
+            print('', file=f)
+            print('.. code::', file=f)
+            print('', file=f)
+            AstPrinter().printAst(record.c3_ast, f)
+            #Writer('  ').write(record.c3_ast, f)
+            print('', file=f)
+            s += '\n' + f.getvalue()
         if hasattr(record, 'ircode'):
             f = io.StringIO()
             print('', file=f)
@@ -90,7 +100,6 @@
   help='Possible import module', action='append', default=[])
 
 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('--target', help="Backend selection",
     choices=targetnames, required=True)
@@ -119,14 +128,12 @@
     for ircode in c3b.build(srcs, imps):
         if not ircode:
             return
+
+        d = {'ircode':ircode}
+        logging.info('Verifying code {}'.format(ircode), extra=d)
         # Optimization passes, TODO
         Verifier().verify(ircode)
 
-        if dumpir:
-            f = io.StringIO()
-            irutils.Writer().write(ircode, f)
-            print(f.getvalue())
-
         # Code generation:
         d = {'ircode':ircode}
         logging.info('Starting code generation for {}'.format(ircode), extra=d)
@@ -138,11 +145,11 @@
 
 
 def main(args):
-    logging.basicConfig(format=logformat, level=args.log)
+    #logging.getLogger().setLevel(logging.DEBUG)
     #logging.getLogger().addHandler(RstLogHandler())
-    fh = logging.FileHandler('log.rst', mode='w')
-    fh.setFormatter(RstFormatter())
-    logging.getLogger().addHandler(fh)
+    #fh = logging.FileHandler('log.rst', mode='w')
+    #fh.setFormatter(RstFormatter())
+    #logging.getLogger().addHandler(fh)
 
     tg = targets[args.target]
     diag = ppci.DiagnosticsManager()
@@ -153,8 +160,7 @@
         diag.printErrors()
         return 1
 
-    if args.dumpasm:
-        outs.dump()
+    logging.info('Assembly created', extra={'zcc_outs':outs})
 
     code_bytes = outs.sections['code'].to_bytes()
     if args.output: