From b9d05bb6fe4b385896877731019d0c25c0c0a17e Mon Sep 17 00:00:00 2001 From: Siu Kwan Lam Date: Thu, 1 Nov 2012 11:41:28 -0500 Subject: [PATCH] Can now modify called_function of CallOrInvokeInstruction --- llvm/_core.cpp | 3 ++- llvm/core.py | 8 ++++++-- llvm/extra.cpp | 7 +++++++ llvm/extra.h | 4 ++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/llvm/_core.cpp b/llvm/_core.cpp index 1a64f88..1b7ec09 100644 --- a/llvm/_core.cpp +++ b/llvm/_core.cpp @@ -772,7 +772,7 @@ _wrap_objintint2none(LLVMSetInstrParamAlignment, LLVMValueRef) _wrap_obj2obj(LLVMIsTailCall, LLVMValueRef, int) _wrap_objint2none(LLVMSetTailCall, LLVMValueRef) _wrap_obj2obj(LLVMInstGetCalledFunction, LLVMValueRef, LLVMValueRef) - +_wrap_objobj2none(LLVMInstSetCalledFunction, LLVMValueRef, LLVMValueRef) /*===-- PHI Nodes --------------------------------------------------------===*/ @@ -1867,6 +1867,7 @@ static PyMethodDef core_methods[] = { _method( LLVMRemoveInstrAttribute ) _method( LLVMSetInstrParamAlignment ) _method( LLVMInstGetCalledFunction ) + _method( LLVMInstSetCalledFunction ) /* PHI Nodes */ _method( LLVMAddIncoming1 ) diff --git a/llvm/core.py b/llvm/core.py index 7c9b1e1..b264b50 100644 --- a/llvm/core.py +++ b/llvm/core.py @@ -1670,12 +1670,16 @@ class CallOrInvokeInstruction(Instruction): def set_parameter_alignment(self, idx, align): _core.LLVMSetInstrParamAlignment(self.ptr, idx, align) - @property - def called_function(self): + def _get_called_function(self): function = _core.LLVMInstGetCalledFunction(self.ptr) if function: # Return value can be None on indirect call/invoke return _make_value(function) + def _set_called_function(self, function): + _core.LLVMInstSetCalledFunction(self.ptr, function.ptr) + + called_function = property(_get_called_function, _set_called_function) + # tail call is valid only for 'call', not 'invoke' # disabled for now #def _get_tc(self): return _core.LLVMIsTailCall(self.ptr) diff --git a/llvm/extra.cpp b/llvm/extra.cpp index b9f4ac2..b8545ea 100644 --- a/llvm/extra.cpp +++ b/llvm/extra.cpp @@ -855,6 +855,13 @@ LLVMValueRef LLVMInstGetCalledFunction(LLVMValueRef inst) return llvm::wrap(CallSite(instp).getCalledFunction()); } +void LLVMInstSetCalledFunction(LLVMValueRef inst, LLVMValueRef fn) +{ + using namespace llvm; + Instruction *instp = unwrap(inst); + CallSite(instp).setCalledFunction(unwrap(fn)); +} + ///* llvm::unwrap a set of `n' wrapped objects starting at `values', // * into a vector of pointers to llvm::unwrapped objects `out'. */ //template diff --git a/llvm/extra.h b/llvm/extra.h index dae90ec..26235e1 100644 --- a/llvm/extra.h +++ b/llvm/extra.h @@ -488,6 +488,10 @@ unsigned LLVMCmpInstGetPredicate(LLVMValueRef cmpinst); */ LLVMValueRef LLVMInstGetCalledFunction(LLVMValueRef inst); +/* Wraps llvm::CallSite::setCalledFunction. + */ +void LLVMInstSetCalledFunction(LLVMValueRef inst, LLVMValueRef fn); + /* Wraps llvm::ParseAssemblyString(). Returns a module reference or NULL (with * `out' pointing to an error message). Dispose error message after use, via * LLVMDisposeMessage(). */