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

Added build tasks
author Windel Bouwman
date Wed, 05 Feb 2014 21:29:31 +0100
parents
children a78b41ff6ad2
comparison
equal deleted inserted replaced
328:0bb16d2a5699 329:8f6f3ace4e78
1
2 """
3 Defines task classes that can compile, link etc..
4 Task can depend upon one another.
5 """
6
7 import logging
8
9 from .c3 import Builder
10 from .irutils import Verifier
11 from .codegen import CodeGenerator
12 from .transform import CleanPass, RemoveAddZero
13 from .tasks import Task
14 from . import DiagnosticsManager
15
16
17 class Assemble(Task):
18 def __init__(self):
19 super().__init__('Assemble')
20
21 def run(self):
22 pass
23
24
25 class Compile(Task):
26 """ Task that compiles source to some target """
27 def __init__(self, sources, includes, target, output_object):
28 super().__init__('Compile')
29 self.sources = sources
30 self.includes = includes
31 self.target = target
32 self.output = output_object
33
34 def run(self):
35 logger = logging.getLogger('zcc')
36 logger.info('Zcc started {}'.format(self.sources))
37 diag = DiagnosticsManager()
38 c3b = Builder(diag, self.target)
39 cg = CodeGenerator(self.target)
40
41 for ircode in c3b.build(self.sources, self.includes):
42 if not ircode:
43 return
44
45 d = {'ircode':ircode}
46 logger.info('Verifying code {}'.format(ircode), extra=d)
47 Verifier().verify(ircode)
48
49 # Optimization passes:
50 CleanPass().run(ircode)
51 Verifier().verify(ircode)
52 RemoveAddZero().run(ircode)
53 Verifier().verify(ircode)
54 CleanPass().run(ircode)
55 Verifier().verify(ircode)
56
57 # Code generation:
58 d = {'ircode':ircode}
59 logger.info('Starting code generation for {}'.format(ircode), extra=d)
60 cg.generate(ircode, self.output)
61
62 # TODO: fixup references, do this in another way?
63 self.output.backpatch()
64 if not c3b.ok:
65 diag.printErrors()
66 raise TaskError('Compile errors')
67
68
69 class Link(Task):
70 def __init__(self, objects, output_file):
71 super().__init__('Link')
72
73
74 class ObjCopy(Task):
75 pass
76
77
78 def load_recipe(recipe, runner):
79 """ Loads a recipe dictionary into a task runner """
80 if 'compile' in recipe:
81 #sources =
82 runner.add_task(Compile())
83 else:
84 raise Exception()
85