mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile, cmd/link: create from 5g, 5l, etc
Trivial merging of 5g, 6g, ... into go tool compile, and similarlly 5l, 6l, ... into go tool link. The files compile/main.go and link/main.go are new. Everything else in those directories is a move followed by change of imports and package name. This CL breaks the build. Manual fixups are in the next CL. See golang-dev thread titled "go tool compile, etc" for background. Change-Id: Id35ff5a5859ad9037c61275d637b1bd51df6828b Reviewed-on: https://go-review.googlesource.com/10287 Reviewed-by: Dave Cheney <dave@cheney.net> Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
parent
2a141dedc4
commit
17eba6e6b7
156 changed files with 186 additions and 118 deletions
103
src/cmd/compile/internal/gc/util.go
Normal file
103
src/cmd/compile/internal/gc/util.go
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
package gc
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (n *Node) Line() string {
|
||||
return Ctxt.LineHist.LineString(int(n.Lineno))
|
||||
}
|
||||
|
||||
func atoi(s string) int {
|
||||
// NOTE: Not strconv.Atoi, accepts hex and octal prefixes.
|
||||
n, _ := strconv.ParseInt(s, 0, 0)
|
||||
return int(n)
|
||||
}
|
||||
|
||||
func isalnum(c int) bool {
|
||||
return isalpha(c) || isdigit(c)
|
||||
}
|
||||
|
||||
func isalpha(c int) bool {
|
||||
return 'A' <= c && c <= 'Z' || 'a' <= c && c <= 'z'
|
||||
}
|
||||
|
||||
func isdigit(c int) bool {
|
||||
return '0' <= c && c <= '9'
|
||||
}
|
||||
|
||||
func plan9quote(s string) string {
|
||||
if s == "" {
|
||||
return "'" + strings.Replace(s, "'", "''", -1) + "'"
|
||||
}
|
||||
for i := 0; i < len(s); i++ {
|
||||
if s[i] <= ' ' || s[i] == '\'' {
|
||||
return "'" + strings.Replace(s, "'", "''", -1) + "'"
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// strings.Compare, introduced in Go 1.5.
|
||||
func stringsCompare(a, b string) int {
|
||||
if a == b {
|
||||
return 0
|
||||
}
|
||||
if a < b {
|
||||
return -1
|
||||
}
|
||||
return +1
|
||||
}
|
||||
|
||||
var atExitFuncs []func()
|
||||
|
||||
func AtExit(f func()) {
|
||||
atExitFuncs = append(atExitFuncs, f)
|
||||
}
|
||||
|
||||
func Exit(code int) {
|
||||
for i := len(atExitFuncs) - 1; i >= 0; i-- {
|
||||
f := atExitFuncs[i]
|
||||
atExitFuncs = atExitFuncs[:i]
|
||||
f()
|
||||
}
|
||||
os.Exit(code)
|
||||
}
|
||||
|
||||
var (
|
||||
cpuprofile string
|
||||
memprofile string
|
||||
memprofilerate int64
|
||||
)
|
||||
|
||||
func startProfile() {
|
||||
if cpuprofile != "" {
|
||||
f, err := os.Create(cpuprofile)
|
||||
if err != nil {
|
||||
Fatal("%v", err)
|
||||
}
|
||||
if err := pprof.StartCPUProfile(f); err != nil {
|
||||
Fatal("%v", err)
|
||||
}
|
||||
AtExit(pprof.StopCPUProfile)
|
||||
}
|
||||
if memprofile != "" {
|
||||
if memprofilerate != 0 {
|
||||
runtime.MemProfileRate = int(memprofilerate)
|
||||
}
|
||||
f, err := os.Create(memprofile)
|
||||
if err != nil {
|
||||
Fatal("%v", err)
|
||||
}
|
||||
AtExit(func() {
|
||||
runtime.GC() // profile all outstanding allocations
|
||||
if err := pprof.WriteHeapProfile(f); err != nil {
|
||||
Fatal("%v", err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue