changelog shortlog tags branches changeset files revisions annotate raw help

Mercurial > hg > plan9front / sys/src/cmd/cc/cc.h

changeset 6843: 7db92ee68f7e
parent: 9b4166d25205
author: 23hiro@gmail.com
date: Thu, 25 Oct 2018 08:09:10 +0200
permissions: -rw-r--r--
description: add Centrino Wireless-N 1030 (thanks lksmk from brazil)
1 #include <u.h>
2 #include <libc.h>
3 #include <bio.h>
4 #include <ctype.h>
5 
6 #pragma lib "../cc/cc.a$O"
7 
8 #ifndef EXTERN
9 #define EXTERN extern
10 #endif
11 
12 typedef struct Node Node;
13 typedef struct Sym Sym;
14 typedef struct Type Type;
15 typedef struct Funct Funct;
16 typedef struct Decl Decl;
17 typedef struct Io Io;
18 typedef struct Hist Hist;
19 typedef struct Term Term;
20 typedef struct Init Init;
21 typedef struct Bits Bits;
22 
23 #define NHUNK 50000L
24 #define BUFSIZ 8192
25 #define NSYMB 1500
26 #define NHASH 1024
27 #define STRINGSZ 200
28 #define HISTSZ 20
29 #define YYMAXDEPTH 1500
30 #define NTERM 10
31 #define MAXALIGN 7
32 
33 #define SIGN(n) (1ULL<<(n-1))
34 #define MASK(n) (SIGN(n)|(SIGN(n)-1))
35 
36 #define BITS 5
37 #define NVAR (BITS*sizeof(ulong)*8)
38 struct Bits
39 {
40  ulong b[BITS];
41 };
42 
43 struct Node
44 {
45  Node* left;
46  Node* right;
47  void* label;
48  long pc;
49  int reg;
50  long xoffset;
51  double fconst; /* fp constant */
52  vlong vconst; /* non fp const */
53  char* cstring; /* character string */
54  Rune* rstring; /* rune string */
55 
56  Sym* sym;
57  Type* type;
58  long lineno;
59  char op;
60  char oldop;
61  char xcast;
62  char class;
63  char etype;
64  char complex;
65  char addable;
66  char scale;
67  char garb;
68 };
69 #define Z ((Node*)0)
70 
71 struct Sym
72 {
73  Sym* link;
74  Type* type;
75  Type* suetag;
76  Type* tenum;
77  char* macro;
78  long varlineno;
79  long offset;
80  vlong vconst;
81  double fconst;
82  Node* label;
83  ushort lexical;
84  char *name;
85  ushort block;
86  ushort sueblock;
87  char class;
88  char sym;
89  char aused;
90  char sig;
91 };
92 #define S ((Sym*)0)
93 
94 enum{
95  SIGNONE = 0,
96  SIGDONE = 1,
97  SIGINTERN = 2,
98 
99  SIGNINTERN = 1729*325*1729,
100 };
101 
102 struct Decl
103 {
104  Decl* link;
105  Sym* sym;
106  Type* type;
107  long varlineno;
108  long offset;
109  short val;
110  ushort block;
111  char class;
112  char aused;
113 };
114 #define D ((Decl*)0)
115 
116 struct Type
117 {
118  Sym* sym;
119  Sym* tag;
120  Funct* funct;
121  Type* link;
122  Type* down;
123  long width;
124  long offset;
125  long lineno;
126  schar shift;
127  char nbits;
128  char etype;
129  char garb;
130 };
131 
132 #define T ((Type*)0)
133 #define NODECL ((void(*)(int, Type*, Sym*))0)
134 
135 struct Init /* general purpose initialization */
136 {
137  int code;
138  ulong value;
139  char* s;
140 };
141 
142 EXTERN struct
143 {
144  char* p;
145  int c;
146 } fi;
147 
148 struct Io
149 {
150  Io* link;
151  char* p;
152  char b[BUFSIZ];
153  short c;
154  short f;
155 };
156 #define I ((Io*)0)
157 
158 struct Hist
159 {
160  Hist* link;
161  char* name;
162  long line;
163  long offset;
164 };
165 #define H ((Hist*)0)
166 EXTERN Hist* hist;
167 
168 struct Term
169 {
170  vlong mult;
171  Node *node;
172 };
173 
174 enum
175 {
176  Axxx,
177  Ael1,
178  Ael2,
179  Asu2,
180  Aarg0,
181  Aarg1,
182  Aarg2,
183  Aaut3,
184  NALIGN,
185 };
186 
187 enum /* also in ../{8a,0a}.h */
188 {
189  Plan9 = 1<<0,
190  Unix = 1<<1,
191  Windows = 1<<2,
192 };
193 
194 enum
195 {
196  DMARK,
197  DAUTO,
198  DSUE,
199  DLABEL,
200 };
201 enum
202 {
203  OXXX,
204  OADD,
205  OADDR,
206  OAND,
207  OANDAND,
208  OARRAY,
209  OAS,
210  OASI,
211  OASADD,
212  OASAND,
213  OASASHL,
214  OASASHR,
215  OASDIV,
216  OASHL,
217  OASHR,
218  OASLDIV,
219  OASLMOD,
220  OASLMUL,
221  OASLSHR,
222  OASMOD,
223  OASMUL,
224  OASOR,
225  OASSUB,
226  OASXOR,
227  OBIT,
228  OBREAK,
229  OCASE,
230  OCAST,
231  OCOMMA,
232  OCOND,
233  OCONST,
234  OCONTINUE,
235  ODIV,
236  ODOT,
237  ODOTDOT,
238  ODWHILE,
239  OENUM,
240  OEQ,
241  OFOR,
242  OFUNC,
243  OGE,
244  OGOTO,
245  OGT,
246  OHI,
247  OHS,
248  OIF,
249  OIND,
250  OINDREG,
251  OINIT,
252  OLABEL,
253  OLDIV,
254  OLE,
255  OLIST,
256  OLMOD,
257  OLMUL,
258  OLO,
259  OLS,
260  OLSHR,
261  OLT,
262  OMOD,
263  OMUL,
264  ONAME,
265  ONE,
266  ONOT,
267  OOR,
268  OOROR,
269  OPOSTDEC,
270  OPOSTINC,
271  OPREDEC,
272  OPREINC,
273  OPROTO,
274  OREGISTER,
275  ORETURN,
276  OROL,
277  OSET,
278  OSIGN,
279  OSIZE,
280  OSTRING,
281  OLSTRING,
282  OSTRUCT,
283  OSUB,
284  OSWITCH,
285  OUNION,
286  OUSED,
287  OWHILE,
288  OXOR,
289  ONEG,
290  OCOM,
291  OPOS,
292  OELEM,
293 
294  OTST, /* used in some compilers */
295  OINDEX,
296  OFAS,
297  OREGPAIR,
298  OEXREG,
299 
300  OEND
301 };
302 enum
303 {
304  TXXX,
305  TCHAR,
306  TUCHAR,
307  TSHORT,
308  TUSHORT,
309  TINT,
310  TUINT,
311  TLONG,
312  TULONG,
313  TVLONG,
314  TUVLONG,
315  TFLOAT,
316  TDOUBLE,
317  TIND,
318  TFUNC,
319  TARRAY,
320  TVOID,
321  TSTRUCT,
322  TUNION,
323  TENUM,
324  TDOT,
325  NTYPE,
326 
327  TAUTO = NTYPE,
328  TEXTERN,
329  TSTATIC,
330  TTYPEDEF,
331  TTYPESTR,
332  TREGISTER,
333  TCONSTNT,
334  TVOLATILE,
335  TUNSIGNED,
336  TSIGNED,
337  TFILE,
338  TOLD,
339  NALLTYPES,
340 
341  TRUNE = sizeof(Rune)==4? TUINT: TUSHORT,
342 };
343 enum
344 {
345  CXXX,
346  CAUTO,
347  CEXTERN,
348  CGLOBL,
349  CSTATIC,
350  CLOCAL,
351  CTYPEDEF,
352  CTYPESTR,
353  CPARAM,
354  CSELEM,
355  CLABEL,
356  CEXREG,
357  NCTYPES,
358 };
359 enum
360 {
361  GXXX = 0,
362  GCONSTNT = 1<<0,
363  GVOLATILE = 1<<1,
364  NGTYPES = 1<<2,
365 
366  GINCOMPLETE = 1<<2,
367 };
368 enum
369 {
370  BCHAR = 1L<<TCHAR,
371  BUCHAR = 1L<<TUCHAR,
372  BSHORT = 1L<<TSHORT,
373  BUSHORT = 1L<<TUSHORT,
374  BINT = 1L<<TINT,
375  BUINT = 1L<<TUINT,
376  BLONG = 1L<<TLONG,
377  BULONG = 1L<<TULONG,
378  BVLONG = 1L<<TVLONG,
379  BUVLONG = 1L<<TUVLONG,
380  BFLOAT = 1L<<TFLOAT,
381  BDOUBLE = 1L<<TDOUBLE,
382  BIND = 1L<<TIND,
383  BFUNC = 1L<<TFUNC,
384  BARRAY = 1L<<TARRAY,
385  BVOID = 1L<<TVOID,
386  BSTRUCT = 1L<<TSTRUCT,
387  BUNION = 1L<<TUNION,
388  BENUM = 1L<<TENUM,
389  BFILE = 1L<<TFILE,
390  BDOT = 1L<<TDOT,
391  BCONSTNT = 1L<<TCONSTNT,
392  BVOLATILE = 1L<<TVOLATILE,
393  BUNSIGNED = 1L<<TUNSIGNED,
394  BSIGNED = 1L<<TSIGNED,
395  BAUTO = 1L<<TAUTO,
396  BEXTERN = 1L<<TEXTERN,
397  BSTATIC = 1L<<TSTATIC,
398  BTYPEDEF = 1L<<TTYPEDEF,
399  BTYPESTR = 1L<<TTYPESTR,
400  BREGISTER = 1L<<TREGISTER,
401 
402  BINTEGER = BCHAR|BUCHAR|BSHORT|BUSHORT|BINT|BUINT|
403  BLONG|BULONG|BVLONG|BUVLONG,
404  BNUMBER = BINTEGER|BFLOAT|BDOUBLE,
405 
406 /* these can be overloaded with complex types */
407 
408  BCLASS = BAUTO|BEXTERN|BSTATIC|BTYPEDEF|BTYPESTR|BREGISTER,
409  BGARB = BCONSTNT|BVOLATILE,
410 };
411 
412 struct Funct
413 {
414  Sym* sym[OEND];
415  Sym* castto[NTYPE];
416  Sym* castfr[NTYPE];
417 };
418 
419 EXTERN struct
420 {
421  Type* tenum; /* type of entire enum */
422  Type* cenum; /* type of current enum run */
423  vlong lastenum; /* value of current enum */
424  double floatenum; /* value of current enum */
425 } en;
426 
427 EXTERN int autobn;
428 EXTERN long autoffset;
429 EXTERN int blockno;
430 EXTERN Decl* dclstack;
431 EXTERN char debug[256];
432 EXTERN Hist* ehist;
433 EXTERN long firstbit;
434 EXTERN Sym* firstarg;
435 EXTERN Type* firstargtype;
436 EXTERN Decl* firstdcl;
437 EXTERN int fperror;
438 EXTERN Sym* hash[NHASH];
439 EXTERN int hasdoubled;
440 EXTERN char* hunk;
441 EXTERN char* include[20];
442 EXTERN Io* iofree;
443 EXTERN Io* ionext;
444 EXTERN Io* iostack;
445 EXTERN long lastbit;
446 EXTERN char lastclass;
447 EXTERN Type* lastdcl;
448 EXTERN long lastfield;
449 EXTERN Type* lasttype;
450 EXTERN long lineno;
451 EXTERN long nearln;
452 EXTERN int nerrors;
453 EXTERN int newflag;
454 EXTERN long nhunk;
455 EXTERN int ninclude;
456 EXTERN Node* nodproto;
457 EXTERN Node* nodcast;
458 EXTERN Biobuf outbuf;
459 EXTERN Biobuf diagbuf;
460 EXTERN char* outfile;
461 EXTERN char* pathname;
462 EXTERN int peekc;
463 EXTERN long stkoff;
464 EXTERN Type* strf;
465 EXTERN Type* strl;
466 EXTERN char symb[NSYMB];
467 EXTERN Sym* symstring;
468 EXTERN int taggen;
469 EXTERN Type* tfield;
470 EXTERN Type* tufield;
471 EXTERN int thechar;
472 EXTERN char* thestring;
473 EXTERN Type* thisfn;
474 EXTERN long thunk;
475 EXTERN Type* types[NTYPE];
476 EXTERN Type* fntypes[NTYPE];
477 EXTERN Node* initlist;
478 EXTERN Term term[NTERM];
479 EXTERN int nterm;
480 EXTERN int packflg;
481 EXTERN int fproundflg;
482 EXTERN int profileflg;
483 EXTERN int ncontin;
484 EXTERN int newvlongcode;
485 EXTERN int canreach;
486 EXTERN int warnreach;
487 EXTERN Bits zbits;
488 
489 extern char *onames[], *tnames[], *gnames[];
490 extern char *cnames[], *qnames[], *bnames[];
491 extern char tab[NTYPE][NTYPE];
492 extern char comrel[], invrel[], logrel[];
493 extern long ncast[], tadd[], tand[];
494 extern long targ[], tasadd[], tasign[], tcast[];
495 extern long tdot[], tfunct[], tindir[], tmul[];
496 extern long tnot[], trel[], tsub[];
497 
498 extern char typeaf[];
499 extern char typefd[];
500 extern char typei[];
501 extern char typesu[];
502 extern char typesuv[];
503 extern char typeu[];
504 extern char typev[];
505 extern char typec[];
506 extern char typeh[];
507 extern char typeil[];
508 extern char typeilp[];
509 extern char typechl[];
510 extern char typechlv[];
511 extern char typechlvp[];
512 extern char typechlp[];
513 extern char typechlpfd[];
514 
515 EXTERN char* typeswitch;
516 EXTERN char* typeword;
517 EXTERN char* typecmplx;
518 
519 extern ulong thash1;
520 extern ulong thash2;
521 extern ulong thash3;
522 extern ulong thash[];
523 
524 /*
525  * compat.c/unix.c/windows.c
526  */
527 int mywait(int*);
528 int mycreat(char*, int);
529 int systemtype(int);
530 int pathchar(void);
531 int myaccess(char*);
532 char* mygetwd(char*, int);
533 int myexec(char*, char*[]);
534 int mydup(int, int);
535 int myfork(void);
536 int mypipe(int*);
537 void* mysbrk(ulong);
538 
539 /*
540  * parser
541  */
542 int yyparse(void);
543 int mpatov(char*, vlong*);
544 
545 /*
546  * lex.c
547  */
548 void* allocn(void*, long, long);
549 void* alloc(long);
550 void cinit(void);
551 int compile(char*, char**, int);
552 void errorexit(void);
553 int filbuf(void);
554 int getc(void);
555 long getr(void);
556 int getnsc(void);
557 Sym* lookup(void);
558 void main(int, char*[]);
559 void newfile(char*, int);
560 void newio(void);
561 void pushio(void);
562 long escchar(long, int, int);
563 Sym* slookup(char*);
564 void syminit(Sym*);
565 void unget(int);
566 long yylex(void);
567 int Lconv(Fmt*);
568 int Tconv(Fmt*);
569 int FNconv(Fmt*);
570 int Oconv(Fmt*);
571 int Qconv(Fmt*);
572 int VBconv(Fmt*);
573 void setinclude(char*);
574 
575 /*
576  * mac.c
577  */
578 void dodefine(char*);
579 void domacro(void);
580 Sym* getsym(void);
581 long getnsn(void);
582 void linehist(char*, int);
583 void macdef(void);
584 void macprag(void);
585 void macend(void);
586 void macexpand(Sym*, char*);
587 void macif(int);
588 void macinc(void);
589 void maclin(void);
590 void macund(void);
591 
592 /*
593  * dcl.c
594  */
595 Node* doinit(Sym*, Type*, long, Node*);
596 Type* tcopy(Type*);
597 Node* init1(Sym*, Type*, long, int);
598 Node* newlist(Node*, Node*);
599 void adecl(int, Type*, Sym*);
600 int anyproto(Node*);
601 void argmark(Node*, int);
602 void dbgdecl(Sym*);
603 Node* dcllabel(Sym*, int);
604 Node* dodecl(void(*)(int, Type*, Sym*), int, Type*, Node*);
605 Sym* mkstatic(Sym*);
606 void doenum(Sym*, Node*);
607 void snap(Type*);
608 Type* dotag(Sym*, int, int);
609 void edecl(int, Type*, Sym*);
610 Type* fnproto(Node*);
611 Type* fnproto1(Node*);
612 void markdcl(void);
613 Type* paramconv(Type*, int);
614 void pdecl(int, Type*, Sym*);
615 Decl* push(void);
616 Decl* push1(Sym*);
617 Node* revertdcl(void);
618 long round(long, int);
619 int rsametype(Type*, Type*, int, int);
620 int sametype(Type*, Type*);
621 ulong sign(Sym*);
622 ulong signature(Type*);
623 void sualign(Type*);
624 void tmerge(Type*, Sym*);
625 void walkparam(Node*, int);
626 void xdecl(int, Type*, Sym*);
627 Node* contig(Sym*, Node*, long);
628 
629 /*
630  * com.c
631  */
632 void ccom(Node*);
633 void complex(Node*);
634 int tcom(Node*);
635 int tcoma(Node*, Node*, Type*, int);
636 int tcomd(Node*);
637 int tcomo(Node*, int);
638 int tcomx(Node*);
639 int tlvalue(Node*);
640 void constas(Node*, Type*, Type*);
641 Node* uncomma(Node*);
642 Node* uncomargs(Node*);
643 
644 /*
645  * con.c
646  */
647 void acom(Node*);
648 void acom1(vlong, Node*);
649 void acom2(Node*, Type*);
650 int acomcmp1(const void*, const void*);
651 int acomcmp2(const void*, const void*);
652 int addo(Node*);
653 void evconst(Node*);
654 
655 /*
656  * funct.c
657  */
658 int isfunct(Node*);
659 void dclfunct(Type*, Sym*);
660 
661 /*
662  * sub.c
663  */
664 void arith(Node*, int);
665 int deadheads(Node*);
666 Type* dotsearch(Sym*, Type*, Node*, long*);
667 long dotoffset(Type*, Type*, Node*);
668 void gethunk(void);
669 Node* invert(Node*);
670 int bitno(long);
671 void makedot(Node*, Type*, long);
672 int mixedasop(Type*, Type*);
673 Node* new(int, Node*, Node*);
674 Node* new1(int, Node*, Node*);
675 int nilcast(Type*, Type*);
676 int nocast(Type*, Type*);
677 void prtree(Node*, char*);
678 void prtree1(Node*, int, int);
679 void relcon(Node*, Node*);
680 int relindex(int);
681 int simpleg(long);
682 Type* garbt(Type*, long);
683 int simplec(long);
684 Type* simplet(long);
685 int stcompat(Node*, Type*, Type*, long[]);
686 int tcompat(Node*, Type*, Type*, long[]);
687 void tinit(void);
688 Type* typ(int, Type*);
689 Type* copytyp(Type*);
690 void typeext(Type*, Node*);
691 void typeext1(Type*, Node*);
692 int side(Node*);
693 int vconst(Node*);
694 int log2(uvlong);
695 int vlog(Node*);
696 int topbit(ulong);
697 void simplifyshift(Node*);
698 void rolor(Node*);
699 long typebitor(long, long);
700 void diag(Node*, char*, ...);
701 void warn(Node*, char*, ...);
702 void yyerror(char*, ...);
703 void fatal(Node*, char*, ...);
704 
705 /*
706  * acid.c
707  */
708 void acidtype(Type*);
709 void acidvar(Sym*);
710 
711 /*
712  * pickle.c
713  */
714 void pickletype(Type*);
715 
716 /*
717  * bits.c
718  */
719 Bits bor(Bits, Bits);
720 Bits band(Bits, Bits);
721 Bits bnot(Bits);
722 int bany(Bits*);
723 int bnum(Bits);
724 Bits blsh(uint);
725 int beq(Bits, Bits);
726 int bset(Bits, uint);
727 
728 /*
729  * dpchk.c
730  */
731 void dpcheck(Node*);
732 void arginit(void);
733 void pragvararg(void);
734 void pragpack(void);
735 void pragfpround(void);
736 void pragprofile(void);
737 void pragincomplete(void);
738 
739 /*
740  * calls to machine depend part
741  */
742 void codgen(Node*, Node*);
743 void gclean(void);
744 void gextern(Sym*, Node*, long, long);
745 void ginit(void);
746 long outstring(char*, long);
747 long outlstring(Rune*, long);
748 void sextern(Sym*, Node*, long, long);
749 void xcom(Node*);
750 long exreg(Type*);
751 long align(long, Type*, int);
752 long maxround(long, long);
753 
754 extern schar ewidth[];
755 
756 /*
757  * com64
758  */
759 int com64(Node*);
760 void com64init(void);
761 void bool64(Node*);
762 double convvtof(vlong);
763 vlong convftov(double);
764 double convftox(double, int);
765 vlong convvtox(vlong, int);
766 
767 /*
768  * machcap
769  */
770 int machcap(Node*);
771 
772 #pragma varargck argpos warn 2
773 #pragma varargck argpos diag 2
774 #pragma varargck argpos yyerror 1
775 
776 #pragma varargck type "F" Node*
777 #pragma varargck type "L" long
778 #pragma varargck type "Q" long
779 #pragma varargck type "O" int
780 #pragma varargck type "T" Type*
781 #pragma varargck type "|" int