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

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