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