github.com/megatontech/mynoteforgo@v0.0.0-20200507084910-5d0c6ea6e890/源码/cmd/compile/internal/gc/go.go (about)

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package gc
     6  
     7  import (
     8  	"cmd/compile/internal/ssa"
     9  	"cmd/compile/internal/types"
    10  	"cmd/internal/obj"
    11  	"cmd/internal/src"
    12  	"sync"
    13  )
    14  
    15  const (
    16  	BADWIDTH = types.BADWIDTH
    17  
    18  	// maximum size variable which we will allocate on the stack.
    19  	// This limit is for explicit variable declarations like "var x T" or "x := ...".
    20  	maxStackVarSize = 10 * 1024 * 1024
    21  
    22  	// maximum size of implicit variables that we will allocate on the stack.
    23  	//   p := new(T)          allocating T on the stack
    24  	//   p := &T{}            allocating T on the stack
    25  	//   s := make([]T, n)    allocating [n]T on the stack
    26  	//   s := []byte("...")   allocating [n]byte on the stack
    27  	maxImplicitStackVarSize = 64 * 1024
    28  )
    29  
    30  // isRuntimePkg reports whether p is package runtime.
    31  func isRuntimePkg(p *types.Pkg) bool {
    32  	if compiling_runtime && p == localpkg {
    33  		return true
    34  	}
    35  	return p.Path == "runtime"
    36  }
    37  
    38  // The Class of a variable/function describes the "storage class"
    39  // of a variable or function. During parsing, storage classes are
    40  // called declaration contexts.
    41  type Class uint8
    42  
    43  //go:generate stringer -type=Class
    44  const (
    45  	Pxxx      Class = iota // no class; used during ssa conversion to indicate pseudo-variables
    46  	PEXTERN                // global variable
    47  	PAUTO                  // local variables
    48  	PAUTOHEAP              // local variable or parameter moved to heap
    49  	PPARAM                 // input arguments
    50  	PPARAMOUT              // output results
    51  	PFUNC                  // global function
    52  
    53  	PDISCARD // discard during parse of duplicate import
    54  	// Careful: Class is stored in three bits in Node.flags.
    55  	// Adding a new Class will overflow that.
    56  )
    57  
    58  func init() {
    59  	if PDISCARD != 7 {
    60  		panic("PDISCARD changed; does all Class values still fit in three bits?")
    61  	}
    62  }
    63  
    64  // note this is the runtime representation
    65  // of the compilers arrays.
    66  //
    67  // typedef	struct
    68  // {				// must not move anything
    69  // 	uchar	array[8];	// pointer to data
    70  // 	uchar	nel[4];		// number of elements
    71  // 	uchar	cap[4];		// allocated number of elements
    72  // } Array;
    73  var array_array int // runtime offsetof(Array,array) - same for String
    74  
    75  var array_nel int // runtime offsetof(Array,nel) - same for String
    76  
    77  var array_cap int // runtime offsetof(Array,cap)
    78  
    79  var sizeof_Array int // runtime sizeof(Array)
    80  
    81  // note this is the runtime representation
    82  // of the compilers strings.
    83  //
    84  // typedef	struct
    85  // {				// must not move anything
    86  // 	uchar	array[8];	// pointer to data
    87  // 	uchar	nel[4];		// number of elements
    88  // } String;
    89  var sizeof_String int // runtime sizeof(String)
    90  
    91  var pragcgobuf [][]string
    92  
    93  var outfile string
    94  var linkobj string
    95  
    96  // nerrors is the number of compiler errors reported
    97  // since the last call to saveerrors.
    98  var nerrors int
    99  
   100  // nsavederrors is the total number of compiler errors
   101  // reported before the last call to saveerrors.
   102  var nsavederrors int
   103  
   104  var nsyntaxerrors int
   105  
   106  var decldepth int32
   107  
   108  var nolocalimports bool
   109  
   110  var Debug [256]int
   111  
   112  var debugstr string
   113  
   114  var Debug_checknil int
   115  var Debug_typeassert int
   116  
   117  var localpkg *types.Pkg // package being compiled
   118  
   119  var inimport bool // set during import
   120  
   121  var itabpkg *types.Pkg // fake pkg for itab entries
   122  
   123  var itablinkpkg *types.Pkg // fake package for runtime itab entries
   124  
   125  var Runtimepkg *types.Pkg // fake package runtime
   126  
   127  var racepkg *types.Pkg // package runtime/race
   128  
   129  var msanpkg *types.Pkg // package runtime/msan
   130  
   131  var unsafepkg *types.Pkg // package unsafe
   132  
   133  var trackpkg *types.Pkg // fake package for field tracking
   134  
   135  var mappkg *types.Pkg // fake package for map zero value
   136  
   137  var gopkg *types.Pkg // pseudo-package for method symbols on anonymous receiver types
   138  
   139  var zerosize int64
   140  
   141  var myimportpath string
   142  
   143  var localimport string
   144  
   145  var asmhdr string
   146  
   147  var simtype [NTYPE]types.EType
   148  
   149  var (
   150  	isInt     [NTYPE]bool
   151  	isFloat   [NTYPE]bool
   152  	isComplex [NTYPE]bool
   153  	issimple  [NTYPE]bool
   154  )
   155  
   156  var (
   157  	okforeq    [NTYPE]bool
   158  	okforadd   [NTYPE]bool
   159  	okforand   [NTYPE]bool
   160  	okfornone  [NTYPE]bool
   161  	okforcmp   [NTYPE]bool
   162  	okforbool  [NTYPE]bool
   163  	okforcap   [NTYPE]bool
   164  	okforlen   [NTYPE]bool
   165  	okforarith [NTYPE]bool
   166  	okforconst [NTYPE]bool
   167  )
   168  
   169  var (
   170  	okfor [OEND][]bool
   171  	iscmp [OEND]bool
   172  )
   173  
   174  var minintval [NTYPE]*Mpint
   175  
   176  var maxintval [NTYPE]*Mpint
   177  
   178  var minfltval [NTYPE]*Mpflt
   179  
   180  var maxfltval [NTYPE]*Mpflt
   181  
   182  var xtop []*Node
   183  
   184  var exportlist []*Node
   185  
   186  var importlist []*Node // imported functions and methods with inlinable bodies
   187  
   188  var (
   189  	funcsymsmu sync.Mutex // protects funcsyms and associated package lookups (see func funcsym)
   190  	funcsyms   []*types.Sym
   191  )
   192  
   193  var dclcontext Class // PEXTERN/PAUTO
   194  
   195  var Curfn *Node
   196  
   197  var Widthptr int
   198  
   199  var Widthreg int
   200  
   201  var nblank *Node
   202  
   203  var typecheckok bool
   204  
   205  var compiling_runtime bool
   206  
   207  // Compiling the standard library
   208  var compiling_std bool
   209  
   210  var use_writebarrier bool
   211  
   212  var pure_go bool
   213  
   214  var flag_installsuffix string
   215  
   216  var flag_race bool
   217  
   218  var flag_msan bool
   219  
   220  var flagDWARF bool
   221  
   222  // Whether we are adding any sort of code instrumentation, such as
   223  // when the race detector is enabled.
   224  var instrumenting bool
   225  
   226  // Whether we are tracking lexical scopes for DWARF.
   227  var trackScopes bool
   228  
   229  // Controls generation of DWARF inlined instance records. Zero
   230  // disables, 1 emits inlined routines but suppresses var info,
   231  // and 2 emits inlined routines with tracking of formals/locals.
   232  var genDwarfInline int
   233  
   234  var debuglive int
   235  
   236  var Ctxt *obj.Link
   237  
   238  var writearchive bool
   239  
   240  var Nacl bool
   241  
   242  var nodfp *Node
   243  
   244  var disable_checknil int
   245  
   246  var autogeneratedPos src.XPos
   247  
   248  // interface to back end
   249  
   250  type Arch struct {
   251  	LinkArch *obj.LinkArch
   252  
   253  	REGSP     int
   254  	MAXWIDTH  int64
   255  	Use387    bool // should 386 backend use 387 FP instructions instead of sse2.
   256  	SoftFloat bool
   257  
   258  	PadFrame     func(int64) int64
   259  	ZeroRange    func(*Progs, *obj.Prog, int64, int64, *uint32) *obj.Prog
   260  	Ginsnop      func(*Progs) *obj.Prog
   261  	Ginsnopdefer func(*Progs) *obj.Prog // special ginsnop for deferreturn
   262  
   263  	// SSAMarkMoves marks any MOVXconst ops that need to avoid clobbering flags.
   264  	SSAMarkMoves func(*SSAGenState, *ssa.Block)
   265  
   266  	// SSAGenValue emits Prog(s) for the Value.
   267  	SSAGenValue func(*SSAGenState, *ssa.Value)
   268  
   269  	// SSAGenBlock emits end-of-block Progs. SSAGenValue should be called
   270  	// for all values in the block before SSAGenBlock.
   271  	SSAGenBlock func(s *SSAGenState, b, next *ssa.Block)
   272  
   273  	// ZeroAuto emits code to zero the given auto stack variable.
   274  	// ZeroAuto must not use any non-temporary registers.
   275  	// ZeroAuto will only be called for variables which contain a pointer.
   276  	ZeroAuto func(*Progs, *Node)
   277  }
   278  
   279  var thearch Arch
   280  
   281  var (
   282  	staticbytes,
   283  	zerobase *Node
   284  
   285  	assertE2I,
   286  	assertE2I2,
   287  	assertI2I,
   288  	assertI2I2,
   289  	deferproc,
   290  	Deferreturn,
   291  	Duffcopy,
   292  	Duffzero,
   293  	gcWriteBarrier,
   294  	goschedguarded,
   295  	growslice,
   296  	msanread,
   297  	msanwrite,
   298  	newproc,
   299  	panicdivide,
   300  	panicdottypeE,
   301  	panicdottypeI,
   302  	panicindex,
   303  	panicnildottype,
   304  	panicoverflow,
   305  	panicslice,
   306  	raceread,
   307  	racereadrange,
   308  	racewrite,
   309  	racewriterange,
   310  	x86HasPOPCNT,
   311  	x86HasSSE41,
   312  	arm64HasATOMICS,
   313  	typedmemclr,
   314  	typedmemmove,
   315  	Udiv,
   316  	writeBarrier *obj.LSym
   317  
   318  	// GO386=387
   319  	ControlWord64trunc,
   320  	ControlWord32 *obj.LSym
   321  
   322  	// Wasm
   323  	WasmMove,
   324  	WasmZero,
   325  	WasmDiv,
   326  	WasmTruncS,
   327  	WasmTruncU,
   328  	SigPanic *obj.LSym
   329  )