From 6cb58c97d7d52ceea26c337023abe186b6e3bb61 Mon Sep 17 00:00:00 2001 From: "mdevan.foobar" Date: Sun, 20 Sep 2009 09:25:14 +0000 Subject: [PATCH] does not throw property for Function (Andrew Straw) git-svn-id: http://llvm-py.googlecode.com/svn/trunk@79 8d1e9007-1d4e-0410-b67e-1979fd6579aa --- llvm/_core.c | 4 ++++ llvm/core.py | 6 +++++- llvm/extra.cpp | 16 ++++++++++++++++ llvm/extra.h | 6 ++++++ test/testall.py | 2 ++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/llvm/_core.c b/llvm/_core.c index f3b86e1..3d15ea1 100644 --- a/llvm/_core.c +++ b/llvm/_core.c @@ -505,6 +505,8 @@ _wrap_obj2obj(LLVMGetFunctionCallConv, LLVMValueRef, int) _wrap_objint2none(LLVMSetFunctionCallConv, LLVMValueRef) _wrap_obj2str(LLVMGetGC, LLVMValueRef) _wrap_objstr2none(LLVMSetGC, LLVMValueRef) +_wrap_obj2obj(LLVMGetDoesNotThrow, LLVMValueRef, int) +_wrap_objint2none(LLVMSetDoesNotThrow, LLVMValueRef) _wrap_obj2none(LLVMViewFunctionCFG, LLVMValueRef) _wrap_obj2none(LLVMViewFunctionCFGOnly, LLVMValueRef) @@ -1324,6 +1326,8 @@ static PyMethodDef core_methods[] = { _method( LLVMSetFunctionCallConv ) _method( LLVMGetGC ) _method( LLVMSetGC ) + _method( LLVMGetDoesNotThrow ) + _method( LLVMSetDoesNotThrow ) _method( LLVMVerifyFunction ) _method( LLVMViewFunctionCFG ) _method( LLVMViewFunctionCFGOnly ) diff --git a/llvm/core.py b/llvm/core.py index 5068552..64ca354 100644 --- a/llvm/core.py +++ b/llvm/core.py @@ -1286,6 +1286,11 @@ class Function(GlobalValue): def _set_coll(self, value): _core.LLVMSetGC(self.ptr, value) collector = property(_get_coll, _set_coll) + # the nounwind attribute: + def _get_does_not_throw(self): return _core.LLVMGetDoesNotThrow(self.ptr) + def _set_does_not_throw(self,value): _core.LLVMSetDoesNotThrow(self.ptr, value) + does_not_throw = property(_get_does_not_throw, _set_does_not_throw) + @property def args(self): return _util.wrapiter(_core.LLVMGetFirstParam, @@ -1324,7 +1329,6 @@ class Function(GlobalValue): # failure, it appears to print result to stderr and abort. return _core.LLVMVerifyFunction(self.ptr) != 0 - #===----------------------------------------------------------------------=== # Instruction #===----------------------------------------------------------------------=== diff --git a/llvm/extra.cpp b/llvm/extra.cpp index d2b1e12..72bd6a2 100644 --- a/llvm/extra.cpp +++ b/llvm/extra.cpp @@ -365,6 +365,22 @@ LLVMValueRef LLVMUserGetOperand(LLVMValueRef user, unsigned idx) return llvm::wrap(operand); } +unsigned LLVMGetDoesNotThrow(LLVMValueRef fn) +{ + llvm::Function *fnp = llvm::unwrap(fn); + assert(fnp); + + return fnp->doesNotThrow(); +} + +void LLVMSetDoesNotThrow(LLVMValueRef fn, int DoesNotThrow) +{ + llvm::Function *fnp = llvm::unwrap(fn); + assert(fnp); + + return fnp->setDoesNotThrow((bool)DoesNotThrow); +} + LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef module, int id, LLVMTypeRef *types, unsigned n_types) { diff --git a/llvm/extra.h b/llvm/extra.h index 73890cb..5833b1f 100644 --- a/llvm/extra.h +++ b/llvm/extra.h @@ -107,6 +107,12 @@ LLVMValueRef LLVMBuildVFCmp(LLVMBuilderRef builder, LLVMRealPredicate predicate, LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef builder, int id, LLVMTypeRef *types, unsigned n_types); +/* Wraps llvm::Function::doesNotThrow(). */ +unsigned LLVMGetDoesNotThrow(LLVMValueRef fn); + +/* Wraps llvm::Function::setDoesNotThrow(). */ +void LLVMSetDoesNotThrow(LLVMValueRef fn, int DoesNotThrow); + /* Wraps llvm::Module::getPointerSize(). */ unsigned LLVMModuleGetPointerSize(LLVMModuleRef module); diff --git a/test/testall.py b/test/testall.py index 82a2460..e16cf47 100755 --- a/test/testall.py +++ b/test/testall.py @@ -282,6 +282,8 @@ def do_function(): f.delete() ft = Type.function(ti, [ti]*20) f = Function.new(m, ft, 'func2') + has_nounwind = f.does_not_throw + f.does_not_throw = True f2 = Function.intrinsic(m, INTR_COS, [ti]) g = f.intrinsic_id f.calling_convenion = CC_FASTCALL