如果我有这个例子:
int a=0, b=0;
a 和 b 是局部变量并对其值进行任何修改,例如:
a++;
b++;
我需要在运行 MCJIT 期间获取此行代码中的值。
我的意思是值(value)不是
Value
类,但实际整数或任何类型的值。
最佳答案
您需要从 JITed LLVM 函数返回值,以便从调用 MCJIT 的代码中检索它。
看看这个 Kaleidoscope example .
相关代码在 HandleTopLevelExpression() 中:
if (FunctionAST *F = ParseTopLevelExpr()) {
if (Function *LF = F->Codegen()) {
// JIT the function, returning a function pointer.
void *FPtr = TheHelper->getPointerToFunction(LF);
// Cast it to the right type (takes no arguments, returns a double) so we
// can call it as a native function.
double (*FP)() = (double (*)())(intptr_t)FPtr;
fprintf(stderr, "Evaluated to %f\n", FP());
}
}
关于clang - 获取llvm中局部变量的实际值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44874575/