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')
|
104
|
14
|
207
|
15 def main(args):
|
|
16 # Front end:
|
|
17 src = args.source.read()
|
|
18 args.source.close()
|
|
19 diag = ppci.DiagnosticsManager()
|
|
20 c3b = c3.Builder(diag)
|
204
|
21
|
207
|
22 ircode = c3b.build(src)
|
|
23 if not ircode:
|
|
24 diag.printErrors(src)
|
|
25 sys.exit(1)
|
104
|
26
|
207
|
27 if args.dumpir:
|
|
28 ircode.dump()
|
|
29
|
|
30 # Code generation:
|
205
|
31
|
207
|
32 #cg = codegen.CodeGenerator(arm_cm3.armtarget)
|
|
33 outs = outstream.TextOutputStream()
|
|
34 cg = codegenarm.ArmCodeGenerator(outs)
|
|
35 obj = cg.generate(ircode)
|
205
|
36
|
207
|
37 if args.dumpir:
|
|
38 outs.dump()
|
105
|
39
|
207
|
40 if args.output:
|
|
41 output_filename = args.output
|
|
42 else:
|
|
43 output_filename = 'lc.output'
|
106
|
44
|
207
|
45 # TODO: store data
|
104
|
46
|
207
|
47 if __name__ == '__main__':
|
|
48 args = parser.parse_args()
|
|
49 print(args, type(args))
|
|
50 main(args)
|
205
|
51
|