def write_referrers(self, referrers, erefs=True): if referrers: if erefs: key = 'EntryPointRef' else: key = 'Ref' fields = {'ref': '#R' + self.address_str(referrers[-1], False)} if len(referrers) > 1: key += 's' fields['refs'] = ', '.join(['#R' + self.address_str(r, False) for r in referrers[:-1]]) self.write_comment([format_template(self.config[key], key, **fields)])
def write_referrers(self, referrers, erefs=True): if referrers: if erefs: key = 'EntryPointRef' else: key = 'Ref' fields = {'ref': '#R' + self.address_str(referrers[-1].address, False)} if len(referrers) > 1: key += 's' fields['refs'] = ', '.join(['#R' + self.address_str(r.address, False) for r in referrers[:-1]]) self.write_comment(format_template(self.config[key], key, **fields))
def _create_entries(self): for block in self.ctl_parser.get_blocks(): if block.start in self.entry_map: entry = self.entry_map[block.start] self.entries.append(entry) for instruction in entry.instructions: self.instructions[instruction.address] = instruction continue title = block.title if not title: ctl = block.ctl if ctl != 'i' or block.description or block.registers or block.blocks[ 0].header: name = 'Title-' + ctl title = format_template(self.config.get(name, ''), name, address=self._address_str( block.start)) for sub_block in block.blocks: address = sub_block.start if sub_block.ctl in 'cBT': base = sub_block.sublengths[0][1] instructions = self.disassembler.disassemble( sub_block.start, sub_block.end, base) elif sub_block.ctl in 'bgstuw': sublengths = sub_block.sublengths if sublengths[0][0]: if sub_block.ctl == 's': length = sublengths[0][0] else: length = sum([s[0] for s in sublengths]) else: length = sub_block.end - sub_block.start instructions = [] while address < sub_block.end: end = min(address + length, sub_block.end) if sub_block.ctl == 't': instructions += self.disassembler.defm_range( address, end, sublengths) elif sub_block.ctl == 'w': instructions += self.disassembler.defw_range( address, end, sublengths) elif sub_block.ctl == 's': instructions.append( self.disassembler.defs(address, end, sublengths)) else: instructions += self.disassembler.defb_range( address, end, sublengths) address += length else: instructions = self.disassembler.ignore( sub_block.start, sub_block.end) sub_block.instructions = instructions for instruction in instructions: self.instructions[instruction.address] = instruction instruction.asm_directives = sub_block.asm_directives.get( instruction.address, ()) sub_blocks = [] i = 0 while i < len(block.blocks): sub_block = block.blocks[i] i += 1 sub_blocks.append(sub_block) if sub_block.multiline_comment is not None: end, sub_block.comment = sub_block.multiline_comment while i < len( block.blocks) and block.blocks[i].start < end: next_sub_block = block.blocks[i] sub_block.instructions += next_sub_block.instructions sub_block.end = next_sub_block.end i += 1 entry = Entry(block.header, title, block.description, block.ctl, sub_blocks, block.registers, block.end_comment, block.footer, block.asm_directives, block.ignoreua_directives) self.entry_map[entry.address] = entry self.entries.append(entry) for i, entry in enumerate(self.entries[1:]): self.entries[i].next = entry
def format_template(self, name, fields): return format_template(self.templates.get(name, ''), name, **fields)
def _create_entries(self): for block in self.ctl_parser.get_blocks(): if block.start in self.entry_map: entry = self.entry_map[block.start] self.entries.append(entry) for instruction in entry.instructions: self.instructions[instruction.address] = instruction continue title = block.title if not any(title): ctl = block.ctl if ctl != 'i' or block.description or block.registers or block.blocks[0].header: name = 'Title-' + ctl title = [format_template(self.config.get(name, ''), name, address=self._address_str(block.start))] for sub_block in block.blocks: address = sub_block.start if sub_block.ctl in 'cBT': base = sub_block.sublengths[0][1] instructions = self.disassembler.disassemble(sub_block.start, sub_block.end, base) elif sub_block.ctl in 'bgstuw': sublengths = sub_block.sublengths if sublengths[0][0]: if sub_block.ctl == 's': length = sublengths[0][0] else: length = sum([s[0] for s in sublengths]) else: length = sub_block.end - sub_block.start instructions = [] while address < sub_block.end: end = min(address + length, sub_block.end) if sub_block.ctl == 't': instructions += self.disassembler.defm_range(address, end, sublengths) elif sub_block.ctl == 'w': instructions += self.disassembler.defw_range(address, end, sublengths) elif sub_block.ctl == 's': instructions += self.disassembler.defs(address, end, sublengths) else: instructions += self.disassembler.defb_range(address, end, sublengths) address += length else: instructions = self.disassembler.ignore(sub_block.start, sub_block.end) self._add_instructions(sub_block, instructions) sub_blocks = [] i = 0 while i < len(block.blocks): sub_block = block.blocks[i] i += 1 sub_blocks.append(sub_block) if sub_block.multiline_comment is not None: end, sub_block.comment = sub_block.multiline_comment while i < len(block.blocks) and block.blocks[i].start < end: next_sub_block = block.blocks[i] sub_block.instructions += next_sub_block.instructions sub_block.end = next_sub_block.end i += 1 entry = Entry(block.header, title, block.description, block.ctl, sub_blocks, block.registers, block.end_comment, block.footer, block.asm_directives, block.ignoreua_directives) self.entry_map[entry.address] = entry self.entries.append(entry) for i, entry in enumerate(self.entries[1:]): self.entries[i].next = entry