JIT functions' signature known only at runtime

Hi there! I am trying to figure out how I can call the function returned
by the JIT execution engine. The only circumstance that makes this case
a little problematic is that the function's signature is only available as
runtime state. More precisely the arguments to be passed are only
available as a vector of, e.g.,

union Types {
   void *ptr;
   float *ptr_float;
   double *ptr_double;
   float fl;
   int in;
   double db;
   bool bl;

std::vector<std::pair<int,Types> > arguments;

where the first element of the pair would clearly identify of which type the argument is.

I thought that I might not be the first having this problem and checked the mailing list
without success.

Does LLVM has any glue code to call functions returned by the JIT execution engine?

Or is the only solution in this case to pass the address of the whole vector and let the
jitted function handle everything?


If the question could be generalized to “how to call the external function without knowing its interface in advance”, then the general solution is Foreign Function Interface (FFI). And LLVM’s JIT is (at least - was) using FFI for certain things. We faced the same need some time ago, maybe this code can give a rough idea:


  • D.