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 #include <u.h>
6 #include <libc.h>
7 #include <bio.h>
8
9 #undef OAPPEND
10
11 // avoid <ctype.h>
12 #undef isblank
13 #define isblank goisblank
14
15 #ifndef EXTERN
16 #define EXTERN extern
17 #endif
18
19 #undef BUFSIZ
20
21 enum
22 {
23 NHUNK = 50000,
24 BUFSIZ = 8192,
25 NSYMB = 500,
26 NHASH = 1024,
27 STRINGSZ = 200,
28 YYMAXDEPTH = 500,
29 MAXALIGN = 7,
30 UINF = 100,
31 HISTSZ = 10,
32
33 PRIME1 = 3,
34
35 AUNK = 100,
36
37 // these values are known by runtime
38 AMEM = 0,
39 ANOEQ,
40 ASTRING,
41 AINTER,
42 ANILINTER,
43 ASLICE,
44 AMEM8,
45 AMEM16,
46 AMEM32,
47 AMEM64,
48 AMEM128,
49 ANOEQ8,
50 ANOEQ16,
51 ANOEQ32,
52 ANOEQ64,
53 ANOEQ128,
54
55 BADWIDTH = -1000000000,
56 };
57
58 extern vlong MAXWIDTH;
59
60 /*
61 * note this is the representation
62 * of the compilers string literals,
63 * it is not the runtime representation
64 */
65 typedef struct Strlit Strlit;
66 struct Strlit
67 {
68 int32 len;
69 char s[3]; // variable
70 };
71
72 /*
73 * note this is the runtime representation
74 * of hashmap iterator. it is probably
75 * insafe to use it this way, but it puts
76 * all the changes in one place.
77 * only flag is referenced from go.
78 * actual placement does not matter as long
79 * as the size is >= actual size.
80 */
81 typedef struct Hiter Hiter;
82 struct Hiter
83 {
84 uchar data[8]; // return val from next
85 int32 elemsize; // size of elements in table */
86 int32 changes; // number of changes observed last time */
87 int32 i; // stack pointer in subtable_state */
88 uchar last[8]; // last hash value returned */
89 uchar h[8]; // the hash table */
90 struct
91 {
92 uchar sub[8]; // pointer into subtable */
93 uchar start[8]; // pointer into start of subtable */
94 uchar end[8]; // pointer into end of subtable */
95 uchar pad[8];
96 } sub[4];
97 };
98
99 enum
100 {
101 Mpscale = 29, // safely smaller than bits in a long
102 Mpprec = 16, // Mpscale*Mpprec is max number of bits
103 Mpnorm = Mpprec - 1, // significant words in a normalized float
104 Mpbase = 1L << Mpscale,
105 Mpsign = Mpbase >> 1,
106 Mpmask = Mpbase - 1,
107 Mpdebug = 0,
108 };
109
110 typedef struct Mpint Mpint;
111 struct Mpint
112 {
113 long a[Mpprec];
114 uchar neg;
115 uchar ovf;
116 };
117
118 typedef struct Mpflt Mpflt;
119 struct Mpflt
120 {
121 Mpint val;
122 short exp;
123 };
124
125 typedef struct Mpcplx Mpcplx;
126 struct Mpcplx
127 {
128 Mpflt real;
129 Mpflt imag;
130 };
131
132 typedef struct Val Val;
133 struct Val
134 {
135 short ctype;
136 union
137 {
138 short reg; // OREGISTER
139 short bval; // bool value CTBOOL
140 Mpint* xval; // int CTINT
141 Mpflt* fval; // float CTFLT
142 Mpcplx* cval; // float CTCPLX
143 Strlit* sval; // string CTSTR
144 } u;
145 };
146
147 typedef struct Pkg Pkg;
148 typedef struct Sym Sym;
149 typedef struct Node Node;
150 typedef struct NodeList NodeList;
151 typedef struct Type Type;
152 typedef struct Label Label;
153
154 struct Type
155 {
156 uchar etype;
157 uchar chan;
158 uchar recur; // to detect loops
159 uchar trecur; // to detect loops
160 uchar printed;
161 uchar embedded; // TFIELD embedded type
162 uchar siggen;
163 uchar funarg;
164 uchar copyany;
165 uchar local; // created in this file
166 uchar deferwidth;
167 uchar broke;
168 uchar isddd; // TFIELD is ... argument
169 uchar align;
170
171 Node* nod; // canonical OTYPE node
172 Type* orig; // original type (type literal or predefined type)
173 int lineno;
174
175 // TFUNCT
176 uchar thistuple;
177 uchar outtuple;
178 uchar intuple;
179 uchar outnamed;
180
181 Type* method;
182 Type* xmethod;
183
184 Sym* sym;
185 int32 vargen; // unique name for OTYPE/ONAME
186
187 Node* nname;
188 vlong argwid;
189
190 // most nodes
191 Type* type;
192 vlong width; // offset in TFIELD, width in all others
193
194 // TFIELD
195 Type* down; // also used in TMAP
196 Strlit* note; // literal string annotation
197
198 // TARRAY
199 int32 bound; // negative is dynamic array
200
201 int32 maplineno; // first use of TFORW as map key
202 int32 embedlineno; // first use of TFORW as embedded type
203 };
204 #define T ((Type*)0)
205
206 struct Node
207 {
208 uchar op;
209 uchar ullman; // sethi/ullman number
210 uchar addable; // type of addressability - 0 is not addressable
211 uchar trecur; // to detect loops
212 uchar etype; // op for OASOP, etype for OTYPE, exclam for export
213 uchar class; // PPARAM, PAUTO, PEXTERN, etc
214 uchar method; // OCALLMETH name
215 uchar embedded; // ODCLFIELD embedded type
216 uchar colas; // OAS resulting from :=
217 uchar diag; // already printed error about this
218 uchar noescape; // ONAME never move to heap
219 uchar funcdepth;
220 uchar builtin; // built-in name, like len or close
221 uchar walkdef;
222 uchar typecheck;
223 uchar local;
224 uchar initorder;
225 uchar dodata; // compile literal assignment as data statement
226 uchar used;
227 uchar isddd;
228 uchar pun; // don't registerize variable ONAME
229 uchar readonly;
230 uchar implicit; // don't show in printout
231
232 // most nodes
233 Node* left;
234 Node* right;
235 Type* type;
236 Type* realtype; // as determined by typecheck
237 NodeList* list;
238 NodeList* rlist;
239 Node* orig; // original form, for printing, and tracking copies of ONAMEs
240
241 // for-body
242 NodeList* ninit;
243 Node* ntest;
244 Node* nincr;
245 NodeList* nbody;
246
247 // if-body
248 NodeList* nelse;
249
250 // cases
251 Node* ncase;
252
253 // func
254 Node* nname;
255 Node* shortname;
256 NodeList* enter;
257 NodeList* exit;
258 NodeList* cvars; // closure params
259 NodeList* dcl; // autodcl for this func/closure
260
261 // OLITERAL/OREGISTER
262 Val val;
263
264 // ONAME
265 Node* ntype;
266 Node* defn;
267 Node* pack; // real package for import . names
268 Node* curfn; // function for local variables
269
270 // ONAME func param with PHEAP
271 Node* heapaddr; // temp holding heap address of param
272 Node* stackparam; // OPARAM node referring to stack copy of param
273 Node* alloc; // allocation call
274
275 // ONAME closure param with PPARAMREF
276 Node* outer; // outer PPARAMREF in nested closure
277 Node* closure; // ONAME/PHEAP <-> ONAME/PPARAMREF
278
279 // OPACK
280 Pkg* pkg;
281
282 Sym* sym; // various
283 int32 vargen; // unique name for OTYPE/ONAME
284 int32 lineno;
285 int32 endlineno;
286 vlong xoffset;
287 int32 stkdelta; // offset added by stack frame compaction phase.
288 int32 ostk;
289 int32 iota;
290 };
291 #define N ((Node*)0)
292 EXTERN int32 walkgen;
293
294 struct NodeList
295 {
296 Node* n;
297 NodeList* next;
298 NodeList* end;
299 };
300
301 enum
302 {
303 SymExport = 1<<0,
304 SymPackage = 1<<1,
305 SymExported = 1<<2,
306 SymUniq = 1<<3,
307 SymSiggen = 1<<4,
308 };
309
310 struct Sym
311 {
312 ushort lexical;
313 uchar flags;
314 uchar sym; // huffman encoding in object file
315 Sym* link;
316 int32 npkg; // number of imported packages with this name
317
318 // saved and restored by dcopy
319 Pkg* pkg;
320 char* name; // variable name
321 Node* def; // definition: ONAME OTYPE OPACK or OLITERAL
322 Label* label; // corresponding label (ephemeral)
323 int32 block; // blocknumber to catch redeclaration
324 int32 lastlineno; // last declaration for diagnostic
325 };
326 #define S ((Sym*)0)
327
328 EXTERN Sym* dclstack;
329
330 struct Pkg
331 {
332 char* name;
333 Strlit* path;
334 Sym* pathsym;
335 char* prefix;
336 Pkg* link;
337 char exported; // import line written in export data
338 char direct; // imported directly
339 };
340
341 typedef struct Iter Iter;
342 struct Iter
343 {
344 int done;
345 Type* tfunc;
346 Type* t;
347 Node** an;
348 Node* n;
349 };
350
351 typedef struct Hist Hist;
352 struct Hist
353 {
354 Hist* link;
355 char* name;
356 int32 line;
357 int32 offset;
358 };
359 #define H ((Hist*)0)
360
361 enum
362 {
363 OXXX,
364
365 // names
366 ONAME,
367 ONONAME,
368 OTYPE,
369 OPACK,
370 OLITERAL,
371
372 // exprs
373 OADD, OSUB, OOR, OXOR, OADDSTR,
374 OADDR,
375 OANDAND,
376 OAPPEND,
377 OARRAY,
378 OARRAYBYTESTR, OARRAYRUNESTR,
379 OSTRARRAYBYTE, OSTRARRAYRUNE,
380 OAS, OAS2, OAS2MAPW, OAS2FUNC, OAS2RECV, OAS2MAPR, OAS2DOTTYPE, OASOP,
381 OBAD,
382 OCALL, OCALLFUNC, OCALLMETH, OCALLINTER,
383 OCAP,
384 OCLOSE,
385 OCLOSURE,
386 OCMPIFACE, OCMPSTR,
387 OCOMPLIT, OMAPLIT, OSTRUCTLIT, OARRAYLIT,
388 OCONV, OCONVIFACE, OCONVNOP,
389 OCOPY,
390 ODCL, ODCLFUNC, ODCLFIELD, ODCLCONST, ODCLTYPE,
391 ODOT, ODOTPTR, ODOTMETH, ODOTINTER, OXDOT,
392 ODOTTYPE,
393 ODOTTYPE2,
394 OEQ, ONE, OLT, OLE, OGE, OGT,
395 OIND,
396 OINDEX, OINDEXMAP,
397 OKEY, OPARAM,
398 OLEN,
399 OMAKE, OMAKECHAN, OMAKEMAP, OMAKESLICE,
400 OHMUL, ORRC, OLRC, // high-mul and rotate-carry
401 OMUL, ODIV, OMOD, OLSH, ORSH, OAND, OANDNOT,
402 ONEW,
403 ONOT, OCOM, OPLUS, OMINUS,
404 OOROR,
405 OPANIC, OPRINT, OPRINTN,
406 OPAREN,
407 OSEND,
408 OSLICE, OSLICEARR, OSLICESTR,
409 ORECOVER,
410 ORECV,
411 ORUNESTR,
412 OSELRECV,
413 OSELRECV2,
414 OIOTA,
415 OREAL, OIMAG, OCOMPLEX,
416
417 // stmts
418 OBLOCK,
419 OBREAK,
420 OCASE, OXCASE,
421 OCONTINUE,
422 ODEFER,
423 OEMPTY,
424 OFALL, OXFALL,
425 OFOR,
426 OGOTO,
427 OIF,
428 OLABEL,
429 OPROC,
430 ORANGE,
431 ORETURN,
432 OSELECT,
433 OSWITCH,
434 OTYPESW, // l = r.(type)
435
436 // types
437 OTCHAN,
438 OTMAP,
439 OTSTRUCT,
440 OTINTER,
441 OTFUNC,
442 OTARRAY,
443 OTPAREN,
444
445 // misc
446 ODDD,
447
448 // for back ends
449 OCMP, ODEC, OEXTEND, OINC, OREGISTER, OINDREG,
450
451 OEND,
452 };
453 enum
454 {
455 Txxx, // 0
456
457 TINT8, TUINT8, // 1
458 TINT16, TUINT16,
459 TINT32, TUINT32,
460 TINT64, TUINT64,
461 TINT, TUINT, TUINTPTR,
462
463 TCOMPLEX64, // 12
464 TCOMPLEX128,
465
466 TFLOAT32, // 14
467 TFLOAT64,
468
469 TBOOL, // 16
470
471 TPTR32, TPTR64, // 17
472
473 TFUNC, // 19
474 TARRAY,
475 T_old_DARRAY,
476 TSTRUCT, // 22
477 TCHAN,
478 TMAP,
479 TINTER, // 25
480 TFORW,
481 TFIELD,
482 TANY,
483 TSTRING,
484 TUNSAFEPTR,
485
486 // pseudo-types for literals
487 TIDEAL, // 31
488 TNIL,
489 TBLANK,
490
491 // pseudo-type for frame layout
492 TFUNCARGS,
493 TCHANARGS,
494 TINTERMETH,
495
496 NTYPE,
497 };
498 enum
499 {
500 CTxxx,
501
502 CTINT,
503 CTFLT,
504 CTCPLX,
505 CTSTR,
506 CTBOOL,
507 CTNIL,
508 };
509
510 enum
511 {
512 /* types of channel */
513 /* must match ../../pkg/nreflect/type.go:/Chandir */
514 Cxxx,
515 Crecv = 1<<0,
516 Csend = 1<<1,
517 Cboth = Crecv | Csend,
518 };
519
520 enum
521 {
522 Pxxx,
523
524 PEXTERN, // declaration context
525 PAUTO,
526 PPARAM,
527 PPARAMOUT,
528 PPARAMREF, // param passed by reference
529 PFUNC,
530
531 PHEAP = 1<<7,
532 };
533
534 enum
535 {
536 Etop = 1<<1, // evaluated at statement level
537 Erv = 1<<2, // evaluated in value context
538 Etype = 1<<3,
539 Ecall = 1<<4, // call-only expressions are ok
540 Efnstruct = 1<<5, // multivalue function returns are ok
541 Eiota = 1<<6, // iota is ok
542 Easgn = 1<<7, // assigning to expression
543 Eindir = 1<<8, // indirecting through expression
544 Eaddr = 1<<9, // taking address of expression
545 Eproc = 1<<10, // inside a go statement
546 Ecomplit = 1<<11, // type in composite literal
547 };
548
549 #define BITS 5
550 #define NVAR (BITS*sizeof(uint32)*8)
551
552 typedef struct Bits Bits;
553 struct Bits
554 {
555 uint32 b[BITS];
556 };
557
558 EXTERN Bits zbits;
559
560 typedef struct Var Var;
561 struct Var
562 {
563 vlong offset;
564 Sym* sym;
565 Sym* gotype;
566 Node* node;
567 int width;
568 char name;
569 char etype;
570 char addr;
571 };
572
573 EXTERN Var var[NVAR];
574
575 typedef struct Typedef Typedef;
576 struct Typedef
577 {
578 char* name;
579 int etype;
580 int sameas;
581 };
582
583 extern Typedef typedefs[];
584
585 typedef struct Sig Sig;
586 struct Sig
587 {
588 char* name;
589 Pkg* pkg;
590 Sym* isym;
591 Sym* tsym;
592 Type* type;
593 Type* mtype;
594 int32 offset;
595 Sig* link;
596 };
597
598 typedef struct Io Io;
599 struct Io
600 {
601 char* infile;
602 Biobuf* bin;
603 int32 ilineno;
604 int nlsemi;
605 int eofnl;
606 int peekc;
607 int peekc1; // second peekc for ...
608 char* cp; // used for content when bin==nil
609 int importsafe;
610 };
611
612 typedef struct Dlist Dlist;
613 struct Dlist
614 {
615 Type* field;
616 };
617
618 typedef struct Idir Idir;
619 struct Idir
620 {
621 Idir* link;
622 char* dir;
623 };
624
625 /*
626 * argument passing to/from
627 * smagic and umagic
628 */
629 typedef struct Magic Magic;
630 struct Magic
631 {
632 int w; // input for both - width
633 int s; // output for both - shift
634 int bad; // output for both - unexpected failure
635
636 // magic multiplier for signed literal divisors
637 int64 sd; // input - literal divisor
638 int64 sm; // output - multiplier
639
640 // magic multiplier for unsigned literal divisors
641 uint64 ud; // input - literal divisor
642 uint64 um; // output - multiplier
643 int ua; // output - adder
644 };
645
646 typedef struct Prog Prog;
647
648 struct Label
649 {
650 uchar used;
651 Sym* sym;
652 Node* def;
653 NodeList* use;
654 Label* link;
655
656 // for use during gen
657 Prog* gotopc; // pointer to unresolved gotos
658 Prog* labelpc; // pointer to code
659 Prog* breakpc; // pointer to code
660 Prog* continpc; // pointer to code
661 };
662 #define L ((Label*)0)
663
664 /*
665 * note this is the runtime representation
666 * of the compilers arrays.
667 *
668 * typedef struct
669 * { // must not move anything
670 * uchar array[8]; // pointer to data
671 * uchar nel[4]; // number of elements
672 * uchar cap[4]; // allocated number of elements
673 * } Array;
674 */
675 EXTERN int Array_array; // runtime offsetof(Array,array) - same for String
676 EXTERN int Array_nel; // runtime offsetof(Array,nel) - same for String
677 EXTERN int Array_cap; // runtime offsetof(Array,cap)
678 EXTERN int sizeof_Array; // runtime sizeof(Array)
679
680
681 /*
682 * note this is the runtime representation
683 * of the compilers strings.
684 *
685 * typedef struct
686 * { // must not move anything
687 * uchar array[8]; // pointer to data
688 * uchar nel[4]; // number of elements
689 * } String;
690 */
691 EXTERN int sizeof_String; // runtime sizeof(String)
692
693 EXTERN Dlist dotlist[10]; // size is max depth of embeddeds
694
695 EXTERN Io curio;
696 EXTERN Io pushedio;
697 EXTERN int32 lexlineno;
698 EXTERN int32 lineno;
699 EXTERN int32 prevlineno;
700 EXTERN char* pathname;
701 EXTERN Hist* hist;
702 EXTERN Hist* ehist;
703
704 EXTERN char* infile;
705 EXTERN char* outfile;
706 EXTERN Biobuf* bout;
707 EXTERN int nerrors;
708 EXTERN int nsavederrors;
709 EXTERN int nsyntaxerrors;
710 EXTERN int safemode;
711 EXTERN char namebuf[NSYMB];
712 EXTERN char lexbuf[NSYMB];
713 EXTERN char litbuf[NSYMB];
714 EXTERN char debug[256];
715 EXTERN Sym* hash[NHASH];
716 EXTERN Sym* importmyname; // my name for package
717 EXTERN Pkg* localpkg; // package being compiled
718 EXTERN Pkg* importpkg; // package being imported
719 EXTERN Pkg* structpkg; // package that declared struct, during import
720 EXTERN Pkg* builtinpkg; // fake package for builtins
721 EXTERN Pkg* gostringpkg; // fake pkg for Go strings
722 EXTERN Pkg* runtimepkg; // package runtime
723 EXTERN Pkg* stringpkg; // fake package for C strings
724 EXTERN Pkg* typepkg; // fake package for runtime type info
725 EXTERN Pkg* unsafepkg; // package unsafe
726 EXTERN Pkg* phash[128];
727 EXTERN int tptr; // either TPTR32 or TPTR64
728 extern char* runtimeimport;
729 extern char* unsafeimport;
730 EXTERN Idir* idirs;
731
732 EXTERN Type* types[NTYPE];
733 EXTERN Type* idealstring;
734 EXTERN Type* idealbool;
735 EXTERN uchar simtype[NTYPE];
736 EXTERN uchar isptr[NTYPE];
737 EXTERN uchar isforw[NTYPE];
738 EXTERN uchar isint[NTYPE];
739 EXTERN uchar isfloat[NTYPE];
740 EXTERN uchar iscomplex[NTYPE];
741 EXTERN uchar issigned[NTYPE];
742 EXTERN uchar issimple[NTYPE];
743
744 EXTERN uchar okforeq[NTYPE];
745 EXTERN uchar okforadd[NTYPE];
746 EXTERN uchar okforand[NTYPE];
747 EXTERN uchar okfornone[NTYPE];
748 EXTERN uchar okforcmp[NTYPE];
749 EXTERN uchar okforbool[NTYPE];
750 EXTERN uchar okforcap[NTYPE];
751 EXTERN uchar okforlen[NTYPE];
752 EXTERN uchar okforarith[NTYPE];
753 EXTERN uchar okforconst[NTYPE];
754 EXTERN uchar* okfor[OEND];
755 EXTERN uchar iscmp[OEND];
756
757 EXTERN Mpint* minintval[NTYPE];
758 EXTERN Mpint* maxintval[NTYPE];
759 EXTERN Mpflt* minfltval[NTYPE];
760 EXTERN Mpflt* maxfltval[NTYPE];
761
762 EXTERN NodeList* xtop;
763 EXTERN NodeList* externdcl;
764 EXTERN NodeList* closures;
765 EXTERN NodeList* exportlist;
766 EXTERN NodeList* typelist;
767 EXTERN int dclcontext; // PEXTERN/PAUTO
768 EXTERN int incannedimport;
769 EXTERN int statuniqgen; // name generator for static temps
770 EXTERN int loophack;
771
772 EXTERN int32 iota;
773 EXTERN NodeList* lastconst;
774 EXTERN Node* lasttype;
775 EXTERN int32 maxarg;
776 EXTERN int32 stksize; // stack size for current frame
777 EXTERN int32 blockgen; // max block number
778 EXTERN int32 block; // current block number
779 EXTERN int hasdefer; // flag that curfn has defer statetment
780
781 EXTERN Node* curfn;
782
783 EXTERN int widthptr;
784
785 EXTERN Node* typesw;
786 EXTERN Node* nblank;
787
788 extern int thechar;
789 extern char* thestring;
790 EXTERN char* hunk;
791 EXTERN int32 nhunk;
792 EXTERN int32 thunk;
793
794 EXTERN int exporting;
795 EXTERN int erroring;
796 EXTERN int noargnames;
797
798 EXTERN int funcdepth;
799 EXTERN int typecheckok;
800 EXTERN int packagequotes;
801 EXTERN int longsymnames;
802 EXTERN int compiling_runtime;
803
804 /*
805 * y.tab.c
806 */
807 int yyparse(void);
808
809 /*
810 * align.c
811 */
812 int argsize(Type *t);
813 void checkwidth(Type *t);
814 void defercheckwidth(void);
815 void dowidth(Type *t);
816 void resumecheckwidth(void);
817 uint32 rnd(uint32 o, uint32 r);
818 void typeinit(void);
819
820 /*
821 * bits.c
822 */
823 int Qconv(Fmt *fp);
824 Bits band(Bits a, Bits b);
825 int bany(Bits *a);
826 int beq(Bits a, Bits b);
827 int bitno(int32 b);
828 Bits blsh(uint n);
829 Bits bnot(Bits a);
830 int bnum(Bits a);
831 Bits bor(Bits a, Bits b);
832 int bset(Bits a, uint n);
833
834 /*
835 * closure.c
836 */
837 Node* closurebody(NodeList *body);
838 void closurehdr(Node *ntype);
839 void typecheckclosure(Node *func, int top);
840 Node* walkclosure(Node *func, NodeList **init);
841 void walkcallclosure(Node *n, NodeList **init);
842
843 /*
844 * const.c
845 */
846 int cmpslit(Node *l, Node *r);
847 int consttype(Node *n);
848 void convconst(Node *con, Type *t, Val *val);
849 void convlit(Node **np, Type *t);
850 void convlit1(Node **np, Type *t, int explicit);
851 void defaultlit(Node **np, Type *t);
852 void defaultlit2(Node **lp, Node **rp, int force);
853 void evconst(Node *n);
854 int isconst(Node *n, int ct);
855 Node* nodcplxlit(Val r, Val i);
856 Node* nodlit(Val v);
857 long nonnegconst(Node *n);
858 void overflow(Val v, Type *t);
859 int smallintconst(Node *n);
860 Val toint(Val v);
861 Mpflt* truncfltlit(Mpflt *oldv, Type *t);
862
863 /*
864 * cplx.c
865 */
866 void complexadd(int op, Node *nl, Node *nr, Node *res);
867 void complexbool(int op, Node *nl, Node *nr, int true, Prog *to);
868 void complexgen(Node *n, Node *res);
869 void complexminus(Node *nl, Node *res);
870 void complexmove(Node *f, Node *t);
871 void complexmul(Node *nl, Node *nr, Node *res);
872 int complexop(Node *n, Node *res);
873 void nodfconst(Node *n, Type *t, Mpflt* fval);
874
875 /*
876 * dcl.c
877 */
878 void addmethod(Sym *sf, Type *t, int local);
879 void addvar(Node *n, Type *t, int ctxt);
880 NodeList* checkarglist(NodeList *all, int input);
881 Node* colas(NodeList *left, NodeList *right);
882 void colasdefn(NodeList *left, Node *defn);
883 NodeList* constiter(NodeList *vl, Node *t, NodeList *cl);
884 Node* dclname(Sym *s);
885 void declare(Node *n, int ctxt);
886 Type* dostruct(NodeList *l, int et);
887 void dumpdcl(char *st);
888 Node* embedded(Sym *s);
889 Node* fakethis(void);
890 void funcbody(Node *n);
891 void funccompile(Node *n, int isclosure);
892 void funchdr(Node *n);
893 Type* functype(Node *this, NodeList *in, NodeList *out);
894 void ifacedcl(Node *n);
895 int isifacemethod(Type *f);
896 void markdcl(void);
897 Node* methodname(Node *n, Type *t);
898 Node* methodname1(Node *n, Node *t);
899 Sym* methodsym(Sym *nsym, Type *t0, int iface);
900 Node* newname(Sym *s);
901 Type* newtype(Sym *s);
902 Node* oldname(Sym *s);
903 void popdcl(void);
904 void poptodcl(void);
905 void redeclare(Sym *s, char *where);
906 void testdclstack(void);
907 Node* typedcl0(Sym *s);
908 Node* typedcl1(Node *n, Node *t, int local);
909 void typedcl2(Type *pt, Type *t);
910 Node* typenod(Type *t);
911 NodeList* variter(NodeList *vl, Node *t, NodeList *el);
912
913 /*
914 * export.c
915 */
916 void autoexport(Node *n, int ctxt);
917 void dumpexport(void);
918 int exportname(char *s);
919 void exportsym(Node *n);
920 void importconst(Sym *s, Type *t, Node *n);
921 void importmethod(Sym *s, Type *t);
922 Sym* importsym(Sym *s, int op);
923 void importtype(Type *pt, Type *t);
924 void importvar(Sym *s, Type *t, int ctxt);
925 Type* pkgtype(Sym *s);
926
927 /*
928 * gen.c
929 */
930 void allocparams(void);
931 void cgen_as(Node *nl, Node *nr);
932 void cgen_callmeth(Node *n, int proc);
933 void clearlabels(void);
934 void checklabels(void);
935 int dotoffset(Node *n, int *oary, Node **nn);
936 void gen(Node *n);
937 void genlist(NodeList *l);
938 Node* sysfunc(char *name);
939 void tempname(Node *n, Type *t);
940
941 /*
942 * init.c
943 */
944 void fninit(NodeList *n);
945 Node* renameinit(Node *n);
946
947 /*
948 * lex.c
949 */
950 void cannedimports(char *file, char *cp);
951 void importfile(Val *f, int line);
952 char* lexname(int lex);
953 void mkpackage(char* pkgname);
954 void unimportfile(void);
955 int32 yylex(void);
956 extern int windows;
957 extern int yylast;
958 extern int yyprev;
959
960 /*
961 * mparith1.c
962 */
963 int Bconv(Fmt *fp);
964 int Fconv(Fmt *fp);
965 void mpaddcfix(Mpint *a, vlong c);
966 void mpaddcflt(Mpflt *a, double c);
967 void mpatofix(Mpint *a, char *as);
968 void mpatoflt(Mpflt *a, char *as);
969 int mpcmpfixc(Mpint *b, vlong c);
970 int mpcmpfixfix(Mpint *a, Mpint *b);
971 int mpcmpfixflt(Mpint *a, Mpflt *b);
972 int mpcmpfltc(Mpflt *b, double c);
973 int mpcmpfltfix(Mpflt *a, Mpint *b);
974 int mpcmpfltflt(Mpflt *a, Mpflt *b);
975 void mpcomfix(Mpint *a);
976 void mpdivfixfix(Mpint *a, Mpint *b);
977 void mpmodfixfix(Mpint *a, Mpint *b);
978 void mpmovefixfix(Mpint *a, Mpint *b);
979 void mpmovefixflt(Mpflt *a, Mpint *b);
980 int mpmovefltfix(Mpint *a, Mpflt *b);
981 void mpmovefltflt(Mpflt *a, Mpflt *b);
982 void mpmulcfix(Mpint *a, vlong c);
983 void mpmulcflt(Mpflt *a, double c);
984 void mpsubfixfix(Mpint *a, Mpint *b);
985 void mpsubfltflt(Mpflt *a, Mpflt *b);
986
987 /*
988 * mparith2.c
989 */
990 void mpaddfixfix(Mpint *a, Mpint *b);
991 void mpandfixfix(Mpint *a, Mpint *b);
992 void mpandnotfixfix(Mpint *a, Mpint *b);
993 void mpdivfract(Mpint *a, Mpint *b);
994 void mpdivmodfixfix(Mpint *q, Mpint *r, Mpint *n, Mpint *d);
995 vlong mpgetfix(Mpint *a);
996 void mplshfixfix(Mpint *a, Mpint *b);
997 void mpmovecfix(Mpint *a, vlong c);
998 void mpmulfixfix(Mpint *a, Mpint *b);
999 void mpmulfract(Mpint *a, Mpint *b);
1000 void mpnegfix(Mpint *a);
1001 void mporfixfix(Mpint *a, Mpint *b);
1002 void mprshfixfix(Mpint *a, Mpint *b);
1003 void mpshiftfix(Mpint *a, int s);
1004 int mptestfix(Mpint *a);
1005 void mpxorfixfix(Mpint *a, Mpint *b);
1006
1007 /*
1008 * mparith3.c
1009 */
1010 void mpaddfltflt(Mpflt *a, Mpflt *b);
1011 void mpdivfltflt(Mpflt *a, Mpflt *b);
1012 double mpgetflt(Mpflt *a);
1013 void mpmovecflt(Mpflt *a, double c);
1014 void mpmulfltflt(Mpflt *a, Mpflt *b);
1015 void mpnegflt(Mpflt *a);
1016 void mpnorm(Mpflt *a);
1017 int mptestflt(Mpflt *a);
1018 int sigfig(Mpflt *a);
1019
1020 /*
1021 * obj.c
1022 */
1023 void Bputname(Biobuf *b, Sym *s);
1024 int duint16(Sym *s, int off, uint16 v);
1025 int duint32(Sym *s, int off, uint32 v);
1026 int duint64(Sym *s, int off, uint64 v);
1027 int duint8(Sym *s, int off, uint8 v);
1028 int duintptr(Sym *s, int off, uint64 v);
1029 int dsname(Sym *s, int off, char *dat, int ndat);
1030 void dumpobj(void);
1031 void ieeedtod(uint64 *ieee, double native);
1032 Sym* stringsym(char*, int);
1033
1034 /*
1035 * print.c
1036 */
1037 void exprfmt(Fmt *f, Node *n, int prec);
1038 void exprlistfmt(Fmt *f, NodeList *l);
1039
1040 /*
1041 * range.c
1042 */
1043 void typecheckrange(Node *n);
1044 void walkrange(Node *n);
1045
1046 /*
1047 * reflect.c
1048 */
1049 void dumptypestructs(void);
1050 Type* methodfunc(Type *f, Type*);
1051 Node* typename(Type *t);
1052 Sym* typesym(Type *t);
1053
1054 /*
1055 * select.c
1056 */
1057 void typecheckselect(Node *sel);
1058 void walkselect(Node *sel);
1059
1060 /*
1061 * sinit.c
1062 */
1063 void anylit(int, Node *n, Node *var, NodeList **init);
1064 int gen_as_init(Node *n);
1065 NodeList* initfix(NodeList *l);
1066 int oaslit(Node *n, NodeList **init);
1067 int stataddr(Node *nam, Node *n);
1068
1069 /*
1070 * subr.c
1071 */
1072 int Econv(Fmt *fp);
1073 int Jconv(Fmt *fp);
1074 int Lconv(Fmt *fp);
1075 int Nconv(Fmt *fp);
1076 int Oconv(Fmt *fp);
1077 int Sconv(Fmt *fp);
1078 int Tconv(Fmt *fp);
1079 int Tpretty(Fmt *fp, Type *t);
1080 int Zconv(Fmt *fp);
1081 Node* adddot(Node *n);
1082 int adddot1(Sym *s, Type *t, int d, Type **save, int ignorecase);
1083 Type* aindex(Node *b, Type *t);
1084 int algtype(Type *t);
1085 void argtype(Node *on, Type *t);
1086 Node* assignconv(Node *n, Type *t, char *context);
1087 int assignop(Type *src, Type *dst, char **why);
1088 void badtype(int o, Type *tl, Type *tr);
1089 int brcom(int a);
1090 int brrev(int a);
1091 NodeList* concat(NodeList *a, NodeList *b);
1092 int convertop(Type *src, Type *dst, char **why);
1093 int count(NodeList *l);
1094 int cplxsubtype(int et);
1095 void dump(char *s, Node *n);
1096 void dumplist(char *s, NodeList *l);
1097 int eqtype(Type *t1, Type *t2);
1098 int eqtypenoname(Type *t1, Type *t2);
1099 void errorexit(void);
1100 void expandmeth(Sym *s, Type *t);
1101 void fatal(char *fmt, ...);
1102 void flusherrors(void);
1103 void frame(int context);
1104 Type* funcfirst(Iter *s, Type *t);
1105 Type* funcnext(Iter *s);
1106 void genwrapper(Type *rcvr, Type *method, Sym *newnam, int iface);
1107 Type** getinarg(Type *t);
1108 Type* getinargx(Type *t);
1109 Type** getoutarg(Type *t);
1110 Type* getoutargx(Type *t);
1111 Type** getthis(Type *t);
1112 Type* getthisx(Type *t);
1113 int implements(Type *t, Type *iface, Type **missing, Type **have, int *ptr);
1114 void importdot(Pkg *opkg, Node *pack);
1115 int is64(Type *t);
1116 int isblank(Node *n);
1117 int isfixedarray(Type *t);
1118 int isideal(Type *t);
1119 int isinter(Type *t);
1120 int isnil(Node *n);
1121 int isnilinter(Type *t);
1122 int isptrto(Type *t, int et);
1123 int isslice(Type *t);
1124 int istype(Type *t, int et);
1125 void linehist(char *file, int32 off, int relative);
1126 NodeList* list(NodeList *l, Node *n);
1127 NodeList* list1(Node *n);
1128 void listsort(NodeList**, int(*f)(Node*, Node*));
1129 Node* liststmt(NodeList *l);
1130 NodeList* listtreecopy(NodeList *l);
1131 Sym* lookup(char *name);
1132 void* mal(int32 n);
1133 Type* maptype(Type *key, Type *val);
1134 Type* methtype(Type *t);
1135 Pkg* mkpkg(Strlit *path);
1136 Sym* ngotype(Node *n);
1137 int noconv(Type *t1, Type *t2);
1138 Node* nod(int op, Node *nleft, Node *nright);
1139 Node* nodbool(int b);
1140 void nodconst(Node *n, Type *t, int64 v);
1141 Node* nodintconst(int64 v);
1142 Node* nodfltconst(Mpflt *v);
1143 Node* nodnil(void);
1144 int parserline(void);
1145 Sym* pkglookup(char *name, Pkg *pkg);
1146 int powtwo(Node *n);
1147 Type* ptrto(Type *t);
1148 void* remal(void *p, int32 on, int32 n);
1149 Sym* restrictlookup(char *name, Pkg *pkg);
1150 Node* safeexpr(Node *n, NodeList **init);
1151 void saveerrors(void);
1152 Node* cheapexpr(Node *n, NodeList **init);
1153 Node* localexpr(Node *n, Type *t, NodeList **init);
1154 int32 setlineno(Node *n);
1155 void setmaxarg(Type *t);
1156 Type* shallow(Type *t);
1157 int simsimtype(Type *t);
1158 void smagic(Magic *m);
1159 Type* sortinter(Type *t);
1160 uint32 stringhash(char *p);
1161 Strlit* strlit(char *s);
1162 int structcount(Type *t);
1163 Type* structfirst(Iter *s, Type **nn);
1164 Type* structnext(Iter *s);
1165 Node* syslook(char *name, int copy);
1166 Type* tounsigned(Type *t);
1167 Node* treecopy(Node *n);
1168 Type* typ(int et);
1169 uint32 typehash(Type *t);
1170 void ullmancalc(Node *n);
1171 void umagic(Magic *m);
1172 void warn(char *fmt, ...);
1173 void yyerror(char *fmt, ...);
1174 void yyerrorl(int line, char *fmt, ...);
1175
1176 /*
1177 * swt.c
1178 */
1179 void typecheckswitch(Node *n);
1180 void walkswitch(Node *sw);
1181
1182 /*
1183 * typecheck.c
1184 */
1185 int exportassignok(Type *t, char *desc);
1186 int islvalue(Node *n);
1187 Node* typecheck(Node **np, int top);
1188 void typechecklist(NodeList *l, int top);
1189 Node* typecheckdef(Node *n);
1190 void resumetypecopy(void);
1191 void copytype(Node *n, Type *t);
1192 void defertypecopy(Node *n, Type *t);
1193 void queuemethod(Node *n);
1194
1195 /*
1196 * unsafe.c
1197 */
1198 Node* unsafenmagic(Node *n);
1199
1200 /*
1201 * walk.c
1202 */
1203 Node* callnew(Type *t);
1204 Node* chanfn(char *name, int n, Type *t);
1205 Node* mkcall(char *name, Type *t, NodeList **init, ...);
1206 Node* mkcall1(Node *fn, Type *t, NodeList **init, ...);
1207 int vmatch1(Node *l, Node *r);
1208 void walk(Node *fn);
1209 void walkexpr(Node **np, NodeList **init);
1210 void walkexprlist(NodeList *l, NodeList **init);
1211 void walkexprlistsafe(NodeList *l, NodeList **init);
1212 void walkstmt(Node **np);
1213 void walkstmtlist(NodeList *l);
1214
1215 /*
1216 * arch-specific ggen.c/gsubr.c/gobj.c/pgen.c
1217 */
1218 #define P ((Prog*)0)
1219
1220 typedef struct Plist Plist;
1221 struct Plist
1222 {
1223 Node* name;
1224 Prog* firstpc;
1225 int recur;
1226 Plist* link;
1227 };
1228
1229 EXTERN Plist* plist;
1230 EXTERN Plist* plast;
1231
1232 EXTERN Prog* continpc;
1233 EXTERN Prog* breakpc;
1234 EXTERN Prog* pc;
1235 EXTERN Prog* firstpc;
1236 EXTERN Prog* retpc;
1237
1238 EXTERN Node* nodfp;
1239
1240 int anyregalloc(void);
1241 void betypeinit(void);
1242 void bgen(Node *n, int true, Prog *to);
1243 void cgen(Node*, Node*);
1244 void cgen_asop(Node *n);
1245 void cgen_call(Node *n, int proc);
1246 void cgen_callinter(Node *n, Node *res, int proc);
1247 void cgen_ret(Node *n);
1248 void clearfat(Node *n);
1249 void compile(Node*);
1250 void defframe(Prog*);
1251 int dgostringptr(Sym*, int off, char *str);
1252 int dgostrlitptr(Sym*, int off, Strlit*);
1253 int dstringptr(Sym *s, int off, char *str);
1254 int dsymptr(Sym *s, int off, Sym *x, int xoff);
1255 int duintxx(Sym *s, int off, uint64 v, int wid);
1256 void dumpdata(void);
1257 void dumpfuncs(void);
1258 void fixautoused(Prog*);
1259 void gdata(Node*, Node*, int);
1260 void gdatacomplex(Node*, Mpcplx*);
1261 void gdatastring(Node*, Strlit*);
1262 void genembedtramp(Type*, Type*, Sym*, int iface);
1263 void ggloblnod(Node *nam, int32 width);
1264 void ggloblsym(Sym *s, int32 width, int dupok);
1265 Prog* gjmp(Prog*);
1266 void gused(Node*);
1267 int isfat(Type*);
1268 void markautoused(Prog*);
1269 Plist* newplist(void);
1270 Node* nodarg(Type*, int);
1271 void nopout(Prog*);
1272 void patch(Prog*, Prog*);
1273 Prog* unpatch(Prog*);
1274 void zfile(Biobuf *b, char *p, int n);
1275 void zhist(Biobuf *b, int line, vlong offset);
1276 void zname(Biobuf *b, Sym *s, int t);
1277 void data(void);
1278 void text(void);
1279