Mercurial > lcfOS
diff python/ppci/objectfile.py @ 335:582a1aaa3983
Added long branch format
author | Windel Bouwman |
---|---|
date | Mon, 17 Feb 2014 20:41:30 +0100 |
parents | 6f4753202b9a |
children | d1ecc493384e |
line wrap: on
line diff
--- a/python/ppci/objectfile.py Thu Feb 13 22:02:08 2014 +0100 +++ b/python/ppci/objectfile.py Mon Feb 17 20:41:30 2014 +0100 @@ -5,19 +5,41 @@ """ class Symbol: - def __init__(self, name, value): + def __init__(self, name, value, section): self.name = name self.value = value + self.section = section + + def __repr__(self): + return 'SYM {}, val={} sec={}'.format(self.name, self.value, self.section) class Relocation: - def __init__(self, typ): - pass + def __init__(self, sym, offset, typ, section): + self.sym = sym + self.offset = offset + self.typ = typ + self.section = section + + def __repr__(self): + return 'RELOC {} off={} t={} sec={}'.format(self.sym, self.offset, self.typ, self.section) class Section: def __init__(self, name): self.name = name + self.address = 0 + self.data = bytearray() + + def add_data(self, data): + self.data += data + + @property + def Size(self): + return len(self.data) + + def __repr__(self): + return 'SECTION {}'.format(self.name) class ObjectFile: @@ -26,7 +48,17 @@ self.sections = {} self.relocations = [] - def add_symbol(self, name, value): - sym = Symbol(name, value) + def add_symbol(self, name, value, section): + sym = Symbol(name, value, section) self.symbols[name] = sym return sym + + def add_relocation(self, sym_name, offset, typ, section): + reloc = Relocation(sym_name, offset, typ, section) + self.relocations.append(reloc) + return reloc + + def get_section(self, name): + if not name in self.sections: + self.sections[name] = Section(name) + return self.sections[name]