Fil-C on Nix

Filnix wiki

mbrock/filnix

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
6name=
"filc-llvm-jit-check"
7dontUnpack=
true
8buildPhase=
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
37installPhase=
"touch $out"