diff options
author | Russ Cox <rsc@golang.org> | 2020-11-19 21:09:22 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2020-11-25 16:53:33 +0000 |
commit | 84e2bd611f9b62ec3b581f8a0d932dc4252ceb67 (patch) | |
tree | ec2c98509844635a32e14fb09a2cbf9fcda6a291 /src/cmd/compile/internal/gc/obj.go | |
parent | 331b8b4797bc4e134a8d8b78bf1c060689144145 (diff) | |
download | go-84e2bd611f9b62ec3b581f8a0d932dc4252ceb67.tar.gz go-84e2bd611f9b62ec3b581f8a0d932dc4252ceb67.zip |
[dev.regabi] cmd/compile: introduce cmd/compile/internal/ir [generated]
If we want to break up package gc at all, we will need to move
the compiler IR it defines into a separate package that can be
imported by packages that gc itself imports. This CL does that.
It also removes the TINT8 etc aliases so that all code is clear
about which package things are coming from.
This CL is automatically generated by the script below.
See the comments in the script for details about the changes.
[git-generate]
cd src/cmd/compile/internal/gc
rf '
# These names were never fully qualified
# when the types package was added.
# Do it now, to avoid confusion about where they live.
inline -rm \
Txxx \
TINT8 \
TUINT8 \
TINT16 \
TUINT16 \
TINT32 \
TUINT32 \
TINT64 \
TUINT64 \
TINT \
TUINT \
TUINTPTR \
TCOMPLEX64 \
TCOMPLEX128 \
TFLOAT32 \
TFLOAT64 \
TBOOL \
TPTR \
TFUNC \
TSLICE \
TARRAY \
TSTRUCT \
TCHAN \
TMAP \
TINTER \
TFORW \
TANY \
TSTRING \
TUNSAFEPTR \
TIDEAL \
TNIL \
TBLANK \
TFUNCARGS \
TCHANARGS \
NTYPE \
BADWIDTH
# esc.go and escape.go do not need to be split.
# Append esc.go onto the end of escape.go.
mv esc.go escape.go
# Pull out the type format installation from func Main,
# so it can be carried into package ir.
mv Main:/Sconv.=/-0,/TypeLinkSym/-1 InstallTypeFormats
# Names that need to be exported for use by code left in gc.
mv Isconst IsConst
mv asNode AsNode
mv asNodes AsNodes
mv asTypesNode AsTypesNode
mv basicnames BasicTypeNames
mv builtinpkg BuiltinPkg
mv consttype ConstType
mv dumplist DumpList
mv fdumplist FDumpList
mv fmtMode FmtMode
mv goopnames OpNames
mv inspect Inspect
mv inspectList InspectList
mv localpkg LocalPkg
mv nblank BlankNode
mv numImport NumImport
mv opprec OpPrec
mv origSym OrigSym
mv stmtwithinit StmtWithInit
mv dump DumpAny
mv fdump FDumpAny
mv nod Nod
mv nodl NodAt
mv newname NewName
mv newnamel NewNameAt
mv assertRepresents AssertValidTypeForConst
mv represents ValidTypeForConst
mv nodlit NewLiteral
# Types and fields that need to be exported for use by gc.
mv nowritebarrierrecCallSym SymAndPos
mv SymAndPos.lineno SymAndPos.Pos
mv SymAndPos.target SymAndPos.Sym
mv Func.lsym Func.LSym
mv Func.setWBPos Func.SetWBPos
mv Func.numReturns Func.NumReturns
mv Func.numDefers Func.NumDefers
mv Func.nwbrCalls Func.NWBRCalls
# initLSym is an algorithm left behind in gc,
# not an operation on Func itself.
mv Func.initLSym initLSym
mv nodeQueue NodeQueue
mv NodeQueue.empty NodeQueue.Empty
mv NodeQueue.popLeft NodeQueue.PopLeft
mv NodeQueue.pushRight NodeQueue.PushRight
# Many methods on Node are actually algorithms that
# would apply to any node implementation.
# Those become plain functions.
mv Node.funcname FuncName
mv Node.isBlank IsBlank
mv Node.isGoConst isGoConst
mv Node.isNil IsNil
mv Node.isParamHeapCopy isParamHeapCopy
mv Node.isParamStackCopy isParamStackCopy
mv Node.isSimpleName isSimpleName
mv Node.mayBeShared MayBeShared
mv Node.pkgFuncName PkgFuncName
mv Node.backingArrayPtrLen backingArrayPtrLen
mv Node.isterminating isTermNode
mv Node.labeledControl labeledControl
mv Nodes.isterminating isTermNodes
mv Nodes.sigerr fmtSignature
mv Node.MethodName methodExprName
mv Node.MethodFunc methodExprFunc
mv Node.IsMethod IsMethod
# Every node will need to implement RawCopy;
# Copy and SepCopy algorithms will use it.
mv Node.rawcopy Node.RawCopy
mv Node.copy Copy
mv Node.sepcopy SepCopy
# Extract Node.Format method body into func FmtNode,
# but leave method wrapper behind.
mv Node.Format:0,$ FmtNode
# Formatting helpers that will apply to all node implementations.
mv Node.Line Line
mv Node.exprfmt exprFmt
mv Node.jconv jconvFmt
mv Node.modeString modeString
mv Node.nconv nconvFmt
mv Node.nodedump nodeDumpFmt
mv Node.nodefmt nodeFmt
mv Node.stmtfmt stmtFmt
# Constant support needed for code moving to ir.
mv okforconst OKForConst
mv vconv FmtConst
mv int64Val Int64Val
mv float64Val Float64Val
mv Node.ValueInterface ConstValue
# Organize code into files.
mv LocalPkg BuiltinPkg ir.go
mv NumImport InstallTypeFormats Line fmt.go
mv syntax.go Nod NodAt NewNameAt Class Pxxx PragmaFlag Nointerface SymAndPos \
AsNode AsTypesNode BlankNode OrigSym \
Node.SliceBounds Node.SetSliceBounds Op.IsSlice3 \
IsConst Node.Int64Val Node.CanInt64 Node.Uint64Val Node.BoolVal Node.StringVal \
Node.RawCopy SepCopy Copy \
IsNil IsBlank IsMethod \
Node.Typ Node.StorageClass node.go
mv ConstType ConstValue Int64Val Float64Val AssertValidTypeForConst ValidTypeForConst NewLiteral idealType OKForConst val.go
# Move files to new ir package.
mv bitset.go class_string.go dump.go fmt.go \
ir.go node.go op_string.go val.go \
sizeof_test.go cmd/compile/internal/ir
'
: # fix mkbuiltin.go to generate the changes made to builtin.go during rf
sed -i '' '
s/\[T/[types.T/g
s/\*Node/*ir.Node/g
/internal\/types/c \
fmt.Fprintln(&b, `import (`) \
fmt.Fprintln(&b, ` "cmd/compile/internal/ir"`) \
fmt.Fprintln(&b, ` "cmd/compile/internal/types"`) \
fmt.Fprintln(&b, `)`)
' mkbuiltin.go
gofmt -w mkbuiltin.go
: # update cmd/dist to add internal/ir
cd ../../../dist
sed -i '' '/compile.internal.gc/a\
"cmd/compile/internal/ir",
' buildtool.go
gofmt -w buildtool.go
: # update cmd/compile TestFormats
cd ../..
go install std cmd
cd cmd/compile
go test -u || go test # first one updates but fails; second passes
Change-Id: I5f7caf6b20629b51970279e81231a3574d5b51db
Reviewed-on: https://go-review.googlesource.com/c/go/+/273008
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/gc/obj.go')
-rw-r--r-- | src/cmd/compile/internal/gc/obj.go | 81 |
1 files changed, 41 insertions, 40 deletions
diff --git a/src/cmd/compile/internal/gc/obj.go b/src/cmd/compile/internal/gc/obj.go index 6c659c91c7..2961dbf636 100644 --- a/src/cmd/compile/internal/gc/obj.go +++ b/src/cmd/compile/internal/gc/obj.go @@ -6,6 +6,7 @@ package gc import ( "cmd/compile/internal/base" + "cmd/compile/internal/ir" "cmd/compile/internal/types" "cmd/internal/bio" "cmd/internal/obj" @@ -83,7 +84,7 @@ func printObjHeader(bout *bio.Writer) { if base.Flag.BuildID != "" { fmt.Fprintf(bout, "build id %q\n", base.Flag.BuildID) } - if localpkg.Name == "main" { + if ir.LocalPkg.Name == "main" { fmt.Fprintf(bout, "main\n") } fmt.Fprintf(bout, "\n") // header ends with blank line @@ -141,7 +142,7 @@ func dumpdata() { for { for i := xtops; i < len(xtop); i++ { n := xtop[i] - if n.Op == ODCLFUNC { + if n.Op == ir.ODCLFUNC { funccompile(n) } } @@ -199,16 +200,16 @@ func dumpLinkerObj(bout *bio.Writer) { } func addptabs() { - if !base.Ctxt.Flag_dynlink || localpkg.Name != "main" { + if !base.Ctxt.Flag_dynlink || ir.LocalPkg.Name != "main" { return } for _, exportn := range exportlist { s := exportn.Sym - n := asNode(s.Def) + n := ir.AsNode(s.Def) if n == nil { continue } - if n.Op != ONAME { + if n.Op != ir.ONAME { continue } if !types.IsExported(s.Name) { @@ -217,37 +218,37 @@ func addptabs() { if s.Pkg.Name != "main" { continue } - if n.Type.Etype == TFUNC && n.Class() == PFUNC { + if n.Type.Etype == types.TFUNC && n.Class() == ir.PFUNC { // function - ptabs = append(ptabs, ptabEntry{s: s, t: asNode(s.Def).Type}) + ptabs = append(ptabs, ptabEntry{s: s, t: ir.AsNode(s.Def).Type}) } else { // variable - ptabs = append(ptabs, ptabEntry{s: s, t: types.NewPtr(asNode(s.Def).Type)}) + ptabs = append(ptabs, ptabEntry{s: s, t: types.NewPtr(ir.AsNode(s.Def).Type)}) } } } -func dumpGlobal(n *Node) { +func dumpGlobal(n *ir.Node) { if n.Type == nil { base.Fatalf("external %v nil type\n", n) } - if n.Class() == PFUNC { + if n.Class() == ir.PFUNC { return } - if n.Sym.Pkg != localpkg { + if n.Sym.Pkg != ir.LocalPkg { return } dowidth(n.Type) ggloblnod(n) } -func dumpGlobalConst(n *Node) { +func dumpGlobalConst(n *ir.Node) { // only export typed constants t := n.Type if t == nil { return } - if n.Sym.Pkg != localpkg { + if n.Sym.Pkg != ir.LocalPkg { return } // only export integer constants for now @@ -257,21 +258,21 @@ func dumpGlobalConst(n *Node) { v := n.Val() if t.IsUntyped() { // Export untyped integers as int (if they fit). - t = types.Types[TINT] + t = types.Types[types.TINT] if doesoverflow(v, t) { return } } - base.Ctxt.DwarfIntConst(base.Ctxt.Pkgpath, n.Sym.Name, typesymname(t), int64Val(t, v)) + base.Ctxt.DwarfIntConst(base.Ctxt.Pkgpath, n.Sym.Name, typesymname(t), ir.Int64Val(t, v)) } func dumpglobls() { // add globals for _, n := range externdcl { switch n.Op { - case ONAME: + case ir.ONAME: dumpGlobal(n) - case OLITERAL: + case ir.OLITERAL: dumpGlobalConst(n) } } @@ -474,12 +475,12 @@ func fileStringSym(pos src.XPos, file string, readonly bool, hash []byte) (*obj. var slicedataGen int -func slicedata(pos src.XPos, s string) *Node { +func slicedata(pos src.XPos, s string) *ir.Node { slicedataGen++ symname := fmt.Sprintf(".gobytes.%d", slicedataGen) - sym := localpkg.Lookup(symname) - symnode := newname(sym) - sym.Def = asTypesNode(symnode) + sym := ir.LocalPkg.Lookup(symname) + symnode := NewName(sym) + sym.Def = ir.AsTypesNode(symnode) lsym := sym.Linksym() off := dstringdata(lsym, 0, s, pos, "slice") @@ -488,8 +489,8 @@ func slicedata(pos src.XPos, s string) *Node { return symnode } -func slicebytes(nam *Node, s string) { - if nam.Op != ONAME { +func slicebytes(nam *ir.Node, s string) { + if nam.Op != ir.ONAME { base.Fatalf("slicebytes %v", nam) } slicesym(nam, slicedata(nam.Pos, s), int64(len(s))) @@ -529,10 +530,10 @@ func dsymptrWeakOff(s *obj.LSym, off int, x *obj.LSym) int { // slicesym writes a static slice symbol {&arr, lencap, lencap} to n. // arr must be an ONAME. slicesym does not modify n. -func slicesym(n, arr *Node, lencap int64) { +func slicesym(n, arr *ir.Node, lencap int64) { s := n.Sym.Linksym() off := n.Xoffset - if arr.Op != ONAME { + if arr.Op != ir.ONAME { base.Fatalf("slicesym non-name arr %v", arr) } s.WriteAddr(base.Ctxt, off, Widthptr, arr.Sym.Linksym(), arr.Xoffset) @@ -542,14 +543,14 @@ func slicesym(n, arr *Node, lencap int64) { // addrsym writes the static address of a to n. a must be an ONAME. // Neither n nor a is modified. -func addrsym(n, a *Node) { - if n.Op != ONAME { +func addrsym(n, a *ir.Node) { + if n.Op != ir.ONAME { base.Fatalf("addrsym n op %v", n.Op) } if n.Sym == nil { base.Fatalf("addrsym nil n sym") } - if a.Op != ONAME { + if a.Op != ir.ONAME { base.Fatalf("addrsym a op %v", a.Op) } s := n.Sym.Linksym() @@ -558,14 +559,14 @@ func addrsym(n, a *Node) { // pfuncsym writes the static address of f to n. f must be a global function. // Neither n nor f is modified. -func pfuncsym(n, f *Node) { - if n.Op != ONAME { +func pfuncsym(n, f *ir.Node) { + if n.Op != ir.ONAME { base.Fatalf("pfuncsym n op %v", n.Op) } if n.Sym == nil { base.Fatalf("pfuncsym nil n sym") } - if f.Class() != PFUNC { + if f.Class() != ir.PFUNC { base.Fatalf("pfuncsym class not PFUNC %d", f.Class()) } s := n.Sym.Linksym() @@ -574,8 +575,8 @@ func pfuncsym(n, f *Node) { // litsym writes the static literal c to n. // Neither n nor c is modified. -func litsym(n, c *Node, wid int) { - if n.Op != ONAME { +func litsym(n, c *ir.Node, wid int) { + if n.Op != ir.ONAME { base.Fatalf("litsym n op %v", n.Op) } if n.Sym == nil { @@ -584,10 +585,10 @@ func litsym(n, c *Node, wid int) { if !types.Identical(n.Type, c.Type) { base.Fatalf("litsym: type mismatch: %v has type %v, but %v has type %v", n, n.Type, c, c.Type) } - if c.Op == ONIL { + if c.Op == ir.ONIL { return } - if c.Op != OLITERAL { + if c.Op != ir.OLITERAL { base.Fatalf("litsym c op %v", c.Op) } s := n.Sym.Linksym() @@ -597,14 +598,14 @@ func litsym(n, c *Node, wid int) { s.WriteInt(base.Ctxt, n.Xoffset, wid, i) case constant.Int: - s.WriteInt(base.Ctxt, n.Xoffset, wid, int64Val(n.Type, u)) + s.WriteInt(base.Ctxt, n.Xoffset, wid, ir.Int64Val(n.Type, u)) case constant.Float: f, _ := constant.Float64Val(u) switch n.Type.Etype { - case TFLOAT32: + case types.TFLOAT32: s.WriteFloat32(base.Ctxt, n.Xoffset, float32(f)) - case TFLOAT64: + case types.TFLOAT64: s.WriteFloat64(base.Ctxt, n.Xoffset, f) } @@ -612,10 +613,10 @@ func litsym(n, c *Node, wid int) { re, _ := constant.Float64Val(constant.Real(u)) im, _ := constant.Float64Val(constant.Imag(u)) switch n.Type.Etype { - case TCOMPLEX64: + case types.TCOMPLEX64: s.WriteFloat32(base.Ctxt, n.Xoffset, float32(re)) s.WriteFloat32(base.Ctxt, n.Xoffset+4, float32(im)) - case TCOMPLEX128: + case types.TCOMPLEX128: s.WriteFloat64(base.Ctxt, n.Xoffset, re) s.WriteFloat64(base.Ctxt, n.Xoffset+8, im) } |