annotate python/zcc.py @ 205:d77cb5962cc5

Added some handcoded arm code generation
author Windel Bouwman
date Sun, 23 Jun 2013 18:23:18 +0200
parents de3a68f677a5
children 8b2f20aae086
rev   line source
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
1 #!/usr/bin/python
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
2
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
3 import sys, os, argparse
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
4 import c3, ppci, codegen
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
5 import arm_cm3
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
6 import codegenarm
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
7 import outstream
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
8
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
9 # Parse arguments:
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
10 parser = argparse.ArgumentParser(description='lcfos Compiler')
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
11 parser.add_argument('source', type=argparse.FileType('r'), help='the source file to build')
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
12 parser.add_argument('-d', '--dumpir', action='store_true', help="Dump IR-code")
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
13 parser.add_argument('-o', '--output', help='Output file', metavar='filename')
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
14 args = parser.parse_args()
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
15
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
16 # Front end:
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
17 src = args.source.read()
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
18 diag = ppci.DiagnosticsManager()
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
19 c3b = c3.Builder(diag)
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
20
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
21 ircode = c3b.build(src)
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
22 if not ircode:
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
23 diag.printErrors(src)
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
24 sys.exit(1)
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
25
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
26 if args.dumpir:
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
27 ircode.dump()
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
28
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
29 # Code generation:
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
30
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
31 #cg = codegen.CodeGenerator(arm_cm3.armtarget)
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
32 outs = outstream.TextOutputStream()
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
33 cg = codegenarm.ArmCodeGenerator(outs)
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
34 obj = cg.generate(ircode)
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
35
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
36 if args.dumpir:
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
37 outs.dump()
106
f2d980eef509 improved code generation
Windel Bouwman
parents: 105
diff changeset
38
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
39 if args.output:
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
40 output_filename = args.output
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
41 else:
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
42 output_filename = 'lc.output'
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
43
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
44 # TODO: store data
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
45