From 67e7ded029034cc3cd510303f7b06faf690d4bc3 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Wed, 21 Jan 2015 21:45:29 -0500 Subject: [PATCH] [dev.cc] cmd/internal/obj, cmd/new9a: use ctxt.NewProg cmd/internal/obj reconverted using rsc.io/c2go rev 40275b8. All Prog*s need Ctxt field set so that the printer can tell which architecture the Prog belongs to. Use ctxt.NewProg consistently for this. Change-Id: Ic981b3d68f24931ffae74a772e83a3dc2fdf518a Reviewed-on: https://go-review.googlesource.com/3152 Reviewed-by: Rob Pike --- src/cmd/internal/obj/arm/asm5.go | 12 ++++++------ src/cmd/internal/obj/arm/obj5.go | 15 ++++++--------- src/cmd/internal/obj/i386/obj8.go | 11 ++++------- src/cmd/internal/obj/ld.go | 4 ++-- src/cmd/internal/obj/link.go | 2 +- src/cmd/internal/obj/ppc64/asm9.go | 4 ++-- src/cmd/internal/obj/ppc64/obj9.go | 23 ++++++++++------------- src/cmd/internal/obj/util.go | 6 ++++++ src/cmd/internal/obj/x86/obj6.go | 11 ++++------- src/cmd/new9a/lex.go | 4 ++-- 10 files changed, 43 insertions(+), 49 deletions(-) diff --git a/src/cmd/internal/obj/arm/asm5.go b/src/cmd/internal/obj/arm/asm5.go index 466e30bc3cc..54155c98f05 100644 --- a/src/cmd/internal/obj/arm/asm5.go +++ b/src/cmd/internal/obj/arm/asm5.go @@ -463,7 +463,7 @@ func asmoutnacl(ctxt *obj.Link, origPC int32, p *obj.Prog, o *Optab, out []uint3 // split it into two instructions: // ADD $-100004, R13 // MOVW R14, 0(R13) - q = ctxt.Arch.Prg() + q = ctxt.NewProg() p.Scond &^= C_WBIT *q = *p @@ -546,7 +546,7 @@ func asmoutnacl(ctxt *obj.Link, origPC int32, p *obj.Prog, o *Optab, out []uint3 ctxt.Diag("unsupported instruction (.P/.W): %v", p) } - q = ctxt.Arch.Prg() + q = ctxt.NewProg() *q = *p if p.To.Type == D_OREG { a2 = &q.To @@ -894,7 +894,7 @@ func flushpool(ctxt *obj.Link, p *obj.Prog, skip int, force int) int { if false && skip == 1 { fmt.Printf("note: flush literal pool at %x: len=%d ref=%x\n", uint64(p.Pc+4), pool.size, pool.start) } - q = ctxt.Arch.Prg() + q = ctxt.NewProg() q.As = AB q.To.Type = D_BRANCH q.Pcond = p.Link @@ -906,7 +906,7 @@ func flushpool(ctxt *obj.Link, p *obj.Prog, skip int, force int) int { } if ctxt.Headtype == obj.Hnacl && pool.size%16 != 0 { // if pool is not multiple of 16 bytes, add an alignment marker - q = ctxt.Arch.Prg() + q = ctxt.NewProg() q.As = ADATABUNDLEEND ctxt.Elitrl.Link = q @@ -983,7 +983,7 @@ func addpool(ctxt *obj.Link, p *obj.Prog, a *obj.Addr) { if ctxt.Headtype == obj.Hnacl && pool.size%16 == 0 { // start a new data bundle - q = ctxt.Arch.Prg() + q = ctxt.NewProg() *q = zprg q.As = ADATABUNDLE @@ -1000,7 +1000,7 @@ func addpool(ctxt *obj.Link, p *obj.Prog, a *obj.Addr) { ctxt.Elitrl = q } - q = ctxt.Arch.Prg() + q = ctxt.NewProg() *q = t q.Pc = int64(pool.size) diff --git a/src/cmd/internal/obj/arm/obj5.go b/src/cmd/internal/obj/arm/obj5.go index e8d4a5fc67a..d59c9df0e4f 100644 --- a/src/cmd/internal/obj/arm/obj5.go +++ b/src/cmd/internal/obj/arm/obj5.go @@ -219,11 +219,8 @@ func progedit(ctxt *obj.Link, p *obj.Prog) { } func prg() *obj.Prog { - var p *obj.Prog - - p = new(obj.Prog) - *p = zprg5 - return p + p := zprg + return &p } // Prog.mark @@ -789,7 +786,7 @@ func softfloat(ctxt *obj.Link, cursym *obj.LSym) { soft: if !(wasfloat != 0) || (p.Mark&LABEL != 0) { - next = ctxt.Arch.Prg() + next = ctxt.NewProg() *next = *p // BL _sfloat(SB) @@ -954,7 +951,7 @@ func follow(ctxt *obj.Link, s *obj.LSym) { ctxt.Cursym = s - firstp = ctxt.Arch.Prg() + firstp = ctxt.NewProg() lastp = firstp xfol(ctxt, s.Text, &lastp) lastp.Link = nil @@ -1048,7 +1045,7 @@ loop: copy: for { - r = ctxt.Arch.Prg() + r = ctxt.NewProg() *r = *p if !(r.Mark&FOLL != 0) { fmt.Printf("can't happen 1\n") @@ -1083,7 +1080,7 @@ loop: } a = AB - q = ctxt.Arch.Prg() + q = ctxt.NewProg() q.As = int16(a) q.Lineno = p.Lineno q.To.Type = D_BRANCH diff --git a/src/cmd/internal/obj/i386/obj8.go b/src/cmd/internal/obj/i386/obj8.go index 1cf5510eea1..909e8f53c6a 100644 --- a/src/cmd/internal/obj/i386/obj8.go +++ b/src/cmd/internal/obj/i386/obj8.go @@ -287,11 +287,8 @@ func progedit(ctxt *obj.Link, p *obj.Prog) { } func prg() *obj.Prog { - var p *obj.Prog - - p = new(obj.Prog) - *p = zprg - return p + p := zprg + return &p } func addstacksplit(ctxt *obj.Link, cursym *obj.LSym) { @@ -726,7 +723,7 @@ func follow(ctxt *obj.Link, s *obj.LSym) { ctxt.Cursym = s - firstp = ctxt.Arch.Prg() + firstp = ctxt.NewProg() lastp = firstp xfol(ctxt, s.Text, &lastp) lastp.Link = nil @@ -882,7 +879,7 @@ loop: /* */ } } - q = ctxt.Arch.Prg() + q = ctxt.NewProg() q.As = AJMP q.Lineno = p.Lineno q.To.Type = D_BRANCH diff --git a/src/cmd/internal/obj/ld.go b/src/cmd/internal/obj/ld.go index a7fb762f71c..06dee836a11 100644 --- a/src/cmd/internal/obj/ld.go +++ b/src/cmd/internal/obj/ld.go @@ -144,7 +144,7 @@ func mkfwd(sym *LSym) { func Copyp(ctxt *Link, q *Prog) *Prog { var p *Prog - p = ctxt.Arch.Prg() + p = ctxt.NewProg() *p = *q return p } @@ -152,7 +152,7 @@ func Copyp(ctxt *Link, q *Prog) *Prog { func Appendp(ctxt *Link, q *Prog) *Prog { var p *Prog - p = ctxt.Arch.Prg() + p = ctxt.NewProg() p.Link = q.Link q.Link = p p.Lineno = q.Lineno diff --git a/src/cmd/internal/obj/link.go b/src/cmd/internal/obj/link.go index 26a11484faf..f2311f92346 100644 --- a/src/cmd/internal/obj/link.go +++ b/src/cmd/internal/obj/link.go @@ -49,7 +49,7 @@ type Addr struct { Class int8 Etype uint8 Offset2 int32 - Node *struct{} + Node interface{} Width int64 } diff --git a/src/cmd/internal/obj/ppc64/asm9.go b/src/cmd/internal/obj/ppc64/asm9.go index a98ae61d212..fe3e626b035 100644 --- a/src/cmd/internal/obj/ppc64/asm9.go +++ b/src/cmd/internal/obj/ppc64/asm9.go @@ -475,14 +475,14 @@ func span9(ctxt *obj.Link, cursym *obj.LSym) { otxt = p.Pcond.Pc - c if otxt < -(1<<15)+10 || otxt >= (1<<15)-10 { - q = ctxt.Arch.Prg() + q = ctxt.NewProg() q.Link = p.Link p.Link = q q.As = ABR q.To.Type = D_BRANCH q.Pcond = p.Pcond p.Pcond = q - q = ctxt.Arch.Prg() + q = ctxt.NewProg() q.Link = p.Link p.Link = q q.As = ABR diff --git a/src/cmd/internal/obj/ppc64/obj9.go b/src/cmd/internal/obj/ppc64/obj9.go index 01fa768df41..3a25a125c2f 100644 --- a/src/cmd/internal/obj/ppc64/obj9.go +++ b/src/cmd/internal/obj/ppc64/obj9.go @@ -599,7 +599,7 @@ func addstacksplit(ctxt *obj.Link, cursym *obj.LSym) { p.To.Reg = REGSP p.Spadj = -autosize - q = ctxt.Arch.Prg() + q = ctxt.NewProg() q.As = ABR q.Lineno = p.Lineno q.To.Type = D_SPR @@ -619,7 +619,7 @@ func addstacksplit(ctxt *obj.Link, cursym *obj.LSym) { p.To.Type = D_REG p.To.Reg = REGTMP - q = ctxt.Arch.Prg() + q = ctxt.NewProg() q.As = AMOVD q.Lineno = p.Lineno q.From.Type = D_REG @@ -633,7 +633,7 @@ func addstacksplit(ctxt *obj.Link, cursym *obj.LSym) { if false { // Debug bad returns - q = ctxt.Arch.Prg() + q = ctxt.NewProg() q.As = AMOVD q.Lineno = p.Lineno @@ -649,7 +649,7 @@ func addstacksplit(ctxt *obj.Link, cursym *obj.LSym) { } if autosize != 0 { - q = ctxt.Arch.Prg() + q = ctxt.NewProg() q.As = AADD q.Lineno = p.Lineno q.From.Type = D_CONST @@ -662,7 +662,7 @@ func addstacksplit(ctxt *obj.Link, cursym *obj.LSym) { p.Link = q } - q1 = ctxt.Arch.Prg() + q1 = ctxt.NewProg() q1.As = ABR q1.Lineno = p.Lineno q1.To.Type = D_SPR @@ -888,7 +888,7 @@ func follow(ctxt *obj.Link, s *obj.LSym) { ctxt.Cursym = s - firstp = ctxt.Arch.Prg() + firstp = ctxt.NewProg() lastp = firstp xfol(ctxt, s.Text, &lastp) lastp.Link = nil @@ -984,7 +984,7 @@ loop: copy: for { - r = ctxt.Arch.Prg() + r = ctxt.NewProg() *r = *p if !(r.Mark&FOLL != 0) { fmt.Printf("cant happen 1\n") @@ -1016,7 +1016,7 @@ loop: } a = ABR - q = ctxt.Arch.Prg() + q = ctxt.NewProg() q.As = int16(a) q.Lineno = p.Lineno q.To.Type = D_BRANCH @@ -1053,11 +1053,8 @@ loop: } func prg() *obj.Prog { - var p *obj.Prog - - p = new(obj.Prog) - *p = zprg - return p + p := zprg + return &p } var Linkppc64 = obj.LinkArch{ diff --git a/src/cmd/internal/obj/util.go b/src/cmd/internal/obj/util.go index 2fc910a78fa..14f2271cb2a 100644 --- a/src/cmd/internal/obj/util.go +++ b/src/cmd/internal/obj/util.go @@ -117,3 +117,9 @@ func (p *Prog) String() string { } return p.Ctxt.Arch.Pconv(p) } + +func (ctxt *Link) NewProg() *Prog { + p := ctxt.Arch.Prg() // should be the only call to this; all others should use ctxt.NewProg + p.Ctxt = ctxt + return p +} diff --git a/src/cmd/internal/obj/x86/obj6.go b/src/cmd/internal/obj/x86/obj6.go index aacc2564b98..1b7c119c3e5 100644 --- a/src/cmd/internal/obj/x86/obj6.go +++ b/src/cmd/internal/obj/x86/obj6.go @@ -887,7 +887,7 @@ func follow(ctxt *obj.Link, s *obj.LSym) { ctxt.Cursym = s - firstp = ctxt.Arch.Prg() + firstp = ctxt.NewProg() lastp = firstp xfol(ctxt, s.Text, &lastp) lastp.Link = nil @@ -1051,7 +1051,7 @@ loop: /* */ } } - q = ctxt.Arch.Prg() + q = ctxt.NewProg() q.As = AJMP q.Lineno = p.Lineno q.To.Type = D_BRANCH @@ -1124,11 +1124,8 @@ loop: } func prg() *obj.Prog { - var p *obj.Prog - - p = new(obj.Prog) - *p = zprg - return p + p := zprg + return &p } var Linkamd64 = obj.LinkArch{ diff --git a/src/cmd/new9a/lex.go b/src/cmd/new9a/lex.go index 42896ae2998..c2c633e3865 100644 --- a/src/cmd/new9a/lex.go +++ b/src/cmd/new9a/lex.go @@ -498,7 +498,7 @@ func outcode(a int, g1 *obj.Addr, reg int, g2 *obj.Addr) { reg = int(g2.Scale) } - p = asm.Ctxt.Arch.Prg() + p = asm.Ctxt.NewProg() p.As = int16(a) p.Lineno = asm.Lineno if nosched != 0 { @@ -531,7 +531,7 @@ func outgcode(a int, g1 *obj.Addr, reg int, g2, g3 *obj.Addr) { goto out } - p = asm.Ctxt.Arch.Prg() + p = asm.Ctxt.NewProg() p.As = int16(a) p.Lineno = asm.Lineno if nosched != 0 {