tests/llvm-jit.nix
Fil-C's LLVM JIT API: build LLVM IR in a Fil-C program, compile it through the Fil-C passes in-process, and call it. Needs a toolchain whose pin has the JIT (staging).
λpkgsFilc
pkgsFilc.stdenv.mkDerivation
for opt in -O0 -O2; do
$CC $opt -enable-filc-jit ${./llvm-jit/hello.c} -o hello
./hello | grep -qx 'Hello!'
$CC $opt -enable-filc-jit ${./llvm-jit/global.c} -o global
./global | grep -qx 'counter 99000 calls 2000 length 20000 sum 9990000'
$CC $opt -enable-filc-jit ${./llvm-jit/contextless.c} -o contextless
./contextless | grep -qx ok
$CC $opt -enable-filc-jit ${./llvm-jit/shared-cache.c} -o shared-cache
./shared-cache | grep -qx ok
$CC $opt -enable-filc-jit ${./llvm-jit/lookup-intrinsic-bad.c} -o badname
if ./badname > badname.log 2>&1; then
echo "LLVMLookupIntrinsicID accepted a name without llvm." >&2
exit 1
fi
grep -q 'does not start with' badname.log
# Without -enable-filc-jit the runtime refuses the JIT API.
$CC $opt ${./llvm-jit/hello.c} -o nojit
if ./nojit > nojit.log 2>&1; then
echo "JIT API ran without -enable-filc-jit" >&2
exit 1
fi
done
"touch $out"