The problem with LLVM-Haskell bindings is that I get "duplicate" names. I think the best way to explain my problem is with a small concrete example (note that the example is contrived, and for such a small example there are simple ways to get around it ... however it points to my problem).
putc :: TFunction (Int32 -> IO Word32)
putc = newNamedFunction ExternalLinkage "putchar"
simple :: TFunction (Int32 -> IO Word32)
simple = do
internalputc <- putc
createNamedFunction ExternalLinkage "simple" $ \x -> do
call internalputc x
call internalputc x
ret (0 :: Word32)
easy :: TFunction (Int32 -> IO Word32)
easy = do
internalputc <- putc
internalsimple <- simple
createNamedFunction ExternalLinkage "easy" $ \x -> do
call internalsimple x
y <- add x (42 :: Int32)
call internalputc y
ret (0 :: Word32)
main :: IO ()
main = do
m <- newNamedModule "Main"
defineModule m easy
writeBitcodeToFile "SillyLib" m
If you run this haskell program now (you will need some imported data, such as Data.Int/Word and LLVM.Core), you will get the following result.
; ModuleID = 'SillyLib'
declare i32 @putchar(i32)
declare i32 @putchar1(i32)
define i32 @simple(i32) {
_L1:
%1 = call i32 @putchar1(i32 %0)
%2 = call i32 @putchar1(i32 %0)
ret i32 0
}
define i32 @easy(i32) {
_L1:
%1 = call i32 @simple(i32 %0)
%2 = add i32 %0, 42
%3 = call i32 @putchar(i32 %2)
ret i32 0
}
The problem is that in IR, the (external) putchar is declared twice, but the second time with the name putchar1. I have common sense why this is so, but not very good for a good general way. That is, I do not want to invest everything in one giant CodeGenModule.
. LLVM-Haskell . , - ... IR-...