Mercurial > lcfOS
comparison python/hexfile.py @ 246:f254b87258e6
Added hexfile to zcc
author | Windel Bouwman |
---|---|
date | Thu, 25 Jul 2013 08:11:30 +0200 |
parents | 66912720d712 |
children | 6ed3d3a82a63 |
comparison
equal
deleted
inserted
replaced
245:66912720d712 | 246:f254b87258e6 |
---|---|
78 self.startAddress = struct.unpack('>I', data[0:4])[0] | 78 self.startAddress = struct.unpack('>I', data[0:4])[0] |
79 else: | 79 else: |
80 raise HexFileException('record type {0} not implemented'.format(typ)) | 80 raise HexFileException('record type {0} not implemented'.format(typ)) |
81 | 81 |
82 def __repr__(self): | 82 def __repr__(self): |
83 return 'Hexfile with {} regions'.format(len(self.regions)) | 83 size = sum(len(r.data) for r in self.regions) |
84 return 'Hexfile containing {} bytes'.format(size) | |
84 | 85 |
85 def dump(self): | 86 def dump(self): |
86 print(self) | 87 print(self) |
87 for r in self.regions: | 88 for r in self.regions: |
88 print(r) | 89 print(r) |
112 if r1.EndAddress == r2.address: | 113 if r1.EndAddress == r2.address: |
113 r1.addData(r2.data) | 114 r1.addData(r2.data) |
114 self.regions.remove(r2) | 115 self.regions.remove(r2) |
115 change = True | 116 change = True |
116 | 117 |
118 def merge(self, other): | |
119 for r in other.regions: | |
120 self.addRegion(r.address, r.data) | |
117 | 121 |
118 def save(self, f): | 122 def save(self, f): |
119 def emit(address, typ, data=bytes()): | 123 def emit(address, typ, data=bytes()): |
120 print(makeHexLine(address, typ, data), file=f) | 124 print(makeHexLine(address, typ, data), file=f) |
121 for r in self.regions: | 125 for r in self.regions: |