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.
9 "cmd/compile/internal/big"
13 // The parser's maximum stack size.
14 // We have to use a #define macro here since yacc
15 // or bison will check for its definition and use
16 // a potentially smaller value if it is undefined.
25 BADWIDTH = -1000000000
26 MaxStackVarSize = 10 * 1024 * 1024
30 // Maximum size in bits for Mpints before signalling
31 // overflow and also mantissa precision for Mpflts.
33 // Turn on for constant arithmetic debugging output.
37 // Mpint represents an integer constant.
40 Ovf bool // set if Val overflowed compiler limit (sticky)
41 Rune bool // set if syntax indicates default type rune
44 // Mpflt represents a floating-point constant.
49 // Mpcplx represents a complex constant.
57 // bool bool when n.ValCtype() == CTBOOL
58 // *Mpint int when n.ValCtype() == CTINT, rune when n.ValCtype() == CTRUNE
59 // *Mpflt float when n.ValCtype() == CTFLT
60 // *Mpcplx pair of floats when n.ValCtype() == CTCPLX
61 // string string when n.ValCtype() == CTSTR
62 // *Nilval when n.ValCtype() == CTNIL
68 func (v Val) Ctype() Ctype {
69 switch x := v.U.(type) {
71 Fatalf("unexpected Ctype for %T", v.U)
94 Name string // package name
95 Path string // string literal used in import statement
97 Prefix string // escaped path for use in symbol table
98 Imported bool // export data of this package was parsed
99 Exported bool // import line written in export data
100 Direct bool // imported directly
101 Safe bool // whether the package is marked as safe
109 Importdef *Pkg // where imported definition was found
110 Linkname string // link name
112 // saved and restored by dcopy
114 Name string // variable name
115 Def *Node // definition: ONAME OTYPE OPACK or OLITERAL
116 Label *Label // corresponding label (ephemeral)
117 Block int32 // blocknumber to catch redeclaration
118 Lastlineno int32 // last declaration for diagnostic
119 Origpkg *Pkg // original package for . import
129 Trecur uint8 // to detect loops
131 Embedded uint8 // TFIELD embedded type
132 Funarg bool // on TSTRUCT and TFIELD
134 Local bool // created in this file
136 Broke bool // broken type definition.
137 Isddd bool // TFIELD is ... argument
139 Haspointers uint8 // 0 unknown, 1 no, 2 yes
141 Nod *Node // canonical OTYPE node
142 Orig *Type // original type (type literal or predefined type)
155 Vargen int32 // unique name for OTYPE/ONAME
161 Type *Type // actual type for TFIELD, element type for TARRAY, TCHAN, TMAP, TPTRxx
162 Width int64 // offset in TFIELD, width in all others
165 Down *Type // next struct field, also key type in TMAP
166 Outer *Type // outer struct
167 Note *string // literal string annotation
170 Bound int64 // negative is slice
173 Bucket *Type // internal type representing a hash bucket
174 Hmap *Type // internal type representing a Hmap (map header object)
175 Hiter *Type // internal type representing hash iterator state
176 Map *Type // link from the above 3 internal types back to the map type.
178 Maplineno int32 // first use of TFORW as map key
179 Embedlineno int32 // first use of TFORW as embedded type
181 // for TFORW, where to copy the eventual value to
184 Lastfn *Node // for usefield
193 // for use during gen
194 Gotopc *obj.Prog // pointer to unresolved gotos
195 Labelpc *obj.Prog // pointer to code
196 Breakpc *obj.Prog // pointer to code
197 Continpc *obj.Prog // pointer to code
202 type InitEntry struct {
203 Xoffset int64 // struct, array only
204 Expr *Node // bytes of run-time computed expressions
207 type InitPlan struct {
215 SymExport = 1 << 0 // to be exported
217 SymExported = 1 << 2 // already written out by export
262 T_old_DARRAY // Doesn't seem to be used in existing code. Used now for Isddd export (see bexport.go). TODO(gri) rename.
273 // pseudo-types for literals
278 // pseudo-type for frame layout
286 // Ctype describes the constant kind of an "ideal" (untyped) constant.
303 // must match ../../../../reflect/type.go:/ChanDir
306 Cboth = Crecv | Csend
309 // The Class of a variable/function describes the "storage class"
310 // of a variable or function. During parsing, storage classes are
311 // called declaration contexts.
316 PEXTERN // global variable
317 PAUTO // local variables
318 PPARAM // input arguments
319 PPARAMOUT // output results
320 PPARAMREF // closure variable reference
321 PFUNC // global function
323 PDISCARD // discard during parse of duplicate import
325 PHEAP = 1 << 7 // an extra bit to identify an escaped variable
329 Etop = 1 << 1 // evaluated at statement level
330 Erv = 1 << 2 // evaluated in value context
332 Ecall = 1 << 4 // call-only expressions are ok
333 Efnstruct = 1 << 5 // multivalue function returns are ok
334 Eiota = 1 << 6 // iota is ok
335 Easgn = 1 << 7 // assigning to expression
336 Eindir = 1 << 8 // indirecting through expression
337 Eaddr = 1 << 9 // taking address of expression
338 Eproc = 1 << 10 // inside a go statement
339 Ecomplit = 1 << 11 // type in composite literal
342 type Typedef struct {
362 // argument passing to/from
365 W int // input for both - width
366 S int // output for both - shift
367 Bad int // output for both - unexpected failure
369 // magic multiplier for signed literal divisors
370 Sd int64 // input - literal divisor
371 Sm int64 // output - multiplier
373 // magic multiplier for unsigned literal divisors
374 Ud uint64 // input - literal divisor
375 Um uint64 // output - multiplier
376 Ua int // output - adder
379 // note this is the runtime representation
380 // of the compilers arrays.
383 // { // must not move anything
384 // uchar array[8]; // pointer to data
385 // uchar nel[4]; // number of elements
386 // uchar cap[4]; // allocated number of elements
388 var Array_array int // runtime offsetof(Array,array) - same for String
390 var Array_nel int // runtime offsetof(Array,nel) - same for String
392 var Array_cap int // runtime offsetof(Array,cap)
394 var sizeof_Array int // runtime sizeof(Array)
396 // note this is the runtime representation
397 // of the compilers strings.
400 // { // must not move anything
401 // uchar array[8]; // pointer to data
402 // uchar nel[4]; // number of elements
404 var sizeof_String int // runtime sizeof(String)
406 var dotlist [10]Dlist // size is max depth of embeddeds
408 // lexlineno is the line number _after_ the most recently read rune.
409 // In particular, it's advanced (or rewound) as newlines are read (or unread).
412 // lineno is the line number at the start of the most recently lexed token.
415 var pragcgobuf string
427 var nsyntaxerrors int
433 var nolocalimports int
435 var lexbuf bytes.Buffer
436 var strbuf bytes.Buffer
437 var litbuf string // LLITERAL value for use in syntax error messages
443 var Debug_checknil int
444 var Debug_typeassert int
446 var localpkg *Pkg // package being compiled
448 var importpkg *Pkg // package being imported
450 var structpkg *Pkg // package that declared struct, during import
452 var builtinpkg *Pkg // fake package for builtins
454 var gostringpkg *Pkg // fake pkg for Go strings
456 var itabpkg *Pkg // fake pkg for itab cache
458 var Runtimepkg *Pkg // package runtime
460 var racepkg *Pkg // package runtime/race
462 var msanpkg *Pkg // package runtime/msan
464 var typepkg *Pkg // fake package for runtime type info (headers)
466 var typelinkpkg *Pkg // fake package for runtime type info (data)
468 var weaktypepkg *Pkg // weak references to runtime type info
470 var unsafepkg *Pkg // package unsafe
472 var trackpkg *Pkg // fake package for field tracking
474 var Tptr EType // either TPTR32 or TPTR64
476 var myimportpath string
478 var localimport string
482 var Types [NTYPE]*Type
484 var idealstring *Type
494 var Simtype [NTYPE]EType
501 Iscomplex [NTYPE]bool
510 okfornone [NTYPE]bool
512 okforbool [NTYPE]bool
515 okforarith [NTYPE]bool
516 okforconst [NTYPE]bool
524 var Minintval [NTYPE]*Mpint
526 var Maxintval [NTYPE]*Mpint
528 var minfltval [NTYPE]*Mpflt
530 var maxfltval [NTYPE]*Mpflt
534 var externdcl []*Node
536 var exportlist []*Node
538 var importlist []*Node // imported functions and methods with inlinable bodies
542 var dclcontext Class // PEXTERN/PAUTO
544 var incannedimport int
546 var statuniqgen int // name generator for static temps
550 var lastconst *NodeList
556 var Stksize int64 // stack size for current frame
558 var stkptrsize int64 // prefix of stack containing pointers
560 var blockgen int32 // max block number
562 var block int32 // current block number
564 var hasdefer bool // flag that curfn has defer statement
580 var compiling_runtime int
582 var compiling_wrappers int
584 var use_writebarrier int
588 var flag_installsuffix string
594 var flag_largemodel int
596 // Whether we are adding any sort of code instrumentation, such as
597 // when the race detector is enabled.
598 var instrumenting bool
606 var bstdout obj.Biobuf
610 var continpc *obj.Prog
612 var breakpc *obj.Prog
618 var Disable_checknil int
621 Prog *obj.Prog // actual instruction
622 P1 *Flow // predecessors of this instruction: p1,
623 P2 *Flow // and then p2 linked though p2link.
625 S1 *Flow // successors of this instruction (at most two: s1 and s2).
627 Link *Flow // next instruction in function code
629 Active int32 // usable by client
631 Id int32 // sequence number in flow graph
632 Rpo int32 // reverse post ordering
633 Loop uint16 // x5 for every loop
634 Refset bool // diagnostic generated
636 Data interface{} // for use by client
643 // After calling flowrpo, rpo lists the flow nodes in reverse postorder,
644 // and each non-dead Flow node f has g->rpo[f->rpo] == f.
648 // interface to back end
651 // Pseudo-op, like TEXT, GLOBL, TYPE, PCDATA, FUNCDATA.
654 // There's nothing to say about the instruction,
655 // but it's still okay to see.
658 // Size of right-side write, or right-side read if no write.
666 // Left side (Prog.from): address taken, read, write.
671 // Register in middle (Prog.reg); only ever read. (arm, ppc64)
675 // Right side (Prog.to): address taken, read, write.
681 Move = 1 << 17 // straight move
682 Conv = 1 << 18 // size conversion
683 Cjmp = 1 << 19 // conditional jump
684 Break = 1 << 20 // breaks control flow (no fallthrough)
685 Call = 1 << 21 // function call
686 Jump = 1 << 22 // jump
687 Skip = 1 << 23 // data instruction
689 // Set, use, or kill of carry bit.
690 // Kill means we never look at the carry bit after this kind of instruction.
695 // Special cases for register use. (amd64, 386)
696 ShiftCX = 1 << 27 // possible shift by CX
697 ImulAXDX = 1 << 28 // possible multiply into DX:AX
699 // Instruction updates whichever of from/to is type D_OREG. (ppc64)
706 Thelinkarch *obj.LinkArch
715 REGZERO int // architectural zero register, if available
721 AddIndex func(*Node, int64, *Node) bool // optional
723 Bgen_float func(*Node, bool, int, *obj.Prog) // optional
724 Cgen64 func(*Node, *Node) // only on 32-bit systems
725 Cgenindex func(*Node, *Node, bool) *obj.Prog
726 Cgen_bmul func(Op, *Node, *Node, *Node) bool
727 Cgen_float func(*Node, *Node) // optional
728 Cgen_hmul func(*Node, *Node, *Node)
729 Cgen_shift func(Op, bool, *Node, *Node, *Node)
731 Cmp64 func(*Node, *Node, Op, int, *obj.Prog) // only on 32-bit systems
732 Defframe func(*obj.Prog)
733 Dodiv func(Op, *Node, *Node, *Node)
735 Expandchecks func(*obj.Prog)
737 Gins func(int, *Node, *Node) *obj.Prog
739 // Ginscmp generates code comparing n1 to n2 and jumping away if op is satisfied.
740 // The returned prog should be Patch'ed with the jump target.
741 // If op is not satisfied, code falls through to the next emitted instruction.
742 // Likely is the branch prediction hint: +1 for likely, -1 for unlikely, 0 for no opinion.
744 // Ginscmp must be able to handle all kinds of arguments for n1 and n2,
745 // not just simple registers, although it can assume that there are no
746 // function calls needed during the evaluation, and on 32-bit systems
747 // the values are guaranteed not to be 64-bit values, so no in-memory
748 // temporaries are necessary.
749 Ginscmp func(op Op, t *Type, n1, n2 *Node, likely int) *obj.Prog
751 // Ginsboolval inserts instructions to convert the result
752 // of a just-completed comparison to a boolean value.
753 // The first argument is the conditional jump instruction
754 // corresponding to the desired value.
755 // The second argument is the destination.
756 // If not present, Ginsboolval will be emulated with jumps.
757 Ginsboolval func(int, *Node)
759 Ginscon func(int, int64, *Node)
761 Gmove func(*Node, *Node)
762 Igenindex func(*Node, *Node, bool) *obj.Prog
765 Proginfo func(*obj.Prog) // fills in Prog.Info
766 Regtyp func(*obj.Addr) bool
767 Sameaddr func(*obj.Addr, *obj.Addr) bool
768 Smallindir func(*obj.Addr, *obj.Addr) bool
769 Stackaddr func(*obj.Addr) bool
770 Blockcopy func(*Node, *Node, int64, int64, int64)
771 Sudoaddable func(int, *Node, *obj.Addr) bool
773 Excludedregs func() uint64
774 RtoB func(int) uint64
775 FtoB func(int) uint64
776 BtoR func(uint64) int
777 BtoF func(uint64) int
778 Optoas func(Op, *Type) int
779 Doregbits func(int) uint64
780 Regnames func(*int) []string
781 Use387 bool // should 8g use 387 FP instructions instead of sse2.
792 var Deferreturn *Node
798 var panicdivide *Node
800 var throwreturn *Node
804 var writebarrierptr *Node
805 var typedmemmove *Node
807 var panicdottype *Node