about summary refs log tree commit diff stats
path: root/treeshake_translate
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2019-12-05 23:42:34 -0800
committerKartik Agaram <vc@akkartik.com>2019-12-05 23:45:22 -0800
commitb6d62cc91c144ad15a2d8361a95be99b1003c5ae (patch)
treee8f8169a1f1c9e41bc04cbbdef69bbb2c9c2cd3c /treeshake_translate
parent58467e6cbc4fce0c11a5200b9846c7a47ec874d9 (diff)
downloadmu-b6d62cc91c144ad15a2d8361a95be99b1003c5ae.tar.gz
5793
Start of a new script called treeshake to emit stats for minimal line counts
and binary sizes for all apps.

It doesn't actually do any dead-code deletion yet. But it does build and
run all apps successfully. (Except apps/mu; we'll ignore that for now.
It's probably not being disciplined about identifying internal labels.)
Diffstat (limited to 'treeshake_translate')
-rwxr-xr-xtreeshake_translate42
1 files changed, 42 insertions, 0 deletions
diff --git a/treeshake_translate b/treeshake_translate
new file mode 100755
index 00000000..beb19aa5
--- /dev/null
+++ b/treeshake_translate
@@ -0,0 +1,42 @@
+#!/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*$' $* |./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