diff python/zcc.py @ 106:f2d980eef509

improved code generation
author Windel Bouwman
date Mon, 31 Dec 2012 18:26:56 +0100
parents 6a303f835c6d
children 1544e7a4aa98
line wrap: on
line diff
--- a/python/zcc.py	Mon Dec 31 17:35:17 2012 +0100
+++ b/python/zcc.py	Mon Dec 31 18:26:56 2012 +0100
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 
 import sys, os, argparse
-from ppci import core
+from ppci import core, frontends
 
 parser = argparse.ArgumentParser(description='K# to bitcode compiler')
 parser.add_argument('source', type=str, help='the source file to build')
@@ -13,19 +13,30 @@
 except IOError:
    print('Failed to load {0}'.format(args.source))
    sys.exit(1)
-
+print('stage 1: Parsing')
 # Create a context and a frontend:
 context = core.Context()
-frontend = core.frontends.ks.KsFrontend(context)
+frontend = frontends.KsFrontend(context)
 try:
    module = frontend.compilesource(src)
 except core.CompilerException as e:
    print(e)
-   sys.exit(2)
+   lines = src.split(os.linesep)
+   row = e.row
+   col = e.col
+   line = lines[row - 1]
+   print('{0}:{1}'.format(row, line))
+   print(' ' * col + '^')
+   raise
+   #sys.exit(2)
 
 # optionally run passes here:
 # TODO
 
+print('stage 3: Code generation')
+asmWriter = core.AsmWriter()
+asmWriter.printModule(module)
+
 # Generate code:
 bitcodeWriter = core.BitcodeWriter()
 with open(args.source + '.bc', 'wb') as f: