[haskell-llvm] [Question] Adding a function in LLVM (haskell bindings) when the number of parameters is not known at compile time

Paul Meng mno2.csie at gmail.com
Mon Feb 18 16:00:10 GMT 2013


Hi haskell-llvm list,

I am trying to write a kaleidoscope <http://llvm.org/docs/tutorial/> 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.. (I
found
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<http://augustss.blogspot.tw/2009/06/more-llvm-recently-someone-asked-me-on.html>,
but I couldn't figure it out.

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.

(My not-yet-complete code is here: https://gist.github.com/MnO2/4736264)

Thanks in advance.


Paul Meng.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://projects.haskell.org/pipermail/haskell-llvm/attachments/20130218/8be0492e/attachment.htm>


More information about the Haskell-llvm mailing list