mk64/tools/generate_vertice_count.py

35 lines
1.2 KiB
Python

import sys
import subprocess
# This script generates vertice count for course geography used in the courseTable.
dir_path = "build/us/courses/"
output_file = "include/vertice_count_gen.h"
sym_list = []
output = ""
# Run objdump for each model.inc.elf file in courses/
for filename in subprocess.check_output(f"find {dir_path} -name model.inc.elf", shell=True).decode().splitlines():
file_output = subprocess.check_output(f"objdump -t {filename} | grep ' .data\| .bss' | awk '$6 != \"\" {{print $5, $6}}'", shell=True)
output += file_output.decode()
# Write includes and defines to the header file
with open(output_file, "w") as f:
# Write comments
f.write("// Generated by tools/generate_vertice_count.py\n\n")
# Write includes
f.write("#include <macros.h>\n\n")
# Write defines
for line in output.splitlines():
addr, name = line.split()
if (name == ".data"):
continue
# (size / 14) -> fill with zeros to make complete u32 -> toUppercase()
# One vertice = 14 bytes. objdump outputs the size. Divide size by 14.
f.write(f"#define {name}_count 0x{hex(int(addr, 16) // 14)[2:].zfill(8).upper()}\n\n")