1
0
mirror of https://github.com/cc65/cc65.git synced 2024-09-27 04:54:54 +00:00

Change the OptStackOps function so that it adjusts the instruction pointer

after changing code. Without this correction, the insn pointer may be wrong
after one of the subfunctions has changed code, which may cause a valid
sequence not to be detected. This change (when proven good) may also go into
2.13.


git-svn-id: svn://svn.cc65.org/cc65/trunk@4649 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2010-04-25 21:51:59 +00:00
parent c63ecc8c28
commit 77bfcc1ff0

View File

@ -1724,7 +1724,8 @@ unsigned OptStackOps (CodeSeg* S)
{
unsigned Changes = 0; /* Number of changes in one run */
StackOpData Data;
unsigned I;
int I;
int OldEntryCount; /* Old number of entries */
enum {
Initialize,
@ -1756,7 +1757,7 @@ unsigned OptStackOps (CodeSeg* S)
* intermediate code for zero page use.
*/
I = 0;
while (I < CS_GetEntryCount (S)) {
while (I < (int)CS_GetEntryCount (S)) {
/* Get the next entry */
CodeEntry* E = CS_GetEntry (S, I);
@ -1890,6 +1891,9 @@ unsigned OptStackOps (CodeSeg* S)
Data.OpEntry = CS_GetEntry (S, Data.OpIndex);
Data.NextEntry = CS_GetNextEntry (S, Data.OpIndex);
/* Remember the current number of code lines */
OldEntryCount = CS_GetEntryCount (S);
/* Adjust stack offsets to account for the upcoming removal */
AdjustStackOffset (&Data, 2);
@ -1901,12 +1905,17 @@ unsigned OptStackOps (CodeSeg* S)
/* Call the optimizer function */
Changes += Data.OptFunc->Func (&Data);
/* Since the function may have added or deleted entries,
* correct the index.
*/
I += CS_GetEntryCount (S) - OldEntryCount;
/* Regenerate register info */
CS_GenRegInfo (S);
/* Done */
State = Initialize;
break;
continue;
}