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.
12 #define isblank goisblank
20 // The parser's maximum stack size.
21 // We have to use a #define macro here since yacc
22 // or bison will check for its definition and use
23 // a potentially smaller value if it is undefined.
24 #define YYMAXDEPTH 500
40 // These values are known by runtime.
41 // The MEMx and NOEQx values must run in parallel. See algtype.
65 BADWIDTH = -1000000000,
67 MaxStackVarSize = 10*1024*1024,
70 extern vlong MAXWIDTH;
73 * note this is the representation
74 * of the compilers string literals,
75 * it is not the runtime representation
77 typedef struct Strlit Strlit;
81 char s[1]; // variable
86 Mpscale = 29, // safely smaller than bits in a long
87 Mpprec = 16, // Mpscale*Mpprec is max number of bits
88 Mpnorm = Mpprec - 1, // significant words in a normalized float
89 Mpbase = 1L << Mpscale,
95 typedef struct Mpint Mpint;
103 typedef struct Mpflt Mpflt;
110 typedef struct Mpcplx Mpcplx;
117 typedef struct Val Val;
123 short reg; // OREGISTER
124 short bval; // bool value CTBOOL
125 Mpint* xval; // int CTINT, rune CTRUNE
126 Mpflt* fval; // float CTFLT
127 Mpcplx* cval; // float CTCPLX
128 Strlit* sval; // string CTSTR
132 // prevent incompatible type signatures between libgc and 8g on Plan 9
133 #pragma incomplete struct Array
135 typedef struct Array Array;
136 typedef struct Bvec Bvec;
137 typedef struct Pkg Pkg;
138 typedef struct Sym Sym;
139 typedef struct Node Node;
140 typedef struct NodeList NodeList;
141 typedef struct Type Type;
142 typedef struct Label Label;
150 uchar trecur; // to detect loops
152 uchar embedded; // TFIELD embedded type
154 uchar funarg; // on TSTRUCT and TFIELD
156 uchar local; // created in this file
158 uchar broke; // broken type definition.
159 uchar isddd; // TFIELD is ... argument
161 uchar haspointers; // 0 unknown, 1 no, 2 yes
163 Node* nod; // canonical OTYPE node
164 Type* orig; // original type (type literal or predefined type)
177 int32 vargen; // unique name for OTYPE/ONAME
183 Type* type; // actual type for TFIELD, element type for TARRAY, TCHAN, TMAP, TPTRxx
184 vlong width; // offset in TFIELD, width in all others
187 Type* down; // next struct field, also key type in TMAP
188 Type* outer; // outer struct
189 Strlit* note; // literal string annotation
192 vlong bound; // negative is dynamic array
195 Type* bucket; // internal type representing a hash bucket
196 Type* hmap; // internal type representing a Hmap (map header object)
197 Type* hiter; // internal type representing hash iterator state
198 Type* map; // link from the above 3 internal types back to the map type.
200 int32 maplineno; // first use of TFORW as map key
201 int32 embedlineno; // first use of TFORW as embedded type
203 // for TFORW, where to copy the eventual value to
206 Node *lastfn; // for usefield
210 typedef struct InitEntry InitEntry;
211 typedef struct InitPlan InitPlan;
215 vlong xoffset; // struct, array only
216 Node *key; // map only
222 vlong lit; // bytes of initialized non-zero literals
223 vlong zero; // bytes of zeros
224 vlong expr; // bytes of run-time computed expressions
240 EscMask = (1<<EscBits) - 1,
241 EscContentEscapes = 1<<EscBits, // value obtained by indirect of parameter escapes to some returned result
242 EscReturnBits = EscBits+1,
248 // Generic recursive walks should follow these fields.
261 uchar ullman; // sethi/ullman number
262 uchar addable; // type of addressability - 0 is not addressable
263 uchar trecur; // to detect loops
264 uchar etype; // op for OASOP, etype for OTYPE, exclam for export
265 uchar bounded; // bounds check unnecessary
266 uchar class; // PPARAM, PAUTO, PEXTERN, etc
267 uchar method; // OCALLMETH name
268 uchar embedded; // ODCLFIELD embedded type
269 uchar colas; // OAS resulting from :=
270 uchar diag; // already printed error about this
271 uchar noescape; // func arguments do not escape
272 uchar nosplit; // func should not execute on separate stack
273 uchar builtin; // built-in name, like len or close
283 uchar addrtaken; // address taken, even if not moved to heap
284 uchar dupok; // duplicate definitions ok (for func)
285 uchar wrapper; // is method wrapper (for func)
286 uchar reslice; // this is a reslice x = x[0:y] or x = append(x, ...)
287 schar likely; // likeliness of if statement
288 uchar hasbreak; // has break statement
289 uchar needzero; // if it contains pointers, needs to be zeroed on function entry
290 uchar needctxt; // function uses context register (has closure variables)
296 Node* orig; // original form, for printing, and tracking copies of ONAMEs
303 NodeList* cvars; // closure params
304 NodeList* dcl; // autodcl for this func/closure
305 NodeList* inl; // copy of the body for use in inlining
306 NodeList* inldcl; // copy of dcl for use in inlining
308 // OLITERAL/OREGISTER
313 Node* defn; // ONAME: initializing assignment; OLABEL: labeled statement
314 Node* pack; // real package for import . names
315 Node* curfn; // function for local variables
316 Type* paramfld; // TFIELD for this PPARAM; also for ODOT, curfn
318 // ONAME func param with PHEAP
319 Node* heapaddr; // temp holding heap address of param
320 Node* stackparam; // OPARAM node referring to stack copy of param
321 Node* alloc; // allocation call
323 // ONAME closure param with PPARAMREF
324 Node* outer; // outer PPARAMREF in nested closure
325 Node* closure; // ONAME/PHEAP <-> ONAME/PPARAMREF
327 // ONAME substitute while inlining
333 // OARRAYLIT, OMAPLIT, OSTRUCTLIT.
337 NodeList* escflowsrc; // flow(this, src)
338 NodeList* escretval; // on OCALLxxx, list of dummy return values
339 int escloopdepth; // -1: global, 0: return variables, 1:function top level, increased inside function for every loop or label to mark scopes
342 int32 vargen; // unique name for OTYPE/ONAME
346 vlong stkdelta; // offset added by stack frame compaction phase.
351 void* opt; // for optimization passes
356 * Every node has a walkgen field.
357 * If you want to do a traversal of a node graph that
358 * might contain duplicates and want to avoid
359 * visiting the same nodes twice, increment walkgen
360 * before starting. Then before processing a node, do
362 * if(n->walkgen == walkgen)
364 * n->walkgen = walkgen;
366 * Such a walk cannot call another such walk recursively,
367 * because of the use of the global walkgen.
369 EXTERN uint32 walkgen;
380 SymExport = 1<<0, // to be exported
382 SymExported = 1<<2, // already written out by export
392 uchar sym; // huffman encoding in object file
394 int32 npkg; // number of imported packages with this name
396 Pkg* importdef; // where imported definition was found
397 char* linkname; // link name
399 // saved and restored by dcopy
401 char* name; // variable name
402 Node* def; // definition: ONAME OTYPE OPACK or OLITERAL
403 Label* label; // corresponding label (ephemeral)
404 int32 block; // blocknumber to catch redeclaration
405 int32 lastlineno; // last declaration for diagnostic
406 Pkg* origpkg; // original package for . import
411 EXTERN Sym* dclstack;
415 char* name; // package name
416 Strlit* path; // string literal used in import statement
418 char* prefix; // escaped path for use in symbol table
420 uchar imported; // export data of this package was parsed
421 char exported; // import line written in export data
422 char direct; // imported directly
423 char safe; // whether the package is marked as safe
426 typedef struct Iter Iter;
442 ONAME, // var, const or func name
443 ONONAME, // unnamed arg or return value: f(int, string) (int, error) { etc }
453 OADDSTR, // s + "foo"
457 OARRAYBYTESTR, // string(bytes)
458 OARRAYBYTESTRTMP, // string(bytes) ephemeral
459 OARRAYRUNESTR, // string(runes)
460 OSTRARRAYBYTE, // []byte(s)
461 OSTRARRAYRUNE, // []rune(s)
462 OAS, // x = y or x := y
463 OAS2, // x, y, z = xx, yy, zz
464 OAS2FUNC, // x, y = f()
465 OAS2RECV, // x, ok = <-c
466 OAS2MAPR, // x, ok = m["foo"]
467 OAS2DOTTYPE, // x, ok = I.(int)
469 OCALL, // function call, method call or type conversion, possibly preceded by defer or go.
471 OCALLMETH, // t.Method()
472 OCALLINTER, // err.Error()
473 OCALLPART, // t.Method (without ())
476 OCLOSURE, // f = func() { etc }
477 OCMPIFACE, // err1 == err2
479 OCOMPLIT, // composite literal, typechecking may convert to a more specific OXXXLIT.
480 OMAPLIT, // M{"foo":3, "bar":4}
481 OSTRUCTLIT, // T{x:3, y:4}
482 OARRAYLIT, // [2]int{3, 4}
483 OPTRLIT, // &T{x:3, y:4}
484 OCONV, // var i int; var u uint; i = int(u)
486 OCONVNOP, // type Int int; var i int; var j Int; i = int(j)
489 ODCLFUNC, // func f() or func (r) f()
490 ODCLFIELD, // struct field, interface field, or func/method argument/return value.
491 ODCLCONST, // const pi = 3.14
492 ODCLTYPE, // type Int int
495 ODOTPTR, // p.x that is implicitly (*p).x
496 ODOTMETH, // t.Method
497 ODOTINTER, // err.Error
498 OXDOT, // t.x, typechecking may convert to a more specific ODOTXXX.
499 ODOTTYPE, // e = err.(MyErr)
500 ODOTTYPE2, // e, ok = err.(MyErr)
510 OKEY, // The x:3 in t{x:3, y:4}, the 1:2 in a[1:2], the 2:20 in [3]int{2:20}, etc.
511 OPARAM, // The on-stack copy of a parameter or return value that escapes.
513 OMAKE, // make, typechecking may convert to a more specific OMAKEXXX.
514 OMAKECHAN, // make(chan int)
515 OMAKEMAP, // make(map[string]int)
516 OMAKESLICE, // make([]int, 0)
535 OSLICE, // v[1:2], typechecking may convert to a more specific OSLICEXXX.
538 OSLICE3, // v[1:2:3], typechecking may convert to OSLICE3ARR.
539 OSLICE3ARR, // a[1:2:3]
542 ORUNESTR, // string(i)
543 OSELRECV, // case x = <-c:
544 OSELRECV2, // case x, ok = <-c:
551 OBLOCK, // block of code
553 OCASE, // case, after being verified by swt.c's casebody.
554 OXCASE, // case, before verification.
555 OCONTINUE, // continue
558 OFALL, // fallthrough, after being verified by swt.c's casebody.
559 OXFALL, // fallthrough, before verification.
569 OTYPESW, // switch err.(type)
573 OTMAP, // map[string]int
574 OTSTRUCT, // struct{}
575 OTINTER, // interface{}
577 OTARRAY, // []int, [8]int, [N]int or [...]int
580 ODDD, // func f(args ...int) or f(l...) or var a = [...]int{0, 1, 2}.
581 ODDDARG, // func f(args ...int), introduced by escape analysis.
582 OINLCALL, // intermediary representation of an inlined call.
583 OEFACE, // itable and data words of an empty-interface value.
584 OITAB, // itable word of an interface value.
585 OSPTR, // base pointer of a slice or string.
586 OCLOSUREVAR, // variable reference at beginning of closure function
587 OCFUNC, // reference to c function pointer (not go func value)
588 OCHECKNIL, // emit code to ensure pointer/interface not nil
589 OVARKILL, // variable is dead
591 // arch-specific registers
592 OREGISTER, // a register, such as AX.
593 OINDREG, // offset plus indirect of a register, such as 8(SP).
595 // 386/amd64-specific opcodes
596 OCMP, // compare: ACMP.
597 ODEC, // decrement: ADEC.
598 OINC, // increment: AINC.
599 OEXTEND, // extend: ACWD/ACDQ/ACQO.
600 OHMUL, // high mul: AMUL/AIMUL for unsigned/signed (OMUL uses AIMUL for both).
601 OLROT, // left rotate: AROL.
602 ORROTC, // right rotate-carry: ARCR.
603 ORETJMP, // return to other function
616 TINT, TUINT, TUINTPTR,
626 TPTR32, TPTR64, // 17
641 // pseudo-types for literals
646 // pseudo-type for frame layout
669 /* types of channel */
670 /* must match ../../pkg/nreflect/type.go:/Chandir */
674 Cboth = Crecv | Csend,
677 // declaration context
682 PEXTERN, // global variable
683 PAUTO, // local variables
684 PPARAM, // input arguments
685 PPARAMOUT, // output results
686 PPARAMREF, // closure variable reference
687 PFUNC, // global function
689 PDISCARD, // discard during parse of duplicate import
691 PHEAP = 1<<7, // an extra bit to identify an escaped variable
696 Etop = 1<<1, // evaluated at statement level
697 Erv = 1<<2, // evaluated in value context
699 Ecall = 1<<4, // call-only expressions are ok
700 Efnstruct = 1<<5, // multivalue function returns are ok
701 Eiota = 1<<6, // iota is ok
702 Easgn = 1<<7, // assigning to expression
703 Eindir = 1<<8, // indirecting through expression
704 Eaddr = 1<<9, // taking address of expression
705 Eproc = 1<<10, // inside a go statement
706 Ecomplit = 1<<11, // type in composite literal
710 #define NVAR (BITS*sizeof(uint64)*8)
712 typedef struct Bits Bits;
722 int32 n; // number of bits
726 typedef struct Var Var;
738 EXTERN Var var[NVAR];
740 typedef struct Typedef Typedef;
748 extern Typedef typedefs[];
750 typedef struct Sig Sig;
763 typedef struct Io Io;
773 int peekc1; // second peekc for ...
774 char* cp; // used for content when bin==nil
778 typedef struct Dlist Dlist;
784 typedef struct Idir Idir;
792 * argument passing to/from
795 typedef struct Magic Magic;
798 int w; // input for both - width
799 int s; // output for both - shift
800 int bad; // output for both - unexpected failure
802 // magic multiplier for signed literal divisors
803 int64 sd; // input - literal divisor
804 int64 sm; // output - multiplier
806 // magic multiplier for unsigned literal divisors
807 uint64 ud; // input - literal divisor
808 uint64 um; // output - multiplier
809 int ua; // output - adder
820 // for use during gen
821 Prog* gotopc; // pointer to unresolved gotos
822 Prog* labelpc; // pointer to code
823 Prog* breakpc; // pointer to code
824 Prog* continpc; // pointer to code
826 #define L ((Label*)0)
829 * note this is the runtime representation
830 * of the compilers arrays.
833 * { // must not move anything
834 * uchar array[8]; // pointer to data
835 * uchar nel[4]; // number of elements
836 * uchar cap[4]; // allocated number of elements
839 EXTERN int Array_array; // runtime offsetof(Array,array) - same for String
840 EXTERN int Array_nel; // runtime offsetof(Array,nel) - same for String
841 EXTERN int Array_cap; // runtime offsetof(Array,cap)
842 EXTERN int sizeof_Array; // runtime sizeof(Array)
846 * note this is the runtime representation
847 * of the compilers strings.
850 * { // must not move anything
851 * uchar array[8]; // pointer to data
852 * uchar nel[4]; // number of elements
855 EXTERN int sizeof_String; // runtime sizeof(String)
857 EXTERN Dlist dotlist[10]; // size is max depth of embeddeds
861 EXTERN int32 lexlineno;
863 EXTERN int32 prevlineno;
865 EXTERN Fmt pragcgobuf;
868 EXTERN char* outfile;
871 EXTERN int nsavederrors;
872 EXTERN int nsyntaxerrors;
874 EXTERN int nolocalimports;
875 EXTERN char namebuf[NSYMB];
876 EXTERN char lexbuf[NSYMB];
877 EXTERN char litbuf[NSYMB];
878 EXTERN int debug[256];
879 EXTERN char* debugstr;
880 EXTERN int debug_checknil;
881 EXTERN Sym* hash[NHASH];
882 EXTERN Sym* importmyname; // my name for package
883 EXTERN Pkg* localpkg; // package being compiled
884 EXTERN Pkg* importpkg; // package being imported
885 EXTERN Pkg* structpkg; // package that declared struct, during import
886 EXTERN Pkg* builtinpkg; // fake package for builtins
887 EXTERN Pkg* gostringpkg; // fake pkg for Go strings
888 EXTERN Pkg* itabpkg; // fake pkg for itab cache
889 EXTERN Pkg* runtimepkg; // package runtime
890 EXTERN Pkg* racepkg; // package runtime/race
891 EXTERN Pkg* stringpkg; // fake package for C strings
892 EXTERN Pkg* typepkg; // fake package for runtime type info (headers)
893 EXTERN Pkg* typelinkpkg; // fake package for runtime type info (data)
894 EXTERN Pkg* weaktypepkg; // weak references to runtime type info
895 EXTERN Pkg* unsafepkg; // package unsafe
896 EXTERN Pkg* trackpkg; // fake package for field tracking
897 EXTERN Pkg* rawpkg; // fake package for raw symbol names
898 EXTERN Pkg* phash[128];
899 EXTERN int tptr; // either TPTR32 or TPTR64
900 extern char* runtimeimport;
901 extern char* unsafeimport;
902 EXTERN char* myimportpath;
904 EXTERN char* localimport;
907 EXTERN Type* types[NTYPE];
908 EXTERN Type* idealstring;
909 EXTERN Type* idealbool;
910 EXTERN Type* bytetype;
911 EXTERN Type* runetype;
912 EXTERN Type* errortype;
913 EXTERN uchar simtype[NTYPE];
914 EXTERN uchar isptr[NTYPE];
915 EXTERN uchar isforw[NTYPE];
916 EXTERN uchar isint[NTYPE];
917 EXTERN uchar isfloat[NTYPE];
918 EXTERN uchar iscomplex[NTYPE];
919 EXTERN uchar issigned[NTYPE];
920 EXTERN uchar issimple[NTYPE];
922 EXTERN uchar okforeq[NTYPE];
923 EXTERN uchar okforadd[NTYPE];
924 EXTERN uchar okforand[NTYPE];
925 EXTERN uchar okfornone[NTYPE];
926 EXTERN uchar okforcmp[NTYPE];
927 EXTERN uchar okforbool[NTYPE];
928 EXTERN uchar okforcap[NTYPE];
929 EXTERN uchar okforlen[NTYPE];
930 EXTERN uchar okforarith[NTYPE];
931 EXTERN uchar okforconst[NTYPE];
932 EXTERN uchar* okfor[OEND];
933 EXTERN uchar iscmp[OEND];
935 EXTERN Mpint* minintval[NTYPE];
936 EXTERN Mpint* maxintval[NTYPE];
937 EXTERN Mpflt* minfltval[NTYPE];
938 EXTERN Mpflt* maxfltval[NTYPE];
940 EXTERN NodeList* xtop;
941 EXTERN NodeList* externdcl;
942 EXTERN NodeList* closures;
943 EXTERN NodeList* exportlist;
944 EXTERN NodeList* importlist; // imported functions and methods with inlinable bodies
945 EXTERN NodeList* funcsyms;
946 EXTERN int dclcontext; // PEXTERN/PAUTO
947 EXTERN int incannedimport;
948 EXTERN int statuniqgen; // name generator for static temps
952 EXTERN NodeList* lastconst;
953 EXTERN Node* lasttype;
955 EXTERN vlong stksize; // stack size for current frame
956 EXTERN vlong stkptrsize; // prefix of stack containing pointers
957 EXTERN int32 blockgen; // max block number
958 EXTERN int32 block; // current block number
959 EXTERN int hasdefer; // flag that curfn has defer statetment
971 extern char* thestring;
972 extern LinkArch* thelinkarch;
979 EXTERN int funcdepth;
980 EXTERN int typecheckok;
981 EXTERN int compiling_runtime;
982 EXTERN int compiling_wrappers;
983 EXTERN int use_writebarrier;
985 EXTERN char* flag_installsuffix;
986 EXTERN int flag_race;
987 EXTERN int flag_largemodel;
990 EXTERN int debuglive;
993 EXTERN int nointerface;
994 EXTERN int fieldtrack_enabled;
995 EXTERN int precisestack_enabled;
996 EXTERN int writearchive;
998 EXTERN Biobuf bstdout;
1010 int argsize(Type *t);
1011 void checkwidth(Type *t);
1012 void defercheckwidth(void);
1013 void dowidth(Type *t);
1014 void resumecheckwidth(void);
1015 vlong rnd(vlong o, vlong r);
1016 void typeinit(void);
1021 Array* arraynew(int32 capacity, int32 size);
1022 void arrayfree(Array *array);
1023 int32 arraylength(Array *array);
1024 void* arrayget(Array *array, int32 index);
1025 void arrayset(Array *array, int32 index, void *element);
1026 void arrayadd(Array *array, void *element);
1027 void arraysort(Array* array, int (*cmp)(const void*, const void*));
1033 Bits band(Bits a, Bits b);
1035 int beq(Bits a, Bits b);
1036 int bitno(uint64 b);
1040 Bits bor(Bits a, Bits b);
1041 int btest(Bits *a, uint n);
1042 void biset(Bits *a, uint n);
1043 void biclr(Bits *a, uint n);
1048 Bvec* bvalloc(int32 n);
1049 void bvandnot(Bvec *dst, Bvec *src1, Bvec *src2);
1050 int bvcmp(Bvec *bv1, Bvec *bv2);
1051 void bvcopy(Bvec *dst, Bvec *src);
1052 Bvec* bvconcat(Bvec *src1, Bvec *src2);
1053 int bvget(Bvec *bv, int32 i);
1054 int32 bvnext(Bvec *bv, int32 i);
1055 int bvisempty(Bvec *bv);
1056 void bvnot(Bvec *bv);
1057 void bvor(Bvec *dst, Bvec *src1, Bvec *src2);
1058 void bvand(Bvec *dst, Bvec *src1, Bvec *src2);
1059 void bvprint(Bvec *bv);
1060 void bvreset(Bvec *bv, int32 i);
1061 void bvresetall(Bvec *bv);
1062 void bvset(Bvec *bv, int32 i);
1067 Node* closurebody(NodeList *body);
1068 void closurehdr(Node *ntype);
1069 void typecheckclosure(Node *func, int top);
1070 Node* walkclosure(Node *func, NodeList **init);
1071 void typecheckpartialcall(Node*, Node*);
1072 Node* walkpartialcall(Node*, NodeList**);
1077 int cmpslit(Node *l, Node *r);
1078 int consttype(Node *n);
1079 void convconst(Node *con, Type *t, Val *val);
1080 void convlit(Node **np, Type *t);
1081 void convlit1(Node **np, Type *t, int explicit);
1082 void defaultlit(Node **np, Type *t);
1083 void defaultlit2(Node **lp, Node **rp, int force);
1084 void evconst(Node *n);
1085 int isconst(Node *n, int ct);
1086 int isgoconst(Node *n);
1087 Node* nodcplxlit(Val r, Val i);
1088 Node* nodlit(Val v);
1089 long nonnegconst(Node *n);
1090 int doesoverflow(Val v, Type *t);
1091 void overflow(Val v, Type *t);
1092 int smallintconst(Node *n);
1094 Mpflt* truncfltlit(Mpflt *oldv, Type *t);
1099 void complexadd(int op, Node *nl, Node *nr, Node *res);
1100 void complexbool(int op, Node *nl, Node *nr, int true, int likely, Prog *to);
1101 void complexgen(Node *n, Node *res);
1102 void complexminus(Node *nl, Node *res);
1103 void complexmove(Node *f, Node *t);
1104 void complexmul(Node *nl, Node *nr, Node *res);
1105 int complexop(Node *n, Node *res);
1106 void nodfconst(Node *n, Type *t, Mpflt* fval);
1111 void addmethod(Sym *sf, Type *t, int local, int nointerface);
1112 void addvar(Node *n, Type *t, int ctxt);
1113 NodeList* checkarglist(NodeList *all, int input);
1114 Node* colas(NodeList *left, NodeList *right, int32 lno);
1115 void colasdefn(NodeList *left, Node *defn);
1116 NodeList* constiter(NodeList *vl, Node *t, NodeList *cl);
1117 Node* dclname(Sym *s);
1118 void declare(Node *n, int ctxt);
1119 void dumpdcl(char *st);
1120 Node* embedded(Sym *s, Pkg *pkg);
1121 Node* fakethis(void);
1122 void funcbody(Node *n);
1123 void funccompile(Node *n, int isclosure);
1124 void funchdr(Node *n);
1125 Type* functype(Node *this, NodeList *in, NodeList *out);
1126 void ifacedcl(Node *n);
1127 int isifacemethod(Type *f);
1129 Node* methodname(Node *n, Type *t);
1130 Node* methodname1(Node *n, Node *t);
1131 Sym* methodsym(Sym *nsym, Type *t0, int iface);
1132 Node* newname(Sym *s);
1133 Node* oldname(Sym *s);
1135 void poptodcl(void);
1136 void redeclare(Sym *s, char *where);
1137 void testdclstack(void);
1138 Type* tointerface(NodeList *l);
1139 Type* tostruct(NodeList *l);
1140 Node* typedcl0(Sym *s);
1141 Node* typedcl1(Node *n, Node *t, int local);
1142 Node* typenod(Type *t);
1143 NodeList* variter(NodeList *vl, Node *t, NodeList *el);
1149 void escapes(NodeList*);
1154 void autoexport(Node *n, int ctxt);
1155 void dumpexport(void);
1156 void dumpasmhdr(void);
1157 int exportname(char *s);
1158 void exportsym(Node *n);
1159 void importconst(Sym *s, Type *t, Node *n);
1160 void importimport(Sym *s, Strlit *z);
1161 Sym* importsym(Sym *s, int op);
1162 void importtype(Type *pt, Type *t);
1163 void importvar(Sym *s, Type *t);
1164 Type* pkgtype(Sym *s);
1169 void fmtinstallgo(void);
1170 void dump(char *s, Node *n);
1171 void dumplist(char *s, NodeList *l);
1176 void addrescapes(Node *n);
1177 void cgen_as(Node *nl, Node *nr);
1178 void cgen_callmeth(Node *n, int proc);
1179 void cgen_eface(Node* n, Node* res);
1180 void cgen_slice(Node* n, Node* res);
1181 void clearlabels(void);
1182 void clearslim(Node*);
1183 void checklabels(void);
1184 int dotoffset(Node *n, int64 *oary, Node **nn);
1186 void genlist(NodeList *l);
1187 Node* sysfunc(char *name);
1188 void tempname(Node *n, Type *t);
1194 void fninit(NodeList *n);
1195 Sym* renameinit(void);
1200 void caninl(Node *fn);
1201 void inlcalls(Node *fn);
1202 void typecheckinl(Node *fn);
1207 void cannedimports(char *file, char *cp);
1208 void importfile(Val *f, int line);
1209 char* lexname(int lex);
1210 char* expstring(void);
1211 void mkpackage(char* pkgname);
1212 void unimportfile(void);
1222 void mpaddcfix(Mpint *a, vlong c);
1223 void mpaddcflt(Mpflt *a, double c);
1224 void mpatofix(Mpint *a, char *as);
1225 void mpatoflt(Mpflt *a, char *as);
1226 int mpcmpfixc(Mpint *b, vlong c);
1227 int mpcmpfixfix(Mpint *a, Mpint *b);
1228 int mpcmpfixflt(Mpint *a, Mpflt *b);
1229 int mpcmpfltc(Mpflt *b, double c);
1230 int mpcmpfltfix(Mpflt *a, Mpint *b);
1231 int mpcmpfltflt(Mpflt *a, Mpflt *b);
1232 void mpcomfix(Mpint *a);
1233 void mpdivfixfix(Mpint *a, Mpint *b);
1234 void mpmodfixfix(Mpint *a, Mpint *b);
1235 void mpmovefixfix(Mpint *a, Mpint *b);
1236 void mpmovefixflt(Mpflt *a, Mpint *b);
1237 int mpmovefltfix(Mpint *a, Mpflt *b);
1238 void mpmovefltflt(Mpflt *a, Mpflt *b);
1239 void mpmulcfix(Mpint *a, vlong c);
1240 void mpmulcflt(Mpflt *a, double c);
1241 void mpsubfixfix(Mpint *a, Mpint *b);
1242 void mpsubfltflt(Mpflt *a, Mpflt *b);
1247 void mpaddfixfix(Mpint *a, Mpint *b, int);
1248 void mpandfixfix(Mpint *a, Mpint *b);
1249 void mpandnotfixfix(Mpint *a, Mpint *b);
1250 void mpdivfract(Mpint *a, Mpint *b);
1251 void mpdivmodfixfix(Mpint *q, Mpint *r, Mpint *n, Mpint *d);
1252 vlong mpgetfix(Mpint *a);
1253 void mplshfixfix(Mpint *a, Mpint *b);
1254 void mpmovecfix(Mpint *a, vlong c);
1255 void mpmulfixfix(Mpint *a, Mpint *b);
1256 void mpmulfract(Mpint *a, Mpint *b);
1257 void mpnegfix(Mpint *a);
1258 void mporfixfix(Mpint *a, Mpint *b);
1259 void mprshfixfix(Mpint *a, Mpint *b);
1260 void mpshiftfix(Mpint *a, int s);
1261 int mptestfix(Mpint *a);
1262 void mpxorfixfix(Mpint *a, Mpint *b);
1267 void mpaddfltflt(Mpflt *a, Mpflt *b);
1268 void mpdivfltflt(Mpflt *a, Mpflt *b);
1269 double mpgetflt(Mpflt *a);
1270 double mpgetflt32(Mpflt *a);
1271 void mpmovecflt(Mpflt *a, double c);
1272 void mpmulfltflt(Mpflt *a, Mpflt *b);
1273 void mpnegflt(Mpflt *a);
1274 void mpnorm(Mpflt *a);
1275 void mpsetexp(Mpflt *a, int exp);
1276 int mptestflt(Mpflt *a);
1277 int sigfig(Mpflt *a);
1282 void Bputname(Biobuf *b, LSym *s);
1283 int duint16(Sym *s, int off, uint16 v);
1284 int duint32(Sym *s, int off, uint32 v);
1285 int duint64(Sym *s, int off, uint64 v);
1286 int duint8(Sym *s, int off, uint8 v);
1287 int duintptr(Sym *s, int off, uint64 v);
1288 int dsname(Sym *s, int off, char *dat, int ndat);
1290 Sym* stringsym(char*, int);
1291 void slicebytes(Node*, char*, int);
1292 LSym* linksym(Sym*);
1297 void order(Node *fn);
1298 void orderstmtinplace(Node **stmt);
1303 void typecheckrange(Node *n);
1304 void walkrange(Node *n);
1309 void dumptypestructs(void);
1310 Type* methodfunc(Type *f, Type*);
1311 Node* typename(Type *t);
1312 Sym* typesym(Type *t);
1313 Sym* typenamesym(Type *t);
1314 Sym* tracksym(Type *t);
1315 Sym* typesymprefix(char *prefix, Type *t);
1316 int haspointers(Type *t);
1317 Type* hiter(Type* t);
1322 void typecheckselect(Node *sel);
1323 void walkselect(Node *sel);
1328 void anylit(int, Node *n, Node *var, NodeList **init);
1329 int gen_as_init(Node *n);
1330 NodeList* initfix(NodeList *l);
1331 int oaslit(Node *n, NodeList **init);
1332 int stataddr(Node *nam, Node *n);
1337 Node* adddot(Node *n);
1338 int adddot1(Sym *s, Type *t, int d, Type **save, int ignorecase);
1339 void addinit(Node**, NodeList*);
1340 Type* aindex(Node *b, Type *t);
1341 int algtype(Type *t);
1342 int algtype1(Type *t, Type **bad);
1343 void argtype(Node *on, Type *t);
1344 Node* assignconv(Node *n, Type *t, char *context);
1345 int assignop(Type *src, Type *dst, char **why);
1346 void badtype(int o, Type *tl, Type *tr);
1349 NodeList* concat(NodeList *a, NodeList *b);
1350 int convertop(Type *src, Type *dst, char **why);
1351 Node* copyexpr(Node*, Type*, NodeList**);
1352 int count(NodeList *l);
1353 int cplxsubtype(int et);
1354 int eqtype(Type *t1, Type *t2);
1355 int eqtypenoname(Type *t1, Type *t2);
1356 void errorexit(void);
1357 void expandmeth(Type *t);
1358 void fatal(char *fmt, ...);
1359 void flusherrors(void);
1360 void frame(int context);
1361 Type* funcfirst(Iter *s, Type *t);
1362 Type* funcnext(Iter *s);
1363 void genwrapper(Type *rcvr, Type *method, Sym *newnam, int iface);
1364 void genhash(Sym *sym, Type *t);
1365 void geneq(Sym *sym, Type *t);
1366 Type** getinarg(Type *t);
1367 Type* getinargx(Type *t);
1368 Type** getoutarg(Type *t);
1369 Type* getoutargx(Type *t);
1370 Type** getthis(Type *t);
1371 Type* getthisx(Type *t);
1372 int implements(Type *t, Type *iface, Type **missing, Type **have, int *ptr);
1373 void importdot(Pkg *opkg, Node *pack);
1375 int isbadimport(Strlit *s);
1376 int isblank(Node *n);
1377 int isblanksym(Sym *s);
1378 int isdirectiface(Type*);
1379 int isfixedarray(Type *t);
1380 int isideal(Type *t);
1381 int isinter(Type *t);
1383 int isnilinter(Type *t);
1384 int isptrto(Type *t, int et);
1385 int isslice(Type *t);
1386 int istype(Type *t, int et);
1387 int iszero(Node *n);
1388 void linehist(char *file, int32 off, int relative);
1389 NodeList* list(NodeList *l, Node *n);
1390 NodeList* list1(Node *n);
1391 void listsort(NodeList**, int(*f)(Node*, Node*));
1392 Node* liststmt(NodeList *l);
1393 NodeList* listtreecopy(NodeList *l);
1394 Sym* lookup(char *name);
1396 Type* maptype(Type *key, Type *val);
1397 Type* methtype(Type *t, int mustname);
1398 Pkg* mkpkg(Strlit *path);
1399 Sym* ngotype(Node *n);
1400 int noconv(Type *t1, Type *t2);
1401 Node* nod(int op, Node *nleft, Node *nright);
1402 Node* nodbool(int b);
1403 void nodconst(Node *n, Type *t, int64 v);
1404 Node* nodintconst(int64 v);
1405 Node* nodfltconst(Mpflt *v);
1407 int parserline(void);
1408 Sym* pkglookup(char *name, Pkg *pkg);
1409 int powtwo(Node *n);
1410 Type* ptrto(Type *t);
1411 void* remal(void *p, int32 on, int32 n);
1412 Sym* restrictlookup(char *name, Pkg *pkg);
1413 Node* safeexpr(Node *n, NodeList **init);
1414 void saveerrors(void);
1415 Node* cheapexpr(Node *n, NodeList **init);
1416 Node* localexpr(Node *n, Type *t, NodeList **init);
1417 void saveorignode(Node *n);
1418 int32 setlineno(Node *n);
1419 void setmaxarg(Type *t);
1420 Type* shallow(Type *t);
1421 int simsimtype(Type *t);
1422 void smagic(Magic *m);
1423 Type* sortinter(Type *t);
1424 uint32 stringhash(char *p);
1425 Strlit* strlit(char *s);
1426 int structcount(Type *t);
1427 Type* structfirst(Iter *s, Type **nn);
1428 Type* structnext(Iter *s);
1429 Node* syslook(char *name, int copy);
1430 Type* tounsigned(Type *t);
1431 Node* treecopy(Node *n);
1433 uint32 typehash(Type *t);
1434 void ullmancalc(Node *n);
1435 void umagic(Magic *m);
1436 void warn(char *fmt, ...);
1437 void warnl(int line, char *fmt, ...);
1438 void yyerror(char *fmt, ...);
1439 void yyerrorl(int line, char *fmt, ...);
1444 void typecheckswitch(Node *n);
1445 void walkswitch(Node *sw);
1450 int islvalue(Node *n);
1451 Node* typecheck(Node **np, int top);
1452 void typechecklist(NodeList *l, int top);
1453 Node* typecheckdef(Node *n);
1454 void copytype(Node *n, Type *t);
1455 void checkreturn(Node*);
1456 void queuemethod(Node *n);
1461 int isunsafebuiltin(Node *n);
1462 Node* unsafenmagic(Node *n);
1467 Node* callnew(Type *t);
1468 Node* chanfn(char *name, int n, Type *t);
1469 Node* mkcall(char *name, Type *t, NodeList **init, ...);
1470 Node* mkcall1(Node *fn, Type *t, NodeList **init, ...);
1471 int vmatch1(Node *l, Node *r);
1472 void walk(Node *fn);
1473 void walkexpr(Node **np, NodeList **init);
1474 void walkexprlist(NodeList *l, NodeList **init);
1475 void walkexprlistsafe(NodeList *l, NodeList **init);
1476 void walkexprlistcheap(NodeList *l, NodeList **init);
1477 void walkstmt(Node **np);
1478 void walkstmtlist(NodeList *l);
1479 Node* conv(Node*, Type*);
1480 int candiscard(Node*);
1481 int needwritebarrier(Node*, Node*);
1482 Node* outervalue(Node*);
1483 void usefield(Node*);
1486 * arch-specific ggen.c/gsubr.c/gobj.c/pgen.c/plive.c
1488 #define P ((Prog*)0)
1490 EXTERN Prog* continpc;
1491 EXTERN Prog* breakpc;
1493 EXTERN Prog* firstpc;
1496 EXTERN int disable_checknil;
1497 EXTERN vlong zerosize;
1499 int anyregalloc(void);
1500 void betypeinit(void);
1501 void bgen(Node *n, int true, int likely, Prog *to);
1502 void checknil(Node*, NodeList**);
1503 void expandchecks(Prog*);
1504 void cgen(Node*, Node*);
1505 void cgen_asop(Node *n);
1506 void cgen_call(Node *n, int proc);
1507 void cgen_callinter(Node *n, Node *res, int proc);
1508 void cgen_checknil(Node*);
1509 void cgen_ret(Node *n);
1510 void clearfat(Node *n);
1511 void compile(Node*);
1512 void defframe(Prog*);
1513 int dgostringptr(Sym*, int off, char *str);
1514 int dgostrlitptr(Sym*, int off, Strlit*);
1515 int dstringptr(Sym *s, int off, char *str);
1516 int dsymptr(Sym *s, int off, Sym *x, int xoff);
1517 int duintxx(Sym *s, int off, uint64 v, int wid);
1518 void dumpdata(void);
1519 void fixautoused(Prog*);
1520 void gdata(Node*, Node*, int);
1521 void gdatacomplex(Node*, Mpcplx*);
1522 void gdatastring(Node*, Strlit*);
1523 void ggloblnod(Node *nam);
1524 void ggloblsym(Sym *s, int32 width, int8 flags);
1525 void gvardef(Node*);
1526 void gvarkill(Node*);
1529 void movelarge(NodeList*);
1531 void linkarchinit(void);
1532 void liveness(Node*, Prog*, Sym*, Sym*);
1533 void twobitwalktype1(Type*, vlong*, Bvec*);
1534 void markautoused(Prog*);
1535 Plist* newplist(void);
1536 Node* nodarg(Type*, int);
1538 void patch(Prog*, Prog*);
1539 Prog* unpatch(Prog*);
1541 #pragma varargck type "B" Mpint*
1542 #pragma varargck type "E" int
1543 #pragma varargck type "E" uint
1544 #pragma varargck type "F" Mpflt*
1545 #pragma varargck type "H" NodeList*
1546 #pragma varargck type "J" Node*
1547 #pragma varargck type "lL" int32
1548 #pragma varargck type "L" int32
1549 #pragma varargck type "N" Node*
1550 #pragma varargck type "lN" Node*
1551 #pragma varargck type "O" int
1552 #pragma varargck type "O" uint
1553 #pragma varargck type "Q" Bits
1554 #pragma varargck type "S" Sym*
1555 #pragma varargck type "lS" LSym*
1556 #pragma varargck type "T" Type*
1557 #pragma varargck type "lT" Type*
1558 #pragma varargck type "V" Val*
1559 #pragma varargck type "Z" Strlit*
1564 void racewalk(Node *fn);