Compile Haskell programs to LLVM IR

…衆ロ難τιáo~ 提交于 2019-12-11 03:26:40

问题


According to this SO post compilation of Haskell programs to C is no longer (officially) supported. So I wanted to explore the option of compiling Haskell programs to LLVM IR. I chose the same program of the mentioned post:

quicksort [] = []
quicksort (p:xs) = (quicksort lesser) ++ [p] ++ (quicksort greater)
  where
    lesser  = filter (<  p) xs
    greater = filter (>= p) xs

main = print(quicksort([5,2,1,0,8,3]))

and then tried to compile it to LLVM IR with:

$ ghc -fllvm main.hs

Then I get this error regarding the LLVM version:

<no location info>: error:
    Warning: Couldn't figure out LLVM version!
             Make sure you have installed LLVM 3.7
ghc: could not execute: opt-3.7

When I check my opt version it's 3.8.0, which is bigger:

$ opt --version
LLVM (http://llvm.org/):
  LLVM version 3.8.0
  DEBUG build with assertions.
  Built Jun 20 2018 (14:59:34).
  Default target: x86_64-unknown-linux-gnu
  Host CPU: broadwell

So what's going on? could ghc expect exactly version 3.7.0 and only that?!

EDIT:

After installing llvm 3.7.0 and copying opt and llc to have 3.7 suffixes:

$ cp opt opt-3.7
$ cp llc llc-3.7

compilation to llvm goes without errors, using this line:

$ ghc -keep-llvm-files main.hs

and a file called main.ll is created.


回答1:


Yes, GHC expects an exact version of LLVM. The LLVM internals change very quickly, and so GHC (like many other tools which target or use LLVM) takes a very conservative approach to versioning of those tools.



来源:https://stackoverflow.com/questions/52040651/compile-haskell-programs-to-llvm-ir

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!