{
unsigned Changes = 0; /* Number of changes in one run */
StackOpData Data;
- unsigned I;
+ int I;
+ int OldEntryCount; /* Old number of entries */
enum {
Initialize,
* 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);
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);
/* 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;
}