Skip to content

Commit

Permalink
Start building up extra data structures
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Nov 29, 2018
1 parent 36d9e34 commit c2cebfe
Showing 1 changed file with 37 additions and 5 deletions.
42 changes: 37 additions & 5 deletions src/cmd/compile/internal/gc/sinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,21 @@ func init2list(l Nodes, out *[]*Node) {
}
}

func initreorder(l []*Node, out *[]*Node, depth int) {
func initreorder(l []*Node, out *[]*Node, depth int, dcls *[]*Node) {
for _, n := range l {
switch n.Op {
case ODCLFUNC, ODCLCONST, ODCLTYPE:
continue
case OAS:
println(depth, "declaring", n.Left.Sym.Name)
println("declaring", n.Left.Sym.Name, "at depth", depth)
*dcls = append(*dcls, n)
case OAS2:
println("declaring like x,y = f():", n.Left.Sym.Name, "at depth", depth)
default:
println(depth, "something else:", n.Op)
println("declaring like ... ?", n.Op, "at depth", depth)
}

initreorder(n.Ninit.Slice(), out, depth+1)
initreorder(n.Ninit.Slice(), out, depth+1, dcls)
n.Ninit.Set(nil)
init1(n, out)
}
Expand All @@ -252,11 +255,40 @@ func initreorder(l []*Node, out *[]*Node, depth int) {
// to include in the init() function body.
func initfix(l []*Node) []*Node {
var lout []*Node
var dcls []*Node
initplans = make(map[*Node]*InitPlan)
lno := lineno
initreorder(l, &lout, 0)
initreorder(l, &lout, 0, &dcls)
lineno = lno
initplans = nil

var out []*Node
for _, n := range dcls {
out = append(out, n)
}

log := func(varname string, foo []*Node) {
print(varname, ": ")
for i, n := range foo {
if n == nil {
print("nil n in ", foo)
} else if n.Left == nil {
print("nil n.Left on ", n)
} else if n.Left.Sym == nil {
print("nil n.Left.Sym on", n.Left)
} else {
print(n.Left.Sym.Name)
}
if i < len(foo)-1 {
print(", ")
}
}
println()
}

log(" out", out)
log("lout", lout)

return lout
}

Expand Down

0 comments on commit c2cebfe

Please sign in to comment.