/
stmt.go
54 lines (46 loc) · 1.33 KB
/
stmt.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package noder
import (
"github.com/go-asm/go/cmd/compile/ir"
"github.com/go-asm/go/cmd/compile/syntax"
)
// TODO(mdempsky): Investigate replacing with switch statements or dense arrays.
var branchOps = [...]ir.Op{
syntax.Break: ir.OBREAK,
syntax.Continue: ir.OCONTINUE,
syntax.Fallthrough: ir.OFALL,
syntax.Goto: ir.OGOTO,
}
var callOps = [...]ir.Op{
syntax.Defer: ir.ODEFER,
syntax.Go: ir.OGO,
}
// initDefn marks the given names as declared by defn and populates
// its Init field with ODCL nodes. It then reports whether any names
// were so declared, which can be used to initialize defn.Def.
func initDefn(defn ir.InitNode, names []*ir.Name) bool {
if len(names) == 0 {
return false
}
init := make([]ir.Node, len(names))
for i, name := range names {
name.Defn = defn
init[i] = ir.NewDecl(name.Pos(), ir.ODCL, name)
}
defn.SetInit(init)
return true
}
// unpackTwo returns the first two nodes in list. If list has fewer
// than 2 nodes, then the missing nodes are replaced with nils.
func unpackTwo(list []ir.Node) (fst, snd ir.Node) {
switch len(list) {
case 0:
return nil, nil
case 1:
return list[0], nil
default:
return list[0], list[1]
}
}