diff options
| author | Russ Cox <rsc@golang.org> | 2015-01-19 14:34:58 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2015-01-21 03:02:27 +0000 |
| commit | d6f6e420fcea98a84a9c6a69a7bcf81ddca7ea74 (patch) | |
| tree | 1248e9ea9a782ad165f211f7142ebe9c48bccb4c /src/cmd/internal/obj/util.go | |
| parent | db52315c88e588b87895dcb159d1b4886f355e92 (diff) | |
| download | go-d6f6e420fcea98a84a9c6a69a7bcf81ddca7ea74.tar.xz | |
[dev.cc] cmd/internal/obj: convert liblink C to Go
This CL adds the real cmd/internal/obj packages.
Collectively they correspond to the liblink library.
The conversion was done using rsc.io/c2go's run script
at rsc.io/c2go repo version 706fac7.
This is not the final conversion, just the first working draft.
There will be more updates, but this works well enough
to use with go tool objwriter and pass all.bash.
Change-Id: I9359e835425f995a392bb2fcdbebf29511477bed
Reviewed-on: https://go-review.googlesource.com/3046
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd/internal/obj/util.go')
| -rw-r--r-- | src/cmd/internal/obj/util.go | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/src/cmd/internal/obj/util.go b/src/cmd/internal/obj/util.go new file mode 100644 index 0000000000..842e42ba50 --- /dev/null +++ b/src/cmd/internal/obj/util.go @@ -0,0 +1,113 @@ +// 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" + "go/build" + "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 + r *bufio.Reader + w *bufio.Writer +} + +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() +} + +func Getgoroot() string { + return build.Default.GOROOT +} + +func Getgoarch() string { + return build.Default.GOARCH +} + +func Getgoos() string { + return build.Default.GOOS +} + +func Atoi(s string) int { + i, _ := strconv.Atoi(s) + return i +} + +func Getgoarm() string { + env := os.Getenv("GOARM") + if env != "" { + return env + } + return "5" +} + +func (p *Prog) Line() string { + return linklinefmt(p.Ctxt, int(p.Lineno), false, false) +} + +func (p *Prog) String() string { + if p.Ctxt == nil { + return fmt.Sprintf("<Prog without ctxt>") + } + return p.Ctxt.Arch.Pconv(p) +} |
