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