omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
omega-bridge / tools / bridge-seeded
| 1 | #!/bin/sh |
| 2 | # Explicit checked frontends: frozen e5b32567 or --float-next draft #1049. |
| 3 | # Authorized by Main acting for Drake for CUDApp native x86 portability. |
| 4 | set -eu |
| 5 | next=0 |
| 6 | runtime=0 |
| 7 | if [ "${1-}" = --runtime-views ]; then runtime=1; shift; fi |
| 8 | if [ "${1-}" = --float-next ]; then next=1; shift; fi |
| 9 | case ${1-} in c) mode=D;; python) mode=Q;; h) mode=H;; lib-c) mode=L;; lib-h) mode=M;; lib-map) mode=V;; *) echo 'usage: tools/bridge-seeded [--runtime-views | --float-next] c|python|h|lib-c|lib-h|lib-map source.om' >&2; exit 64;; esac |
| 10 | case $mode in L|M|V) lib=1;; *) lib=0;; esac |
| 11 | [ "$lib" = 0 ] || [ "$next$runtime" = 00 ] || { echo 'library modes use the frozen e5 profile' >&2; exit 24; } |
| 12 | if [ "$next" = 1 ]; then |
| 13 | case $mode in D) mode=E;; H) mode=J;; *) echo 'next float profile supports c|h only' >&2; exit 24;; esac |
| 14 | fi |
| 15 | if [ "$runtime" = 1 ]; then |
| 16 | [ "$next" = 0 ] || { echo 'runtime views require the frozen e5 profile' >&2; exit 24; } |
| 17 | case $mode in D) mode=R;; H) mode=S;; *) echo 'runtime views support c|h only' >&2; exit 24;; esac |
| 18 | fi |
| 19 | [ "$#" = 2 ] || exit 64 |
| 20 | input=$(realpath -- "$2") |
| 21 | cd "$(dirname "$0")/.." |
| 22 | sha256sum --status -c build/compiler.sha256 || { echo 'rebuild required: tools/build.sh' >&2; exit 65; } |
| 23 | want=2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f |
| 24 | if [ "$next" = 1 ]; then |
| 25 | seed=${OMEGA_SEEDED_NEXT_OMC:-} |
| 26 | want=d89bdc08ca21ea9726f1117adc791f683287d3698ea112a9db5519df2e79aeec |
| 27 | label=OMEGA_SEEDED_NEXT_OMC |
| 28 | else |
| 29 | seed=${OMEGA_SEEDED_OMC:-} |
| 30 | label=OMEGA_SEEDED_OMC |
| 31 | fi |
| 32 | [ -n "$seed" ] && [ -f "$seed" ] || { echo "NOT_RUN: set $label" >&2; exit 3; } |
| 33 | [ "$(sha256sum "$seed" | cut -d' ' -f1)" = "$want" ] || { echo 'seeded frontend fingerprint mismatch' >&2; exit 65; } |
| 34 | tmp=$(mktemp -d build/seeded-request.XXXXXX) |
| 35 | trap 'find "$tmp" -type f -delete; rmdir "$tmp"' EXIT HUP INT TERM |
| 36 | cat "$input" > "$tmp/input.om" |
| 37 | "$seed" < "$tmp/input.om" > "$tmp/native" |
| 38 | [ -s "$tmp/native" ] || exit 65 |
| 39 | if [ "$lib" = 1 ]; then |
| 40 | # cabi-1 provenance trailer: generator and source digests. src/toc.om recomputes both with its own |
| 41 | # SHA-256 (generator bytes on fd 3, source bytes from stdin) and refuses a mismatch with error 52. |
| 42 | # Successor: a seeded-Omega driver replaces this shell (ISSUES-TO-FILE.md, bridge-seeded successor). |
| 43 | { printf '%s' "$mode"; cat "$tmp/input.om"; printf '\n%s %s\n' "$(sha256sum src/toc.om | cut -d' ' -f1)" "$(sha256sum "$tmp/input.om" | cut -d' ' -f1)"; } | build/bridge 3< src/toc.om |
| 44 | else |
| 45 | { printf '%s' "$mode"; cat "$tmp/input.om"; } | build/bridge |
| 46 | fi |