github.com/panjjo/go@v0.0.0-20161104043856-d62b31386338/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  var nerrors int
   123  
   124  var nsavederrors int
   125  
   126  var nsyntaxerrors int
   127  
   128  var decldepth int32
   129  
   130  var safemode bool
   131  
   132  var nolocalimports bool
   133  
   134  var Debug [256]int
   135  
   136  var debugstr string
   137  
   138  var Debug_checknil int
   139  var Debug_typeassert int
   140  
   141  var localpkg *Pkg // package being compiled
   142  
   143  var importpkg *Pkg // package being imported
   144  
   145  var itabpkg *Pkg // fake pkg for itab entries
   146  
   147  var itablinkpkg *Pkg // fake package for runtime itab entries
   148  
   149  var Runtimepkg *Pkg // package runtime
   150  
   151  var racepkg *Pkg // package runtime/race
   152  
   153  var msanpkg *Pkg // package runtime/msan
   154  
   155  var typepkg *Pkg // fake package for runtime type info (headers)
   156  
   157  var unsafepkg *Pkg // package unsafe
   158  
   159  var trackpkg *Pkg // fake package for field tracking
   160  
   161  var mappkg *Pkg // fake package for map zero value
   162  var zerosize int64
   163  
   164  var Tptr EType // either TPTR32 or TPTR64
   165  
   166  var myimportpath string
   167  
   168  var localimport string
   169  
   170  var asmhdr string
   171  
   172  var simtype [NTYPE]EType
   173  
   174  var (
   175  	isforw    [NTYPE]bool
   176  	isInt     [NTYPE]bool
   177  	isFloat   [NTYPE]bool
   178  	isComplex [NTYPE]bool
   179  	issimple  [NTYPE]bool
   180  )
   181  
   182  var (
   183  	okforeq    [NTYPE]bool
   184  	okforadd   [NTYPE]bool
   185  	okforand   [NTYPE]bool
   186  	okfornone  [NTYPE]bool
   187  	okforcmp   [NTYPE]bool
   188  	okforbool  [NTYPE]bool
   189  	okforcap   [NTYPE]bool
   190  	okforlen   [NTYPE]bool
   191  	okforarith [NTYPE]bool
   192  	okforconst [NTYPE]bool
   193  )
   194  
   195  var (
   196  	okfor [OEND][]bool
   197  	iscmp [OEND]bool
   198  )
   199  
   200  var minintval [NTYPE]*Mpint
   201  
   202  var maxintval [NTYPE]*Mpint
   203  
   204  var minfltval [NTYPE]*Mpflt
   205  
   206  var maxfltval [NTYPE]*Mpflt
   207  
   208  var xtop []*Node
   209  
   210  var exportlist []*Node
   211  
   212  var importlist []*Node // imported functions and methods with inlinable bodies
   213  
   214  var funcsyms []*Node
   215  
   216  var dclcontext Class // PEXTERN/PAUTO
   217  
   218  var statuniqgen int // name generator for static temps
   219  
   220  var iota_ int64
   221  
   222  var lastconst []*Node
   223  
   224  var lasttype *Node
   225  
   226  var Maxarg int64
   227  
   228  var Stksize int64 // stack size for current frame
   229  
   230  var stkptrsize int64 // prefix of stack containing pointers
   231  
   232  var hasdefer bool // flag that curfn has defer statement
   233  
   234  var Curfn *Node
   235  
   236  var Widthptr int
   237  
   238  var Widthint int
   239  
   240  var Widthreg int
   241  
   242  var nblank *Node
   243  
   244  var typecheckok bool
   245  
   246  var compiling_runtime bool
   247  
   248  var compiling_wrappers int
   249  
   250  var use_writebarrier bool
   251  
   252  var pure_go bool
   253  
   254  var flag_installsuffix string
   255  
   256  var flag_race bool
   257  
   258  var flag_msan bool
   259  
   260  var flag_largemodel bool
   261  
   262  // Whether we are adding any sort of code instrumentation, such as
   263  // when the race detector is enabled.
   264  var instrumenting bool
   265  
   266  var debuglive int
   267  
   268  var Ctxt *obj.Link
   269  
   270  var writearchive bool
   271  
   272  var Nacl bool
   273  
   274  var pc *obj.Prog
   275  
   276  var nodfp *Node
   277  
   278  var disable_checknil int
   279  
   280  // interface to back end
   281  
   282  const (
   283  	// Pseudo-op, like TEXT, GLOBL, TYPE, PCDATA, FUNCDATA.
   284  	Pseudo = 1 << 1
   285  
   286  	// There's nothing to say about the instruction,
   287  	// but it's still okay to see.
   288  	OK = 1 << 2
   289  
   290  	// Size of right-side write, or right-side read if no write.
   291  	SizeB = 1 << 3
   292  	SizeW = 1 << 4
   293  	SizeL = 1 << 5
   294  	SizeQ = 1 << 6
   295  	SizeF = 1 << 7
   296  	SizeD = 1 << 8
   297  
   298  	// Left side (Prog.from): address taken, read, write.
   299  	LeftAddr  = 1 << 9
   300  	LeftRead  = 1 << 10
   301  	LeftWrite = 1 << 11
   302  
   303  	// Register in middle (Prog.reg); only ever read. (arm, ppc64)
   304  	RegRead    = 1 << 12
   305  	CanRegRead = 1 << 13
   306  
   307  	// Right side (Prog.to): address taken, read, write.
   308  	RightAddr  = 1 << 14
   309  	RightRead  = 1 << 15
   310  	RightWrite = 1 << 16
   311  
   312  	// Instruction kinds
   313  	Move  = 1 << 17 // straight move
   314  	Conv  = 1 << 18 // size conversion
   315  	Cjmp  = 1 << 19 // conditional jump
   316  	Break = 1 << 20 // breaks control flow (no fallthrough)
   317  	Call  = 1 << 21 // function call
   318  	Jump  = 1 << 22 // jump
   319  	Skip  = 1 << 23 // data instruction
   320  
   321  	// Set, use, or kill of carry bit.
   322  	// Kill means we never look at the carry bit after this kind of instruction.
   323  	// Originally for understanding ADC, RCR, and so on, but now also
   324  	// tracks set, use, and kill of the zero and overflow bits as well.
   325  	// TODO rename to {Set,Use,Kill}Flags
   326  	SetCarry  = 1 << 24
   327  	UseCarry  = 1 << 25
   328  	KillCarry = 1 << 26
   329  
   330  	// Special cases for register use. (amd64, 386)
   331  	ShiftCX  = 1 << 27 // possible shift by CX
   332  	ImulAXDX = 1 << 28 // possible multiply into DX:AX
   333  
   334  	// Instruction updates whichever of from/to is type D_OREG. (ppc64)
   335  	PostInc = 1 << 29
   336  
   337  	// Optional 3rd input operand, only ever read.
   338  	From3Read = 1 << 30
   339  )
   340  
   341  type Arch struct {
   342  	LinkArch *obj.LinkArch
   343  
   344  	REGSP    int
   345  	MAXWIDTH int64
   346  
   347  	Defframe func(*obj.Prog)
   348  	Proginfo func(*obj.Prog) ProgInfo
   349  	Use387   bool // should 8g use 387 FP instructions instead of sse2.
   350  
   351  	// SSAMarkMoves marks any MOVXconst ops that need to avoid clobbering flags.
   352  	SSAMarkMoves func(*SSAGenState, *ssa.Block)
   353  
   354  	// SSAGenValue emits Prog(s) for the Value.
   355  	SSAGenValue func(*SSAGenState, *ssa.Value)
   356  
   357  	// SSAGenBlock emits end-of-block Progs. SSAGenValue should be called
   358  	// for all values in the block before SSAGenBlock.
   359  	SSAGenBlock func(s *SSAGenState, b, next *ssa.Block)
   360  }
   361  
   362  var pcloc int32
   363  
   364  var Thearch Arch
   365  
   366  var (
   367  	Newproc,
   368  	Deferproc,
   369  	Deferreturn,
   370  	panicindex,
   371  	panicslice,
   372  	panicdivide,
   373  	growslice,
   374  	panicdottype,
   375  	panicnildottype,
   376  	assertE2I,
   377  	assertE2I2,
   378  	assertI2I,
   379  	assertI2I2 *Node
   380  )