Can now modify called_function of CallOrInvokeInstruction

This commit is contained in:
Siu Kwan Lam 2012-11-01 11:41:28 -05:00
commit b9d05bb6fe
4 changed files with 19 additions and 3 deletions

View file

@ -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 )

View file

@ -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)

View file

@ -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<Instruction>(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 <typename W, typename UW>

View file

@ -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(). */