haskellllvmllvm-ir

In llvm-hs, is linking required between known lists of Definition's, to have a valid Module, or can I just concatenate the lists?


I am trying to make a compiler using LLVM Haskell bindings provided by llvm-hs. I have not yet reached the point to actually use the bindings, I am trying to generate LLVM IR. I have a bunch of functions, already defined, that I would like to have in each Module that I later create. I was wondering, can I use execModuleBuilder on each function, and concatenate the lists of definitions to be used to create a Module?

I thought about considering these functions a library and just linking them to each Module I create, but isn't concatenating the lists of Definition's and throwing them in a Module pretty much the same thing? I guess as far as optimality goes, it is better to consider them a library.

My question still remains, since they are not external definitions, rather LLVM functions, and I could add more in the future, can I generally concatenate lists of Definition's?

EDIT: I should mention that currently all of my objects have external linkage, which I think enables what I am trying to do.


Solution

  • ModuleBuilderT is a newtype wrapper around StateT ModuleBuilderState, and exposes the full state-ful API. So in principle a ModuleBuilderT action could do things that do not cleanly compose in the way you suggest (concatenating [Definition]s).

    However, from my read of the code, all of the ModuleBuilderT actions exported from LLVM.IRBuilder.Module treat the state as an append-only log, not using the full stateful superpowers available to them. So if you only use actions available from that module, and don't define any of your own actions that do strange things with the ModuleBuilderState, then you should be good to go.

    If there are actions available in other modules, they should be audited for calls to liftModuleState or unModuleBuilderT and for pattern matches on the ModuleBuilderT constructor. If they do none of those, you should be fine.