papermario/tools/asm_sizes.py
Ethan Roseman 8c690d23d1
Assorted Morsels (#297)
* bss

* 3 audios

* d5a50 stuff

* some icon funcs

* get_icon_render_pos

* PlayerLandJump

* func_80248170

* cleanup

* splat update prep

* git subrepo pull --force tools/splat

subrepo:
  subdir:   "tools/splat"
  merged:   "81c4b35b89"
upstream:
  origin:   "https://github.com/ethteck/splat.git"
  branch:   "master"
  commit:   "81c4b35b89"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"

* git subrepo pull tools/splat

subrepo:
  subdir:   "tools/splat"
  merged:   "9b791a654a"
upstream:
  origin:   "https://github.com/ethteck/splat.git"
  branch:   "master"
  commit:   "9b791a654a"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"

* git subrepo pull tools/splat

subrepo:
  subdir:   "tools/splat"
  merged:   "2cf2a5e5d8"
upstream:
  origin:   "https://github.com/ethteck/splat.git"
  branch:   "master"
  commit:   "2cf2a5e5d8"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo.git"
  commit:   "2f68596"

* fix loop in PaperMarioNpcSprites

* git subrepo pull tools/splat

subrepo:
  subdir:   "tools/splat"
  merged:   "2fab217750"
upstream:
  origin:   "https://github.com/ethteck/splat.git"
  branch:   "master"
  commit:   "2fab217750"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "2f68596"

* add sha1 to yaml

* git subrepo pull tools/splat

subrepo:
  subdir:   "tools/splat"
  merged:   "426b08200d"
upstream:
  origin:   "https://github.com/ethteck/splat.git"
  branch:   "master"
  commit:   "426b08200d"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "2f68596"

* varTable -> union :( + player_api funcs

* 6 more

* 4 more

* 5 mo

* 1 mo

* 1 mo 2

* 5 mo

* player_jump

* 3 mo

* some 18F340

* 6 more

* 6 mo

* nm

* 1

* 1 more

* some PR feedback

* symbol addr update

* UnsetCamera0Flag1000

* SetPlayerSpriteSet2

* action 18

* encounter + a smol hammer

* git subrepo pull (merge) tools/splat

subrepo:
  subdir:   "tools/splat"
  merged:   "8cf482fe57"
upstream:
  origin:   "https://github.com/ethteck/splat.git"
  branch:   "master"
  commit:   "4c0a93eaed"
git-subrepo:
  version:  "0.4.3"
  origin:   "https://github.com/ingydotnet/git-subrepo"
  commit:   "2f68596"

* 3 and cleanup

* undo yucky union

* PR comments

* get_enemy_safe

* cleanup

* move VirtualEntity

* attempt to fix doxygen

* 3, cleanup

* broken

* fixed!

* progress

* 2

* 3 and cleanup

* 6 map_api funcs

* 3 map api

* CreateNpc

* BringPartnerOut & NpcFlyTo

* npc_api complete

* update_scripts

* 4 si bois inc si_execute_next_command

* update symbol_addrs

* 2 more and cleanup

* camera struct & do_camera_type_0

* PR feedback

* small tidying
2021-06-21 13:30:57 +09:00

57 lines
1.2 KiB
Python
Executable File

#! /usr/bin/python3
import glob
import os
print_funcs = True
sizes = {}
funcs = {}
def calc_insns(f_path):
ret = 0
with open(f_path) as f:
f_lines = f.readlines()
for line in f_lines:
if line.startswith("/* "):
ret += 1
funcs[f_path.split("/")[-1][:-2]] = ret
return ret
def do_dir(root, dir):
max = 0
min = None
total = 0
files = glob.glob(os.path.join(root, dir) + "/*.s")
for f in files:
amt = calc_insns(f)
if amt > max:
max = amt
if min is None or amt < min:
min = amt
total += amt
avg = 0 if len(files) == 0 else total / len(files)
sizes[dir] = ((min, max, total, avg))
script_dir = os.path.dirname(os.path.realpath(__file__))
asm_dir = script_dir + "/../ver/current/asm/nonmatchings"
for root, dirs, files in os.walk(asm_dir):
for asm_dir in dirs:
if "/os" not in root and "/world/" not in root and "/battle/" not in root:
do_dir(root, asm_dir)
for thing in sorted(sizes.keys(), key=lambda x: sizes[x][2]):
val = sizes[thing][2]
if val > 0:
print(thing.ljust(25) + str(val))
if print_funcs:
print(dict(sorted(funcs.items(), key=lambda f: f[1])))