github.com/freddyisaac/sicortex-golang@v0.0.0-20231019035217-e03519e66f60/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  var compiling_std bool
   252  
   253  var compiling_wrappers int
   254  
   255  var use_writebarrier bool
   256  
   257  var pure_go bool
   258  
   259  var flag_installsuffix string
   260  
   261  var flag_race bool
   262  
   263  var flag_msan bool
   264  
   265  var flag_largemodel bool
   266  
   267  // Whether we are adding any sort of code instrumentation, such as
   268  // when the race detector is enabled.
   269  var instrumenting bool
   270  
   271  var debuglive int
   272  
   273  var Ctxt *obj.Link
   274  
   275  var writearchive bool
   276  
   277  var Nacl bool
   278  
   279  var pc *obj.Prog
   280  
   281  var nodfp *Node
   282  
   283  var disable_checknil int
   284  
   285  // interface to back end
   286  
   287  const (
   288  	// Pseudo-op, like TEXT, GLOBL, TYPE, PCDATA, FUNCDATA.
   289  	Pseudo = 1 << 1
   290  
   291  	// There's nothing to say about the instruction,
   292  	// but it's still okay to see.
   293  	OK = 1 << 2
   294  
   295  	// Size of right-side write, or right-side read if no write.
   296  	SizeB = 1 << 3
   297  	SizeW = 1 << 4
   298  	SizeL = 1 << 5
   299  	SizeQ = 1 << 6
   300  	SizeF = 1 << 7
   301  	SizeD = 1 << 8
   302  
   303  	// Left side (Prog.from): address taken, read, write.
   304  	LeftAddr  = 1 << 9
   305  	LeftRead  = 1 << 10
   306  	LeftWrite = 1 << 11
   307  
   308  	// Register in middle (Prog.reg); only ever read. (arm, ppc64)
   309  	RegRead    = 1 << 12
   310  	CanRegRead = 1 << 13
   311  
   312  	// Right side (Prog.to): address taken, read, write.
   313  	RightAddr  = 1 << 14
   314  	RightRead  = 1 << 15
   315  	RightWrite = 1 << 16
   316  
   317  	// Instruction kinds
   318  	Move  = 1 << 17 // straight move
   319  	Conv  = 1 << 18 // size conversion
   320  	Cjmp  = 1 << 19 // conditional jump
   321  	Break = 1 << 20 // breaks control flow (no fallthrough)
   322  	Call  = 1 << 21 // function call
   323  	Jump  = 1 << 22 // jump
   324  	Skip  = 1 << 23 // data instruction
   325  
   326  	// Set, use, or kill of carry bit.
   327  	// Kill means we never look at the carry bit after this kind of instruction.
   328  	// Originally for understanding ADC, RCR, and so on, but now also
   329  	// tracks set, use, and kill of the zero and overflow bits as well.
   330  	// TODO rename to {Set,Use,Kill}Flags
   331  	SetCarry  = 1 << 24
   332  	UseCarry  = 1 << 25
   333  	KillCarry = 1 << 26
   334  
   335  	// Special cases for register use. (amd64, 386)
   336  	ShiftCX  = 1 << 27 // possible shift by CX
   337  	ImulAXDX = 1 << 28 // possible multiply into DX:AX
   338  
   339  	// Instruction updates whichever of from/to is type D_OREG. (ppc64)
   340  	PostInc = 1 << 29
   341  
   342  	// Optional 3rd input operand, only ever read.
   343  	From3Read = 1 << 30
   344  )
   345  
   346  type Arch struct {
   347  	LinkArch *obj.LinkArch
   348  
   349  	REGSP    int
   350  	MAXWIDTH int64
   351  
   352  	Defframe func(*obj.Prog)
   353  	Proginfo func(*obj.Prog) ProgInfo
   354  	Use387   bool // should 8g use 387 FP instructions instead of sse2.
   355  
   356  	// SSAMarkMoves marks any MOVXconst ops that need to avoid clobbering flags.
   357  	SSAMarkMoves func(*SSAGenState, *ssa.Block)
   358  
   359  	// SSAGenValue emits Prog(s) for the Value.
   360  	SSAGenValue func(*SSAGenState, *ssa.Value)
   361  
   362  	// SSAGenBlock emits end-of-block Progs. SSAGenValue should be called
   363  	// for all values in the block before SSAGenBlock.
   364  	SSAGenBlock func(s *SSAGenState, b, next *ssa.Block)
   365  
   366  	// ZeroAuto emits code to zero the given auto stack variable.
   367  	// Code is added immediately after pp.
   368  	// ZeroAuto must not use any non-temporary registers.
   369  	// ZeroAuto will only be called for variables which contain a pointer.
   370  	ZeroAuto func(n *Node, pp *obj.Prog)
   371  }
   372  
   373  var pcloc int32
   374  
   375  var Thearch Arch
   376  
   377  var (
   378  	Newproc,
   379  	Deferproc,
   380  	Deferreturn,
   381  	panicindex,
   382  	panicslice,
   383  	panicdivide,
   384  	growslice,
   385  	panicdottype,
   386  	panicnildottype,
   387  	assertE2I,
   388  	assertE2I2,
   389  	assertI2I,
   390  	assertI2I2 *Node
   391  )