LLVM:将指向包含指向函数的指针的结构的指针传递给JIT函数
问题描述:
我有一个带有函数的LLVM(版本为2.7)模块,该指针指向一个结构体。该结构包含一个指向C++函数的函数指针。模块函数将被JIT编译,我需要使用LLVM API在C++中构建该结构。我似乎无法将指向该函数的指针视为LLVM值,更不用说传递指向我无法构建的ConstantStruct的指针了。LLVM:将指向包含指向函数的指针的结构的指针传递给JIT函数
我不知道如果我甚至在轨道上,但是这是我到目前为止有:
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);
答
其实,请不要介意。我不会使用LLVM API,只是传递一个与LLVM结构类型的布局相匹配的C++结构。忽略该代码的第一位并将args [0] .PointerVal设置为指向该结构的指针。