about summary refs log tree commit diff stats
path: root/tools/treeshake_all
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-12-07 15:20:44 -0800
committerKartik Agaram <vc@akkartik.com>2019-12-07 18:05:06 -0800
commitc1d596f56a6f2198ea8ea1b0a90c613e919d891b (patch)
tree6e44703f23864ad78dd68e7b0a9229f54a46b281 /tools/treeshake_all
parente9aee071f44876bcce4d741eea52198249e5b339 (diff)
downloadmu-c1d596f56a6f2198ea8ea1b0a90c613e919d891b.tar.gz
5796 - move treeshake to a new tools/ directory
Diffstat (limited to 'tools/treeshake_all')
-rwxr-xr-xtools/treeshake_all44
1 files changed, 44 insertions, 0 deletions
diff --git a/tools/treeshake_all b/tools/treeshake_all
new file mode 100755
index 00000000..614b106a
--- /dev/null
+++ b/tools/treeshake_all
@@ -0,0 +1,44 @@
+#!/bin/sh
+# Build minimal-size versions of all apps.
+# Hacky; only intended for some stats at the moment.
+
+set -e
+
+[ ! -f tools/treeshake ] && {
+  echo building tools/treeshake
+  c++ -g -O3 tools/treeshake.cc -o tools/treeshake
+}
+
+export OS=${OS:-linux}
+
+echo "== deleting dead code"
+for app in factorial crenshaw2-1 crenshaw2-1b handle hex survey pack dquotes assort tests sigils calls braces
+do
+  echo "- $app"
+  tools/treeshake_translate init.$OS 0*.subx apps/subx-params.subx apps/$app.subx
+  mv a.in apps/$app.in
+  mv a.treeshake apps/$app.treeshake
+  echo "LoC $(cat apps/$app.subx |wc -l) => $(grep -vh '^\s*$\|^\s*#' apps/$app.subx |tools/treeshake |wc -l)"
+  echo "LoC including common libraries: $(cat apps/$app.in |wc -l) => $(cat apps/$app.treeshake |wc -l)"
+  mv a.elf apps/$app.treeshake.bin
+  echo "binary size: $(ls -lh apps/$app |column 5) => $(ls -lh apps/$app.treeshake.bin |column 5)"
+done
+
+echo "== testing treeshaken binaries"
+for app in factorial crenshaw2-1 crenshaw2-1b
+do
+  echo $app
+  tools/test_treeshake_translate init.$OS 0*.subx apps/$app.subx
+  diff apps/$app a.elf
+done
+
+for app in hex survey pack assort dquotes tests sigils calls braces
+do
+  echo $app
+  tools/test_treeshake_translate init.$OS 0*.subx apps/subx-params.subx apps/$app.subx
+  diff apps/$app a.elf
+done
+
+echo mu.subx
+tools/test_treeshake_translate init.$OS 0*.subx apps/mu.subx
+diff apps/mu a.elf