1
0
mirror of https://github.com/cc65/cc65.git synced 2024-08-20 09:29:12 +00:00

Rewrote code for better readability

git-svn-id: svn://svn.cc65.org/cc65/trunk@1560 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2002-11-21 20:46:16 +00:00
parent 0ba44bb2d4
commit 42463beaee

View File

@ -112,7 +112,6 @@ static const CallDesc CallTable [] = {
{ "tosumodax", -1, 0, -1, "tosumoda0" }, { "tosumodax", -1, 0, -1, "tosumoda0" },
{ "tosumulax", -1, 0, -1, "tosumula0" }, { "tosumulax", -1, 0, -1, "tosumula0" },
{ "tosxorax", -1, 0, -1, "tosxora0" }, { "tosxorax", -1, 0, -1, "tosxora0" },
{ "zzzzzzzz", -1, -1, -1, "zzzzzzzz" },
#if 0 #if 0
"tosadd0ax", /* tosaddeax, sreg = 0 */ "tosadd0ax", /* tosaddeax, sreg = 0 */
@ -155,18 +154,16 @@ static const CallDesc* FindCall (const char* Name)
{ {
/* Do a binary search */ /* Do a binary search */
int First = 0; int First = 0;
int Last = (sizeof(CallTable) / sizeof(CallTable[0])) - 1; int Last = CALL_COUNT - 1;
int Current;
int Result;
int Found = 0; int Found = 0;
while (First <= Last) { while (First <= Last) {
/* Set current to mid of range */ /* Set current to mid of range */
Current = (Last + First) / 2; int Current = (Last + First) / 2;
/* Do a compare */ /* Do a compare */
Result = strcmp (CallTable[Current].LongFunc, Name); int Result = strcmp (CallTable[Current].LongFunc, Name);
if (Result < 0) { if (Result < 0) {
First = Current + 1; First = Current + 1;
} else { } else {
@ -178,7 +175,6 @@ static const CallDesc* FindCall (const char* Name)
Found = 1; Found = 1;
} }
} }
} }
/* Return the first entry if found, or NULL otherwise */ /* Return the first entry if found, or NULL otherwise */
@ -210,17 +206,17 @@ unsigned OptSize1 (CodeSeg* S)
I = 0; I = 0;
while (I < CS_GetEntryCount (S)) { while (I < CS_GetEntryCount (S)) {
const CallDesc* D;
/* Get next entry */ /* Get next entry */
E = CS_GetEntry (S, I); E = CS_GetEntry (S, I);
/* Check if it's a subroutine call */ /* Check if it's a subroutine call */
if (E->OPC == OP65_JSR) { if (E->OPC == OP65_JSR && (D = FindCall (E->Arg)) != 0) {
/* Check for any of the known functions. */ /* Check for any of the known functions. */
const CallDesc* D = FindCall (E->Arg); while (1) {
while (D &&
D < CallTable + (sizeof (CallTable) / sizeof (CallTable[0])) &&
strcmp (D->LongFunc, E->Arg) == 0) {
/* Check the registers */ /* Check the registers */
if ((D->A < 0 || D->A == E->RI->In.RegA) && if ((D->A < 0 || D->A == E->RI->In.RegA) &&
(D->X < 0 || D->X == E->RI->In.RegX) && (D->X < 0 || D->X == E->RI->In.RegX) &&
@ -234,7 +230,13 @@ unsigned OptSize1 (CodeSeg* S)
/* Remember that we had changes */ /* Remember that we had changes */
++Changes; ++Changes;
} }
++D;
/* Next table entry, bail out if next entry not valid */
if (++D >= CallTable + CALL_COUNT ||
strcmp (D->LongFunc, E->Arg) != 0) {
/* End of table or entries reached */
break;
}
} }
} }