104
|
1 #!/usr/bin/python
|
|
2
|
|
3 import sys, os, argparse
|
204
|
4 import c3, ppci
|
105
|
5
|
204
|
6 parser = argparse.ArgumentParser(description='lcfos Compiler')
|
|
7 parser.add_argument('source', type=argparse.FileType('r'), help='the source file to build')
|
105
|
8 args = parser.parse_args()
|
104
|
9
|
204
|
10 # Building:
|
|
11 src = args.source.read()
|
|
12 diag = ppci.DiagnosticsManager()
|
|
13 c3b = c3.Builder(diag)
|
|
14
|
|
15 ircode = c3b.build(src)
|
|
16 if not ircode:
|
|
17 diag.printErrors(src)
|
|
18 sys.exit(1)
|
104
|
19
|
105
|
20 # optionally run passes here:
|
|
21 # TODO
|
|
22
|
106
|
23 print('stage 3: Code generation')
|
|
24 asmWriter = core.AsmWriter()
|
|
25 asmWriter.printModule(module)
|
|
26
|
105
|
27 # Generate code:
|
|
28 bitcodeWriter = core.BitcodeWriter()
|
|
29 with open(args.source + '.bc', 'wb') as f:
|
|
30 bitcodeWriter.WriteModuleToFile(module, f)
|
104
|
31
|