about summary refs log blame commit diff stats
path: root/tools/treeshake_all
blob: bdf14c906a363c4e4af35e1751b725244b38a44c (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13












                                                    













                                                                                                              



                                                                                                             
              

                                    
                                  





                                             
                                                                     


                      







                                                                                           





                                                                                      



                                                                  
#!/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}

process() {
  app=$1
  tools/treeshake_translate init.$OS 0*.subx apps/subx-params.subx apps/$app.subx
  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 a.in |wc -l) => $(cat a.treeshake |wc -l)"
  echo "binary size: $(ls -lh apps/$app |column 5) => $(ls -lh a.elf |column 5)"
}

if [ $# -gt 0 ]
then
  process $1
  exit 0
fi

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"
  process $app
  mv a.in apps/$app.in
  mv a.treeshake apps/$app.treeshake
  mv a.elf apps/$app.treeshake.bin
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

app=mu
echo $app
tools/test_treeshake_translate init.$OS [0-9]*.subx apps/$app.subx
diff apps/$app a.elf