OdysseyDecomp/tools/diff.py
MonsterDruide1 72b3d5cdce Moving structure to system as zeldaret/botw
Co-authored-by: leoetlino <leo@leolam.fr>
2021-08-19 16:30:33 +02:00

61 lines
2.1 KiB
Python
Executable file

#!/usr/bin/env python3
import argparse
import subprocess
import cxxfilt
from colorama import Fore, Style
from util import utils
import util.checker
import check
parser = argparse.ArgumentParser(description="Diff assembly")
parser.add_argument(
"function", help="Name of the function to diff. Pass | to get a WIP function", nargs="?", default="|")
args, unknown = parser.parse_known_args()
find_wip = args.function == "|"
def find_function_info(name: str):
for info in utils.get_functions():
if info.decomp_name == name or (find_wip and info.status == utils.FunctionStatus.Wip):
return info
for info in utils.get_functions():
if name in cxxfilt.demangle(info.decomp_name):
return info
return None
def check_func(info):
checker = util.checker.FunctionChecker(log_mismatch_cause=True)
return check.check_function(checker, info.addr, info.size, info.decomp_name)
info = find_function_info(args.function)
if info is not None:
if not info.decomp_name:
utils.fail(f"{args.function} has not been decompiled")
print("comparing functions...")
if(check_func(info)):
print("matching function!")
else:
print(
f"diffing: {Style.BRIGHT}{Fore.BLUE}{cxxfilt.demangle(info.decomp_name)}{Style.RESET_ALL} {Style.DIM}({info.decomp_name}){Style.RESET_ALL}")
addr_end = info.addr + info.size
subprocess.call(["tools/asm-differ/diff.py", "-I", "-e", info.decomp_name, "0x%016x" %
info.addr, "0x%016x" % addr_end] + unknown)
if info.status == utils.FunctionStatus.NonMatching:
utils.warn(
f"{info.decomp_name} is marked as non-matching and possibly NOT functionally equivalent")
elif info.status == utils.FunctionStatus.Equivalent:
utils.warn(f"{info.decomp_name} is marked as functionally equivalent but non-matching")
else:
if find_wip:
utils.fail("no WIP function")
utils.fail(
f"unknown function '{args.function}'\nfor constructors and destructors, list the complete object constructor (C1) or destructor (D1)")