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 // These values are known by runtime.
31 // The MEMx and NOEQx values must run in parallel. See algtype.
58 // Maximum size in bits for Mpints before signalling
59 // overflow and also mantissa precision for Mpflts.
61 // Turn on for constant arithmetic debugging output.
65 // Mpint represents an integer constant.
68 Ovf bool // set if Val overflowed compiler limit (sticky)
69 Rune bool // set if syntax indicates default type rune
72 // Mpflt represents a floating-point constant.
77 // Mpcplx represents a complex constant.
85 // bool bool when n.ValCtype() == CTBOOL
86 // *Mpint int when n.ValCtype() == CTINT, rune when n.ValCtype() == CTRUNE
87 // *Mpflt float when n.ValCtype() == CTFLT
88 // *Mpcplx pair of floats when n.ValCtype() == CTCPLX
89 // string string when n.ValCtype() == CTSTR
90 // *Nilval when n.ValCtype() == CTNIL
96 func (v Val) Ctype() Ctype {
97 switch x := v.U.(type) {
99 Fatalf("unexpected Ctype for %T", v.U)
122 Name string // package name
123 Path string // string literal used in import statement
125 Prefix string // escaped path for use in symbol table
126 Imported bool // export data of this package was parsed
127 Exported bool // import line written in export data
128 Direct bool // imported directly
129 Safe bool // whether the package is marked as safe
138 Importdef *Pkg // where imported definition was found
139 Linkname string // link name
141 // saved and restored by dcopy
143 Name string // variable name
144 Def *Node // definition: ONAME OTYPE OPACK or OLITERAL
145 Label *Label // corresponding label (ephemeral)
146 Block int32 // blocknumber to catch redeclaration
147 Lastlineno int32 // last declaration for diagnostic
148 Origpkg *Pkg // original package for . import
158 Trecur uint8 // to detect loops
160 Embedded uint8 // TFIELD embedded type
161 Funarg bool // on TSTRUCT and TFIELD
163 Local bool // created in this file
165 Broke bool // broken type definition.
166 Isddd bool // TFIELD is ... argument
168 Haspointers uint8 // 0 unknown, 1 no, 2 yes
170 Nod *Node // canonical OTYPE node
171 Orig *Type // original type (type literal or predefined type)
184 Vargen int32 // unique name for OTYPE/ONAME
190 Type *Type // actual type for TFIELD, element type for TARRAY, TCHAN, TMAP, TPTRxx
191 Width int64 // offset in TFIELD, width in all others
194 Down *Type // next struct field, also key type in TMAP
195 Outer *Type // outer struct
196 Note *string // literal string annotation
199 Bound int64 // negative is slice
202 Bucket *Type // internal type representing a hash bucket
203 Hmap *Type // internal type representing a Hmap (map header object)
204 Hiter *Type // internal type representing hash iterator state
205 Map *Type // link from the above 3 internal types back to the map type.
207 Maplineno int32 // first use of TFORW as map key
208 Embedlineno int32 // first use of TFORW as embedded type
210 // for TFORW, where to copy the eventual value to
213 Lastfn *Node // for usefield
222 // for use during gen
223 Gotopc *obj.Prog // pointer to unresolved gotos
224 Labelpc *obj.Prog // pointer to code
225 Breakpc *obj.Prog // pointer to code
226 Continpc *obj.Prog // pointer to code
231 type InitEntry struct {
232 Xoffset int64 // struct, array only
233 Expr *Node // bytes of run-time computed expressions
236 type InitPlan struct {
244 SymExport = 1 << 0 // to be exported
246 SymExported = 1 << 2 // already written out by export
291 T_old_DARRAY // Doesn't seem to be used in existing code. Used now for Isddd export (see bexport.go). TODO(gri) rename.
302 // pseudo-types for literals
307 // pseudo-type for frame layout
315 // Ctype describes the constant kind of an "ideal" (untyped) constant.
332 // must match ../../pkg/nreflect/type.go:/Chandir
336 Cboth = Crecv | Csend
339 // The Class of a variable/function describes the "storage class"
340 // of a variable or function. During parsing, storage classes are
341 // called declaration contexts.
346 PEXTERN // global variable
347 PAUTO // local variables
348 PPARAM // input arguments
349 PPARAMOUT // output results
350 PPARAMREF // closure variable reference
351 PFUNC // global function
353 PDISCARD // discard during parse of duplicate import
355 PHEAP = 1 << 7 // an extra bit to identify an escaped variable
359 Etop = 1 << 1 // evaluated at statement level
360 Erv = 1 << 2 // evaluated in value context
362 Ecall = 1 << 4 // call-only expressions are ok
363 Efnstruct = 1 << 5 // multivalue function returns are ok
364 Eiota = 1 << 6 // iota is ok
365 Easgn = 1 << 7 // assigning to expression
366 Eindir = 1 << 8 // indirecting through expression
367 Eaddr = 1 << 9 // taking address of expression
368 Eproc = 1 << 10 // inside a go statement
369 Ecomplit = 1 << 11 // type in composite literal
372 type Typedef struct {
391 cp string // used for content when bin==nil
394 peekc1 int // second peekc for ...
409 // argument passing to/from
412 W int // input for both - width
413 S int // output for both - shift
414 Bad int // output for both - unexpected failure
416 // magic multiplier for signed literal divisors
417 Sd int64 // input - literal divisor
418 Sm int64 // output - multiplier
420 // magic multiplier for unsigned literal divisors
421 Ud uint64 // input - literal divisor
422 Um uint64 // output - multiplier
423 Ua int // output - adder
426 // note this is the runtime representation
427 // of the compilers arrays.
430 // { // must not move anything
431 // uchar array[8]; // pointer to data
432 // uchar nel[4]; // number of elements
433 // uchar cap[4]; // allocated number of elements
435 var Array_array int // runtime offsetof(Array,array) - same for String
437 var Array_nel int // runtime offsetof(Array,nel) - same for String
439 var Array_cap int // runtime offsetof(Array,cap)
441 var sizeof_Array int // runtime sizeof(Array)
443 // note this is the runtime representation
444 // of the compilers strings.
447 // { // must not move anything
448 // uchar array[8]; // pointer to data
449 // uchar nel[4]; // number of elements
451 var sizeof_String int // runtime sizeof(String)
453 var dotlist [10]Dlist // size is max depth of embeddeds
465 var pragcgobuf string
477 var nsyntaxerrors int
483 var nolocalimports int
485 var lexbuf bytes.Buffer
486 var strbuf bytes.Buffer
487 var litbuf string // LLITERAL value for use in syntax error messages
493 var Debug_checknil int
494 var Debug_typeassert int
496 var importmyname *Sym // my name for package
498 var localpkg *Pkg // package being compiled
500 var importpkg *Pkg // package being imported
502 var structpkg *Pkg // package that declared struct, during import
504 var builtinpkg *Pkg // fake package for builtins
506 var gostringpkg *Pkg // fake pkg for Go strings
508 var itabpkg *Pkg // fake pkg for itab cache
510 var Runtimepkg *Pkg // package runtime
512 var racepkg *Pkg // package runtime/race
514 var msanpkg *Pkg // package runtime/msan
516 var typepkg *Pkg // fake package for runtime type info (headers)
518 var typelinkpkg *Pkg // fake package for runtime type info (data)
520 var weaktypepkg *Pkg // weak references to runtime type info
522 var unsafepkg *Pkg // package unsafe
524 var trackpkg *Pkg // fake package for field tracking
526 var Tptr EType // either TPTR32 or TPTR64
528 var myimportpath string
532 var localimport string
536 var Types [NTYPE]*Type
538 var idealstring *Type
548 var Simtype [NTYPE]EType
555 Iscomplex [NTYPE]bool
564 okfornone [NTYPE]bool
566 okforbool [NTYPE]bool
569 okforarith [NTYPE]bool
570 okforconst [NTYPE]bool
578 var Minintval [NTYPE]*Mpint
580 var Maxintval [NTYPE]*Mpint
582 var minfltval [NTYPE]*Mpflt
584 var maxfltval [NTYPE]*Mpflt
588 var externdcl []*Node
590 var exportlist []*Node
592 var importlist []*Node // imported functions and methods with inlinable bodies
596 var dclcontext Class // PEXTERN/PAUTO
598 var incannedimport int
600 var statuniqgen int // name generator for static temps
606 var lastconst *NodeList
612 var Stksize int64 // stack size for current frame
614 var stkptrsize int64 // prefix of stack containing pointers
616 var blockgen int32 // max block number
618 var block int32 // current block number
620 var hasdefer bool // flag that curfn has defer statement
630 var typesw *Node // TODO(gri) remove when yacc-based parser is gone
638 var compiling_runtime int
640 var compiling_wrappers int
642 var use_writebarrier int
646 var flag_installsuffix string
652 var flag_largemodel int
654 // Whether we are adding any sort of code instrumentation, such as
655 // when the race detector is enabled.
656 var instrumenting bool
658 // Pending annotations for next func declaration.
665 nowritebarrierrec bool
677 var bstdout obj.Biobuf
681 var continpc *obj.Prog
683 var breakpc *obj.Prog
689 var Disable_checknil int
692 Prog *obj.Prog // actual instruction
693 P1 *Flow // predecessors of this instruction: p1,
694 P2 *Flow // and then p2 linked though p2link.
696 S1 *Flow // successors of this instruction (at most two: s1 and s2).
698 Link *Flow // next instruction in function code
700 Active int32 // usable by client
702 Id int32 // sequence number in flow graph
703 Rpo int32 // reverse post ordering
704 Loop uint16 // x5 for every loop
705 Refset bool // diagnostic generated
707 Data interface{} // for use by client
714 // After calling flowrpo, rpo lists the flow nodes in reverse postorder,
715 // and each non-dead Flow node f has g->rpo[f->rpo] == f.
719 // interface to back end
722 // Pseudo-op, like TEXT, GLOBL, TYPE, PCDATA, FUNCDATA.
725 // There's nothing to say about the instruction,
726 // but it's still okay to see.
729 // Size of right-side write, or right-side read if no write.
737 // Left side (Prog.from): address taken, read, write.
742 // Register in middle (Prog.reg); only ever read. (arm, ppc64)
746 // Right side (Prog.to): address taken, read, write.
752 Move = 1 << 17 // straight move
753 Conv = 1 << 18 // size conversion
754 Cjmp = 1 << 19 // conditional jump
755 Break = 1 << 20 // breaks control flow (no fallthrough)
756 Call = 1 << 21 // function call
757 Jump = 1 << 22 // jump
758 Skip = 1 << 23 // data instruction
760 // Set, use, or kill of carry bit.
761 // Kill means we never look at the carry bit after this kind of instruction.
766 // Special cases for register use. (amd64, 386)
767 ShiftCX = 1 << 27 // possible shift by CX
768 ImulAXDX = 1 << 28 // possible multiply into DX:AX
770 // Instruction updates whichever of from/to is type D_OREG. (ppc64)
777 Thelinkarch *obj.LinkArch
786 REGZERO int // architectural zero register, if available
792 AddIndex func(*Node, int64, *Node) bool // optional
794 Bgen_float func(*Node, bool, int, *obj.Prog) // optional
795 Cgen64 func(*Node, *Node) // only on 32-bit systems
796 Cgenindex func(*Node, *Node, bool) *obj.Prog
797 Cgen_bmul func(Op, *Node, *Node, *Node) bool
798 Cgen_float func(*Node, *Node) // optional
799 Cgen_hmul func(*Node, *Node, *Node)
800 Cgen_shift func(Op, bool, *Node, *Node, *Node)
802 Cmp64 func(*Node, *Node, Op, int, *obj.Prog) // only on 32-bit systems
803 Defframe func(*obj.Prog)
804 Dodiv func(Op, *Node, *Node, *Node)
806 Expandchecks func(*obj.Prog)
808 Gins func(int, *Node, *Node) *obj.Prog
810 // Ginscmp generates code comparing n1 to n2 and jumping away if op is satisfied.
811 // The returned prog should be Patch'ed with the jump target.
812 // If op is not satisfied, code falls through to the next emitted instruction.
813 // Likely is the branch prediction hint: +1 for likely, -1 for unlikely, 0 for no opinion.
815 // Ginscmp must be able to handle all kinds of arguments for n1 and n2,
816 // not just simple registers, although it can assume that there are no
817 // function calls needed during the evaluation, and on 32-bit systems
818 // the values are guaranteed not to be 64-bit values, so no in-memory
819 // temporaries are necessary.
820 Ginscmp func(op Op, t *Type, n1, n2 *Node, likely int) *obj.Prog
822 // Ginsboolval inserts instructions to convert the result
823 // of a just-completed comparison to a boolean value.
824 // The first argument is the conditional jump instruction
825 // corresponding to the desired value.
826 // The second argument is the destination.
827 // If not present, Ginsboolval will be emulated with jumps.
828 Ginsboolval func(int, *Node)
830 Ginscon func(int, int64, *Node)
832 Gmove func(*Node, *Node)
833 Igenindex func(*Node, *Node, bool) *obj.Prog
836 Proginfo func(*obj.Prog) // fills in Prog.Info
837 Regtyp func(*obj.Addr) bool
838 Sameaddr func(*obj.Addr, *obj.Addr) bool
839 Smallindir func(*obj.Addr, *obj.Addr) bool
840 Stackaddr func(*obj.Addr) bool
841 Blockcopy func(*Node, *Node, int64, int64, int64)
842 Sudoaddable func(int, *Node, *obj.Addr) bool
844 Excludedregs func() uint64
845 RtoB func(int) uint64
846 FtoB func(int) uint64
847 BtoR func(uint64) int
848 BtoF func(uint64) int
849 Optoas func(Op, *Type) int
850 Doregbits func(int) uint64
851 Regnames func(*int) []string
852 Use387 bool // should 8g use 387 FP instructions instead of sse2.
863 var Deferreturn *Node
869 var panicdivide *Node
871 var throwreturn *Node
875 var typedmemmove_nostore *Node
877 var panicdottype *Node