]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/cmd/internal/obj/util.go
[dev.ssa] Merge remote-tracking branch 'origin/master' into ssamerge
[gostls13.git] / src / cmd / internal / obj / util.go
index 459361cf48ee009f641f2b98f8d7573cb9e5e611..b6e644372fa3775af67e2e3af1687e2b3f8b177e 100644 (file)
@@ -287,6 +287,10 @@ func CConv(s uint8) string {
 }
 
 func (p *Prog) String() string {
+       if p == nil {
+               return "<nil Prog>"
+       }
+
        if p.Ctxt == nil {
                return "<Prog without ctxt>"
        }
@@ -325,10 +329,23 @@ func (p *Prog) String() string {
 }
 
 func (ctxt *Link) NewProg() *Prog {
-       p := new(Prog) // should be the only call to this; all others should use ctxt.NewProg
+       var p *Prog
+       if i := ctxt.allocIdx; i < len(ctxt.progs) {
+               p = &ctxt.progs[i]
+               ctxt.allocIdx = i + 1
+       } else {
+               p = new(Prog) // should be the only call to this; all others should use ctxt.NewProg
+       }
        p.Ctxt = ctxt
        return p
 }
+func (ctxt *Link) freeProgs() {
+       s := ctxt.progs[:ctxt.allocIdx]
+       for i := range s {
+               s[i] = Prog{}
+       }
+       ctxt.allocIdx = 0
+}
 
 func (ctxt *Link) Line(n int) string {
        return ctxt.LineHist.LineString(n)