diff options
Diffstat (limited to 'src/cmd/compile/internal/gc/main.go')
-rw-r--r-- | src/cmd/compile/internal/gc/main.go | 61 |
1 files changed, 16 insertions, 45 deletions
diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index 69ec5c8f2f..b98d1f2e10 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -13,6 +13,7 @@ import ( "cmd/compile/internal/ir" "cmd/compile/internal/logopt" "cmd/compile/internal/ssa" + "cmd/compile/internal/typecheck" "cmd/compile/internal/types" "cmd/internal/bio" "cmd/internal/dwarf" @@ -49,9 +50,6 @@ func hidePanic() { } } -// Target is the package being compiled. -var Target *ir.Package - // Main parses flags and Go source files specified in the command-line // arguments, type-checks the parsed Go package, compiles functions to machine // code, and finally writes the compiled package definition to disk. @@ -197,18 +195,18 @@ func Main(archInit func(*Arch)) { return typenamesym(t).Linksym() } - Target = new(ir.Package) + typecheck.Target = new(ir.Package) - NeedFuncSym = makefuncsym - NeedITab = func(t, iface *types.Type) { itabname(t, iface) } - NeedRuntimeType = addsignat // TODO(rsc): typenamesym for lock? + typecheck.NeedFuncSym = makefuncsym + typecheck.NeedITab = func(t, iface *types.Type) { itabname(t, iface) } + typecheck.NeedRuntimeType = addsignat // TODO(rsc): typenamesym for lock? base.AutogeneratedPos = makePos(src.NewFileBase("<autogenerated>", "<autogenerated>"), 1, 0) types.TypeLinkSym = func(t *types.Type) *obj.LSym { return typenamesym(t).Linksym() } - TypecheckInit() + typecheck.Init() // Parse input. base.Timer.Start("fe", "parse") @@ -219,7 +217,7 @@ func Main(archInit func(*Arch)) { recordPackageName() // Typecheck. - TypecheckPackage() + typecheck.Package() // With all user code typechecked, it's now safe to verify unused dot imports. checkDotImports() @@ -227,7 +225,7 @@ func Main(archInit func(*Arch)) { // Build init task. if initTask := fninit(); initTask != nil { - exportsym(initTask) + typecheck.Export(initTask) } // Inlining @@ -237,7 +235,7 @@ func Main(archInit func(*Arch)) { } // Devirtualize. - for _, n := range Target.Decls { + for _, n := range typecheck.Target.Decls { if n.Op() == ir.ODCLFUNC { devirtualize(n.(*ir.Func)) } @@ -253,7 +251,7 @@ func Main(archInit func(*Arch)) { // Large values are also moved off stack in escape analysis; // because large values may contain pointers, it must happen early. base.Timer.Start("fe", "escapes") - escapes(Target.Decls) + escapes(typecheck.Target.Decls) // Collect information for go:nowritebarrierrec // checking. This must happen before transformclosure. @@ -267,7 +265,7 @@ func Main(archInit func(*Arch)) { // This needs to happen before walk, because closures must be transformed // before walk reaches a call of a closure. base.Timer.Start("fe", "xclosures") - for _, n := range Target.Decls { + for _, n := range typecheck.Target.Decls { if n.Op() == ir.ODCLFUNC { n := n.(*ir.Func) if n.OClosure != nil { @@ -292,8 +290,8 @@ func Main(archInit func(*Arch)) { // Don't use range--walk can add functions to Target.Decls. base.Timer.Start("be", "compilefuncs") fcount := int64(0) - for i := 0; i < len(Target.Decls); i++ { - n := Target.Decls[i] + for i := 0; i < len(typecheck.Target.Decls); i++ { + n := typecheck.Target.Decls[i] if n.Op() == ir.ODCLFUNC { funccompile(n.(*ir.Func)) fcount++ @@ -327,7 +325,7 @@ func Main(archInit func(*Arch)) { } CheckLargeStacks() - CheckFuncStack() + typecheck.CheckFuncStack() if len(compilequeue) != 0 { base.Fatalf("%d uncompiled functions", len(compilequeue)) @@ -363,7 +361,7 @@ func CheckLargeStacks() { func cgoSymABIs() { // The linker expects an ABI0 wrapper for all cgo-exported // functions. - for _, prag := range Target.CgoPragmas { + for _, prag := range typecheck.Target.CgoPragmas { switch prag[0] { case "cgo_export_static", "cgo_export_dynamic": if symabiRefs == nil { @@ -581,33 +579,6 @@ func findpkg(name string) (file string, ok bool) { return "", false } -// loadsys loads the definitions for the low-level runtime functions, -// so that the compiler can generate calls to them, -// but does not make them visible to user code. -func loadsys() { - types.Block = 1 - - inimport = true - typecheckok = true - - typs := runtimeTypes() - for _, d := range &runtimeDecls { - sym := ir.Pkgs.Runtime.Lookup(d.name) - typ := typs[d.typ] - switch d.tag { - case funcTag: - importfunc(ir.Pkgs.Runtime, src.NoXPos, sym, typ) - case varTag: - importvar(ir.Pkgs.Runtime, src.NoXPos, sym, typ) - default: - base.Fatalf("unhandled declaration tag %v", d.tag) - } - } - - typecheckok = false - inimport = false -} - // myheight tracks the local package's height based on packages // imported so far. var myheight int @@ -776,7 +747,7 @@ func importfile(f constant.Value) *types.Pkg { base.Errorf("import %s: unexpected package format byte: %v", file, c) base.ErrorExit() } - fingerprint = iimport(importpkg, imp) + fingerprint = typecheck.ReadImports(importpkg, imp) default: base.Errorf("no import in %q", path_) |