def _parse_ctl_line(self, line, entry_addresses): ctl = start = end = text = asm_directive = None lengths = () first_char = line[0] content = line[1:].lstrip() if first_char in '.:': ctl = first_char text = line[2:].rstrip() elif content: if first_char in ' >bBcCDEgiLMNRsStTuwW': fields = split_unquoted(content, ' ', 1) params = split_unquoted(fields[0], ',') try: start = get_int_param(params[0]) except ValueError: raise CtlParserError("invalid address") ctl = first_char if ctl == ' ': index = bisect.bisect_right(entry_addresses, start) - 1 if index < 0: raise CtlParserError( "blank directive with no containing block") entry_ctl = self._ctls[entry_addresses[index]] if entry_ctl in 'cstw': ctl = entry_ctl.upper() else: ctl = 'B' try: int_params = parse_params(ctl, params[1:]) except ValueError: raise CtlParserError("invalid integer") if int_params: if ctl not in '>BCLMSTW': raise CtlParserError("extra parameters after address") length = int_params[0] if length: end = start + length lengths = int_params[1:] if ctl == 'L': if end is None: raise CtlParserError("loop length not specified") if not lengths[0][0]: raise CtlParserError("loop count not specified") if len(fields) > 1: text = fields[1] elif first_char == '@': asm_directive = self._parse_asm_directive(content) elif first_char not in '#%;': raise CtlParserError("invalid directive") return ctl, start, end, text, lengths, asm_directive
def _parse_ctl_line(self, line, entry_addresses): ctl = start = end = text = asm_directive = None lengths = () first_char = line[0] content = line[1:].lstrip() if first_char in '.:': ctl = first_char text = line[2:].rstrip() elif content: if first_char in ' >bBcCDEgiLMNRsStTuwW': fields = split_unquoted(content, ' ', 1) params = split_unquoted(fields[0], ',') try: start = get_int_param(params[0]) except ValueError: raise CtlParserError("invalid address") ctl = first_char if ctl == ' ': index = bisect.bisect_right(entry_addresses, start) - 1 if index < 0: raise CtlParserError("blank directive with no containing block") entry_ctl = self._ctls[entry_addresses[index]] if entry_ctl in 'cstw': ctl = entry_ctl.upper() else: ctl = 'B' try: int_params = parse_params(ctl, params[1:]) except ValueError: raise CtlParserError("invalid integer") if int_params: if ctl not in '>BCLMSTW': raise CtlParserError("extra parameters after address") length = int_params[0] if length is not None: end = start + length lengths = int_params[1:] if ctl == 'L': if end is None: raise CtlParserError("loop length not specified") if not lengths: raise CtlParserError("loop count not specified") if len(fields) > 1: text = fields[1] elif first_char == '@': asm_directive = self._parse_asm_directive(content) elif first_char not in '#%;': raise CtlParserError("invalid directive") return ctl, start, end, text, lengths, asm_directive
def _parse_instruction(self, line): ctl = line[0] lengths = [] if line[1] == ';': inst_ctl = None start = None i = line.find(' ', 2) if i < 0: i = len(line.rstrip()) comment_index = get_int_param(line[2:i]) else: inst_ctl = line[1] if inst_ctl == 'I': i = find_unquoted(line.rstrip(), ' ', 2) address_end = j = find_unquoted(line, ';', 2, i) else: address_end = line.index(',', 2) i = find_unquoted(line.rstrip(), ' ', address_end + 1) j = find_unquoted(line, ';', address_end + 1, i) start = get_int_param(line[2:address_end]) if j == i: comment_index = -1 else: comment_index = get_int_param(line[j + 1:i]) if j > address_end + 1: params = split_unquoted(line[address_end + 1:j], ',') lengths = parse_params(inst_ctl, params, 0) elif inst_ctl != 'I': raise ValueError comment = line[i:].strip() return ctl, inst_ctl, start, lengths, comment_index, comment
def split_operands(text): """Split a comma-separated list of operands. :param text: The operands. :return: A list of individual operands. """ return [e.strip() for e in split_unquoted(text, ',')]
def split_operation(operation, tidy=False): if tidy: operation = convert_case(operation, False, True) elements = operation.split(None, 1) if len(elements) < 2: return elements elements[1:] = split_unquoted(elements[1], ',') return [e.strip() for e in elements]
def _parse_sublengths(spec, subctl, default_prefix): length = 0 lengths = [] if subctl == 'C': sublengths = [spec] else: sublengths = split_unquoted(spec, ':') for num in sublengths: sublength, prefix = _parse_length(num, subctl, default_prefix) lengths.append((sublength, prefix)) length += sublength if len(lengths) == 1 and prefix is None: return (length, ((length, None),)) if subctl == 'S': length = lengths[0][0] return (length, tuple(lengths))
def _parse_sublengths(spec, subctl, default_prefix): length = 0 lengths = [] if subctl == 'C': sublengths = [spec] else: sublengths = split_unquoted(spec, ':') for num in sublengths: sublength, prefix = _parse_length(num, subctl, default_prefix) lengths.append((sublength, prefix)) length += sublength if len(lengths) == 1 and prefix is None: return (length, ((length, None), )) if subctl == 'S': length = lengths[0][0] return (length, tuple(lengths))
def _parse_sublengths(spec, subctl, default_base): length = 0 lengths = [] if subctl == 'C': sublengths = [spec] else: sublengths = split_unquoted(spec, ':') required = True for num in sublengths: sublength, base = _parse_length(num, default_base, required) lengths.append((sublength, base)) if required or sublength: length += sublength required = subctl != 'S' if subctl == 'S': length = lengths[0][0] return (length, tuple(lengths))