Update StructType to LLVM 3.x (incomplete).

Bring back StructType.elements.
This commit is contained in:
Siu Kwan Lam 2012-07-22 00:00:04 -07:00
commit b71d22b570
6 changed files with 444 additions and 300 deletions

View file

@ -11,7 +11,7 @@
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* * Neither the name of this software, nor the names of its * * Neither the name of this software, nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
@ -53,7 +53,7 @@ typedef int Py_ssize_t;
#endif #endif
/* Project-wide setting */ /* Project-wide setting */
#if (PY_MAJOR_VERSION >= 3) #if (PY_MAJOR_VERSION >= 3)
#define LLVM_PY_USE_PYCAPSULE #define LLVM_PY_USE_PYCAPSULE
#endif #endif
@ -72,13 +72,13 @@ _wLLVMModuleCreateWithName(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "U:LLVMModuleCreateWithName", &s_)) { if (!PyArg_ParseTuple(args, "U:LLVMModuleCreateWithName", &s_)) {
return NULL; return NULL;
} }
s = PyUnicode_AS_DATA(s_); s = PyUnicode_AS_DATA(s_);
#else #else
if (!PyArg_ParseTuple(args, "s", &s)) if (!PyArg_ParseTuple(args, "s", &s))
return NULL; return NULL;
#endif #endif
module = LLVMModuleCreateWithName(s); module = LLVMModuleCreateWithName(s);
return ctor_LLVMModuleRef(module); return ctor_LLVMModuleRef(module);
} }
@ -95,8 +95,8 @@ _wrap_obj2none(LLVMDumpModule, LLVMModuleRef)
_wrap_obj2none(LLVMDisposeModule, LLVMModuleRef) _wrap_obj2none(LLVMDisposeModule, LLVMModuleRef)
_wrap_dumper(LLVMDumpModuleToString, LLVMModuleRef) _wrap_dumper(LLVMDumpModuleToString, LLVMModuleRef)
_wrap_obj2obj(LLVMModuleGetPointerSize, LLVMModuleRef, int) _wrap_obj2obj(LLVMModuleGetPointerSize, LLVMModuleRef, int)
_wrap_objstrobj2obj(LLVMModuleGetOrInsertFunction, LLVMModuleRef, _wrap_objstrobj2obj(LLVMModuleGetOrInsertFunction, LLVMModuleRef,
LLVMTypeRef, LLVMValueRef) LLVMTypeRef, LLVMValueRef)
static PyObject * static PyObject *
_wLLVMVerifyModule(PyObject *self, PyObject *args) _wLLVMVerifyModule(PyObject *self, PyObject *args)
@ -188,7 +188,7 @@ static PyObject *
_wLLVMLinkModules(PyObject *self, PyObject *args) _wLLVMLinkModules(PyObject *self, PyObject *args)
{ {
PyObject *dest_obj, *src_obj, *ret; PyObject *dest_obj, *src_obj, *ret;
LLVMModuleRef dest, src; LLVMModuleRef dest, src;
char *errmsg; char *errmsg;
unsigned int mode = 0; unsigned int mode = 0;
@ -212,7 +212,7 @@ _wLLVMLinkModules(PyObject *self, PyObject *args)
} }
return ret; return ret;
} }
/* note: success => None, failure => string with error message */ /* note: success => None, failure => string with error message */
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -298,15 +298,19 @@ _wLLVMGetFunctionTypeParams(PyObject *self, PyObject *args)
/*===-- Struct types -----------------------------------------------------===*/ /*===-- Struct types -----------------------------------------------------===*/
_wrap_listint2obj(LLVMStructType, LLVMTypeRef, LLVMTypeRef) _wrap_listint2obj(LLVMStructType, LLVMTypeRef, LLVMTypeRef)
_wrap_str2obj(LLVMStructTypeIdentified, LLVMTypeRef)
_wrap_objlistint2none(LLVMSetStructBody, LLVMTypeRef, LLVMTypeRef)
_wrap_obj2obj(LLVMCountStructElementTypes, LLVMTypeRef, int) _wrap_obj2obj(LLVMCountStructElementTypes, LLVMTypeRef, int)
_wrap_obj2str(LLVMGetStructName, LLVMTypeRef)
_wrap_objstr2none(LLVMSetStructName, LLVMTypeRef)
/*
static PyObject * static PyObject *
_wLLVMGetStructElementTypes(PyObject *self, PyObject *args) _wLLVMGetStructElementTypes(PyObject *self, PyObject *args)
{ {
return obj2arr(self, args, LLVMCountStructElementTypes, LLVMGetStructElementTypes); return obj2arr(self, args, LLVMCountStructElementTypes, LLVMGetStructElementTypes);
} }
*/
_wrap_obj2obj(LLVMIsPackedStruct, LLVMTypeRef, int) _wrap_obj2obj(LLVMIsPackedStruct, LLVMTypeRef, int)
@ -398,13 +402,13 @@ _wLLVMConstInt(PyObject *self, PyObject *args)
int sign_extend; int sign_extend;
LLVMTypeRef ty; LLVMTypeRef ty;
LLVMValueRef val; LLVMValueRef val;
if (!PyArg_ParseTuple(args, "OKi", &obj, &n, &sign_extend)) if (!PyArg_ParseTuple(args, "OKi", &obj, &n, &sign_extend))
return NULL; return NULL;
#ifdef LLVM_PY_USE_PYCAPSULE #ifdef LLVM_PY_USE_PYCAPSULE
ty = (LLVMTypeRef) PyCapsule_GetPointer(obj, NULL); ty = (LLVMTypeRef) PyCapsule_GetPointer(obj, NULL);
#else #else
ty = (LLVMTypeRef)(PyCObject_AsVoidPtr(obj)); ty = (LLVMTypeRef)(PyCObject_AsVoidPtr(obj));
#endif #endif
@ -419,10 +423,10 @@ _wLLVMConstReal(PyObject *self, PyObject *args)
double d; double d;
LLVMTypeRef ty; LLVMTypeRef ty;
LLVMValueRef val; LLVMValueRef val;
if (!PyArg_ParseTuple(args, "Od", &obj, &d)) if (!PyArg_ParseTuple(args, "Od", &obj, &d))
return NULL; return NULL;
#ifdef LLVM_PY_USE_PYCAPSULE #ifdef LLVM_PY_USE_PYCAPSULE
ty = (LLVMTypeRef) PyCapsule_GetPointer(obj, NULL); ty = (LLVMTypeRef) PyCapsule_GetPointer(obj, NULL);
#else #else
@ -449,13 +453,13 @@ _wLLVMConstString(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "Ui:LLVMConstString", &s_, &dont_null_terminate)) { if (!PyArg_ParseTuple(args, "Ui:LLVMConstString", &s_, &dont_null_terminate)) {
return NULL; return NULL;
} }
s = PyUnicode_AS_DATA(s_); s = PyUnicode_AS_DATA(s_);
#else #else
if (!PyArg_ParseTuple(args, "si", &s, &dont_null_terminate)) if (!PyArg_ParseTuple(args, "si", &s, &dont_null_terminate))
return NULL; return NULL;
#endif #endif
val = LLVMConstString(s, strlen(s), dont_null_terminate); val = LLVMConstString(s, strlen(s), dont_null_terminate);
return ctor_LLVMValueRef(val); return ctor_LLVMValueRef(val);
} }
@ -520,7 +524,7 @@ _wrap_objobjobj2obj(LLVMConstShuffleVector, LLVMValueRef, LLVMValueRef, LLVMValu
_wrap_obj2obj(LLVMGetGlobalParent, LLVMValueRef, LLVMModuleRef) _wrap_obj2obj(LLVMGetGlobalParent, LLVMValueRef, LLVMModuleRef)
_wrap_obj2obj(LLVMIsDeclaration, LLVMValueRef, int) _wrap_obj2obj(LLVMIsDeclaration, LLVMValueRef, int)
_wrap_obj2obj(LLVMGetLinkage, LLVMValueRef, int) _wrap_obj2obj(LLVMGetLinkage, LLVMValueRef, int)
_wrap_objenum2none(LLVMSetLinkage, LLVMValueRef, LLVMLinkage) _wrap_objenum2none(LLVMSetLinkage, LLVMValueRef, LLVMLinkage)
_wrap_obj2str(LLVMGetSection, LLVMValueRef) _wrap_obj2str(LLVMGetSection, LLVMValueRef)
_wrap_objstr2none(LLVMSetSection, LLVMValueRef) _wrap_objstr2none(LLVMSetSection, LLVMValueRef)
_wrap_obj2obj(LLVMGetVisibility, LLVMValueRef, int) _wrap_obj2obj(LLVMGetVisibility, LLVMValueRef, int)
@ -545,7 +549,7 @@ _wrap_obj2obj(LLVMIsGlobalConstant, LLVMValueRef, int)
/*===-- Functions --------------------------------------------------------===*/ /*===-- Functions --------------------------------------------------------===*/
_wrap_objstrobj2obj(LLVMAddFunction, LLVMModuleRef, LLVMTypeRef, LLVMValueRef) _wrap_objstrobj2obj(LLVMAddFunction, LLVMModuleRef, LLVMTypeRef, LLVMValueRef)
_wrap_objstr2obj(LLVMGetNamedFunction, LLVMModuleRef, LLVMValueRef) _wrap_objstr2obj(LLVMGetNamedFunction, LLVMModuleRef, LLVMValueRef)
_wrap_obj2obj(LLVMGetFirstFunction, LLVMModuleRef, LLVMValueRef) _wrap_obj2obj(LLVMGetFirstFunction, LLVMModuleRef, LLVMValueRef)
_wrap_obj2obj(LLVMGetNextFunction, LLVMValueRef, LLVMValueRef) _wrap_obj2obj(LLVMGetNextFunction, LLVMValueRef, LLVMValueRef)
@ -675,12 +679,12 @@ _wLLVMBuildInvoke(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "OOOOOU:LLVMBuildInvoke", &obj1, &obj2, &obj3, &obj4, &obj5, &name_)) { if (!PyArg_ParseTuple(args, "OOOOOU:LLVMBuildInvoke", &obj1, &obj2, &obj3, &obj4, &obj5, &name_)) {
return NULL; return NULL;
} }
name = PyUnicode_AS_DATA(name_); name = PyUnicode_AS_DATA(name_);
#else #else
if (!PyArg_ParseTuple(args, "OOOOOs", &obj1, &obj2, &obj3, &obj4, &obj5, &name)) if (!PyArg_ParseTuple(args, "OOOOOs", &obj1, &obj2, &obj3, &obj4, &obj5, &name))
return NULL; return NULL;
#endif #endif
#ifdef LLVM_PY_USE_PYCAPSULE #ifdef LLVM_PY_USE_PYCAPSULE
builder = (LLVMBuilderRef) PyCapsule_GetPointer(obj1, NULL); builder = (LLVMBuilderRef) PyCapsule_GetPointer(obj1, NULL);
@ -694,7 +698,7 @@ _wLLVMBuildInvoke(PyObject *self, PyObject *args)
fnargs = (LLVMValueRef *)make_array_from_list(obj3, fnarg_count); fnargs = (LLVMValueRef *)make_array_from_list(obj3, fnarg_count);
if (!fnargs) if (!fnargs)
return PyErr_NoMemory(); return PyErr_NoMemory();
#ifdef LLVM_PY_USE_PYCAPSULE #ifdef LLVM_PY_USE_PYCAPSULE
then_blk = (LLVMBasicBlockRef) PyCapsule_GetPointer(obj4, NULL); then_blk = (LLVMBasicBlockRef) PyCapsule_GetPointer(obj4, NULL);
catch_blk = (LLVMBasicBlockRef) PyCapsule_GetPointer(obj5, NULL); catch_blk = (LLVMBasicBlockRef) PyCapsule_GetPointer(obj5, NULL);
@ -799,13 +803,13 @@ _wLLVMCreateMemoryBufferWithContentsOfFile(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "U:LLVMCreateMemoryBufferWithContentsOfFile", &path_)) { if (!PyArg_ParseTuple(args, "U:LLVMCreateMemoryBufferWithContentsOfFile", &path_)) {
return NULL; return NULL;
} }
path = PyUnicode_AS_DATA(path_); path = PyUnicode_AS_DATA(path_);
#else #else
if (!PyArg_ParseTuple(args, "s", &path)) if (!PyArg_ParseTuple(args, "s", &path))
return NULL; return NULL;
#endif #endif
if (!LLVMCreateMemoryBufferWithContentsOfFile(path, &ref, &outmsg)) { if (!LLVMCreateMemoryBufferWithContentsOfFile(path, &ref, &outmsg)) {
ret = ctor_LLVMMemoryBufferRef(ref); ret = ctor_LLVMMemoryBufferRef(ref);
} else { } else {
@ -980,10 +984,10 @@ _wrap_objobj2obj(LLVMCallFrameAlignmentOfType, LLVMTargetDataRef, LLVMTypeRef,
int) int)
_wrap_objobj2obj(LLVMPreferredAlignmentOfType, LLVMTargetDataRef, LLVMTypeRef, _wrap_objobj2obj(LLVMPreferredAlignmentOfType, LLVMTargetDataRef, LLVMTypeRef,
int) int)
_wrap_objobj2obj(LLVMPreferredAlignmentOfGlobal, LLVMTargetDataRef, _wrap_objobj2obj(LLVMPreferredAlignmentOfGlobal, LLVMTargetDataRef,
LLVMValueRef, int) LLVMValueRef, int)
_wrap_objobjull2obj(LLVMElementAtOffset, LLVMTargetDataRef, LLVMTypeRef, int) _wrap_objobjull2obj(LLVMElementAtOffset, LLVMTargetDataRef, LLVMTypeRef, int)
_wrap_objobjint2obj(LLVMOffsetOfElement, LLVMTargetDataRef, LLVMTypeRef, _wrap_objobjint2obj(LLVMOffsetOfElement, LLVMTargetDataRef, LLVMTypeRef,
llvmwrap_ull) llvmwrap_ull)
@ -1263,7 +1267,7 @@ _wLLVMLoadLibraryPermanently(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "U:LLVMLoadLibraryPermanently", &filename_)) { if (!PyArg_ParseTuple(args, "U:LLVMLoadLibraryPermanently", &filename_)) {
return NULL; return NULL;
} }
filename = PyUnicode_AS_DATA(filename_); filename = PyUnicode_AS_DATA(filename_);
#else #else
if (!PyArg_ParseTuple(args, "s", &filename)) { if (!PyArg_ParseTuple(args, "s", &filename)) {
@ -1292,7 +1296,7 @@ static PyObject *
_wPyCObjectVoidPtrToPyLong(PyObject *self, PyObject *args) _wPyCObjectVoidPtrToPyLong(PyObject *self, PyObject *args)
{ {
void *p; void *p;
if (!(p = get_object_arg(args))) if (!(p = get_object_arg(args)))
return NULL; return NULL;
@ -1319,13 +1323,13 @@ _wPyCObjectVoidPtrToPyLong(PyObject *self, PyObject *args)
static PyMethodDef core_methods[] = { static PyMethodDef core_methods[] = {
/* Modules */ /* Modules */
_method( LLVMModuleCreateWithName ) _method( LLVMModuleCreateWithName )
_method( LLVMGetDataLayout ) _method( LLVMGetDataLayout )
_method( LLVMSetDataLayout ) _method( LLVMSetDataLayout )
_method( LLVMGetModuleIdentifier ) _method( LLVMGetModuleIdentifier )
_method( LLVMSetModuleIdentifier ) _method( LLVMSetModuleIdentifier )
_method( LLVMGetTarget ) _method( LLVMGetTarget )
_method( LLVMSetTarget ) _method( LLVMSetTarget )
_method( LLVMModuleAddLibrary ) _method( LLVMModuleAddLibrary )
_method( LLVMGetTypeByName ) _method( LLVMGetTypeByName )
_method( LLVMDumpModule ) _method( LLVMDumpModule )
@ -1342,68 +1346,72 @@ static PyMethodDef core_methods[] = {
/* Types */ /* Types */
/* General */ /* General */
_method( LLVMGetTypeKind ) _method( LLVMGetTypeKind )
_method( LLVMDumpTypeToString ) _method( LLVMDumpTypeToString )
/* Integer types */ /* Integer types */
_method( LLVMInt1Type ) _method( LLVMInt1Type )
_method( LLVMInt8Type ) _method( LLVMInt8Type )
_method( LLVMInt16Type ) _method( LLVMInt16Type )
_method( LLVMInt32Type ) _method( LLVMInt32Type )
_method( LLVMInt64Type ) _method( LLVMInt64Type )
_method( LLVMIntType ) _method( LLVMIntType )
_method( LLVMGetIntTypeWidth ) _method( LLVMGetIntTypeWidth )
/* Floating-point types */ /* Floating-point types */
_method( LLVMFloatType ) _method( LLVMFloatType )
_method( LLVMDoubleType ) _method( LLVMDoubleType )
_method( LLVMX86FP80Type ) _method( LLVMX86FP80Type )
_method( LLVMFP128Type ) _method( LLVMFP128Type )
_method( LLVMPPCFP128Type ) _method( LLVMPPCFP128Type )
/* Function types */ /* Function types */
_method( LLVMFunctionType ) _method( LLVMFunctionType )
_method( LLVMIsFunctionVarArg ) _method( LLVMIsFunctionVarArg )
_method( LLVMGetReturnType ) _method( LLVMGetReturnType )
_method( LLVMCountParamTypes ) _method( LLVMCountParamTypes )
_method( LLVMGetFunctionTypeParams ) _method( LLVMGetFunctionTypeParams )
/* Struct types */ /* Struct types */
_method( LLVMStructType ) _method( LLVMStructType )
_method( LLVMCountStructElementTypes ) _method( LLVMStructTypeIdentified )
//_method( LLVMGetStructElementTypes ) _method( LLVMSetStructBody )
_method( LLVMIsPackedStruct ) _method( LLVMCountStructElementTypes )
_method( LLVMGetStructElementTypes )
_method( LLVMIsPackedStruct )
_method( LLVMGetStructName )
_method( LLVMSetStructName )
/* Array types */ /* Array types */
_method( LLVMArrayType ) _method( LLVMArrayType )
_method( LLVMGetElementType ) _method( LLVMGetElementType )
_method( LLVMGetArrayLength ) _method( LLVMGetArrayLength )
/* Pointer types */ /* Pointer types */
_method( LLVMPointerType ) _method( LLVMPointerType )
_method( LLVMGetPointerAddressSpace ) _method( LLVMGetPointerAddressSpace )
/* Vector type */ /* Vector type */
_method( LLVMVectorType ) _method( LLVMVectorType )
_method( LLVMGetVectorSize ) _method( LLVMGetVectorSize )
/* Other types */ /* Other types */
_method( LLVMVoidType ) _method( LLVMVoidType )
_method( LLVMLabelType ) _method( LLVMLabelType )
/* Type handles */ /* Type handles */
/* /*
_method( LLVMResolveTypeHandle ) _method( LLVMResolveTypeHandle )
_method( LLVMDisposeTypeHandle ) _method( LLVMDisposeTypeHandle )
*/ */
/* Values */ /* Values */
/* Operations on all values */ /* Operations on all values */
_method( LLVMTypeOf ) _method( LLVMTypeOf )
_method( LLVMGetValueName ) _method( LLVMGetValueName )
_method( LLVMSetValueName ) _method( LLVMSetValueName )
_method( LLVMDumpValue ) _method( LLVMDumpValue )
_method( LLVMDumpValueToString ) _method( LLVMDumpValueToString )
_method( LLVMValueGetID ) _method( LLVMValueGetID )
_method( LLVMValueGetNumUses ) _method( LLVMValueGetNumUses )
@ -1417,102 +1425,102 @@ static PyMethodDef core_methods[] = {
/* Constant Values */ /* Constant Values */
/* Operations on constants of any type */ /* Operations on constants of any type */
_method( LLVMConstNull ) _method( LLVMConstNull )
_method( LLVMConstAllOnes ) _method( LLVMConstAllOnes )
_method( LLVMGetUndef ) _method( LLVMGetUndef )
_method( LLVMIsConstant ) _method( LLVMIsConstant )
_method( LLVMIsNull ) _method( LLVMIsNull )
_method( LLVMIsUndef ) _method( LLVMIsUndef )
/* Operations on scalar constants */ /* Operations on scalar constants */
_method( LLVMConstInt ) _method( LLVMConstInt )
_method( LLVMConstReal ) _method( LLVMConstReal )
_method( LLVMConstRealOfString ) _method( LLVMConstRealOfString )
/* Operations on composite constants */ /* Operations on composite constants */
_method( LLVMConstString ) _method( LLVMConstString )
_method( LLVMConstArray ) _method( LLVMConstArray )
_method( LLVMConstStruct ) _method( LLVMConstStruct )
_method( LLVMConstVector ) _method( LLVMConstVector )
/* Constant expressions */ /* Constant expressions */
_method( LLVMSizeOf ) _method( LLVMSizeOf )
_method( LLVMConstNeg ) _method( LLVMConstNeg )
_method( LLVMConstNot ) _method( LLVMConstNot )
_method( LLVMConstAdd ) _method( LLVMConstAdd )
_method( LLVMConstFAdd ) _method( LLVMConstFAdd )
_method( LLVMConstSub ) _method( LLVMConstSub )
_method( LLVMConstFSub ) _method( LLVMConstFSub )
_method( LLVMConstMul ) _method( LLVMConstMul )
_method( LLVMConstFMul ) _method( LLVMConstFMul )
_method( LLVMConstUDiv ) _method( LLVMConstUDiv )
_method( LLVMConstSDiv ) _method( LLVMConstSDiv )
_method( LLVMConstFDiv ) _method( LLVMConstFDiv )
_method( LLVMConstURem ) _method( LLVMConstURem )
_method( LLVMConstSRem ) _method( LLVMConstSRem )
_method( LLVMConstFRem ) _method( LLVMConstFRem )
_method( LLVMConstAnd ) _method( LLVMConstAnd )
_method( LLVMConstOr ) _method( LLVMConstOr )
_method( LLVMConstXor ) _method( LLVMConstXor )
_method( LLVMConstICmp ) _method( LLVMConstICmp )
_method( LLVMConstFCmp ) _method( LLVMConstFCmp )
_method( LLVMConstShl ) _method( LLVMConstShl )
_method( LLVMConstLShr ) _method( LLVMConstLShr )
_method( LLVMConstAShr ) _method( LLVMConstAShr )
_method( LLVMConstGEP ) _method( LLVMConstGEP )
_method( LLVMConstTrunc ) _method( LLVMConstTrunc )
_method( LLVMConstSExt ) _method( LLVMConstSExt )
_method( LLVMConstZExt ) _method( LLVMConstZExt )
_method( LLVMConstFPTrunc ) _method( LLVMConstFPTrunc )
_method( LLVMConstFPExt ) _method( LLVMConstFPExt )
_method( LLVMConstUIToFP ) _method( LLVMConstUIToFP )
_method( LLVMConstSIToFP ) _method( LLVMConstSIToFP )
_method( LLVMConstFPToUI ) _method( LLVMConstFPToUI )
_method( LLVMConstFPToSI ) _method( LLVMConstFPToSI )
_method( LLVMConstPtrToInt ) _method( LLVMConstPtrToInt )
_method( LLVMConstIntToPtr ) _method( LLVMConstIntToPtr )
_method( LLVMConstBitCast ) _method( LLVMConstBitCast )
_method( LLVMConstSelect ) _method( LLVMConstSelect )
_method( LLVMConstExtractElement ) _method( LLVMConstExtractElement )
_method( LLVMConstInsertElement ) _method( LLVMConstInsertElement )
_method( LLVMConstShuffleVector ) _method( LLVMConstShuffleVector )
/* Globals */ /* Globals */
/* Globals (general) */ /* Globals (general) */
_method( LLVMGetGlobalParent ) _method( LLVMGetGlobalParent )
_method( LLVMIsDeclaration ) _method( LLVMIsDeclaration )
_method( LLVMGetLinkage ) _method( LLVMGetLinkage )
_method( LLVMSetLinkage ) _method( LLVMSetLinkage )
_method( LLVMGetSection ) _method( LLVMGetSection )
_method( LLVMSetSection ) _method( LLVMSetSection )
_method( LLVMGetVisibility ) _method( LLVMGetVisibility )
_method( LLVMSetVisibility ) _method( LLVMSetVisibility )
_method( LLVMGetAlignment ) _method( LLVMGetAlignment )
_method( LLVMSetAlignment ) _method( LLVMSetAlignment )
/* Global Variables */ /* Global Variables */
_method( LLVMAddGlobal ) _method( LLVMAddGlobal )
_method( LLVMGetNamedGlobal ) _method( LLVMGetNamedGlobal )
_method( LLVMGetFirstGlobal ) _method( LLVMGetFirstGlobal )
_method( LLVMGetNextGlobal ) _method( LLVMGetNextGlobal )
_method( LLVMDeleteGlobal ) _method( LLVMDeleteGlobal )
_method( LLVMHasInitializer ) _method( LLVMHasInitializer )
_method( LLVMGetInitializer ) _method( LLVMGetInitializer )
_method( LLVMSetInitializer ) _method( LLVMSetInitializer )
_method( LLVMSetThreadLocal ) _method( LLVMSetThreadLocal )
_method( LLVMSetGlobalConstant ) _method( LLVMSetGlobalConstant )
_method( LLVMIsThreadLocal ) _method( LLVMIsThreadLocal )
_method( LLVMIsGlobalConstant ) _method( LLVMIsGlobalConstant )
/* Functions */ /* Functions */
_method( LLVMAddFunction ) _method( LLVMAddFunction )
_method( LLVMGetNamedFunction ) _method( LLVMGetNamedFunction )
_method( LLVMGetFirstFunction ) _method( LLVMGetFirstFunction )
_method( LLVMGetNextFunction ) _method( LLVMGetNextFunction )
_method( LLVMDeleteFunction ) _method( LLVMDeleteFunction )
_method( LLVMGetIntrinsicID ) _method( LLVMGetIntrinsicID )
_method( LLVMGetFunctionCallConv ) _method( LLVMGetFunctionCallConv )
_method( LLVMSetFunctionCallConv ) _method( LLVMSetFunctionCallConv )
_method( LLVMGetGC ) _method( LLVMGetGC )
_method( LLVMSetGC ) _method( LLVMSetGC )
@ -1525,27 +1533,27 @@ static PyMethodDef core_methods[] = {
_method( LLVMRemoveFunctionAttr ) _method( LLVMRemoveFunctionAttr )
/* Arguments */ /* Arguments */
_method( LLVMCountParams ) _method( LLVMCountParams )
_method( LLVMGetFirstParam ) _method( LLVMGetFirstParam )
_method( LLVMGetNextParam ) _method( LLVMGetNextParam )
_method( LLVMGetParamParent ) _method( LLVMGetParamParent )
_method( LLVMAddAttribute ) _method( LLVMAddAttribute )
_method( LLVMRemoveAttribute ) _method( LLVMRemoveAttribute )
_method( LLVMSetParamAlignment ) _method( LLVMSetParamAlignment )
_method( LLVMGetParamAlignment ) _method( LLVMGetParamAlignment )
/* Basic Blocks */ /* Basic Blocks */
_method( LLVMGetBasicBlockParent ) _method( LLVMGetBasicBlockParent )
_method( LLVMCountBasicBlocks ) _method( LLVMCountBasicBlocks )
_method( LLVMGetFirstBasicBlock ) _method( LLVMGetFirstBasicBlock )
_method( LLVMGetNextBasicBlock ) _method( LLVMGetNextBasicBlock )
_method( LLVMGetEntryBasicBlock ) _method( LLVMGetEntryBasicBlock )
_method( LLVMAppendBasicBlock ) _method( LLVMAppendBasicBlock )
_method( LLVMInsertBasicBlock ) _method( LLVMInsertBasicBlock )
_method( LLVMDeleteBasicBlock ) _method( LLVMDeleteBasicBlock )
/* Instructions */ /* Instructions */
_method( LLVMGetInstructionParent ) _method( LLVMGetInstructionParent )
_method( LLVMGetFirstInstruction ) _method( LLVMGetFirstInstruction )
_method( LLVMGetNextInstruction ) _method( LLVMGetNextInstruction )
_method( LLVMInstIsTerminator ) _method( LLVMInstIsTerminator )
@ -1561,102 +1569,102 @@ static PyMethodDef core_methods[] = {
_method( LLVMInstGetOpcodeName ) _method( LLVMInstGetOpcodeName )
/* Call Sites (Call or Invoke) */ /* Call Sites (Call or Invoke) */
_method( LLVMSetInstructionCallConv ) _method( LLVMSetInstructionCallConv )
_method( LLVMGetInstructionCallConv ) _method( LLVMGetInstructionCallConv )
_method( LLVMIsTailCall ) _method( LLVMIsTailCall )
_method( LLVMSetTailCall ) _method( LLVMSetTailCall )
_method( LLVMAddInstrAttribute ) _method( LLVMAddInstrAttribute )
_method( LLVMRemoveInstrAttribute ) _method( LLVMRemoveInstrAttribute )
_method( LLVMSetInstrParamAlignment ) _method( LLVMSetInstrParamAlignment )
/* PHI Nodes */ /* PHI Nodes */
_method( LLVMAddIncoming1 ) _method( LLVMAddIncoming1 )
_method( LLVMCountIncoming ) _method( LLVMCountIncoming )
_method( LLVMGetIncomingValue ) _method( LLVMGetIncomingValue )
_method( LLVMGetIncomingBlock ) _method( LLVMGetIncomingBlock )
/* Comparison Instructions */ /* Comparison Instructions */
_method( LLVMCmpInstGetPredicate ) _method( LLVMCmpInstGetPredicate )
/* Instruction builders */ /* Instruction builders */
_method( LLVMCreateBuilder ) _method( LLVMCreateBuilder )
_method( LLVMPositionBuilderBefore ) _method( LLVMPositionBuilderBefore )
_method( LLVMPositionBuilderAtEnd ) _method( LLVMPositionBuilderAtEnd )
_method( LLVMGetInsertBlock ) _method( LLVMGetInsertBlock )
_method( LLVMDisposeBuilder ) _method( LLVMDisposeBuilder )
/* Terminators */ /* Terminators */
_method( LLVMBuildRetVoid ) _method( LLVMBuildRetVoid )
_method( LLVMBuildRet ) _method( LLVMBuildRet )
_method( LLVMBuildRetMultiple ) _method( LLVMBuildRetMultiple )
_method( LLVMBuildBr ) _method( LLVMBuildBr )
_method( LLVMBuildCondBr ) _method( LLVMBuildCondBr )
_method( LLVMBuildSwitch ) _method( LLVMBuildSwitch )
_method( LLVMBuildInvoke ) _method( LLVMBuildInvoke )
_method( LLVMBuildUnreachable ) _method( LLVMBuildUnreachable )
/* Add a case to the switch instruction */ /* Add a case to the switch instruction */
_method( LLVMAddCase ) _method( LLVMAddCase )
/* Arithmetic */ /* Arithmetic */
_method( LLVMBuildAdd ) _method( LLVMBuildAdd )
_method( LLVMBuildFAdd) _method( LLVMBuildFAdd)
_method( LLVMBuildSub ) _method( LLVMBuildSub )
_method( LLVMBuildFSub) _method( LLVMBuildFSub)
_method( LLVMBuildMul ) _method( LLVMBuildMul )
_method( LLVMBuildFMul) _method( LLVMBuildFMul)
_method( LLVMBuildUDiv ) _method( LLVMBuildUDiv )
_method( LLVMBuildSDiv ) _method( LLVMBuildSDiv )
_method( LLVMBuildFDiv ) _method( LLVMBuildFDiv )
_method( LLVMBuildURem ) _method( LLVMBuildURem )
_method( LLVMBuildSRem ) _method( LLVMBuildSRem )
_method( LLVMBuildFRem ) _method( LLVMBuildFRem )
_method( LLVMBuildShl ) _method( LLVMBuildShl )
_method( LLVMBuildLShr ) _method( LLVMBuildLShr )
_method( LLVMBuildAShr ) _method( LLVMBuildAShr )
_method( LLVMBuildAnd ) _method( LLVMBuildAnd )
_method( LLVMBuildOr ) _method( LLVMBuildOr )
_method( LLVMBuildXor ) _method( LLVMBuildXor )
_method( LLVMBuildNeg ) _method( LLVMBuildNeg )
_method( LLVMBuildNot ) _method( LLVMBuildNot )
/* Memory */ /* Memory */
_method( LLVMBuildMalloc ) _method( LLVMBuildMalloc )
_method( LLVMBuildArrayMalloc ) _method( LLVMBuildArrayMalloc )
_method( LLVMBuildAlloca ) _method( LLVMBuildAlloca )
_method( LLVMBuildArrayAlloca ) _method( LLVMBuildArrayAlloca )
_method( LLVMBuildFree ) _method( LLVMBuildFree )
_method( LLVMBuildLoad ) _method( LLVMBuildLoad )
_method( LLVMBuildStore ) _method( LLVMBuildStore )
_method( LLVMBuildGEP ) _method( LLVMBuildGEP )
/* Casts */ /* Casts */
_method( LLVMBuildTrunc ) _method( LLVMBuildTrunc )
_method( LLVMBuildZExt ) _method( LLVMBuildZExt )
_method( LLVMBuildSExt ) _method( LLVMBuildSExt )
_method( LLVMBuildFPToUI ) _method( LLVMBuildFPToUI )
_method( LLVMBuildFPToSI ) _method( LLVMBuildFPToSI )
_method( LLVMBuildUIToFP ) _method( LLVMBuildUIToFP )
_method( LLVMBuildSIToFP ) _method( LLVMBuildSIToFP )
_method( LLVMBuildFPTrunc ) _method( LLVMBuildFPTrunc )
_method( LLVMBuildFPExt ) _method( LLVMBuildFPExt )
_method( LLVMBuildPtrToInt ) _method( LLVMBuildPtrToInt )
_method( LLVMBuildIntToPtr ) _method( LLVMBuildIntToPtr )
_method( LLVMBuildBitCast ) _method( LLVMBuildBitCast )
/* Comparisons */ /* Comparisons */
_method( LLVMBuildICmp ) _method( LLVMBuildICmp )
_method( LLVMBuildFCmp ) _method( LLVMBuildFCmp )
/* Miscellaneous instructions */ /* Miscellaneous instructions */
_method( LLVMBuildGetResult ) _method( LLVMBuildGetResult )
_method( LLVMBuildPhi ) _method( LLVMBuildPhi )
_method( LLVMBuildCall ) _method( LLVMBuildCall )
_method( LLVMBuildSelect ) _method( LLVMBuildSelect )
_method( LLVMBuildVAArg ) _method( LLVMBuildVAArg )
_method( LLVMBuildExtractElement ) _method( LLVMBuildExtractElement )
_method( LLVMBuildInsertElement ) _method( LLVMBuildInsertElement )
_method( LLVMBuildShuffleVector ) _method( LLVMBuildShuffleVector )
/* Memory Buffer */ /* Memory Buffer */
_method( LLVMCreateMemoryBufferWithContentsOfFile ) _method( LLVMCreateMemoryBufferWithContentsOfFile )
@ -1664,12 +1672,12 @@ static PyMethodDef core_methods[] = {
_method( LLVMDisposeMemoryBuffer ) _method( LLVMDisposeMemoryBuffer )
/* Pass Manager */ /* Pass Manager */
_method( LLVMCreatePassManager ) _method( LLVMCreatePassManager )
_method( LLVMCreateFunctionPassManagerForModule ) _method( LLVMCreateFunctionPassManagerForModule )
_method( LLVMRunPassManager ) _method( LLVMRunPassManager )
_method( LLVMInitializeFunctionPassManager ) _method( LLVMInitializeFunctionPassManager )
_method( LLVMRunFunctionPassManager ) _method( LLVMRunFunctionPassManager )
_method( LLVMFinalizeFunctionPassManager ) _method( LLVMFinalizeFunctionPassManager )
_method( LLVMDisposePassManager ) _method( LLVMDisposePassManager )
/* Passes */ /* Passes */
@ -1838,7 +1846,7 @@ init_core(void)
if (module == NULL) if (module == NULL)
INITERROR; INITERROR;
#if PY_MAJOR_VERSION >= 3 #if PY_MAJOR_VERSION >= 3
return module; return module;
#endif #endif
} }

View file

@ -585,24 +585,42 @@ class Type(object):
var_arg), TYPE_FUNCTION) var_arg), TYPE_FUNCTION)
@staticmethod @staticmethod
def struct(element_tys): # not packed def struct(element_tys, name=''): # not packed
"""Create a (unpacked) structure type. """Create a (unpacked) structure type.
Creates a structure type with elements of types as given in the Creates a structure type with elements of types as given in the
iterable `element_tys'. This method creates a unpacked iterable `element_tys'. This method creates a unpacked
structure. For a packed one, use the packed_struct() method.""" structure. For a packed one, use the packed_struct() method.
If name is not '', creates a identified type;
otherwise, creates a literal type."""
elems = unpack_types(element_tys) elems = unpack_types(element_tys)
return _make_type(_core.LLVMStructType(elems, 0), TYPE_STRUCT)
if name: # create Identified StructType
objptr = _core.LLVMStructTypeIdentified(name)
_core.LLVMSetStructBody(objptr, elems, 0)
else: # create Literal StructType
objptr = _core.LLVMStructType(elems, 0)
return _make_type(objptr, TYPE_STRUCT)
@staticmethod @staticmethod
def packed_struct(element_tys): def packed_struct(element_tys, name=''):
"""Create a (packed) structure type. """Create a (packed) structure type.
Creates a structure type with elements of types as given in the Creates a structure type with elements of types as given in the
iterable `element_tys'. This method creates a packed iterable `element_tys'. This method creates a packed
structure. For an unpacked one, use the struct() method.""" structure. For an unpacked one, use the struct() method.
If name is not '', creates a identified type;
otherwise, creates a literal type."""
elems = unpack_types(element_tys) elems = unpack_types(element_tys)
return _make_type(_core.LLVMStructType(elems, 1), TYPE_STRUCT)
if name: # create Identified StructType
objptr = _core.LLVMStructTypeIdentified(name)
_core.LLVMSetStructBody(objptr, elems, 0)
else: # create Literal StructType
objptr = _core.LLVMStructType(elems, 1)
@staticmethod @staticmethod
def array(element_ty, count): def array(element_ty, count):
@ -725,18 +743,25 @@ class StructType(Type):
Same as len(obj.elements), but faster.""" Same as len(obj.elements), but faster."""
return _core.LLVMCountStructElementTypes(self.ptr) return _core.LLVMCountStructElementTypes(self.ptr)
#@property @property
#def elements(self): def elements(self):
# """An iterable that yieldsd Type objects, representing the types of the """An iterable that yieldsd Type objects, representing the types of the
# elements (members) of the structure, in order.""" elements (members) of the structure, in order."""
# pp = _core.LLVMGetStructElementTypes(self.ptr) pp = _core.LLVMGetStructElementTypes(self.ptr)
# return [ _make_type(p, _core.LLVMGetTypeKind(p)) for p in pp ] return [ _make_type(p, _core.LLVMGetTypeKind(p)) for p in pp ]
@property @property
def packed(self): def packed(self):
"""True if the structure is packed, False otherwise.""" """True if the structure is packed, False otherwise."""
return _core.LLVMIsPackedStruct(self.ptr) != 0 return _core.LLVMIsPackedStruct(self.ptr) != 0
def _set_name(self, name):
_core.LLVMSetStructName(self.ptr, name)
def _get_name(self):
return _core.LLVMGetStructName(self.ptr)
name = property(_get_name, _set_name)
class ArrayType(Type): class ArrayType(Type):
"""Represents an array type.""" """Represents an array type."""

View file

@ -90,6 +90,25 @@ char *do_print(W obj)
return strdup(buf.str().c_str()); return strdup(buf.str().c_str());
} }
LLVMTypeRef LLVMStructTypeIdentified(const char * name)
{
using namespace llvm;
return wrap(StructType::create(getGlobalContext(), name));
}
void LLVMSetStructBody(LLVMTypeRef type, LLVMTypeRef* elemtys, unsigned elemct, int is_packed)
{
using namespace llvm;
ArrayRef<Type*> elemtys_aryref(unwrap(elemtys), elemct);
unwrap<StructType>(type)->setBody(elemtys_aryref, is_packed);
}
void LLVMSetStructName(LLVMTypeRef type, const char * name)
{
llvm::StructType *st = llvm::unwrap<llvm::StructType>(type);
st->setName(name);
}
char *LLVMGetModuleIdentifier(LLVMModuleRef module) char *LLVMGetModuleIdentifier(LLVMModuleRef module)
{ {
return strdup(llvm::unwrap(module)->getModuleIdentifier().c_str()); return strdup(llvm::unwrap(module)->getModuleIdentifier().c_str());

View file

@ -41,6 +41,21 @@
extern "C" { extern "C" {
#endif #endif
/*
* Wraps StructType::create()
*/
LLVMTypeRef LLVMStructTypeIdentified(const char * name);
/*
* StructType::setBody()
*/
void LLVMSetStructBody(LLVMTypeRef type, LLVMTypeRef* elemtys, unsigned elemct, int is_packed);
/*
* Wraps llvm::StructType::setName()
*/
void LLVMSetStructName(LLVMTypeRef type, const char * name);
/* /*
* Wraps llvm::Module::getModuleIdentifier() * Wraps llvm::Module::getModuleIdentifier()

View file

@ -11,7 +11,7 @@
* this list of conditions and the following disclaimer in the documentation * this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution. * and/or other materials provided with the distribution.
* *
* * Neither the name of this software, nor the names of its * * Neither the name of this software, nor the names of its
* contributors may be used to endorse or promote products derived from * contributors may be used to endorse or promote products derived from
* this software without specific prior written permission. * this software without specific prior written permission.
* *
@ -30,7 +30,7 @@
/** /**
* Functions and macros to aid in wrapping. * Functions and macros to aid in wrapping.
*/ */
#ifndef LLVM_PY_WRAP_H #ifndef LLVM_PY_WRAP_H
#define LLVM_PY_WRAP_H #define LLVM_PY_WRAP_H
@ -169,7 +169,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2) * outtype func(intype1 arg1, intype2 arg2)
*/ */
#define _wrap_objobj2obj(func, intype1, intype2, outtype)\ #define _wrap_objobj2obj(func, intype1, intype2, outtype)\
@ -232,7 +232,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, intype3 arg3) * outtype func(intype1 arg1, intype2 arg2, intype3 arg3)
*/ */
#define _wrap_objobjobj2obj(func, intype1, intype2, intype3, outtype) \ #define _wrap_objobjobj2obj(func, intype1, intype2, intype3, outtype) \
@ -255,7 +255,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* void func(intype1 arg1, intype2 arg2, intype3 arg3) * void func(intype1 arg1, intype2 arg2, intype3 arg3)
*/ */
#define _wrap_objobjobj2none(func, intype1, intype2, intype3) \ #define _wrap_objobjobj2none(func, intype1, intype2, intype3) \
@ -474,7 +474,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, const char *arg3) * outtype func(intype1 arg1, intype2 arg2, const char *arg3)
*/ */
#define _wrap_objobjstr2obj(func, intype1, intype2, outtype) \ #define _wrap_objobjstr2obj(func, intype1, intype2, outtype) \
@ -497,7 +497,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, int arg3) * outtype func(intype1 arg1, intype2 arg2, int arg3)
*/ */
#define _wrap_objobjint2obj(func, intype1, intype2, outtype) \ #define _wrap_objobjint2obj(func, intype1, intype2, outtype) \
@ -519,7 +519,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, unsigned long long arg3) * outtype func(intype1 arg1, intype2 arg2, unsigned long long arg3)
*/ */
#define _wrap_objobjull2obj(func, intype1, intype2, outtype) \ #define _wrap_objobjull2obj(func, intype1, intype2, outtype) \
@ -541,7 +541,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* void func(intype1 arg1, <unsigned/signed int> arg2, <unsigned/signed int> arg3) * void func(intype1 arg1, <unsigned/signed int> arg2, <unsigned/signed int> arg3)
*/ */
#define _wrap_objintint2none(func, intype1) \ #define _wrap_objintint2none(func, intype1) \
@ -562,7 +562,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* void func(intype1 arg1, <unsigned/signed int> arg2, enum_intype3 arg3) * void func(intype1 arg1, <unsigned/signed int> arg2, enum_intype3 arg3)
*/ */
#define _wrap_objintenum2none(func, intype1, intype3) \ #define _wrap_objintenum2none(func, intype1, intype3) \
@ -584,7 +584,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, const char *arg2, intype3 arg3) * outtype func(intype1 arg1, const char *arg2, intype3 arg3)
*/ */
#define _wrap_objstrobj2obj(func, intype1, intype3, outtype) \ #define _wrap_objstrobj2obj(func, intype1, intype3, outtype) \
@ -608,7 +608,7 @@ _w ## func (PyObject *self, PyObject *args) \
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, int arg3, const char *arg4) * outtype func(intype1 arg1, intype2 arg2, int arg3, const char *arg4)
*/ */
#define _wrap_objobjintstr2obj(func, intype1, intype2, outtype) \ #define _wrap_objobjintstr2obj(func, intype1, intype2, outtype) \
@ -632,7 +632,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, intype3 arg3, const char *arg4) * outtype func(intype1 arg1, intype2 arg2, intype3 arg3, const char *arg4)
*/ */
#define _wrap_objobjobjstr2obj(func, intype1, intype2, intype3, outtype)\ #define _wrap_objobjobjstr2obj(func, intype1, intype2, intype3, outtype)\
@ -657,7 +657,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, intype3 arg3, <unsigned/signed int> arg4) * outtype func(intype1 arg1, intype2 arg2, intype3 arg3, <unsigned/signed int> arg4)
*/ */
#define _wrap_objobjobjint2obj(func, intype1, intype2, intype3, outtype) \ #define _wrap_objobjobjint2obj(func, intype1, intype2, intype3, outtype) \
@ -681,7 +681,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, intype3 arg3, intype arg4) * outtype func(intype1 arg1, intype2 arg2, intype3 arg3, intype arg4)
*/ */
#define _wrap_objobjobjobj2obj(func, intype1, intype2, intype3, intype4, outtype) \ #define _wrap_objobjobjobj2obj(func, intype1, intype2, intype3, intype4, outtype) \
@ -706,7 +706,7 @@ _w ## func (PyObject *self, PyObject *args)
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, intype3 arg3, intype arg4, const char *arg5) * outtype func(intype1 arg1, intype2 arg2, intype3 arg3, intype arg4, const char *arg5)
*/ */
#define _wrap_objobjobjobjstr2obj(func, intype1, intype2, intype3, intype4, outtype)\ #define _wrap_objobjobjobjstr2obj(func, intype1, intype2, intype3, intype4, outtype)\
@ -868,6 +868,35 @@ _w ## func (PyObject *self, PyObject *args) \
return ctor_ ## outtype (ret); \ return ctor_ ## outtype (ret); \
} }
/**
* Wrap LLVM functions of the type
* void func(intype1 arg1, intype2 *arg2v, unsigned arg2n, int arg3)
* where arg2v is an array of intype2 elements, arg2n in length.
*/
#define _wrap_objlistint2none(func, intype1, intype2) \
static PyObject * \
_w ## func (PyObject *self, PyObject *args) \
{ \
PyObject *obj1, *obj2; \
intype1 arg1; \
intype2 *arg2v; \
unsigned arg2n; \
int arg3; \
\
if (!PyArg_ParseTuple(args, "OOi", &obj1, &obj2, &arg3)) \
return NULL; \
\
arg1 = ( intype1 ) PyCapsule_GetPointer(obj1, NULL); \
arg2n = (unsigned) PyList_Size(obj2); \
if (!(arg2v = ( intype2 *)make_array_from_list(obj2, arg2n)))\
return PyErr_NoMemory(); \
\
func (arg1, arg2v, arg2n, arg3); \
free(arg2v); \
Py_RETURN_NONE; \
}
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, int arg2, intype3 *arg3v, unsigned arg3n) * outtype func(intype1 arg1, int arg2, intype3 *arg3v, unsigned arg3n)
@ -1022,7 +1051,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2) * outtype func(intype1 arg1, intype2 arg2)
*/ */
#define _wrap_objobj2obj(func, intype1, intype2, outtype) \ #define _wrap_objobj2obj(func, intype1, intype2, outtype) \
@ -1082,7 +1111,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, intype3 arg3) * outtype func(intype1 arg1, intype2 arg2, intype3 arg3)
*/ */
#define _wrap_objobjobj2obj(func, intype1, intype2, intype3, outtype) \ #define _wrap_objobjobj2obj(func, intype1, intype2, intype3, outtype) \
@ -1105,7 +1134,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* void func(intype1 arg1, intype2 arg2, intype3 arg3) * void func(intype1 arg1, intype2 arg2, intype3 arg3)
*/ */
#define _wrap_objobjobj2none(func, intype1, intype2, intype3) \ #define _wrap_objobjobj2none(func, intype1, intype2, intype3) \
@ -1319,7 +1348,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, const char *arg3) * outtype func(intype1 arg1, intype2 arg2, const char *arg3)
*/ */
#define _wrap_objobjstr2obj(func, intype1, intype2, outtype) \ #define _wrap_objobjstr2obj(func, intype1, intype2, outtype) \
@ -1341,7 +1370,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, int arg3) * outtype func(intype1 arg1, intype2 arg2, int arg3)
*/ */
#define _wrap_objobjint2obj(func, intype1, intype2, outtype) \ #define _wrap_objobjint2obj(func, intype1, intype2, outtype) \
@ -1363,7 +1392,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, unsigned long long arg3) * outtype func(intype1 arg1, intype2 arg2, unsigned long long arg3)
*/ */
#define _wrap_objobjull2obj(func, intype1, intype2, outtype) \ #define _wrap_objobjull2obj(func, intype1, intype2, outtype) \
@ -1385,7 +1414,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* void func(intype1 arg1, <unsigned/signed int> arg2, <unsigned/signed int> arg3) * void func(intype1 arg1, <unsigned/signed int> arg2, <unsigned/signed int> arg3)
*/ */
#define _wrap_objintint2none(func, intype1) \ #define _wrap_objintint2none(func, intype1) \
@ -1406,7 +1435,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* void func(intype1 arg1, <unsigned/signed int> arg2, enum_intype3 arg3) * void func(intype1 arg1, <unsigned/signed int> arg2, enum_intype3 arg3)
*/ */
#define _wrap_objintenum2none(func, intype1, intype3) \ #define _wrap_objintenum2none(func, intype1, intype3) \
@ -1428,7 +1457,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, const char *arg2, intype3 arg3) * outtype func(intype1 arg1, const char *arg2, intype3 arg3)
*/ */
#define _wrap_objstrobj2obj(func, intype1, intype3, outtype) \ #define _wrap_objstrobj2obj(func, intype1, intype3, outtype) \
@ -1451,7 +1480,7 @@ _w ## func (PyObject *self, PyObject *args) \
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, int arg3, const char *arg4) * outtype func(intype1 arg1, intype2 arg2, int arg3, const char *arg4)
*/ */
#define _wrap_objobjintstr2obj(func, intype1, intype2, outtype) \ #define _wrap_objobjintstr2obj(func, intype1, intype2, outtype) \
@ -1474,7 +1503,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, intype3 arg3, const char *arg4) * outtype func(intype1 arg1, intype2 arg2, intype3 arg3, const char *arg4)
*/ */
#define _wrap_objobjobjstr2obj(func, intype1, intype2, intype3, outtype) \ #define _wrap_objobjobjstr2obj(func, intype1, intype2, intype3, outtype) \
@ -1498,7 +1527,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, intype3 arg3, <unsigned/signed int> arg4) * outtype func(intype1 arg1, intype2 arg2, intype3 arg3, <unsigned/signed int> arg4)
*/ */
#define _wrap_objobjobjint2obj(func, intype1, intype2, intype3, outtype) \ #define _wrap_objobjobjint2obj(func, intype1, intype2, intype3, outtype) \
@ -1522,7 +1551,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, intype3 arg3, intype arg4) * outtype func(intype1 arg1, intype2 arg2, intype3 arg3, intype arg4)
*/ */
#define _wrap_objobjobjobj2obj(func, intype1, intype2, intype3, intype4, outtype) \ #define _wrap_objobjobjobj2obj(func, intype1, intype2, intype3, intype4, outtype) \
@ -1547,7 +1576,7 @@ _w ## func (PyObject *self, PyObject *args) \
} }
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, intype3 arg3, intype arg4, const char *arg5) * outtype func(intype1 arg1, intype2 arg2, intype3 arg3, intype arg4, const char *arg5)
*/ */
#define _wrap_objobjobjobjstr2obj(func, intype1, intype2, intype3, intype4, outtype) \ #define _wrap_objobjobjobjstr2obj(func, intype1, intype2, intype3, intype4, outtype) \
@ -1706,6 +1735,35 @@ _w ## func (PyObject *self, PyObject *args) \
return ctor_ ## outtype (ret); \ return ctor_ ## outtype (ret); \
} }
/**
* Wrap LLVM functions of the type
* void func(intype1 arg1, intype2 *arg2v, unsigned arg2n, int arg3)
* where arg2v is an array of intype2 elements, arg2n in length.
*/
#define _wrap_objlistint2none(func, intype1, intype2) \
static PyObject * \
_w ## func (PyObject *self, PyObject *args) \
{ \
PyObject *obj1, *obj2; \
intype1 arg1; \
intype2 *arg2v; \
unsigned arg2n; \
int arg3; \
\
if (!PyArg_ParseTuple(args, "OOi", &obj1, &obj2, &arg3)) \
return NULL; \
\
arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \
arg2n = (unsigned) PyList_Size(obj2); \
if (!(arg2v = ( intype2 *)make_array_from_list(obj2, arg2n))) \
return PyErr_NoMemory(); \
\
func (arg1, arg2v, arg2n, arg3); \
free(arg2v); \
Py_RETURN_NONE; \
}
/** /**
* Wrap LLVM functions of the type * Wrap LLVM functions of the type
* outtype func(intype1 arg1, int arg2, intype3 *arg3v, unsigned arg3n) * outtype func(intype1 arg1, int arg2, intype3 *arg3v, unsigned arg3n)

View file

@ -3,17 +3,17 @@
# watch out for uncollected objects # watch out for uncollected objects
import gc import gc
import unittest, sys import unittest, sys, logging
from llvm import * from llvm import *
from llvm.core import * from llvm.core import *
class TestModule(unittest.TestCase): class TestModule(unittest.TestCase):
def setUp(self): def setUp(self):
pass pass
def testdata_layout(self): def testdata_layout(self):
"""Data layout property.""" """Data layout property."""
m = Module.new("test2.1") m = Module.new("test2.1")
@ -33,23 +33,39 @@ class TestModule(unittest.TestCase):
reqd = '; ModuleID = \'test3.1\'\ntarget triple = "some_value"\n' reqd = '; ModuleID = \'test3.1\'\ntarget triple = "some_value"\n'
self.assertEqual(str(m), reqd) self.assertEqual(str(m), reqd)
# Type system is rewritten in LLVM 3.0.
# Only named StructType is supported.
# See http://blog.llvm.org/2011/11/llvm-30-type-system-rewrite.html
#
# def testtype_name(self):
# """Type names."""
# m = Module.new("test4.1")
# r = m.add_type_name("typename41", Type.int())
# self.assertEqual(r, 0)
# r = m.add_type_name("typename41", Type.int())
# self.assertEqual(r, 1)
# reqd = "; ModuleID = 'test4.1'\n\n%typename41 = type i32\n"
# self.assertEqual(str(m), reqd)
# r = m.delete_type_name("typename41")
# reqd = "; ModuleID = 'test4.1'\n"
# self.assertEqual(str(m), reqd)
# r = m.delete_type_name("no such name") # nothing should happen
# reqd = "; ModuleID = 'test4.1'\n"
# self.assertEqual(str(m), reqd)
def testtype_name(self): def testtype_name(self):
"""Type names."""
m = Module.new("test4.1") m = Module.new("test4.1")
r = m.add_type_name("typename41", Type.int()) struct = Type.struct([Type.int(), Type.int()], name="struct.two.int")
self.assertEqual(r, 0) self.assertEqual(struct.name, "struct.two.int")
r = m.add_type_name("typename41", Type.int()) got_struct = m.get_type_named(struct.name)
self.assertEqual(r, 1) self.assertEqual(got_struct.name, struct.name)
reqd = "; ModuleID = 'test4.1'\n\n%typename41 = type i32\n"
self.assertEqual(str(m), reqd)
r = m.delete_type_name("typename41")
reqd = "; ModuleID = 'test4.1'\n"
self.assertEqual(str(m), reqd)
r = m.delete_type_name("no such name") # nothing should happen
reqd = "; ModuleID = 'test4.1'\n"
self.assertEqual(str(m), reqd)
self.assertEqual(got_struct.element_count, struct.element_count)
self.assertEqual(len(struct.elements), struct.element_count)
self.assertEqual(struct.elements, got_struct.elements)
for elty in struct.elements:
self.assertEqual(elty, Type.int())
def testglobal_variable(self): def testglobal_variable(self):
"""Global variables.""" """Global variables."""
@ -65,11 +81,14 @@ def main():
gc.set_debug(gc.DEBUG_LEAK) gc.set_debug(gc.DEBUG_LEAK)
# run tests # run tests
unittest.main() unittest.main(exit=False) # set exit to False so that it will return.
# done # done
if gc.garbage: for it in gc.garbage:
print("garbage = ", gc.garbage) logging.debug('garbage = %s', it)
if __name__ == '__main__':
main()
main()