comparison 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
comparison
equal deleted inserted replaced
203:ca1ea402f6a1 204:de3a68f677a5
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 import sys, os, argparse 3 import sys, os, argparse
4 from ppci import core, frontends 4 import c3, ppci
5 5
6 parser = argparse.ArgumentParser(description='K# to bitcode compiler') 6 parser = argparse.ArgumentParser(description='lcfos Compiler')
7 parser.add_argument('source', type=str, help='the source file to build') 7 parser.add_argument('source', type=argparse.FileType('r'), help='the source file to build')
8 args = parser.parse_args() 8 args = parser.parse_args()
9 9
10 try: 10 # Building:
11 with open(args.source, 'r') as f: 11 src = args.source.read()
12 src = f.read() 12 diag = ppci.DiagnosticsManager()
13 except IOError: 13 c3b = c3.Builder(diag)
14 print('Failed to load {0}'.format(args.source)) 14
15 sys.exit(1) 15 ircode = c3b.build(src)
16 print('stage 1: Parsing') 16 if not ircode:
17 # Create a context and a frontend: 17 diag.printErrors(src)
18 context = core.Context() 18 sys.exit(1)
19 frontend = frontends.KsFrontend(context)
20 try:
21 module = frontend.compilesource(src)
22 except core.CompilerException as e:
23 print(e)
24 lines = src.split(os.linesep)
25 row = e.row
26 col = e.col
27 line = lines[row - 1]
28 print('{0}:{1}'.format(row, line))
29 print(' ' * col + '^')
30 raise
31 #sys.exit(2)
32 19
33 # optionally run passes here: 20 # optionally run passes here:
34 # TODO 21 # TODO
35 22
36 print('stage 3: Code generation') 23 print('stage 3: Code generation')