Quick Search:

Mode

Context

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

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.191
 
1.192
 
MAIN:ragge:20080126221617
 
pftn.c
_>120120 static NODE *arrstk[10];
 121121 static int arrstkp;
 122122 static int intcompare;
<> 123+static NODE *parlink;
123124 
 124125 void fixtype(NODE *p, int class);
 125126 int fixclass(int class, TWORD type);
     
 !
187188         if (blevel == 1) {
 188189                 switch (class) {
 189190                 default:
<>190 -                        if (!(class&FIELD))
  191+                        if (!(class&FIELD) && !ISFTN(type))
191192                                 uerror("declared argument %s missing",
 192193                                     p->sname );
 193194                 case MOS:
 194195                 case STNAME:
 195196                 case MOU:
 196197                 case UNAME:
 197198                 case TYPEDEF:
<> 199+                case PARAM:
198200                         ;
 199201                 }
 200202         }
     
 !
343345 
 344346         case AUTO:
 345347         case REGISTER:
<> 348+                if (blevel == slev)
  349+                        goto redec;
346350                 ;  /* mismatch.. */
 347351         }
 348352 
     
 !
354358         if (blevel == slev || class == EXTERN || class == FORTRAN ||
 355359             class == UFORTRAN) {
 356360                 if (ISSTR(class) && !ISSTR(p->sclass)) {
<>357 -                        uerror("redeclaration of %s", p->sname);
  361+redec:                  uerror("redeclaration of %s", p->sname);
358362                         return;
 359363                 }
 360364         }
 361365         if (blevel == 0)
<>362 -                uerror("redeclaration of %s", p->sname);
  366+                goto redec;
363367         q->n_sp = p = hide(p);
 364368 
 365369         enter/* make a new entry */
     
 !
416420                 else
 417421                         oalloc(p, &autooff);
 418422                 break;
<> 423+        case PARAM:
  424+                if (arrstkp)
  425+                        dynalloc(p, &argoff);
  426+                else
  427+                        oalloc(p, &argoff);
  428+                break;
  429+                
419430         case STATIC:
 420431         case EXTDEF:
 421432         case EXTERN:
     
 !
476487 {
 477488         extern struct savbc *savbc;
 478489         extern struct swdef *swpole;
<> 490+        extern int tvaloff;
479491         char *c;
 480492 
 481493         if (retlab != NOLAB && nerrors == 0) { /* inside a real function */
     
 !
484496                 c = cftnsp->soname;
 485497                 SETOFF(maxautooff, ALCHAR);
 486498                 send_passt(IP_EPILOG, 0, maxautooff/SZCHAR, c,
<>487 -                    cftnsp->stype, cftnsp->sclass == EXTDEF, retlab);
  499+                    cftnsp->stype, cftnsp->sclass == EXTDEF, retlab, tvaloff);
488500         }
 489501 
 490502         tcheck();
     
 !
517529         union arglist *al, *al2, *alb;
 518530         struct params *a;
 519531         struct symtab *p, **parr = NULL; /* XXX gcc */
<>520 -        char *c;
521532         int i;
 522533 
<>523 -        argoff = ARGINIT;
 524 -
525534         /*
 526535          * Deal with fun(void) properly.
 527536          */
     
 !
541550 
 542551                 p = a->sym;
 543552                 parr[i++] = p;
<> 553+                if (p == NULL) {
  554+                        uerror("arg %d missing", i);
  555+                        p = cftnsp; /* just some symtab */
  556+                }
544557                 if (p->stype == FARG) {
 545558                         p->stype = INT;
 546559                         p->ssue = MKSUE(INT);
     
 !
552565                         werror("function declared as argument");
 553566                         p->stype = INCREF(p->stype);
 554567                 }
<>555 -                /* always set aside space, even for register arguments */
 556 -                oalloc(p, &argoff);
557568 #ifdef STABS
 558569                 if (gflag)
 559570                         stabs_newsym(p);
     
 !
581592                 intcompare = 0;
 582593         }
 583594 done:   cendarg();
<>584 -        c = cftnsp->soname;
 585 -#if 0
 586 -        prolab = getlab();
 587 -        send_passt(IP_PROLOG, -1, -1, c, cftnsp->stype,
 588 -            cftnsp->sclass == EXTDEF, prolab);
 589 -#endif
  595+
590596         plabel(prolab); /* after prolog, used in optimization */
 591597         retlab = getlab();
 592598         bfcode(parr, nparams);
 593599         plabel(getlab()); /* used when spilling */
