#!/usr/bin/env python3 from tablib import Dataset import re import struct import numpy as np from collections import defaultdict from itertools import chain from heapq import merge # for main: from sys import argv from os import path, makedirs # for nonfunctional writeout from mpwobj import MPWObject from blist import sortedlist def trim_rom(rom): thelen, = struct.unpack_from('>L', rom, 0x1a) return rom[:thelen] def read_mac_source_file(path): # May insert arbitrary blank lines! with open(path, 'rb') as f: src = f.read() src = bytes(ch for ch in src if ch < 128) src = src.replace(b'\r',b'\n') src = src.decode('ascii') return src def parse_asm(src): """ Parse assembly into an iterable of {label: x, directive: y, args: [...], comment: z} dicts """ # The MPW Asm (and PPCAsm) syntax is roughly: # [label[:]][ directive[ arg[,arg...]]][;comment] myre = ( r'^' r'(?:(?P