decomp: github.com/decomp/decomp/cfa Index | Files | Directories

package cfa

import "github.com/decomp/decomp/cfa"

Package cfa implements control flow analysis of control flow graphs.

Index

Package Files

cfa.go if.go if_else.go if_return.go post_loop.go pre_loop.go seq.go

func FindPrim Uses

func FindPrim(g graph.Directed, dom cfg.DominatorTree) (*primitive.Primitive, error)

FindPrim locates a control flow primitive in the provided control flow graph and merges its nodes into a single node.

func Merge Uses

func Merge(g *cfg.Graph, prim *primitive.Primitive) error

Merge merges the nodes of the primitive into a single node, which is assigned the basic block label of the entry node.

type If Uses

type If struct {
    // Condition node (A).
    Cond graph.Node
    // Body node (B).
    Body graph.Node
    // Exit node (C).
    Exit graph.Node
}

If represents a 1-way conditional statement.

Pseudo-code:

if (A) {
   B
}
C

func FindIf Uses

func FindIf(g graph.Directed, dom cfg.DominatorTree) (prim If, ok bool)

FindIf returns the first occurrence of a 1-way conditional statement in g, and a boolean indicating if such a primitive was found.

func (If) IsValid Uses

func (prim If) IsValid(g graph.Directed, dom cfg.DominatorTree) bool

IsValid reports whether the cond, body and exit node candidates of prim form a valid 1-way conditional statement in g.

Control flow graph:

cond
↓   ↘
↓    body
↓   ↙
exit

func (If) Prim Uses

func (prim If) Prim() *primitive.Primitive

Prim returns a representation of the high-level control flow primitive, as a mapping from control flow primitive node names to control flow graph node names.

Example mapping:

"cond": "A"
"body": "B"
"exit": "C"

func (If) String Uses

func (prim If) String() string

String returns a string representation of prim in DOT format.

Example output:

digraph if {
   cond -> body
   cond -> exit
   body -> exit
}

type IfElse Uses

type IfElse struct {
    // Condition node (A).
    Cond graph.Node
    // Body node of the true branch (B).
    BodyTrue graph.Node
    // Body node of the false branch (C).
    BodyFalse graph.Node
    // Exit node (D).
    Exit graph.Node
}

IfElse represents a 2-way conditional statement.

Pseudo-code:

if (A) {
   B
} else {
   C
}
D

func FindIfElse Uses

func FindIfElse(g graph.Directed, dom cfg.DominatorTree) (prim IfElse, ok bool)

FindIfElse returns the first occurrence of a 2-way conditional statement in g, and a boolean indicating if such a primitive was found.

func (IfElse) IsValid Uses

func (prim IfElse) IsValid(g graph.Directed, dom cfg.DominatorTree) bool

IsValid reports whether the cond, body_true, body_false and exit node candidates of prim form a valid 2-way conditional statement in g.

Control flow graph:

          cond
         ↙    ↘
body_true      body_false
         ↘    ↙
          exit

func (IfElse) Prim Uses

func (prim IfElse) Prim() *primitive.Primitive

Prim returns a representation of the high-level control flow primitive, as a mapping from control flow primitive node names to control flow graph node names.

Example mapping:

"cond":       "A"
"body_true":  "B"
"body_false": "C"
"exit":       "D"

func (IfElse) String Uses

func (prim IfElse) String() string

String returns a string representation of prim in DOT format.

Example output:

digraph if_else {
   cond -> body_true
   cond -> body_false
   body_true -> exit
   body_false -> exit
}

type IfReturn Uses

type IfReturn struct {
    // Condition node (A).
    Cond graph.Node
    // Body node with return statement (B).
    Body graph.Node
    // Exit node (C).
    Exit graph.Node
}

IfReturn represents a 1-way conditional with a body return statement.

Pseudo-code:

if (A) {
   B
   return
}
C

func FindIfReturn Uses

func FindIfReturn(g graph.Directed, dom cfg.DominatorTree) (prim IfReturn, ok bool)

FindIfReturn returns the first occurrence of a 1-way conditional with a body return statement in g, and a boolean indicating if such a primitive was found.

func (IfReturn) IsValid Uses

func (prim IfReturn) IsValid(g graph.Directed, dom cfg.DominatorTree) bool

IsValid reports whether the cond, body and exit node candidates of prim form a valid 1-way conditional with a body return statement in g.

Control flow graph:

cond
↓   ↘
↓    body
↓
exit

