Fixed a bug
git-svn-id: svn://svn.cc65.org/cc65/trunk@2523 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -6,9 +6,9 @@
|
|||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
/* (C) 2001-2002 Ullrich von Bassewitz */
|
/* (C) 2001-2003 Ullrich von Bassewitz */
|
||||||
/* Wacholderweg 14 */
|
/* R<EFBFBD>merstrasse 52 */
|
||||||
/* D-70597 Stuttgart */
|
/* D-70794 Filderstadt */
|
||||||
/* EMail: uz@cc65.org */
|
/* EMail: uz@cc65.org */
|
||||||
/* */
|
/* */
|
||||||
/* */
|
/* */
|
||||||
@@ -72,13 +72,13 @@ struct StackOpData {
|
|||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Helpers */
|
/* Helpers */
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static unsigned AdjustStackOffset (CodeSeg* S, unsigned Start, unsigned Stop,
|
static unsigned AdjustStackOffset (CodeSeg* S, unsigned Start, unsigned Stop,
|
||||||
unsigned Offs)
|
unsigned Offs)
|
||||||
/* Adjust the offset for all stack accesses in the range Start to Stop, both
|
/* Adjust the offset for all stack accesses in the range Start to Stop, both
|
||||||
* inclusive. The function returns the number of instructions that have been
|
* inclusive. The function returns the number of instructions that have been
|
||||||
* inserted.
|
* inserted.
|
||||||
@@ -114,31 +114,50 @@ static unsigned AdjustStackOffset (CodeSeg* S, unsigned Start, unsigned Stop,
|
|||||||
|
|
||||||
CodeEntry* P;
|
CodeEntry* P;
|
||||||
|
|
||||||
|
/* If the Y register value is needed later, we have to reload the
|
||||||
|
* register after changing it.
|
||||||
|
*/
|
||||||
|
int NeedY = RegYUsed (S, I+1);
|
||||||
|
unsigned YVal = E->RI->In.RegY;
|
||||||
|
|
||||||
/* Get the code entry before this one. If it's a LDY, adjust the
|
/* Get the code entry before this one. If it's a LDY, adjust the
|
||||||
* value.
|
* value.
|
||||||
*/
|
*/
|
||||||
P = CS_GetPrevEntry (S, I);
|
P = CS_GetPrevEntry (S, I);
|
||||||
if (P && P->OPC == OP65_LDY && CE_KnownImm (P)) {
|
if (P && P->OPC == OP65_LDY && CE_KnownImm (P)) {
|
||||||
|
|
||||||
/* The Y load is just before the stack access, adjust it */
|
/* The Y load is just before the stack access, adjust it */
|
||||||
CE_SetNumArg (P, P->Num - Offs);
|
CE_SetNumArg (P, P->Num - Offs);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* Insert a new load instruction before the stack access */
|
/* Insert a new load instruction before the stack access */
|
||||||
const char* Arg = MakeHexArg (E->RI->In.RegY - Offs);
|
const char* Arg = MakeHexArg (YVal - Offs);
|
||||||
CodeEntry* X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, E->LI);
|
CodeEntry* X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, E->LI);
|
||||||
CS_InsertEntry (S, X, I);
|
CS_InsertEntry (S, X, I);
|
||||||
|
|
||||||
/* One more inserted entries */
|
/* One more inserted entries */
|
||||||
++Inserted;
|
++Inserted;
|
||||||
++Stop;
|
++Stop;
|
||||||
|
|
||||||
/* Be sure to skip the stack access for the next round */
|
/* Be sure to skip the stack access for the next round */
|
||||||
++I;
|
++I;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If we need the value of Y later, be sure to reload it */
|
||||||
|
if (NeedY) {
|
||||||
|
const char* Arg = MakeHexArg (YVal);
|
||||||
|
CodeEntry* X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, E->LI);
|
||||||
|
CS_InsertEntry (S, X, I+1);
|
||||||
|
|
||||||
|
/* One more inserted entries */
|
||||||
|
++Inserted;
|
||||||
|
++Stop;
|
||||||
|
|
||||||
|
/* Skip this instruction int the next round */
|
||||||
|
++I;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Next entry */
|
/* Next entry */
|
||||||
|
|||||||
Reference in New Issue
Block a user