[haskell-llvm] [Haskell-cafe] LLVM, type-level?

Lally Singh lally.singh at gmail.com
Thu Dec 9 09:17:47 EST 2010


On Wed, Dec 8, 2010 at 11:13 AM, Henning Thielemann
<lemming at henning-thielemann.de> wrote:
>
> On Wed, 8 Dec 2010, Lally Singh wrote:
>
>> On Wed, Dec 8, 2010 at 9:15 AM, Lally Singh <lally.singh at gmail.com> wrote:
>>>
>>> I didn't figure out how to add an instance for GetElementPtr within my
>>> module -- I think it was because IsIndexable.getArg and getIxList
>>> weren't exported -- perhaps it should be in the llvm.  But, changing
>>> the type to Ptr(Array D0 Word8) made it work.
>>
>> Ugh, it compiled, but LLVm didn't like the generated code when I ran lli.
>>
>> The only way to get this to work is by modifying the llvm package, it
>> seems.  I think I'll have to modify GEP in general to make it work for
>> structure declarations.
>
> No hacks please! :-) Ptr Word8 can be used for unbounded arrays with element
> type Word8.
>
>  getElementPtr (ptrReg::Value (Ptr Word8)) (i::Int32, ())
>
> should work. You cannot define custom types, because they would not have an
> equivalent in LLVM. As far as I have used 'llvm', the package provides all
> LLVM types and type constructors.

So how do I make it work with Ptr (Ptr Word8)?

Here's what I'm building: https://gist.github.com/734713  (it's 15
lines, and I've included the compiler complaint.)

type MainFunction = Function (Int32 -> Ptr (Ptr Word8) -> IO Int32)
buildReaderFun :: String -> CodeGenModule (MainFunction)
buildReaderFun nm  = do
  puts <- newNamedFunction ExternalLinkage "puts" ::
    TFunction (Ptr Word8 -> IO Word32)
  let callPuts format = (
        createNamedFunction ExternalLinkage "main" $
        \ argc argv -> do
          tmp <- getElementPtr (argv ::Value (Ptr Word8))
                 (0 :: Int32,  ())
          call puts tmp -- Throw away return value.
          ret (0 :: Int32)) :: CodeGenModule (MainFunction)

  withStringNul nm callPuts



More information about the Haskell-llvm mailing list