/* put out other arrays, copy the parsers */ static void others() { extern int gen_lines; int c, i, j; int tmpline; finput = fopen(parser, "r"); if (finput == NULL) /* * TRANSLATION_NOTE -- This is a message from yacc. * This message is passed to error() function. * This error message is issued when yacc can not find * the parser to be copied. */ error(gettext( "cannot find parser %s"), parser); warray(L"yyr1", levprd, nprod); aryfil(temp1, nprod, 0); /* had_act[i] is either 1 or 0 */ PLOOP(1, i) temp1[i] = ((prdptr[i+1] - prdptr[i]-2) << 1) | had_act[i]; warray(L"yyr2", temp1, nprod); aryfil(temp1, nstate, -10000000); TLOOP(i) for (j = tstates[i]; j != 0; j = mstates[j]) temp1[j] = tokset[i].value; NTLOOP(i) for (j = ntstates[i]; j != 0; j = mstates[j]) temp1[j] = -i; warray(L"yychk", temp1, nstate); warray(L"yydef", defact, nstate); if ((fdebug = fopen(DEBUGNAME, "r")) == NULL) error("cannot open yacc.debug"); while ((c = getwc(fdebug)) != EOF) (void) putwc(c, ftable); (void) fclose(fdebug); ZAPFILE(DEBUGNAME); if (gen_lines) (void) fprintf(ftable, "# line\t1 \"%s\"\n", parser); tmpline = 1; /* copy parser text */ while ((c = getwc(finput)) != EOF) { if (c == '\n') tmpline++; if (c == L'$') { if ((c = getwc(finput)) != L'A') (void) putwc(L'$', ftable); else { /* copy actions */ tmpline++; faction = fopen(ACTNAME, "r"); if (faction == NULL) /* * TRANSLATION_NOTE -- This is a message from yacc. * This message is passed to error() function. * This error is issued when yacc can not open a * temporary file to be used. You do not need to * use the word 'tempfile'. You can translate it to * mean 'temporary file'. */ error(gettext( "cannot open action tempfile")); while ((c = getwc(faction)) != EOF) (void) putwc(c, ftable); (void) fclose(faction); if (gen_lines) (void) fprintf(ftable, "\n# line\t%d \"%s\"", tmpline, parser); ZAPFILE(ACTNAME); c = getwc(finput); } } (void) putwc(c, ftable); } (void) fclose(ftable); }
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); }
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); }
/* put out other arrays, copy the parsers */ static void others () { extern int gen_lines; int c, i, j; int tmpline; finput = fopen (parser, "r"); if (finput == NULL) /* * TRANSLATION_NOTE -- This is a message from yacc. * This message is passed to error() function. * This error message is issued when yacc can not find * the parser to be copied. */ error ("cannot find parser %s", parser); warray ("yyr1", levprd, nprod); aryfil (temp1, nprod, 0); /* had_act[i] is either 1 or 0 */ /* original PLOOP(1, i) temp1[i] = ((prdptr[i+1] - prdptr[i]-2) << 1) | had_act[i]; */ PLOOP (1, i) temp1[i] = prdptr[i + 1] - prdptr[i] - 2; warray ("yyr2", temp1, nprod); aryfil (temp1, nstate, -1000); TLOOP (i) for (j = tstates[i]; j != 0; j = mstates[j]) temp1[j] = tokset[i].value; NTLOOP (i) for (j = ntstates[i]; j != 0; j = mstates[j]) temp1[j] = -i; warray ("yychk", temp1, nstate); warray ("yydef", defact, nstate); fclose (ftable); fclose (fudecl); if ((fdebug = fopen (DEBUGNAME, "r")) == NULL) error ("cannot open yacc.debug"); while ((c = getc (fdebug)) != EOF) (void) putc (c, fsppout); (void) fclose (fdebug); ZAPFILE (DEBUGNAME); if (gen_lines) (void) fprintf (fsppout, "# line\t1 \"%s\"\n", parser); tmpline = 1; /* copy parser text */ while ((c = getc (finput)) != EOF) { if (c == '\n') tmpline++; if (c == '$') { if ((c = getc (finput)) == 'A') { /* Replace $A macro by the user declarations. */ fudecl = fopen (UDFILE, "r"); if (fudecl == NULL) error ("cannot reopen user declarations tempfile"); while ((c = getc (fudecl)) != EOF) putc (c, fsppout); fclose (fudecl); ZAPFILE (UDFILE); /* Skip remainder of line following macro. */ while ((c = getc (finput)) != '\n' && c != EOF); } else if (c == 'B') { /* Replace $B macro by the parser tables. */ ftable = fopen (TABFILE, "r"); if (ftable == NULL) error ("cannot reopen parser tables tempfile"); while ((c = getc (ftable)) != EOF) putc (c, fsppout); fclose (ftable); ZAPFILE (TABFILE); /* Skip remainder of line following macro. */ while ((c = getc (finput)) != '\n' && c != EOF); } else if (c == 'C') { /* Replace $C macro by user-supplied actions. */ faction = fopen (ACTNAME, "r"); if (faction == NULL) error ("cannot reopen action tempfile"); while ((c = getc (faction)) != EOF) putc (c, fsppout); fclose (faction); ZAPFILE (ACTNAME); /* Skip remainder of line following macro. */ while ((c = getc (finput)) != '\n' && c != EOF); } else { putc ('$', fsppout); putc (c, fsppout); } } else putc (c, fsppout); } fclose (fsppout); }