diff options
author | Kartik Agaram <vc@akkartik.com> | 2019-12-07 15:20:44 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2019-12-07 18:05:06 -0800 |
commit | c1d596f56a6f2198ea8ea1b0a90c613e919d891b (patch) | |
tree | 6e44703f23864ad78dd68e7b0a9229f54a46b281 | |
parent | e9aee071f44876bcce4d741eea52198249e5b339 (diff) | |
download | mu-c1d596f56a6f2198ea8ea1b0a90c613e919d891b.tar.gz |
5796 - move treeshake to a new tools/ directory
-rwxr-xr-x | build | 5 | ||||
-rwxr-xr-x | clean | 3 | ||||
-rw-r--r-- | tools/Readme.md | 11 | ||||
-rwxr-xr-x | tools/test_treeshake_translate | 29 | ||||
-rw-r--r-- | tools/treeshake.cc (renamed from treeshake.cc) | 0 | ||||
-rwxr-xr-x | tools/treeshake_all | 44 | ||||
-rwxr-xr-x | tools/treeshake_translate | 8 | ||||
-rwxr-xr-x | treeshake_all | 42 | ||||
-rwxr-xr-x | treeshake_ntranslate | 40 | ||||
-rwxr-xr-x | treeshake_translate | 44 |
10 files changed, 94 insertions, 132 deletions
diff --git a/build b/build index 9028bfa3..9e95bb34 100755 --- a/build +++ b/build @@ -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 diff --git a/clean b/clean index aeb8f520..567d6152 100755 --- a/clean +++ b/clean @@ -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; ) diff --git a/tools/Readme.md b/tools/Readme.md new file mode 100644 index 00000000..3a24955b --- /dev/null +++ b/tools/Readme.md @@ -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 + ``` diff --git a/tools/test_treeshake_translate b/tools/test_treeshake_translate new file mode 100755 index 00000000..1aa6f068 --- /dev/null +++ b/tools/test_treeshake_translate @@ -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 diff --git a/treeshake.cc b/tools/treeshake.cc index 9bf5106e..9bf5106e 100644 --- a/treeshake.cc +++ b/tools/treeshake.cc 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 diff --git a/tools/treeshake_translate b/tools/treeshake_translate new file mode 100755 index 00000000..ba80dea0 --- /dev/null +++ b/tools/treeshake_translate @@ -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 diff --git a/treeshake_all b/treeshake_all deleted file mode 100755 index 8ebf51d0..00000000 --- a/treeshake_all +++ /dev/null @@ -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 diff --git a/treeshake_ntranslate b/treeshake_ntranslate deleted file mode 100755 index 7a54e436..00000000 --- a/treeshake_ntranslate +++ /dev/null @@ -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 diff --git a/treeshake_translate b/treeshake_translate deleted file mode 100755 index 6794b066..00000000 --- a/treeshake_translate +++ /dev/null @@ -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 |