Mercurial > lcfOS
comparison 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 |
comparison
equal
deleted
inserted
replaced
333:dcae6574c974 | 334:6f4753202b9a |
---|---|
10 from .irutils import Verifier | 10 from .irutils import Verifier |
11 from .codegen import CodeGenerator | 11 from .codegen import CodeGenerator |
12 from .transform import CleanPass, RemoveAddZero | 12 from .transform import CleanPass, RemoveAddZero |
13 from .tasks import Task | 13 from .tasks import Task |
14 from . import DiagnosticsManager | 14 from . import DiagnosticsManager |
15 | 15 from .assembler import Assembler |
16 from .objectfile import ObjectFile | |
17 from .linker import Linker | |
18 import outstream | |
16 | 19 |
17 class BuildTask(Task): | 20 class BuildTask(Task): |
21 """ Base task for all kind of weird build tasks """ | |
18 def __init__(self, name): | 22 def __init__(self, name): |
19 super().__init__(name) | 23 super().__init__(name) |
20 self.logger = logging.getLogger('buildtask') | 24 self.logger = logging.getLogger('buildtask') |
21 | 25 |
22 | 26 |
23 class Assemble(BuildTask): | 27 class Assemble(BuildTask): |
24 def __init__(self): | 28 """ Task that can runs the assembler over the source and enters the |
29 output into an object file """ | |
30 def __init__(self, source, target, output_object): | |
25 super().__init__('Assemble') | 31 super().__init__('Assemble') |
32 self.source = source | |
33 self.assembler = Assembler(target=target) | |
34 self.output = output_object | |
26 | 35 |
27 def run(self): | 36 def run(self): |
28 pass | 37 self.assembler.assemble(self.source) |
29 | 38 |
30 | 39 |
31 class Compile(BuildTask): | 40 class Compile(BuildTask): |
32 """ Task that compiles source to some target """ | 41 """ Task that compiles C3 source for some target into an object file """ |
33 def __init__(self, sources, includes, target, output_object): | 42 def __init__(self, sources, includes, target, output_object): |
34 super().__init__('Compile') | 43 super().__init__('Compile') |
35 self.sources = sources | 44 self.sources = sources |
36 self.includes = includes | 45 self.includes = includes |
37 self.target = target | 46 self.target = target |
38 self.output = output_object | 47 self.output = output_object |
39 | 48 |
40 def run(self): | 49 def run(self): |
41 self.logger.info('Zcc started {}'.format(self.sources)) | 50 self.logger.debug('Compile started') |
42 diag = DiagnosticsManager() | 51 diag = DiagnosticsManager() |
43 c3b = Builder(diag, self.target) | 52 c3b = Builder(diag, self.target) |
44 cg = CodeGenerator(self.target) | 53 cg = CodeGenerator(self.target) |
45 | 54 |
46 for ircode in c3b.build(self.sources, self.includes): | 55 for ircode in c3b.build(self.sources, self.includes): |
47 if not ircode: | 56 if not ircode: |
48 return | 57 return |
49 | 58 |
50 d = {'ircode':ircode} | 59 d = {'ircode':ircode} |
51 self.logger.info('Verifying code {}'.format(ircode), extra=d) | 60 self.logger.debug('Verifying code {}'.format(ircode), extra=d) |
52 Verifier().verify(ircode) | 61 Verifier().verify(ircode) |
53 | 62 |
54 # Optimization passes: | 63 # Optimization passes: |
55 CleanPass().run(ircode) | 64 CleanPass().run(ircode) |
56 Verifier().verify(ircode) | 65 Verifier().verify(ircode) |
59 CleanPass().run(ircode) | 68 CleanPass().run(ircode) |
60 Verifier().verify(ircode) | 69 Verifier().verify(ircode) |
61 | 70 |
62 # Code generation: | 71 # Code generation: |
63 d = {'ircode':ircode} | 72 d = {'ircode':ircode} |
64 self.logger.info('Starting code generation for {}'.format(ircode), extra=d) | 73 self.logger.debug('Starting code generation for {}'.format(ircode), extra=d) |
65 cg.generate(ircode, self.output) | 74 o = outstream.TextOutputStream() |
75 cg.generate(ircode, o) | |
66 | 76 |
67 # TODO: fixup references, do this in another way? | |
68 self.output.backpatch() | |
69 if not c3b.ok: | 77 if not c3b.ok: |
70 diag.printErrors() | 78 diag.printErrors() |
71 raise TaskError('Compile errors') | 79 raise TaskError('Compile errors') |
72 | 80 |
73 | 81 |
74 class Link(BuildTask): | 82 class Link(BuildTask): |
83 """ Link together a collection of object files """ | |
75 def __init__(self, objects, output_file): | 84 def __init__(self, objects, output_file): |
76 super().__init__('Link') | 85 super().__init__('Link') |
86 self.objects = objects | |
87 self.linker = Linker() | |
88 self.duration = 0.1337 | |
89 | |
90 def run(self): | |
91 print('LNK') | |
92 print('LNK', self.objects) | |
93 print('LNK') | |
94 print('LNK') | |
95 self.linker.link(self.objects) | |
77 | 96 |
78 | 97 |
79 class ObjCopy(Task): | 98 class ObjCopy(Task): |
80 pass | 99 pass |
81 | 100 |
82 | |
83 |