104
|
1 #!/usr/bin/python
|
|
2
|
213
|
3 import sys, argparse
|
205
|
4 import c3, ppci, codegen
|
|
5 import codegenarm
|
219
|
6 from transform import CleanPass
|
205
|
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
|
219
|
28 # Optimization passes:
|
|
29 cp = CleanPass()
|
|
30 cp.run(ircode)
|
|
31
|
207
|
32 if args.dumpir:
|
|
33 ircode.dump()
|
|
34 # Code generation:
|
205
|
35
|
207
|
36 #cg = codegen.CodeGenerator(arm_cm3.armtarget)
|
|
37 outs = outstream.TextOutputStream()
|
|
38 cg = codegenarm.ArmCodeGenerator(outs)
|
|
39 obj = cg.generate(ircode)
|
205
|
40
|
207
|
41 if args.dumpir:
|
|
42 outs.dump()
|
105
|
43
|
207
|
44 if args.output:
|
|
45 output_filename = args.output
|
|
46 else:
|
|
47 output_filename = 'lc.output'
|
106
|
48
|
207
|
49 # TODO: store data
|
104
|
50
|
207
|
51 if __name__ == '__main__':
|
213
|
52 arguments = parser.parse_args()
|
|
53 main(arguments)
|
205
|
54
|