2022-01-24 17:58:33 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
2021-09-22 13:17:46 +02:00
|
|
|
import os
|
2021-09-27 01:19:58 +02:00
|
|
|
import re
|
2021-09-22 13:17:46 +02:00
|
|
|
|
|
|
|
syms = []
|
|
|
|
groups = {}
|
|
|
|
|
|
|
|
with open("tools/symz.txt") as f:
|
|
|
|
for line in f.readlines():
|
2022-05-27 15:03:19 +02:00
|
|
|
if line.strip() and not line.startswith("//"):
|
2022-01-24 17:58:33 +01:00
|
|
|
name, addr = line.strip().strip(";").split(" = ")
|
|
|
|
syms.append({"name": name, "address": int(addr, 0), "found_in": set(), "dead": False})
|
2021-09-22 13:17:46 +02:00
|
|
|
|
|
|
|
# Search src for syms
|
|
|
|
for root, dirs, files in os.walk("src"):
|
|
|
|
for file in files:
|
2022-01-24 17:58:33 +01:00
|
|
|
if file.endswith(".c") and "bss" not in file:
|
2021-09-22 13:17:46 +02:00
|
|
|
with open(os.path.join(root, file)) as f:
|
|
|
|
text = f.read()
|
|
|
|
for sym in syms:
|
2021-09-27 01:19:58 +02:00
|
|
|
if sym["name"] in text:
|
2022-01-24 17:58:33 +01:00
|
|
|
sym["found_in"].add(os.path.join(root, file).replace("src/", ""))
|
2021-09-22 13:17:46 +02:00
|
|
|
|
|
|
|
# Search asm for syms
|
|
|
|
for root, dirs, files in os.walk("ver/us/asm"):
|
|
|
|
for file in files:
|
|
|
|
if file.endswith(".s"):
|
|
|
|
with open(os.path.join(root, file)) as f:
|
|
|
|
text = f.read()
|
|
|
|
for sym in syms:
|
2021-09-27 01:19:58 +02:00
|
|
|
if sym["name"] in text:
|
|
|
|
sym["found_in"].add(os.path.join(root, file).replace("ver/us/asm/nonmatchings/", ""))
|
2022-01-24 17:58:33 +01:00
|
|
|
if re.match(r"E[A-F][0-9A-F]{4}", root.split("/")[-1]):
|
2021-09-27 01:19:58 +02:00
|
|
|
sym["dead"] = True
|
|
|
|
else:
|
|
|
|
sym["dead"] = False
|
2021-09-22 13:17:46 +02:00
|
|
|
|
|
|
|
for sym in syms:
|
2021-09-27 01:19:58 +02:00
|
|
|
if len(sym["found_in"]) == 0:
|
2021-09-22 13:17:46 +02:00
|
|
|
group = ""
|
2021-09-27 01:19:58 +02:00
|
|
|
elif sym["dead"]:
|
|
|
|
group = "dead"
|
|
|
|
elif len(sym["found_in"]) > 1:
|
2021-09-22 13:17:46 +02:00
|
|
|
group = "multig"
|
|
|
|
else:
|
2021-09-27 01:19:58 +02:00
|
|
|
group = next(iter(sym["found_in"]))
|
2021-09-22 13:17:46 +02:00
|
|
|
|
|
|
|
if group not in groups:
|
|
|
|
groups[group] = []
|
|
|
|
groups[group].append(sym)
|
|
|
|
|
|
|
|
for group in groups:
|
|
|
|
if group == "":
|
2022-01-24 17:58:33 +01:00
|
|
|
print("// The following symbols can be simply removed from undefined_syms:")
|
2021-09-22 13:17:46 +02:00
|
|
|
elif group == "multig":
|
2022-01-24 17:58:33 +01:00
|
|
|
print("// The following symbols are found in multiple locations:")
|
2021-09-27 01:19:58 +02:00
|
|
|
elif group == "dead":
|
2022-01-24 17:58:33 +01:00
|
|
|
print("// The following symbols are dead:")
|
2021-09-22 13:17:46 +02:00
|
|
|
else:
|
2022-01-24 17:58:33 +01:00
|
|
|
print("// " + group + ":")
|
2021-09-22 13:17:46 +02:00
|
|
|
|
2021-09-27 01:19:58 +02:00
|
|
|
sorted_syms = sorted(groups[group], key=lambda tup: tup["address"])
|
2021-09-22 13:17:46 +02:00
|
|
|
|
|
|
|
for sym in sorted_syms:
|
2021-09-27 01:19:58 +02:00
|
|
|
print(f"{sym['name']} = 0x{sym['address']:X}")
|
2021-09-22 13:17:46 +02:00
|
|
|
print()
|