From: kvigor Date: Wed, 12 Mar 2003 00:40:52 +0000 (+0000) Subject: Fix peephole rule condition functions properly; add special case so test for bug... X-Git-Url: https://git.gag.com/?p=fw%2Fsdcc;a=commitdiff_plain;h=5ecc3e8f1d952ffccc4829acdc798cb28df00157 Fix peephole rule condition functions properly; add special case so test for bug 700121 is less ugly git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2378 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 6289c21a..ce578ec3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2003-03-11 Kevin Vigor + * src/SDCCpeeph.c: quit being lazy and made proper fix (peephole + test function names must now match exactly). + * src/SDCCcse.c: added special case in findCheaperOp to allow + extending a short integer. Makes less awful code for bug 700121 test case. + 2003-03-11 Jesus Calvino-Fraga * as/mcs51/lkmain.c: Added ASlink-Warning to messages diff --git a/src/SDCCcse.c b/src/SDCCcse.c index 00e9cfaf..b720c262 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -363,13 +363,22 @@ DEFSETFUNC (findCheaperOp) if (IS_SPEC(operandType (cop)) && IS_SPEC(operandType (*opp)) && SPEC_NOUN(operandType(cop)) != SPEC_NOUN(operandType(*opp))) { - //fprintf(stderr, - // "findCheaperOp: " - // "was about to replace %s with %s, Kev says no.\n", - // nounName(operandType(cop)), - // nounName(operandType(*opp))); - *opp = NULL; - return 0; + // special case: we can make an unsigned char literal + // into an int literal with no cost. + if (isOperandLiteral(*opp) + && SPEC_NOUN(operandType(*opp)) == V_CHAR + && SPEC_NOUN(operandType(cop)) == V_INT) + { + *opp = operandFromOperand (*opp); + SPEC_NOUN(operandType(*opp)) = V_INT; + } + else + { + // No clue... + *opp = NULL; + return 0; + } + } LRH(printf ("findCheaperOp: %s < %s\n",\ diff --git a/src/SDCCpeeph.c b/src/SDCCpeeph.c index 6b68b305..37e349c6 100644 --- a/src/SDCCpeeph.c +++ b/src/SDCCpeeph.c @@ -450,6 +450,10 @@ callFuncByName (char *fname, "labelInRange", labelInRange } , + { + "operandsNotSame", operandsNotSame + } + , { "operandsNotSame3", operandsNotSame3 } @@ -473,10 +477,6 @@ callFuncByName (char *fname, { "operandsNotSame8", operandsNotSame8 } - , - { - "operandsNotSame", operandsNotSame - } , { "24bitMode", flat24bitMode @@ -497,16 +497,40 @@ callFuncByName (char *fname, "24bitModeAndPortDS390", flat24bitModeAndPortDS390 } }; - int i; + int i; + char *cmdCopy, *funcName, *funcArgs; + int rc = -1; + + /* Isolate the function name part (we are passed the full condition + * string including arguments) + */ + cmdCopy = Safe_strdup(fname); + funcName = strtok(cmdCopy, " \t"); + funcArgs = strtok(NULL, ""); - for (i = 0; i < ((sizeof (ftab)) / (sizeof (struct ftab))); i++) - if (strncmp (ftab[i].fname, fname, strlen (ftab[i].fname)) == 0) - { - return (*ftab[i].func) (vars, currPl, head, - fname + strlen (ftab[i].fname)); - } - fprintf (stderr, "could not find named function in function table\n"); - return TRUE; + for (i = 0; i < ((sizeof (ftab)) / (sizeof (struct ftab))); i++) + { + if (strcmp (ftab[i].fname, funcName) == 0) + { + rc = (*ftab[i].func) (vars, currPl, head, + funcArgs); + } + } + + Safe_free(cmdCopy); + + if (rc == -1) + { + fprintf (stderr, + "could not find named function \"%s\" in " + "peephole function table\n", + funcName); + // If the function couldn't be found, let's assume it's + // a bad rule and refuse it. + rc = FALSE; + } + + return rc; } /*-----------------------------------------------------------------*/