2

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

1 回答 1

1

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

于 2010-06-05T01:09:40.077 回答