mirror of
https://github.com/cc65/cc65.git
synced 2024-12-24 11:31:31 +00:00
Fixed a bug in the for loop optimization applied earlier
git-svn-id: svn://svn.cc65.org/cc65/trunk@800 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
6c34eeb93d
commit
c1c402c6ba
@ -62,6 +62,29 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void CS_MoveLabelsToEntry (CodeSeg* S, CodeEntry* E)
|
||||||
|
/* Move all labels from the label pool to the given entry and remove them
|
||||||
|
* from the pool.
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
/* Transfer the labels if we have any */
|
||||||
|
unsigned I;
|
||||||
|
unsigned LabelCount = CollCount (&S->Labels);
|
||||||
|
for (I = 0; I < LabelCount; ++I) {
|
||||||
|
|
||||||
|
/* Get the label */
|
||||||
|
CodeLabel* L = CollAt (&S->Labels, I);
|
||||||
|
|
||||||
|
/* Attach it to the entry */
|
||||||
|
CE_AttachLabel (E, L);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Delete the transfered labels */
|
||||||
|
CollDeleteAll (&S->Labels);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void CS_MoveLabelsToPool (CodeSeg* S, CodeEntry* E)
|
static void CS_MoveLabelsToPool (CodeSeg* S, CodeEntry* E)
|
||||||
/* Move the labels of the code entry E to the label pool of the code segment */
|
/* Move the labels of the code entry E to the label pool of the code segment */
|
||||||
{
|
{
|
||||||
@ -406,19 +429,7 @@ void CS_AddEntry (CodeSeg* S, struct CodeEntry* E)
|
|||||||
/* Add an entry to the given code segment */
|
/* Add an entry to the given code segment */
|
||||||
{
|
{
|
||||||
/* Transfer the labels if we have any */
|
/* Transfer the labels if we have any */
|
||||||
unsigned I;
|
CS_MoveLabelsToEntry (S, E);
|
||||||
unsigned LabelCount = CollCount (&S->Labels);
|
|
||||||
for (I = 0; I < LabelCount; ++I) {
|
|
||||||
|
|
||||||
/* Get the label */
|
|
||||||
CodeLabel* L = CollAt (&S->Labels, I);
|
|
||||||
|
|
||||||
/* Attach it to the entry */
|
|
||||||
CE_AttachLabel (E, L);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Delete the transfered labels */
|
|
||||||
CollDeleteAll (&S->Labels);
|
|
||||||
|
|
||||||
/* Add the entry to the list of code entries in this segment */
|
/* Add the entry to the list of code entries in this segment */
|
||||||
CollAppend (&S->Entries, E);
|
CollAppend (&S->Entries, E);
|
||||||
@ -551,6 +562,30 @@ void CS_DelEntries (CodeSeg* S, unsigned Start, unsigned Count)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void CS_MoveEntries (CodeSeg* S, unsigned Start, unsigned Count, unsigned NewPos)
|
||||||
|
/* Move a range of entries from one position to another. Start is the index
|
||||||
|
* of the first entry to move, Count is the number of entries and NewPos is
|
||||||
|
* the index of the target entry. The entry with the index Start will later
|
||||||
|
* have the index NewPos. All entries with indices NewPos and above are
|
||||||
|
* moved to higher indices. If the code block is moved to the end of the
|
||||||
|
* current code, and if pending labels exist, these labels will get attached
|
||||||
|
* to the first instruction of the moved block (the first one after the
|
||||||
|
* current code end)
|
||||||
|
*/
|
||||||
|
{
|
||||||
|
/* If NewPos is at the end of the code segment, move any labels from the
|
||||||
|
* label pool to the first instruction of the moved range.
|
||||||
|
*/
|
||||||
|
if (NewPos == CS_GetEntryCount (S)) {
|
||||||
|
CS_MoveLabelsToEntry (S, CS_GetEntry (S, Start));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Move the code block to the destination */
|
||||||
|
CollMoveMultiple (&S->Entries, Start, Count, NewPos);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct CodeEntry* CS_GetNextEntry (CodeSeg* S, unsigned Index)
|
struct CodeEntry* CS_GetNextEntry (CodeSeg* S, unsigned Index)
|
||||||
/* Get the code entry following the one with the index Index. If there is no
|
/* Get the code entry following the one with the index Index. If there is no
|
||||||
* following code entry, return NULL.
|
* following code entry, return NULL.
|
||||||
|
@ -116,6 +116,17 @@ void CS_DelEntries (CodeSeg* S, unsigned Start, unsigned Count);
|
|||||||
* labels attached to the entries and so on.
|
* labels attached to the entries and so on.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void CS_MoveEntries (CodeSeg* S, unsigned Start, unsigned Count, unsigned NewPos);
|
||||||
|
/* Move a range of entries from one position to another. Start is the index
|
||||||
|
* of the first entry to move, Count is the number of entries and NewPos is
|
||||||
|
* the index of the target entry. The entry with the index Start will later
|
||||||
|
* have the index NewPos. All entries with indices NewPos and above are
|
||||||
|
* moved to higher indices. If the code block is moved to the end of the
|
||||||
|
* current code, and if pending labels exist, these labels will get attached
|
||||||
|
* to the first instruction of the moved block (the first one after the
|
||||||
|
* current code end)
|
||||||
|
*/
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE void CS_MoveEntry (CodeSeg* S, unsigned OldPos, unsigned NewPos)
|
INLINE void CS_MoveEntry (CodeSeg* S, unsigned OldPos, unsigned NewPos)
|
||||||
/* Move an entry from one position to another. OldPos is the current position
|
/* Move an entry from one position to another. OldPos is the current position
|
||||||
@ -128,21 +139,6 @@ INLINE void CS_MoveEntry (CodeSeg* S, unsigned OldPos, unsigned NewPos)
|
|||||||
# define CS_MoveEntry(S, OldPos, NewPos) CollMove (&(S)->Entries, OldPos, NewPos)
|
# define CS_MoveEntry(S, OldPos, NewPos) CollMove (&(S)->Entries, OldPos, NewPos)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
|
||||||
INLINE void CS_MoveEntries (CodeSeg* S, unsigned Start, unsigned Count, unsigned NewPos)
|
|
||||||
/* Move a range of entries from one position to another. Start is the index
|
|
||||||
* of the first entry to move, Count is the number of entries and NewPos is
|
|
||||||
* the index of the target entry. The entry with the index Start will later
|
|
||||||
* have the index NewPos. All entries with indices NewPos and above are
|
|
||||||
* moved to higher indices.
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
CollMoveMultiple (&S->Entries, Start, Count, NewPos);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
# define CS_MoveEntries(S, Start, Count, NewPos) CollMoveMultiple (&(S)->Entries, Start, Count, NewPos)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(HAVE_INLINE)
|
#if defined(HAVE_INLINE)
|
||||||
INLINE struct CodeEntry* CS_GetEntry (CodeSeg* S, unsigned Index)
|
INLINE struct CodeEntry* CS_GetEntry (CodeSeg* S, unsigned Index)
|
||||||
/* Get an entry from the given code segment */
|
/* Get an entry from the given code segment */
|
||||||
|
Loading…
Reference in New Issue
Block a user