Added missing instructions and constant expressions. Updated documentation.

git-svn-id: http://llvm-py.googlecode.com/svn/trunk@9 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
mdevan.foobar 2008-06-11 17:55:38 +00:00
commit a73422f719
17 changed files with 752 additions and 57 deletions

View file

@ -286,6 +286,8 @@ _wrap_objobj2obj(LLVMConstXor, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_intobjobj2obj(LLVMConstICmp, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_intobjobj2obj(LLVMConstFCmp, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_intobjobj2obj(LLVMConstVICmp, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_intobjobj2obj(LLVMConstVFCmp, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_objobj2obj(LLVMConstShl, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_objobj2obj(LLVMConstLShr, LLVMValueRef, LLVMValueRef, LLVMValueRef)
@ -435,6 +437,7 @@ _wrap_obj2none(LLVMDisposeBuilder, LLVMBuilderRef)
_wrap_obj2obj(LLVMBuildRetVoid, LLVMBuilderRef, LLVMValueRef)
_wrap_objobj2obj(LLVMBuildRet, LLVMBuilderRef, LLVMValueRef, LLVMValueRef)
_wrap_objlist2obj(LLVMBuildRetMultiple, LLVMBuilderRef, LLVMValueRef, LLVMValueRef)
_wrap_objobj2obj(LLVMBuildBr, LLVMBuilderRef, LLVMBasicBlockRef, LLVMValueRef)
_wrap_objobjobjobj2obj(LLVMBuildCondBr, LLVMBuilderRef, LLVMValueRef, LLVMBasicBlockRef, LLVMBasicBlockRef, LLVMValueRef)
_wrap_objobjobjint2obj(LLVMBuildSwitch, LLVMBuilderRef, LLVMValueRef, LLVMBasicBlockRef, LLVMValueRef)
@ -527,9 +530,12 @@ _wrap_objobjobjstr2obj(LLVMBuildBitCast, LLVMBuilderRef, LLVMValueRef, LLVMTypeR
_wrap_objintobjobjstr2obj(LLVMBuildICmp, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_objintobjobjstr2obj(LLVMBuildFCmp, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_objintobjobjstr2obj(LLVMBuildVICmp, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_objintobjobjstr2obj(LLVMBuildVFCmp, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
/* Miscellaneous instructions */
_wrap_objobjintstr2obj(LLVMBuildGetResult, LLVMBuilderRef, LLVMValueRef, LLVMValueRef)
_wrap_objobjstr2obj(LLVMBuildPhi, LLVMBuilderRef, LLVMTypeRef, LLVMValueRef)
_wrap_objobjliststr2obj(LLVMBuildCall, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
_wrap_objobjobjobjstr2obj(LLVMBuildSelect, LLVMBuilderRef, LLVMValueRef, LLVMValueRef, LLVMValueRef, LLVMValueRef)
@ -837,6 +843,8 @@ static PyMethodDef core_methods[] = {
_method( LLVMConstXor )
_method( LLVMConstICmp )
_method( LLVMConstFCmp )
_method( LLVMConstVICmp )
_method( LLVMConstVFCmp )
_method( LLVMConstShl )
_method( LLVMConstLShr )
_method( LLVMConstAShr )
@ -947,6 +955,7 @@ static PyMethodDef core_methods[] = {
/* Terminators */
_method( LLVMBuildRetVoid )
_method( LLVMBuildRet )
_method( LLVMBuildRetMultiple )
_method( LLVMBuildBr )
_method( LLVMBuildCondBr )
_method( LLVMBuildSwitch )
@ -1003,8 +1012,11 @@ static PyMethodDef core_methods[] = {
/* Comparisons */
_method( LLVMBuildICmp )
_method( LLVMBuildFCmp )
_method( LLVMBuildVICmp )
_method( LLVMBuildVFCmp )
/* Miscellaneous instructions */
_method( LLVMBuildGetResult )
_method( LLVMBuildPhi )
_method( LLVMBuildCall )
_method( LLVMBuildSelect )

View file

@ -660,6 +660,10 @@ class Constant(Value):
check_is_constant(rhs)
return Constant(_core.LLVMConstSRem(self.ptr, rhs.ptr))
def frem(self, rhs):
check_is_constant(rhs)
return Constant(_core.LLVMConstFRem(self.ptr, rhs.ptr))
def and_(self, rhs):
check_is_constant(rhs)
return Constant(_core.LLVMConstAnd(self.ptr, rhs.ptr))
@ -674,11 +678,19 @@ class Constant(Value):
def icmp(self, int_pred, rhs):
check_is_constant(rhs)
return Constant(_core.LLVMConstICmp(self.ptr, int_pred, rhs.ptr))
return Constant(_core.LLVMConstICmp(int_pred, self.ptr, rhs.ptr))
def fcmp(self, real_pred, rhs):
check_is_constant(rhs)
return Constant(_core.LLVMConstFCmp(self.ptr, real_pred, rhs.ptr))
return Constant(_core.LLVMConstFCmp(real_pred, self.ptr, rhs.ptr))
def vicmp(self, int_pred, rhs):
check_is_constant(rhs)
return Constant(_core.LLVMConstVICmp(int_pred, self.ptr, rhs.ptr))
def vfcmp(self, real_pred, rhs):
check_is_constant(rhs)
return Constant(_core.LLVMConstVFCmp(real_pred, self.ptr, rhs.ptr))
def shl(self, rhs):
check_is_constant(rhs)
@ -749,16 +761,16 @@ class Constant(Value):
check_is_constant(false_const)
return Constant(_core.LLVMConstSelect(self.ptr, true_const.ptr, false_const.ptr))
def extract(self, index): # note: self must be a _vector_ constant
def extract_element(self, index): # note: self must be a _vector_ constant
check_is_constant(index)
return Constant(_core.LLVMConstExtractElement(self.ptr, index.ptr))
def insert(self, value, index): # note: self must be a _vector_ constant
def insert_element(self, value, index): # note: self must be a _vector_ constant
check_is_constant(value)
check_is_constant(index)
return Constant(_core.LLVMConstInsertElement(self.ptr, value.ptr, index.ptr))
def shuffle(self, vector_b, mask): # note: self must be a _vector_ constant
def shuffle_element(self, vector_b, mask): # note: self must be a _vector_ constant
check_is_constant(vector_b) # note: vector_b must be a _vector_ constant
check_is_constant(mask)
return Constant(_core.LLVMConstShuffleVector(self.ptr, vector_b.ptr, mask.ptr))
@ -1035,11 +1047,15 @@ class Builder(object):
def ret_void(self):
return Instruction(_core.LLVMBuildRetVoid(self.ptr))
def ret(self, value):
check_is_value(value)
return Instruction(_core.LLVMBuildRet(self.ptr, value.ptr))
def ret_many(self, values):
vs = unpack_values(values)
return Instruction(_core.LLVMBuildRetMultiple(self.ptr, vs))
def branch(self, bblk):
check_is_basic_block(bblk)
return Instruction(_core.LLVMBuildBr(self.ptr, bblk.ptr))
@ -1265,8 +1281,22 @@ class Builder(object):
check_is_value(rhs)
return Value(_core.LLVMBuildFCmp(self.ptr, rpred, lhs.ptr, rhs.ptr, name))
def vicmp(self, ipred, lhs, rhs, name=""):
check_is_value(lhs)
check_is_value(rhs)
return Value(_core.LLVMBuildVICmp(self.ptr, ipred, lhs.ptr, rhs.ptr, name))
def vfcmp(self, rpred, lhs, rhs, name=""):
check_is_value(lhs)
check_is_value(rhs)
return Value(_core.LLVMBuildVFCmp(self.ptr, rpred, lhs.ptr, rhs.ptr, name))
# misc
def getresult(self, retval, idx, name=""):
check_is_value(retval)
return PHINode(_core.LLVMBuildGetResult(self.ptr, retval.ptr, idx, name))
def phi(self, ty, name=""):
check_is_type(ty)
return PHINode(_core.LLVMBuildPhi(self.ptr, ty.ptr, name))

View file

@ -41,3 +41,45 @@ char *LLVMDumpValueToString(LLVMValueRef Val) {
return strdup(buf.str().c_str());
}
LLVMValueRef LLVMConstVICmp(LLVMIntPredicate Predicate,
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
return wrap(ConstantExpr::getVICmp(Predicate,
unwrap<Constant>(LHSConstant),
unwrap<Constant>(RHSConstant)));
}
LLVMValueRef LLVMConstVFCmp(LLVMRealPredicate Predicate,
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
return wrap(ConstantExpr::getVFCmp(Predicate,
unwrap<Constant>(LHSConstant),
unwrap<Constant>(RHSConstant)));
}
LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef B, LLVMValueRef *Values,
unsigned NumValues) {
std::vector<Value *> Vs;
for (LLVMValueRef *I = Values, *E = Values + NumValues; I != E; ++I)
Vs.push_back(unwrap(*I));
return wrap(unwrap(B)->CreateRet(&Vs[0], NumValues));
}
LLVMValueRef LLVMBuildVICmp(LLVMBuilderRef B, LLVMIntPredicate Op,
LLVMValueRef LHS, LLVMValueRef RHS,
const char *Name) {
return wrap(unwrap(B)->CreateVICmp(static_cast<ICmpInst::Predicate>(Op),
unwrap(LHS), unwrap(RHS), Name));
}
LLVMValueRef LLVMBuildVFCmp(LLVMBuilderRef B, LLVMRealPredicate Op,
LLVMValueRef LHS, LLVMValueRef RHS,
const char *Name) {
return wrap(unwrap(B)->CreateVFCmp(static_cast<FCmpInst::Predicate>(Op),
unwrap(LHS), unwrap(RHS), Name));
}
LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef B, LLVMValueRef V,
unsigned Index, const char *Name) {
return wrap(unwrap(B)->CreateGetResult(unwrap(V), Index, Name));
}

View file

@ -23,6 +23,26 @@ char *LLVMDumpTypeToString(LLVMTypeRef Ty);
LLVMDisposeMessage, after use. */
char *LLVMDumpValueToString(LLVMValueRef Val);
/* missing constant expressions */
LLVMValueRef LLVMConstVICmp(LLVMIntPredicate Predicate,
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
LLVMValueRef LLVMConstVFCmp(LLVMRealPredicate Predicate,
LLVMValueRef LHSConstant, LLVMValueRef RHSConstant);
/* missing instructions */
LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef, LLVMValueRef *Values,
unsigned NumValues);
LLVMValueRef LLVMBuildVICmp(LLVMBuilderRef, LLVMIntPredicate Op,
LLVMValueRef LHS, LLVMValueRef RHS,
const char *Name);
LLVMValueRef LLVMBuildVFCmp(LLVMBuilderRef, LLVMRealPredicate Op,
LLVMValueRef LHS, LLVMValueRef RHS,
const char *Name);
LLVMValueRef LLVMBuildGetResult(LLVMBuilderRef, LLVMValueRef V,
unsigned Index, const char *Name);
#ifdef __cplusplus
} /* extern "C" */
#endif

View file

@ -464,6 +464,29 @@ _w ## func (PyObject *self, PyObject *args) \
}
/**
* Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, int arg3, const char *arg4)
*/
#define _wrap_objobjintstr2obj(func, intype1, intype2, outtype) \
static PyObject * \
_w ## func (PyObject *self, PyObject *args) \
{ \
PyObject *obj1, *obj2; \
intype1 arg1; \
intype2 arg2; \
int arg3; \
const char *arg4; \
\
if (!PyArg_ParseTuple(args, "OOis", &obj1, &obj2, &arg3, &arg4)) \
return NULL; \
\
arg1 = ( intype1 ) PyCObject_AsVoidPtr(obj1); \
arg2 = ( intype2 ) PyCObject_AsVoidPtr(obj2); \
\
return ctor_ ## outtype ( func (arg1, arg2, arg3, arg4)) ;\
}
/**
* Wrap LLVM functions of the type
* outtype func(intype1 arg1, intype2 arg2, intype3 arg3, const char *arg4)