From 1f6cca2140eb3005e502a8bc38d083b27b8422f7 Mon Sep 17 00:00:00 2001 From: Colin Leroy-Mira Date: Sun, 20 Jul 2025 16:06:34 +0200 Subject: [PATCH] Coding style --- src/cc65/codeent.h | 6 ++++++ src/cc65/coptmisc.c | 28 +++++++++------------------- src/cc65/coptmisc.h | 2 +- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/cc65/codeent.h b/src/cc65/codeent.h index 3b2c1aa2d..b1b6f3365 100644 --- a/src/cc65/codeent.h +++ b/src/cc65/codeent.h @@ -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); } +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); /* Return true if the instruction uses any flags that are set by a load of ** a register (N and Z). diff --git a/src/cc65/coptmisc.c b/src/cc65/coptmisc.c index e21234cd1..deca3fbe5 100644 --- a/src/cc65/coptmisc.c +++ b/src/cc65/coptmisc.c @@ -486,14 +486,14 @@ static unsigned OptIncDecOps (CodeSeg* S, const char* dec, const char* inc, cons unsigned OptStackPtrOps (CodeSeg* S) { - return OptIncDecOps(S, "decsp", "incsp", "subysp", "addysp"); + return OptIncDecOps (S, "decsp", "incsp", "subysp", "addysp"); } 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); /* Check for the sequence */ - if (E->OPC == OP65_JSR && - strncmp (E->Arg, "ldax0sp", 5) == 0 && - (N = CS_GetNextEntry (S, I)) != 0 && - (N->OPC == OP65_JSR || N->OPC == OP65_JMP) && - strcmp (N->Arg, "incsp2") == 0 && + if (CE_IsCallTo (E, "ldax0sp") && + (N = CS_GetNextEntry (S, I)) != 0 && + (CE_IsCallTo (N, "incsp2") || CE_IsJumpTo (N, "incsp2")) && !CE_HasLabel (N)) { CodeEntry* X; @@ -588,9 +586,6 @@ unsigned OptTosLoadPop (CodeSeg* S) /* Delete the old code */ CS_DelEntries (S, I, 2); - /* Regenerate register info */ - CS_GenRegInfo (S); - /* Remember we had changes */ ++Changes; @@ -1203,7 +1198,7 @@ unsigned OptBinOps2 (CodeSeg* S) } -unsigned OptTosPushPop(CodeSeg *S) +unsigned OptTosPushPop (CodeSeg* S) /* Merge jsr pushax/j?? popax */ { unsigned Changes = 0; @@ -1219,11 +1214,9 @@ unsigned OptTosPushPop(CodeSeg *S) const CodeEntry* E = CS_GetEntry (S, I); /* Check for decspn, incspn, subysp or addysp */ - if (E->OPC == OP65_JSR && - strcmp(E->Arg, "pushax") == 0 && - (N = CS_GetNextEntry (S, I)) != 0 && - (N->OPC == OP65_JSR || N->OPC == OP65_JMP) && - strcmp(N->Arg, "popax") == 0 && + if (CE_IsCallTo (E, "pushax") && + (N = CS_GetNextEntry (S, I)) != 0 && + (CE_IsCallTo (N, "popax") || CE_IsJumpTo (N, "popax")) && !CE_HasLabel (N)) { /* Insert an rts if jmp popax */ @@ -1235,9 +1228,6 @@ unsigned OptTosPushPop(CodeSeg *S) /* Delete the old code */ CS_DelEntries (S, I+1, 2); - /* Regenerate register info */ - CS_GenRegInfo (S); - /* Remember we had changes */ ++Changes; diff --git a/src/cc65/coptmisc.h b/src/cc65/coptmisc.h index 64c310d20..7297fb5a0 100644 --- a/src/cc65/coptmisc.h +++ b/src/cc65/coptmisc.h @@ -134,7 +134,7 @@ unsigned OptBinOps2 (CodeSeg* S); unsigned OptTosLoadPop (CodeSeg* S); /* Merge jsr ldax0sp / jsr|jmp incsp2 into jsr|jmp popax */ -unsigned OptTosPushPop(CodeSeg *S); +unsigned OptTosPushPop (CodeSeg* S); /* Merge jsr pushax/j?? popax */ /* End of coptmisc.h */