equip.analysis package

Submodules

equip.analysis.block

Basic block for the bytecode.

copyright:
  1. 2014 by Romain Gaucher (@rgaucher)
license:

Apache 2, see LICENSE for more details.

class equip.analysis.block.BasicBlock(kind, decl, index)[source]

Bases: object

Represents a basic block from the bytecode.

ENTRY = 1
EXCEPT = 6
IF = 5
IMPLICIT_RETURN = 2
LOOP = 4
UNKNOWN = 3
add_jump(jump_index, branch_kind)[source]
clear_jumps()[source]
decl
end_target
fallthrough
has_return_path
index
jumps
kind
length

equip.analysis.flow

Extract the control flow graphs from the bytecode.

copyright:
  1. 2014 by Romain Gaucher (@rgaucher)
license:

Apache 2, see LICENSE for more details.

class equip.analysis.flow.ControlFlow(decl)[source]

Bases: object

Performs the control-flow analysis on a Declaration object. It iterates over its bytecode and builds the basic block. The final representation leverages the DiGraph structure, and contains an instance of the DominatorTree.

BLOCK_NODE_KIND = {1: 'ENTRY', 2: 'IMPLICIT_RETURN', 3: 'UNKNOWN', 4: 'LOOP', 5: 'IF', 6: 'EXCEPT'}
CFG_TMP_BREAK = -2
CFG_TMP_RAISE = -3
CFG_TMP_RETURN = -1
E_COND = 'COND'
E_END_LOOP = 'END_LOOP'
E_EXCEPT = 'EXCEPT'
E_FALSE = 'FALSE'
E_FINALLY = 'FINALLY'
E_RAISE = 'RAISE'
E_RETURN = 'RETURN'
E_TRUE = 'TRUE'
E_UNCOND = 'UNCOND'
N_CONDITION = 'CONDITION'
N_ENTRY = 'ENTRY'
N_EXCEPT = 'EXCEPT'
N_IF = 'IF'
N_IMPLICIT_RETURN = 'IMPLICIT_RETURN'
N_LOOP = 'LOOP'
N_UNKNOWN = 'UNKNOWN'
analyze()[source]

Performs the CFA and stores the resulting CFG.

block_indices_dict

Returns the mapping of a bytecode indices and a basic blocks.

static block_kind_from_op(op)[source]
block_nodes_dict

Returns the mapping of a basic bocks and CFG nodes.

blocks

Returns the basic blocks created during the control flow analysis.

decl
dominators
Returns the DominatorTree that contains:
  • Dominator tree (dict of IDom)
  • Post dominator tree (doc of PIDom)
  • Dominance frontier (dict of CFG node -> set CFG nodes)
entry
entry_node
exit
exit_node
static find_targets(bytecode)[source]
frames
static get_kind_from_block(block)[source]
static get_pairs(iterable)[source]
graph

Returns the underlying graph that holds the CFG.

static make_blocks(decl, bytecode)[source]

Returns the set of BasicBlock that are encountered in the current bytecode. Each block is annotated with its qualified jump targets (if any).

Parameters:
  • decl – The current declaration object.
  • bytecode – The bytecode associated with the declaration object.

Module contents

equip.analysis

Operators and simple algorithms to perform analysis on the bytecode.

copyright:
  1. 2014 by Romain Gaucher (@rgaucher)
license:

Apache 2, see LICENSE for more details.