Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.120
 
1.121
 
MAIN:ragge:20040919094048
 
pftn.c
_>132132 } *lpole, *lparam;
 133133 static int nparams;
 134134 
<>135 -/*
 136 - * Struct used in array initialisation.
 137 - */
 138 -static struct instk {
 139 -        struct  instk *in_prev/* linked list */
 140 -        int     in_sz;          /* size of array element */
 141 -        struct  symtab **in_xp/* member in structure initializations */
 142 -        int     in_n;           /* number of initializations seen */
 143 -        struct  suedef *in_sue;
 144 -        union   dimfun *in_df;  /* dimoff/protos */
 145 -        TWORD   in_t;           /* type */
 146 -        TWORD   in_q;           /* qualifier */
 147 -        struct  symtab *in_sym; /* stab index */
 148 -        int     in_fl;  /* flag which says if this level is controlled by {} */
 149 -        OFFSZ   in_off;         /* offset of the beginning of this level */
 150 -} *pstk;
 151 -
152135 /* defines used for getting things off of the initialization stack */
 153136 
 154137 static NODE *arrstk[10];
     
 !
162145 static void dynalloc(struct symtab *p, int *poff);
 163146 void inforce(OFFSZ n);
 164147 void vfdalign(int n);
<>165 -static void instk(struct symtab *p, TWORD t, TWORD q, union dimfun *d,
 166 -    struct suedef *, OFFSZ off);
 167 -void gotscal(void);
168148 static void ssave(struct symtab *);
 169149 static void strprint(void);
 170150 
     
 !
10521032         return((unsigned int)sue->suesize * mult);
 10531033 }
 10541034 
<>1055 -/*
 1056 - * force inoff to have the value n
 1057 - */
 1058 -void
 1059 -inforce(OFFSZ n)
 1060 -{
 1061 -        /* inoff is updated to have the value n */
 1062 -        OFFSZ wb;
 1063 -        int rest;
 1064 -        /* rest is used to do a lot of conversion to ints... */
  1035+int idebug;
10651036 
<>1066 -        if( inoff == n ) return;
 1067 -        if (inoff > n)
 1068 -                cerror("initialization alignment error: inoff %lld n %lld",
 1069 -                    inoff, n);
 1070 -
 1071 -        wb = inoff;
 1072 -        SETOFF( wb, SZINT );
 1073 -
 1074 -        /* wb now has the next higher word boundary */
 1075 -
 1076 -        if( wb >= n ){ /* in the same word */
 1077 -                rest = n - inoff;
 1078 -                if (rest > 0)
 1079 -                        vfdzero( rest );
 1080 -                return;
 1081 -                }
 1082 -
 1083 -        /* otherwise, extend inoff to be word aligned */
 1084 -
 1085 -        rest = wb - inoff;
 1086 -        if (rest > 0)
 1087 -                vfdzero( rest );
 1088 -
 1089 -        /* now, skip full words until near to n */
 1090 -
 1091 -        rest = (n-inoff)/SZINT;
 1092 -        if (rest > 0)
 1093 -                zecode(rest);
 1094 -
 1095 -        /* now, the remainder of the last word */
 1096 -
 1097 -        rest = n-inoff;
 1098 -        if (rest > 0)
 1099 -                vfdzero( rest );
 1100 -        if( inoff != n ) cerror( "inoff error");
 1101 -
 1102 -        }
 1103 -
