Coding style

This commit is contained in:
Colin Leroy-Mira
2025-07-20 16:06:34 +02:00
parent a0b705fd41
commit 1f6cca2140
3 changed files with 16 additions and 20 deletions

View File

@@ -244,6 +244,12 @@ static inline int CE_IsCallTo (const CodeEntry* E, const char* Name)
return (E->OPC == OP65_JSR && strcmp (E->Arg, Name) == 0); return (E->OPC == OP65_JSR && strcmp (E->Arg, Name) == 0);
} }
static inline int CE_IsJumpTo (const CodeEntry* E, const char* Name)
/* Check if this is a jump to the given function */
{
return (E->OPC == OP65_JMP && strcmp (E->Arg, Name) == 0);
}
int CE_UseLoadFlags (CodeEntry* E); int CE_UseLoadFlags (CodeEntry* E);
/* Return true if the instruction uses any flags that are set by a load of /* Return true if the instruction uses any flags that are set by a load of
** a register (N and Z). ** a register (N and Z).

View File

@@ -486,14 +486,14 @@ static unsigned OptIncDecOps (CodeSeg* S, const char* dec, const char* inc, cons
unsigned OptStackPtrOps (CodeSeg* S) unsigned OptStackPtrOps (CodeSeg* S)
{ {
return OptIncDecOps(S, "decsp", "incsp", "subysp", "addysp"); return OptIncDecOps (S, "decsp", "incsp", "subysp", "addysp");
} }
unsigned OptAXOps (CodeSeg* S) unsigned OptAXOps (CodeSeg* S)
{ {
return OptIncDecOps(S, "decax", "incax", "decaxy", "incaxy"); return OptIncDecOps (S, "decax", "incax", "decaxy", "incaxy");
} }
@@ -573,11 +573,9 @@ unsigned OptTosLoadPop (CodeSeg* S)
const CodeEntry* E = CS_GetEntry (S, I); const CodeEntry* E = CS_GetEntry (S, I);
/* Check for the sequence */ /* Check for the sequence */
if (E->OPC == OP65_JSR && if (CE_IsCallTo (E, "ldax0sp") &&
strncmp (E->Arg, "ldax0sp", 5) == 0 && (N = CS_GetNextEntry (S, I)) != 0 &&
(N = CS_GetNextEntry (S, I)) != 0 && (CE_IsCallTo (N, "incsp2") || CE_IsJumpTo (N, "incsp2")) &&
(N->OPC == OP65_JSR || N->OPC == OP65_JMP) &&
strcmp (N->Arg, "incsp2") == 0 &&
!CE_HasLabel (N)) { !CE_HasLabel (N)) {
CodeEntry* X; CodeEntry* X;
@@ -588,9 +586,6 @@ unsigned OptTosLoadPop (CodeSeg* S)
/* Delete the old code */ /* Delete the old code */
CS_DelEntries (S, I, 2); CS_DelEntries (S, I, 2);
/* Regenerate register info */
CS_GenRegInfo (S);
/* Remember we had changes */ /* Remember we had changes */
++Changes; ++Changes;
@@ -1203,7 +1198,7 @@ unsigned OptBinOps2 (CodeSeg* S)
} }
unsigned OptTosPushPop(CodeSeg *S) unsigned OptTosPushPop (CodeSeg* S)
/* Merge jsr pushax/j?? popax */ /* Merge jsr pushax/j?? popax */
{ {
unsigned Changes = 0; unsigned Changes = 0;
@@ -1219,11 +1214,9 @@ unsigned OptTosPushPop(CodeSeg *S)
const CodeEntry* E = CS_GetEntry (S, I); const CodeEntry* E = CS_GetEntry (S, I);
/* Check for decspn, incspn, subysp or addysp */ /* Check for decspn, incspn, subysp or addysp */
if (E->OPC == OP65_JSR && if (CE_IsCallTo (E, "pushax") &&
strcmp(E->Arg, "pushax") == 0 && (N = CS_GetNextEntry (S, I)) != 0 &&
(N = CS_GetNextEntry (S, I)) != 0 && (CE_IsCallTo (N, "popax") || CE_IsJumpTo (N, "popax")) &&
(N->OPC == OP65_JSR || N->OPC == OP65_JMP) &&
strcmp(N->Arg, "popax") == 0 &&
!CE_HasLabel (N)) { !CE_HasLabel (N)) {
/* Insert an rts if jmp popax */ /* Insert an rts if jmp popax */
@@ -1235,9 +1228,6 @@ unsigned OptTosPushPop(CodeSeg *S)
/* Delete the old code */ /* Delete the old code */
CS_DelEntries (S, I+1, 2); CS_DelEntries (S, I+1, 2);
/* Regenerate register info */
CS_GenRegInfo (S);
/* Remember we had changes */ /* Remember we had changes */
++Changes; ++Changes;

View File

@@ -134,7 +134,7 @@ unsigned OptBinOps2 (CodeSeg* S);
unsigned OptTosLoadPop (CodeSeg* S); unsigned OptTosLoadPop (CodeSeg* S);
/* Merge jsr ldax0sp / jsr|jmp incsp2 into jsr|jmp popax */ /* Merge jsr ldax0sp / jsr|jmp incsp2 into jsr|jmp popax */
unsigned OptTosPushPop(CodeSeg *S); unsigned OptTosPushPop (CodeSeg* S);
/* Merge jsr pushax/j?? popax */ /* Merge jsr pushax/j?? popax */
/* End of coptmisc.h */ /* End of coptmisc.h */