#!/usr/bin/env bash # The spike, end to end: the real frontend produces a Tast, x86.ml turns it # into bytes, the bytes go into an mmap, and the mmap gets called. # # Driven by hand with ocamlfind and clang against the flan.cmxa dune already # builds, exactly as spike/embed does and for the same reason: nothing under # spike/ is wired into the build, so there is no dune file here and `dune test` # cannot see any of it. set -u here=$(cd "$(dirname "$0")" && pwd) root=$(cd "$here/../.." && pwd) cd "$root" || exit 1 dune build --root . lib/flan.cmxa 2>&1 | head -20 out=$(mktemp -d); trap 'rm -rf "$out"' EXIT # The C stubs. -O2 on purpose: spike_probe_align's aligned load only becomes a # real movaps with optimisation on, and an alignment bug that only shows up in # a release build is the one this is looking for. clang -O2 -c -I"$(ocamlopt -where)" "$here/jit_stubs.c" -o "$out/jit_stubs.o" || exit 1 ocamlfind ocamlopt -thread -package unix,threads.posix -linkpkg \ -I "$root/_build/default/lib/.flan.objs/byte" \ -I "$root/_build/default/lib/.flan.objs/native" \ -I "$out" -I "$here" \ -o "$out/spike" \ "$root/_build/default/lib/flan.cmxa" \ -cclib -rdynamic -ccopt -L"$root/_build/default/lib" \ "$out/jit_stubs.o" \ "$here/x86.ml" "$here/driver.ml" 2>&1 | head -40 test -x "$out/spike" || { echo "build failed"; exit 1; } "$out/spike" "$here/probe.flan" rc=$? echo "exit: $rc" exit $rc