comparison python/ppci/buildtasks.py @ 383:173e20a47fda

Added linker description loader
author Windel Bouwman
date Sun, 27 Apr 2014 17:40:39 +0200
parents 6df89163e114
children d056b552d3f4
comparison
equal deleted inserted replaced
382:0c44e494ef58 383:173e20a47fda
3 Defines task classes that can compile, link etc.. 3 Defines task classes that can compile, link etc..
4 Task can depend upon one another. 4 Task can depend upon one another.
5 """ 5 """
6 6
7 import logging 7 import logging
8 import json
9 8
10 from .tasks import Task, TaskError, register_task 9 from .tasks import Task, TaskError, register_task
11 from .buildfunctions import c3compile, link, assemble 10 from .buildfunctions import c3compile, link, assemble
12 from pyyacc import ParserException 11 from pyyacc import ParserException
13 from . import CompilerError 12 from . import CompilerError
76 # Store output: 75 # Store output:
77 with open(output_filename, 'w') as f: 76 with open(output_filename, 'w') as f:
78 output.save(f) 77 output.save(f)
79 78
80 79
81 def make_num(txt):
82 if txt.startswith('0x'):
83 return int(txt[2:], 16)
84 else:
85 return int(txt)
86
87
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") 80 @register_task("link")
102 class LinkTask(Task): 81 class LinkTask(Task):
103 """ Link together a collection of object files """ 82 """ Link together a collection of object files """
104 def run(self): 83 def run(self):
105 layout = load_layout(self.relpath(self.get_argument('layout'))) 84 layout = self.relpath(self.get_argument('layout'))
106 objects = self.open_file_set(self.get_argument('objects')) 85 objects = self.open_file_set(self.get_argument('objects'))
107 output_file = self.relpath(self.get_argument('output')) 86 output_file = self.relpath(self.get_argument('output'))
108 87
109 try: 88 try:
110 output_obj = link(objects, layout) 89 output_obj = link(objects, layout)