4 new(int t, Node *l, Node *r)
13 n->lineno = l->lineno;
15 n->lineno = r->lineno;
23 new1(int o, Node *l, Node *r)
33 prtree(Node *n, char *s)
36 print(" == %s ==\n", s);
42 prtree1(Node *n, int d, int f)
54 prtree1(n->left, d, 0);
55 prtree1(n->right, d, 1);
65 print(" %ld", n->xoffset);
70 print(" %ld(R%d)", n->xoffset, n->reg);
76 print(" %ld+R%d", n->xoffset, n->reg);
78 print(" R%d", n->reg);
83 print(" \"%s\"", n->cstring);
88 print(" \"%S\"", n->rstring);
98 if(typefd[n->type->etype])
99 print(" \"%.8e\"", n->fconst);
101 print(" \"%lld\"", n->vconst);
106 print(" <%d>", n->addable);
108 print(" %T", n->type);
110 print(" (%d)", n->complex);
111 print(" %L\n", n->lineno);
113 prtree1(n->left, d, 1);
115 prtree1(n->right, d, 1);
123 t = alloc(sizeof(*t));
128 t->width = ewidth[et];
147 garbt(Type *t, long b)
153 t1->garb = simpleg(b);
169 case BVOLATILE|BCONSTNT:
170 return GCONSTNT|GVOLATILE;
185 case BAUTO|BREGISTER:
189 case BEXTERN|BREGISTER:
198 diag(Z, "illegal combination of classes %Q", b);
206 b &= ~BCLASS & ~BGARB;
212 case BCHAR|BUNSIGNED:
213 return types[TUCHAR];
218 case BSHORT|BINT|BSIGNED:
219 return types[TSHORT];
221 case BUNSIGNED|BSHORT:
222 case BUNSIGNED|BSHORT|BINT:
223 return types[TUSHORT];
238 case BLONG|BINT|BSIGNED:
241 case BUNSIGNED|BLONG:
242 case BUNSIGNED|BLONG|BINT:
243 return types[TULONG];
246 case BVLONG|BLONG|BINT:
247 case BVLONG|BLONG|BSIGNED:
248 case BVLONG|BLONG|BINT|BSIGNED:
249 return types[TVLONG];
251 case BVLONG|BLONG|BUNSIGNED:
252 case BVLONG|BLONG|BINT|BUNSIGNED:
253 return types[TUVLONG];
256 return types[TFLOAT];
261 return types[TDOUBLE];
267 diag(Z, "illegal combination of types %Q", b);
272 stcompat(Node *n, Type *t1, Type *t2, long ttab[])
286 if(b == BSTRUCT || b == BUNION)
287 if(!sametype(t1, t2))
290 if(b == BIND && i == TIND)
291 if(!sametype(t1, t2))
299 tcompat(Node *n, Type *t1, Type *t2, long ttab[])
302 if(stcompat(n, t1, t2, ttab)) {
304 diag(n, "incompatible type: \"%T\" for op \"%O\"",
307 diag(n, "incompatible types: \"%T\" and \"%T\" for op \"%O\"",
315 makedot(Node *n, Type *t, long o)
320 n1 = new(OXXX, Z, Z);
326 n->addable = n1->left->addable;
329 n->addable = n->left->addable;
330 if(n->addable == 0) {
331 n1 = new1(OCONST, Z, Z);
333 n1->type = types[TLONG];
344 n1 = new1(OCONST, Z, Z);
347 t->width = types[TIND]->width;
350 n2 = new1(OADDR, n->left, Z);
353 n1 = new1(OADD, n1, n2);
362 dotsearch(Sym *s, Type *t, Node *n, long *off)
371 for(t1 = t; t1 != T; t1 = t1->down)
381 if(s->class == CTYPEDEF || s->class == CTYPESTR)
382 for(t1 = t; t1 != T; t1 = t1->down)
383 if(t1->sym == S && typesu[t1->etype])
384 if(sametype(s->type, t1)) {
395 * look it up in unnamed substructures
397 for(t1 = t; t1 != T; t1 = t1->down)
398 if(t1->sym == S && typesu[t1->etype]){
399 rt = dotsearch(s, t1->link, n, off);
410 diag(n, "ambiguous structure element: %s", s->name);
415 dotoffset(Type *st, Type *lt, Node *n)
423 * first try matching at the top level
424 * for matching tag names
428 for(t=lt->link; t!=T; t=t->down)
439 * second try matching at the top level
442 for(t=lt->link; t!=T; t=t->down)
444 if(sametype(st, t)) {
453 * last try matching sub-levels
455 for(t=lt->link; t!=T; t=t->down)
457 if(typesu[t->etype]) {
458 o1 = dotoffset(st, t, n);
468 diag(n, "ambiguous unnamed structure element");
473 * look into tree for floating point constant expressions
476 allfloat(Node *n, int flag)
480 if(n->type->etype != TDOUBLE)
485 n->type = types[TFLOAT];
487 case OADD: /* no need to get more exotic than this */
491 if(!allfloat(n->right, flag))
494 if(!allfloat(n->left, flag))
497 n->type = types[TFLOAT];
505 constas(Node *n, Type *il, Type *ir)
514 if(l->garb & GCONSTNT) {
515 warn(n, "assignment to a constant type (%T)", il);
521 if(l->etype != TIND || r->etype != TIND)
527 if(r->garb & GCONSTNT)
528 if(!(l->garb & GCONSTNT)) {
529 warn(n, "assignment of a constant pointer type (%T)", ir);
536 typeext1(Type *st, Node *l)
538 if(st->etype == TFLOAT && allfloat(l, 0))
543 typeext(Type *st, Node *l)
552 if(st->etype == TIND && vconst(l) == 0) {
561 * if assign of struct containing unnamed sub-struct
562 * to type of sub-struct, insert the DOT.
563 * if assign of *struct containing unnamed substruct
564 * to type of *sub-struct, insert the add-offset
566 if(typesu[st->etype] && typesu[lt->etype]) {
567 o = dotoffset(st, lt, l);
569 n1 = new1(OXXX, Z, Z);
578 if(st->etype == TIND && typesu[st->link->etype])
579 if(lt->etype == TIND && typesu[lt->link->etype]) {
580 o = dotoffset(st->link, lt->link, l);
585 n1 = new1(OXXX, Z, Z);
587 n2 = new1(OCONST, Z, Z);
599 * a cast that generates no code
603 nocast(Type *t1, Type *t2)
622 * a cast that has a noop semantic
623 * (small to large, convert)
626 nilcast(Type *t1, Type *t2)
640 if(typefd[et1] && typefd[et2]) {
641 if(ewidth[et1] < ewidth[et2])
645 if(typechlp[et1] && typechlp[et2]) {
646 if(ewidth[et1] < ewidth[et2])
654 * "the usual arithmetic conversions are performed"
657 arith(Node *n, int f)
683 /* convert up to at least int */
690 if(i == TIND && j == TIND) {
691 w = n->right->type->link->width;
693 snap(n->right->type->link);
694 w = n->right->type->link->width;
697 if(n->left->type->link != T) {
698 x = n->left->type->link->width;
700 snap(n->left->type->link);
701 x = n->left->type->link->width;
706 n->type = types[ewidth[TIND] <= ewidth[TLONG]? TLONG: TVLONG];
708 n1 = new1(OXXX, Z, Z);
712 n1 = new1(OCONST, Z, Z);
722 if(0 && ewidth[TIND] > ewidth[TLONG]){
723 n1 = new1(OXXX, Z, Z);
728 n->type = types[TLONG];
732 if(!sametype(n->type, n->left->type)) {
733 n->left = new1(OCAST, n->left, Z);
734 n->left->type = n->type;
735 if(n->type->etype == TIND) {
736 w = n->type->link->width;
739 w = n->type->link->width;
744 n1 = new1(OCONST, Z, Z);
747 n->left = new1(OMUL, n->left, n1);
748 n->left->type = n->type;
753 if(!sametype(n->type, n->right->type)) {
754 n->right = new1(OCAST, n->right, Z);
755 n->right->type = n->type;
756 if(n->type->etype == TIND) {
757 w = n->type->link->width;
760 w = n->type->link->width;
765 n1 = new1(OCONST, Z, Z);
768 n->right = new1(OMUL, n->right, n1);
769 n->right->type = n->type;
775 diag(n, "pointer addition not fully declared: %T", n->type->link);
779 * try to rewrite shift & mask
782 simplifyshift(Node *n)
785 int o, s1, s2, c1, c2;
787 if(!typechlp[n->type->etype])
802 if(n->right->op != OCONST)
804 if(n->left->op != OAND)
806 if(n->left->right->op != OCONST)
808 switch(n->left->left->op) {
821 if(n->left->left->right->op != OCONST)
824 c1 = n->right->vconst;
825 c2 = n->left->left->right->vconst;
826 c3 = n->left->right->vconst;
830 print("%.3o %ld %ld %d #%.lux\n",
831 (s1<<3)|s2, c1, c2, topbit(c3), c3);
836 case 000: /* (((e <<u c2) & c3) <<u c1) */
843 case 002: /* (((e >>s c2) & c3) <<u c1) */
844 if(topbit(c3) >= (32-c2))
846 case 001: /* (((e >>u c2) & c3) <<u c1) */
860 case 022: /* (((e >>s c2) & c3) >>s c1) */
863 case 012: /* (((e >>s c2) & c3) >>u c1) */
864 if(topbit(c3) >= (32-c2))
867 case 021: /* (((e >>u c2) & c3) >>s c1) */
868 if(topbit(c3) >= 31 && c2 <= 0)
871 case 011: /* (((e >>u c2) & c3) >>u c1) */
880 case 020: /* (((e <<u c2) & c3) >>s c1) */
883 case 010: /* (((e <<u c2) & c3) >>u c1) */
897 rewrite0: /* get rid of both shifts */
898 if(debug['<'])prtree(n, "rewrite0");
900 n->left = n->left->left;
901 n->right->vconst = c3;
903 rewrite1: /* get rid of lower shift */
904 if(debug['<'])prtree(n, "rewrite1");
905 n->left->left = n->left->left->left;
906 n->left->right->vconst = c3;
907 n->right->vconst = c1;
910 rewrite2: /* get rid of upper shift */
911 if(debug['<'])prtree(n, "rewrite2");
913 n->right->vconst = c3;
914 n->left->right->vconst = c1;
919 * replace shift/or with rotate left
926 if(!typeu[n->type->etype])
945 if(l->right->op != OCONST || r->right->op != OCONST)
947 if(vconst(l->right) + vconst(r->right) != ewidth[n->type->etype]*8)
949 if(l->left->type != n->type || r->left->type != n->type)
951 if(l->left->op != ONAME || r->left->op != ONAME || l->left->sym != r->left->sym)
1031 while(n->op == OCAST){
1034 if(n->type->etype != TIND)
1036 if(n->type->link->etype != TVOID)
1040 return vconst(n) == 0;
1054 switch(n->type->etype)
1059 if(n->fconst > i || n->fconst < -i)
1088 return -159; /* first uninteresting constant */
1092 * return log(n) if n is a power of 2 constant
1101 m = MASK(8*sizeof(uvlong));
1102 for(i=32; i; i>>=1) {
1119 if(typefd[n->type->etype])
1122 return log2(n->vconst);
1139 * try to cast a constant down
1140 * rather than cast a variable up
1145 relcon(Node *l, Node *r)
1153 if(!nilcast(r->left->type, r->type))
1155 switch(r->type->etype) {
1162 v = convvtox(l->vconst, r->type->etype);
1167 l->type = r->left->type;
1177 diag(Z, "bad in relindex: %O", o);
1196 if(n == Z || n->op != OLIST)
1199 for(n = n->left; n != Z; n = n->left) {
1218 diag(Z, "bad in bitno");
1223 typebitor(long a, long b)
1229 if((a & b) == BLONG)
1230 c |= BVLONG; /* long long => vlong */
1232 warn(Z, "once is enough: %Q", a & b);
1237 diag(Node *n, char *fmt, ...)
1243 vseprint(buf, buf+sizeof(buf), fmt, arg);
1245 Bprint(&diagbuf, "%L %s\n", (n==Z)? nearln: n->lineno, buf);
1253 prtree(n, "diagnostic");
1257 Bprint(&diagbuf, "too many errors\n");
1263 warn(Node *n, char *fmt, ...)
1269 Bprint(&diagbuf, "warning: ");
1271 vseprint(buf, buf+sizeof(buf), fmt, arg);
1273 Bprint(&diagbuf, "%L %s\n", (n==Z)? nearln: n->lineno, buf);
1277 prtree(n, "warning");
1282 yyerror(char *fmt, ...)
1288 * hack to intercept message from yaccpar
1290 if(strcmp(fmt, "syntax error") == 0) {
1291 yyerror("syntax error, last name: %s", symb);
1295 vseprint(buf, buf+sizeof(buf), fmt, arg);
1297 Bprint(&diagbuf, "%L %s\n", lineno, buf);
1300 Bprint(&diagbuf, "too many errors\n");
1306 fatal(Node *n, char *fmt, ...)
1312 vseprint(buf, buf+sizeof(buf), fmt, arg);
1314 Bprint(&diagbuf, "%L %s\n", (n==Z)? nearln: n->lineno, buf);
1322 prtree(n, "diagnostic");
1328 ulong thash1 = 0x2edab8c9;
1329 ulong thash2 = 0x1dc74fb8;
1330 ulong thash3 = 0x1f241331;
1331 ulong thash[NALLTYPES];
1334 TXXX, 0x17527bbd, 0,
1335 TCHAR, 0x5cedd32b, 0,
1336 TUCHAR, 0x552c4454, 0,
1337 TSHORT, 0x63040b4b, 0,
1338 TUSHORT, 0x32a45878, 0,
1339 TINT, 0x4151d5bd, 0,
1340 TUINT, 0x5ae707d6, 0,
1341 TLONG, 0x5ef20f47, 0,
1342 TULONG, 0x36d8eb8f, 0,
1343 TVLONG, 0x6e5e9590, 0,
1344 TUVLONG, 0x75910105, 0,
1345 TFLOAT, 0x25fd7af1, 0,
1346 TDOUBLE, 0x7c40a1b2, 0,
1347 TIND, 0x1b832357, 0,
1348 TFUNC, 0x6babc9cb, 0,
1349 TARRAY, 0x7c50986d, 0,
1350 TVOID, 0x44112eff, 0,
1351 TSTRUCT, 0x7c2da3bf, 0,
1352 TUNION, 0x3eb25e98, 0,
1353 TENUM, 0x44b54f61, 0,
1354 TFILE, 0x19242ac3, 0,
1355 TOLD, 0x22b15988, 0,
1356 TDOT, 0x0204f6b3, 0,
1360 char* bnames[NALIGN];
1374 char* tnames[NALLTYPES];
1381 TUSHORT, 0, "USHORT",
1387 TUVLONG, 0, "UVLONG",
1389 TDOUBLE, 0, "DOUBLE",
1394 TSTRUCT, 0, "STRUCT",
1403 char* gnames[NGTYPES];
1407 GCONSTNT, 0, "CONST",
1408 GVOLATILE, 0, "VOLATILE",
1409 GVOLATILE|GCONSTNT, 0, "CONST-VOLATILE",
1413 char* qnames[NALLTYPES];
1420 TUSHORT, 0, "USHORT",
1426 TUVLONG, 0, "UVLONG",
1428 TDOUBLE, 0, "DOUBLE",
1433 TSTRUCT, 0, "STRUCT",
1438 TEXTERN, 0, "EXTERN",
1439 TSTATIC, 0, "STATIC",
1440 TTYPEDEF, 0, "TYPEDEF",
1441 TTYPESTR, 0, "TYPESTR",
1442 TREGISTER, 0, "REGISTER",
1443 TCONSTNT, 0, "CONSTNT",
1444 TVOLATILE, 0, "VOLATILE",
1445 TUNSIGNED, 0, "UNSIGNED",
1446 TSIGNED, 0, "SIGNED",
1452 char* cnames[NCTYPES];
1457 CEXTERN, 0, "EXTERN",
1459 CSTATIC, 0, "STATIC",
1461 CTYPEDEF, 0, "TYPEDEF",
1462 CTYPESTR, 0, "TYPESTR",
1470 char* onames[OEND+1];
1477 OANDAND, 0, "ANDAND",
1483 OASASHL, 0, "ASASHL",
1484 OASASHR, 0, "ASASHR",
1488 OASLDIV, 0, "ASLDIV",
1489 OASLMOD, 0, "ASLMOD",
1490 OASLMUL, 0, "ASLMUL",
1491 OASLSHR, 0, "ASLSHR",
1504 OCONTINUE, 0, "CONTINUE",
1507 ODOTDOT, 0, "DOTDOT",
1508 ODWHILE, 0, "DWHILE",
1520 OINDREG, 0, "INDREG",
1539 OPOSTDEC, 0, "POSTDEC",
1540 OPOSTINC, 0, "POSTINC",
1541 OPREDEC, 0, "PREDEC",
1542 OPREINC, 0, "PREINC",
1544 OREGISTER, 0, "REGISTER",
1545 ORETURN, 0, "RETURN",
1550 OSTRING, 0, "STRING",
1551 OLSTRING, 0, "LSTRING",
1552 OSTRUCT, 0, "STRUCT",
1554 OSWITCH, 0, "SWITCH",
1566 OREGPAIR, 0, "REGPAIR",
1572 /* OEQ, ONE, OLE, OLS, OLT, OLO, OGE, OHS, OGT, OHI */
1575 ONE, OEQ, OGT, OHI, OGE, OHS, OLT, OLO, OLE, OLS,
1579 OEQ, ONE, OGE, OHS, OGT, OHI, OLE, OLS, OLT, OLO,
1583 OEQ, ONE, OLS, OLS, OLO, OLO, OHS, OHS, OHI, OHI,
1589 TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TVLONG, TUVLONG, -1,
1594 TUCHAR, TUSHORT, TUINT, TULONG, TUVLONG, TIND, -1,
1597 char typesuv[NTYPE];
1600 TVLONG, TUVLONG, TSTRUCT, TUNION, -1,
1603 char typeilp[NTYPE];
1606 TINT, TUINT, TLONG, TULONG, TIND, -1
1609 char typechl[NTYPE];
1610 char typechlv[NTYPE];
1611 char typechlvp[NTYPE];
1614 TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, -1,
1617 char typechlp[NTYPE];
1618 int typechlpinit[] =
1620 TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TIND, -1,
1623 char typechlpfd[NTYPE];
1624 int typechlpfdinit[] =
1626 TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TFLOAT, TDOUBLE, TIND, -1,
1638 TSHORT, TUSHORT, -1,
1644 TINT, TUINT, TLONG, TULONG, -1,
1650 TVLONG, TUVLONG, -1,
1656 TFLOAT, TDOUBLE, -1,
1668 TSTRUCT, TUNION, -1,
1677 TUSHORT, BNUMBER, 0,
1683 TUVLONG, BNUMBER, 0,
1685 TDOUBLE, BNUMBER, 0,
1687 TSTRUCT, BSTRUCT, 0,
1698 TUSHORT, BNUMBER, 0,
1704 TUVLONG, BNUMBER, 0,
1706 TDOUBLE, BNUMBER, 0,
1714 TCHAR, BNUMBER|BIND|BVOID, 0,
1715 TUCHAR, BNUMBER|BIND|BVOID, 0,
1716 TSHORT, BNUMBER|BIND|BVOID, 0,
1717 TUSHORT, BNUMBER|BIND|BVOID, 0,
1718 TINT, BNUMBER|BIND|BVOID, 0,
1719 TUINT, BNUMBER|BIND|BVOID, 0,
1720 TLONG, BNUMBER|BIND|BVOID, 0,
1721 TULONG, BNUMBER|BIND|BVOID, 0,
1722 TVLONG, BNUMBER|BIND|BVOID, 0,
1723 TUVLONG, BNUMBER|BIND|BVOID, 0,
1724 TFLOAT, BNUMBER|BVOID, 0,
1725 TDOUBLE, BNUMBER|BVOID, 0,
1726 TIND, BINTEGER|BIND|BVOID, 0,
1728 TSTRUCT, BSTRUCT|BVOID, 0,
1729 TUNION, BUNION|BVOID, 0,
1736 TCHAR, BNUMBER|BIND, 0,
1737 TUCHAR, BNUMBER|BIND, 0,
1738 TSHORT, BNUMBER|BIND, 0,
1739 TUSHORT, BNUMBER|BIND, 0,
1740 TINT, BNUMBER|BIND, 0,
1741 TUINT, BNUMBER|BIND, 0,
1742 TLONG, BNUMBER|BIND, 0,
1743 TULONG, BNUMBER|BIND, 0,
1744 TVLONG, BNUMBER|BIND, 0,
1745 TUVLONG, BNUMBER|BIND, 0,
1747 TDOUBLE, BNUMBER, 0,
1758 TUSHORT, BNUMBER, 0,
1764 TUVLONG, BNUMBER, 0,
1766 TDOUBLE, BNUMBER, 0,
1767 TIND, BINTEGER|BIND, 0,
1777 TUSHORT, BNUMBER, 0,
1783 TUVLONG, BNUMBER, 0,
1785 TDOUBLE, BNUMBER, 0,
1793 TUCHAR, BINTEGER, 0,
1794 TSHORT, BINTEGER, 0,
1795 TUSHORT, BINTEGER, 0,
1799 TULONG, BINTEGER, 0,
1800 TVLONG, BINTEGER, 0,
1801 TUVLONG, BINTEGER, 0,
1811 TUSHORT, BNUMBER, 0,
1817 TUVLONG, BNUMBER, 0,
1819 TDOUBLE, BNUMBER, 0,
1846 BNUMBER|BIND|BSTRUCT|BUNION,
1849 char tab[NTYPE][NTYPE] =
1854 /*TCHAR*/ { 0, TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG,
1855 TULONG, TVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1857 /*TUCHAR*/ { 0, TUCHAR, TUCHAR, TUSHORT, TUSHORT, TUINT, TUINT, TULONG,
1858 TULONG, TUVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1860 /*TSHORT*/ { 0, TSHORT, TUSHORT, TSHORT, TUSHORT, TINT, TUINT, TLONG,
1861 TULONG, TVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1863 /*TUSHORT*/ { 0, TUSHORT, TUSHORT, TUSHORT, TUSHORT, TUINT, TUINT, TULONG,
1864 TULONG, TUVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1866 /*TINT*/ { 0, TINT, TUINT, TINT, TUINT, TINT, TUINT, TLONG,
1867 TULONG, TVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1869 /*TUINT*/ { 0, TUINT, TUINT, TUINT, TUINT, TUINT, TUINT, TULONG,
1870 TULONG, TUVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1872 /*TLONG*/ { 0, TLONG, TULONG, TLONG, TULONG, TLONG, TULONG, TLONG,
1873 TULONG, TVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1875 /*TULONG*/ { 0, TULONG, TULONG, TULONG, TULONG, TULONG, TULONG, TULONG,
1876 TULONG, TUVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1878 /*TVLONG*/ { 0, TVLONG, TUVLONG, TVLONG, TUVLONG, TVLONG, TUVLONG, TVLONG,
1879 TUVLONG, TVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1881 /*TUVLONG*/ { 0, TUVLONG, TUVLONG, TUVLONG, TUVLONG, TUVLONG, TUVLONG, TUVLONG,
1882 TUVLONG, TUVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1884 /*TFLOAT*/ { 0, TFLOAT, TFLOAT, TFLOAT, TFLOAT, TFLOAT, TFLOAT, TFLOAT,
1885 TFLOAT, TFLOAT, TFLOAT, TFLOAT, TDOUBLE, TIND,
1887 /*TDOUBLE*/ { 0, TDOUBLE, TDOUBLE, TDOUBLE, TDOUBLE, TDOUBLE, TDOUBLE, TDOUBLE,
1888 TDOUBLE, TDOUBLE, TDOUBLE, TFLOAT, TDOUBLE, TIND,
1890 /*TIND*/ { 0, TIND, TIND, TIND, TIND, TIND, TIND, TIND,
1891 TIND, TIND, TIND, TIND, TIND, TIND,
1896 urk(char *name, int max, int i)
1899 fprint(2, "bad tinit: %s %d>=%d\n", name, i, max);
1910 for(p=thashinit; p->code >= 0; p++) {
1911 urk("thash", nelem(thash), p->code);
1912 thash[p->code] = p->value;
1914 for(p=bnamesinit; p->code >= 0; p++) {
1915 urk("bnames", nelem(bnames), p->code);
1916 bnames[p->code] = p->s;
1918 for(p=tnamesinit; p->code >= 0; p++) {
1919 urk("tnames", nelem(tnames), p->code);
1920 tnames[p->code] = p->s;
1922 for(p=gnamesinit; p->code >= 0; p++) {
1923 urk("gnames", nelem(gnames), p->code);
1924 gnames[p->code] = p->s;
1926 for(p=qnamesinit; p->code >= 0; p++) {
1927 urk("qnames", nelem(qnames), p->code);
1928 qnames[p->code] = p->s;
1930 for(p=cnamesinit; p->code >= 0; p++) {
1931 urk("cnames", nelem(cnames), p->code);
1932 cnames[p->code] = p->s;
1934 for(p=onamesinit; p->code >= 0; p++) {
1935 urk("onames", nelem(onames), p->code);
1936 onames[p->code] = p->s;
1938 for(ip=typeiinit; *ip>=0; ip++) {
1939 urk("typei", nelem(typei), *ip);
1942 for(ip=typeuinit; *ip>=0; ip++) {
1943 urk("typeu", nelem(typeu), *ip);
1946 for(ip=typesuvinit; *ip>=0; ip++) {
1947 urk("typesuv", nelem(typesuv), *ip);
1950 for(ip=typeilpinit; *ip>=0; ip++) {
1951 urk("typeilp", nelem(typeilp), *ip);
1954 for(ip=typechlinit; *ip>=0; ip++) {
1955 urk("typechl", nelem(typechl), *ip);
1960 for(ip=typechlpinit; *ip>=0; ip++) {
1961 urk("typechlp", nelem(typechlp), *ip);
1965 for(ip=typechlpfdinit; *ip>=0; ip++) {
1966 urk("typechlpfd", nelem(typechlpfd), *ip);
1967 typechlpfd[*ip] = 1;
1969 for(ip=typecinit; *ip>=0; ip++) {
1970 urk("typec", nelem(typec), *ip);
1973 for(ip=typehinit; *ip>=0; ip++) {
1974 urk("typeh", nelem(typeh), *ip);
1977 for(ip=typeilinit; *ip>=0; ip++) {
1978 urk("typeil", nelem(typeil), *ip);
1981 for(ip=typevinit; *ip>=0; ip++) {
1982 urk("typev", nelem(typev), *ip);
1987 for(ip=typefdinit; *ip>=0; ip++) {
1988 urk("typefd", nelem(typefd), *ip);
1991 for(ip=typeafinit; *ip>=0; ip++) {
1992 urk("typeaf", nelem(typeaf), *ip);
1995 for(ip=typesuinit; *ip >= 0; ip++) {
1996 urk("typesu", nelem(typesu), *ip);
1999 for(p=tasigninit; p->code >= 0; p++) {
2000 urk("tasign", nelem(tasign), p->code);
2001 tasign[p->code] = p->value;
2003 for(p=tasaddinit; p->code >= 0; p++) {
2004 urk("tasadd", nelem(tasadd), p->code);
2005 tasadd[p->code] = p->value;
2007 for(p=tcastinit; p->code >= 0; p++) {
2008 urk("tcast", nelem(tcast), p->code);
2009 tcast[p->code] = p->value;
2011 for(p=taddinit; p->code >= 0; p++) {
2012 urk("tadd", nelem(tadd), p->code);
2013 tadd[p->code] = p->value;
2015 for(p=tsubinit; p->code >= 0; p++) {
2016 urk("tsub", nelem(tsub), p->code);
2017 tsub[p->code] = p->value;
2019 for(p=tmulinit; p->code >= 0; p++) {
2020 urk("tmul", nelem(tmul), p->code);
2021 tmul[p->code] = p->value;
2023 for(p=tandinit; p->code >= 0; p++) {
2024 urk("tand", nelem(tand), p->code);
2025 tand[p->code] = p->value;
2027 for(p=trelinit; p->code >= 0; p++) {
2028 urk("trel", nelem(trel), p->code);
2029 trel[p->code] = p->value;
2032 /* 32-bit defaults */
2033 typeword = typechlp;
2034 typeswitch = typechl;
2035 typecmplx = typesuv;
2039 * return 1 if it is impossible to jump into the middle of n.
2042 deadhead(Node *n, int caseok)
2049 if(!deadhead(n->left, caseok))
2070 return deadhead(n->right, 1);
2086 return deadhead(n->right->left, caseok) && deadhead(n->right->right, caseok);
2098 return deadhead(c->left, 0) && deadhead(c->right, 0);
2102 mixedasop(Type *l, Type *r)
2104 return !typefd[l->etype] && typefd[r->etype];
2109 * (uvlong)~ul creates a ul mask with top bits zero, which is usually wrong
2110 * an explicit cast to ulong after ~ suppresses the diagnostic
2117 if(r->op == OCAST &&
2118 (rl = r->left)->op == OCOM &&
2119 (r->type->etype == TVLONG || r->type->etype == TUVLONG) &&
2120 typeu[rl->type->etype] && typechl[rl->type->etype])