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

Method termSwitch

cmd/ll2go/terminator.go:78–98  ·  view source on GitHub ↗

termSwitch converts the given LLVM IR switch terminator to a corresponding Go statement.

(term *ir.TermSwitch)

Source from the content-addressed store, hash-verified

76// termSwitch converts the given LLVM IR switch terminator to a corresponding Go
77// statement.
78func (d *decompiler) termSwitch(term *ir.TermSwitch) ast.Stmt {
79 // Use goto-statements as a fallback for incomplete control flow recovery.
80 var cases []ast.Stmt
81 for _, c := range term.Cases {
82 gotoStmt := &ast.BranchStmt{
83 Tok: token.GOTO,
84 Label: d.localIdent(c.Target.Name),
85 }
86 cc := &ast.CaseClause{
87 List: []ast.Expr{d.value(c.X)},
88 Body: []ast.Stmt{gotoStmt},
89 }
90 cases = append(cases, cc)
91 }
92 return &ast.SwitchStmt{
93 Tag: d.value(term.X),
94 Body: &ast.BlockStmt{
95 List: cases,
96 },
97 }
98}
99
100// termUnreachable converts the given LLVM IR unreachable terminator to a
101// corresponding Go statement.

Callers 1

termMethod · 0.95

Calls 2

localIdentMethod · 0.95
valueMethod · 0.95

Tested by

no test coverage detected