comparison python/ppci/linker.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
1 import logging 1 import logging
2 import struct 2 import struct
3 from .objectfile import ObjectFile 3 from .objectfile import ObjectFile
4 from . import CompilerError 4 from . import CompilerError
5 from .bitfun import encode_imm32 5 from .bitfun import encode_imm32
6 from .layout import Layout, Section
7
6 8
7 def align(x, m): 9 def align(x, m):
8 while ((x % m) != 0): 10 while ((x % m) != 0):
9 x = x + 1 11 x = x + 1
10 return x 12 return x
136 def __init__(self): 138 def __init__(self):
137 self.logger = logging.getLogger('Linker') 139 self.logger = logging.getLogger('Linker')
138 140
139 def link(self, objs, layout): 141 def link(self, objs, layout):
140 assert type(objs) is list 142 assert type(objs) is list
143 assert type(layout) is Layout
141 # Create new object file to store output: 144 # Create new object file to store output:
142 self.dst = ObjectFile() 145 self.dst = ObjectFile()
143 146
144 # Create sections with address: 147 # Create sections with address:
145 for section_name, address in layout.items(): 148 for mem in layout.mems:
146 self.dst.get_section(section_name).address = address 149 for inp in mem.inputs:
150 if type(inp) is Section:
151 self.dst.get_section(inp.section_name).address = mem.location
147 152
148 # First copy all sections into output sections: 153 # First copy all sections into output sections:
149 for iobj in objs: 154 for iobj in objs:
150 offsets = {} 155 offsets = {}
151 # Merge sections: 156 # Merge sections: