base.AutogeneratedPos = makePos(src.NewFileBase("<autogenerated>", "<autogenerated>"), 1, 0)
- typecheck.Init()
+ typecheck.InitUniverse()
- // Parse input.
- base.Timer.Start("fe", "parse")
- lines := noder.ParseFiles(flag.Args())
- ssagen.CgoSymABIs()
- base.Timer.Stop()
- base.Timer.AddEvent(int64(lines), "lines")
- dwarfgen.RecordPackageName()
+ // Parse and typecheck input.
+ noder.LoadPackage(flag.Args())
- // Typecheck.
- noder.Package()
+ dwarfgen.RecordPackageName()
+ ssagen.CgoSymABIs()
- // With all user code typechecked, it's now safe to verify unused dot imports.
- noder.CheckDotImports()
- base.ExitIfErrors()
- // Phase 6: Compute Addrtaken for names.
+ // Compute Addrtaken for names.
// We need to wait until typechecking is done so that when we see &x[i]
// we know that x has its address taken if x is an array, but not if x is a slice.
// We compute Addrtaken in bulk here.
}
typecheck.IncrementalAddrtaken = true
- // Phase 7: Eliminate some obviously dead code.
+ // Eliminate some obviously dead code.
// Must happen after typechecking.
for _, n := range typecheck.Target.Decls {
if n.Op() == ir.ODCLFUNC {
}
}
- // Phase 8: Decide how to capture closed variables.
+ // Decide how to capture closed variables.
// This needs to run before escape analysis,
// because variables captured by value do not escape.
base.Timer.Start("fe", "capturevars")
// otherwise lazily when used or re-exported.
typecheck.AllImportedBodies()
}
+
// Build init task.
if initTask := pkginit.Task(); initTask != nil {
typecheck.Export(initTask)
// Prepare for SSA compilation.
// This must be before peekitabs, because peekitabs
// can trigger function compilation.
+ typecheck.InitRuntime()
ssagen.InitConfig()
// Just before compilation, compile itabs found on
"cmd/internal/src"
)
+func LoadPackage(filenames []string) {
+ base.Timer.Start("fe", "parse")
+ lines := ParseFiles(filenames)
+ base.Timer.Stop()
+ base.Timer.AddEvent(int64(lines), "lines")
+
+ // Typecheck.
+ Package()
+
+ // With all user code typechecked, it's now safe to verify unused dot imports.
+ CheckDotImports()
+ base.ExitIfErrors()
+}
+
// ParseFiles concurrently parses files into *syntax.File structures.
// Each declaration in every *syntax.File is converted to a syntax tree
// and its root represented by *Node is appended to Target.Decls.
// so that the compiler can generate calls to them,
// but does not make them visible to user code.
func InitRuntime() {
+ base.Timer.Start("fe", "loadsys")
types.Block = 1
- inimport = true
- TypecheckAllowed = true
-
typs := runtimeTypes()
for _, d := range &runtimeDecls {
sym := ir.Pkgs.Runtime.Lookup(d.name)
base.Fatalf("unhandled declaration tag %v", d.tag)
}
}
-
- TypecheckAllowed = false
- inimport = false
}
// LookupRuntimeFunc looks up Go function name in package runtime. This function