"cmd/internal/obj"
"crypto/md5"
"fmt"
+ "sort"
"strings"
)
return a.Sym.Name < b.Sym.Name
}
+// byStackvar implements sort.Interface for []*Node using cmpstackvarlt.
+type byStackVar []*Node
+
+func (s byStackVar) Len() int { return len(s) }
+func (s byStackVar) Less(i, j int) bool { return cmpstackvarlt(s[i], s[j]) }
+func (s byStackVar) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
+
// stkdelta records the stack offset delta for a node
// during the compaction of the stack frame to remove
// unused stack slots.
Stksize = 0
stkptrsize = 0
- if Curfn.Func.Dcl == nil {
+ if len(Curfn.Func.Dcl) == 0 {
return
}
// Mark the PAUTO's unused.
- for ll := Curfn.Func.Dcl; ll != nil; ll = ll.Next {
- if ll.N.Class == PAUTO {
- ll.N.Used = false
+ for _, ln := range Curfn.Func.Dcl {
+ if ln.Class == PAUTO {
+ ln.Used = false
}
}
markautoused(ptxt)
- listsort(&Curfn.Func.Dcl, cmpstackvarlt)
+ sort.Sort(byStackVar(Curfn.Func.Dcl))
// Unused autos are at the end, chop 'em off.
- ll := Curfn.Func.Dcl
-
- n := ll.N
+ n := Curfn.Func.Dcl[0]
if n.Class == PAUTO && n.Op == ONAME && !n.Used {
// No locals used at all
Curfn.Func.Dcl = nil
return
}
- for ll := Curfn.Func.Dcl; ll.Next != nil; ll = ll.Next {
- n = ll.Next.N
+ for i := 1; i < len(Curfn.Func.Dcl); i++ {
+ n = Curfn.Func.Dcl[i]
if n.Class == PAUTO && n.Op == ONAME && !n.Used {
- ll.Next = nil
- Curfn.Func.Dcl.End = ll
+ Curfn.Func.Dcl = Curfn.Func.Dcl[:i]
break
}
}
// Reassign stack offsets of the locals that are still there.
var w int64
- for ll := Curfn.Func.Dcl; ll != nil; ll = ll.Next {
- n = ll.N
+ for _, n := range Curfn.Func.Dcl {
if n.Class != PAUTO || n.Op != ONAME {
continue
}
fixautoused(ptxt)
// The debug information needs accurate offsets on the symbols.
- for ll := Curfn.Func.Dcl; ll != nil; ll = ll.Next {
- if ll.N.Class != PAUTO || ll.N.Op != ONAME {
+ for _, ln := range Curfn.Func.Dcl {
+ if ln.Class != PAUTO || ln.Op != ONAME {
continue
}
- ll.N.Xoffset += stkdelta[ll.N]
- delete(stkdelta, ll.N)
+ ln.Xoffset += stkdelta[ln]
+ delete(stkdelta, ln)
}
}
if fn.Func.Needctxt {
ptxt.From3.Offset |= obj.NEEDCTXT
}
- if fn.Func.Nosplit {
+ if fn.Func.Pragma&Nosplit != 0 {
ptxt.From3.Offset |= obj.NOSPLIT
}
- if fn.Func.Systemstack {
+ if fn.Func.Pragma&Systemstack != 0 {
ptxt.From.Sym.Cfunc = 1
}
gtrack(tracksym(t))
}
- for l := fn.Func.Dcl; l != nil; l = l.Next {
- n = l.N
+ for _, n := range fn.Func.Dcl {
if n.Op != ONAME { // might be OTYPE or OLITERAL
continue
}
switch n.Class {
case PAUTO, PPARAM, PPARAMOUT:
- Nodconst(&nod1, Types[TUINTPTR], l.N.Type.Width)
- p = Thearch.Gins(obj.ATYPE, l.N, &nod1)
- p.From.Gotype = Linksym(ngotype(l.N))
+ Nodconst(&nod1, Types[TUINTPTR], n.Type.Width)
+ p = Thearch.Gins(obj.ATYPE, n, &nod1)
+ p.From.Gotype = Linksym(ngotype(n))
}
}
ssafn.Free()
return
}
- Genlist(Curfn.Func.Enter)
+ Genslice(Curfn.Func.Enter.Slice())
Genlist(Curfn.Nbody)
gclean()
checklabels()