11041037 /*
<>1105 - * make inoff have the offset the next alignment of n
 1106 - */
 1107 -void
 1108 -vfdalign(int n)
 1109 -{
 1110 -        OFFSZ m;
 1111 -
 1112 -        m = inoff;
 1113 -        SETOFF( m, n );
 1114 -        inforce( m );
 1115 -}
 1116 -
 1117 -
 1118 -int idebug = 0;
 1119 -
 1120 -int ibseen = 0/* the number of } constructions which have been filled */
 1121 -
 1122 -int iclass/* storage class of thing being initialized */
 1123 -
 1124 -int ilocctr = 0/* location counter for current initialization */
 1125 -
 1126 -/*
 1127 - * beginning of initilization; set location ctr and set type
 1128 - */
 1129 -void
 1130 -beginit(struct symtab *p, int class)
 1131 -{
 1132 -#ifdef PCC_DEBUG
 1133 -        if (idebug >= 3)
 1134 -                printf("beginit(), symtab = %p\n", p);
 1135 -#endif
 1136 -
 1137 -        iclass = p->sclass;
 1138 -        if (class == EXTERN || class == FORTRAN)
 1139 -                iclass = EXTERN;
 1140 -        switch (iclass) {
 1141 -
 1142 -        case UNAME:
 1143 -        case EXTERN:
 1144 -                return;
 1145 -        case AUTO:
 1146 -        case REGISTER:
 1147 -                break;
 1148 -        case EXTDEF:
 1149 -        case STATIC:
 1150 -                ilocctr = ISARY(p->stype)?ADATA:DATA;
 1151 -                send_passt(IP_LOCCTR, ilocctr);
 1152 -                defalign(talign(p->stype, p->ssue));
 1153 -                defnam(p);
 1154 -        }
 1155 -
 1156 -        inoff = 0;
 1157 -        ibseen = 0;
 1158 -
 1159 -        pstk = 0;
 1160 -
 1161 -        instk(p, p->stype, p->squal, p->sdf, p->ssue, inoff);
 1162 -
 1163 -}
 1164 -
 1165 -/*
 1166 - * make a new entry on the parameter stack to initialize p
 1167 - */
 1168 -void
 1169 -instk(struct symtab *p, TWORD t, TWORD q,
 1170 -    union dimfun *d, struct suedef *sue, OFFSZ off)
 1171 -{
 1172 -        struct instk *sp;
 1173 -
 1174 -        for (;;) {
 1175 -#ifdef PCC_DEBUG
 1176 -                if (idebug)
 1177 -                        printf("instk((%p, %x, %x, %p,%p, %lld)\n",
 1178 -                            p, t, q, d, sue, (long long)off);
 1179 -#endif
 1180 -
 1181 -                /* save information on the stack */
 1182 -                sp = tmpalloc(sizeof(struct instk));
 1183 -                sp->in_prev = pstk;
 1184 -                pstk = sp;
 1185 -
 1186 -                pstk->in_fl = 0;        /* { flag */
 1187 -                pstk->in_sym = p;
 1188 -                pstk->in_t = t;
 1189 -                pstk->in_q = q;
 1190 -                pstk->in_df = d;
 1191 -                pstk->in_sue = sue;
 1192 -                pstk->in_n = 0/* number seen */
 1193 -                pstk->in_xp = (t == STRTY || t == UNIONTY) ? sue->suelem : NULL;
 1194 -                pstk->in_off = off;/* offset at the beginning of this element */
 1195 -
 1196 -                /* if t is an array, DECREF(t) can't be a field */
 1197 -                /* in_sz has size of array elements, and -size for fields */
 1198 -                if (ISARY(t)) {
 1199 -                        pstk->in_sz = tsize(DECREF(t), d+1, sue);
 1200 -                } else if (p->sclass & FIELD){
 1201 -                        pstk->in_sz = - (p->sclass & FLDSIZ);
 1202 -                } else {
 1203 -                        pstk->in_sz = 0;
 1204 -                }
 1205 -
 1206 -                if (iclass==AUTO || iclass == REGISTER) {
 1207 -                        if (t == STRTY || t == UNIONTY || ISARY(t))
 1208 -                                return; /* dealt with in doinit() */
 1209 -#if 0
 1210 -                        if (ISARY(t))
 1211 -                                uerror("no automatic aggregate initialization");
 1212 -#endif
 1213 -                }
 1214 -
 1215 -                /* now, if this is not a scalar, put on another element */
 1216 -
 1217 -                if (ISARY(t)) {
 1218 -                        t = DECREF(t);
 1219 -                        q = DECREF(q);
 1220 -                        ++d;
 1221 -                        continue;
 1222 -                } else if (t == STRTY || t == UNIONTY) {
 1223 -                        if (pstk->in_sue == 0) {
 1224 -                                uerror("can't initialize undefined %s",
 1225 -                                    t == STRTY ? "structure" : "union");
 1226 -                                iclass = -1;
 1227 -                                return;
 1228 -                        }
 1229 -                        p = *pstk->in_xp;
 1230 -                        if (((p->sclass != MOS && t == STRTY) ||
 1231 -                            (p->sclass != MOU && t == UNIONTY)) &&
 1232 -                            !(p->sclass&FIELD))
 1233 -                                cerror("insane %s member list",
 1234 -                                    t == STRTY ? "structure" : "union");
 1235 -                        t = p->stype;
 1236 -                        q = p->squal;
 1237 -                        d = p->sdf;
 1238 -                        sue = p->ssue;
 1239 -                        off += p->soffset;
 1240 -                        continue;
 1241 -                } else
 1242 -                        return;
 1243 -        }
 1244 -}
 1245 -
 1246 -/*
12471038  * Write last part of string.
 12481039  */
 12491040 NODE *
 12501041 strend(struct stri *si)
 12511042 {
 12521043         struct symtab *s;
<>1253 -        int lxarg, i, val;
 1254 -        char *wr = si->str;
12551044         NODE *p;
 12561045 
<>1257 -        i = 0;
 1258 -        if ((iclass == EXTDEF || iclass==STATIC) &&
 1259 -            (pstk->in_t == CHAR || pstk->in_t == UCHAR) &&
 1260 -            pstk->in_prev != NULL && ISARY(pstk->in_prev->in_t)) {
 1261 -                /* treat "abc" as { 'a', 'b', 'c', 0 } */
 1262 -                ilbrace();  /* simulate { */
 1263 -                inforce(pstk->in_off);
 1264 -                /*
 1265 -                 * if the array is inflexible (not top level),
 1266 -                 * pass in the size and be prepared to throw away
 1267 -                 * unwanted initializers
 1268 -                 */
 1269 -
 1270 -                lxarg = pstk->in_prev != NULL ?
 1271 -                    pstk->in_prev->in_df->ddim : 0;
 1272 -                while (*wr != 0) {
 1273 -                        if (*wr++ == '\\')
 1274 -                                val = esccon(&wr);
 1275 -                        else
 1276 -                                val = wr[-1];
 1277 -                        if (lxarg == 0 || i < lxarg)
 1278 -                                putbyte(val);
 1279 -                        else if (i == lxarg)
 1280 -                                werror("non-null byte ignored in string"
 1281 -                                    " initializer");
 1282 -                        i++;
 1283 -                }
 1284 -
 1285 -                if (lxarg == 0 || i < lxarg)
 1286 -                        putbyte(0);
 1287 -                irbrace();  /* simulate } */
 1288 -                return(NIL);
 1289 -        }
 1290 -        /* make a label, and get the contents and stash them away */
 1291 -        if (iclass != SNULL) { /* initializing */
 1292 -                /* fill out previous word, to permit pointer */
 1293 -                vfdalign(ALPOINT);
 1294 -        }
 1295 -
12961046         /* If an identical string is already emitted, just forget this one */
 12971047         si->str = addstring(si->str);   /* enter string in string table */
 12981048         s = lookup(si->str, SSTRING);   /* check for existance */
     
 !
13061056                  * function, or the end of the statement.
 13071057                  */
 13081058                 sc = tmpalloc(sizeof(struct strsched));
<>1309 -                sc->locctr = blevel==0 ? ISTRNG : STRNG;
  1059+                sc->locctr = STRNG;
13101060                 sc->sym = s;
 13111061                 sc->next = strpole;
 13121062                 strpole = sc;
 13131063                 s->soffset = getlab();
 13141064         }
 13151065 
