class documentation

class BasicBlock(object): (source)

View In Hierarchy

A basic block in a control flow graph.

All instructions (generally, AST nodes) in a basic block are either executed or none are (with the exception of blocks interrupted by exceptions). These instructions are executed in a straight-line manner.

Method __init__ Undocumented
Method add_exit Adds an exit from this block to block.
Method add_instruction Undocumented
Method can_merge Undocumented
Method can_prune Undocumented
Method compact Undocumented
Method exits_to Whether this block exits to block.
Method get_label Gets the value of a label on the BasicBlock.
Method has_label Returns whether this BasicBlock has the specified label.
Method index_of Returns the index of the Instruction in this BasicBlock.
Method is_empty Whether this block is empty.
Method merge Merge this block with its one successor.
Method prune Prunes the empty block from its control flow graph.
Method raises_to Whether this block exits to block in the case of an exception.
Method remove_exit Removes the exit from this block to block.
Method set_label Sets the value of a label on the BasicBlock.
Instance Variable branches A map from booleans to the basic block reachable by making the branch decision indicated by that boolean.
Instance Variable control_flow_node_indexes Maps from id(control_flow_node) to the ControlFlowNode's index in self.control_flow_nodes. Only available once the block is compacted.
Instance Variable control_flow_nodes A list of the ControlFlowNodes contained in this basic block. Each ControlFlowNode corresponds to a single Instruction.
Instance Variable except_branches Undocumented
Instance Variable exits_from_end These basic blocks may only be exited to at the end of the execution of this basic block.
Instance Variable exits_from_middle These basic blocks may be exited to at any point during the execution of this basic block.
Instance Variable graph The control flow graph which this basic block is a part of.
Instance Variable identities A list of (node, label) pairs that refer to this basic block. This starts as (self.node, self.label), but old identities are preserved during merging and pruning. Allows lookup of blocks by node and label, e...
Instance Variable label A label for the basic block.
Instance Variable labels Labels, used for example by data flow analyses. Maps from label name to value.
Instance Variable next Indicates which basic blocks may be executed after this basic block.
Instance Variable node The AST node this basic block is associated with.
Instance Variable prev Indicates which basic blocks may lead to the execution of this basic block in a Python program.
Instance Variable prunable Whether this basic block may be pruned from the control flow graph if empty. Set to False for special blocks, such as enter and exit blocks.
Instance Variable reraise_branches Undocumented
def __init__(self, node=None, label=None, prunable=True): (source)

Undocumented

def add_exit(self, block, interrupting=False, branch=None, except_branch=None, reraise_branch=None): (source)

Adds an exit from this block to block.

def add_instruction(self, instruction): (source)

Undocumented

def can_merge(self): (source)

Undocumented

def can_prune(self): (source)

Undocumented

def compact(self): (source)

Undocumented

def exits_to(self, block): (source)

Whether this block exits to block.

def get_label(self, label): (source)

Gets the value of a label on the BasicBlock.

def has_label(self, label): (source)

Returns whether this BasicBlock has the specified label.

def index_of(self, control_flow_node): (source)

Returns the index of the Instruction in this BasicBlock.

def is_empty(self): (source)

Whether this block is empty.

def merge(self): (source)

Merge this block with its one successor.

Returns
The successor block removed by the merge operation.
def prune(self): (source)

Prunes the empty block from its control flow graph.

A block is prunable if it has no control flow nodes and has not been marked as unprunable (e.g. because it's the exit block, or a return block, etc).

Returns
The block removed by the prune operation. That is, self.
def raises_to(self, block): (source)

Whether this block exits to block in the case of an exception.

def remove_exit(self, block): (source)

Removes the exit from this block to block.

def set_label(self, label, value): (source)

Sets the value of a label on the BasicBlock.

branches: dict = (source)

A map from booleans to the basic block reachable by making the branch decision indicated by that boolean.

control_flow_node_indexes: dict = (source)

Maps from id(control_flow_node) to the ControlFlowNode's index in self.control_flow_nodes. Only available once the block is compacted.

control_flow_nodes: list = (source)

A list of the ControlFlowNodes contained in this basic block. Each ControlFlowNode corresponds to a single Instruction.

except_branches: dict = (source)

Undocumented

exits_from_end = (source)

These basic blocks may only be exited to at the end of the execution of this basic block.

exits_from_middle = (source)

These basic blocks may be exited to at any point during the execution of this basic block.

The control flow graph which this basic block is a part of.

identities = (source)

A list of (node, label) pairs that refer to this basic block. This starts as (self.node, self.label), but old identities are preserved during merging and pruning. Allows lookup of blocks by node and label, e.g. for finding the after block of a particular if statement.

A label for the basic block.

Labels, used for example by data flow analyses. Maps from label name to value.

Indicates which basic blocks may be executed after this basic block.

The AST node this basic block is associated with.

Indicates which basic blocks may lead to the execution of this basic block in a Python program.

prunable = (source)

Whether this basic block may be pruned from the control flow graph if empty. Set to False for special blocks, such as enter and exit blocks.

reraise_branches: dict = (source)

Undocumented