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

后端 未结 1 1674
长发绾君心
长发绾君心 2021-02-09 10:12

Background: I have written a toy Lisp interpreter that I am trying to add LLVM JIT functionality to. For the moment, have imposed the following limitations:

1条回答
  •  北恋
    北恋 (楼主)
    2021-02-09 10:41

    I don't know if it's possible to do this with just the EDSL from LLVM.Core (the types are indeed quite hairy), but if you look at LLVM.FFI.Core, you'll find the lower-level functionality for manipulating LLVM function types and creating LLVM functions. This leads to the following plan of action:

    • Create a TypeRef for your function with functionType.
    • Add this function to your module using addFunction.
    • Populate it with basic blocks by using appendBasicBlock/insertBasicBlock. Use getParam to reference function arguments inside your basic blocks.

    It should be possible to utilise the nice monadic EDSL syntax for constructing the basic blocks. Also, look at LLVM.Core.Util, it contains some helper functions for working with the FFI layer.

    0 讨论(0)
提交回复
热议问题