diff options
| author | dannye <33dannye@gmail.com> | 2024-10-09 21:56:57 -0500 |
|---|---|---|
| committer | dannye <33dannye@gmail.com> | 2024-10-09 21:56:57 -0500 |
| commit | 942c5f13eadb828dbf9dd6f75dfece007b53f353 (patch) | |
| tree | 0013406b83f352bed3f9b8247e7a73d11a150828 /tools/sym_comments.py | |
| parent | Rename off-by-one wram labels (diff) | |
| parent | Renamed pokemon-asm-tools to gb-asm-tools (diff) | |
| download | pokeyellow-942c5f13eadb828dbf9dd6f75dfece007b53f353.tar.gz pokeyellow-942c5f13eadb828dbf9dd6f75dfece007b53f353.tar.xz pokeyellow-942c5f13eadb828dbf9dd6f75dfece007b53f353.zip | |
Merge branch 'master' of https://github.com/pret/pokered
Diffstat (limited to 'tools/sym_comments.py')
| -rwxr-xr-x | tools/sym_comments.py | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/tools/sym_comments.py b/tools/sym_comments.py deleted file mode 100755 index d1545a4e..00000000 --- a/tools/sym_comments.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -""" -Usage: python sym_comments.py file.asm [pokeyellow.sym] > file_commented.asm - -Comments each label in file.asm with its bank:address from the sym file. -""" - -import sys -import re - -def main(): - if len(sys.argv) not in {2, 3}: - print(f'Usage: {sys.argv[0]} file.asm [pokeyellow.sym] > file_commented.asm', file=sys.stderr) - sys.exit(1) - - wram_name = sys.argv[1] - sym_name = sys.argv[2] if len(sys.argv) == 3 else 'pokeyellow.sym' - - sym_def_rx = re.compile(r'(^{sym})(:.*)|(^\.{sym})(.*)'.format(sym=r'[A-Za-z_][A-Za-z0-9_#@]*')) - - sym_addrs = {} - with open(sym_name, 'r', encoding='utf-8') as file: - for line in file: - line = line.split(';', 1)[0].rstrip() - parts = line.split(' ', 1) - if len(parts) != 2: - continue - addr, sym = parts - sym_addrs[sym] = addr - - with open(wram_name, 'r', encoding='utf-8') as file: - cur_label = None - for line in file: - line = line.rstrip() - if (m = re.match(sym_def_rx, line)): - sym, rest = m.group(1), m.group(2) - if sym is None and rest is None: - sym, rest = m.group(3), m.group(4) - key = sym - if not sym.startswith('.'): - cur_label = sym - elif cur_label: - key = cur_label + sym - if key in sym_addrs: - addr = sym_addrs[key] - line = sym + rest + ' ; ' + addr - print(line) - -if __name__ == '__main__': - main() |
