]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile, cmd/asm: remove Link.Plists
authorHeschi Kreinick <heschi@google.com>
Fri, 17 Feb 2017 21:52:16 +0000 (16:52 -0500)
committerHeschi Kreinick <heschi@google.com>
Wed, 1 Mar 2017 00:29:23 +0000 (00:29 +0000)
Link.Plists never contained more than one Plist, and sometimes none.
Passing around the Plist being worked on is straightforward and makes
the data flow easier to follow.

Change-Id: I79cb30cb2bd3d319fdbb1dfa5d35b27fcb748e5c
Reviewed-on: https://go-review.googlesource.com/37169
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/asm/internal/asm/endtoend_test.go
src/cmd/asm/main.go
src/cmd/compile/internal/gc/dcl.go
src/cmd/compile/internal/gc/gsubr.go
src/cmd/compile/internal/gc/obj.go
src/cmd/compile/internal/gc/pgen.go
src/cmd/internal/obj/link.go
src/cmd/internal/obj/objfile.go
src/cmd/internal/obj/plist.go

index 0abcd1f27513583fd2a0e68d524f79f66645a7be..d1a35c017cc43ce27c0b3e6f6ac07af09c1b4b59 100644 (file)
@@ -30,7 +30,7 @@ func testEndToEnd(t *testing.T, goarch, file string) {
        architecture, ctxt := setArch(goarch)
        lexer := lex.NewLexer(input)
        parser := NewParser(ctxt, architecture, lexer)
-       pList := obj.Linknewplist(ctxt)
+       pList := new(obj.Plist)
        var ok bool
        testOut = new(bytes.Buffer) // The assembler writes test output to this buffer.
        ctxt.Bso = bufio.NewWriter(os.Stdout)
@@ -179,7 +179,7 @@ Diff:
                t.Errorf(format, args...)
                ok = false
        }
