Added User class, moved operands to User, cleanup
git-svn-id: http://llvm-py.googlecode.com/svn/trunk@69 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
parent
10843ec2ec
commit
8b6109d8eb
7 changed files with 144 additions and 154 deletions
139
llvm/core.py
139
llvm/core.py
|
|
@ -329,6 +329,7 @@ class Module(llvm.Ownable, llvm.Cacheable):
|
|||
Use the static method `Module.new' instead.
|
||||
"""
|
||||
llvm.Ownable.__init__(self, ptr, _core.LLVMDisposeModule)
|
||||
llvm.Cacheable.__init__(self, ptr)
|
||||
|
||||
def __str__(self):
|
||||
"""Text representation of a module.
|
||||
|
|
@ -666,12 +667,6 @@ class Type(object):
|
|||
class IntegerType(Type):
|
||||
"""Represents an integer type."""
|
||||
|
||||
def __init__(self, ptr, kind):
|
||||
"""DO NOT CALL DIRECTLY.
|
||||
|
||||
Use one of the static methods of the *base* class (Type) instead."""
|
||||
Type.__init__(self, ptr, kind)
|
||||
|
||||
@property
|
||||
def width(self):
|
||||
"""The width of the integer type, in bits."""
|
||||
|
|
@ -681,12 +676,6 @@ class IntegerType(Type):
|
|||
class FunctionType(Type):
|
||||
"""Represents a function type."""
|
||||
|
||||
def __init__(self, ptr, kind):
|
||||
"""DO NOT CALL DIRECTLY.
|
||||
|
||||
Use one of the static methods of the *base* class (Type) instead."""
|
||||
Type.__init__(self, ptr, kind)
|
||||
|
||||
@property
|
||||
def return_type(self):
|
||||
"""The type of the value returned by this function."""
|
||||
|
|
@ -717,12 +706,6 @@ class FunctionType(Type):
|
|||
class StructType(Type):
|
||||
"""Represents a structure type."""
|
||||
|
||||
def __init__(self, ptr, kind):
|
||||
"""DO NOT CALL DIRECTLY.
|
||||
|
||||
Use one of the static methods of the *base* class (Type) instead."""
|
||||
Type.__init__(self, ptr, kind)
|
||||
|
||||
@property
|
||||
def element_count(self):
|
||||
"""Number of elements (members) in the structure.
|
||||
|
|
@ -746,12 +729,6 @@ class StructType(Type):
|
|||
class ArrayType(Type):
|
||||
"""Represents an array type."""
|
||||
|
||||
def __init__(self, ptr, kind):
|
||||
"""DO NOT CALL DIRECTLY.
|
||||
|
||||
Use one of the static methods of the *base* class (Type) instead."""
|
||||
Type.__init__(self, ptr, kind)
|
||||
|
||||
@property
|
||||
def element(self):
|
||||
ptr = _core.LLVMGetElementType(self.ptr)
|
||||
|
|
@ -765,12 +742,6 @@ class ArrayType(Type):
|
|||
|
||||
class PointerType(Type):
|
||||
|
||||
def __init__(self, ptr, kind):
|
||||
"""DO NOT CALL DIRECTLY.
|
||||
|
||||
Use one of the static methods of the *base* class (Type) instead."""
|
||||
Type.__init__(self, ptr, kind)
|
||||
|
||||
@property
|
||||
def pointee(self):
|
||||
ptr = _core.LLVMGetElementType(self.ptr)
|
||||
|
|
@ -784,12 +755,6 @@ class PointerType(Type):
|
|||
|
||||
class VectorType(Type):
|
||||
|
||||
def __init__(self, ptr, kind):
|
||||
"""DO NOT CALL DIRECTLY.
|
||||
|
||||
Use one of the static methods of the *base* class (Type) instead."""
|
||||
Type.__init__(self, ptr, kind)
|
||||
|
||||
@property
|
||||
def element(self):
|
||||
ptr = _core.LLVMGetElementType(self.ptr)
|
||||
|
|
@ -854,6 +819,7 @@ class TypeHandle(object):
|
|||
class Value(llvm.Cacheable):
|
||||
|
||||
def __init__(self, ptr):
|
||||
llvm.Cacheable.__init__(self, ptr)
|
||||
self.ptr = ptr
|
||||
|
||||
def __str__(self):
|
||||
|
|
@ -887,7 +853,22 @@ class Value(llvm.Cacheable):
|
|||
return _make_type(ptr, kind)
|
||||
|
||||
|
||||
class Constant(Value):
|
||||
class User(Value):
|
||||
|
||||
@property
|
||||
def operand_count(self):
|
||||
return _core.LLVMUserGetNumOperands(self.ptr)
|
||||
|
||||
@property
|
||||
def operands(self):
|
||||
"""Yields operands of this instruction."""
|
||||
return [self._get_operand(i) for i in range(self.operand_count)]
|
||||
|
||||
def _get_operand(self, i):
|
||||
return _make_value(_core.LLVMUserGetOperand(self.ptr, i))
|
||||
|
||||
|
||||
class Constant(User):
|
||||
|
||||
@staticmethod
|
||||
def null(ty):
|
||||
|
|
@ -956,9 +937,6 @@ class Constant(Value):
|
|||
check_is_type(ty)
|
||||
return _make_value(_core.LLVMSizeOf(ty.ptr))
|
||||
|
||||
def __init__(self, ptr):
|
||||
Value.__init__(self, ptr)
|
||||
|
||||
def neg(self):
|
||||
return _make_value(_core.LLVMConstNeg(self.ptr))
|
||||
|
||||
|
|
@ -1121,51 +1099,39 @@ class Constant(Value):
|
|||
|
||||
|
||||
class ConstantExpr(Constant):
|
||||
|
||||
def __init__(self, ptr):
|
||||
Constant.__init__(self, ptr)
|
||||
pass
|
||||
|
||||
|
||||
class ConstantAggregateZero(Constant):
|
||||
|
||||
def __init__(self, ptr):
|
||||
Constant.__init__(self, ptr)
|
||||
pass
|
||||
|
||||
|
||||
class ConstantInt(Constant):
|
||||
|
||||
def __init__(self, ptr):
|
||||
Constant.__init__(self, ptr)
|
||||
pass
|
||||
|
||||
|
||||
class ConstantFP(Constant):
|
||||
|
||||
def __init__(self, ptr):
|
||||
Constant.__init__(self, ptr)
|
||||
pass
|
||||
|
||||
|
||||
class ConstantArray(Constant):
|
||||
|
||||
def __init__(self, ptr):
|
||||
Constant.__init__(self, ptr)
|
||||
pass
|
||||
|
||||
|
||||
class ConstantStruct(Constant):
|
||||
|
||||
def __init__(self, ptr):
|
||||
Constant.__init__(self, ptr)
|
||||
pass
|
||||
|
||||
|
||||
class ConstantVector(Constant):
|
||||
|
||||
def __init__(self, ptr):
|
||||
Constant.__init__(self, ptr)
|
||||
pass
|
||||
|
||||
|
||||
class ConstantPointerNull(Constant):
|
||||
pass
|
||||
|
||||
def __init__(self, ptr):
|
||||
Constant.__init__(self, ptr)
|
||||
|
||||
class UndefValue(Constant):
|
||||
pass
|
||||
|
||||
|
||||
class GlobalValue(Constant):
|
||||
|
|
@ -1228,9 +1194,6 @@ class GlobalVariable(GlobalValue):
|
|||
raise llvm.LLVMException, ("no global named `%s`" % name)
|
||||
return _make_value(ptr)
|
||||
|
||||
def __init__(self, ptr):
|
||||
GlobalValue.__init__(self, ptr)
|
||||
|
||||
def delete(self):
|
||||
self._delete()
|
||||
_core.LLVMDeleteGlobal(self.ptr)
|
||||
|
|
@ -1262,9 +1225,6 @@ class GlobalVariable(GlobalValue):
|
|||
|
||||
class Argument(Value):
|
||||
|
||||
def __init__(self, ptr):
|
||||
Value.__init__(self, ptr)
|
||||
|
||||
def add_attribute(self, attr):
|
||||
_core.LLVMAddAttribute(self.ptr, attr)
|
||||
|
||||
|
|
@ -1306,9 +1266,6 @@ class Function(GlobalValue):
|
|||
return _make_value(
|
||||
_core.LLVMGetIntrinsic(module.ptr, intrinsic_id, ptrs))
|
||||
|
||||
def __init__(self, ptr):
|
||||
GlobalValue.__init__(self, ptr)
|
||||
|
||||
def delete(self):
|
||||
self._delete()
|
||||
_core.LLVMDeleteFunction(self.ptr)
|
||||
|
|
@ -1336,11 +1293,16 @@ class Function(GlobalValue):
|
|||
def basic_block_count(self):
|
||||
return _core.LLVMCountBasicBlocks(self.ptr)
|
||||
|
||||
def get_entry_basic_block(self):
|
||||
@property
|
||||
def entry_basic_block(self):
|
||||
if self.basic_block_count == 0:
|
||||
return None
|
||||
return _make_value(_core.LLVMGetEntryBasicBlock(self.ptr))
|
||||
|
||||
def get_entry_basic_block(self):
|
||||
"""Deprecated, use entry_basic_block property."""
|
||||
return self.entry_basic_block
|
||||
|
||||
def append_basic_block(self, name):
|
||||
return _make_value(_core.LLVMAppendBasicBlock(self.ptr, name))
|
||||
|
||||
|
|
@ -1365,10 +1327,7 @@ class Function(GlobalValue):
|
|||
# Instruction
|
||||
#===----------------------------------------------------------------------===
|
||||
|
||||
class Instruction(Value):
|
||||
|
||||
def __init__(self, ptr):
|
||||
Value.__init__(self, ptr)
|
||||
class Instruction(User):
|
||||
|
||||
@property
|
||||
def basic_block(self):
|
||||
|
|
@ -1423,24 +1382,9 @@ class Instruction(Value):
|
|||
def opcode_name(self):
|
||||
return _core.LLVMInstGetOpcodeName(self.ptr)
|
||||
|
||||
@property
|
||||
def operand_count(self):
|
||||
return _core.LLVMInstGetNumOperands(self.ptr)
|
||||
|
||||
@property
|
||||
def operands(self):
|
||||
"""Yields operands of this instruction."""
|
||||
return [self._get_operand(i) for i in range(self.operand_count)]
|
||||
|
||||
def _get_operand(self, i):
|
||||
return _make_value(_core.LLVMInstGetOperand(self.ptr, i))
|
||||
|
||||
|
||||
class CallOrInvokeInstruction(Instruction):
|
||||
|
||||
def __init__(self, ptr):
|
||||
Instruction.__init__(self, ptr)
|
||||
|
||||
def _get_cc(self): return _core.LLVMGetInstructionCallConv(self.ptr)
|
||||
def _set_cc(self, value): _core.LLVMSetInstructionCallConv(self.ptr, value)
|
||||
calling_convention = property(_get_cc, _set_cc)
|
||||
|
|
@ -1457,9 +1401,6 @@ class CallOrInvokeInstruction(Instruction):
|
|||
|
||||
class PHINode(Instruction):
|
||||
|
||||
def __init__(self, ptr):
|
||||
Instruction.__init__(self, ptr)
|
||||
|
||||
@property
|
||||
def incoming_count(self):
|
||||
return _core.LLVMCountIncoming(self.ptr)
|
||||
|
|
@ -1478,9 +1419,6 @@ class PHINode(Instruction):
|
|||
|
||||
class SwitchInstruction(Instruction):
|
||||
|
||||
def __init__(self, ptr):
|
||||
Instruction.__init__(self, ptr)
|
||||
|
||||
def add_case(self, const, bblk):
|
||||
check_is_constant(const) # and has to be an int too
|
||||
check_is_basic_block(bblk)
|
||||
|
|
@ -1493,9 +1431,6 @@ class SwitchInstruction(Instruction):
|
|||
|
||||
class BasicBlock(Value):
|
||||
|
||||
def __init__(self, ptr):
|
||||
Value.__init__(self, ptr)
|
||||
|
||||
def insert_before(self, name):
|
||||
return _make_value(_core.LLVMInsertBasicBlock(self.ptr, name))
|
||||
|
||||
|
|
@ -1526,8 +1461,8 @@ __class_for_valueid = {
|
|||
VALUE_FUNCTION : Function,
|
||||
VALUE_GLOBAL_ALIAS : GlobalValue,
|
||||
VALUE_GLOBAL_VARIABLE : GlobalVariable,
|
||||
VALUE_UNDEF_VALUE : UndefValue,
|
||||
VALUE_CONSTANT_EXPR : ConstantExpr,
|
||||
VALUE_INLINE_ASM : Constant,
|
||||
VALUE_CONSTANT_AGGREGATE_ZERO : ConstantAggregateZero,
|
||||
VALUE_CONSTANT_INT : ConstantInt,
|
||||
VALUE_CONSTANT_FP : ConstantFP,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue