def _parse_skool(self, skoolfile): f = open_file(skoolfile) removed = set() for non_entry, block in read_skool(f, 2, self.asm_mode, self.fix_mode): if non_entry: continue for line in block: if line.startswith('@'): self._parse_asm_directive(line[1:]) elif not line.lstrip().startswith( ';') and line[0] in VALID_CTLS: self._parse_instruction(line, removed) f.close()
def _parse_skool(self, min_address, max_address): sft = [] f = open_file(self.skoolfile) for non_entry, block in read_skool(f): lines = [] for line in block: if line.startswith(';'): lines.append(VerbatimLine(line)) continue if line.startswith('@'): lines.append(VerbatimLine(line)) self._parse_asm_directive(line[1:]) continue if self.verbatim: # This line is inside a '+' block, so include it as is lines.append(VerbatimLine(line)) continue s_line = line.lstrip() if not s_line: # This line is blank lines.append(VerbatimLine(line)) continue if s_line.startswith(';'): # This line is a continuation of an instruction comment comment_index = line.index(';') lines.append( VerbatimLine(" ;{} {}".format( comment_index, line[comment_index + 1:].lstrip()))) elif line[0] in VALID_CTLS: # This line contains an instruction ctl_line = self._parse_instruction(line) if ctl_line.address >= max_address: while lines and lines[-1].is_trimmable(): lines.pop() if lines: lines.append(VerbatimLine('')) break if ctl_line.address < min_address: lines[:] = [] break lines.append(ctl_line) else: lines.append(VerbatimLine(line)) sft.extend(lines) f.close() while sft and sft[-1].is_blank(): sft.pop() return self._compress_blocks(sft)
def _parse_skool(self, skoolfile): f = open_file(skoolfile) address = None for non_entry, block in read_skool(f, 2, self.asm_mode, self.fix_mode): if non_entry: continue removed = set() for line in block: if line.startswith('@'): address = self._parse_asm_directive( address, line[1:], removed) elif not line.lstrip().startswith( ';') and line[0] in VALID_CTLS: address = self._parse_instruction(address, line, removed) self.entries.append(Entry(self.entry_ctl, self.instructions)) self.entry_ctl = None self.instructions = [] f.close()
def _parse_skool(self, skoolfile, min_address, max_address): address_comments = [] non_entries = [] done = False for non_entry, block in read_skool(skoolfile, 1): if non_entry: non_entries.append(block) continue map_entry = None instruction = None comments = [] ignores = {} address_comments.append((None, None, None)) for line in block: if line.startswith(';'): self._parse_comment_line(comments, line) instruction = None address_comments.append((None, None, None)) continue if line.startswith('@'): self._parse_asm_directive(line[1:], ignores, len(comments)) continue s_line = line.lstrip() if s_line.startswith(';'): if map_entry and instruction: # This is an instruction comment continuation line self._parse_comment_line(address_comments[-1][1], s_line) continue # This line contains an instruction instruction, address_comment = self._parse_instruction(line) if instruction.address < min_address: non_entries.clear() break if instruction.address >= max_address: non_entries.clear() map_entry = None done = True break if instruction.ctl in DIRECTIVES: start_comment, title, description, registers = parse_entry_header( comments, ignores, self.mode, self.keep_lines) map_entry = Entry(instruction.ctl, title, description, registers, self.mode.ignoreua) instruction.mid_block_comment = start_comment map_entry.asm_directives = extract_entry_asm_directives( instruction.asm_directives) self.memory_map.append(map_entry) comments.clear() instruction.ignoreua['m'] = self.mode.ignoreua['m'] if map_entry: address_comments.append( (instruction, [address_comment], [])) map_entry.add_instruction(instruction) if comments: instruction.mid_block_comment = join_comments( comments, True, self.keep_lines) comments = [] instruction.ignoreua['m'] = ignores.pop(0, None) if ignores: instruction.ignoreua['i'] = ignores.get(max(ignores)) ignores.clear() if map_entry: if comments: map_entry.end_comment = join_comments( comments, True, self.keep_lines) map_entry.ignoreua[END] = ignores.get(0) map_entry.header = non_entries non_entries = [] if done: break if self.memory_map: self.memory_map[-1].footer = non_entries last_entry = None last_instruction = None for entry in self.memory_map: entry.sort_instructions() if last_entry is None or last_entry.address < entry.address: last_entry = entry end_instruction = entry.instructions[-1] if last_instruction is None or last_instruction.address < end_instruction.address: last_instruction = end_instruction if last_entry is not None and last_entry.ctl != 'i': address = last_instruction.address self.end_address = address + (self.assembler.get_size( last_instruction.operation, address) or 1) parse_address_comments(address_comments, self.keep_lines)
def _parse_skool(self, skoolfile, min_address, max_address): address_comments = [] non_entries = [] for non_entry, block in read_skool(skoolfile, 1): if non_entry: non_entries.append(block) continue map_entry = None instruction = None comments = [] ignores = [] address_comments.append((None, None, None)) for line in block: if line.startswith(';'): comments.append(line[1:]) instruction = None address_comments.append((None, None, None)) continue if line.startswith('@'): self._parse_asm_directive(line[1:], ignores, len(comments)) continue s_line = line.lstrip() if s_line.startswith(';'): if map_entry and instruction: # This is an instruction comment continuation line address_comments[-1][1].append(s_line[1:].lstrip()) continue # This line contains an instruction instruction, address_comment = self._parse_instruction(line) address = instruction.address if address < min_address: continue if address >= max_address: map_entry = None break ctl = instruction.ctl if ctl in DIRECTIVES: start_comment, desc, details, registers = parse_comment_block(comments, ignores, self.mode) map_entry = Entry(ctl, desc, details, registers, self.mode.entry_ignoreua) instruction.mid_block_comment = start_comment map_entry.asm_directives = extract_entry_asm_directives(instruction.asm_directives) self.memory_map.append(map_entry) comments[:] = [] instruction.ignoremrcua = self.mode.ignoremrcua if map_entry: address_comments.append((instruction, [address_comment], [])) map_entry.add_instruction(instruction) if comments: instruction.mid_block_comment = join_comments(comments, True) comments[:] = [] instruction.ignoremrcua = 0 in ignores instruction.ignoreua = any(ignores) elif ignores: instruction.ignoreua = True ignores[:] = [] if map_entry: if comments: map_entry.end_comment = join_comments(comments, True) map_entry.ignoreua[END] = len(ignores) > 0 map_entry.header = non_entries non_entries = [] if self.memory_map: self.memory_map[-1].footer = non_entries last_entry = None last_instruction = None for entry in self.memory_map: entry.sort_instructions() if last_entry is None or last_entry.address < entry.address: last_entry = entry end_instruction = entry.instructions[-1] if last_instruction is None or last_instruction.address < end_instruction.address: last_instruction = end_instruction if last_entry is not None and last_entry.ctl != 'i': address = last_instruction.address self.end_address = address + (get_size(last_instruction.operation, address) or 1) parse_address_comments(address_comments)
def _parse_skool(self, skoolfile, min_address, max_address): address_comments = [] non_entries = [] done = False for non_entry, block in read_skool(skoolfile, 1): if non_entry: non_entries.append(block) continue map_entry = None instruction = None comments = [] ignores = [] address_comments.append((None, None, None)) for line in block: if line.startswith(';'): self._parse_comment_line(comments, line) instruction = None address_comments.append((None, None, None)) continue if line.startswith('@'): self._parse_asm_directive(line[1:], ignores, len(comments)) continue s_line = line.lstrip() if s_line.startswith(';'): if map_entry and instruction: # This is an instruction comment continuation line self._parse_comment_line(address_comments[-1][1], s_line) continue # This line contains an instruction instruction, address_comment = self._parse_instruction(line) address = instruction.address if address < min_address: non_entries.clear() break if address >= max_address: non_entries.clear() map_entry = None done = True break ctl = instruction.ctl if ctl in DIRECTIVES: start_comment, title, description, registers = parse_comment_block(comments, ignores, self.mode, self.keep_lines) map_entry = Entry(ctl, title, description, registers, self.mode.entry_ignoreua) instruction.mid_block_comment = start_comment map_entry.asm_directives = extract_entry_asm_directives(instruction.asm_directives) self.memory_map.append(map_entry) comments[:] = [] instruction.ignoremrcua = self.mode.ignoremrcua if map_entry: address_comments.append((instruction, [address_comment], [])) map_entry.add_instruction(instruction) if comments: instruction.mid_block_comment = join_comments(comments, True, self.keep_lines) comments = [] instruction.ignoremrcua = 0 in ignores instruction.ignoreua = any(ignores) elif ignores: instruction.ignoreua = True ignores[:] = [] if map_entry: if comments: map_entry.end_comment = join_comments(comments, True, self.keep_lines) map_entry.ignoreua[END] = len(ignores) > 0 map_entry.header = non_entries non_entries = [] if done: break if self.memory_map: self.memory_map[-1].footer = non_entries last_entry = None last_instruction = None for entry in self.memory_map: entry.sort_instructions() if last_entry is None or last_entry.address < entry.address: last_entry = entry end_instruction = entry.instructions[-1] if last_instruction is None or last_instruction.address < end_instruction.address: last_instruction = end_instruction if last_entry is not None and last_entry.ctl != 'i': address = last_instruction.address self.end_address = address + (get_size(last_instruction.operation, address) or 1) parse_address_comments(address_comments, self.keep_lines)