我有一个 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);