Mercurial > lcfOS
diff python/zcc.py @ 204:de3a68f677a5
Added long comment to c3 parser
author | Windel Bouwman |
---|---|
date | Fri, 21 Jun 2013 15:01:08 +0200 |
parents | 1544e7a4aa98 |
children | d77cb5962cc5 |
line wrap: on
line diff
--- a/python/zcc.py Sat Jun 15 19:13:05 2013 +0200 +++ b/python/zcc.py Fri Jun 21 15:01:08 2013 +0200 @@ -1,34 +1,21 @@ #!/usr/bin/python import sys, os, argparse -from ppci import core, frontends +import c3, ppci -parser = argparse.ArgumentParser(description='K# to bitcode compiler') -parser.add_argument('source', type=str, help='the source file to build') +parser = argparse.ArgumentParser(description='lcfos Compiler') +parser.add_argument('source', type=argparse.FileType('r'), help='the source file to build') args = parser.parse_args() -try: - with open(args.source, 'r') as f: - src = f.read() -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 = frontends.KsFrontend(context) -try: - module = frontend.compilesource(src) -except core.CompilerException as e: - print(e) - 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) +# Building: +src = args.source.read() +diag = ppci.DiagnosticsManager() +c3b = c3.Builder(diag) + +ircode = c3b.build(src) +if not ircode: + diag.printErrors(src) + sys.exit(1) # optionally run passes here: # TODO