mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[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>
This commit is contained in:
parent
db52315c88
commit
d6f6e420fc
40 changed files with 27998 additions and 7 deletions
113
src/cmd/internal/obj/util.go
Normal file
113
src/cmd/internal/obj/util.go
Normal file
|
|
@ -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)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue