github.com/FenixAra/go@v0.0.0-20170127160404-96ea0918e670/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/internal/bio" 10 "cmd/internal/obj" 11 ) 12 13 const ( 14 UINF = 100 15 BADWIDTH = -1000000000 16 MaxStackVarSize = 10 * 1024 * 1024 17 ) 18 19 type Pkg struct { 20 Name string // package name, e.g. "sys" 21 Path string // string literal used in import statement, e.g. "runtime/internal/sys" 22 Pathsym *obj.LSym 23 Prefix string // escaped path for use in symbol table 24 Imported bool // export data of this package was parsed 25 Direct bool // imported directly 26 Syms map[string]*Sym 27 } 28 29 // Sym represents an object name. Most commonly, this is a Go identifier naming 30 // an object declared within a package, but Syms are also used to name internal 31 // synthesized objects. 32 // 33 // As an exception, field and method names that are exported use the Sym 34 // associated with localpkg instead of the package that declared them. This 35 // allows using Sym pointer equality to test for Go identifier uniqueness when 36 // handling selector expressions. 37 type Sym struct { 38 Flags SymFlags 39 Link *Sym 40 Importdef *Pkg // where imported definition was found 41 Linkname string // link name 42 43 // saved and restored by dcopy 44 Pkg *Pkg 45 Name string // object name 46 Def *Node // definition: ONAME OTYPE OPACK or OLITERAL 47 Block int32 // blocknumber to catch redeclaration 48 Lastlineno int32 // last declaration for diagnostic 49 50 Label *Node // corresponding label (ephemeral) 51 Origpkg *Pkg // original package for . import 52 Lsym *obj.LSym 53 Fsym *Sym // funcsym 54 } 55 56 type SymFlags uint8 57 58 const ( 59 SymExport SymFlags = 1 << iota // to be exported 60 SymPackage 61 SymExported // already written out by export 62 SymUniq 63 SymSiggen 64 SymAsm 65 SymAlgGen 66 SymAlias // alias, original is Sym.Def.Sym 67 ) 68 69 // The Class of a variable/function describes the "storage class" 70 // of a variable or function. During parsing, storage classes are 71 // called declaration contexts. 72 type Class uint8 73 74 const ( 75 Pxxx Class = iota 76 PEXTERN // global variable 77 PAUTO // local variables 78 PAUTOHEAP // local variable or parameter moved to heap 79 PPARAM // input arguments 80 PPARAMOUT // output results 81 PFUNC // global function 82 83 PDISCARD // discard during parse of duplicate import 84 ) 85 86 // note this is the runtime representation 87 // of the compilers arrays. 88 // 89 // typedef struct 90 // { // must not move anything 91 // uchar array[8]; // pointer to data 92 // uchar nel[4]; // number of elements 93 // uchar cap[4]; // allocated number of elements 94 // } Array; 95 var array_array int // runtime offsetof(Array,array) - same for String 96 97 var array_nel int // runtime offsetof(Array,nel) - same for String 98 99 var array_cap int // runtime offsetof(Array,cap) 100 101 var sizeof_Array int // runtime sizeof(Array) 102 103 // note this is the runtime representation 104 // of the compilers strings. 105 // 106 // typedef struct 107 // { // must not move anything 108 // uchar array[8]; // pointer to data 109 // uchar nel[4]; // number of elements 110 // } String; 111 var sizeof_String int // runtime sizeof(String) 112 113 var pragcgobuf string 114 115 var infile string 116 117 var outfile string 118 var linkobj string 119 120 var bout *bio.Writer 121 122 // nerrors is the number of compiler errors reported 123 // since the last call to saveerrors. 124 var nerrors int 125 126 // nsavederrors is the total number of compiler errors 127 // reported before the last call to saveerrors. 128 var nsavederrors int 129 130 var nsyntaxerrors int 131 132 var decldepth int32 133 134 var safemode bool 135 136 var nolocalimports bool 137 138 var Debug [256]int 139 140 var debugstr string 141 142 var Debug_checknil int 143 var Debug_typeassert int 144 145 var localpkg *Pkg // package being compiled 146 147 var importpkg *Pkg // package being imported 148 149 var itabpkg *Pkg // fake pkg for itab entries 150 151 var itablinkpkg *Pkg // fake package for runtime itab entries 152 153 var Runtimepkg *Pkg // package runtime 154 155 var racepkg *Pkg // package runtime/race 156 157 var msanpkg *Pkg // package runtime/msan 158 159 var typepkg *Pkg // fake package for runtime type info (headers) 160 161 var unsafepkg *Pkg // package unsafe 162 163 var trackpkg *Pkg // fake package for field tracking 164 165 var mappkg *Pkg // fake package for map zero value 166 var zerosize int64 167 168 var Tptr EType // either TPTR32 or TPTR64 169 170 var myimportpath string 171 172 var localimport string 173 174 var asmhdr string 175 176 var simtype [NTYPE]EType 177 178 var ( 179 isforw [NTYPE]bool 180 isInt [NTYPE]bool 181 isFloat [NTYPE]bool 182 isComplex [NTYPE]bool 183 issimple [NTYPE]bool 184 ) 185 186 var ( 187 okforeq [NTYPE]bool 188 okforadd [NTYPE]bool 189 okforand [NTYPE]bool 190 okfornone [NTYPE]bool 191 okforcmp [NTYPE]bool 192 okforbool [NTYPE]bool 193 okforcap [NTYPE]bool 194 okforlen [NTYPE]bool 195 okforarith [NTYPE]bool 196 okforconst [NTYPE]bool 197 ) 198 199 var ( 200 okfor [OEND][]bool 201 iscmp [OEND]bool 202 ) 203 204 var minintval [NTYPE]*Mpint 205 206 var maxintval [NTYPE]*Mpint 207 208 var minfltval [NTYPE]*Mpflt 209 210 var maxfltval [NTYPE]*Mpflt 211 212 var xtop []*Node 213 214 var exportlist []*Node 215 216 var importlist []*Node // imported functions and methods with inlinable bodies 217 218 var funcsyms []*Node 219 220 var dclcontext Class // PEXTERN/PAUTO 221 222 var statuniqgen int // name generator for static temps 223 224 var iota_ int64 225 226 var lastconst []*Node 227 228 var lasttype *Node 229 230 var Maxarg int64 231 232 var Stksize int64 // stack size for current frame 233 234 var stkptrsize int64 // prefix of stack containing pointers 235 236 var hasdefer bool // flag that curfn has defer statement 237 238 var Curfn *Node 239 240 var Widthptr int 241 242 var Widthint int 243 244 var Widthreg int 245 246 var nblank *Node 247 248 var typecheckok bool 249 250 var compiling_runtime bool 251 252 var compiling_wrappers int 253 254 var use_writebarrier bool 255 256 var pure_go bool 257 258 var flag_installsuffix string 259 260 var flag_race bool 261 262 var flag_msan bool 263 264 var flag_largemodel bool 265 266 // Whether we are adding any sort of code instrumentation, such as 267 // when the race detector is enabled. 268 var instrumenting bool 269 270 var debuglive int 271 272 var Ctxt *obj.Link 273 274 var writearchive bool 275 276 var Nacl bool 277 278 var pc *obj.Prog 279 280 var nodfp *Node 281 282 var disable_checknil int 283 284 // interface to back end 285 286 const ( 287 // Pseudo-op, like TEXT, GLOBL, TYPE, PCDATA, FUNCDATA. 288 Pseudo = 1 << 1 289 290 // There's nothing to say about the instruction, 291 // but it's still okay to see. 292 OK = 1 << 2 293 294 // Size of right-side write, or right-side read if no write. 295 SizeB = 1 << 3 296 SizeW = 1 << 4 297 SizeL = 1 << 5 298 SizeQ = 1 << 6 299 SizeF = 1 << 7 300 SizeD = 1 << 8 301 302 // Left side (Prog.from): address taken, read, write. 303 LeftAddr = 1 << 9 304 LeftRead = 1 << 10 305 LeftWrite = 1 << 11 306 307 // Register in middle (Prog.reg); only ever read. (arm, ppc64) 308 RegRead = 1 << 12 309 CanRegRead = 1 << 13 310 311 // Right side (Prog.to): address taken, read, write. 312 RightAddr = 1 << 14 313 RightRead = 1 << 15 314 RightWrite = 1 << 16 315 316 // Instruction kinds 317 Move = 1 << 17 // straight move 318 Conv = 1 << 18 // size conversion 319 Cjmp = 1 << 19 // conditional jump 320 Break = 1 << 20 // breaks control flow (no fallthrough) 321 Call = 1 << 21 // function call 322 Jump = 1 << 22 // jump 323 Skip = 1 << 23 // data instruction 324 325 // Set, use, or kill of carry bit. 326 // Kill means we never look at the carry bit after this kind of instruction. 327 // Originally for understanding ADC, RCR, and so on, but now also 328 // tracks set, use, and kill of the zero and overflow bits as well. 329 // TODO rename to {Set,Use,Kill}Flags 330 SetCarry = 1 << 24 331 UseCarry = 1 << 25 332 KillCarry = 1 << 26 333 334 // Special cases for register use. (amd64, 386) 335 ShiftCX = 1 << 27 // possible shift by CX 336 ImulAXDX = 1 << 28 // possible multiply into DX:AX 337 338 // Instruction updates whichever of from/to is type D_OREG. (ppc64) 339 PostInc = 1 << 29 340 341 // Optional 3rd input operand, only ever read. 342 From3Read = 1 << 30 343 ) 344 345 type Arch struct { 346 LinkArch *obj.LinkArch 347 348 REGSP int 349 MAXWIDTH int64 350 351 Defframe func(*obj.Prog) 352 Proginfo func(*obj.Prog) ProgInfo 353 Use387 bool // should 8g use 387 FP instructions instead of sse2. 354 355 // SSAMarkMoves marks any MOVXconst ops that need to avoid clobbering flags. 356 SSAMarkMoves func(*SSAGenState, *ssa.Block) 357 358 // SSAGenValue emits Prog(s) for the Value. 359 SSAGenValue func(*SSAGenState, *ssa.Value) 360 361 // SSAGenBlock emits end-of-block Progs. SSAGenValue should be called 362 // for all values in the block before SSAGenBlock. 363 SSAGenBlock func(s *SSAGenState, b, next *ssa.Block) 364 } 365 366 var pcloc int32 367 368 var Thearch Arch 369 370 var ( 371 Newproc, 372 Deferproc, 373 Deferreturn, 374 panicindex, 375 panicslice, 376 panicdivide, 377 growslice, 378 panicdottype, 379 panicnildottype, 380 assertE2I, 381 assertE2I2, 382 assertI2I, 383 assertI2I2 *Node 384 )