-       obj.FlushplistNoFree(ctxt)
+       obj.FlushplistNoFree(ctxt, pList)
 
        for p := top; p != nil; p = p.Link {
                if p.As == obj.ATEXT {
@@ -267,7 +267,7 @@ func testErrors(t *testing.T, goarch, file string) {
        architecture, ctxt := setArch(goarch)
        lexer := lex.NewLexer(input)
        parser := NewParser(ctxt, architecture, lexer)
-       pList := obj.Linknewplist(ctxt)
+       pList := new(obj.Plist)
        var ok bool
        testOut = new(bytes.Buffer) // The assembler writes test output to this buffer.
        ctxt.Bso = bufio.NewWriter(os.Stdout)
@@ -283,7 +283,7 @@ func testErrors(t *testing.T, goarch, file string) {
                errBuf.WriteString(s)
        }
        pList.Firstpc, ok = parser.Parse()
-       obj.Flushplist(ctxt)
+       obj.Flushplist(ctxt, pList)
        if ok && !failed {
                t.Errorf("asm: %s had no errors", goarch)
        }
index 1e27e1a9bdee10854d5f74e881952ff782554579..0bea3c5f20c7e883e15618ef9034b09c16fb6e93 100644 (file)
@@ -62,16 +62,17 @@ func main() {
                        diag = true
                        log.Printf(format, args...)
                }
-               pList := obj.Linknewplist(ctxt)
+               pList := new(obj.Plist)
                pList.Firstpc, ok = parser.Parse()
                if !ok {
                        failedFile = f
                        break
                }
+               // reports errors to parser.Errorf
+               obj.Flushplist(ctxt, pList)
        }
        if ok {
-               // reports errors to parser.Errorf
-               obj.Writeobjdirect(ctxt, buf)
+               obj.WriteObjFile(ctxt, buf)
        }
        if !ok || diag {
                if failedFile != "" {
index b6c9bfb1509f4aa2094663f3e5ac2b476c1eed2d..23fb2cbb9c5d797e45a44e36d27cd5582b7712c1 100644 (file)
@@ -5,7 +5,6 @@
 package gc
 
 import (
-       "cmd/internal/obj"
        "cmd/internal/src"
        "fmt"
        "sort"
@@ -1228,11 +1227,6 @@ func funccompile(n *Node) {
        pc = nil
        funcdepth = 0
        dclcontext = PEXTERN
-       if nerrors != 0 {
-               // If we have compile errors, ignore any assembler/linker errors.
-               Ctxt.DiagFunc = func(string, ...interface{}) {}
-       }
-       obj.Flushplist(Ctxt) // convert from Prog list to machine code
 }
 
 func funcsym(s *Sym) *Sym {
index 3719ccbd55e862c4c18f7b65c0d27314b49b123d..ad7bf05889c83e112377793625d3ca0c895b9061 100644 (file)
@@ -161,16 +161,6 @@ func Addrconst(a *obj.Addr, v int64) {
        a.Offset = v
 }
 
-func newplist() *obj.Plist {
-       pl := obj.Linknewplist(Ctxt)
-
-       pc = Ctxt.NewProg()
-       Clearp(pc)
-       pl.Firstpc = pc
-
-       return pl
-}
-
 // nodarg returns a Node for the function argument denoted by t,
 // which is either the entire function argument or result struct (t is a  struct *Type)
 // or a specific argument (t is a *Field within a struct *Type).
index bec5d89d758e7119e363bc286840e78319f37129..a7fe4692830f3c04894648ced1723fad2f9fc5c0 100644 (file)
@@ -151,7 +151,7 @@ func dumpobj1(outfile string, mode int) {
                ggloblsym(zero, int32(zerosize), obj.DUPOK|obj.RODATA)
        }
 
-       obj.Writeobjdirect(Ctxt, bout.Writer)
+       obj.WriteObjFile(Ctxt, bout.Writer)
 
        if writearchive {
                bout.Flush()
index 519cf02f2789695be15acd2ee16e45332877c657..f6d3c42f6559920c9570d07c56fd95d943303860 100644 (file)
@@ -368,7 +368,10 @@ func compile(fn *Node) {
                return
        }
 
-       newplist()
+       plist := new(obj.Plist)
+       pc = Ctxt.NewProg()
+       Clearp(pc)
+       plist.Firstpc = pc
 
        setlineno(Curfn)
 
@@ -430,6 +433,7 @@ func compile(fn *Node) {
 
        genssa(ssafn, ptxt, gcargs, gclocals)
        ssafn.Free()
+       obj.Flushplist(Ctxt, plist) // convert from Prog list to machine code
 }
 
 func gendebug(fn *obj.LSym, decls []*Node) {
index 7f588b93562e8ae19db3a77ac042af20dbe14f25..9dd0c1447846a36c259b745c39f2fbcc9728aa8b 100644 (file)
@@ -729,7 +729,6 @@ type Link struct {
        Hash          map[SymVer]*LSym
        PosTable      src.PosTable
        Imports       []string
-       Plists        []*Plist
        Sym_div       *LSym
        Sym_divu      *LSym
        Sym_mod       *LSym
index 96122fb23352961d4049328f0665af45fbcb71a2..be8b2b40c9d47939a6c585f931c64425bf4568a7 100644 (file)
@@ -119,14 +119,6 @@ import (
        "sort"
 )
 
-// The Go and C compilers, and the assembler, call writeobj to write
-// out a Go object file. The linker does not call this; the linker
-// does not write out object files.
-func Writeobjdirect(ctxt *Link, b *bufio.Writer) {
-       Flushplist(ctxt)
-       WriteObjFile(ctxt, b)
-}
-
 // objWriter writes Go object files.
 type objWriter struct {
        wr   *bufio.Writer
index 27a24ef10036cfed84d1eb6ad680dcac82e63a95..a74352cdbab1ecd984dd55d9117660d9b699443c 100644 (file)
@@ -14,96 +14,83 @@ type Plist struct {
        Firstpc *Prog
 }
 
-/*
- * start a new Prog list.
- */
-func Linknewplist(ctxt *Link) *Plist {
-       pl := new(Plist)
-       ctxt.Plists = append(ctxt.Plists, pl)
-       return pl
+func Flushplist(ctxt *Link, plist *Plist) {
+       flushplist(ctxt, plist, ctxt.Debugasm == 0)
 }
-
-func Flushplist(ctxt *Link) {
-       flushplist(ctxt, ctxt.Debugasm == 0)
-}
-func FlushplistNoFree(ctxt *Link) {
-       flushplist(ctxt, false)
+func FlushplistNoFree(ctxt *Link, plist *Plist) {
+       flushplist(ctxt, plist, false)
 }
-func flushplist(ctxt *Link, freeProgs bool) {
+func flushplist(ctxt *Link, plist *Plist, freeProgs bool) {
        // Build list of symbols, and assign instructions to lists.
-       // Ignore ctxt->plist boundaries. There are no guarantees there,
-       // and the assemblers just use one big list.
        var curtext *LSym
        var etext *Prog
        var text []*LSym
 
-       for _, pl := range ctxt.Plists {
-               var plink *Prog
-               for p := pl.Firstpc; p != nil; p = plink {
-                       if ctxt.Debugasm != 0 && ctxt.Debugvlog != 0 {
-                               fmt.Printf("obj: %v\n", p)
-                       }
-                       plink = p.Link
-                       p.Link = nil
-
-                       switch p.As {
-                       case AEND:
-                               continue
+       var plink *Prog
+       for p := plist.Firstpc; p != nil; p = plink {
+               if ctxt.Debugasm != 0 && ctxt.Debugvlog != 0 {
+                       fmt.Printf("obj: %v\n", p)
+               }
+               plink = p.Link
+               p.Link = nil
 
-                       case ATEXT:
-                               s := p.From.Sym
-                               if s == nil {
-                                       // func _() { }
-                                       curtext = nil
+               switch p.As {
+               case AEND:
+                       continue
 
-                                       continue
-                               }
+               case ATEXT:
+                       s := p.From.Sym
+                       if s == nil {
+                               // func _() { }
+                               curtext = nil
 
-                               if s.Text != nil {
-                                       log.Fatalf("duplicate TEXT for %s", s.Name)
-                               }
-                               if s.OnList() {
-                                       log.Fatalf("symbol %s listed multiple times", s.Name)
-                               }
-                               s.Set(AttrOnList, true)
-                               text = append(text, s)
-                               flag := int(p.From3Offset())
-                               if flag&DUPOK != 0 {
-                                       s.Set(AttrDuplicateOK, true)
-                               }
-                               if flag&NOSPLIT != 0 {
-                                       s.Set(AttrNoSplit, true)
-                               }
-                               if flag&REFLECTMETHOD != 0 {
-                                       s.Set(AttrReflectMethod, true)
-                               }
-                               s.Type = STEXT
-                               s.Text = p
-                               etext = p
-                               curtext = s
                                continue
+                       }
 
-                       case AFUNCDATA:
-                               // Rewrite reference to go_args_stackmap(SB) to the Go-provided declaration information.
-                               if curtext == nil { // func _() {}
-                                       continue
-                               }
-                               if p.To.Sym.Name == "go_args_stackmap" {
-                                       if p.From.Type != TYPE_CONST || p.From.Offset != FUNCDATA_ArgsPointerMaps {
-                                               ctxt.Diag("FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps")
-                                       }
-                                       p.To.Sym = Linklookup(ctxt, fmt.Sprintf("%s.args_stackmap", curtext.Name), int(curtext.Version))
-                               }
-
+                       if s.Text != nil {
+                               log.Fatalf("duplicate TEXT for %s", s.Name)
+                       }
+                       if s.OnList() {
+                               log.Fatalf("symbol %s listed multiple times", s.Name)
+                       }
+                       s.Set(AttrOnList, true)
+                       text = append(text, s)
+                       flag := int(p.From3Offset())
+                       if flag&DUPOK != 0 {
+                               s.Set(AttrDuplicateOK, true)
                        }
+                       if flag&NOSPLIT != 0 {
+                               s.Set(AttrNoSplit, true)
+                       }
+                       if flag&REFLECTMETHOD != 0 {
+                               s.Set(AttrReflectMethod, true)
+                       }
+                       s.Type = STEXT
+                       s.Text = p
+                       etext = p
+                       curtext = s
+                       continue
 
-                       if curtext == nil {
-                               etext = nil
+               case AFUNCDATA:
+                       // Rewrite reference to go_args_stackmap(SB) to the Go-provided declaration information.
+                       if curtext == nil { // func _() {}
                                continue
                        }
-                       etext.Link = p
-                       etext = p
+                       if p.To.Sym.Name == "go_args_stackmap" {
+                               if p.From.Type != TYPE_CONST || p.From.Offset != FUNCDATA_ArgsPointerMaps {
+                                       ctxt.Diag("FUNCDATA use of go_args_stackmap(SB) without FUNCDATA_ArgsPointerMaps")
+                               }
+                               p.To.Sym = Linklookup(ctxt, fmt.Sprintf("%s.args_stackmap", curtext.Name), int(curtext.Version))
+                       }
+
+               }
+
+               if curtext == nil {
+                       etext = nil
+                       continue
                }
+               etext.Link = p
+               etext = p
        }
 
        // Add reference to Go arguments for C or assembly functions without them.
@@ -147,7 +134,6 @@ func flushplist(ctxt *Link, freeProgs bool) {
        // Add to running list in ctxt.
        ctxt.Text = append(ctxt.Text, text...)
        ctxt.Data = append(ctxt.Data, gendwarf(ctxt, text)...)
-       ctxt.Plists = nil
        ctxt.Curp = nil
        if freeProgs {
                ctxt.freeProgs()