about summary refs log tree commit diff stats
path: root/tools/treeshake_all
blob: 58efcf1ae76ba670fa3bdece405cf5d1a48628c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/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[0-8]*.subx apps/$app.subx
  diff apps/$app a.elf
done

for app in hex survey pack assort dquotes tests
do
  echo $app
  tools/test_treeshake_translate init.$OS 0[0-8]*.subx apps/subx-params.subx apps/$app.subx
  diff apps/$app a.elf
done

for app in 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-9]*.subx apps/mu.subx
diff apps/mu a.elf