github.com/hikaru7719/go@v0.0.0-20181025140707-c8b2ac68906a/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 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 isforw [NTYPE]bool 151 isInt [NTYPE]bool 152 isFloat [NTYPE]bool 153 isComplex [NTYPE]bool 154 issimple [NTYPE]bool 155 ) 156 157 var ( 158 okforeq [NTYPE]bool 159 okforadd [NTYPE]bool 160 okforand [NTYPE]bool 161 okfornone [NTYPE]bool 162 okforcmp [NTYPE]bool 163 okforbool [NTYPE]bool 164 okforcap [NTYPE]bool 165 okforlen [NTYPE]bool 166 okforarith [NTYPE]bool 167 okforconst [NTYPE]bool 168 ) 169 170 var ( 171 okfor [OEND][]bool 172 iscmp [OEND]bool 173 ) 174 175 var minintval [NTYPE]*Mpint 176 177 var maxintval [NTYPE]*Mpint 178 179 var minfltval [NTYPE]*Mpflt 180 181 var maxfltval [NTYPE]*Mpflt 182 183 var xtop []*Node 184 185 var exportlist []*Node 186 187 var importlist []*Node // imported functions and methods with inlinable bodies 188 189 var ( 190 funcsymsmu sync.Mutex // protects funcsyms and associated package lookups (see func funcsym) 191 funcsyms []*types.Sym 192 ) 193 194 var dclcontext Class // PEXTERN/PAUTO 195 196 var Curfn *Node 197 198 var Widthptr int 199 200 var Widthreg int 201 202 var nblank *Node 203 204 var typecheckok bool 205 206 var compiling_runtime bool 207 208 // Compiling the standard library 209 var compiling_std bool 210 211 var use_writebarrier bool 212 213 var pure_go bool 214 215 var flag_installsuffix string 216 217 var flag_race bool 218 219 var flag_msan bool 220 221 var flagDWARF bool 222 223 // Whether we are adding any sort of code instrumentation, such as 224 // when the race detector is enabled. 225 var instrumenting bool 226 227 // Whether we are tracking lexical scopes for DWARF. 228 var trackScopes bool 229 230 // Controls generation of DWARF inlined instance records. Zero 231 // disables, 1 emits inlined routines but suppresses var info, 232 // and 2 emits inlined routines with tracking of formals/locals. 233 var genDwarfInline int 234 235 var debuglive int 236 237 var Ctxt *obj.Link 238 239 var writearchive bool 240 241 var Nacl bool 242 243 var nodfp *Node 244 245 var disable_checknil int 246 247 var autogeneratedPos src.XPos 248 249 // interface to back end 250 251 type Arch struct { 252 LinkArch *obj.LinkArch 253 254 REGSP int 255 MAXWIDTH int64 256 Use387 bool // should 386 backend use 387 FP instructions instead of sse2. 257 SoftFloat bool 258 259 PadFrame func(int64) int64 260 ZeroRange func(*Progs, *obj.Prog, int64, int64, *uint32) *obj.Prog 261 Ginsnop func(*Progs) 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 panicslice, 305 raceread, 306 racereadrange, 307 racewrite, 308 racewriterange, 309 supportPopcnt, 310 supportSSE41, 311 arm64SupportAtomics, 312 typedmemclr, 313 typedmemmove, 314 Udiv, 315 writeBarrier *obj.LSym 316 317 // GO386=387 318 ControlWord64trunc, 319 ControlWord32 *obj.LSym 320 321 // Wasm 322 WasmMove, 323 WasmZero, 324 WasmDiv, 325 WasmTruncS, 326 WasmTruncU, 327 SigPanic *obj.LSym 328 )