Skip to content

Commit 8b2ffd6

Browse files
committed
maptool: add --partial to search for partial/incomplete shared funcs
welp, looks like there's a few here
1 parent 9564d7a commit 8b2ffd6

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tools/maptool.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,31 @@ def find_equal_asm_files(searchType, map1, map2, maxdistance, replaceIncludeAsm,
612612
print(f"\nError: File {file2_sym_path} not found.")
613613
else:
614614
print("\nNo matching files found.")
615+
616+
def find_partial_shares():
617+
# Search map .c files for funcs in include/maps/shared which are INCLUDE_ASM instead of #include
618+
include_dir = "include/maps/shared"
619+
src_dir = "src/maps"
620+
621+
# Get all filenames in include/shared without extension
622+
include_files = [
623+
os.path.splitext(f)[0]
624+
for f in os.listdir(include_dir)
625+
if os.path.isfile(os.path.join(include_dir, f))
626+
]
627+
628+
# Walk through all .c files under src/maps
629+
for root, _, files in os.walk(src_dir):
630+
for cfile in files:
631+
if not cfile.endswith(".c"):
632+
continue
633+
cpath = os.path.join(root, cfile)
634+
with open(cpath, "r", errors="ignore") as f:
635+
lines = f.readlines()
636+
for lineno, line in enumerate(lines, start=1):
637+
for inc in include_files:
638+
if inc in line and "INCLUDE_ASM" in line:
639+
print(f"{cpath}:{lineno}: {line.strip()}")
615640

616641
# Map header related code
617642

@@ -756,6 +781,7 @@ def print_usage():
756781
print(" --sortsyms [MAP_NAME] Sort map symbols ('all' to sort all map symbol files)")
757782
print(" --compareFuncs [FUNC1_ASM_PATH] [FUNC2_ASM_PATH] Compare two functions, print Levenshtein distance, write clean files for comparing")
758783
print(" --similar [MAX_DIFF] [FUNC_ASM_PATH] Search for funcs similar to FUNC_ASM_PATH, with max difference of MAX_DIFF")
784+
print(" --partial Search map .c files for funcs in include/maps/shared which are INCLUDE_ASM instead of #include")
759785

760786
def main():
761787
import argparse
@@ -780,13 +806,18 @@ def main():
780806
parser.add_argument("--sortsyms", type=str)
781807
parser.add_argument("--compareFuncs", action="store_true")
782808
parser.add_argument("--similar", type=int)
809+
parser.add_argument("--partial", action="store_true")
783810

784811
args = parser.parse_args()
785812

786813
if args.help:
787814
print_usage()
788815
return
789816

817+
if args.partial:
818+
find_partial_shares()
819+
return
820+
790821
if args.sortsyms is not None:
791822
map_files = [args.sortsyms]
792823
if args.sortsyms == "all":

0 commit comments

Comments
 (0)