Haskell LLVM Bindings

The LLVM bindings for Haskell are split across two packages:

  • llvm-hs-pure is a pure Haskell representation of the LLVM IR.

  • llvm-hs is the FFI bindings to LLVM required for constructing the C representation of the LLVM IR and performing optimization and compilation.

llvm-hs-pure does not require the LLVM libraries be available on the system.

On Hackage there is an older version of the LLVM bindings named llvm and llvm-base which should likely be avoided since they have not been updated since their development a few years ago.

As an aside, the GHCi can have issues with the FFI and can lead to errors when working with llvm-hs. If you end up with errors like the following, then you are likely trying to use GHCi or runhaskell and it is unable to link against your LLVM library. Instead compile with standalone ghc.

  1. Loading package llvm-hs-4.0.1.0
  2. ... linking
  3. ... ghc: /usr/lib/llvm-4.0/lib/libLLVMSupport.a: unknown symbol `_ZTVN4llvm14error_categoryE'
  4. ghc: unable to load package `llvm-hs-4.0.1.0'