MCPcopy Create free account
hub / github.com/decomp/decomp / FindIfReturn

Function FindIfReturn

cfa/if_return.go:73–96  ·  view source on GitHub ↗

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.

(g graph.Directed, dom cfg.DominatorTree)

Source from the content-addressed store, hash-verified

71// return statement in g, and a boolean indicating if such a primitive was
72// found.
73func FindIfReturn(g graph.Directed, dom cfg.DominatorTree) (prim IfReturn, ok bool) {
74 // Range through cond node candidates.
75 for _, cond := range g.Nodes() {
76 // Verify that cond has two successors (body and exit).
77 condSuccs := g.From(cond)
78 if len(condSuccs) != 2 {
79 continue
80 }
81 prim.Cond = cond
82
83 // Select body and exit node candidates.
84 prim.Body, prim.Exit = condSuccs[0], condSuccs[1]
85 if prim.IsValid(g, dom) {
86 return prim, true
87 }
88
89 // Swap body and exit node candidates and try again.
90 prim.Body, prim.Exit = prim.Exit, prim.Body
91 if prim.IsValid(g, dom) {
92 return prim, true
93 }
94 }
95 return IfReturn{}, false
96}
97
98// IsValid reports whether the cond, body and exit node candidates of prim form
99// a valid 1-way conditional with a body return statement in g.

Callers 1

FindPrimFunction · 0.85

Calls 1

IsValidMethod · 0.45

Tested by

no test coverage detected