我有一个LLVM(2.7版)模块,它的函数接受一个指向结构的指针。该结构包含一个指向C++函数的函数指针。模块函数将被JIT编译,并且我需要使用LLVM API在C++中构建该结构。我似乎无法将指向函数的指针作为llvm值,更不用说将指针传递给我无法构建的constantstruct。
我不确定我是否在赛道上,但这就是我目前为止所拥有的:
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);