Documentation
¶
Overview ¶
Package block provides the Analyser interface for blocks and supporting utils.
Index ¶
- Variables
- func TraverseEdges(fn *ssa.Function, visit func(from, to *ssa.BasicBlock))
- type Analyser
- type VisitGraph
- func (g *VisitGraph) EdgeVisited(from, to *VisitNode) bool
- func (g *VisitGraph) LastNode() *VisitNode
- func (g *VisitGraph) MarkLast(n *VisitNode)
- func (g *VisitGraph) NodePartialVisited(toVisit *VisitNode) bool
- func (g *VisitGraph) NodeVisited(toVisit *VisitNode) bool
- func (g *VisitGraph) Size() int
- func (g *VisitGraph) Visit(n *VisitNode)
- func (g *VisitGraph) VisitFrom(prev, n *VisitNode)
- func (g *VisitGraph) VisitedOnce(toVisit *VisitNode) bool
- type VisitNode
Constants ¶
This section is empty.
Variables ¶
var ( ErrEdgesStackEmpty = errors.New("blockgraph: cannot pop edges: stack empty") ErrBadNode = errors.New("VisitNode does not contain block (or has nil block)") ErrBadBlock = errors.New("internal error: Block is nil") ErrBadParentFn = errors.New("internal error: Block has nil parent Fn") )
Functions ¶
func TraverseEdges ¶
func TraverseEdges(fn *ssa.Function, visit func(from, to *ssa.BasicBlock))
TraverseEdges takes a Function and apply visit to each edge.
Types ¶
type Analyser ¶
type Analyser interface { // EnterBlk analyses a block where there is no predecessor or just follow // the natural order, // e.g. the first block in a Function, or the direct predecessor. EnterBlk(blk *ssa.BasicBlock) // JumpBlk analyses a block where the predecessor is specified explicitly, // where the transfer of control may impact the control flow directly. JumpBlk(curr, next *ssa.BasicBlock) // ExitBlk analyses a terminating block where there are no successors, this // should be called when marking a block an end. // Typically this is called in the end of a block where it was entered via // EnterBlk or JumpBlk, so blk should not be "visited". ExitBlk(blk *ssa.BasicBlock) // CurrBlk returns the current block (last block entered). CurrBlk() *ssa.BasicBlock // PrevBlk() returns the previous block (last block exited). PrevBlk() *ssa.BasicBlock }
Analyser is an interface for BasicBlock analysis, handles block transitions within functions.
type VisitGraph ¶
VisitGraph is a data structure to track the control flow of execution within functions. Each node is the ssa.BasicBlock that the analysis has previously visited.
VisitGraph, unlike the name suggests, is a doubly linked list. Traversing the VisitGraph is equivalent to going through the analysis.
func NewVisitGraph ¶
func NewVisitGraph(reentrant bool) *VisitGraph
NewVisitGraph returns a new VisitGraph.
func (*VisitGraph) EdgeVisited ¶
func (g *VisitGraph) EdgeVisited(from, to *VisitNode) bool
EdgeVisited returns true if the edge between the node pair has been visited.
func (*VisitGraph) LastNode ¶
func (g *VisitGraph) LastNode() *VisitNode
LastNode returns the last node in the VisitGraph.
func (*VisitGraph) MarkLast ¶
func (g *VisitGraph) MarkLast(n *VisitNode)
MarkLast marks a block that has no successor VisitNode.
The function has no effect in a non-reentrant VisitGraph.
This assumes that the VisitNode n will not be added to the VisitGraph (because it is already visited). The reason this is separated from a Visit (which can inspect the Block and mark as 'Last') is to allow for MarkLast to be called in a defer.
func (*VisitGraph) NodePartialVisited ¶
func (g *VisitGraph) NodePartialVisited(toVisit *VisitNode) bool
NodePartialVisited returns false if a block has been Visit()'ed at least once, otherwise true.
func (*VisitGraph) NodeVisited ¶
func (g *VisitGraph) NodeVisited(toVisit *VisitNode) bool
NodeVisited returns true if the block is visited. A block is visited if all the in edges are visited.
func (*VisitGraph) Visit ¶
func (g *VisitGraph) Visit(n *VisitNode)
Visit enters a new BasicBlock, which adds a new VisitNode to the end of the VisitGraph.
If the current new BasicBlock is not node 0 (entry), it is assumed that the immediate predecessor of the block is the last VisitNode in the VisitGraph.
func (*VisitGraph) VisitFrom ¶
func (g *VisitGraph) VisitFrom(prev, n *VisitNode)
VisitFrom is the Visit function for non-linear visits.
Param prev is not modified or stored, and is used for looking up the previous BasicBlock Index. However, prev must be visited before.
func (*VisitGraph) VisitedOnce ¶
func (g *VisitGraph) VisitedOnce(toVisit *VisitNode) bool
VisitedOnce returns true if the block is visited at least once.
type VisitNode ¶
type VisitNode struct {
Prev, Next *VisitNode
// contains filtered or unexported fields
}
VisitNode is one node in the VisitGraph. Each VisitNode corresponds to one ssa.BasicBlock.
func NewVisitNode ¶
func NewVisitNode(block *ssa.BasicBlock) *VisitNode
NewVisitNode reutrns a new VisitNode.
func (*VisitNode) Blk ¶
func (n *VisitNode) Blk() *ssa.BasicBlock
Blk returns the underlying BasicBlock.