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[Lib.Statement.Instru3A | Lib.Statement.Comment], terminator: Lib.Terminator.Return | Lib.Statement.AbsoluteJump | Lib.Terminator.BranchingTerminator)[source]
Bases:
objectA basic block of a
CFGis made of three main parts:a start
labelthat uniquely identifies the block in the CFGthe main body of the block, a list of instructions (excluding labels, jumps and branching instructions)
a
terminatorthat represents the final jump or branching instruction of the block, and points to the successors of the block. See the documentation forLib.Terminator.Terminatorfor further explanations.
- get_body() List[Lib.Statement.Instru3A | Lib.Statement.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_terminator() Lib.Terminator.Return | Lib.Statement.AbsoluteJump | Lib.Terminator.BranchingTerminator[source]
Return the terminator of the block.
- set_terminator(term: Lib.Terminator.Return | Lib.Statement.AbsoluteJump | Lib.Terminator.BranchingTerminator) None[source]
Set the terminator of the block.
- iter_statements(f) None[source]
Iterate over instructions. For each real instruction i (not label or comment), replace it with the list of instructions given by f(i).
Assume there is no phi-node.
- add_instruction(instr: Lib.Statement.Instru3A | Lib.Statement.Comment) None[source]
Add an instruction to the body of the block.
- class Lib.CFG.CFG(fdata: FunctionData)[source]
Bases:
objectA 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
fdatamember variable.- fdata: FunctionData
Metadata about the function represented by this CFG
- 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.