+class Function(Value):
+
+ def __init__(self, value):
+ Value.__init__(self, value)
+
+ @property
+ def next(self):
+ f = lib.LLVMGetNextFunction(self)
+ return f and Function(f)
+
+ @property
+ def prev(self):
+ f = lib.LLVMGetPreviousFunction(self)
+ return f and Function(f)
+
+ @property
+ def first(self):
+ b = lib.LLVMGetFirstBasicBlock(self)
+ return b and BasicBlock(b)
+
+ @property
+ def last(self):
+ b = lib.LLVMGetLastBasicBlock(self)
+ return b and BasicBlock(b)
+
+ class __bb_iterator(object):
+ def __init__(self, function, reverse=False):
+ self.function = function
+ self.reverse = reverse
+ if self.reverse:
+ self.bb = function.last
+ else:
+ self.bb = function.first
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ if not isinstance(self.bb, BasicBlock):
+ raise StopIteration("")
+ result = self.bb
+ if self.reverse:
+ self.bb = self.bb.prev
+ else:
+ self.bb = self.bb.next
+ return result
+
+ def __iter__(self):
+ return Function.__bb_iterator(self)
+
+ def __reversed__(self):
+ return Function.__bb_iterator(self, reverse=True)
+
+ def __len__(self):
+ return lib.LLVMCountBasicBlocks(self)
+
+class BasicBlock(LLVMObject):
+
+ def __init__(self, value):
+ LLVMObject.__init__(self, value)
+
+ @property
+ def next(self):
+ b = lib.LLVMGetNextBasicBlock(self)
+ return b and BasicBlock(b)
+
+ @property
+ def prev(self):
+ b = lib.LLVMGetPreviousBasicBlock(self)
+ return b and BasicBlock(b)
+
+ @property
+ def first(self):
+ i = lib.LLVMGetFirstInstruction(self)
+ return i and Instruction(i)
+
+ @property
+ def last(self):
+ i = lib.LLVMGetLastInstruction(self)
+ return i and Instruction(i)
+
+ def __as_value(self):
+ return Value(lib.LLVMBasicBlockAsValue(self))
+
+ @property
+ def name(self):
+ return lib.LLVMGetValueName(self.__as_value())
+
+ def dump(self):
+ lib.LLVMDumpValue(self.__as_value())
+
+ def get_operand(self, i):
+ return Value(lib.LLVMGetOperand(self.__as_value(),
+ i))
+
+ def set_operand(self, i, v):
+ return lib.LLVMSetOperand(self.__as_value(),
+ i, v)
+
+ def __len__(self):
+ return lib.LLVMGetNumOperands(self.__as_value())
+
+ class __inst_iterator(object):
+ def __init__(self, bb, reverse=False):
+ self.bb = bb
+ self.reverse = reverse
+ if self.reverse:
+ self.inst = self.bb.last
+ else:
+ self.inst = self.bb.first
+
+ def __iter__(self):
+ return self
+
+ def next(self):
+ if not isinstance(self.inst, Instruction):
+ raise StopIteration("")
+ result = self.inst
+ if self.reverse:
+ self.inst = self.inst.prev
+ else:
+ self.inst = self.inst.next
+ return result
+
+ def __iter__(self):
+ return BasicBlock.__inst_iterator(self)
+
+ def __reversed__(self):
+ return BasicBlock.__inst_iterator(self, reverse=True)
+
+
+class Instruction(Value):
+
+ def __init__(self, value):
+ Value.__init__(self, value)
+
+ @property
+ def next(self):
+ i = lib.LLVMGetNextInstruction(self)
+ return i and Instruction(i)
+
+ @property
+ def prev(self):
+ i = lib.LLVMGetPreviousInstruction(self)
+ return i and Instruction(i)
+
+ @property
+ def opcode(self):
+ return OpCode.from_value(lib.LLVMGetInstructionOpcode(self))
+