Uncached `ziran run` of a ZX bundle spent its time rescanning text and reading thread-local state through emutls on 32-bit Android. - Embedded runtime and native headers carry a bitmask of the headers they include, so header closure needs no strstr over 2 MB texts. - Native helper discovery walks each text's words once, marking includes and helper calls in the same pass. - ScalarType dispatches on length; builder_text_module formats its scoped name only after the cheap rejections. - The IR writer remembers written string addresses; the reader keeps each string-table entry once and records its context once per read. - Each thread's compiler state is one record (zir_thread.h): memory scope, selected context, storage hints and the KeepText cache. Field walks, symbol lookups and KeepText find it once and pass it down. Bundles, native C and Breeze's generated C are byte-identical.
25 lines
930 B
Bash
Executable File
25 lines
930 B
Bash
Executable File
#!/bin/sh
|
|
# Write a C source holding each runtime header's text, so zi2c
|
|
# can copy the headers a program includes next to its generated code,
|
|
# and which other embedded headers each text includes (bit j for header j).
|
|
set -eu
|
|
test $# -le 32 || { echo "embed_headers.sh: at most 32 headers" >&2; exit 1; }
|
|
echo '/* Generated by scripts/embed_headers.sh. Do not edit. */'
|
|
echo '#include "zir_runtime.h"'
|
|
echo '#include <stddef.h>'
|
|
echo 'const ZirRuntimeHeader ZirRuntimeHeaders[] = {'
|
|
for header in "$@"; do
|
|
printf ' {"%s",\n' "$(basename "$header")"
|
|
sed -e 's/\\/\\\\/g' -e 's/"/\\"/g' -e 's/^/ "/' -e 's/$/\\n"/' "$header"
|
|
includes=0 bit=0
|
|
for other in "$@"; do
|
|
if grep -qF "#include \"$(basename "$other")\"" "$header"; then
|
|
includes="$includes | 1u << $bit"
|
|
fi
|
|
bit=$((bit + 1))
|
|
done
|
|
printf ' , %s},\n' "$includes"
|
|
done
|
|
echo ' {NULL, NULL, 0}'
|
|
echo '};'
|