在llvm中获取局部变量的实际值 [英] Getting actual value of local variables in llvm
本文介绍了在llvm中获取局部变量的实际值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有这个示例:
int a=0, b=0;
a和b是局部变量,并对其值进行任何修改,例如:
a and b are local variables and make any modifications in their values, such as:
a++;
b++;
在运行MCJIT期间,我需要获取此行代码中的值.
I need to get the value in this line code during running MCJIT.
我的意思是值不是Value
类,而是实际的整数或任何类型的值.
I mean by value not Value
class, but the actual integer or any type value.
推荐答案
您需要从JITed LLVM函数返回该值,以便从调用MCJIT的代码中检索该值.
You need to return the value from a JITed LLVM function in order to retrieve it from the code invoking MCJIT.
查看此万花筒示例.
相关代码在HandleTopLevelExpression()中:
The relevant code is in 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());
}
}
这篇关于在llvm中获取局部变量的实际值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文