104
|
1 #!/usr/bin/python
|
|
2
|
|
3 import sys, os, argparse
|
205
|
4 import c3, ppci, codegen
|
|
5 import arm_cm3
|
|
6 import codegenarm
|
|
7 import outstream
|
105
|
8
|
205
|
9 # Parse arguments:
|
204
|
10 parser = argparse.ArgumentParser(description='lcfos Compiler')
|
|
11 parser.add_argument('source', type=argparse.FileType('r'), help='the source file to build')
|
205
|
12 parser.add_argument('-d', '--dumpir', action='store_true', help="Dump IR-code")
|
|
13 parser.add_argument('-o', '--output', help='Output file', metavar='filename')
|
105
|
14 args = parser.parse_args()
|
104
|
15
|
205
|
16 # Front end:
|
204
|
17 src = args.source.read()
|
|
18 diag = ppci.DiagnosticsManager()
|
|
19 c3b = c3.Builder(diag)
|
|
20
|
|
21 ircode = c3b.build(src)
|
|
22 if not ircode:
|
|
23 diag.printErrors(src)
|
|
24 sys.exit(1)
|
104
|
25
|
205
|
26 if args.dumpir:
|
|
27 ircode.dump()
|
|
28
|
|
29 # Code generation:
|
|
30
|
|
31 #cg = codegen.CodeGenerator(arm_cm3.armtarget)
|
|
32 outs = outstream.TextOutputStream()
|
|
33 cg = codegenarm.ArmCodeGenerator(outs)
|
|
34 obj = cg.generate(ircode)
|
105
|
35
|
205
|
36 if args.dumpir:
|
|
37 outs.dump()
|
106
|
38
|
205
|
39 if args.output:
|
|
40 output_filename = args.output
|
|
41 else:
|
|
42 output_filename = 'lc.output'
|
104
|
43
|
205
|
44 # TODO: store data
|
|
45
|