github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/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 "github.com/gagliardetto/golang-go/cmd/compile/internal/ssa" 9 "github.com/gagliardetto/golang-go/cmd/compile/internal/types" 10 "github.com/gagliardetto/golang-go/cmd/internal/obj" 11 "github.com/gagliardetto/golang-go/cmd/internal/src" 12 "sync" 13 ) 14 15 const ( 16 BADWIDTH = types.BADWIDTH 17 ) 18 19 var ( 20 // maximum size variable which we will allocate on the stack. 21 // This limit is for explicit variable declarations like "var x T" or "x := ...". 22 // Note: the flag smallframes can update this value. 23 maxStackVarSize = int64(10 * 1024 * 1024) 24 25 // maximum size of implicit variables that we will allocate on the stack. 26 // p := new(T) allocating T on the stack 27 // p := &T{} allocating T on the stack 28 // s := make([]T, n) allocating [n]T on the stack 29 // s := []byte("...") allocating [n]byte on the stack 30 // Note: the flag smallframes can update this value. 31 maxImplicitStackVarSize = int64(64 * 1024) 32 33 // smallArrayBytes is the maximum size of an array which is considered small. 34 // Small arrays will be initialized directly with a sequence of constant stores. 35 // Large arrays will be initialized by copying from a static temp. 36 // 256 bytes was chosen to minimize generated code + statictmp size. 37 smallArrayBytes = int64(256) 38 ) 39 40 // isRuntimePkg reports whether p is package runtime. 41 func isRuntimePkg(p *types.Pkg) bool { 42 if compiling_runtime && p == localpkg { 43 return true 44 } 45 return p.Path == "runtime" 46 } 47 48 // The Class of a variable/function describes the "storage class" 49 // of a variable or function. During parsing, storage classes are 50 // called declaration contexts. 51 type Class uint8 52 53 //go:generate stringer -type=Class 54 const ( 55 Pxxx Class = iota // no class; used during ssa conversion to indicate pseudo-variables 56 PEXTERN // global variable 57 PAUTO // local variables 58 PAUTOHEAP // local variable or parameter moved to heap 59 PPARAM // input arguments 60 PPARAMOUT // output results 61 PFUNC // global function 62 63 // Careful: Class is stored in three bits in Node.flags. 64 _ = uint((1 << 3) - iota) // static assert for iota <= (1 << 3) 65 ) 66 67 // note this is the runtime representation 68 // of the compilers slices. 69 // 70 // typedef struct 71 // { // must not move anything 72 // uchar array[8]; // pointer to data 73 // uchar nel[4]; // number of elements 74 // uchar cap[4]; // allocated number of elements 75 // } Slice; 76 var slice_array int // runtime offsetof(Slice,array) - same for String 77 78 var slice_nel int // runtime offsetof(Slice,nel) - same for String 79 80 var slice_cap int // runtime offsetof(Slice,cap) 81 82 var sizeof_Slice int // runtime sizeof(Slice) 83 84 // note this is the runtime representation 85 // of the compilers strings. 86 // 87 // typedef struct 88 // { // must not move anything 89 // uchar array[8]; // pointer to data 90 // uchar nel[4]; // number of elements 91 // } String; 92 var sizeof_String int // runtime sizeof(String) 93 94 var pragcgobuf [][]string 95 96 var outfile string 97 var linkobj string 98 99 // nerrors is the number of compiler errors reported 100 // since the last call to saveerrors. 101 var nerrors int 102 103 // nsavederrors is the total number of compiler errors 104 // reported before the last call to saveerrors. 105 var nsavederrors int 106 107 var nsyntaxerrors int 108 109 var decldepth int32 110 111 var nolocalimports bool 112 113 var Debug [256]int 114 115 var debugstr string 116 117 var Debug_checknil int 118 var Debug_typeassert int 119 120 var localpkg *types.Pkg // package being compiled 121 122 var inimport bool // set during import 123 124 var itabpkg *types.Pkg // fake pkg for itab entries 125 126 var itablinkpkg *types.Pkg // fake package for runtime itab entries 127 128 var Runtimepkg *types.Pkg // fake package runtime 129 130 var racepkg *types.Pkg // package runtime/race 131 132 var msanpkg *types.Pkg // package runtime/msan 133 134 var unsafepkg *types.Pkg // package unsafe 135 136 var trackpkg *types.Pkg // fake package for field tracking 137 138 var mappkg *types.Pkg // fake package for map zero value 139 140 var gopkg *types.Pkg // pseudo-package for method symbols on anonymous receiver types 141 142 var zerosize int64 143 144 var myimportpath string 145 146 var localimport string 147 148 var asmhdr string 149 150 var simtype [NTYPE]types.EType 151 152 var ( 153 isInt [NTYPE]bool 154 isFloat [NTYPE]bool 155 isComplex [NTYPE]bool 156 issimple [NTYPE]bool 157 ) 158 159 var ( 160 okforeq [NTYPE]bool 161 okforadd [NTYPE]bool 162 okforand [NTYPE]bool 163 okfornone [NTYPE]bool 164 okforcmp [NTYPE]bool 165 okforbool [NTYPE]bool 166 okforcap [NTYPE]bool 167 okforlen [NTYPE]bool 168 okforarith [NTYPE]bool 169 okforconst [NTYPE]bool 170 ) 171 172 var ( 173 okfor [OEND][]bool 174 iscmp [OEND]bool 175 ) 176 177 var minintval [NTYPE]*Mpint 178 179 var maxintval [NTYPE]*Mpint 180 181 var minfltval [NTYPE]*Mpflt 182 183 var maxfltval [NTYPE]*Mpflt 184 185 var xtop []*Node 186 187 var exportlist []*Node 188 189 var importlist []*Node // imported functions and methods with inlinable bodies 190 191 var ( 192 funcsymsmu sync.Mutex // protects funcsyms and associated package lookups (see func funcsym) 193 funcsyms []*types.Sym 194 ) 195 196 var dclcontext Class // PEXTERN/PAUTO 197 198 var Curfn *Node 199 200 var Widthptr int 201 202 var Widthreg int 203 204 var nblank *Node 205 206 var typecheckok bool 207 208 var compiling_runtime bool 209 210 // Compiling the standard library 211 var compiling_std bool 212 213 var use_writebarrier bool 214 215 var pure_go bool 216 217 var flag_installsuffix string 218 219 var flag_race bool 220 221 var flag_msan bool 222 223 var flagDWARF bool 224 225 // Whether we are adding any sort of code instrumentation, such as 226 // when the race detector is enabled. 227 var instrumenting bool 228 229 // Whether we are tracking lexical scopes for DWARF. 230 var trackScopes bool 231 232 // Controls generation of DWARF inlined instance records. Zero 233 // disables, 1 emits inlined routines but suppresses var info, 234 // and 2 emits inlined routines with tracking of formals/locals. 235 var genDwarfInline int 236 237 var debuglive int 238 239 var Ctxt *obj.Link 240 241 var writearchive 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 261 // ZeroRange zeroes a range of memory on stack. It is only inserted 262 // at function entry, and it is ok to clobber registers. 263 ZeroRange func(*Progs, *obj.Prog, int64, int64, *uint32) *obj.Prog 264 265 Ginsnop func(*Progs) *obj.Prog 266 Ginsnopdefer func(*Progs) *obj.Prog // special ginsnop for deferreturn 267 268 // SSAMarkMoves marks any MOVXconst ops that need to avoid clobbering flags. 269 SSAMarkMoves func(*SSAGenState, *ssa.Block) 270 271 // SSAGenValue emits Prog(s) for the Value. 272 SSAGenValue func(*SSAGenState, *ssa.Value) 273 274 // SSAGenBlock emits end-of-block Progs. SSAGenValue should be called 275 // for all values in the block before SSAGenBlock. 276 SSAGenBlock func(s *SSAGenState, b, next *ssa.Block) 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 deferprocStack, 291 Deferreturn, 292 Duffcopy, 293 Duffzero, 294 gcWriteBarrier, 295 goschedguarded, 296 growslice, 297 msanread, 298 msanwrite, 299 newobject, 300 newproc, 301 panicdivide, 302 panicshift, 303 panicdottypeE, 304 panicdottypeI, 305 panicnildottype, 306 panicoverflow, 307 raceread, 308 racereadrange, 309 racewrite, 310 racewriterange, 311 x86HasPOPCNT, 312 x86HasSSE41, 313 x86HasFMA, 314 armHasVFPv4, 315 arm64HasATOMICS, 316 typedmemclr, 317 typedmemmove, 318 Udiv, 319 writeBarrier, 320 zerobaseSym *obj.LSym 321 322 BoundsCheckFunc [ssa.BoundsKindCount]*obj.LSym 323 ExtendCheckFunc [ssa.BoundsKindCount]*obj.LSym 324 325 // GO386=387 326 ControlWord64trunc, 327 ControlWord32 *obj.LSym 328 329 // Wasm 330 WasmMove, 331 WasmZero, 332 WasmDiv, 333 WasmTruncS, 334 WasmTruncU, 335 SigPanic *obj.LSym 336 )