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