cfg

package
v0.0.0-...-4e6f075 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: Unlicense Imports: 13 Imported by: 0

Documentation

Overview

Package cfg provides access to control flow graphs of LLVM IR functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attrs

type Attrs map[string]string

Attrs specifies a set of DOT attributes as key-value pairs.

func (Attrs) Attributes

func (a Attrs) Attributes() []encoding.Attribute

Attributes returns the DOT attributes of a node or edge.

type DominatorTree

type DominatorTree struct {
	flow.DominatorTree
}

A DominatorTree represents a dominator tree.

func NewDom

func NewDom(g graph.Directed, entry graph.Node) DominatorTree

NewDom returns a new dominator tree based on the given graph.

func (DominatorTree) Dominates

func (dt DominatorTree) Dominates(a, b graph.Node) bool

Dominates reports whether A dominates B.

type Edge

type Edge struct {
	graph.Edge
	// Edge label.
	Label string
}

Edge represents an edge of a control flow graph.

func (*Edge) Attributes

func (e *Edge) Attributes() []encoding.Attribute

Attributes returns the attributes of the edge.

func (*Edge) SetAttribute

func (e *Edge) SetAttribute(attr encoding.Attribute) error

SetAttribute sets the attribute of the edge.

type Graph

type Graph struct {
	*simple.DirectedGraph
	// contains filtered or unexported fields
}

Graph represents a control flow graph.

func New

func New(f *ir.Func) *Graph

New returns a new control flow graph based on the given function.

func ParseFile

func ParseFile(path string) (*Graph, error)

ParseFile parses the given Graphviz DOT file into a control flow graph.

func (*Graph) AddNode

func (g *Graph) AddNode(n graph.Node)

AddNode adds the given node to the graph. If the node is an entry node, the graph entry node is updated.

func (*Graph) Entry

func (g *Graph) Entry() graph.Node

Entry returns the entry node of the control flow graph.

func (*Graph) NewEdge

func (g *Graph) NewEdge(from, to graph.Node) graph.Edge

NewEdge returns a new Edge from the source to the destination node.

func (*Graph) NewEdgeWithLabel

func (g *Graph) NewEdgeWithLabel(from, to graph.Node, label string) *Edge

NewEdgeWithLabel returns a new edge from the source to the destination node in the graph, or the existing edge if already present.

func (*Graph) NewNode

func (g *Graph) NewNode() graph.Node

NewNode returns a new graph node with a unique arbitrary ID.

func (*Graph) NewNodeWithLabel

func (g *Graph) NewNodeWithLabel(label string) *Node

NewNodeWithLabel returns a new node with the given basic block label in the graph, or the existing node if already present.

func (*Graph) NodeByLabel

func (g *Graph) NodeByLabel(label string) (*Node, bool)

NodeByLabel returns the node with the given basic block label in the graph. The boolean return value indicates success.

func (*Graph) RemoveNode

func (g *Graph) RemoveNode(n graph.Node)

RemoveNode removes n from the graph, as well as any edges attached to it. If the node is not in the graph it is a no-op.

func (*Graph) SetEntry

func (g *Graph) SetEntry(entry graph.Node)

SetEntry sets the entry node of the control flow graph.

func (*Graph) SetNodeLabel

func (g *Graph) SetNodeLabel(n graph.Node, label string)

SetNodeLabel sets the basic block label of the node.

type Node

type Node struct {
	graph.Node
	// Basic block label.
	Label string
	// DOT attributes.
	Attrs
	// contains filtered or unexported fields
}

Node represents a node of a control flow graph.

func (*Node) Attributes

func (n *Node) Attributes() []encoding.Attribute

Attributes returns the DOT attributes of the node.

func (*Node) DOTID

func (n *Node) DOTID() string

DOTID returns the DOT node ID of the node.

func (*Node) SetAttribute

func (n *Node) SetAttribute(attr encoding.Attribute) error

SetAttribute sets the attribute of the node.

func (*Node) SetDOTID

func (n *Node) SetDOTID(id string)

SetDOTID sets the DOT node ID of the node.

Jump to

Keyboard shortcuts

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