Refactor: rearrange Opt_a_tosbitwise() code to follow the common if-else if-else pattern form used by other subopts.

This commit is contained in:
Alex Volkov
2026-03-10 20:47:39 -04:00
parent bf5d8c44e4
commit 82d672e904

View File

@@ -1204,35 +1204,33 @@ static unsigned Opt_a_tosbitwise (StackOpData* D, opc_t OPC)
/* Inline the bitwise operation */ /* Inline the bitwise operation */
D->IP = D->OpIndex+1; D->IP = D->OpIndex+1;
/* Backup lhs if necessary */ if ((D->Rhs.A.Flags & LI_DIRECT) != 0) {
/* ### Note: This should be rearranged into a common form used in others:
** if (Rhs) { } else if (Lhs) { } else { ZP }.
*/
if ((D->Rhs.A.Flags & LI_DIRECT) == 0) {
if ((D->Lhs.A.Flags & (LI_DIRECT | LI_RELOAD_Y)) == LI_DIRECT) {
/* Just reload lhs */
X = NewCodeEntry (OPC, D->Lhs.A.LoadEntry->AM, D->Lhs.A.LoadEntry->Arg, 0, D->OpEntry->LI);
InsertEntry (D, X, D->IP++);
} else {
/* Implement the op via a temp ZP location */
/* HaveUnusedTempZPLoc precondition must have been met */
ChooseTempZPLoc (D);
/* Backup lhs */ /* Add code for low operand using direct Rhs */
X = NewCodeEntry (OP65_STA, AM65_ZP, D->ZPLo, 0, D->PushEntry->LI);
InsertEntry (D, X, D->PushIndex+1);
/* Add code for low operand */
X = NewCodeEntry (OPC, AM65_ZP, D->ZPLo, 0, D->OpEntry->LI);
InsertEntry (D, X, D->IP++);
}
} else {
/* Add code for low operand */
X = NewCodeEntry (OPC, D->Rhs.A.LoadEntry->AM, D->Rhs.A.LoadEntry->Arg, 0, D->OpEntry->LI); X = NewCodeEntry (OPC, D->Rhs.A.LoadEntry->AM, D->Rhs.A.LoadEntry->Arg, 0, D->OpEntry->LI);
InsertEntry (D, X, D->IP++); InsertEntry (D, X, D->IP++);
/* Rhs load entries may be removed */ /* Rhs load entries must be removed */
D->Rhs.A.Flags |= LI_REMOVE; D->Rhs.A.Flags |= LI_REMOVE;
} else if ((D->Lhs.A.Flags & (LI_DIRECT | LI_RELOAD_Y)) == LI_DIRECT) {
/* Add code for low operand using direct Lhs */
X = NewCodeEntry (OPC, D->Lhs.A.LoadEntry->AM, D->Lhs.A.LoadEntry->Arg, 0, D->OpEntry->LI);
InsertEntry (D, X, D->IP++);
} else {
/* Implement the op via a temp ZP location */
/* HaveUnusedTempZPLoc precondition must have been met */
ChooseTempZPLoc (D);
/* Backup lhs */
X = NewCodeEntry (OP65_STA, AM65_ZP, D->ZPLo, 0, D->PushEntry->LI);
InsertEntry (D, X, D->PushIndex+1);
/* Add code for low operand */
X = NewCodeEntry (OPC, AM65_ZP, D->ZPLo, 0, D->OpEntry->LI);
InsertEntry (D, X, D->IP++);
} }
/* ### Bug to come: there are dangerous Rhs X removal attempts here. /* ### Bug to come: there are dangerous Rhs X removal attempts here.