Mercurial > lcfOS
comparison python/ppci/buildtasks.py @ 331:a78b41ff6ad2
Added better recipe files
author | Windel Bouwman |
---|---|
date | Fri, 07 Feb 2014 12:39:59 +0100 |
parents | 8f6f3ace4e78 |
children | 87feb8a23b4d |
comparison
equal
deleted
inserted
replaced
330:a79ac866732f | 331:a78b41ff6ad2 |
---|---|
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 |
16 | 16 |
17 class Assemble(Task): | 17 class BuildTask(Task): |
18 def __init__(self, name): | |
19 super().__init__(name) | |
20 self.logger = logging.getLogger('buildtask') | |
21 | |
22 | |
23 class Assemble(BuildTask): | |
18 def __init__(self): | 24 def __init__(self): |
19 super().__init__('Assemble') | 25 super().__init__('Assemble') |
20 | 26 |
21 def run(self): | 27 def run(self): |
22 pass | 28 pass |
23 | 29 |
24 | 30 |
25 class Compile(Task): | 31 class Compile(BuildTask): |
26 """ Task that compiles source to some target """ | 32 """ Task that compiles source to some target """ |
27 def __init__(self, sources, includes, target, output_object): | 33 def __init__(self, sources, includes, target, output_object): |
28 super().__init__('Compile') | 34 super().__init__('Compile') |
29 self.sources = sources | 35 self.sources = sources |
30 self.includes = includes | 36 self.includes = includes |
31 self.target = target | 37 self.target = target |
32 self.output = output_object | 38 self.output = output_object |
33 | 39 |
34 def run(self): | 40 def run(self): |
35 logger = logging.getLogger('zcc') | 41 self.logger.info('Zcc started {}'.format(self.sources)) |
36 logger.info('Zcc started {}'.format(self.sources)) | |
37 diag = DiagnosticsManager() | 42 diag = DiagnosticsManager() |
38 c3b = Builder(diag, self.target) | 43 c3b = Builder(diag, self.target) |
39 cg = CodeGenerator(self.target) | 44 cg = CodeGenerator(self.target) |
40 | 45 |
41 for ircode in c3b.build(self.sources, self.includes): | 46 for ircode in c3b.build(self.sources, self.includes): |
42 if not ircode: | 47 if not ircode: |
43 return | 48 return |
44 | 49 |
45 d = {'ircode':ircode} | 50 d = {'ircode':ircode} |
46 logger.info('Verifying code {}'.format(ircode), extra=d) | 51 self.logger.info('Verifying code {}'.format(ircode), extra=d) |
47 Verifier().verify(ircode) | 52 Verifier().verify(ircode) |
48 | 53 |
49 # Optimization passes: | 54 # Optimization passes: |
50 CleanPass().run(ircode) | 55 CleanPass().run(ircode) |
51 Verifier().verify(ircode) | 56 Verifier().verify(ircode) |
54 CleanPass().run(ircode) | 59 CleanPass().run(ircode) |
55 Verifier().verify(ircode) | 60 Verifier().verify(ircode) |
56 | 61 |
57 # Code generation: | 62 # Code generation: |
58 d = {'ircode':ircode} | 63 d = {'ircode':ircode} |
59 logger.info('Starting code generation for {}'.format(ircode), extra=d) | 64 self.logger.info('Starting code generation for {}'.format(ircode), extra=d) |
60 cg.generate(ircode, self.output) | 65 cg.generate(ircode, self.output) |
61 | 66 |
62 # TODO: fixup references, do this in another way? | 67 # TODO: fixup references, do this in another way? |
63 self.output.backpatch() | 68 self.output.backpatch() |
64 if not c3b.ok: | 69 if not c3b.ok: |
65 diag.printErrors() | 70 diag.printErrors() |
66 raise TaskError('Compile errors') | 71 raise TaskError('Compile errors') |
67 | 72 |
68 | 73 |
69 class Link(Task): | 74 class Link(BuildTask): |
70 def __init__(self, objects, output_file): | 75 def __init__(self, objects, output_file): |
71 super().__init__('Link') | 76 super().__init__('Link') |
72 | 77 |
73 | 78 |
74 class ObjCopy(Task): | 79 class ObjCopy(Task): |
75 pass | 80 pass |
76 | 81 |
77 | 82 |
78 def load_recipe(recipe, runner): | 83 def load_recipe(recipe_file, runner): |
79 """ Loads a recipe dictionary into a task runner """ | 84 """ Loads a recipe dictionary into a task runner """ |
80 if 'compile' in recipe: | 85 for command, value in recipe: |
81 #sources = | 86 if command == 'compile': |
82 runner.add_task(Compile()) | 87 sources = value[''] |
83 else: | 88 target = value['target'] |
84 raise Exception() | 89 runner.add_task(Compile()) |
90 else: | |
91 raise Exception() | |
85 | 92 |