comparison 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
comparison
equal deleted inserted replaced
204:de3a68f677a5 205:d77cb5962cc5
1 #!/usr/bin/python 1 #!/usr/bin/python
2 2
3 import sys, os, argparse 3 import sys, os, argparse
4 import c3, ppci 4 import c3, ppci, codegen
5 import arm_cm3
6 import codegenarm
7 import outstream
5 8
9 # Parse arguments:
6 parser = argparse.ArgumentParser(description='lcfos Compiler') 10 parser = argparse.ArgumentParser(description='lcfos Compiler')
7 parser.add_argument('source', type=argparse.FileType('r'), help='the source file to build') 11 parser.add_argument('source', type=argparse.FileType('r'), help='the source file to build')
12 parser.add_argument('-d', '--dumpir', action='store_true', help="Dump IR-code")
13 parser.add_argument('-o', '--output', help='Output file', metavar='filename')
8 args = parser.parse_args() 14 args = parser.parse_args()
9 15
10 # Building: 16 # Front end:
11 src = args.source.read() 17 src = args.source.read()
12 diag = ppci.DiagnosticsManager() 18 diag = ppci.DiagnosticsManager()
13 c3b = c3.Builder(diag) 19 c3b = c3.Builder(diag)
14 20
15 ircode = c3b.build(src) 21 ircode = c3b.build(src)
16 if not ircode: 22 if not ircode:
17 diag.printErrors(src) 23 diag.printErrors(src)
18 sys.exit(1) 24 sys.exit(1)
19 25
20 # optionally run passes here: 26 if args.dumpir:
21 # TODO 27 ircode.dump()
22 28
23 print('stage 3: Code generation') 29 # Code generation:
24 asmWriter = core.AsmWriter()
25 asmWriter.printModule(module)
26 30
27 # Generate code: 31 #cg = codegen.CodeGenerator(arm_cm3.armtarget)
28 bitcodeWriter = core.BitcodeWriter() 32 outs = outstream.TextOutputStream()
29 with open(args.source + '.bc', 'wb') as f: 33 cg = codegenarm.ArmCodeGenerator(outs)
30 bitcodeWriter.WriteModuleToFile(module, f) 34 obj = cg.generate(ircode)
31 35
36 if args.dumpir:
37 outs.dump()
38
39 if args.output:
40 output_filename = args.output
41 else:
42 output_filename = 'lc.output'
43
44 # TODO: store data
45