I'm trying to make a call to a foreign import prim written in LLVM, using the ideas from this post but I just keep getting segfaults. Here's what I've got currently.
In Haskell
{-# LANGUAGE GHCForeignImportPrim #-}
{-# LANGUAGE MagicHash, UnboxedTuples #-}
{-# LANGUAGE ForeignFunctionInterface, UnliftedFFITypes #-}
import GHC.Prim
foreign import prim "primllvm" primllvm :: Word# -> Word# -> (# Word#, Word# #)
And in the .ll
file
define cc10 void @primllvm(i64* %baseReg, i64* %sp, i64* %hp, i64* %buffer, i64 %length, i64 %r3, i64 %r4, i64 %r5, i64 %r6, i64* %spLim, float %f1, float %f2, float %f3, float %f4, double %d1, double %d2)
{
%fp = bitcast i64* %sp to void(i64*, i64*, i64*, i64*, i64, i64, i64, i64, i64, i64*, float, float, float, float, double, double)*
tail call cc10 void %fp(i64* %baseReg, i64* %sp, i64* %hp, i64* %buffer, i64 %length, i64 %r3, i64 %r4, i64 %r5, i64 %r6, i64* %spLim, float %f1, float %f2, float %f3, float %f4, double %d1, double %d2) noreturn;
ret void
}
In theory I think this should just return it's arguments as a tuple, but like I said, it just segfaults. Any help to get this working appreciated.