5796 - move treeshake to a new tools/ directory

This commit is contained in:
Kartik Agaram 2019-12-07 15:20:44 -08:00
parent e9aee071f4
commit c1d596f56a
10 changed files with 94 additions and 132 deletions

5
build
View File

@ -106,9 +106,4 @@ older_than subx_bin subx.cc *_list && {
$CXX $CFLAGS subx.cc -o subx_bin
}
older_than treeshake treeshake.cc && {
echo $CXX $CFLAGS treeshake.cc -o treeshake
$CXX $CFLAGS treeshake.cc -o treeshake
}
exit 0

3
clean
View File

@ -5,7 +5,8 @@ set -v
rm -rf subx.cc subx_bin* *_list
rm -rf .until
test $# -gt 0 && exit 0 # convenience: 'clean top-level' to leave subsidiary tools alone
rm -rf enumerate/enumerate tangle/tangle tangle/*_list */*.dSYM treeshake
rm -rf enumerate/enumerate tangle/tangle tangle/*_list */*.dSYM
rm -rf browse_trace/browse_trace_bin browse_trace/*_list
rm -rf tools/treeshake
rm -rf tmp mu-linux.iso outfs initrd.fat mu-soso.iso
( cd kernel.soso && make clean; )

11
tools/Readme.md Normal file
View File

@ -0,0 +1,11 @@
Run all these from the top-level `mu/` directory.
### Miscellaneous odds and ends
These are built lazily.
* `treeshake_all`: rebuild SubX binaries without tests and unused functions.
Pretty hacky; just helps estimate the code needed to perform various tasks.
```
tools/treeshake_all
```

29
tools/test_treeshake_translate Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
# Translate SubX programs using a minified translator.
# Based on ntranslate.
set -e
./build
cat $* |apps/braces.treeshake.bin > a.braces
cat a.braces |apps/calls.treeshake.bin > a.calls
cat a.calls |apps/sigils.treeshake.bin > a.sigils
cat a.sigils |apps/tests.treeshake.bin > a.tests
cat a.tests |apps/assort.treeshake.bin > a.assort
cat a.assort |apps/dquotes.treeshake.bin > a.dquotes
cat a.dquotes |apps/assort.treeshake.bin > a.assort2
cat a.assort2 |apps/pack.treeshake.bin > a.pack
cat a.pack |apps/survey.treeshake.bin > a.survey
cat a.survey |apps/hex.treeshake.bin > a.elf
chmod +x a.elf

44
tools/treeshake_all Executable file
View File

@ -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

8
tools/treeshake_translate Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
# Translate SubX into minified ELF binaries for Linux.
set -e
grep -vh '^\s*#\|^\s*$' $* > a.in
cat a.in |tools/treeshake > a.treeshake
./ntranslate a.treeshake

View File

@ -1,42 +0,0 @@
#!/bin/sh
# Build minimal-size versions of all apps.
# Hacky; only intended for some stats at the moment.
set -e
cd `dirname $0`
./build
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
./treeshake_translate init.$OS 0*.subx apps/subx-params.subx apps/$app.subx 2> apps/$app.stderr
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 |./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
./treeshake_ntranslate 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
./treeshake_ntranslate init.$OS 0*.subx apps/subx-params.subx apps/$app.subx
diff apps/$app a.elf
done
echo mu.subx
./treeshake_ntranslate init.$OS 0*.subx apps/mu.subx
diff apps/mu a.elf

View File

@ -1,40 +0,0 @@
#!/bin/sh
# Translate SubX by running the minified self-hosted translator natively on Linux.
# This script is a hack; see the other *translate scripts instead.
set -e
./build
cat $* |apps/braces.treeshake.bin > a.braces
cat a.braces |apps/calls.treeshake.bin > a.calls
cat a.calls |apps/sigils.treeshake.bin > a.sigils
cat a.sigils |apps/tests.treeshake.bin > a.tests
cat a.tests |apps/assort.treeshake.bin > a.assort
cat a.assort |apps/dquotes.treeshake.bin > a.dquotes
# A little hack. We want ntranslate to always emit identical binaries to the
# C++ translator. The C++ translator assorts segments before it processes
# string literals, so we follow the same order above.
#
# However, dquotes currently emits a separate data segment for string literals.
# So we need to run assort a second time to clean up after it.
#
# Potential solutions:
# a) modify C++ translator to process string literals before assorting.
# b) clean up dquotes to assume assorted segments, and append to the
# existing data segment.
cat a.dquotes |apps/assort.treeshake.bin > a.assort2
cat a.assort2 |apps/pack.treeshake.bin > a.pack
cat a.pack |apps/survey.treeshake.bin > a.survey
cat a.survey |apps/hex.treeshake.bin > a.elf
chmod +x a.elf

View File

@ -1,44 +0,0 @@
#!/bin/sh
# Translate SubX into minimal ELF binaries for Linux.
# This script is a hack; see the other *translate scripts instead.
set -e
./build
grep -vh '^\s*#\|^\s*$' $* > a.in
cat a.in |./treeshake > a.treeshake
cat a.treeshake |apps/braces > a.braces
cat a.braces |apps/calls > a.calls
cat a.calls |apps/sigils > a.sigils
cat a.sigils |apps/tests > a.tests
cat a.tests |apps/assort > a.assort
cat a.assort |apps/dquotes > a.dquotes
# A little hack. We want ntranslate to always emit identical binaries to the
# C++ translator. The C++ translator assorts segments before it processes
# string literals, so we follow the same order above.
#
# However, dquotes currently emits a separate data segment for string literals.
# So we need to run assort a second time to clean up after it.
#
# Potential solutions:
# a) modify C++ translator to process string literals before assorting.
# b) clean up dquotes to assume assorted segments, and append to the
# existing data segment.
cat a.dquotes |apps/assort > a.assort2
cat a.assort2 |apps/pack > a.pack
cat a.pack |apps/survey > a.survey
cat a.survey |apps/hex > a.elf
chmod +x a.elf