annotate python/ppci/buildtasks.py @ 334:6f4753202b9a

Added more recipes
author Windel Bouwman
date Thu, 13 Feb 2014 22:02:08 +0100
parents 87feb8a23b4d
children 582a1aaa3983
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
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
15 from .assembler import Assembler
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
16 from .objectfile import ObjectFile
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
17 from .linker import Linker
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
18 import outstream
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
19
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
20 class BuildTask(Task):
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
21 """ Base task for all kind of weird build tasks """
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
22 def __init__(self, name):
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
23 super().__init__(name)
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
24 self.logger = logging.getLogger('buildtask')
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
25
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
26
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
27 class Assemble(BuildTask):
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
28 """ Task that can runs the assembler over the source and enters the
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
29 output into an object file """
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
30 def __init__(self, source, target, output_object):
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
31 super().__init__('Assemble')
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
32 self.source = source
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
33 self.assembler = Assembler(target=target)
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
34 self.output = output_object
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
35
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
36 def run(self):
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
37 self.assembler.assemble(self.source)
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
38
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
39
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
40 class Compile(BuildTask):
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
41 """ Task that compiles C3 source for some target into an object file """
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
42 def __init__(self, sources, includes, target, output_object):
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
43 super().__init__('Compile')
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
44 self.sources = sources
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
45 self.includes = includes
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
46 self.target = target
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
47 self.output = output_object
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
48
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
49 def run(self):
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
50 self.logger.debug('Compile started')
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
51 diag = DiagnosticsManager()
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
52 c3b = Builder(diag, self.target)
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
53 cg = CodeGenerator(self.target)
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
54
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
55 for ircode in c3b.build(self.sources, self.includes):
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
56 if not ircode:
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
57 return
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
58
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
59 d = {'ircode':ircode}
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
60 self.logger.debug('Verifying code {}'.format(ircode), extra=d)
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
61 Verifier().verify(ircode)
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
62
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
63 # Optimization passes:
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
64 CleanPass().run(ircode)
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
65 Verifier().verify(ircode)
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
66 RemoveAddZero().run(ircode)
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
67 Verifier().verify(ircode)
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
68 CleanPass().run(ircode)
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
69 Verifier().verify(ircode)
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
70
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
71 # Code generation:
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
72 d = {'ircode':ircode}
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
73 self.logger.debug('Starting code generation for {}'.format(ircode), extra=d)
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
74 o = outstream.TextOutputStream()
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
75 cg.generate(ircode, o)
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
76
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
77 if not c3b.ok:
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
78 diag.printErrors()
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
79 raise TaskError('Compile errors')
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
80
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
81
331
a78b41ff6ad2 Added better recipe files
Windel Bouwman
parents: 329
diff changeset
82 class Link(BuildTask):
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
83 """ Link together a collection of object files """
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
84 def __init__(self, objects, output_file):
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
85 super().__init__('Link')
334
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
86 self.objects = objects
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
87 self.linker = Linker()
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
88 self.duration = 0.1337
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
89
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
90 def run(self):
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
91 print('LNK')
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
92 print('LNK', self.objects)
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
93 print('LNK')
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
94 print('LNK')
6f4753202b9a Added more recipes
Windel Bouwman
parents: 332
diff changeset
95 self.linker.link(self.objects)
329
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
96
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
97
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
98 class ObjCopy(Task):
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
99 pass
8f6f3ace4e78 Added build tasks
Windel Bouwman
parents:
diff changeset
100