LLVM:将指向结构的指针传递给JIT函数,该结构包含指向函数的指针

LLVM:将指向结构的指针传递给JIT函数,该结构包含指向函数的指针,jit,llvm,Jit,Llvm,我有一个LLVM(版本2.7)模块,其中有一个函数,该函数接受指向结构的指针。该结构包含一个指向C++函数的函数指针。模块函数将被JIT编译,并且我需要使用LLVM API在C++中构建该结构。我似乎无法将指向函数的指针作为LLVM值获取,更不用说传递指向我无法构建的ConstantStruct的指针了 我甚至不确定自己是否在赛道上,但到目前为止我已经做到了: void print(char*); vector<Constant*> functions; functions.pus

我有一个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);
void打印(字符*);
向量函数;
函数。推回(ConstantExpr::getIntToPtr)(
ConstantInt::get(类型::getInt32Ty(上下文),(int)print),
/*这里的函数指针类型,FunctionType::get(…)似乎不起作用*/
));
ConstantStruct*struct=cast(ConstantStruct::get(
cast(m->getTypeByName(“打印机”),
功能
));
函数*main=m->getFunction(“main”);
向量args;
args[0]。PointerVal=/*不确定此处的内容*/
ee->runFunction(主,参数);

实际上,没关系。我不会使用LLVM API,只需传递一个与LLVM结构类型的布局相匹配的C++结构。忽略该代码的第一位,并将args[0].PointerVal设置为指向该结构的指针