Lib.CFG module
Classes for a RiscV CFG: CFG
for the CFG itself,
and Block
for its basic blocks.
- class Lib.CFG.Block(label: Label, insts: List[Instru3A | Comment], terminator: Return | AbsoluteJump | BranchingTerminator)[source]
Bases:
object
A basic block of a
CFG
is made of three main parts:a start
label
that uniquely identifies the block in the CFGthe main body of the block, a list of instructions (excluding labels, jumps and branching instructions)
a
terminator
that represents the final jump or branching instruction of the block, and points to the successors of the block. See the documentation forLib.Terminator.Terminator
for further explanations.
- get_body() List[Instru3A | Comment] [source]
Return the statements in the body of the block (no phi-node nor the terminator).
- get_all_statements() List[Statement] [source]
Return all statements of the block (including phi-nodes and the terminator, but not the label of the block).
- get_body_and_terminator() List[Statement] [source]
Return all statements of the block, except phi-nodes (and the label of the block).
- get_terminator() Return | AbsoluteJump | BranchingTerminator [source]
Return the terminator of the block.
- set_terminator(term: Return | AbsoluteJump | BranchingTerminator) None [source]
Set the terminator of the block.
- set_phis(phis: List[Statement]) None [source]
Replace the φ instructions in the block by the given list phis.
- class Lib.CFG.CFG(fdata: FunctionData)[source]
Bases:
object
A complete control-flow graph representing a function. This class is mainly made of a list of basic
Block
, a label indicating theentry point of the function
, and anexit label
.As with linear code, metadata about the function can be found in the
fdata
member variable.- fdata: FunctionData
Metadata about the function represented by this CFG
- add_edge(src: Block, dest: Block) None [source]
Add the edge src -> dest in the control flow graph.
- remove_edge(src: Block, dest: Block) None [source]
Remove the edge src -> dest in the control flow graph.
- out_blocks(block: Block) List[Block] [source]
Return the list of blocks in the CFG targeted by the Terminator of Block block.
- gather_defs() Dict[Any, Set[Block]] [source]
Return a dictionary associating variables to all the blocks containing one of their definitions.
- linearize_naive() Iterator[Statement] [source]
Linearize the given control flow graph as a list of instructions. Naive procedure that adds jumps everywhere.