Mercurial > lcfOS
diff python/zcc.py @ 329:8f6f3ace4e78
Added build tasks
author | Windel Bouwman |
---|---|
date | Wed, 05 Feb 2014 21:29:31 +0100 |
parents | e9fe6988497c |
children | a78b41ff6ad2 |
line wrap: on
line diff
--- a/python/zcc.py Tue Feb 04 09:01:11 2014 +0100 +++ b/python/zcc.py Wed Feb 05 21:29:31 2014 +0100 @@ -4,17 +4,15 @@ import argparse import logging -from ppci.c3 import Builder, AstPrinter -import ppci -from ppci.irutils import Verifier, Writer -from ppci.codegen import CodeGenerator +from ppci.c3 import AstPrinter +from ppci.buildtasks import Compile +from ppci.tasks import TaskRunner import outstream from utils import HexFile import target from target.target_list import target_list from ppci import irutils import io -from ppci.transform import CleanPass, RemoveAddZero logformat='%(asctime)s|%(levelname)s|%(name)s|%(message)s' @@ -123,63 +121,19 @@ parser.add_argument('-i', '--imp', type=argparse.FileType('r'), \ help='Possible import module', action='append', default=[]) +#sub_parsers = parser.add_subparsers() +#recipe = sub_parsers.add_parser('recipe') parser.add_argument('--optimize', action='store_true', help="Optimize") parser.add_argument('--target', help="Backend selection", 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,[WARN])', +parser.add_argument('--log', help='Log level (INFO,DEBUG,[WARN])', type=logLevel, default='WARN') parser.add_argument('--report', - help='Specify a file to write the compile report to', + help='Specify a file to write the compile report to', type=argparse.FileType('w')) -def zcc(srcs, imps, tg, outs, diag): - """ - Compiler driver - Compile sources into output stream. - Sources is an iterable of open files. - """ - logger = logging.getLogger('zcc') - logger.info('Zcc started {}'.format(srcs)) - # Front end: - c3b = Builder(diag, tg) - cg = 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 - - d = {'ircode':ircode} - logger.info('Verifying code {}'.format(ircode), extra=d) - Verifier().verify(ircode) - - # Optimization passes: - CleanPass().run(ircode) - Verifier().verify(ircode) - RemoveAddZero().run(ircode) - Verifier().verify(ircode) - CleanPass().run(ircode) - Verifier().verify(ircode) - - # Code generation: - d = {'ircode':ircode} - logger.info('Starting code generation for {}'.format(ircode), extra=d) - cg.generate(ircode, outs) - # TODO: fixup references, do this in another way? - outs.backpatch() - outs.backpatch() # Why two times? - return c3b.ok - - def main(args): # Configure some logging: logging.getLogger().setLevel(logging.DEBUG) @@ -193,14 +147,14 @@ logging.getLogger().addHandler(fh) tg = targets[args.target] - diag = ppci.DiagnosticsManager() outs = outstream.TextOutputStream() - res = zcc(args.source, args.imp, tg, outs, diag) - if not res: - diag.printErrors() + tr = TaskRunner() + tr.add_task(Compile(args.source, args.imp, tg, outs)) + + res = tr.run_tasks() + if res > 0: return 1 - logging.info('Assembly created', extra={'zcc_outs':outs}) code_bytes = outs.sections['code'].to_bytes() @@ -209,12 +163,6 @@ with open(output_filename, 'wb') as f: f.write(code_bytes) - if args.hexfile: - logging.info('Creating hexfile') - hf = HexFile() - hf.addRegion(0x08000000, code_bytes) - hf.save(args.hexfile) - if args.report: logging.getLogger().removeHandler(fh) logging.getLogger().removeHandler(ch)