Getting the actual value of local variables in llvm
2 answers
You need to return the value from the JITed LLVM function in order to extract it from the code that calls MCJIT.
Check out this example of a kaleidoscope .
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());
}
}
0
source to share