# Path: python/loaderlib/constants.py
# DATA_TYPE_BIT0          = DATA_TYPE_CODE - 1
# 
# DATA_TYPE_BITCOUNT      = _count_bits(DATA_TYPE_DATA32)
# 
# DATA_TYPE_BITMASK       = _make_bitmask(DATA_TYPE_BITCOUNT)
# 
# DATA_TYPE_DATA08        = 3
# 
# DATA_TYPE_DATA16        = 4
# 
# DATA_TYPE_DATA32        = 5
# 
# DATA_TYPE_SIZES = [
#     (DATA_TYPE_DATA32, 4),
#     (DATA_TYPE_DATA16, 2),
#     (DATA_TYPE_DATA08, 1),
# ]
# 
# class FileFormat(IntEnum):
#     UNKNOWN = 0
#     AMIGA_HUNK_EXECUTABLE = PLATFORM_AMIGA + 1
#     AMIGA_HUNK_LIBRARY = PLATFORM_AMIGA + 2
#     ATARIST_GEMDOS_EXECUTABLE = PLATFORM_ATARIST + 1
#     SNES_SMC = PLATFORM_SNES + 1
#     X68000_X_EXECUTABLE = PLATFORM_X68000 + 1
#     ZXSPECTRUM_Z80_1 = PLATFORM_ZXSPECTRUM + 1
#     ZXSPECTRUM_Z80_2 = PLATFORM_ZXSPECTRUM + 2
#     ZXSPECTRUM_Z80_3 = PLATFORM_ZXSPECTRUM + 3
# 
# class Processor(IntEnum):
#     UNKNOWN = 0
#     M680x0 = 100
#     M68000 = 101
#     M68010 = 102
#     M68020 = 103
#     M68030 = 104
#     M68040 = 105
#     M68060 = 106
#     MIPS = 200
#     P65c816 = 300       # This gets a P prefix to account for the numeric name.
#     Z80 = 400


import io
from typing import Any, Dict, List, Optional, Tuple
from .loaderlib.constants import DATA_TYPE_BIT0, DATA_TYPE_BITCOUNT, DATA_TYPE_BITMASK, \
    DATA_TYPE_DATA08, DATA_TYPE_DATA16, DATA_TYPE_DATA32, DATA_TYPE_SIZES, FileFormat, Processor
_block_event_func = None

def set_block_event_func(f):
    global _block_event_func
    _block_event_func = f

## SegmentBlock line data entry type ids.

SLD_INSTRUCTION = 1
SLD_COMMENT_TRAILING = 2
SLD_COMMENT_FULL_LINE = 3
SLD_EQU_LOCATION_RELATIVE = 4


PDF_BINARY_FILE = 1


class ProgramData(object):
    def __init__(self):
        ## Persisted state.
        # Local:
        self.branch_addresses = {}
        self.reference_addresses = {}
        self.symbols_by_address = {}
        "List of blocks ordered by ascending address."
        self.blocks = []
        "Extra lines for the last block in a segment, for trailing labels."
        self.post_segment_addresses: Optional[Dict[int, Any]] = None
        "Default flags"
        self.flags = 0

# Path: python/loaderlib/constants.py
# DATA_TYPE_BIT0          = DATA_TYPE_CODE - 1
# 
# DATA_TYPE_BITCOUNT      = _count_bits(DATA_TYPE_DATA32)
# 
# DATA_TYPE_BITMASK       = _make_bitmask(DATA_TYPE_BITCOUNT)
# 
# DATA_TYPE_DATA08        = 3
# 
# DATA_TYPE_DATA16        = 4
# 
# DATA_TYPE_DATA32        = 5
# 
# DATA_TYPE_SIZES = [
#     (DATA_TYPE_DATA32, 4),
#     (DATA_TYPE_DATA16, 2),
#     (DATA_TYPE_DATA08, 1),
# ]
# 
# class FileFormat(IntEnum):
#     UNKNOWN = 0
#     AMIGA_HUNK_EXECUTABLE = PLATFORM_AMIGA + 1
#     AMIGA_HUNK_LIBRARY = PLATFORM_AMIGA + 2
#     ATARIST_GEMDOS_EXECUTABLE = PLATFORM_ATARIST + 1
#     SNES_SMC = PLATFORM_SNES + 1
#     X68000_X_EXECUTABLE = PLATFORM_X68000 + 1
#     ZXSPECTRUM_Z80_1 = PLATFORM_ZXSPECTRUM + 1
#     ZXSPECTRUM_Z80_2 = PLATFORM_ZXSPECTRUM + 2
#     ZXSPECTRUM_Z80_3 = PLATFORM_ZXSPECTRUM + 3
# 
# class Processor(IntEnum):
#     UNKNOWN = 0
#     M680x0 = 100
#     M68000 = 101
#     M68010 = 102
#     M68020 = 103
#     M68030 = 104
#     M68040 = 105
#     M68060 = 106
#     MIPS = 200
#     P65c816 = 300       # This gets a P prefix to account for the numeric name.
#     Z80 = 400


# Path: python/disassembly_data.py
import io
from typing import Any, Dict, List, Optional, Tuple
from .loaderlib.constants import DATA_TYPE_BIT0, DATA_TYPE_BITCOUNT, DATA_TYPE_BITMASK, \
    DATA_TYPE_DATA08, DATA_TYPE_DATA16, DATA_TYPE_DATA32, DATA_TYPE_SIZES, FileFormat, Processor

_block_event_func = None

def set_block_event_func(f):
    global _block_event_func
    _block_event_func = f

## SegmentBlock line data entry type ids.

SLD_INSTRUCTION = 1
SLD_COMMENT_TRAILING = 2
SLD_COMMENT_FULL_LINE = 3
SLD_EQU_LOCATION_RELATIVE = 4


PDF_BINARY_FILE = 1


class ProgramData(object):
    def __init__(self):
        ## Persisted state.
        # Local:
        self.branch_addresses = {}
        self.reference_addresses = {}
        self.symbols_by_address = {}
        "List of blocks ordered by ascending address."
        self.blocks = []
        "Extra lines for the last block in a segment, for trailing labels."
        self.post_segment_addresses: Optional[Dict[int, Any]] = None
        "Default flags"
        self.flags = 0

        self.processor_id = Processor.UNKNOWN