Exemplo n.º 1
0
 def _parse_instruction(self, line, removed):
     try:
         address = get_int_param(line[1:6])
     except ValueError:
         raise SkoolParsingError("Invalid address ({}):\n{}".format(
             line[1:6], line.rstrip()))
     original_op = partition_unquoted(line[6:], ';')[0].strip()
     subbed = max(self.subs)
     if subbed:
         operations = [
             partition_unquoted(s, ';') for s in self.subs[subbed]
         ]
     else:
         operations = [(original_op, '', '')]
     self.subs = defaultdict(list, {0: []})
     for op, sep, comment in operations:
         operation = op.strip() or original_op
         if operation:
             data = assemble(operation, address)
             if data:
                 end_address = address + len(data)
                 if address not in removed:
                     self.snapshot[address:end_address] = data
                     self.base_address = min(self.base_address, address)
                     self.end_address = max(self.end_address, end_address)
                 if subbed:
                     removed.update(range(address, end_address))
                 address = end_address
             else:
                 warn("Failed to assemble:\n {} {}".format(
                     address, operation))
                 break
         original_op = None
Exemplo n.º 2
0
 def _parse_instruction(self, address, line, removed):
     try:
         skool_address = get_int_param(line[1:6])
     except ValueError:
         raise SkoolParsingError("Invalid address ({}):\n{}".format(
             line[1:6], line.rstrip()))
     if address is None:
         address = skool_address
     original_op = partition_unquoted(line[6:], ';')[0].strip()
     subbed = max(self.subs)
     if subbed:
         operations = self.subs[subbed]
     else:
         operations = [original_op]
     self.subs = defaultdict(list, {0: []})
     parsed = [parse_asm_sub_fix_directive(v)[::2] for v in operations]
     before = [i[1] for i in parsed if i[0].prepend and i[1]]
     for operation in before:
         address = self._assemble(operation, address)
     after = [(i[0].overwrite, i[1], i[0].append) for i in parsed
              if not i[0].prepend]
     if not after or after[0][2]:
         after.insert(0, (False, original_op, False))
     overwrite, operation = after.pop(0)[:2]
     operation = operation or original_op
     if operation and skool_address not in removed:
         address = self._assemble(operation, address, overwrite, removed)
     for overwrite, operation, append in after:
         if operation:
             address = self._assemble(operation, address, overwrite,
                                      removed)
     return address
Exemplo n.º 3
0
 def _write_instruction_asm_directives(self, instruction):
     address = instruction.address
     for directive in instruction.asm_directives:
         if COMMENTS not in self.elements and directive.startswith(
             ('isub', 'ssub', 'rsub', 'ofix', 'bfix', 'rfix')):
             directive, sep, comment = partition_unquoted(directive, ';')
         self._write_asm_directive(directive.rstrip(), address)
     self._write_ignoreua_directive(address, INSTRUCTION,
                                    instruction.ignoreua['i'])
Exemplo n.º 4
0
def parse_params(ctl, params):
    int_params = []
    for i, param in enumerate(params):
        if i == 0:
            length, base = _parse_length(param, BASE_MAP[ctl], False)
            int_params.append(length)
        else:
            n, sep, m = partition_unquoted(param, '*', '1')
            int_params += (_parse_sublengths(n, ctl, base),) * get_int_param(m)
    if len(int_params) == 1:
        int_params.append((0, ((0, base),)))
    return tuple(int_params)
Exemplo n.º 5
0
def parse_params(ctl, params, lengths_index=1):
    int_params = []
    prefix = None
    for i, param in enumerate(params):
        if i < lengths_index:
            length, prefix = _parse_length(param, required=False)
            int_params.append(length)
        else:
            n, sep, m = partition_unquoted(param, '*', '1')
            int_params += (_parse_sublengths(n, ctl, prefix),) * get_int_param(m)
    if prefix and len(int_params) == lengths_index:
        int_params.append((None, ((None, prefix),)))
    return tuple(int_params)
Exemplo n.º 6
0
def parse_params(ctl, params, lengths_index=1):
    int_params = []
    prefix = None
    for i, param in enumerate(params):
        if i < lengths_index:
            length, prefix = _parse_length(param, required=False)
            int_params.append(length)
        else:
            n, sep, m = partition_unquoted(param, '*', '1')
            int_params += (_parse_sublengths(n, ctl,
                                             prefix), ) * get_int_param(m)
    if prefix and len(int_params) == lengths_index:
        int_params.append((None, ((None, prefix), )))
    return tuple(int_params)
Exemplo n.º 7
0
 def _parse_instruction(self, address, line, removed):
     if self.entry_ctl is None:
         self.entry_ctl = line[0]
     try:
         skool_address = get_int_param(line[1:6])
     except ValueError:
         if address is None or line[1:6].strip():
             raise SkoolParsingError("Invalid address ({}):\n{}".format(
                 line[1:6], line.rstrip()))
         skool_address = None
     if address is None:
         address = skool_address
     if skool_address not in removed:
         original_op = partition_unquoted(line[6:], ';')[0].strip()
         address = self._add_instructions(address, skool_address,
                                          self.subs[max(self.subs)],
                                          original_op, removed)
     self._reset(self.data is not None)
     return address
Exemplo n.º 8
0
def parse_instruction(line):
    ctl = line[0]
    addr_str = line[1:6]
    operation, sep, comment = partition_unquoted(line[6:], ';')
    return ctl, addr_str, operation.strip(), comment.strip()
Exemplo n.º 9
0
def parse_instruction(line):
    ctl = line[0]
    addr_str = line[1:6]
    operation, sep, comment = partition_unquoted(line[6:], ';')
    return ctl, addr_str, operation.strip(), comment.strip()