<>1316 -        p = buildtree(STRING, NIL, NIL);
 1317 -        p->n_df = tmpalloc(sizeof(union dimfun));
  1066+        p = block(NAME, NIL, NIL, CHAR+ARY,
  1067+            tmpalloc(sizeof(union dimfun)), MKSUE(CHAR));
  1068+#ifdef CHAR_UNSIGNED
  1069+        p->n_type = UCHAR+ARY;
  1070+#endif
13181071         p->n_df->ddim = si->len+1;
 13191072         p->n_sp = s;
 13201073         return(p);
     
 !
13591112         p = bcon(v);
 13601113         incode( p, SZCHAR );
 13611114         tfree( p );
<>1362 -        gotscal();
  1115+//      gotscal();
13631116 }
 13641117 
<>1365 -void
 1366 -endinit(void)
 1367 -{
 1368 -        struct suedef *sue;
 1369 -        TWORD t;
 1370 -        union dimfun *d, *d1;
 1371 -        int n;
 1372 -
 1373 -#ifdef PCC_DEBUG
 1374 -        if (idebug)
 1375 -                printf("endinit(), inoff = %lld\n", (long long)inoff);
 1376 -#endif
 1377 -
 1378 -        switch( iclass ){
 1379 -
 1380 -        case EXTERN:
 1381 -        case AUTO:
 1382 -        case REGISTER:
 1383 -                return;
 1384 -                }
 1385 -
 1386 -        while (pstk->in_prev)
 1387 -                pstk = pstk->in_prev;
 1388 -
 1389 -        t = pstk->in_t;
 1390 -        d = pstk->in_df;
 1391 -        sue = pstk->in_sue;
 1392 -        n = pstk->in_n;
 1393 -
 1394 -        if( ISARY(t) ){
 1395 -                d1 = d;
 1396 -
 1397 -                vfdalign(pstk->in_sz);  /* fill out part of the last element, if needed */
 1398 -                n = inoff/pstk->in_sz/* real number of initializers */
 1399 -                if (d1->ddim >= n) {
 1400 -                        /* once again, t is an array, so no fields */
 1401 -                        inforce(tsize(t, d, sue));
 1402 -                        n = d1->ddim;
 1403 -                }
 1404 -                if (d1->ddim != 0 && d1->ddim != n)
 1405 -                        uerror("too many initializers");
 1406 -                if (n == 0)
 1407 -                        werror("empty array declaration");
 1408 -                d->ddim = n;
 1409 -        }
 1410 -
 1411 -        else if (t == STRTY || t == UNIONTY) {
 1412 -                /* clearly not fields either */
 1413 -                inforce( tsize( t, d, sue ) );
 1414 -        } else if (n > 1)
 1415 -                uerror("bad scalar initialization");
 1416 -        else
 1417 -        /* this will never be called with a field element... */
 1418 -                inforce(tsize(t, d, sue));
 1419 -
 1420 -        lparam = NULL;
 1421 -        vfdalign( AL_INIT );
 1422 -        inoff = 0;
 1423 -        iclass = SNULL;
 1424 -
 1425 -}
 1426 -
