callopt(){ register i, *p, j, k, *q; /* read the arrays from tempfile and set parameters */ if( (finput=fopen(TEMPNAME,"r")) == NULL ) error( "optimizer cannot open tempfile" ); pgo[0] = 0; yypact[0] = 0; nstate = 0; nnonter = 0; for(;;){ switch( gtnm() ){ case '\n': yypact[++nstate] = (--pmem) - mem; case ',': continue; case '$': break; default: error( "bad tempfile" ); } break; } yypact[nstate] = yypgo[0] = (--pmem) - mem; for(;;){ switch( gtnm() ){ case '\n': yypgo[++nnonter]= pmem-mem; case ',': continue; case EOF: break; default: error( "bad tempfile" ); } break; } yypgo[nnonter--] = (--pmem) - mem; for( i=0; i<nstate; ++i ){ k = 32000; j = 0; q = mem + yypact[i+1]; for( p = mem + yypact[i]; p<q ; p += 2 ){ if( *p > j ) j = *p; if( *p < k ) k = *p; } if( k <= j ){ /* nontrivial situation */ /* temporarily, kill this for compatibility j -= k; /* j is now the range */ if( k > maxoff ) maxoff = k; } greed[i] = (yypact[i+1]-yypact[i]) + 2*j; if( j > maxspr ) maxspr = j; } /* initialize ggreed table */ for( i=1; i<=nnonter; ++i ){ ggreed[i] = 1; j = 0; /* minimum entry index is always 0 */ q = mem + yypgo[i+1] -1; for( p = mem+yypgo[i]; p<q ; p += 2 ) { ggreed[i] += 2; if( *p > j ) j = *p; } ggreed[i] = ggreed[i] + 2*j; if( j > maxoff ) maxoff = j; } /* now, prepare to put the shift actions into the a array */ for( i=0; i<ACTSIZE; ++i ) a[i] = 0; maxa = a; for( i=0; i<nstate; ++i ) { if( greed[i]==0 && adb>1 ) fprintf( ftable, "State %d: null\n", i ); pa[i] = YYFLAG1; } while( (i = nxti()) != NOMORE ) { if( i >= 0 ) stin(i); else gin(-i); } if( adb>2 ){ /* print a array */ for( p=a; p <= maxa; p += 10){ fprintf( ftable, "%4d ", p-a ); for( i=0; i<10; ++i ) fprintf( ftable, "%4d ", p[i] ); fprintf( ftable, "\n" ); } } /* write out the output appropriate to the language */ aoutput(); osummary(); ZAPFILE(TEMPNAME); }
void callopt(void) { register int i, *p, j, k, *q; ggreed = malloc(sizeof (int) * size); pgo = malloc(sizeof (int) * size); yypgo = &nontrst[0].tvalue; /* read the arrays from tempfile and set parameters */ if ((finput = fopen(TEMPNAME, "r")) == NULL) error("optimizer cannot open tempfile"); optimmem = tracemem; pgo[0] = 0; temp1[0] = 0; nstate = 0; nnonter = 0; for (;;) { switch (gtnm()) { case L'\n': temp1[++nstate] = (--optimmem) - tracemem; /* FALLTHRU */ case L',': continue; case L'$': break; default: error("bad tempfile"); } break; } temp1[nstate] = yypgo[0] = (--optimmem) - tracemem; for (;;) { switch (gtnm()) { case L'\n': yypgo[++nnonter] = optimmem-tracemem; /* FALLTHRU */ case L',': continue; case EOF: break; default: error("bad tempfile"); } break; } yypgo[nnonter--] = (--optimmem) - tracemem; for (i = 0; i < nstate; ++i) { k = 32000000; j = 0; q = tracemem + temp1[i+1]; for (p = tracemem + temp1[i]; p < q; p += 2) { if (*p > j) j = *p; if (*p < k) k = *p; } if (k <= j) { /* * nontrivial situation * temporarily, kill this for compatibility */ /* j -= k; j is now the range */ if (k > maxoff) maxoff = k; } tystate[i] = (temp1[i+1] - temp1[i]) + 2*j; if (j > maxspr) maxspr = j; } /* initialize ggreed table */ for (i = 1; i <= nnonter; ++i) { ggreed[i] = 1; j = 0; /* minimum entry index is always 0 */ q = tracemem + yypgo[i+1] -1; for (p = tracemem + yypgo[i]; p < q; p += 2) { ggreed[i] += 2; if (*p > j) j = *p; } ggreed[i] = ggreed[i] + 2*j; if (j > maxoff) maxoff = j; } /* now, prepare to put the shift actions into the amem array */ for (i = 0; i < new_actsize; ++i) amem[i] = 0; maxa = amem; for (i = 0; i < nstate; ++i) { if (tystate[i] == 0 && adb > 1) fprintf(ftable, "State %d: null\n", i); indgo[i] = YYFLAG1; } while ((i = nxti()) != NOMORE) { if (i >= 0) stin(i); else gin(-i); } if (adb > 2) { /* print a array */ for (p = amem; p <= maxa; p += 10) { fprintf(ftable, "%4d ", p-amem); for (i = 0; i < 10; ++i) fprintf(ftable, "%4d ", p[i]); fprintf(ftable, "\n"); } } /* write out the output appropriate to the language */ aoutput(); osummary(); ZAPFILE(TEMPNAME); }