LLVM: Passing a pointer to a struct, which holds a pointer to a function, to a JIT function

Posted by Rusky on Stack Overflow See other posts from Stack Overflow or by Rusky
Published on 2010-06-05T01:00:18Z Indexed on 2010/06/06 3:12 UTC
Read the original article Hit count: 312

Filed under:
|

I have an LLVM (version 2.7) module with a function that takes a pointer to a struct. That struct contains a function pointer to a C++ function. The module function is going to be JIT-compiled, and I need to build that struct in C++ using the LLVM API. I can't seem get the pointer to the function as an LLVM value, let alone pass a pointer to the ConstantStruct that I can't build.

I'm not sure if I'm even on the track, but this is what I have so far:

void print(char*);

vector<Constant*> functions;
functions.push_back(ConstantExpr::getIntToPtr(
    ConstantInt::get(Type::getInt32Ty(context), (int)print),
    /* function pointer type here, FunctionType::get(...) doesn't seem to work */
));
ConstantStruct* struct = cast<ConstantStruct>(ConstantStruct::get(
    cast<StructType>(m->getTypeByName("printer")),
    functions
));

Function* main = m->getFunction("main");
vector<GenericValue> args;
args[0].PointerVal = /* not sure what goes here */
ee->runFunction(main, args);

© Stack Overflow or respective owner

Related posts about jit

Related posts about llvm