14271118 /*
<>1428 - * take care of generating a value for the initializer p
 1429 - * inoff has the current offset (last bit written)
 1430 - * in the current word being generated
 1431 - */
 1432 -void
 1433 -doinit(NODE *p)
 1434 -{
 1435 -        union dimfun *d;
 1436 -        NODE *u;
 1437 -        struct suedef *sue;
 1438 -        int sz;
 1439 -        TWORD t;
 1440 -        int o;
 1441 -
 1442 -        /* note: size of an individual initializer is assumed to fit into an int */
 1443 -
 1444 -        if( iclass < 0 ) return;
 1445 -        if( iclass == EXTERN || iclass == UNAME ){
 1446 -                uerror( "cannot initialize extern or union" );
 1447 -                iclass = -1;
 1448 -                return;
 1449 -                }
 1450 -
 1451 -        if( iclass == AUTO || iclass == REGISTER ){
 1452 -                /*
 1453 -                 * do the initialization and get out, without regard
 1454 -                 * for filing out the variable with zeros, etc.
 1455 -                 * Also deal with structs/arrays on stack.
 1456 -                 * pstk has info about the variable, p about what
 1457 -                 * should be initiated with.
 1458 -                 */
 1459 -                bccode(); /* XXX ??? */
 1460 -                send_passt(IP_NEWBLK, regvar, autooff); /* Wrong place */
 1461 -
 1462 -                spname = pstk->in_sym;
 1463 -                u = buildtree(NAME, NIL, NIL); /* Get variable node */
 1464 -//fwalk(p, eprint, 0);
 1465 -//fwalk(u, eprint, 0);
 1466 -                /* Allow for array init */
 1467 -                if (ISARY(u->n_type)) {
 1468 -                        if (u->n_type != p->n_type || p->n_type != ARY+CHAR)
 1469 -                                uerror("illegal types in assignment");
 1470 -                        /*
 1471 -                         * Check and construct the assign tree here.
 1472 -                         * Don't wanna go through buildtree(), too messy.
 1473 -                         */
 1474 -                        if (pstk->in_sym->sdf->ddim == 0) {
 1475 -                                /* Get size from string */
 1476 -                                pstk->in_sym->sdf->ddim = p->n_df->ddim;
 1477 -//printf("size set to %d\n", p->n_df->ddim);
 1478 -                                /* Adjust stack accordingly */
 1479 -                                pstk->in_sym->soffset = NOOFFSET;
 1480 -                                oalloc(pstk->in_sym, &autooff);
 1481 -                                if (autooff > maxautooff)
 1482 -                                        maxautooff = autooff;
 1483 -                        }
 1484 -                        p = buildtree(ADDROF, p, NIL);
 1485 -                        p = block(STASG, u, p, u->n_type, u->n_df, u->n_sue);
 1486 -                        p = block(UMUL, p, NIL, u->n_type, u->n_df, u->n_sue);
 1487 -//fwalk(p, eprint, 0);
 1488 -//                      if (p->n_op != STRING)
 1489 -//                              uerror("bad init op %d", p->n_op);
 1490 -
 1491 -
 1492 -                } else
 1493 -                        p = buildtree( ASSIGN, u, p );
 1494 -printf("after assign:\n");
 1495 -fwalk(p, eprint, 0);
 1496 -                ecomp(p);
 1497 -                return;
 1498 -                }
 1499 -
 1500 -        if( p == NIL ) return/* for throwing away strings that have been turned into lists */
 1501 -
 1502 -        if( ibseen ){
 1503 -                uerror( "} expected");
 1504 -                return;
 1505 -                }
 1506 -
 1507 -#ifdef PCC_DEBUG
 1508 -        if (idebug > 1)
 1509 -                printf("doinit(%p)\n", p);
 1510 -#endif
 1511 -
 1512 -        t = pstk->in_t/* type required */
 1513 -        d = pstk->in_df;
 1514 -        sue = pstk->in_sue;
 1515 -        if (pstk->in_sz < 0) {  /* bit field */
 1516 -                sz = -pstk->in_sz;
 1517 -        } else {
 1518 -                sz = tsize( t, d, sue );
 1519 -        }
 1520 -
 1521 -        inforce( pstk->in_off );
 1522 -
 1523 -        u = block(NAME, NIL,NIL, t, d, sue);
 1524 -        u->n_qual = pstk->in_q;
 1525 -        p = buildtree( ASSIGN, u, p );
 1526 -        nfree(p->n_left);
 1527 -        p->n_left = p->n_right;
 1528 -        p->n_right = NIL;
 1529 -        p->n_left = optim( p->n_left );
 1530 -        o = p->n_left->n_op;
 1531 -        if( o == ADDROF ){
 1532 -                NODE *l = p->n_left->n_left;
 1533 -                nfree(p->n_left);
 1534 -                p->n_left = l;
 1535 -        }
 1536 -        p->n_op = INIT;
 1537 -
 1538 -        if( sz < SZINT ){ /* special case: bit fields, etc. */
 1539 -                if (o != ICON)
 1540 -                        uerror( "illegal initialization" );
 1541 -                else {
 1542 -                        incode( p->n_left, sz );
 1543 -                        tfree(p);
 1544 -                }
 1545 -        } else if( o == FCON ){
 1546 -                fincode(p->n_left, sz );
 1547 -                tfree(p);
 1548 -        } else {
 1549 -                cinit( optim(p), sz );
 1550 -        }
 1551 -
 1552 -        gotscal();
 1553 -}
 1554 -
 1555 -void
 1556 -gotscal(void)
 1557 -{
 1558 -        int t, n;
 1559 -        struct symtab *p;
 1560 -        OFFSZ temp;
 1561 -
 1562 -        for( ; pstk->in_prev != NULL; ) {
 1563 -
 1564 -                if( pstk->in_fl ) ++ibseen;
 1565 -
 1566 -                pstk = pstk->in_prev;
 1567 -                
 1568 -                t = pstk->in_t;
 1569 -
 1570 -                if( t == STRTY || t == UNIONTY){
 1571 -                        ++pstk->in_xp;
 1572 -                        if ((p = *pstk->in_xp) == NULL)
 1573 -                                continue;
 1574 -
 1575 -                        /* otherwise, put next element on the stack */
 1576 -                        instk(p, p->stype, p->squal, p->sdf, p->ssue,
 1577 -                            p->soffset + pstk->in_off);
 1578 -                        return;
 1579 -                } else if( ISARY(t) ){
 1580 -                        n = ++pstk->in_n;
 1581 -                        if (n >= pstk->in_df->ddim && pstk->in_prev != NULL)
 1582 -                                continue;
 1583 -
 1584 -                        /* put the new element onto the stack */
 1585 -
 1586 -                        temp = pstk->in_sz;
 1587 -                        instk(pstk->in_sym, DECREF(pstk->in_t), DECREF(pstk->in_q),
 1588 -                            pstk->in_df+1, pstk->in_sue, pstk->in_off+n*temp);
 1589 -                        return;
 1590 -                } else if (ISFTN(t))
 1591 -                        cerror("gotscal");
 1592 -
 1593 -        }
 1594 -}
 1595 -
 1596 -/*
 1597 - * process an initializer's left brace
 1598 - */
 1599 -void
 1600 -ilbrace()
 1601 -{
 1602 -        int t;
 1603 -        struct instk *temp;
 1604 -
 1605 -        temp = pstk;
 1606 -
 1607 -        for (; pstk->in_prev != NULL; pstk = pstk->in_prev) {
 1608 -
 1609 -                t = pstk->in_t;
 1610 -                if (t != UNIONTY && t != STRTY && !ISARY(t))
 1611 -                        continue; /* not an aggregate */
 1612 -                if (pstk->in_fl) { /* already associated with a { */
 1613 -                        if (pstk->in_n)
 1614 -                                uerror( "illegal {");
 1615 -                        continue;
 1616 -                }
 1617 -
 1618 -                /* we have one ... */
 1619 -                pstk->in_fl = 1;
 1620 -                break;
 1621 -        }
 1622 -
 1623 -        /* cannot find one */
 1624 -        /* ignore such right braces */
 1625 -
 1626 -        pstk = temp;
 1627 -}
 1628 -
 1629 -/*
 1630 - * called when a '}' is seen
 1631 - */
 1632 -void
 1633 -irbrace()
 1634 -{
 1635 -#ifdef PCC_DEBUG
 1636 -        if (idebug)
 1637 -                printf( "irbrace(): lparam = %p on entry\n", lparam);
 1638 -#endif
 1639 -
 1640 -        if (ibseen) {
 1641 -                --ibseen;
 1642 -                return;
 1643 -        }
 1644 -
 1645 -        for (; pstk->in_prev != NULL; pstk = pstk->in_prev) {
 1646 -                if(!pstk->in_fl)
 1647 -                        continue;
 1648 -
 1649 -                /* we have one now */
 1650 -
 1651 -                pstk->in_fl = 0/* cancel { */
 1652 -                gotscal();  /* take it away... */
 1653 -                return;
 1654 -        }
 1655 -
 1656 -        /* these right braces match ignored left braces: throw out */
 1657 -}
 1658 -
 1659 -/*
16601119  * update the offset pointed to by poff; return the
 16611120  * offset of a value of size `size', alignment `alignment',
 16621121  * given that off is increasing
     
 !
18701329 void
 18711330 nidcl(NODE *p, int class)
 18721331 {
<>1873 -        int commflag;
  1332+        int commflag = 0;
<_18741333 
 18751334         /* compute class */
 18761335         if (class == SNULL) {
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-08-22 03:57 +0200