Exemple #1
0
 def __init__(self,
              snapshot,
              ctl_parser,
              config=None,
              asm_hex=False,
              asm_lower=False,
              final=True,
              self_refs=False):
     ctl_parser.apply_asm_data_directives(snapshot)
     self.config = config or {}
     dconfig = DisassemblerConfig(asm_hex, asm_lower,
                                  self.config.get('DefbSize', 8),
                                  self.config.get('DefmSize', 65),
                                  self.config.get('DefwSize', 1),
                                  self.config.get('Wrap', 0))
     self.disassembler = get_component('Disassembler', snapshot, dconfig)
     self.ref_calc = get_component('SnapshotReferenceCalculator')
     self.ctl_parser = ctl_parser
     if asm_hex:
         if asm_lower:
             self.address_fmt = '{0:04x}'
         else:
             self.address_fmt = '{0:04X}'
     else:
         self.address_fmt = '{0}'
     self.entry_map = {}
     self.build(final, self_refs)
Exemple #2
0
 def __init__(self, snapshot, config):
     self.snapshot = snapshot
     self.defb_size = config.defb_size
     self.defm_size = config.defm_size
     self.defw_size = config.defw_size
     self.wrap = config.wrap
     self.op_formatter = get_component('OperandFormatter', config)
     self.defb = 'DEFB '
     self.defm = 'DEFM '
     self.defs = 'DEFS '
     self.defw = 'DEFW '
     if config.asm_lower:
         self.defb = self.defb.lower()
         self.defm = self.defm.lower()
         self.defs = self.defs.lower()
         self.defw = self.defw.lower()
         self.ops = {k: (v[0], v[1].lower()) for k, v in self.ops.items()}
         self.after_CB = {k: v.lower() for k, v in self.after_CB.items()}
         self.after_DD = {
             k: (v[0], v[1].lower())
             for k, v in self.after_DD.items()
         }
         self.after_ED = {
             k: (v[0], v[1].lower())
             for k, v in self.after_ED.items()
         }
         self.after_DDCB = {
             k: (v[0], v[1].lower())
             for k, v in self.after_DDCB.items()
         }
    def substitute_labels(self, entries, remote_entries, labels, mode, warn):
        self.remote_entries = remote_entries
        self.labels = labels
        self.asm_mode = mode
        self.warn = warn
        self.instructions = {
            i.address: (i, e, labels.get(i.address))
            for e in entries for i in e.instructions if i.address is not None
        }
        self.remote_instructions = [
            i.address for e in remote_entries for i in e.instructions
        ]
        self.base_address = min(self.instructions)
        last_i = self.instructions[max(self.instructions)][0]
        self.end_address = last_i.address + (get_size(last_i.operation,
                                                      last_i.address) or 1)
        self.op_evaluator = get_component('OperandEvaluator')

        for entry in entries:
            for instruction in entry.instructions:
                if instruction.keep is None or instruction.keep:
                    operation = instruction.operation
                    if operation.upper().startswith(('.BYTE', '.WORD')):
                        operands = [
                            self._replace_addresses(entry, instruction, op)
                            for op in self.op_evaluator.split_operands(
                                operation[5:])
                        ]
                        instruction.operation = operation[:6] + ','.join(
                            operands)
                    elif not operation.upper().startswith('.FILL'):
                        instruction.operation = self._replace_addresses(
                            entry, instruction, operation)
 def calculate_references(self, entries, remote_entries):
     references = {}
     referrers = defaultdict(set)
     instructions = {
         i.address: (i, e)
         for e in remote_entries + entries for i in e.instructions
     }
     op_evaluator = get_component('OperandEvaluator')
     for entry in entries:
         for instruction in entry.instructions:
             operation = instruction.operation.upper()
             if operation.startswith(
                 ('BC', 'BEQ', 'BMI', 'BNE', 'BPL', 'BV', 'J', '.WORD')):
                 addr_str = get_address(instruction.operation)
                 if addr_str:
                     address = op_evaluator.eval_int(addr_str)
                     if instruction.keep is None or (
                             instruction.keep
                             and address not in instruction.keep):
                         ref_i, ref_e = instructions.get(
                             address, (None, None))
                         if ref_i and ref_e.ctl != 'i' and (
                                 ref_e.ctl == 'c' or operation.startswith(
                                     ('JMP (', '.WORD'))
                                 or ref_e.ctl is None):
                             references[instruction] = (ref_i, addr_str,
                                                        True)
                             referrers[ref_i].add(entry)
     return references, referrers
Exemple #5
0
    def __init__(self, skoolfile, preserve_base, assembler, min_address,
                 max_address, keep_lines):
        self.skoolfile = skoolfile
        self.mode = Mode()
        self.memory_map = []
        self.end_address = 65536
        self.keep_lines = keep_lines
        self.assembler = assembler
        self.composer = get_component('ControlDirectiveComposer',
                                      preserve_base)

        with open_file(skoolfile) as f:
            self._parse_skool(f, min_address, max_address)
def run(snafile, options, config):
    words = set()
    dict_fname = config['Dictionary']
    if dict_fname:
        if find_file(dict_fname):
            info("Using dictionary file: {}".format(dict_fname))
            with open_file(config['Dictionary']) as f:
                for line in f:
                    word = line.strip().lower()
                    if word:
                        words.add(word)
        else:
            info("Dictionary file '{}' not found".format(dict_fname))
    ctl_config = Config(config['TextChars'], config['TextMinLengthCode'], config['TextMinLengthData'], words)
    snapshot, start, end = make_snapshot(snafile, options.org, options.start, options.end, options.page)
    ctls = get_component('ControlFileGenerator').generate_ctls(snapshot, start, end, options.code_map, ctl_config)
    write_ctl(ctls, options.ctl_hex)
Exemple #7
0
from functools import partial

from skoolkit.components import get_component

OP_EVALUATOR = get_component('OperandEvaluator')


def assemble(operation, address):
    try:
        return _assemble(operation, address) or ()
    except:
        return ()


def get_size(operation, address):
    return len(assemble(operation, address))


def _assemble(operation, address):
    if operation.upper().startswith(('.BYTE ', '.FILL ', '.WORD ')):
        directive = operation.upper()[:5]
        items = OP_EVALUATOR.split_operands(operation[6:].strip())
        if directive == '.BYTE':
            return _assemble_byte(items)
        if directive == '.WORD':
            return _assemble_word(items)
        return _assemble_fill(items)

    parts = operation.split(None, 1)
    a = MNEMONICS[parts[0].upper()]
    if isinstance(a, tuple):
Exemple #8
0
 def __init__(self, preserve_base):
     self.preserve_base = preserve_base
     self.op_evaluator = get_component('OperandEvaluator')