2015-01-19 14:34:58 -05:00
|
|
|
// Copyright 2015 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package obj
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bufio"
|
|
|
|
|
"fmt"
|
|
|
|
|
"io"
|
|
|
|
|
"os"
|
|
|
|
|
"strconv"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var start time.Time
|
|
|
|
|
|
|
|
|
|
func Cputime() float64 {
|
|
|
|
|
if start.IsZero() {
|
|
|
|
|
start = time.Now()
|
|
|
|
|
}
|
|
|
|
|
return time.Since(start).Seconds()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Biobuf struct {
|
|
|
|
|
unget int
|
|
|
|
|
haveUnget bool
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
f *os.File
|
2015-01-19 14:34:58 -05:00
|
|
|
r *bufio.Reader
|
|
|
|
|
w *bufio.Writer
|
|
|
|
|
}
|
|
|
|
|
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
func Bopenw(name string) (*Biobuf, error) {
|
|
|
|
|
f, err := os.Open(name)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &Biobuf{f: f, w: bufio.NewWriter(f)}, nil
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 14:34:58 -05:00
|
|
|
func Binitw(w io.Writer) *Biobuf {
|
|
|
|
|
return &Biobuf{w: bufio.NewWriter(w)}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Biobuf) Write(p []byte) (int, error) {
|
|
|
|
|
return b.w.Write(p)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Bgetc(b *Biobuf) int {
|
|
|
|
|
if b.haveUnget {
|
|
|
|
|
b.haveUnget = false
|
|
|
|
|
return int(b.unget)
|
|
|
|
|
}
|
|
|
|
|
c, err := b.r.ReadByte()
|
|
|
|
|
if err != nil {
|
|
|
|
|
b.unget = -1
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
b.unget = int(c)
|
|
|
|
|
return int(c)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Bungetc(b *Biobuf) {
|
|
|
|
|
b.haveUnget = true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Boffset(b *Biobuf) int64 {
|
|
|
|
|
panic("Boffset")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Bflush(b *Biobuf) error {
|
|
|
|
|
return b.w.Flush()
|
|
|
|
|
}
|
|
|
|
|
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
func Bterm(b *Biobuf) error {
|
|
|
|
|
err := b.w.Flush()
|
|
|
|
|
err1 := b.f.Close()
|
|
|
|
|
if err == nil {
|
|
|
|
|
err = err1
|
|
|
|
|
}
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-21 12:27:36 -05:00
|
|
|
func envOr(key, value string) string {
|
|
|
|
|
if x := os.Getenv(key); x != "" {
|
|
|
|
|
return x
|
|
|
|
|
}
|
|
|
|
|
return value
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 14:34:58 -05:00
|
|
|
func Getgoroot() string {
|
2015-01-21 12:27:36 -05:00
|
|
|
return envOr("GOROOT", defaultGOROOT)
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Getgoarch() string {
|
2015-01-21 12:27:36 -05:00
|
|
|
return envOr("GOARCH", defaultGOARCH)
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Getgoos() string {
|
2015-01-21 12:27:36 -05:00
|
|
|
return envOr("GOOS", defaultGOOS)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Getgoarm() string {
|
|
|
|
|
return envOr("GOARM", defaultGOARM)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Getgoversion() string {
|
|
|
|
|
return version
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Atoi(s string) int {
|
|
|
|
|
i, _ := strconv.Atoi(s)
|
|
|
|
|
return i
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Prog) Line() string {
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
return Linklinefmt(p.Ctxt, int(p.Lineno), false, false)
|
2015-01-19 14:34:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (p *Prog) String() string {
|
|
|
|
|
if p.Ctxt == nil {
|
|
|
|
|
return fmt.Sprintf("<Prog without ctxt>")
|
|
|
|
|
}
|
|
|
|
|
return p.Ctxt.Arch.Pconv(p)
|
|
|
|
|
}
|
2015-01-21 21:45:29 -05:00
|
|
|
|
|
|
|
|
func (ctxt *Link) NewProg() *Prog {
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
p := new(Prog) // should be the only call to this; all others should use ctxt.NewProg
|
2015-01-21 21:45:29 -05:00
|
|
|
p.Ctxt = ctxt
|
|
|
|
|
return p
|
|
|
|
|
}
|
[dev.cc] cmd/internal/obj: reconvert from liblink
cmd/internal/obj reconverted using rsc.io/c2go rev 2a95256.
- Brings in new, more regular Prog, Addr definitions
- Add Prog* argument to oclass in liblink/asm[68].c, for c2go conversion.
- Update objwriter for change in TEXT size encoding.
- Merge 5a, 6a, 8a, 9a changes into new5a, new6a, new8a, new9a (by hand).
- Add +build ignore to cmd/asm/internal/{addr,arch,asm}, cmd/asm.
They need to be updated for the changes.
- Reenable verifyAsm in cmd/go.
- Reenable GOOBJ=2 mode by default in liblink.
All architectures build successfully again.
Change-Id: I2c845c5d365aa484b570476898171bee657b626d
Reviewed-on: https://go-review.googlesource.com/3963
Reviewed-by: Rob Pike <r@golang.org>
2015-02-05 03:57:44 -05:00
|
|
|
|
|
|
|
|
func (ctxt *Link) Line(n int) string {
|
|
|
|
|
return Linklinefmt(ctxt, n, false, false)
|
|
|
|
|
}
|