我想使用 ghc 前端和 llvm 后端编译 haskell。
我的 haskell hello.hs 文件中有以下代码:
main = putStrLn "Hello World!"
我使用以下命令用 ghc 编译 hello.hs
ghc -fllvm -keep-llvm-files -force-recomp -hello.hs
它会生成 hello.ll 文件以及其他文件。
然后我尝试将此 .ll 文件编译为 .bc 文件。
llvm-as hello.ll -o hello.bc
然后将此 .bc 文件转换为可执行文件
llc hello.bc -o hello
生成一个可执行文件。问题是当我运行这个文件时我发现以下错误
./hello: line 1: .file: command not found
./hello: line 2: .section: command not found
./hello: line 3: .globl: command not found
./hello: line 4: .align: command not found
./hello: line 5: .type: command not found
./hello: line 6: Main_main2_info:: command not found
./hello: line 8: subq: command not found
./hello: line 9: syntax error near unexpected token `('
./hello: line 9: ` movq
%r13, 112(%rsp)'
当我在 .bc 文件上使用 lli 时,我得到
main function not found in module error
我在 docker 上运行 ghc 和 llvm。我有 llvm 3.4 版本和 ghc 7.6.3 版本。
当我尝试在 Mac 上执行此操作时,会发生“类似”错误。我不知道为什么我会收到此错误。