Added instruction properties (is_XXX, opcode, opcode_name)
git-svn-id: http://llvm-py.googlecode.com/svn/trunk@42 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
parent
b873cb8bea
commit
aee33c6612
5 changed files with 108 additions and 5 deletions
25
llvm/_core.c
25
llvm/_core.c
|
|
@ -461,7 +461,18 @@ _wrap_obj2none(LLVMDeleteBasicBlock, LLVMBasicBlockRef)
|
|||
_wrap_obj2obj(LLVMGetInstructionParent, LLVMValueRef, LLVMBasicBlockRef)
|
||||
_wrap_obj2obj(LLVMGetFirstInstruction, LLVMBasicBlockRef, LLVMValueRef)
|
||||
_wrap_obj2obj(LLVMGetNextInstruction, LLVMValueRef, LLVMValueRef)
|
||||
_wrap_obj2obj(LLVMInstIsTerminator, LLVMValueRef, int)
|
||||
_wrap_obj2obj(LLVMInstIsTerminator, LLVMValueRef, int)
|
||||
_wrap_obj2obj(LLVMInstIsBinaryOp, LLVMValueRef, int)
|
||||
_wrap_obj2obj(LLVMInstIsShift, LLVMValueRef, int)
|
||||
_wrap_obj2obj(LLVMInstIsCast, LLVMValueRef, int)
|
||||
_wrap_obj2obj(LLVMInstIsLogicalShift, LLVMValueRef, int)
|
||||
_wrap_obj2obj(LLVMInstIsArithmeticShift, LLVMValueRef, int)
|
||||
_wrap_obj2obj(LLVMInstIsAssociative, LLVMValueRef, int)
|
||||
_wrap_obj2obj(LLVMInstIsCommutative, LLVMValueRef, int)
|
||||
_wrap_obj2obj(LLVMInstIsTrapping, LLVMValueRef, int)
|
||||
_wrap_obj2obj(LLVMInstGetOpcode, LLVMValueRef, int)
|
||||
_wrap_obj2str(LLVMInstGetOpcodeName, LLVMValueRef)
|
||||
|
||||
|
||||
/*===-- Call Sites (Call or Invoke) --------------------------------------===*/
|
||||
|
||||
|
|
@ -1130,7 +1141,17 @@ static PyMethodDef core_methods[] = {
|
|||
_method( LLVMGetInstructionParent )
|
||||
_method( LLVMGetFirstInstruction )
|
||||
_method( LLVMGetNextInstruction )
|
||||
_method( LLVMInstIsTerminator )
|
||||
_method( LLVMInstIsTerminator )
|
||||
_method( LLVMInstIsBinaryOp )
|
||||
_method( LLVMInstIsShift )
|
||||
_method( LLVMInstIsCast )
|
||||
_method( LLVMInstIsLogicalShift )
|
||||
_method( LLVMInstIsArithmeticShift )
|
||||
_method( LLVMInstIsAssociative )
|
||||
_method( LLVMInstIsCommutative )
|
||||
_method( LLVMInstIsTrapping )
|
||||
_method( LLVMInstGetOpcode )
|
||||
_method( LLVMInstGetOpcodeName )
|
||||
|
||||
/* Call Sites (Call or Invoke) */
|
||||
_method( LLVMSetInstructionCallConv )
|
||||
|
|
|
|||
42
llvm/core.py
42
llvm/core.py
|
|
@ -1686,7 +1686,47 @@ class Instruction(Value):
|
|||
|
||||
@property
|
||||
def is_terminator(self):
|
||||
return _core.LLVMInstIsTerminator(self.ptr)
|
||||
return _core.LLVMInstIsTerminator(self.ptr) != 0
|
||||
|
||||
@property
|
||||
def is_binary_op(self):
|
||||
return _core.LLVMInstIsBinaryOp(self.ptr) != 0
|
||||
|
||||
@property
|
||||
def is_shift(self):
|
||||
return _core.LLVMInstIsShift(self.ptr) != 0
|
||||
|
||||
@property
|
||||
def is_cast(self):
|
||||
return _core.LLVMInstIsCast(self.ptr) != 0
|
||||
|
||||
@property
|
||||
def is_logical_shift(self):
|
||||
return _core.LLVMInstIsLogicalShift(self.ptr) != 0
|
||||
|
||||
@property
|
||||
def is_arithmetic_shift(self):
|
||||
return _core.LLVMInstIsArithmeticShift(self.ptr) != 0
|
||||
|
||||
@property
|
||||
def is_associative(self):
|
||||
return _core.LLVMInstIsAssociative(self.ptr) != 0
|
||||
|
||||
@property
|
||||
def is_commutative(self):
|
||||
return _core.LLVMInstIsCommutative(self.ptr) != 0
|
||||
|
||||
@property
|
||||
def is_trapping(self):
|
||||
return _core.LLVMInstIsTrapping(self.ptr) != 0
|
||||
|
||||
@property
|
||||
def opcode(self):
|
||||
return _core.LLVMInstGetOpcode(self.ptr)
|
||||
|
||||
@property
|
||||
def opcode_name(self):
|
||||
return _core.LLVMInstGetOpcodeName(self.ptr)
|
||||
|
||||
|
||||
class CallOrInvokeInstruction(Instruction):
|
||||
|
|
|
|||
|
|
@ -84,8 +84,29 @@ LLVMValueRef LLVMBuildVFCmp(LLVMBuilderRef B, LLVMRealPredicate Op,
|
|||
}
|
||||
#endif
|
||||
|
||||
unsigned LLVMInstIsTerminator(LLVMValueRef I) {
|
||||
return unwrap<Instruction>(I)->isTerminator() ? 1 : 0;
|
||||
#define inst_checkfn(ourfn, llvmfn) \
|
||||
unsigned ourfn (LLVMValueRef I) { \
|
||||
return unwrap<Instruction>(I)-> llvmfn () ? 1 : 0; \
|
||||
}
|
||||
|
||||
inst_checkfn(LLVMInstIsTerminator, isTerminator)
|
||||
inst_checkfn(LLVMInstIsBinaryOp, isBinaryOp)
|
||||
inst_checkfn(LLVMInstIsShift, isShift)
|
||||
inst_checkfn(LLVMInstIsCast, isCast)
|
||||
inst_checkfn(LLVMInstIsLogicalShift,isLogicalShift)
|
||||
inst_checkfn(LLVMInstIsArithmeticShift,isArithmeticShift)
|
||||
inst_checkfn(LLVMInstIsAssociative, isAssociative)
|
||||
inst_checkfn(LLVMInstIsCommutative, isCommutative)
|
||||
inst_checkfn(LLVMInstIsTrapping, isTrapping)
|
||||
|
||||
const char *LLVMInstGetOpcodeName(LLVMValueRef I)
|
||||
{
|
||||
return unwrap<Instruction>(I)->getOpcodeName();
|
||||
}
|
||||
|
||||
unsigned LLVMInstGetOpcode(LLVMValueRef I)
|
||||
{
|
||||
return unwrap<Instruction>(I)->getOpcode();
|
||||
}
|
||||
|
||||
LLVMValueRef LLVMBuildRetMultiple(LLVMBuilderRef B, LLVMValueRef *Values,
|
||||
|
|
|
|||
11
llvm/extra.h
11
llvm/extra.h
|
|
@ -54,6 +54,17 @@ LLVMValueRef LLVMGetIntrinsic(LLVMModuleRef B, int ID,
|
|||
/* instruction */
|
||||
|
||||
unsigned LLVMInstIsTerminator(LLVMValueRef I);
|
||||
unsigned LLVMInstIsBinaryOp(LLVMValueRef I);
|
||||
unsigned LLVMInstIsShift(LLVMValueRef I);
|
||||
unsigned LLVMInstIsCast(LLVMValueRef I);
|
||||
unsigned LLVMInstIsLogicalShift(LLVMValueRef I);
|
||||
unsigned LLVMInstIsArithmeticShift(LLVMValueRef I);
|
||||
unsigned LLVMInstIsAssociative(LLVMValueRef I);
|
||||
unsigned LLVMInstIsCommutative(LLVMValueRef I);
|
||||
unsigned LLVMInstIsTrapping(LLVMValueRef I);
|
||||
|
||||
const char *LLVMInstGetOpcodeName(LLVMValueRef I);
|
||||
unsigned LLVMInstGetOpcode(LLVMValueRef I);
|
||||
|
||||
/* reading llvm "assembly" */
|
||||
|
||||
|
|
|
|||
|
|
@ -411,6 +411,16 @@ def do_builder():
|
|||
i = b.phi(Type.int())
|
||||
i.add_incoming(v, blk)
|
||||
t = i.is_terminator == False
|
||||
t = i.is_binary_op == False
|
||||
t = i.is_shift == False
|
||||
t = i.is_cast == False
|
||||
t = i.is_logical_shift == False
|
||||
t = i.is_arithmetic_shift == False
|
||||
t = i.is_associative == False
|
||||
t = i.is_commutative == False
|
||||
t = i.is_trapping == False
|
||||
t = i.opcode
|
||||
t = i.opcode_name
|
||||
|
||||
|
||||
def do_moduleprovider():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue