[haskell-llvm] some trouble getting started

Keith Sheppard keithshep at gmail.com
Thu Apr 28 02:46:29 BST 2011


Hi All,

I'm trying to figure out haskell-llvm. I intend to work through the
kaleidoscope tutorial in haskell but I'm starting off simple and got
stuck pretty much right away.

This Fibonacci code from the examples compiles with no problems:
<https://gist.github.com/945506/edce9f68beeedd6b90dc57463c2f2ddfb3ac25ed>

But when I change it to
<https://gist.github.com/945506/2ca13a3d06cc4e90416643293cc5208acbda5975>
I get the following compile errors:

==================================
keith at sugarglider:~/projects/haskaleidoscope/> cabal clean && cabal
configure && cabal build
cleaning...
Resolving dependencies...
Configuring haskaleidoscope-0.0.0...
Preprocessing executables for haskaleidoscope-0.0.0...
Building haskaleidoscope-0.0.0...
[1 of 1] Compiling Main             ( Fibonacci/Fibonacci.hs,
dist/build/fibonacci/fibonacci-tmp/Main.o )

Fibonacci/Fibonacci.hs:59:12:
    No instance for (FunctionArgs
                       f (a -> b -> CodeGenFunction r1 Terminate)
(CodeGenFunction r ()))
      arising from a use of `createFunction'
                   at Fibonacci/Fibonacci.hs:59:12-41
    Possible fix:
      add an instance declaration for
      (FunctionArgs
         f (a -> b -> CodeGenFunction r1 Terminate) (CodeGenFunction r ()))
    In the first argument of `($)', namely
        `createFunction InternalLinkage'
    In a stmt of a 'do' expression:
        plus <- createFunction InternalLinkage
              $ \ x y
                    -> do l1 <- newBasicBlock
                          l2 <- newBasicBlock
                          ....
    In the expression:
        do plus <- createFunction InternalLinkage $ \ x y -> do ...
           fib <- newNamedFunction ExternalLinkage "fib"
             defineFunction fib $ \ arg -> do ...
           return ()

Fibonacci/Fibonacci.hs:66:13:
    No instance for (ABinOp a Word32 (v c))
      arising from a use of `and' at Fibonacci/Fibonacci.hs:66:13-31
    Possible fix:
      add an instance declaration for (ABinOp a Word32 (v c))
    In a stmt of a 'do' expression: a <- and x (1 :: Word32)
    In the expression:
        do l1 <- newBasicBlock
           l2 <- newBasicBlock
           l3 <- newBasicBlock
           a <- and x (1 :: Word32)
           ....
    In the second argument of `($)', namely
        `\ x y
             -> do l1 <- newBasicBlock
                   l2 <- newBasicBlock
                   ....'

Fibonacci/Fibonacci.hs:67:13:
    No instances for (CmpRet c1 Bool, CmpOp (v c) Word32 c1 Bool)
      arising from a use of `icmp' at Fibonacci/Fibonacci.hs:67:13-38
    Possible fix:
      add an instance declaration for
      (CmpRet c1 Bool, CmpOp (v c) Word32 c1 Bool)
    In a stmt of a 'do' expression: c <- icmp IntEQ a (0 :: Word32)
    In the expression:
        do l1 <- newBasicBlock
           l2 <- newBasicBlock
           l3 <- newBasicBlock
           a <- and x (1 :: Word32)
           ....
    In the second argument of `($)', namely
        `\ x y
             -> do l1 <- newBasicBlock
                   l2 <- newBasicBlock
                   ....'

Fibonacci/Fibonacci.hs:72:14:
    No instance for (ABinOp a b (Value c2))
      arising from a use of `add' at Fibonacci/Fibonacci.hs:72:14-20
    Possible fix:
      add an instance declaration for (ABinOp a b (Value c2))
    In a stmt of a 'do' expression: r1 <- add x y
    In the expression:
        do l1 <- newBasicBlock
           l2 <- newBasicBlock
           l3 <- newBasicBlock
           a <- and x (1 :: Word32)
           ....
    In the second argument of `($)', namely
        `\ x y
             -> do l1 <- newBasicBlock
                   l2 <- newBasicBlock
                   ....'

Fibonacci/Fibonacci.hs:77:14:
    No instance for (ABinOp b a (Value c2))
      arising from a use of `add' at Fibonacci/Fibonacci.hs:77:14-20
    Possible fix:
      add an instance declaration for (ABinOp b a (Value c2))
    In a stmt of a 'do' expression: r2 <- add y x
    In the expression:
        do l1 <- newBasicBlock
           l2 <- newBasicBlock
           l3 <- newBasicBlock
           a <- and x (1 :: Word32)
           ....
    In the second argument of `($)', namely
        `\ x y
             -> do l1 <- newBasicBlock
                   l2 <- newBasicBlock
                   ....'
==================================

These type errors are beyond me. If someone can give me an intuitive
explanation for why my change is not valid I would really appreciate
that.

Also, for all of the examples I see in the example dir it's known
ahead of time what the types of the LLVM expressions should be. Is it
necessary to drop down to the FFI API to generate code for a general
purpose language where the expression types will not be known ahead of
time or should I be able to accomplish that at the high level API?

Thanks
-Keith



More information about the Haskell-llvm mailing list