mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/internal/obj: various code cleanups
Mostly replacing C-Style loops with range expressions, but also other simplifications like the introduction of writeBool and unindenting some code. Passes toolstash -cmp on std cmd. Change-Id: I799bccd4e5d411428dcf122b8588a564a9217e7c Reviewed-on: https://go-review.googlesource.com/104936 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Marvin Stenger <marvin.stenger94@gmail.com> Reviewed-by: Ilya Tocar <ilya.tocar@intel.com>
This commit is contained in:
parent
47427d67d6
commit
e8aa9a533d
4 changed files with 45 additions and 55 deletions
|
|
@ -56,8 +56,8 @@ func (w *objWriter) addLengths(s *LSym) {
|
|||
data += len(pc.Pcfile.P)
|
||||
data += len(pc.Pcline.P)
|
||||
data += len(pc.Pcinline.P)
|
||||
for i := 0; i < len(pc.Pcdata); i++ {
|
||||
data += len(pc.Pcdata[i].P)
|
||||
for _, pcd := range pc.Pcdata {
|
||||
data += len(pcd.P)
|
||||
}
|
||||
|
||||
w.nData += data
|
||||
|
|
@ -124,8 +124,8 @@ func WriteObjFile(ctxt *Link, b *bufio.Writer) {
|
|||
w.wr.Write(pc.Pcfile.P)
|
||||
w.wr.Write(pc.Pcline.P)
|
||||
w.wr.Write(pc.Pcinline.P)
|
||||
for i := 0; i < len(pc.Pcdata); i++ {
|
||||
w.wr.Write(pc.Pcdata[i].P)
|
||||
for _, pcd := range pc.Pcdata {
|
||||
w.wr.Write(pcd.P)
|
||||
}
|
||||
}
|
||||
for _, s := range ctxt.Data {
|
||||
|
|
@ -175,11 +175,7 @@ func (w *objWriter) writeRef(s *LSym, isPath bool) {
|
|||
w.writeString(s.Name)
|
||||
}
|
||||
// Write "version".
|
||||
if s.Static() {
|
||||
w.writeInt(1)
|
||||
} else {
|
||||
w.writeInt(0)
|
||||
}
|
||||
w.writeBool(s.Static())
|
||||
w.nRefs++
|
||||
s.RefIdx = w.nRefs
|
||||
m[s.Name] = w.nRefs
|
||||
|
|
@ -188,8 +184,8 @@ func (w *objWriter) writeRef(s *LSym, isPath bool) {
|
|||
func (w *objWriter) writeRefs(s *LSym) {
|
||||
w.writeRef(s, false)
|
||||
w.writeRef(s.Gotype, false)
|
||||
for i := range s.R {
|
||||
w.writeRef(s.R[i].Sym, false)
|
||||
for _, r := range s.R {
|
||||
w.writeRef(r.Sym, false)
|
||||
}
|
||||
|
||||
if s.Type == objabi.STEXT {
|
||||
|
|
@ -309,7 +305,7 @@ func (w *objWriter) writeSym(s *LSym) {
|
|||
|
||||
w.writeInt(int64(len(s.R)))
|
||||
var r *Reloc
|
||||
for i := 0; i < len(s.R); i++ {
|
||||
for i := range s.R {
|
||||
r = &s.R[i]
|
||||
w.writeInt(int64(r.Off))
|
||||
w.writeInt(int64(r.Siz))
|
||||
|
|
@ -324,11 +320,7 @@ func (w *objWriter) writeSym(s *LSym) {
|
|||
|
||||
w.writeInt(int64(s.Func.Args))
|
||||
w.writeInt(int64(s.Func.Locals))
|
||||
if s.NoSplit() {
|
||||
w.writeInt(1)
|
||||
} else {
|
||||
w.writeInt(0)
|
||||
}
|
||||
w.writeBool(s.NoSplit())
|
||||
flags = int64(0)
|
||||
if s.Leaf() {
|
||||
flags |= 1
|
||||
|
|
@ -365,14 +357,14 @@ func (w *objWriter) writeSym(s *LSym) {
|
|||
w.writeInt(int64(len(pc.Pcline.P)))
|
||||
w.writeInt(int64(len(pc.Pcinline.P)))
|
||||
w.writeInt(int64(len(pc.Pcdata)))
|
||||
for i := 0; i < len(pc.Pcdata); i++ {
|
||||
w.writeInt(int64(len(pc.Pcdata[i].P)))
|
||||
for _, pcd := range pc.Pcdata {
|
||||
w.writeInt(int64(len(pcd.P)))
|
||||
}
|
||||
w.writeInt(int64(len(pc.Funcdataoff)))
|
||||
for i := 0; i < len(pc.Funcdataoff); i++ {
|
||||
for i := range pc.Funcdataoff {
|
||||
w.writeRefIndex(pc.Funcdata[i])
|
||||
}
|
||||
for i := 0; i < len(pc.Funcdataoff); i++ {
|
||||
for i := range pc.Funcdataoff {
|
||||
w.writeInt(pc.Funcdataoff[i])
|
||||
}
|
||||
w.writeInt(int64(len(pc.File)))
|
||||
|
|
@ -391,6 +383,14 @@ func (w *objWriter) writeSym(s *LSym) {
|
|||
}
|
||||
}
|
||||
|
||||
func (w *objWriter) writeBool(b bool) {
|
||||
if b {
|
||||
w.writeInt(1)
|
||||
} else {
|
||||
w.writeInt(0)
|
||||
}
|
||||
}
|
||||
|
||||
func (w *objWriter) writeInt(sval int64) {
|
||||
var v uint64
|
||||
uv := (uint64(sval) << 1) ^ uint64(sval>>63)
|
||||
|
|
@ -766,7 +766,7 @@ func (ft *DwarfFixupTable) RegisterChildDIEOffsets(s *LSym, vars []*dwarf.Var, c
|
|||
|
||||
// Generate the slice of declOffset's based in vars/coffsets
|
||||
doffsets := make([]declOffset, len(coffsets))
|
||||
for i := 0; i < len(coffsets); i++ {
|
||||
for i := range coffsets {
|
||||
doffsets[i].dclIdx = vars[i].ChildIndex
|
||||
doffsets[i].offset = coffsets[i]
|
||||
}
|
||||
|
|
@ -791,9 +791,9 @@ func (ft *DwarfFixupTable) processFixups(slot int, s *LSym) {
|
|||
sf := &ft.svec[slot]
|
||||
for _, f := range sf.fixups {
|
||||
dfound := false
|
||||
for i := 0; i < len(sf.doffsets); i++ {
|
||||
if sf.doffsets[i].dclIdx == f.dclidx {
|
||||
f.refsym.R[f.relidx].Add += int64(sf.doffsets[i].offset)
|
||||
for _, doffset := range sf.doffsets {
|
||||
if doffset.dclIdx == f.dclidx {
|
||||
f.refsym.R[f.relidx].Add += int64(doffset.offset)
|
||||
dfound = true
|
||||
break
|
||||
}
|
||||
|
|
@ -833,7 +833,7 @@ func (ft *DwarfFixupTable) Finalize(myimportpath string, trace bool) {
|
|||
// resulting list (don't want to rely on map ordering here).
|
||||
fns := make([]*LSym, len(ft.precursor))
|
||||
idx := 0
|
||||
for fn, _ := range ft.precursor {
|
||||
for fn := range ft.precursor {
|
||||
fns[idx] = fn
|
||||
idx++
|
||||
}
|
||||
|
|
@ -845,8 +845,7 @@ func (ft *DwarfFixupTable) Finalize(myimportpath string, trace bool) {
|
|||
}
|
||||
|
||||
// Generate any missing abstract functions.
|
||||
for i := 0; i < len(fns); i++ {
|
||||
s := fns[i]
|
||||
for _, s := range fns {
|
||||
absfn := ft.AbsFuncDwarfSym(s)
|
||||
slot, found := ft.symtab[absfn]
|
||||
if !found || !ft.svec[slot].defseen {
|
||||
|
|
@ -855,8 +854,7 @@ func (ft *DwarfFixupTable) Finalize(myimportpath string, trace bool) {
|
|||
}
|
||||
|
||||
// Apply fixups.
|
||||
for i := 0; i < len(fns); i++ {
|
||||
s := fns[i]
|
||||
for _, s := range fns {
|
||||
absfn := ft.AbsFuncDwarfSym(s)
|
||||
slot, found := ft.symtab[absfn]
|
||||
if !found {
|
||||
|
|
|
|||
|
|
@ -118,10 +118,6 @@ func checkaddr(ctxt *Link, p *Prog, a *Addr) {
|
|||
}
|
||||
|
||||
func linkpatch(ctxt *Link, sym *LSym, newprog ProgAlloc) {
|
||||
var c int32
|
||||
var name string
|
||||
var q *Prog
|
||||
|
||||
for p := sym.Func.Text; p != nil; p = p.Link {
|
||||
checkaddr(ctxt, p, &p.From)
|
||||
if p.GetFrom3() != nil {
|
||||
|
|
@ -144,12 +140,12 @@ func linkpatch(ctxt *Link, sym *LSym, newprog ProgAlloc) {
|
|||
if p.To.Sym != nil {
|
||||
continue
|
||||
}
|
||||
c = int32(p.To.Offset)
|
||||
for q = sym.Func.Text; q != nil; {
|
||||
if int64(c) == q.Pc {
|
||||
q := sym.Func.Text
|
||||
for q != nil {
|
||||
if p.To.Offset == q.Pc {
|
||||
break
|
||||
}
|
||||
if q.Forwd != nil && int64(c) >= q.Forwd.Pc {
|
||||
if q.Forwd != nil && p.To.Offset >= q.Forwd.Pc {
|
||||
q = q.Forwd
|
||||
} else {
|
||||
q = q.Link
|
||||
|
|
@ -157,11 +153,11 @@ func linkpatch(ctxt *Link, sym *LSym, newprog ProgAlloc) {
|
|||
}
|
||||
|
||||
if q == nil {
|
||||
name = "<nil>"
|
||||
name := "<nil>"
|
||||
if p.To.Sym != nil {
|
||||
name = p.To.Sym.Name
|
||||
}
|
||||
ctxt.Diag("branch out of range (%#x)\n%v [%s]", uint32(c), p, name)
|
||||
ctxt.Diag("branch out of range (%#x)\n%v [%s]", uint32(p.To.Offset), p, name)
|
||||
p.To.Type = TYPE_NONE
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -118,8 +118,8 @@ func funcpctab(ctxt *Link, dst *Pcdata, func_ *LSym, desc string, valfunc func(*
|
|||
|
||||
if dbg {
|
||||
ctxt.Logf("wrote %d bytes to %p\n", len(dst.P), dst)
|
||||
for i := 0; i < len(dst.P); i++ {
|
||||
ctxt.Logf(" %02x", dst.P[i])
|
||||
for _, p := range dst.P {
|
||||
ctxt.Logf(" %02x", p)
|
||||
}
|
||||
ctxt.Logf("\n")
|
||||
}
|
||||
|
|
@ -342,10 +342,11 @@ func linkpcln(ctxt *Link, cursym *LSym) {
|
|||
|
||||
// funcdata
|
||||
if nfuncdata > 0 {
|
||||
var i int
|
||||
for p := cursym.Func.Text; p != nil; p = p.Link {
|
||||
if p.As == AFUNCDATA {
|
||||
i = int(p.From.Offset)
|
||||
if p.As != AFUNCDATA {
|
||||
continue
|
||||
}
|
||||
i := int(p.From.Offset)
|
||||
pcln.Funcdataoff[i] = p.To.Offset
|
||||
if p.To.Type != TYPE_CONST {
|
||||
// TODO: Dedup.
|
||||
|
|
@ -355,4 +356,3 @@ func linkpcln(ctxt *Link, cursym *LSym) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,10 +165,6 @@ func (ctxt *Link) CanReuseProgs() bool {
|
|||
return !ctxt.Debugasm
|
||||
}
|
||||
|
||||
func (ctxt *Link) Dconv(a *Addr) string {
|
||||
return Dconv(nil, a)
|
||||
}
|
||||
|
||||
func Dconv(p *Prog, a *Addr) string {
|
||||
var str string
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue