【问题标题】:LLVM: Passing a pointer to a struct, which holds a pointer to a function, to a JIT functionLLVM:将指向结构的指针(包含指向函数的指针)传递给 JIT 函数
【发布时间】:2010-06-06 11:03:20
【问题描述】:

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

【问题讨论】:

    标签: jit llvm


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2021-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多