Mercurial > lcfOS
comparison python/zcc.py @ 105:6a303f835c6d
Removed compilers directory
author | Windel Bouwman |
---|---|
date | Mon, 31 Dec 2012 17:35:17 +0100 |
parents | ed230e947dc6 |
children | f2d980eef509 |
comparison
equal
deleted
inserted
replaced
104:ed230e947dc6 | 105:6a303f835c6d |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 | 2 |
3 import sys, os, argparse | 3 import sys, os, argparse |
4 from ppci.compilers import KsCompiler | 4 from ppci import core |
5 from ppci.core import BitcodeWriter | |
6 | 5 |
7 if __name__ == '__main__': | 6 parser = argparse.ArgumentParser(description='K# to bitcode compiler') |
8 parser = argparse.ArgumentParser(description='K# to bitcode compiler') | 7 parser.add_argument('source', type=str, help='the source file to build') |
9 parser.add_argument('source', type=str, help='the source file to build') | 8 args = parser.parse_args() |
10 args = parser.parse_args() | |
11 | 9 |
12 print(args) | 10 try: |
13 try: | 11 with open(args.source, 'r') as f: |
14 with open(args.source, 'r') as f: | 12 src = f.read() |
15 src = f.read() | 13 except IOError: |
16 except IOError: | 14 print('Failed to load {0}'.format(args.source)) |
17 print('Failed to load {0}'.format(args.project)) | 15 sys.exit(1) |
18 sys.exit(3) | |
19 c = KsCompiler() | |
20 module = c.compilesource(src) | |
21 | 16 |
22 with open('sjaak.bc', 'wb') as f: | 17 # Create a context and a frontend: |
23 BitcodeWriter().WriteModuleToFile(module, f) | 18 context = core.Context() |
19 frontend = core.frontends.ks.KsFrontend(context) | |
20 try: | |
21 module = frontend.compilesource(src) | |
22 except core.CompilerException as e: | |
23 print(e) | |
24 sys.exit(2) | |
25 | |
26 # optionally run passes here: | |
27 # TODO | |
28 | |
29 # Generate code: | |
30 bitcodeWriter = core.BitcodeWriter() | |
31 with open(args.source + '.bc', 'wb') as f: | |
32 bitcodeWriter.WriteModuleToFile(module, f) | |
24 | 33 |
25 | 34 |
26 | 35 |