diff python/ppci/buildtasks.py @ 329:8f6f3ace4e78

Added build tasks
author Windel Bouwman
date Wed, 05 Feb 2014 21:29:31 +0100
parents
children a78b41ff6ad2
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/ppci/buildtasks.py	Wed Feb 05 21:29:31 2014 +0100
@@ -0,0 +1,85 @@
+
+"""
+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 Assemble(Task):
+    def __init__(self):
+        super().__init__('Assemble')
+
+    def run(self):
+        pass
+
+
+class Compile(Task):
+    """ 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):
+        logger = logging.getLogger('zcc')
+        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}
+            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, 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(Task):
+    def __init__(self, objects, output_file):
+        super().__init__('Link')
+
+
+class ObjCopy(Task):
+    pass
+
+
+def load_recipe(recipe, runner):
+    """ Loads a recipe dictionary into a task runner """
+    if 'compile' in recipe:
+        #sources =
+        runner.add_task(Compile())
+    else:
+        raise Exception()
+