annotate python/zcc.py @ 220:3f6c30a5d234

Major change in expression parsing to enable pointers and structs
author Windel Bouwman
date Sat, 06 Jul 2013 21:32:20 +0200
parents 1fa3e0050b49
children 81752b0f85a5
rev   line source
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
1 #!/usr/bin/python
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
2
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 207
diff changeset
3 import sys, 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 codegenarm
219
1fa3e0050b49 Expanded ad hoc code generator
Windel Bouwman
parents: 218
diff changeset
6 from transform import CleanPass
205
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')
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 207
diff changeset
11 parser.add_argument('source', type=argparse.FileType('r'), \
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 207
diff changeset
12 help='the source file to build')
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
13 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
14 parser.add_argument('-o', '--output', help='Output file', metavar='filename')
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
15
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
16 def main(args):
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
17 # Front end:
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
18 src = args.source.read()
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
19 args.source.close()
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
20 diag = ppci.DiagnosticsManager()
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
21 c3b = c3.Builder(diag)
204
de3a68f677a5 Added long comment to c3 parser
Windel Bouwman
parents: 107
diff changeset
22
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
23 ircode = c3b.build(src)
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
24 if not ircode:
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
25 diag.printErrors(src)
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
26 sys.exit(1)
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
27
219
1fa3e0050b49 Expanded ad hoc code generator
Windel Bouwman
parents: 218
diff changeset
28 # Optimization passes:
1fa3e0050b49 Expanded ad hoc code generator
Windel Bouwman
parents: 218
diff changeset
29 cp = CleanPass()
1fa3e0050b49 Expanded ad hoc code generator
Windel Bouwman
parents: 218
diff changeset
30 cp.run(ircode)
1fa3e0050b49 Expanded ad hoc code generator
Windel Bouwman
parents: 218
diff changeset
31
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
32 if args.dumpir:
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
33 ircode.dump()
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
34 # Code generation:
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
35
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
36 #cg = codegen.CodeGenerator(arm_cm3.armtarget)
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
37 outs = outstream.TextOutputStream()
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
38 cg = codegenarm.ArmCodeGenerator(outs)
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
39 obj = cg.generate(ircode)
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
40
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
41 if args.dumpir:
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
42 outs.dump()
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
43
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
44 if args.output:
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
45 output_filename = args.output
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
46 else:
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
47 output_filename = 'lc.output'
106
f2d980eef509 improved code generation
Windel Bouwman
parents: 105
diff changeset
48
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
49 # TODO: store data
104
ed230e947dc6 Added hexviewer
windel
parents:
diff changeset
50
207
8b2f20aae086 cleaning of files
Windel Bouwman
parents: 205
diff changeset
51 if __name__ == '__main__':
213
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 207
diff changeset
52 arguments = parser.parse_args()
003c8a976fff Merge of semantics and parser again ..
Windel Bouwman
parents: 207
diff changeset
53 main(arguments)
205
d77cb5962cc5 Added some handcoded arm code generation
Windel Bouwman
parents: 204
diff changeset
54