-static void InsertEntry (StackOpData* D, CodeEntry* E, int Index)
-/* Insert a new entry. Depending on Index, D->PushIndex and D->OpIndex will
- * be adjusted by this function.
- */
-{
- /* Insert the entry into the code segment */
- CS_InsertEntry (D->Code, E, Index);
-
- /* Adjust register loads if necessary */
- AdjustLoadInfo (&D->Lhs, Index, 1);
- AdjustLoadInfo (&D->Rhs, Index, 1);
-
- /* Adjust the indices if necessary */
- if (D->PushEntry && Index <= D->PushIndex) {
- ++D->PushIndex;
- }
- if (D->OpEntry && Index <= D->OpIndex) {
- ++D->OpIndex;
- }
-}
-
-
-
-static void DelEntry (StackOpData* D, int Index)
-/* Delete an entry. Depending on Index, D->PushIndex and D->OpIndex will be
- * adjusted by this function, and PushEntry/OpEntry may get invalidated.
- */
-{
- /* Delete the entry from the code segment */
- CS_DelEntry (D->Code, Index);
-
- /* Adjust register loads if necessary */
- AdjustLoadInfo (&D->Lhs, Index, -1);
- AdjustLoadInfo (&D->Rhs, Index, -1);
-
- /* Adjust the other indices if necessary */
- if (Index < D->PushIndex) {
- --D->PushIndex;
- } else if (Index == D->PushIndex) {
- D->PushEntry = 0;
- }
- if (Index < D->OpIndex) {
- --D->OpIndex;
- } else if (Index == D->OpIndex) {
- D->OpEntry = 0;
- }
-}
-
-
-
-static void CheckOneDirectOp (LoadRegInfo* LI, unsigned char Offs)
-/* Check if the given entry is a lda instruction with an addressing mode
- * that allows us to replace it by another operation (like ora). If so, we may
- * use this location for the or and must not save the value in the zero
- * page location.
- */
-{
- /* Get the load entry */
- CodeEntry* E = LI->LoadEntry;
- if (E == 0) {
- /* No load insn */
- return;
- }
-
- /* Check the load entry */
- if (E) {
- /* Must check the call first since addressing mode is ABS, so second
- * "if" will catch otherwise.
- */
- if (CE_IsCallTo (E, "ldaxysp")) {
- /* Same as single loads from stack. Since we must distinguish
- * between A and X here, the necessary offset is passed to the
- * function as a parameter.
- */
- LI->Offs = (unsigned char) E->RI->In.RegY - Offs;
- LI->Flags |= (LI_DIRECT | LI_RELOAD_Y);
- } else if (E->AM == AM65_IMM || E->AM == AM65_ZP || E->AM == AM65_ABS) {
- /* These insns are all ok and replaceable */
- LI->Flags |= LI_DIRECT;
- } else if (E->AM == AM65_ZP_INDY &&
- RegValIsKnown (E->RI->In.RegY) &&
- strcmp (E->Arg, "sp") == 0) {
- /* A load from the stack with known offset is also ok, but in this
- * case we must reload the index register later. Please note that
- * a load indirect via other zero page locations is not ok, since
- * these locations may change between the push and the actual
- * operation.
- */
- LI->Offs = (unsigned char) E->RI->In.RegY;
- LI->Flags |= (LI_DIRECT | LI_RELOAD_Y);
- }
- }
-}
-
-
-
-static void CheckDirectOp (StackOpData* D)
-/* Check if the given entry is a lda instruction with an addressing mode
- * that allows us to replace it by another operation (like ora). If so, we may
- * use this location for the or and must not save the value in the zero
- * page location.
- */
-{
- /* Check flags for all load instructions */
- CheckOneDirectOp (&D->Lhs.A, 1);
- CheckOneDirectOp (&D->Lhs.X, 0);
- CheckOneDirectOp (&D->Rhs.A, 1);
- CheckOneDirectOp (&D->Rhs.X, 0);
-}
-
-
-