From 7c22f37b57e2781993375d2fd11706c199b85171 Mon Sep 17 00:00:00 2001 From: Jon Riehl Date: Fri, 17 Aug 2012 15:52:07 -0500 Subject: [PATCH] Adding support for building the "insertvalue" instruction. --- llvm/_core.cpp | 2 ++ llvm/core.py | 7 +++++++ llvm/wrap.h | 26 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/llvm/_core.cpp b/llvm/_core.cpp index 2f99ae3..ae94e83 100644 --- a/llvm/_core.cpp +++ b/llvm/_core.cpp @@ -778,6 +778,7 @@ _wrap_objstrint2obj(LLVMBuildFence, LLVMBuilderRef, LLVMValueRef) /* Miscellaneous instructions */ _wrap_objobjintstr2obj(LLVMBuildGetResult, LLVMBuilderRef, LLVMValueRef, LLVMValueRef) +_wrap_objobjobjintstr2obj(LLVMBuildInsertValue, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef) _wrap_objobjstr2obj(LLVMBuildPhi, LLVMBuilderRef, LLVMTypeRef, LLVMValueRef) _wrap_objobjliststr2obj(LLVMBuildCall, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef) _wrap_objobjobjobjstr2obj(LLVMBuildSelect, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef, LLVMValueRef) @@ -1764,6 +1765,7 @@ static PyMethodDef core_methods[] = { /* Miscellaneous instructions */ _method( LLVMBuildGetResult ) + _method( LLVMBuildInsertValue ) _method( LLVMBuildPhi ) _method( LLVMBuildCall ) _method( LLVMBuildSelect ) diff --git a/llvm/core.py b/llvm/core.py index d49e32a..0560f5b 100644 --- a/llvm/core.py +++ b/llvm/core.py @@ -1959,6 +1959,13 @@ class Builder(object): # obsolete synonym for extract_value getresult = extract_value + def insert_value(self, retval, rhs, idx, name=""): + check_is_value(retval) + check_is_value(rhs) + return _make_value( + _core.LLVMBuildInsertValue(self.ptr, retval.ptr, rhs.ptr, idx, + name)) + def phi(self, ty, name=""): check_is_type(ty) return _make_value(_core.LLVMBuildPhi(self.ptr, ty.ptr, name)) diff --git a/llvm/wrap.h b/llvm/wrap.h index 3fa84d9..06b45af 100644 --- a/llvm/wrap.h +++ b/llvm/wrap.h @@ -659,6 +659,32 @@ _w ## func (PyObject *self, PyObject *args) \ return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)) ; \ } +/** + * Wrap LLVM functions of the type + * outtype func(intype1 arg1, intype2 arg2, intype3, int arg3, const char *arg4) + */ +#define _wrap_objobjobjintstr2obj(func, intype1, intype2, intype3, outtype) \ +static PyObject * \ +_w ## func (PyObject *self, PyObject *args) \ +{ \ + PyObject *obj1, *obj2, *obj3; \ + intype1 arg1; \ + intype2 arg2; \ + intype3 arg3; \ + int arg4; \ + const char *arg5; \ + \ + if (!PyArg_ParseTuple(args, "OOOis", &obj1, &obj2, &obj3, &arg4, \ + &arg5)) \ + return NULL; \ + \ + arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \ + arg2 = ( intype2 ) PyCapsule_GetPointer(obj2, NULL); \ + arg3 = ( intype3 ) PyCapsule_GetPointer(obj3, NULL); \ + \ + return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4, arg5)) ; \ +} + /** * Wrap LLVM functions of the type * outtype func(intype1 arg1, intype2 arg2, intype3 arg3, const char *arg4)