[haskell-llvm] [Question] Adding a function in LLVM (haskell bindings) when the number of parameters is not known at compile time
Henning Thielemann
lemming at henning-thielemann.de
Fri Mar 8 09:43:38 GMT 2013
On Tue, 19 Feb 2013, Paul Meng wrote:
> Hi haskell-llvm list,
> I am trying to write a kaleidoscope language compiler using the haskell llvm high-level binding. However,
> when I was about to write the codegen part, I found I was not so sure about the usage of ``defineFunction``
> and ``simpleFunction``. When I had the AST of a function with arguments, say I represented ``def f(a b c
> d)`` with ``Proto String [String]``. I got a list of argument but it seems to me I can only pass variadic of
> arguments to either ``defineFunction`` or ``simpleFunction``, like ``defineFunction f $ \a b c d ...``. And
> this is decided at the compile time of the compiler. I looked up stackoverflow, and no good answer about how
> to use "highlevel" binding to achieve this.. (Ifound http://stackoverflow.com/questions/6448705/adding-a-function-in-llvm-haskell-bindings-when-the-number
> -of-parameters-is-no and http://stackoverflow.com/questions/9018449/binding-ffi-and-dsl )
> I also found the usage like ``translate = unsafePerformIO . fmap unsafePurify . simpleFunction .
> compileFunction`` on augustss's blog, but I couldn't figure it out.
Generally it is not clear whether it is a good idea to use the high-level
binding for writing compilers, since the types in the compiled programs
are only know at the runtime of the compiler. You may either use the
low-level bindings or you have to use higher rank, existential types or
GADTs in your compiler. The latter ones allow you to choose types at the
runtime of the compiler.
> Please kindly guide me a way to do this with DSL interface. I've also traced the llvm binding code, but the
> type is too difficult to me.
Did you find the ltrace.conf in the llvm package?
More information about the Haskell-llvm
mailing list