aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/gc/init.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/compile/internal/gc/init.go')
-rw-r--r--src/cmd/compile/internal/gc/init.go45
1 files changed, 24 insertions, 21 deletions
diff --git a/src/cmd/compile/internal/gc/init.go b/src/cmd/compile/internal/gc/init.go
index ec9cc4bddc..2b7ecd1d05 100644
--- a/src/cmd/compile/internal/gc/init.go
+++ b/src/cmd/compile/internal/gc/init.go
@@ -5,6 +5,8 @@
package gc
import (
+ "cmd/compile/internal/base"
+ "cmd/compile/internal/ir"
"cmd/compile/internal/types"
"cmd/internal/obj"
)
@@ -15,8 +17,9 @@ import (
// the name, normally "pkg.init", is altered to "pkg.init.0".
var renameinitgen int
-// Dummy function for autotmps generated during typechecking.
-var dummyInitFn = nod(ODCLFUNC, nil, nil)
+// Function collecting autotmps generated during typechecking,
+// to be included in the package-level init function.
+var initTodo = ir.Nod(ir.ODCLFUNC, nil, nil)
func renameinit() *types.Sym {
s := lookupN("init.", renameinitgen)
@@ -30,7 +33,7 @@ func renameinit() *types.Sym {
// 1) Initialize all of the packages the current package depends on.
// 2) Initialize all the variables that have initializers.
// 3) Run any init functions.
-func fninit(n []*Node) {
+func fninit(n []ir.Node) {
nf := initOrder(n)
var deps []*obj.LSym // initTask records for packages the current package depends on
@@ -43,16 +46,16 @@ func fninit(n []*Node) {
// Make a function that contains all the initialization statements.
if len(nf) > 0 {
- lineno = nf[0].Pos // prolog/epilog gets line number of first init stmt
+ base.Pos = nf[0].Pos() // prolog/epilog gets line number of first init stmt
initializers := lookup("init")
- fn := dclfunc(initializers, nod(OTFUNC, nil, nil))
- for _, dcl := range dummyInitFn.Func.Dcl {
- dcl.Name.Curfn = fn
+ fn := dclfunc(initializers, ir.Nod(ir.OTFUNC, nil, nil))
+ for _, dcl := range initTodo.Func().Dcl {
+ dcl.Name().Curfn = fn
}
- fn.Func.Dcl = append(fn.Func.Dcl, dummyInitFn.Func.Dcl...)
- dummyInitFn.Func.Dcl = nil
+ fn.Func().Dcl = append(fn.Func().Dcl, initTodo.Func().Dcl...)
+ initTodo.Func().Dcl = nil
- fn.Nbody.Set(nf)
+ fn.PtrBody().Set(nf)
funcbody()
fn = typecheck(fn, ctxStmt)
@@ -62,35 +65,35 @@ func fninit(n []*Node) {
xtop = append(xtop, fn)
fns = append(fns, initializers.Linksym())
}
- if dummyInitFn.Func.Dcl != nil {
- // We only generate temps using dummyInitFn if there
+ if initTodo.Func().Dcl != nil {
+ // We only generate temps using initTodo if there
// are package-scope initialization statements, so
// something's weird if we get here.
- Fatalf("dummyInitFn still has declarations")
+ base.Fatalf("initTodo still has declarations")
}
- dummyInitFn = nil
+ initTodo = nil
// Record user init functions.
for i := 0; i < renameinitgen; i++ {
s := lookupN("init.", i)
- fn := asNode(s.Def).Name.Defn
+ fn := ir.AsNode(s.Def).Name().Defn
// Skip init functions with empty bodies.
- if fn.Nbody.Len() == 1 && fn.Nbody.First().Op == OEMPTY {
+ if fn.Body().Len() == 1 && fn.Body().First().Op() == ir.OEMPTY {
continue
}
fns = append(fns, s.Linksym())
}
- if len(deps) == 0 && len(fns) == 0 && localpkg.Name != "main" && localpkg.Name != "runtime" {
+ if len(deps) == 0 && len(fns) == 0 && ir.LocalPkg.Name != "main" && ir.LocalPkg.Name != "runtime" {
return // nothing to initialize
}
// Make an .inittask structure.
sym := lookup(".inittask")
- nn := newname(sym)
- nn.Type = types.Types[TUINT8] // dummy type
- nn.SetClass(PEXTERN)
- sym.Def = asTypesNode(nn)
+ nn := NewName(sym)
+ nn.SetType(types.Types[types.TUINT8]) // fake type
+ nn.SetClass(ir.PEXTERN)
+ sym.Def = nn
exportsym(nn)
lsym := sym.Linksym()
ot := 0