Mercurial > lcfOS
diff python/zcc.py @ 292:534b94b40aa8
Fixup reorganize
author | Windel Bouwman |
---|---|
date | Wed, 27 Nov 2013 08:06:42 +0100 |
parents | 7b38782ed496 |
children | 6aa721e7b10b |
line wrap: on
line diff
--- a/python/zcc.py Sun Nov 24 11:24:15 2013 +0100 +++ b/python/zcc.py Wed Nov 27 08:06:42 2013 +0100 @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python import sys import argparse @@ -8,7 +8,7 @@ import ppci import codegen import outstream -import hexfile +from utils import HexFile import target @@ -23,7 +23,8 @@ target_list = [target.armtarget] -targetnames = {t.name: t for t in target_list} +targets = {t.name: t for t in target_list} +targetnames = list(targets.keys()) # Parse arguments: parser = argparse.ArgumentParser(description='lcfos Compiler') @@ -37,14 +38,14 @@ parser.add_argument('--dumpasm', action='store_true', help="Dump ASM-code") parser.add_argument('--optimize', action='store_true', help="Optimize") parser.add_argument('--target', help="Backend selection", - choices=targetnames.keys()) + choices=targetnames, required=True) parser.add_argument('-o', '--output', help='Output file', metavar='filename') parser.add_argument('--hexfile', help='Output hexfile', type=argparse.FileType('w')) parser.add_argument('--log', help='Log level (INFO,DEBUG)', type=logLevel) -def zcc(srcs, imps, outs, diag, dumpir=False): +def zcc(srcs, imps, tg, outs, diag, dumpir=False): """ Compile sources into output stream. Sources is an iterable of open files. @@ -52,9 +53,14 @@ logging.info('Zcc started') # Front end: c3b = c3.Builder(diag) - tg = target.armtarget.armtarget - # TODO select target here! - cg = codegen.CodeGenerator(outs, tg) + cg = codegen.CodeGenerator(tg) + + # TODO: remove this arm specifics: + outs.getSection('code').address = 0x08000000 + outs.getSection('data').address = 0x20000000 + + # Emit some custom start code: + tg.startCode(outs) for ircode in c3b.build(srcs, imps): if not ircode: return @@ -65,7 +71,10 @@ ircode.dump() # Code generation: - cg.generate(ircode) + cg.generate(ircode, outs) + # TODO: fixup references, do this in another way? + outs.backpatch() + outs.backpatch() # Why two times? return c3b.ok @@ -73,11 +82,11 @@ logging.basicConfig(format=logformat, level=args.log) src = args.source imps = args.imp + tg = targets[args.target] diag = ppci.DiagnosticsManager() outs = outstream.TextOutputStream() - # Invoke compiler: - res = zcc(src, imps, outs, diag, dumpir=args.dumpir) + res = zcc(src, imps, tg, outs, diag, dumpir=args.dumpir) if not res: diag.printErrors(src) return 1 @@ -93,7 +102,7 @@ if args.hexfile: logging.info('Creating hexfile') - hf = hexfile.HexFile() + hf = HexFile() hf.addRegion(0x08000000, code_bytes) hf.save(args.hexfile) return 0