func (IfReturn) Prim Uses

func (prim IfReturn) Prim() *primitive.Primitive

Prim returns a representation of the high-level control flow primitive, as a mapping from control flow primitive node names to control flow graph node names.

Example mapping:

"cond": "A"
"body": "B"
"exit": "C"

func (IfReturn) String Uses

func (prim IfReturn) String() string

String returns a string representation of prim in DOT format.

Example output:

digraph if_return {
   cond -> body
   cond -> exit
}

type PostLoop Uses

type PostLoop struct {
    // Condition node (A).
    Cond graph.Node
    // Exit node (B).
    Exit graph.Node
}

PostLoop represents a post-test loop.

Pseudo-code:

do {
} while (A)
B

func FindPostLoop Uses

func FindPostLoop(g graph.Directed, dom cfg.DominatorTree) (prim PostLoop, ok bool)

FindPostLoop returns the first occurrence of a post-test loop in g, and a boolean indicating if such a primitive was found.

func (PostLoop) IsValid Uses

func (prim PostLoop) IsValid(g graph.Directed, dom cfg.DominatorTree) bool

IsValid reports whether the cond and exit node candidates of prim form a valid post-test loop in g.

Control flow graph:

cond ↘
↓   ↖↲
↓
exit

func (PostLoop) Prim Uses

func (prim PostLoop) Prim() *primitive.Primitive

Prim returns a representation of the high-level control flow primitive, as a mapping from control flow primitive node names to control flow graph node names.

Example mapping:

"cond": "A"
"exit": "B"

func (PostLoop) String Uses

func (prim PostLoop) String() string

String returns a string representation of prim in DOT format.

Example output:

digraph post_loop {
   cond -> cond
   cond -> exit
}

type PreLoop Uses

type PreLoop struct {
    // Condition node (A).
    Cond graph.Node
    // Body node (B).
    Body graph.Node
    // Exit node (C).
    Exit graph.Node
}

PreLoop represents a pre-test loop.

Pseudo-code:

while (A) {
   B
}
C

func FindPreLoop Uses

func FindPreLoop(g graph.Directed, dom cfg.DominatorTree) (prim PreLoop, ok bool)

FindPreLoop returns the first occurrence of a pre-test loop in g, and a boolean indicating if such a primitive was found.

func (PreLoop) IsValid Uses

func (prim PreLoop) IsValid(g graph.Directed, dom cfg.DominatorTree) bool

IsValid reports whether the cond, body and exit node candidates of prim form a valid pre-test loop in g.

Control flow graph:

cond
↓  ↖↘
↓   body
↓
exit

func (PreLoop) Prim Uses

func (prim PreLoop) Prim() *primitive.Primitive

Prim returns a representation of the high-level control flow primitive, as a mapping from control flow primitive node names to control flow graph node names.

Example mapping:

"cond": "A"
"body": "B"
"exit": "C"

func (PreLoop) String Uses

func (prim PreLoop) String() string

String returns a string representation of prim in DOT format.

Example output:

digraph pre_loop {
   cond -> body
   cond -> exit
   body -> cond
}

type Seq Uses

type Seq struct {
    // Entry node (A).
    Entry graph.Node
    // Exit node (B).
    Exit graph.Node
}

Seq represents a sequence of two statements.

Pseudo-code:

A
B

func FindSeq Uses

func FindSeq(g graph.Directed, dom cfg.DominatorTree) (prim Seq, ok bool)

FindSeq returns the first occurrence of a sequence of two statements in g, and a boolean indicating if such a primitive was found.

func (Seq) IsValid Uses

func (prim Seq) IsValid(g graph.Directed, dom cfg.DominatorTree) bool

IsValid reports whether the entry and exit node candidates of prim form a valid sequence of two statements in g.

Control flow graph:

entry
↓
exit

func (Seq) Prim Uses

func (prim Seq) Prim() *primitive.Primitive

Prim returns a representation of the high-level control flow primitive, as a mapping from control flow primitive node names to control flow graph node names.

Example mapping:

"entry": "A"
"exit":  "B"

func (Seq) String Uses

func (prim Seq) String() string

String returns a string representation of prim in DOT format.

Example output:

digraph seq {
   entry -> exit
}

Directories

PathSynopsis
primitivePackage primitive defines the types used to represent high-level control flow primitives.

Package cfa imports 5 packages (graph) and is imported by 2 packages. Updated 2019-11-26. Refresh now. Tools for package owners.