mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
Move Flag, Debug, Ctxt, Exit, and error messages to
new package cmd/compile/internal/base.
These are the core functionality that everything in gc uses
and which otherwise prevent splitting any other code
out of gc into different packages.
A minor milestone: the compiler source code
no longer contains the string "yy".
[git-generate]
cd src/cmd/compile/internal/gc
rf '
mv atExit AtExit
mv Ctxt atExitFuncs AtExit Exit base.go
mv lineno Pos
mv linestr FmtPos
mv flusherrors FlushErrors
mv yyerror Errorf
mv yyerrorl ErrorfAt
mv yyerrorv ErrorfVers
mv noder.yyerrorpos noder.errorAt
mv Warnl WarnfAt
mv errorexit ErrorExit
mv base.go debug.go flag.go print.go cmd/compile/internal/base
'
: # update comments
sed -i '' 's/yyerrorl/ErrorfAt/g; s/yyerror/Errorf/g' *.go
: # bootstrap.go is not built by default so invisible to rf
sed -i '' 's/Fatalf/base.Fatalf/' bootstrap.go
goimports -w bootstrap.go
: # update cmd/dist to add internal/base
cd ../../../dist
sed -i '' '/internal.amd64/a\
"cmd/compile/internal/base",
' buildtool.go
gofmt -w buildtool.go
Change-Id: I59903c7084222d6eaee38823fd222159ba24a31a
Reviewed-on: https://go-review.googlesource.com/c/go/+/272250
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
87 lines
2.3 KiB
Go
87 lines
2.3 KiB
Go
// Copyright 2009 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 gc
|
|
|
|
import (
|
|
"cmd/compile/internal/base"
|
|
"cmd/compile/internal/types"
|
|
"cmd/internal/obj"
|
|
"cmd/internal/src"
|
|
"strconv"
|
|
)
|
|
|
|
// sysfunc looks up Go function name in package runtime. This function
|
|
// must follow the internal calling convention.
|
|
func sysfunc(name string) *obj.LSym {
|
|
s := Runtimepkg.Lookup(name)
|
|
s.SetFunc(true)
|
|
return s.Linksym()
|
|
}
|
|
|
|
// sysvar looks up a variable (or assembly function) name in package
|
|
// runtime. If this is a function, it may have a special calling
|
|
// convention.
|
|
func sysvar(name string) *obj.LSym {
|
|
return Runtimepkg.Lookup(name).Linksym()
|
|
}
|
|
|
|
// isParamStackCopy reports whether this is the on-stack copy of a
|
|
// function parameter that moved to the heap.
|
|
func (n *Node) isParamStackCopy() bool {
|
|
return n.Op == ONAME && (n.Class() == PPARAM || n.Class() == PPARAMOUT) && n.Name.Param.Heapaddr != nil
|
|
}
|
|
|
|
// isParamHeapCopy reports whether this is the on-heap copy of
|
|
// a function parameter that moved to the heap.
|
|
func (n *Node) isParamHeapCopy() bool {
|
|
return n.Op == ONAME && n.Class() == PAUTOHEAP && n.Name.Param.Stackcopy != nil
|
|
}
|
|
|
|
// autotmpname returns the name for an autotmp variable numbered n.
|
|
func autotmpname(n int) string {
|
|
// Give each tmp a different name so that they can be registerized.
|
|
// Add a preceding . to avoid clashing with legal names.
|
|
const prefix = ".autotmp_"
|
|
// Start with a buffer big enough to hold a large n.
|
|
b := []byte(prefix + " ")[:len(prefix)]
|
|
b = strconv.AppendInt(b, int64(n), 10)
|
|
return types.InternString(b)
|
|
}
|
|
|
|
// make a new Node off the books
|
|
func tempAt(pos src.XPos, curfn *Node, t *types.Type) *Node {
|
|
if curfn == nil {
|
|
base.Fatalf("no curfn for tempAt")
|
|
}
|
|
if curfn.Op == OCLOSURE {
|
|
Dump("tempAt", curfn)
|
|
base.Fatalf("adding tempAt to wrong closure function")
|
|
}
|
|
if t == nil {
|
|
base.Fatalf("tempAt called with nil type")
|
|
}
|
|
|
|
s := &types.Sym{
|
|
Name: autotmpname(len(curfn.Func.Dcl)),
|
|
Pkg: localpkg,
|
|
}
|
|
n := newnamel(pos, s)
|
|
s.Def = asTypesNode(n)
|
|
n.Type = t
|
|
n.SetClass(PAUTO)
|
|
n.Esc = EscNever
|
|
n.Name.Curfn = curfn
|
|
n.Name.SetUsed(true)
|
|
n.Name.SetAutoTemp(true)
|
|
curfn.Func.Dcl = append(curfn.Func.Dcl, n)
|
|
|
|
dowidth(t)
|
|
|
|
return n.Orig
|
|
}
|
|
|
|
func temp(t *types.Type) *Node {
|
|
return tempAt(base.Pos, Curfn, t)
|
|
}
|