Mercurial > lcfOS
diff python/zcc.py @ 290:7b38782ed496
File moves
author | Windel Bouwman |
---|---|
date | Sun, 24 Nov 2013 11:24:15 +0100 |
parents | bd2593de3ff8 |
children | 534b94b40aa8 |
line wrap: on
line diff
--- a/python/zcc.py Thu Nov 21 15:46:50 2013 +0100 +++ b/python/zcc.py Sun Nov 24 11:24:15 2013 +0100 @@ -7,10 +7,9 @@ import c3 import ppci import codegen -import codegenarm -from optimize import optimize import outstream import hexfile +import target logformat='%(asctime)s|%(levelname)s|%(name)s|%(message)s' @@ -23,20 +22,25 @@ return numeric_level +target_list = [target.armtarget] +targetnames = {t.name: t for t in target_list} + # Parse arguments: parser = argparse.ArgumentParser(description='lcfos Compiler') # Input: parser.add_argument('source', type=argparse.FileType('r'), \ help='the source file to build', nargs="+") -parser.add_argument('-i', '--import', type=argparse.FileType('r'), \ +parser.add_argument('-i', '--imp', type=argparse.FileType('r'), \ help='Possible import module', action='append') parser.add_argument('--dumpir', action='store_true', help="Dump IR-code") 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") +parser.add_argument('--target', help="Backend selection", + choices=targetnames.keys()) parser.add_argument('-o', '--output', help='Output file', metavar='filename') -parser.add_argument('--hexfile', help='Output hexfile', type=argparse.FileType('w')) +parser.add_argument('--hexfile', help='Output hexfile', + type=argparse.FileType('w')) parser.add_argument('--log', help='Log level (INFO,DEBUG)', type=logLevel) @@ -48,26 +52,27 @@ logging.info('Zcc started') # Front end: c3b = c3.Builder(diag) + tg = target.armtarget.armtarget + # TODO select target here! + cg = codegen.CodeGenerator(outs, tg) for ircode in c3b.build(srcs, imps): if not ircode: return - # Optimization passes: - optimize(ircode) + # Optimization passes, TODO if dumpir: ircode.dump() - # TODO select target here! # Code generation: - codegenarm.ArmCodeGenerator(outs).generate(ircode) + cg.generate(ircode) return c3b.ok def main(args): logging.basicConfig(format=logformat, level=args.log) src = args.source - imps = getattr(args, 'import') + imps = args.imp diag = ppci.DiagnosticsManager() outs = outstream.TextOutputStream()