import "github.com/decomp/decomp/cfa"
Package cfa implements control flow analysis of control flow graphs.
cfa.go if.go if_else.go if_return.go post_loop.go pre_loop.go seq.go
FindPrim locates a control flow primitive in the provided control flow graph and merges its nodes into a single node.
Merge merges the nodes of the primitive into a single node, which is assigned the basic block label of the entry node.
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
FindIf returns the first occurrence of a 1-way conditional statement in g, and a boolean indicating if such a primitive was found.
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
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"
String returns a string representation of prim in DOT format.
Example output:
digraph if { cond -> body cond -> exit body -> exit }
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
FindIfElse returns the first occurrence of a 2-way conditional statement in g, and a boolean indicating if such a primitive was found.
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
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"
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 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
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.
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
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"
String returns a string representation of prim in DOT format.
Example output:
digraph if_return { cond -> body cond -> exit }
PostLoop represents a post-test loop.
Pseudo-code:
do { } while (A) B
FindPostLoop returns the first occurrence of a post-test loop in g, and a boolean indicating if such a primitive was found.
IsValid reports whether the cond and exit node candidates of prim form a valid post-test loop in g.
Control flow graph:
cond ↘ ↓ ↖↲ ↓ exit
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"
String returns a string representation of prim in DOT format.
Example output:
digraph post_loop { cond -> cond cond -> exit }
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
FindPreLoop returns the first occurrence of a pre-test loop in g, and a boolean indicating if such a primitive was found.
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
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"
String returns a string representation of prim in DOT format.
Example output:
digraph pre_loop { cond -> body cond -> exit body -> cond }
Seq represents a sequence of two statements.
Pseudo-code:
A B
FindSeq returns the first occurrence of a sequence of two statements in g, and a boolean indicating if such a primitive was found.
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
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"
String returns a string representation of prim in DOT format.
Example output:
digraph seq { entry -> exit }
Path | Synopsis |
---|---|
primitive | Package 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.