mirror of https://github.com/zeldaret/mm.git
parent
77cfd399d0
commit
cf98c4e7e8
|
|
@ -18,6 +18,14 @@ parser.add_argument(
|
||||||
default=False,
|
default=False,
|
||||||
help="Decompile all files regardless of whether they are used or not",
|
help="Decompile all files regardless of whether they are used or not",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"-files",
|
||||||
|
"--files",
|
||||||
|
dest="files",
|
||||||
|
nargs="+",
|
||||||
|
required=False,
|
||||||
|
help="Optional list of files to diassemble separated by a space. This is a whitelist, all files will be skipped besides the ones listed here if used.",
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
jobs = args.jobs
|
jobs = args.jobs
|
||||||
|
|
@ -26,7 +34,7 @@ ASM_OUT = "asm/"
|
||||||
DATA_OUT = "data/"
|
DATA_OUT = "data/"
|
||||||
|
|
||||||
|
|
||||||
def discard_decomped_files(files_spec):
|
def discard_decomped_files(files_spec, include_files):
|
||||||
root_path = Path(__file__).parent.parent.parent
|
root_path = Path(__file__).parent.parent.parent
|
||||||
|
|
||||||
with open(root_path / "spec", "r") as f:
|
with open(root_path / "spec", "r") as f:
|
||||||
|
|
@ -38,6 +46,12 @@ def discard_decomped_files(files_spec):
|
||||||
for f in files_spec:
|
for f in files_spec:
|
||||||
name, _, type, _, file_list = f
|
name, _, type, _, file_list = f
|
||||||
|
|
||||||
|
force_include = False
|
||||||
|
if include_files:
|
||||||
|
if not any([x in name for x in include_files]):
|
||||||
|
continue
|
||||||
|
force_include = True
|
||||||
|
|
||||||
# Find the beginseg for this file
|
# Find the beginseg for this file
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(spec):
|
while i < len(spec):
|
||||||
|
|
@ -92,6 +106,7 @@ def discard_decomped_files(files_spec):
|
||||||
if "GLOBAL_ASM" in f2.read():
|
if "GLOBAL_ASM" in f2.read():
|
||||||
include = True
|
include = True
|
||||||
|
|
||||||
|
include |= force_include
|
||||||
if include:
|
if include:
|
||||||
new_files[offset] = file
|
new_files[offset] = file
|
||||||
included = True
|
included = True
|
||||||
|
|
@ -2191,16 +2206,23 @@ for segment in files_spec:
|
||||||
full_file_list[segment[0]] = new
|
full_file_list[segment[0]] = new
|
||||||
|
|
||||||
if args.full:
|
if args.full:
|
||||||
|
new_spec = []
|
||||||
for segment in files_spec:
|
for segment in files_spec:
|
||||||
|
if args.files and not any(
|
||||||
|
[file_name in segment[0] for file_name in args.files]
|
||||||
|
):
|
||||||
|
continue
|
||||||
for offset, name in segment[4].items():
|
for offset, name in segment[4].items():
|
||||||
if name == "":
|
if name == "":
|
||||||
name = f"{segment[2]}_{offset:08X}"
|
name = f"{segment[2]}_{offset:08X}"
|
||||||
segment[4][offset] = name
|
segment[4][offset] = name
|
||||||
|
new_spec.append(segment)
|
||||||
|
files_spec = new_spec
|
||||||
else:
|
else:
|
||||||
# Prune
|
# Prune
|
||||||
old_file_count = sum([len(f[4].keys()) for f in files_spec])
|
old_file_count = sum([len(f[4].keys()) for f in files_spec])
|
||||||
|
|
||||||
files_spec = discard_decomped_files(files_spec)
|
files_spec = discard_decomped_files(files_spec, args.files)
|
||||||
|
|
||||||
new_file_count = sum([len(f[4].keys()) for f in files_spec])
|
new_file_count = sum([len(f[4].keys()) for f in files_spec])
|
||||||
|
|
||||||
|
|
@ -2413,11 +2435,20 @@ rodata_symbols_regex = re.compile(r"(?<=\n)glabel (.+)(?=\n)")
|
||||||
asm_symbols_regex = re.compile(r"%(?:lo|hi)\((.+?)\)")
|
asm_symbols_regex = re.compile(r"%(?:lo|hi)\((.+?)\)")
|
||||||
|
|
||||||
# Split files and migrate rodata that should be migrated
|
# Split files and migrate rodata that should be migrated
|
||||||
for root, dirs, files in os.walk(ASM_OUT):
|
for file in Path(ASM_OUT).glob("**/*.s"):
|
||||||
for f in files:
|
asm_path = str(file)
|
||||||
if "non_matchings" in root:
|
|
||||||
|
if "non_matchings" in asm_path:
|
||||||
continue
|
continue
|
||||||
asm_path = os.path.join(root, f)
|
|
||||||
|
if file.parts[1] == "overlays":
|
||||||
|
name = file.parts[2]
|
||||||
|
else:
|
||||||
|
name = file.parts[1]
|
||||||
|
|
||||||
|
if not any([name == section[-1]["name"] for section in all_sections]):
|
||||||
|
continue
|
||||||
|
|
||||||
rodata_path = (
|
rodata_path = (
|
||||||
asm_path.replace(ASM_OUT + "overlays/", DATA_OUT)
|
asm_path.replace(ASM_OUT + "overlays/", DATA_OUT)
|
||||||
.replace(ASM_OUT, DATA_OUT)
|
.replace(ASM_OUT, DATA_OUT)
|
||||||
|
|
@ -2533,9 +2564,9 @@ for root, dirs, files in os.walk(ASM_OUT):
|
||||||
# TODO hack: getting the address from a comment
|
# TODO hack: getting the address from a comment
|
||||||
first_block_split = late_rodata[0][1].split(" */ .")
|
first_block_split = late_rodata[0][1].split(" */ .")
|
||||||
vaddr = None
|
vaddr = None
|
||||||
if first_block_split[1].startswith(
|
if first_block_split[1].startswith("float") or first_block_split[
|
||||||
"float"
|
1
|
||||||
) or first_block_split[1].startswith("double"):
|
].startswith("double"):
|
||||||
vaddr = first_block_split[0].split(" ")[-2]
|
vaddr = first_block_split[0].split(" ")[-2]
|
||||||
else:
|
else:
|
||||||
vaddr = first_block_split[0].split(" ")[-1]
|
vaddr = first_block_split[0].split(" ")[-1]
|
||||||
|
|
@ -2562,7 +2593,9 @@ for root, dirs, files in os.walk(ASM_OUT):
|
||||||
]:
|
]:
|
||||||
# hacks for especially badly behaved rodata, TODO these are ALL jumptables associated with
|
# hacks for especially badly behaved rodata, TODO these are ALL jumptables associated with
|
||||||
# comparatively tiny functions, can we swat these programmatically?
|
# comparatively tiny functions, can we swat these programmatically?
|
||||||
late_rodata_alignment = f".late_rodata_alignment {'8' if vaddr % 8 == 0 else '4'}\n"
|
late_rodata_alignment = (
|
||||||
|
f".late_rodata_alignment {'8' if vaddr % 8 == 0 else '4'}\n"
|
||||||
|
)
|
||||||
|
|
||||||
rdata_out = ""
|
rdata_out = ""
|
||||||
if rdata is not None:
|
if rdata is not None:
|
||||||
|
|
@ -2592,14 +2625,11 @@ for root, dirs, files in os.walk(ASM_OUT):
|
||||||
all_out = rodata_out + text_out
|
all_out = rodata_out + text_out
|
||||||
|
|
||||||
# write it out
|
# write it out
|
||||||
out_path = (
|
out_path = Path(asm_path.replace(ASM_OUT, f"{ASM_OUT}non_matchings/")).parent
|
||||||
root.replace(ASM_OUT, f"{ASM_OUT}/non_matchings/")
|
if out_path.parts[2] not in ("overlays", "makerom"):
|
||||||
+ "/"
|
out_path /= file.name.split(".")[0]
|
||||||
+ ((f.replace(".text.s", "") + "/") if "overlays" not in root else "")
|
out_path.mkdir(parents=True, exist_ok=True)
|
||||||
)
|
|
||||||
os.makedirs(out_path, exist_ok=True)
|
|
||||||
with open(out_path + label + ".s", "w") as outfile:
|
|
||||||
outfile.write(all_out.strip() + "\n")
|
|
||||||
|
|
||||||
# remove rodata and unsplit file
|
out_path /= label + ".s"
|
||||||
# TODO
|
with open(out_path, "w") as outfile:
|
||||||
|
outfile.write(all_out.strip() + "\n")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue