about summary refs log tree commit diff stats
path: root/treeshake_ntranslate
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-12-06 01:12:08 -0800
committerKartik Agaram <vc@akkartik.com>2019-12-06 01:12:08 -0800
commit68719bebc02ca355aa96dee2497f511d24606fc8 (patch)
tree4f279ad52a1f83e386672b81eeb1f95e4ae9d692 /treeshake_ntranslate
parentb6d62cc91c144ad15a2d8361a95be99b1003c5ae (diff)
downloadmu-68719bebc02ca355aa96dee2497f511d24606fc8.tar.gz
5794
Rather surprisingly, all the treeshake tooling is done in just about 2
hours of work. From now on it'll be easier to update stats.txt. Observations:

a) Binaries are tiny compared to conventional stacks. Tens of KB.
b) ~80% of binaries are tests and unused libraries in all my apps.
c) ~75% of LoC in SubX sources are tests or comments.
Diffstat (limited to 'treeshake_ntranslate')
-rwxr-xr-xtreeshake_ntranslate40
1 files changed, 40 insertions, 0 deletions
diff --git a/treeshake_ntranslate b/treeshake_ntranslate
new file mode 100755
index 00000000..7a54e436
--- /dev/null
+++ b/treeshake_ntranslate
@@ -0,0 +1,40 @@
+#!/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