diff --git a/reccmp/tools/asmcmp.py b/reccmp/tools/asmcmp.py index f40afb6a..90ee71bf 100755 --- a/reccmp/tools/asmcmp.py +++ b/reccmp/tools/asmcmp.py @@ -264,6 +264,10 @@ def main(): ### Compare everything. + # Count how many functions have the same virtual address in orig and recomp. + functions_aligned_count = 0 + + # Number of functions compared (i.e. excluding stubs) function_count = 0 total_accuracy = 0 total_effective_accuracy = 0 @@ -275,6 +279,12 @@ def main(): match, show_both_addrs=args.print_rec_addr, is_plain=args.no_color ) + if ( + match.match_type == SymbolType.FUNCTION + and match.orig_addr == match.recomp_addr + ): + functions_aligned_count += 1 + if match.match_type == SymbolType.FUNCTION and not match.is_stub: function_count += 1 total_accuracy += match.ratio @@ -322,15 +332,22 @@ def main(): implemented_funcs = function_count + # If we know how many functions are in the file (via analysis with Ghidra or other tools) + # we can substitute an alternate value to use when calculating the percentages below. if args.total: - function_count = int(args.total) + # Use the alternate value if it exceeds the number of annotated functions + function_count = max(function_count, int(args.total)) if function_count > 0: effective_accuracy = total_effective_accuracy / function_count * 100 actual_accuracy = total_accuracy / function_count * 100 + alignment_percentage = functions_aligned_count / function_count * 100 print( f"\nTotal effective accuracy {effective_accuracy:.2f}% across {function_count} functions ({actual_accuracy:.2f}% actual accuracy)" ) + print( + f"{functions_aligned_count} functions are aligned ({alignment_percentage:.2f}%)" + ) if args.svg is not None: gen_svg(