Fixed problem with cost computation, added some assertions and

added some more precise debugging printing
This commit is contained in:
ceriel 1990-12-17 10:02:52 +00:00
parent 0ad960a9b0
commit 41dc11e497

View file

@ -71,6 +71,7 @@ unsigned codegen(codep,ply,toplevel,costlimit,forced) byte *codep; unsigned cost
#endif #endif
#ifndef NDEBUG #ifndef NDEBUG
assert(costlimit <= INFINITY);
level++; level++;
DEBUG("Entering codegen"); DEBUG("Entering codegen");
if (Debug > 1) fprintf(stderr, "toplevel = %d\n", toplevel); if (Debug > 1) fprintf(stderr, "toplevel = %d\n", toplevel);
@ -195,6 +196,7 @@ if (Debug)
*/ */
SAVEST; SAVEST;
mincost = costlimit-totalcost+1; mincost = costlimit-totalcost+1;
assert(mincost <= INFINITY);
for(i=0;i<npos;i++) { for(i=0;i<npos;i++) {
t=codegen(&coderules[pos[i]],ply,FALSE, t=codegen(&coderules[pos[i]],ply,FALSE,
costlimit<MAXINT?mincost:MAXINT,0); costlimit<MAXINT?mincost:MAXINT,0);
@ -444,6 +446,7 @@ normalfailed: if (stackpad!=tokpatlen) {
} }
for (i=0;i<nregneeded;i++) for (i=0;i<nregneeded;i++)
totalcost += docoerc(regtp[i],regcp[i],ply,toplevel,besttup->p_rar[i]); totalcost += docoerc(regtp[i],regcp[i],ply,toplevel,besttup->p_rar[i]);
assert(totalcost <= costlimit);
myfree((string)besttup); myfree((string)besttup);
break; break;
} }
@ -455,7 +458,7 @@ normalfailed: if (stackpad!=tokpatlen) {
int doremove = (codep[-1] & 037) == DO_REMOVE; int doremove = (codep[-1] & 037) == DO_REMOVE;
extern int allsetno; extern int allsetno;
DEBUG("REMOVE"); DEBUG(doremove ? "REMOVE" : "TOSTACK");
if (codep[-1]&32) { if (codep[-1]&32) {
getint(texpno,codep); getint(texpno,codep);
getint(nodeno,codep); getint(nodeno,codep);
@ -477,10 +480,15 @@ normalfailed: if (stackpad!=tokpatlen) {
CHKCOST(); CHKCOST();
break; break;
} }
if (doremove) for (rp=machregs;rp<machregs+NREGS;rp++) if (doremove) for (rp=machregs;rp<machregs+NREGS;rp++) {
if (rp->r_contents.t_token != 0 && if (rp->r_contents.t_token != 0 &&
match(&rp->r_contents,&machsets[texpno],nodeno)) match(&rp->r_contents,&machsets[texpno],nodeno)) {
#ifndef NDEBUG
if (Debug > 1) fprintf(stderr, "killing reg %ld (%s)\n", (long)(rp-machregs), rp->r_repr ? codestrings[rp->r_repr] : "cc");
#endif
rp->r_contents.t_token=0; rp->r_contents.t_token=0;
}
}
break; break;
} }
case DO_KILLREG: case DO_KILLREG:
@ -492,7 +500,7 @@ normalfailed: if (stackpad!=tokpatlen) {
result_t result; result_t result;
int dokill = (codep[-1] & 037) == DO_KILLREG; int dokill = (codep[-1] & 037) == DO_KILLREG;
DEBUG("RREMOVE"); DEBUG(dokill ? "KILLREG" : "RREMOVE");
getint(nodeno,codep); getint(nodeno,codep);
result=compute(&enodes[nodeno]); result=compute(&enodes[nodeno]);
if (result.e_typ!=EV_REG) if (result.e_typ!=EV_REG)
@ -718,6 +726,7 @@ normalfailed: if (stackpad!=tokpatlen) {
} }
if (toplevel) if (toplevel)
gennl(); gennl();
CHKCOST();
break; break;
} }
case DO_MOVE: { case DO_MOVE: {