Mercurial > lcfOS
view python/ppci/buildtasks.py @ 331:a78b41ff6ad2
Added better recipe files
author | Windel Bouwman |
---|---|
date | Fri, 07 Feb 2014 12:39:59 +0100 |
parents | 8f6f3ace4e78 |
children | 87feb8a23b4d |
line wrap: on
line source
""" Defines task classes that can compile, link etc.. Task can depend upon one another. """ import logging from .c3 import Builder from .irutils import Verifier from .codegen import CodeGenerator from .transform import CleanPass, RemoveAddZero from .tasks import Task from . import DiagnosticsManager class BuildTask(Task): def __init__(self, name): super().__init__(name) self.logger = logging.getLogger('buildtask') class Assemble(BuildTask): def __init__(self): super().__init__('Assemble') def run(self): pass class Compile(BuildTask): """ Task that compiles source to some target """ def __init__(self, sources, includes, target, output_object): super().__init__('Compile') self.sources = sources self.includes = includes self.target = target self.output = output_object def run(self): self.logger.info('Zcc started {}'.format(self.sources)) diag = DiagnosticsManager() c3b = Builder(diag, self.target) cg = CodeGenerator(self.target) for ircode in c3b.build(self.sources, self.includes): if not ircode: return d = {'ircode':ircode} self.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} self.logger.info('Starting code generation for {}'.format(ircode), extra=d) cg.generate(ircode, self.output) # TODO: fixup references, do this in another way? self.output.backpatch() if not c3b.ok: diag.printErrors() raise TaskError('Compile errors') class Link(BuildTask): def __init__(self, objects, output_file): super().__init__('Link') class ObjCopy(Task): pass def load_recipe(recipe_file, runner): """ Loads a recipe dictionary into a task runner """ for command, value in recipe: if command == 'compile': sources = value[''] target = value['target'] runner.add_task(Compile()) else: raise Exception()