<> 600+        if (parlink)
  601+                ecomp(parlink);
  602+        parlink = NIL;
594603         lparam = NULL;
 595604         nparams = 0;
<> 605+        symclear(1);    /* In case of function pointer args */
596606 }
 597607 
 598608 /*
     
 !
930940 ftnarg(NODE *p)
 931941 {
 932942         NODE *q;
<>933 -        struct symtab *s;
934943 
 935944 #ifdef PCC_DEBUG
 936945         if (ddebug > 2)
 937946                 printf("ftnarg(%p)\n", p);
 938947 #endif
 939948         /*
<>940 -         * Enter argument onto param stack.
 941 -         * Do not declare parameters until later (in dclargs);
 942 -         * the function must be declared first.
 943 -         * put it on the param stack in reverse order, due to the
 944 -         * nature of the stack it will be reclaimed correct.
  949+         * Push argument symtab entries onto param stack in reverse order,
  950+         * due to the nature of the stack it will be reclaimed correct.
945951          */
 946952         for (; p->n_op != NAME; p = p->n_left) {
<>947 -                if (p->n_op == (UCALL) && p->n_left->n_op == NAME)
  953+                if (p->n_op == UCALL && p->n_left->n_op == NAME)
948954                         return/* Nothing to enter */
 949955                 if (p->n_op == CALL && p->n_left->n_op == NAME)
 950956                         break;
 951957         }
 952958 
 953959         p = p->n_right;
<>954 -        blevel = 1;
 955 -
956960         while (p->n_op == CM) {
 957961                 q = p->n_right;
 958962                 if (q->n_op != ELLIPSIS) {
<>959 -                        s = lookup((char *)q->n_sp, 0);
 960 -                        if (s->stype != UNDEF) {
 961 -                                if (s->slevel > 0)
 962 -                                        uerror("parameter '%s' redefined",
 963 -                                            s->sname);
 964 -                                s = hide(s);
 965 -                        }
 966 -                        s->soffset = NOOFFSET;
 967 -                        s->sclass = PARAM;
 968 -                        s->stype = q->n_type;
 969 -                        s->sdf = q->n_df;
 970 -                        s->ssue = q->n_sue;
 971 -                        ssave(s);
  963+                        ssave(q->n_sp);
972964                         nparams++;
 973965 #ifdef PCC_DEBUG
 974966                         if (ddebug > 2)
 975967                                 printf("        saving sym %s (%p) from (%p)\n",
<>976 -                                    s->sname, s, q);
  968+                                    q->n_sp->sname, q->n_sp, q);
977969 #endif
 978970                 }
 979971                 p = p->n_left;
 980972         }
<>981 -        s = lookup((char *)p->n_sp, 0);
 982 -        if (s->stype != UNDEF) {
 983 -                if (s->slevel > 0)
 984 -                        uerror("parameter '%s' redefined", s->sname);
 985 -                s = hide(s);
 986 -        }
 987 -        s->soffset = NOOFFSET;
 988 -        s->sclass = PARAM;
 989 -        s->stype = p->n_type;
 990 -        s->sdf = p->n_df;
 991 -        s->ssue = p->n_sue;
 992 -        ssave(s);
  973+        ssave(p->n_sp);
993974         if (p->n_type != VOID)
 994975                 nparams++;
<>995 -        blevel = 0;
996976 
 997977 #ifdef PCC_DEBUG
 998978         if (ddebug > 2)
 999979                 printf("        saving sym %s (%p) from (%p)\n",
<>1000 -                    s->sname, s, p);
  980+                    p->n_sp->sname, p->n_sp, p);
1001981 #endif
 1002982 }
 1003983 
     
 !
