cfg

package
v0.0.0-...-c695042 Latest Latest
Warning

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

Go to latest
Published: May 12, 2022 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyAllGraph

func ApplyAllGraph(graph *Graph, meta *transform.Meta, visitors []TransformGenerator)

ApplyAllGraph applies a list of transforms to a CFG graph.

Types

type Branch

type Branch struct {
	Cond     ast.Expr
	SuccIf   int
	SuccElse int
	// contains filtered or unexported fields
}

Branch is a branching (ifelse, switch, for).

func (*Branch) Index

func (n *Branch) Index() int

Index see Node.Index.

func (*Branch) SetIndex

func (n *Branch) SetIndex(idx int)

SetIndex see Node.SetIndex

func (*Branch) Succs

func (n *Branch) Succs() []int

Succs see Node.Succs.

type EliminateCallExprStmt

type EliminateCallExprStmt struct {
}

EliminateCallExprStmt visitor type.

func (EliminateCallExprStmt) Post

Post traversal does nothing.

func (EliminateCallExprStmt) Pre

Pre traversal applies the transformation.

type Empty

type Empty struct {
	// contains filtered or unexported fields
}

Empty is the final node in the graph. It has no successors.

func (*Empty) Index

func (n *Empty) Index() int

Index see Node.Index

func (*Empty) SetIndex

func (n *Empty) SetIndex(idx int)

SetIndex see Node.SetIndex

func (Empty) Succs

func (Empty) Succs() []int

Succs see Node.Succs.

type FunctionCalls

type FunctionCalls struct {
	// contains filtered or unexported fields
}

FunctionCalls visitor type.

func (*FunctionCalls) Post

func (t *FunctionCalls) Post(meta *transform.Meta, v *transform.Visitor) bool

Post traversal applies the transformation.

func (*FunctionCalls) Pre

func (t *FunctionCalls) Pre(meta *transform.Meta, v *transform.Visitor) bool

Pre traversal does nothing.

type Graph

type Graph struct {
	Nodes []Node
}

Graph of instructions.

func Build

func Build(meta *transform.Meta, block *ast.BlockStmt) *Graph

Build builds a CFG from a block statement.

func (*Graph) NewNode

func (g *Graph) NewNode(stmt ast.Stmt, succ int) *Single

NewNode creates a Single node with the provided statement and successor.

func (*Graph) Swap

func (g *Graph) Swap(nodeA, nodeB Node)

Swap two nodes. The predecessors of `nodeA` will now be the predecessors of `nodeB`, and vice-versa.

type LinkResults

type LinkResults struct {
}

LinkResults visitor type.

func (LinkResults) Post

func (LinkResults) Post(meta *transform.Meta, v *transform.Visitor) bool

Post traversal does nothing.

func (LinkResults) Pre

Pre traversal applies the transformation.

type Node

type Node interface {
	// Succs returns all the successors of the node.
	Succs() []int
	// Index returns the index of the node inside of the graph's node array.
	Index() int
	// SetIndex updates the index of the node.
	SetIndex(int)
}

Node represents a node of the graph, with between 0 to 2 successors.

type Single

type Single struct {
	Stmt ast.Stmt
	Succ int
	// contains filtered or unexported fields
}

Single is a node that represents a single state transition.

func (*Single) Index

func (n *Single) Index() int

Index see Node.Index.

func (*Single) SetIndex

func (n *Single) SetIndex(idx int)

SetIndex see Node.SetIndex

func (*Single) Succs

func (n *Single) Succs() []int

Succs see Node.Succs.

type Transform

type Transform struct {
}

Transform visitor type, stateless.

func (Transform) Post

func (Transform) Post(meta *transform.Meta, v *transform.Visitor) bool

Post traversal does nothing.

func (Transform) Pre

func (Transform) Pre(meta *transform.Meta, v *transform.Visitor) bool

Pre traversal applies all CFG transformations.

type TransformGenerator

type TransformGenerator func(Node) transform.Transform

A TransformGenerator is a function that returns a transformation given a specific node.

Directories

Path Synopsis
Package cfg constructs a simple control-flow graph (CFG) of the statements and expressions within a single function.
Package cfg constructs a simple control-flow graph (CFG) of the statements and expressions within a single function.

Jump to

Keyboard shortcuts

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