block

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2019 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package block provides the Analyser interface for blocks and supporting utils.

Index

Constants

This section is empty.

Variables

View Source
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

type VisitGraph struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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) Size

func (g *VisitGraph) Size() int

Size of the graph.

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.

func (*VisitNode) Fn

func (n *VisitNode) Fn() *ssa.Function

Fn returns the function which the block belongs to.

func (*VisitNode) Index

func (n *VisitNode) Index() int

Index returns the block index.

func (*VisitNode) String

func (n *VisitNode) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL