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)
1039 switch(n->type->etype)
1044 if(n->fconst > i || n->fconst < -i)
1073 return -159; /* first uninteresting constant */
1077 * return log(n) if n is a power of 2 constant
1086 m = MASK(8*sizeof(uvlong));
1087 for(i=32; i; i>>=1) {
1104 if(typefd[n->type->etype])
1107 return log2(n->vconst);
1124 * try to cast a constant down
1125 * rather than cast a variable up
1130 relcon(Node *l, Node *r)
1138 if(!nilcast(r->left->type, r->type))
1140 switch(r->type->etype) {
1147 v = convvtox(l->vconst, r->type->etype);
1152 l->type = r->left->type;
1162 diag(Z, "bad in relindex: %O", o);
1181 if(n == Z || n->op != OLIST)
1184 for(n = n->left; n != Z; n = n->left) {
1203 diag(Z, "bad in bitno");
1208 typebitor(long a, long b)
1214 if((a & b) == BLONG)
1215 c |= BVLONG; /* long long => vlong */
1217 warn(Z, "once is enough: %Q", a & b);
1222 diag(Node *n, char *fmt, ...)
1228 vseprint(buf, buf+sizeof(buf), fmt, arg);
1230 Bprint(&diagbuf, "%L %s\n", (n==Z)? nearln: n->lineno, buf);
1238 prtree(n, "diagnostic");
1242 Bprint(&diagbuf, "too many errors\n");
1248 warn(Node *n, char *fmt, ...)
1254 Bprint(&diagbuf, "warning: ");
1256 vseprint(buf, buf+sizeof(buf), fmt, arg);
1258 Bprint(&diagbuf, "%L %s\n", (n==Z)? nearln: n->lineno, buf);
1262 prtree(n, "warning");
1267 yyerror(char *fmt, ...)
1273 * hack to intercept message from yaccpar
1275 if(strcmp(fmt, "syntax error") == 0) {
1276 yyerror("syntax error, last name: %s", symb);
1280 vseprint(buf, buf+sizeof(buf), fmt, arg);
1282 Bprint(&diagbuf, "%L %s\n", lineno, buf);
1285 Bprint(&diagbuf, "too many errors\n");
1291 fatal(Node *n, char *fmt, ...)
1297 vseprint(buf, buf+sizeof(buf), fmt, arg);
1299 Bprint(&diagbuf, "%L %s\n", (n==Z)? nearln: n->lineno, buf);
1307 prtree(n, "diagnostic");
1313 ulong thash1 = 0x2edab8c9;
1314 ulong thash2 = 0x1dc74fb8;
1315 ulong thash3 = 0x1f241331;
1316 ulong thash[NALLTYPES];
1319 TXXX, 0x17527bbd, 0,
1320 TCHAR, 0x5cedd32b, 0,
1321 TUCHAR, 0x552c4454, 0,
1322 TSHORT, 0x63040b4b, 0,
1323 TUSHORT, 0x32a45878, 0,
1324 TINT, 0x4151d5bd, 0,
1325 TUINT, 0x5ae707d6, 0,
1326 TLONG, 0x5ef20f47, 0,
1327 TULONG, 0x36d8eb8f, 0,
1328 TVLONG, 0x6e5e9590, 0,
1329 TUVLONG, 0x75910105, 0,
1330 TFLOAT, 0x25fd7af1, 0,
1331 TDOUBLE, 0x7c40a1b2, 0,
1332 TIND, 0x1b832357, 0,
1333 TFUNC, 0x6babc9cb, 0,
1334 TARRAY, 0x7c50986d, 0,
1335 TVOID, 0x44112eff, 0,
1336 TSTRUCT, 0x7c2da3bf, 0,
1337 TUNION, 0x3eb25e98, 0,
1338 TENUM, 0x44b54f61, 0,
1339 TFILE, 0x19242ac3, 0,
1340 TOLD, 0x22b15988, 0,
1341 TDOT, 0x0204f6b3, 0,
1345 char* bnames[NALIGN];
1359 char* tnames[NALLTYPES];
1366 TUSHORT, 0, "USHORT",
1372 TUVLONG, 0, "UVLONG",
1374 TDOUBLE, 0, "DOUBLE",
1379 TSTRUCT, 0, "STRUCT",
1388 char* gnames[NGTYPES];
1392 GCONSTNT, 0, "CONST",
1393 GVOLATILE, 0, "VOLATILE",
1394 GVOLATILE|GCONSTNT, 0, "CONST-VOLATILE",
1398 char* qnames[NALLTYPES];
1405 TUSHORT, 0, "USHORT",
1411 TUVLONG, 0, "UVLONG",
1413 TDOUBLE, 0, "DOUBLE",
1418 TSTRUCT, 0, "STRUCT",
1423 TEXTERN, 0, "EXTERN",
1424 TSTATIC, 0, "STATIC",
1425 TTYPEDEF, 0, "TYPEDEF",
1426 TTYPESTR, 0, "TYPESTR",
1427 TREGISTER, 0, "REGISTER",
1428 TCONSTNT, 0, "CONSTNT",
1429 TVOLATILE, 0, "VOLATILE",
1430 TUNSIGNED, 0, "UNSIGNED",
1431 TSIGNED, 0, "SIGNED",
1437 char* cnames[NCTYPES];
1442 CEXTERN, 0, "EXTERN",
1444 CSTATIC, 0, "STATIC",
1446 CTYPEDEF, 0, "TYPEDEF",
1447 CTYPESTR, 0, "TYPESTR",
1455 char* onames[OEND+1];
1462 OANDAND, 0, "ANDAND",
1468 OASASHL, 0, "ASASHL",
1469 OASASHR, 0, "ASASHR",
1473 OASLDIV, 0, "ASLDIV",
1474 OASLMOD, 0, "ASLMOD",
1475 OASLMUL, 0, "ASLMUL",
1476 OASLSHR, 0, "ASLSHR",
1489 OCONTINUE, 0, "CONTINUE",
1492 ODOTDOT, 0, "DOTDOT",
1493 ODWHILE, 0, "DWHILE",
1505 OINDREG, 0, "INDREG",
1524 OPOSTDEC, 0, "POSTDEC",
1525 OPOSTINC, 0, "POSTINC",
1526 OPREDEC, 0, "PREDEC",
1527 OPREINC, 0, "PREINC",
1529 OREGISTER, 0, "REGISTER",
1530 ORETURN, 0, "RETURN",
1535 OSTRING, 0, "STRING",
1536 OLSTRING, 0, "LSTRING",
1537 OSTRUCT, 0, "STRUCT",
1539 OSWITCH, 0, "SWITCH",
1551 OREGPAIR, 0, "REGPAIR",
1557 /* OEQ, ONE, OLE, OLS, OLT, OLO, OGE, OHS, OGT, OHI */
1560 ONE, OEQ, OGT, OHI, OGE, OHS, OLT, OLO, OLE, OLS,
1564 OEQ, ONE, OGE, OHS, OGT, OHI, OLE, OLS, OLT, OLO,
1568 OEQ, ONE, OLS, OLS, OLO, OLO, OHS, OHS, OHI, OHI,
1574 TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TVLONG, TUVLONG, -1,
1579 TUCHAR, TUSHORT, TUINT, TULONG, TUVLONG, TIND, -1,
1582 char typesuv[NTYPE];
1585 TVLONG, TUVLONG, TSTRUCT, TUNION, -1,
1588 char typeilp[NTYPE];
1591 TINT, TUINT, TLONG, TULONG, TIND, -1
1594 char typechl[NTYPE];
1595 char typechlv[NTYPE];
1596 char typechlvp[NTYPE];
1599 TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, -1,
1602 char typechlp[NTYPE];
1603 int typechlpinit[] =
1605 TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TIND, -1,
1608 char typechlpfd[NTYPE];
1609 int typechlpfdinit[] =
1611 TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TFLOAT, TDOUBLE, TIND, -1,
1623 TSHORT, TUSHORT, -1,
1629 TINT, TUINT, TLONG, TULONG, -1,
1635 TVLONG, TUVLONG, -1,
1641 TFLOAT, TDOUBLE, -1,
1653 TSTRUCT, TUNION, -1,
1662 TUSHORT, BNUMBER, 0,
1668 TUVLONG, BNUMBER, 0,
1670 TDOUBLE, BNUMBER, 0,
1672 TSTRUCT, BSTRUCT, 0,
1683 TUSHORT, BNUMBER, 0,
1689 TUVLONG, BNUMBER, 0,
1691 TDOUBLE, BNUMBER, 0,
1699 TCHAR, BNUMBER|BIND|BVOID, 0,
1700 TUCHAR, BNUMBER|BIND|BVOID, 0,
1701 TSHORT, BNUMBER|BIND|BVOID, 0,
1702 TUSHORT, BNUMBER|BIND|BVOID, 0,
1703 TINT, BNUMBER|BIND|BVOID, 0,
1704 TUINT, BNUMBER|BIND|BVOID, 0,
1705 TLONG, BNUMBER|BIND|BVOID, 0,
1706 TULONG, BNUMBER|BIND|BVOID, 0,
1707 TVLONG, BNUMBER|BIND|BVOID, 0,
1708 TUVLONG, BNUMBER|BIND|BVOID, 0,
1709 TFLOAT, BNUMBER|BVOID, 0,
1710 TDOUBLE, BNUMBER|BVOID, 0,
1711 TIND, BINTEGER|BIND|BVOID, 0,
1713 TSTRUCT, BSTRUCT|BVOID, 0,
1714 TUNION, BUNION|BVOID, 0,
1721 TCHAR, BNUMBER|BIND, 0,
1722 TUCHAR, BNUMBER|BIND, 0,
1723 TSHORT, BNUMBER|BIND, 0,
1724 TUSHORT, BNUMBER|BIND, 0,
1725 TINT, BNUMBER|BIND, 0,
1726 TUINT, BNUMBER|BIND, 0,
1727 TLONG, BNUMBER|BIND, 0,
1728 TULONG, BNUMBER|BIND, 0,
1729 TVLONG, BNUMBER|BIND, 0,
1730 TUVLONG, BNUMBER|BIND, 0,
1732 TDOUBLE, BNUMBER, 0,
1743 TUSHORT, BNUMBER, 0,
1749 TUVLONG, BNUMBER, 0,
1751 TDOUBLE, BNUMBER, 0,
1752 TIND, BINTEGER|BIND, 0,
1762 TUSHORT, BNUMBER, 0,
1768 TUVLONG, BNUMBER, 0,
1770 TDOUBLE, BNUMBER, 0,
1778 TUCHAR, BINTEGER, 0,
1779 TSHORT, BINTEGER, 0,
1780 TUSHORT, BINTEGER, 0,
1784 TULONG, BINTEGER, 0,
1785 TVLONG, BINTEGER, 0,
1786 TUVLONG, BINTEGER, 0,
1796 TUSHORT, BNUMBER, 0,
1802 TUVLONG, BNUMBER, 0,
1804 TDOUBLE, BNUMBER, 0,
1831 BNUMBER|BIND|BSTRUCT|BUNION,
1834 char tab[NTYPE][NTYPE] =
1839 /*TCHAR*/ { 0, TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG,
1840 TULONG, TVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1842 /*TUCHAR*/ { 0, TUCHAR, TUCHAR, TUSHORT, TUSHORT, TUINT, TUINT, TULONG,
1843 TULONG, TUVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1845 /*TSHORT*/ { 0, TSHORT, TUSHORT, TSHORT, TUSHORT, TINT, TUINT, TLONG,
1846 TULONG, TVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1848 /*TUSHORT*/ { 0, TUSHORT, TUSHORT, TUSHORT, TUSHORT, TUINT, TUINT, TULONG,
1849 TULONG, TUVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1851 /*TINT*/ { 0, TINT, TUINT, TINT, TUINT, TINT, TUINT, TLONG,
1852 TULONG, TVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1854 /*TUINT*/ { 0, TUINT, TUINT, TUINT, TUINT, TUINT, TUINT, TULONG,
1855 TULONG, TUVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1857 /*TLONG*/ { 0, TLONG, TULONG, TLONG, TULONG, TLONG, TULONG, TLONG,
1858 TULONG, TVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1860 /*TULONG*/ { 0, TULONG, TULONG, TULONG, TULONG, TULONG, TULONG, TULONG,
1861 TULONG, TUVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1863 /*TVLONG*/ { 0, TVLONG, TUVLONG, TVLONG, TUVLONG, TVLONG, TUVLONG, TVLONG,
1864 TUVLONG, TVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1866 /*TUVLONG*/ { 0, TUVLONG, TUVLONG, TUVLONG, TUVLONG, TUVLONG, TUVLONG, TUVLONG,
1867 TUVLONG, TUVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND,
1869 /*TFLOAT*/ { 0, TFLOAT, TFLOAT, TFLOAT, TFLOAT, TFLOAT, TFLOAT, TFLOAT,
1870 TFLOAT, TFLOAT, TFLOAT, TFLOAT, TDOUBLE, TIND,
1872 /*TDOUBLE*/ { 0, TDOUBLE, TDOUBLE, TDOUBLE, TDOUBLE, TDOUBLE, TDOUBLE, TDOUBLE,
1873 TDOUBLE, TDOUBLE, TDOUBLE, TFLOAT, TDOUBLE, TIND,
1875 /*TIND*/ { 0, TIND, TIND, TIND, TIND, TIND, TIND, TIND,
1876 TIND, TIND, TIND, TIND, TIND, TIND,
1881 urk(char *name, int max, int i)
1884 fprint(2, "bad tinit: %s %d>=%d\n", name, i, max);
1895 for(p=thashinit; p->code >= 0; p++) {
1896 urk("thash", nelem(thash), p->code);
1897 thash[p->code] = p->value;
1899 for(p=bnamesinit; p->code >= 0; p++) {
1900 urk("bnames", nelem(bnames), p->code);
1901 bnames[p->code] = p->s;
1903 for(p=tnamesinit; p->code >= 0; p++) {
1904 urk("tnames", nelem(tnames), p->code);
1905 tnames[p->code] = p->s;
1907 for(p=gnamesinit; p->code >= 0; p++) {
1908 urk("gnames", nelem(gnames), p->code);
1909 gnames[p->code] = p->s;
1911 for(p=qnamesinit; p->code >= 0; p++) {
1912 urk("qnames", nelem(qnames), p->code);
1913 qnames[p->code] = p->s;
1915 for(p=cnamesinit; p->code >= 0; p++) {
1916 urk("cnames", nelem(cnames), p->code);
1917 cnames[p->code] = p->s;
1919 for(p=onamesinit; p->code >= 0; p++) {
1920 urk("onames", nelem(onames), p->code);
1921 onames[p->code] = p->s;
1923 for(ip=typeiinit; *ip>=0; ip++) {
1924 urk("typei", nelem(typei), *ip);
1927 for(ip=typeuinit; *ip>=0; ip++) {
1928 urk("typeu", nelem(typeu), *ip);
1931 for(ip=typesuvinit; *ip>=0; ip++) {
1932 urk("typesuv", nelem(typesuv), *ip);
1935 for(ip=typeilpinit; *ip>=0; ip++) {
1936 urk("typeilp", nelem(typeilp), *ip);
1939 for(ip=typechlinit; *ip>=0; ip++) {
1940 urk("typechl", nelem(typechl), *ip);
1945 for(ip=typechlpinit; *ip>=0; ip++) {
1946 urk("typechlp", nelem(typechlp), *ip);
1950 for(ip=typechlpfdinit; *ip>=0; ip++) {
1951 urk("typechlpfd", nelem(typechlpfd), *ip);
1952 typechlpfd[*ip] = 1;
1954 for(ip=typecinit; *ip>=0; ip++) {
1955 urk("typec", nelem(typec), *ip);
1958 for(ip=typehinit; *ip>=0; ip++) {
1959 urk("typeh", nelem(typeh), *ip);
1962 for(ip=typeilinit; *ip>=0; ip++) {
1963 urk("typeil", nelem(typeil), *ip);
1966 for(ip=typevinit; *ip>=0; ip++) {
1967 urk("typev", nelem(typev), *ip);
1972 for(ip=typefdinit; *ip>=0; ip++) {
1973 urk("typefd", nelem(typefd), *ip);
1976 for(ip=typeafinit; *ip>=0; ip++) {
1977 urk("typeaf", nelem(typeaf), *ip);
1980 for(ip=typesuinit; *ip >= 0; ip++) {
1981 urk("typesu", nelem(typesu), *ip);
1984 for(p=tasigninit; p->code >= 0; p++) {
1985 urk("tasign", nelem(tasign), p->code);
1986 tasign[p->code] = p->value;
1988 for(p=tasaddinit; p->code >= 0; p++) {
1989 urk("tasadd", nelem(tasadd), p->code);
1990 tasadd[p->code] = p->value;
1992 for(p=tcastinit; p->code >= 0; p++) {
1993 urk("tcast", nelem(tcast), p->code);
1994 tcast[p->code] = p->value;
1996 for(p=taddinit; p->code >= 0; p++) {
1997 urk("tadd", nelem(tadd), p->code);
1998 tadd[p->code] = p->value;
2000 for(p=tsubinit; p->code >= 0; p++) {
2001 urk("tsub", nelem(tsub), p->code);
2002 tsub[p->code] = p->value;
2004 for(p=tmulinit; p->code >= 0; p++) {
2005 urk("tmul", nelem(tmul), p->code);
2006 tmul[p->code] = p->value;
2008 for(p=tandinit; p->code >= 0; p++) {
2009 urk("tand", nelem(tand), p->code);
2010 tand[p->code] = p->value;
2012 for(p=trelinit; p->code >= 0; p++) {
2013 urk("trel", nelem(trel), p->code);
2014 trel[p->code] = p->value;
2017 /* 32-bit defaults */
2018 typeword = typechlp;
2019 typeswitch = typechl;
2020 typecmplx = typesuv;
2024 * return 1 if it is impossible to jump into the middle of n.
2027 deadhead(Node *n, int caseok)
2034 if(!deadhead(n->left, caseok))
2055 return deadhead(n->right, 1);
2071 return deadhead(n->right->left, caseok) && deadhead(n->right->right, caseok);
2083 return deadhead(c->left, 0) && deadhead(c->right, 0);
2087 mixedasop(Type *l, Type *r)
2089 return !typefd[l->etype] && typefd[r->etype];
2094 * (uvlong)~ul creates a ul mask with top bits zero, which is usually wrong
2095 * an explicit cast to ulong after ~ suppresses the diagnostic
2102 if(r->op == OCAST &&
2103 (rl = r->left)->op == OCOM &&
2104 (r->type->etype == TVLONG || r->type->etype == TUVLONG) &&
2105 typeu[rl->type->etype] && typechl[rl->type->etype])