我正在尝试开始使用 haskell-llvm 绑定,但遇到了我不太理解的编译错误。
代码:
module ModuleMaker where
import LLVM.Core
import LLVM.FFI.Core
import Data.Int
main :: IO ()
main = do
m <- newNamedModule "test"
fns <- defineModule m buildMod
writeBitcodeToFile "ModuleMaker.bc" m
return ()
buildMod :: CodeGenModule (Function (IO Int32))
buildMod = do
main <- createNamedFunction ExternalLinkage "main" $ do
addResult <- iadd (2::Int32) (3::Int32)
ret addResult
return main
这导致这两个错误:
ModuleMaker.hs:20:18:
No instance for (ABinOp Int32 Int32 (v0 c0))
arising from a use of `iadd'
Possible fix:
add an instance declaration for (ABinOp Int32 Int32 (v0 c0))
In a stmt of a 'do' block:
addResult <- iadd (2 :: Int32) (3 :: Int32)
In the second argument of `($)', namely
`do { addResult <- iadd (2 :: Int32) (3 :: Int32);
ret addResult }'
In a stmt of a 'do' block:
main <- createNamedFunction ExternalLinkage "main"
$ do { addResult <- iadd (2 :: Int32) (3 :: Int32);
ret addResult }
ModuleMaker.hs:21:5:
No instance for (Ret (v0 c0) Int32) arising from a use of `ret'
The type variables `v0', `c0' are ambiguous
Possible fix: add a type signature that fixes these type variable(s)
Note: there is a potential instance available:
instance [overlap ok] Ret (LLVM.Core.Value a) a
-- Defined in `llvm-3.2.0.2:LLVM.Core.Instructions'
Possible fix: add an instance declaration for (Ret (v0 c0) Int32)
In a stmt of a 'do' block: ret addResult
In the second argument of `($)', namely
`do { addResult <- iadd (2 :: Int32) (3 :: Int32);
ret addResult }'
In a stmt of a 'do' block:
main <- createNamedFunction ExternalLinkage "main"
$ do { addResult <- iadd (2 :: Int32) (3 :: Int32);
ret addResult }
在第一个错误中,我看到那(ABinOp Int32 Int32
是iadd
专门用于 的指令Int32
,但我不明白(v0 c0)
它来自哪里或它应该是什么值。我见过的 haskell-llvm 示例似乎没有提供任何进一步的论据,add
所以我有点困惑......
我看到的第二个错误与第一个错误有关(因为v0
andc0
变量对吗?)。我猜测修复第一个错误将修复第二个错误。我做错了什么导致这些错误?