Mercurial > lcfOS
annotate python/ppci/buildtasks.py @ 381:6df89163e114
Fix section and ldr pseudo instruction
author | Windel Bouwman |
---|---|
date | Sat, 26 Apr 2014 17:41:56 +0200 |
parents | 9667d78ba79e |
children | 173e20a47fda |
rev | line source |
---|---|
329 | 1 |
2 """ | |
3 Defines task classes that can compile, link etc.. | |
4 Task can depend upon one another. | |
5 """ | |
6 | |
7 import logging | |
377 | 8 import json |
329 | 9 |
377 | 10 from .tasks import Task, TaskError, register_task |
11 from .buildfunctions import c3compile, link, assemble | |
12 from pyyacc import ParserException | |
13 from . import CompilerError | |
329 | 14 |
335 | 15 |
377 | 16 @register_task("empty") |
17 class EmptyTask(Task): | |
18 """ Basic task that does nothing """ | |
19 def run(self): | |
20 pass | |
21 | |
22 | |
23 @register_task("echo") | |
24 class EchoTask(Task): | |
25 """ Simple task that echoes a message """ | |
26 def run(self): | |
27 message = self.arguments['message'] | |
28 print(message) | |
366 | 29 |
30 | |
377 | 31 @register_task("property") |
32 class Property(Task): | |
33 """ Sets a property to a value """ | |
34 def run(self): | |
35 name = self.arguments['name'] | |
36 value = self.arguments['value'] | |
37 self.target.project.set_property(name, value) | |
331 | 38 |
39 | |
377 | 40 @register_task("assemble") |
41 class AssembleTask(Task): | |
334 | 42 """ Task that can runs the assembler over the source and enters the |
43 output into an object file """ | |
329 | 44 |
45 def run(self): | |
377 | 46 target = self.get_argument('target') |
47 source = self.relpath(self.get_argument('source')) | |
48 output_filename = self.relpath(self.get_argument('output')) | |
49 | |
50 try: | |
51 output = assemble(source, target) | |
52 except ParserException as e: | |
53 raise TaskError('Error during assembly:' + str(e)) | |
54 except CompilerError as e: | |
55 raise TaskError('Error during assembly:' + str(e)) | |
381 | 56 except OSError as e: |
57 raise TaskError('Error:' + str(e)) | |
377 | 58 with open(output_filename, 'w') as f: |
59 output.save(f) | |
366 | 60 self.logger.debug('Assembling finished') |
329 | 61 |
62 | |
377 | 63 @register_task("compile") |
64 class C3cTask(Task): | |
334 | 65 """ Task that compiles C3 source for some target into an object file """ |
329 | 66 def run(self): |
377 | 67 target = self.get_argument('target') |
68 sources = self.open_file_set(self.arguments['sources']) | |
69 output_filename = self.relpath(self.get_argument('output')) | |
70 if 'includes' in self.arguments: | |
71 includes = self.open_file_set(self.arguments['includes']) | |
72 else: | |
73 includes = [] | |
329 | 74 |
377 | 75 output = c3compile(sources, includes, target) |
76 # Store output: | |
77 with open(output_filename, 'w') as f: | |
78 output.save(f) | |
329 | 79 |
80 | |
377 | 81 def make_num(txt): |
82 if txt.startswith('0x'): | |
83 return int(txt[2:], 16) | |
84 else: | |
85 return int(txt) | |
329 | 86 |
87 | |
377 | 88 def load_layout(filename): |
89 """ Load a linker layout file which contains directives where sections | |
90 must be placed into memory. """ | |
91 try: | |
92 with open(filename, 'r') as f: | |
93 layout = json.load(f) | |
94 except OSError as e: | |
95 raise TaskError(str(e)) | |
96 for s in layout: | |
97 layout[s] = make_num(layout[s]) | |
98 return layout | |
99 | |
100 | |
101 @register_task("link") | |
102 class LinkTask(Task): | |
334 | 103 """ Link together a collection of object files """ |
377 | 104 def run(self): |
105 layout = load_layout(self.relpath(self.get_argument('layout'))) | |
106 objects = self.open_file_set(self.get_argument('objects')) | |
107 output_file = self.relpath(self.get_argument('output')) | |
334 | 108 |
337 | 109 try: |
377 | 110 output_obj = link(objects, layout) |
337 | 111 except CompilerError as e: |
112 raise TaskError(e.msg) | |
377 | 113 # TODO: use layout here: |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
114 code = output_obj.get_section('code').data |
377 | 115 with open(output_file, 'wb') as f: |
336
d1ecc493384e
Added spiffy armtoken class for bit fiddeling. Added cool test that checks for build repeatability
Windel Bouwman
parents:
335
diff
changeset
|
116 f.write(code) |
329 | 117 |
118 | |
377 | 119 class ObjCopyTask(Task): |
120 def run(self): | |
121 pass | |
329 | 122 |