annotate 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
rev   line source
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
1 #!/usr/bin/python
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
2
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
3 import sys, os, argparse
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
4 import c3, ppci
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
5
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
6 parser = argparse.ArgumentParser(description='lcfos Compiler')
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
7 parser.add_argument('source', type=argparse.FileType('r'), help='the source file to build')
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
8 args = parser.parse_args()
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
9
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
10 # Building:
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
11 src = args.source.read()
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
12 diag = ppci.DiagnosticsManager()
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
13 c3b = c3.Builder(diag)
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
14
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
15 ircode = c3b.build(src)
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
16 if not ircode:
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
17 diag.printErrors(src)
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
18 sys.exit(1)
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
19
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
20 # optionally run passes here:
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
21 # TODO
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
22
106
f2d980eef509 improved code generation
Windel Bouwman
parents: 105
diff changeset
23 print('stage 3: Code generation')
f2d980eef509 improved code generation
Windel Bouwman
parents: 105
diff changeset
24 asmWriter = core.AsmWriter()
f2d980eef509 improved code generation
Windel Bouwman
parents: 105
diff changeset
25 asmWriter.printModule(module)
f2d980eef509 improved code generation
Windel Bouwman
parents: 105
diff changeset
26
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
27 # Generate code:
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
28 bitcodeWriter = core.BitcodeWriter()
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
29 with open(args.source + '.bc', 'wb') as f:
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
30 bitcodeWriter.WriteModuleToFile(module, f)
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
31