void foo(int x, int y) { ... } void bar() { CallSite CS(...); // initialize CallSite object // extract callee and arguments Function *callee = CS.getCalledFunction(); Value *arg1 = CS.getArgOperand(0); Value *arg2 = CS.getArgOperand(1); // call foo with arguments foo(cast(arg1)->getSExtValue(), cast (arg2)->getSExtValue()); }
void foo(int x, int y) { ... } void bar(CallSite CS) { // change the second argument to '3' CS.setArgOperand(1, ConstantInt::get(Type::getInt32Ty(Context), 3)); // call the modified function CS.getInstruction()->getParent()->getParent() ->getModule()->getFunction("foo")->getReturnType() ->setIntN(32); // set return type to 32 bits CS.getInstruction()->setOperand(0, callee); }This example shows how to use CallSite to change the arguments of a call instruction, and then modify the function itself before calling it. Package/library: LLVM