12431223 }
 12441224 
 12451225 /*
<>1246 - * Allocate space on the stack for dynamic arrays.
  1226+ * Delay emission of code generated in argument headers.
  1227+ */
  1228+static void
  1229+edelay(NODE *p)
  1230+{
  1231+        if (blevel == 1) {
  1232+                /* Delay until after declarations */
  1233+                if (parlink == NULL)
  1234+                        parlink = p;
  1235+                else
  1236+                        parlink = block(COMOP, parlink, p, 0, 0, 0);
  1237+        } else
  1238+                ecomp(p);
  1239+}
  1240+
  1241+/*
  1242+ * Allocate space on the stack for dynamic arrays (or at least keep track
  1243+ * of the index).
12471244  * Strategy is as follows:
 12481245  * - first entry is a pointer to the dynamic datatype.
 12491246  * - if it's a one-dimensional array this will be the only entry used.
     
 !
12581255         union dimfun *df;
 12591256         NODE *n, *nn, *tn, *pol;
 12601257         TWORD t;
<>1261 -        int i, no;
  1258+        int astkp, no;
12621259 
 12631260         /*
<>1264 -         * The pointer to the array is stored in a TEMP node, which number
 1265 -         * is in the soffset field;
  1261+         * The pointer to the array is not necessarily stored in a
  1262+         * TEMP node, but if it is, its number is in the soffset field;
12661263          */
 12671264         t = p->stype;
<>1268 -        p->sflags |= (STNODE|SDYNARRAY);
 1269 -        p->stype = INCREF(p->stype);    /* Make this an indirect pointer */
 1270 -        tn = tempnode(0, p->stype, p->sdf, p->ssue);
 1271 -        p->soffset = regno(tn);
  1265+        astkp = 0;
  1266+        if (ISARY(t) && blevel == 1) {
  1267+                /* must take care of side effects of dynamic arg arrays */
  1268+                if (p->sdf->ddim < 0) {
  1269+                        /* first-level array will be indexed correct */
  1270+                        edelay(arrstk[astkp++]);
  1271+                }
  1272+                p->sdf++;
  1273+                p->stype += (PTR-ARY);
  1274+                t = p->stype;
  1275+        }
  1276+        if (ISARY(t)) {
  1277+                p->sflags |= (STNODE|SDYNARRAY);
  1278+                p->stype = INCREF(p->stype); /* Make this an indirect pointer */
  1279+                tn = tempnode(0, p->stype, p->sdf, p->ssue);
  1280+                p->soffset = regno(tn);
  1281+        } else {
  1282+                oalloc(p, poff);
  1283+                tn = NIL;
  1284+        }
12721285 
 12731286         df = p->sdf;
 12741287 
 12751288         pol = NIL;
<>1276 -        for (i = 0; ISARY(t); t = DECREF(t), df++) {
 1277 -                if (df->ddim >= 0)
  1289+        for (; t > BTMASK; t = DECREF(t)) {
  1290+                if (!ISARY(t))
12781291                         continue;
<>1279 -                n = arrstk[i++];
 1280 -                nn = tempnode(0, INT, 0, MKSUE(INT));
 1281 -                no = regno(nn);
 1282 -                ecomp(buildtree(ASSIGN, nn, n)); /* Save size */
  1292+                if (df->ddim < 0) {
  1293+                        n = arrstk[astkp++];
  1294+                        nn = tempnode(0, INT, 0, MKSUE(INT));
  1295+                        no = regno(nn);
  1296+                        edelay(buildtree(ASSIGN, nn, n));
12831297 
<>1284 -                df->ddim = -no;
 1285 -                n = tempnode(no, INT, 0, MKSUE(INT));
 1286 -                if (pol == NIL)
 1287 -                        pol = n;
 1288 -                else
 1289 -                        pol = buildtree(MUL, pol, n);
  1298+                        df->ddim = -no;
  1299+                        n = tempnode(no, INT, 0, MKSUE(INT));
  1300+                } else
  1301+                        n = bcon(df->ddim);
  1302+
  1303+                pol = (pol == NIL ? n : buildtree(MUL, pol, n));
  1304+                df++;
12901305         }
 12911306         /* Create stack gap */
<>1292 -        if (pol == NIL)
 1293 -                uerror("aggregate dynamic array not allowed");
 1294 -        else
 1295 -                spalloc(tn, pol, tsize(t, 0, p->ssue));
  1307+        if (blevel == 1) {
  1308+                if (tn)
  1309+                        tfree(tn);
  1310+                if (pol)
  1311+                        tfree(pol);
  1312+        } else {
  1313+                if (pol == NIL)
  1314+                        uerror("aggregate dynamic array not allowed");
  1315+                if (tn)
  1316+                        spalloc(tn, pol, tsize(t, 0, p->ssue));
  1317+        }
12961318         arrstkp = 0;
 12971319 }
 12981320 
     
 !
24792501         case EXTDEF:
 24802502         case TYPEDEF:
 24812503         case USTATIC:
<> 2504+        case PARAM:
<_24822505                 return( class );
 24832506 
 24842507         default:
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-07-10 17:48 +0200