mirror of
https://github.com/golang/go
synced 2024-09-30 18:18:32 -06:00
cmd/internal/obj: clean up Biobuf
This is a follow up to rev 443a32e707
which reduces some of the
duplication between methods and functions that operate on obj.Biobuf.
obj.Biobuf has Flush and Write methods as well as helpers which duplicate
those methods, consolidate on the former and remove the latter.
Also, address a final comment from CL 9525.
Change-Id: I67deaf3a163bb489a9bb21bb39524785d7a2f6c5
Reviewed-on: https://go-review.googlesource.com/9527
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
bc44b818a6
commit
e9ab343f0e
@ -61,7 +61,7 @@ func main() {
|
||||
gc.Thearch.FREGMAX = x86.REG_X7
|
||||
default:
|
||||
fmt.Fprintf(os.Stderr, "unsupported setting GO386=%s\n", v)
|
||||
os.Exit(1)
|
||||
gc.Exit(1)
|
||||
}
|
||||
gc.Thearch.MAXWIDTH = MAXWIDTH
|
||||
gc.Thearch.ReservedRegs = resvd
|
||||
|
@ -33,7 +33,7 @@ func testEndToEnd(t *testing.T, goarch string) {
|
||||
var ok bool
|
||||
testOut = new(bytes.Buffer) // The assembler writes -S output to this buffer.
|
||||
ctxt.Bso = obj.Binitw(os.Stdout)
|
||||
defer obj.Bflush(ctxt.Bso)
|
||||
defer ctxt.Bso.Flush()
|
||||
ctxt.Diag = log.Fatalf
|
||||
obj.Binitw(ioutil.Discard)
|
||||
pList.Firstpc, ok = parser.Parse()
|
||||
|
@ -46,7 +46,7 @@ func main() {
|
||||
ctxt.Flag_shared = 1
|
||||
}
|
||||
ctxt.Bso = obj.Binitw(os.Stdout)
|
||||
defer obj.Bflush(ctxt.Bso)
|
||||
defer ctxt.Bso.Flush()
|
||||
ctxt.Diag = log.Fatalf
|
||||
output := obj.Binitw(fd)
|
||||
fmt.Fprintf(output, "go object %s %s %s\n", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion())
|
||||
@ -63,5 +63,5 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
obj.Writeobjdirect(ctxt, output)
|
||||
obj.Bflush(output)
|
||||
output.Flush()
|
||||
}
|
||||
|
@ -209,7 +209,7 @@ func Main() {
|
||||
if assemble(flag.Arg(0)) != 0 {
|
||||
errorexit()
|
||||
}
|
||||
obj.Bflush(&bstdout)
|
||||
bstdout.Flush()
|
||||
if nerrors > 0 {
|
||||
errorexit()
|
||||
}
|
||||
@ -244,7 +244,7 @@ func assemble(file string) int {
|
||||
}
|
||||
|
||||
obj.Writeobjdirect(Ctxt, &obuf)
|
||||
obj.Bflush(&obuf)
|
||||
obuf.Flush()
|
||||
return 0
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ func setinclude(p string) {
|
||||
}
|
||||
|
||||
func errorexit() {
|
||||
obj.Bflush(&bstdout)
|
||||
bstdout.Flush()
|
||||
if outfile != "" {
|
||||
os.Remove(outfile)
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ func dumpobj() {
|
||||
if writearchive != 0 {
|
||||
obj.Bwritestring(bout, "!<arch>\n")
|
||||
arhdr = [ArhdrSize]byte{}
|
||||
obj.Bwrite(bout, arhdr[:])
|
||||
bout.Write(arhdr[:])
|
||||
startobj = obj.Boffset(bout)
|
||||
}
|
||||
|
||||
@ -43,19 +43,19 @@ func dumpobj() {
|
||||
dumpexport()
|
||||
|
||||
if writearchive != 0 {
|
||||
obj.Bflush(bout)
|
||||
bout.Flush()
|
||||
size := obj.Boffset(bout) - startobj
|
||||
if size&1 != 0 {
|
||||
obj.Bputc(bout, 0)
|
||||
}
|
||||
obj.Bseek(bout, startobj-ArhdrSize, 0)
|
||||
formathdr(arhdr[:], "__.PKGDEF", size)
|
||||
obj.Bwrite(bout, arhdr[:])
|
||||
obj.Bflush(bout)
|
||||
bout.Write(arhdr[:])
|
||||
bout.Flush()
|
||||
|
||||
obj.Bseek(bout, startobj+size+(size&1), 0)
|
||||
arhdr = [ArhdrSize]byte{}
|
||||
obj.Bwrite(bout, arhdr[:])
|
||||
bout.Write(arhdr[:])
|
||||
startobj = obj.Boffset(bout)
|
||||
fmt.Fprintf(bout, "go object %s %s %s %s\n", obj.Getgoos(), obj.Getgoarch(), obj.Getgoversion(), obj.Expstring())
|
||||
}
|
||||
@ -96,7 +96,7 @@ func dumpobj() {
|
||||
obj.Writeobjdirect(Ctxt, bout)
|
||||
|
||||
if writearchive != 0 {
|
||||
obj.Bflush(bout)
|
||||
bout.Flush()
|
||||
size := obj.Boffset(bout) - startobj
|
||||
if size&1 != 0 {
|
||||
obj.Bputc(bout, 0)
|
||||
@ -104,7 +104,7 @@ func dumpobj() {
|
||||
obj.Bseek(bout, startobj-ArhdrSize, 0)
|
||||
name := fmt.Sprintf("_go_.%c", Thearch.Thechar)
|
||||
formathdr(arhdr[:], name, size)
|
||||
obj.Bwrite(bout, arhdr[:])
|
||||
bout.Write(arhdr[:])
|
||||
}
|
||||
|
||||
obj.Bterm(bout)
|
||||
|
@ -82,7 +82,7 @@ func (x errcmp) Less(i, j int) bool {
|
||||
}
|
||||
|
||||
func Flusherrors() {
|
||||
obj.Bflush(&bstdout)
|
||||
bstdout.Flush()
|
||||
if len(errors) == 0 {
|
||||
return
|
||||
}
|
||||
|
@ -338,7 +338,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
|
||||
if autosize == 0 && cursym.Text.Mark&LEAF == 0 {
|
||||
if ctxt.Debugvlog != 0 {
|
||||
fmt.Fprintf(ctxt.Bso, "save suppressed in: %s\n", cursym.Name)
|
||||
obj.Bflush(ctxt.Bso)
|
||||
ctxt.Bso.Flush()
|
||||
}
|
||||
|
||||
cursym.Text.Mark |= LEAF
|
||||
|
@ -485,7 +485,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
|
||||
* strip NOPs
|
||||
* expand RET
|
||||
*/
|
||||
obj.Bflush(ctxt.Bso)
|
||||
ctxt.Bso.Flush()
|
||||
q := (*obj.Prog)(nil)
|
||||
var q1 *obj.Prog
|
||||
for p := cursym.Text; p != nil; p = p.Link {
|
||||
@ -575,7 +575,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
|
||||
if ctxt.Debugvlog != 0 {
|
||||
fmt.Fprintf(ctxt.Bso, "save suppressed in: %s\n", cursym.Text.From.Sym.Name)
|
||||
}
|
||||
obj.Bflush(ctxt.Bso)
|
||||
ctxt.Bso.Flush()
|
||||
cursym.Text.Mark |= LEAF
|
||||
}
|
||||
|
||||
|
@ -481,7 +481,7 @@ func wrint(b *Biobuf, sval int64) {
|
||||
}
|
||||
p[0] = uint8(v)
|
||||
p = p[1:]
|
||||
Bwrite(b, varintbuf[:len(varintbuf)-len(p)])
|
||||
b.Write(varintbuf[:len(varintbuf)-len(p)])
|
||||
}
|
||||
|
||||
func wrstring(b *Biobuf, s string) {
|
||||
@ -497,7 +497,7 @@ func wrpath(ctxt *Link, b *Biobuf, p string) {
|
||||
|
||||
func wrdata(b *Biobuf, v []byte) {
|
||||
wrint(b, int64(len(v)))
|
||||
Bwrite(b, v)
|
||||
b.Write(v)
|
||||
}
|
||||
|
||||
func wrpathsym(ctxt *Link, b *Biobuf, s *LSym) {
|
||||
|
@ -137,7 +137,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
|
||||
if ctxt.Debugvlog != 0 {
|
||||
fmt.Fprintf(ctxt.Bso, "%5.2f noops\n", obj.Cputime())
|
||||
}
|
||||
obj.Bflush(ctxt.Bso)
|
||||
ctxt.Bso.Flush()
|
||||
|
||||
var q *obj.Prog
|
||||
var q1 *obj.Prog
|
||||
@ -346,7 +346,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
|
||||
} else if cursym.Text.Mark&LEAF == 0 {
|
||||
if ctxt.Debugvlog != 0 {
|
||||
fmt.Fprintf(ctxt.Bso, "save suppressed in: %s\n", cursym.Name)
|
||||
obj.Bflush(ctxt.Bso)
|
||||
ctxt.Bso.Flush()
|
||||
}
|
||||
|
||||
cursym.Text.Mark |= LEAF
|
||||
|
@ -99,10 +99,6 @@ func (b *Biobuf) Flush() error {
|
||||
return b.w.Flush()
|
||||
}
|
||||
|
||||
func Bwrite(b *Biobuf, p []byte) (int, error) {
|
||||
return b.w.Write(p)
|
||||
}
|
||||
|
||||
func Bputc(b *Biobuf, c byte) {
|
||||
b.w.WriteByte(c)
|
||||
}
|
||||
@ -189,10 +185,6 @@ func Bungetc(b *Biobuf) {
|
||||
b.numUnget++
|
||||
}
|
||||
|
||||
func Bflush(b *Biobuf) error {
|
||||
return b.w.Flush()
|
||||
}
|
||||
|
||||
func Bterm(b *Biobuf) error {
|
||||
var err error
|
||||
if b.w != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user