mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
[dev.regabi] cmd/compile: introduce cmd/compile/internal/base [generated]
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>
This commit is contained in:
parent
eb3086e5a8
commit
26b66fd60b
67 changed files with 1626 additions and 1542 deletions
|
|
@ -5,6 +5,7 @@
|
|||
package gc
|
||||
|
||||
import (
|
||||
"cmd/compile/internal/base"
|
||||
"cmd/compile/internal/types"
|
||||
"cmd/internal/obj"
|
||||
"fmt"
|
||||
|
|
@ -40,7 +41,7 @@ func (s *InitSchedule) append(n *Node) {
|
|||
// staticInit adds an initialization statement n to the schedule.
|
||||
func (s *InitSchedule) staticInit(n *Node) {
|
||||
if !s.tryStaticInit(n) {
|
||||
if Flag.Percent != 0 {
|
||||
if base.Flag.Percent != 0 {
|
||||
Dump("nonstatic", n)
|
||||
}
|
||||
s.append(n)
|
||||
|
|
@ -62,7 +63,7 @@ func (s *InitSchedule) tryStaticInit(n *Node) bool {
|
|||
return true
|
||||
}
|
||||
lno := setlineno(n)
|
||||
defer func() { lineno = lno }()
|
||||
defer func() { base.Pos = lno }()
|
||||
return s.staticassign(n.Left, n.Right)
|
||||
}
|
||||
|
||||
|
|
@ -256,8 +257,8 @@ func (s *InitSchedule) staticassign(l *Node, r *Node) bool {
|
|||
|
||||
case OCLOSURE:
|
||||
if hasemptycvars(r) {
|
||||
if Debug.Closure > 0 {
|
||||
Warnl(r.Pos, "closure converted to global")
|
||||
if base.Debug.Closure > 0 {
|
||||
base.WarnfAt(r.Pos, "closure converted to global")
|
||||
}
|
||||
// Closures with no captured variables are globals,
|
||||
// so the assignment can be done at link time.
|
||||
|
|
@ -462,7 +463,7 @@ func isStaticCompositeLiteral(n *Node) bool {
|
|||
case OSTRUCTLIT:
|
||||
for _, r := range n.List.Slice() {
|
||||
if r.Op != OSTRUCTKEY {
|
||||
Fatalf("isStaticCompositeLiteral: rhs not OSTRUCTKEY: %v", r)
|
||||
base.Fatalf("isStaticCompositeLiteral: rhs not OSTRUCTKEY: %v", r)
|
||||
}
|
||||
if !isStaticCompositeLiteral(r.Left) {
|
||||
return false
|
||||
|
|
@ -517,7 +518,7 @@ func fixedlit(ctxt initContext, kind initKind, n *Node, var_ *Node, init *Nodes)
|
|||
if r.Op == OKEY {
|
||||
k = indexconst(r.Left)
|
||||
if k < 0 {
|
||||
Fatalf("fixedlit: invalid index %v", r.Left)
|
||||
base.Fatalf("fixedlit: invalid index %v", r.Left)
|
||||
}
|
||||
r = r.Right
|
||||
}
|
||||
|
|
@ -531,7 +532,7 @@ func fixedlit(ctxt initContext, kind initKind, n *Node, var_ *Node, init *Nodes)
|
|||
case OSTRUCTLIT:
|
||||
splitnode = func(r *Node) (*Node, *Node) {
|
||||
if r.Op != OSTRUCTKEY {
|
||||
Fatalf("fixedlit: rhs not OSTRUCTKEY: %v", r)
|
||||
base.Fatalf("fixedlit: rhs not OSTRUCTKEY: %v", r)
|
||||
}
|
||||
if r.Sym.IsBlank() || isBlank {
|
||||
return nblank, r.Left
|
||||
|
|
@ -540,7 +541,7 @@ func fixedlit(ctxt initContext, kind initKind, n *Node, var_ *Node, init *Nodes)
|
|||
return nodSym(ODOT, var_, r.Sym), r.Left
|
||||
}
|
||||
default:
|
||||
Fatalf("fixedlit bad op: %v", n.Op)
|
||||
base.Fatalf("fixedlit bad op: %v", n.Op)
|
||||
}
|
||||
|
||||
for _, r := range n.List.Slice() {
|
||||
|
|
@ -578,7 +579,7 @@ func fixedlit(ctxt initContext, kind initKind, n *Node, var_ *Node, init *Nodes)
|
|||
a = walkstmt(a)
|
||||
init.Append(a)
|
||||
default:
|
||||
Fatalf("fixedlit: bad kind %d", kind)
|
||||
base.Fatalf("fixedlit: bad kind %d", kind)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -610,7 +611,7 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
|
|||
var_ = typecheck(var_, ctxExpr|ctxAssign)
|
||||
nam := stataddr(var_)
|
||||
if nam == nil || nam.Class() != PEXTERN {
|
||||
Fatalf("slicelit: %v", var_)
|
||||
base.Fatalf("slicelit: %v", var_)
|
||||
}
|
||||
slicesym(nam, vstat, t.NumElem())
|
||||
return
|
||||
|
|
@ -709,7 +710,7 @@ func slicelit(ctxt initContext, n *Node, var_ *Node, init *Nodes) {
|
|||
if value.Op == OKEY {
|
||||
index = indexconst(value.Left)
|
||||
if index < 0 {
|
||||
Fatalf("slicelit: invalid index %v", value.Left)
|
||||
base.Fatalf("slicelit: invalid index %v", value.Left)
|
||||
}
|
||||
value = value.Right
|
||||
}
|
||||
|
|
@ -770,7 +771,7 @@ func maplit(n *Node, m *Node, init *Nodes) {
|
|||
// All remaining entries are static. Double-check that.
|
||||
for _, r := range entries {
|
||||
if !isStaticCompositeLiteral(r.Left) || !isStaticCompositeLiteral(r.Right) {
|
||||
Fatalf("maplit: entry is not a literal: %v", r)
|
||||
base.Fatalf("maplit: entry is not a literal: %v", r)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -868,7 +869,7 @@ func anylit(n *Node, var_ *Node, init *Nodes) {
|
|||
t := n.Type
|
||||
switch n.Op {
|
||||
default:
|
||||
Fatalf("anylit: not lit, op=%v node=%v", n.Op, n)
|
||||
base.Fatalf("anylit: not lit, op=%v node=%v", n.Op, n)
|
||||
|
||||
case ONAME, OMETHEXPR:
|
||||
a := nod(OAS, var_, n)
|
||||
|
|
@ -877,7 +878,7 @@ func anylit(n *Node, var_ *Node, init *Nodes) {
|
|||
|
||||
case OPTRLIT:
|
||||
if !t.IsPtr() {
|
||||
Fatalf("anylit: not ptr")
|
||||
base.Fatalf("anylit: not ptr")
|
||||
}
|
||||
|
||||
var r *Node
|
||||
|
|
@ -905,7 +906,7 @@ func anylit(n *Node, var_ *Node, init *Nodes) {
|
|||
|
||||
case OSTRUCTLIT, OARRAYLIT:
|
||||
if !t.IsStruct() && !t.IsArray() {
|
||||
Fatalf("anylit: not struct/array")
|
||||
base.Fatalf("anylit: not struct/array")
|
||||
}
|
||||
|
||||
if var_.isSimpleName() && n.List.Len() > 4 {
|
||||
|
|
@ -951,7 +952,7 @@ func anylit(n *Node, var_ *Node, init *Nodes) {
|
|||
|
||||
case OMAPLIT:
|
||||
if !t.IsMap() {
|
||||
Fatalf("anylit: not map")
|
||||
base.Fatalf("anylit: not map")
|
||||
}
|
||||
maplit(n, var_, init)
|
||||
}
|
||||
|
|
@ -1052,7 +1053,7 @@ func (s *InitSchedule) initplan(n *Node) {
|
|||
s.initplans[n] = p
|
||||
switch n.Op {
|
||||
default:
|
||||
Fatalf("initplan")
|
||||
base.Fatalf("initplan")
|
||||
|
||||
case OARRAYLIT, OSLICELIT:
|
||||
var k int64
|
||||
|
|
@ -1060,7 +1061,7 @@ func (s *InitSchedule) initplan(n *Node) {
|
|||
if a.Op == OKEY {
|
||||
k = indexconst(a.Left)
|
||||
if k < 0 {
|
||||
Fatalf("initplan arraylit: invalid index %v", a.Left)
|
||||
base.Fatalf("initplan arraylit: invalid index %v", a.Left)
|
||||
}
|
||||
a = a.Right
|
||||
}
|
||||
|
|
@ -1071,7 +1072,7 @@ func (s *InitSchedule) initplan(n *Node) {
|
|||
case OSTRUCTLIT:
|
||||
for _, a := range n.List.Slice() {
|
||||
if a.Op != OSTRUCTKEY {
|
||||
Fatalf("initplan structlit")
|
||||
base.Fatalf("initplan structlit")
|
||||
}
|
||||
if a.Sym.IsBlank() {
|
||||
continue
|
||||
|
|
@ -1082,7 +1083,7 @@ func (s *InitSchedule) initplan(n *Node) {
|
|||
case OMAPLIT:
|
||||
for _, a := range n.List.Slice() {
|
||||
if a.Op != OKEY {
|
||||
Fatalf("initplan maplit")
|
||||
base.Fatalf("initplan maplit")
|
||||
}
|
||||
s.addvalue(p, -1, a.Right)
|
||||
}
|
||||
|
|
@ -1155,12 +1156,12 @@ func isvaluelit(n *Node) bool {
|
|||
|
||||
func genAsStatic(as *Node) {
|
||||
if as.Left.Type == nil {
|
||||
Fatalf("genAsStatic as.Left not typechecked")
|
||||
base.Fatalf("genAsStatic as.Left not typechecked")
|
||||
}
|
||||
|
||||
nam := stataddr(as.Left)
|
||||
if nam == nil || (nam.Class() != PEXTERN && as.Left != nblank) {
|
||||
Fatalf("genAsStatic: lhs %v", as.Left)
|
||||
base.Fatalf("genAsStatic: lhs %v", as.Left)
|
||||
}
|
||||
|
||||
switch {
|
||||
|
|
@ -1169,6 +1170,6 @@ func genAsStatic(as *Node) {
|
|||
case (as.Right.Op == ONAME || as.Right.Op == OMETHEXPR) && as.Right.Class() == PFUNC:
|
||||
pfuncsym(nam, as.Right)
|
||||
default:
|
||||
Fatalf("genAsStatic: rhs %v", as.Right)
|
||||
base.Fatalf("genAsStatic: rhs %v", as.Right)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue