github.com/epfl-dcsl/gotee@v0.0.0-20200909122901-014b35f5e5e9/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 130 var Gosecpkg *types.Pkg // fake package for the gosecload function. 131 var zerosize int64 132 133 var myimportpath string 134 135 var localimport string 136 137 var asmhdr string 138 139 var simtype [NTYPE]types.EType 140 141 var ( 142 isforw [NTYPE]bool 143 isInt [NTYPE]bool 144 isFloat [NTYPE]bool 145 isComplex [NTYPE]bool 146 issimple [NTYPE]bool 147 ) 148 149 var ( 150 okforeq [NTYPE]bool 151 okforadd [NTYPE]bool 152 okforand [NTYPE]bool 153 okfornone [NTYPE]bool 154 okforcmp [NTYPE]bool 155 okforbool [NTYPE]bool 156 okforcap [NTYPE]bool 157 okforlen [NTYPE]bool 158 okforarith [NTYPE]bool 159 okforconst [NTYPE]bool 160 ) 161 162 var ( 163 okfor [OEND][]bool 164 iscmp [OEND]bool 165 ) 166 167 var minintval [NTYPE]*Mpint 168 169 var maxintval [NTYPE]*Mpint 170 171 var minfltval [NTYPE]*Mpflt 172 173 var maxfltval [NTYPE]*Mpflt 174 175 var xtop []*Node 176 177 var exportlist []*Node 178 179 var importlist []*Node // imported functions and methods with inlinable bodies 180 181 var ( 182 funcsymsmu sync.Mutex // protects funcsyms and associated package lookups (see func funcsym) 183 funcsyms []*types.Sym 184 ) 185 186 var dclcontext Class // PEXTERN/PAUTO 187 188 var Curfn *Node 189 190 var Widthptr int 191 192 var Widthreg int 193 194 var nblank *Node 195 196 var typecheckok bool 197 198 var compiling_runtime bool 199 200 // Compiling the standard library 201 var compiling_std bool 202 203 var compiling_wrappers bool 204 205 var use_writebarrier bool 206 207 var pure_go bool 208 209 var flag_installsuffix string 210 211 var flag_race bool 212 213 var flag_msan bool 214 215 var flagDWARF bool 216 217 // Whether we are adding any sort of code instrumentation, such as 218 // when the race detector is enabled. 219 var instrumenting bool 220 221 // Whether we are tracking lexical scopes for DWARF. 222 var trackScopes bool 223 224 // Controls generation of DWARF inlined instance records. Zero 225 // disables, 1 emits inlined routines but suppresses var info, 226 // and 2 emits inlined routines with tracking of formals/locals. 227 var genDwarfInline int 228 229 var debuglive int 230 231 var Ctxt *obj.Link 232 233 var writearchive bool 234 235 var Nacl bool 236 237 var nodfp *Node 238 239 var disable_checknil int 240 241 var autogeneratedPos src.XPos 242 243 // interface to back end 244 245 type Arch struct { 246 LinkArch *obj.LinkArch 247 248 REGSP int 249 MAXWIDTH int64 250 Use387 bool // should 386 backend use 387 FP instructions instead of sse2. 251 SoftFloat bool 252 253 PadFrame func(int64) int64 254 ZeroRange func(*Progs, *obj.Prog, int64, int64, *uint32) *obj.Prog 255 Ginsnop func(*Progs) 256 257 // SSAMarkMoves marks any MOVXconst ops that need to avoid clobbering flags. 258 SSAMarkMoves func(*SSAGenState, *ssa.Block) 259 260 // SSAGenValue emits Prog(s) for the Value. 261 SSAGenValue func(*SSAGenState, *ssa.Value) 262 263 // SSAGenBlock emits end-of-block Progs. SSAGenValue should be called 264 // for all values in the block before SSAGenBlock. 265 SSAGenBlock func(s *SSAGenState, b, next *ssa.Block) 266 267 // ZeroAuto emits code to zero the given auto stack variable. 268 // ZeroAuto must not use any non-temporary registers. 269 // ZeroAuto will only be called for variables which contain a pointer. 270 ZeroAuto func(*Progs, *Node) 271 } 272 273 var thearch Arch 274 275 var ( 276 staticbytes, 277 zerobase *Node 278 279 Newproc, 280 Deferproc, 281 Gosecload, 282 Deferreturn, 283 Duffcopy, 284 Duffzero, 285 panicindex, 286 panicslice, 287 panicdivide, 288 growslice, 289 panicdottypeE, 290 panicdottypeI, 291 panicnildottype, 292 assertE2I, 293 assertE2I2, 294 assertI2I, 295 assertI2I2, 296 goschedguarded, 297 writeBarrier, 298 writebarrierptr, 299 gcWriteBarrier, 300 typedmemmove, 301 typedmemclr, 302 Udiv *obj.LSym 303 304 // GO386=387 305 ControlWord64trunc, 306 ControlWord32 *obj.LSym 307 )