commit
47baa49160
5 changed files with 34 additions and 2 deletions
|
|
@ -461,6 +461,8 @@ _wLLVMConstReal(PyObject *self, PyObject *args)
|
|||
}
|
||||
|
||||
_wrap_objstr2obj(LLVMConstRealOfString, LLVMTypeRef, LLVMValueRef)
|
||||
_wrap_obj2obj(LLVMConstIntGetZExtValue, LLVMValueRef, llvmwrap_ull)
|
||||
_wrap_obj2obj(LLVMConstIntGetSExtValue, LLVMValueRef, llvmwrap_ll)
|
||||
|
||||
/* Operations on composite constants */
|
||||
|
||||
|
|
@ -1581,6 +1583,8 @@ static PyMethodDef core_methods[] = {
|
|||
_method( LLVMConstInt )
|
||||
_method( LLVMConstReal )
|
||||
_method( LLVMConstRealOfString )
|
||||
_method( LLVMConstIntGetZExtValue )
|
||||
_method( LLVMConstIntGetSExtValue )
|
||||
|
||||
/* Operations on composite constants */
|
||||
_method( LLVMConstString )
|
||||
|
|
|
|||
12
llvm/core.py
12
llvm/core.py
|
|
@ -1193,7 +1193,17 @@ class ConstantDataVector(Constant):
|
|||
pass
|
||||
|
||||
class ConstantInt(Constant):
|
||||
pass
|
||||
@property
|
||||
def z_ext_value(self):
|
||||
'''Obtain the zero extended value for an integer constant value.'''
|
||||
# Warning: assertion failure when value does not fit in 64 bits
|
||||
return _core.LLVMConstIntGetZExtValue(self.ptr)
|
||||
|
||||
@property
|
||||
def s_ext_value(self):
|
||||
'''Obtain the sign extended value for an integer constant value.'''
|
||||
# Warning: assertion failure when value does not fit in 64 bits
|
||||
return _core.LLVMConstIntGetSExtValue(self.ptr)
|
||||
|
||||
|
||||
class ConstantFP(Constant):
|
||||
|
|
|
|||
|
|
@ -37,7 +37,9 @@ entry:
|
|||
%tmp1 = call i32 @prod(i32 %0, i32 %1)
|
||||
%tmp2 = add i32 %tmp1, %2
|
||||
%tmp3 = add i32 %tmp2, 1
|
||||
ret i32 %tmp3
|
||||
%tmp4 = add i32 %tmp3, -1
|
||||
%tmp5 = add i64 -81985529216486895, 12297829382473034410
|
||||
ret i32 %tmp4
|
||||
}
|
||||
"""
|
||||
def test_operands(self):
|
||||
|
|
@ -49,10 +51,20 @@ entry:
|
|||
# test operands
|
||||
i1 = test_func.basic_blocks[0].instructions[0]
|
||||
i2 = test_func.basic_blocks[0].instructions[1]
|
||||
i3 = test_func.basic_blocks[0].instructions[2]
|
||||
i4 = test_func.basic_blocks[0].instructions[3]
|
||||
i5 = test_func.basic_blocks[0].instructions[4]
|
||||
|
||||
self.assertEqual(i1.operand_count, 3)
|
||||
self.assertEqual(i2.operand_count, 2)
|
||||
|
||||
self.assertEqual(i3.operands[1].z_ext_value, 1)
|
||||
self.assertEqual(i3.operands[1].s_ext_value, 1)
|
||||
self.assertEqual(i4.operands[1].z_ext_value, 0xffffffff)
|
||||
self.assertEqual(i4.operands[1].s_ext_value, -1)
|
||||
self.assertEqual(i5.operands[0].s_ext_value, -81985529216486895)
|
||||
self.assertEqual(i5.operands[1].z_ext_value, 12297829382473034410)
|
||||
|
||||
self.assert_(i1.operands[-1] is prod)
|
||||
self.assert_(i1.operands[0] is test_func.args[0])
|
||||
self.assert_(i1.operands[1] is test_func.args[1])
|
||||
|
|
|
|||
|
|
@ -72,6 +72,10 @@ PyObject *ctor_llvmwrap_ull(llvmwrap_ull ull)
|
|||
return PyLong_FromUnsignedLongLong(ull);
|
||||
}
|
||||
|
||||
PyObject *ctor_llvmwrap_ll(llvmwrap_ll ll)
|
||||
{
|
||||
return PyLong_FromLongLong(ll);
|
||||
}
|
||||
|
||||
/*===----------------------------------------------------------------------===*/
|
||||
/* Helper functions */
|
||||
|
|
|
|||
|
|
@ -64,6 +64,7 @@
|
|||
/*===----------------------------------------------------------------------===*/
|
||||
|
||||
typedef unsigned long long llvmwrap_ull;
|
||||
typedef long long llvmwrap_ll;
|
||||
|
||||
/*===----------------------------------------------------------------------===*/
|
||||
/* Type ctor/dtor */
|
||||
|
|
@ -98,6 +99,7 @@ _declare_std_ctor(LLVMTargetMachineRef)
|
|||
/* standard types */
|
||||
_declare_std_ctor(int)
|
||||
_declare_std_ctor(llvmwrap_ull)
|
||||
_declare_std_ctor(llvmwrap_ll)
|
||||
|
||||
|
||||
/*===----------------------------------------------------------------------===*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue