From 0a8ca3041a80768590af5e18f5a6b7763c685cb4 Mon Sep 17 00:00:00 2001 From: acqn Date: Sat, 13 Mar 2021 14:31:23 +0800 Subject: [PATCH] Changd all Find*Last*InOpenRange() to return the beginning of the open range. Fixed FindArgLastUsageInOpenRange(). --- src/cc65/codeoptutil.c | 16 ++++++++-------- src/cc65/codeoptutil.h | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/cc65/codeoptutil.c b/src/cc65/codeoptutil.c index 36232bf3a..23c759fd1 100644 --- a/src/cc65/codeoptutil.c +++ b/src/cc65/codeoptutil.c @@ -3038,13 +3038,13 @@ int FindArgLastUsageInOpenRange (CodeSeg* S, int First, int Last, CodeEntry* E, /* Find the last index where the arg of E might be used or changed in the range (First, Last). ** ReloadY indicates whether Y is supposed to be reloaded. ** The code block in the range must be basic without any jump backwards. -** Return the index of the found entry, or -1 if not found. +** Return the index of the found entry, or First if not found. */ { LoadRegInfo LRI; CodeEntry* X; unsigned CheckedFlags = LI_SRC_USE | LI_SRC_CHG; - int Found = -1; + int Found = First; CHECK (Last <= (int)CollCount (&S->Entries)); @@ -3066,8 +3066,8 @@ int FindArgLastUsageInOpenRange (CodeSeg* S, int First, int Last, CodeEntry* E, /* TODO: We don't currently check for all cases */ if ((LRI.Flags & (LI_DIRECT | LI_CHECK_ARG | LI_CHECK_Y | LI_RELOAD_Y)) == 0) { - /* Just bail out as if the src would change right away */ - return 0; + /* Just bail out as if the src would change everywhere */ + return First < Last ? Last - 1 : First; } if ((LRI.Flags & LI_CHECK_Y) != 0) { @@ -3145,11 +3145,11 @@ int FindRegLastChangeInOpenRange (CodeSeg* S, int First, int Last, unsigned what /* Find the last possible spot where the queried ZPs, registers and/or processor ** states might be changed in the range (First, Last). The code block in the ** range must be basic without any jump backwards. -** Return the index of the found entry, or -1 if not found. +** Return the index of the found entry, or First if not found. */ { CodeEntry* X; - int Found = -1; + int Found = First; CHECK (Last <= (int)CollCount (&S->Entries)); @@ -3169,11 +3169,11 @@ int FindRegLastUseInOpenRange (CodeSeg* S, int First, int Last, unsigned what) /* Find the last possible spot where the queried ZPs, registers and/or processor ** states might be used in the range (First, Last). The code block in the range ** must be basic without any jump backwards. -** Return the index of the found entry, or -1 if not found. +** Return the index of the found entry, or First if not found. */ { CodeEntry* X; - int Found = -1; + int Found = First; CHECK (Last <= (int)CollCount (&S->Entries)); diff --git a/src/cc65/codeoptutil.h b/src/cc65/codeoptutil.h index c3596acd4..70aa5f462 100644 --- a/src/cc65/codeoptutil.h +++ b/src/cc65/codeoptutil.h @@ -433,7 +433,7 @@ int FindArgLastUsageInOpenRange (CodeSeg* S, int First, int Last, CodeEntry* E, /* Find the last index where the arg of E might be used or changed in the range (First, Last). ** ReloadY indicates whether Y is supposed to be reloaded. ** The code block in the range must be basic without any jump backwards. -** Return the index of the found entry, or -1 if not found. +** Return the index of the found entry, or First if not found. */ int FindRegFirstChangeInOpenRange (CodeSeg* S, int First, int Last, unsigned what); @@ -454,14 +454,14 @@ int FindRegLastChangeInOpenRange (CodeSeg* S, int First, int Last, unsigned what /* Find the last possible spot where the queried ZPs, registers and/or processor ** states might be changed in the range (First, Last). The code block in the ** range must be basic without any jump backwards. -** Return the index of the found entry, or -1 if not found. +** Return the index of the found entry, or First if not found. */ int FindRegLastUseInOpenRange (CodeSeg* S, int First, int Last, unsigned what); /* Find the last possible spot where the queried ZPs, registers and/or processor ** states might be used in the range (First, Last). The code block in the range ** must be basic without any jump backwards. -** Return the index of the found entry, or -1 if not found. +** Return the index of the found entry, or First if not found. */ /* End of codeoptutil.h */