X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fcc65%2Fcodelab.c;h=89b45b0e6d4d9a0fb45699aad9460ea584fa11db;hb=eab608616187b988e81e6f513fc405347ea620a7;hp=bc52e5878688cf68cc811ff7a31712f58da8b301;hpb=c71a80b0afd9a035dd0aab156bf1931c6aaef7fa;p=cc65 diff --git a/src/cc65/codelab.c b/src/cc65/codelab.c index bc52e5878..89b45b0e6 100644 --- a/src/cc65/codelab.c +++ b/src/cc65/codelab.c @@ -1,6 +1,6 @@ /*****************************************************************************/ /* */ -/* label.c */ +/* codelab.c */ /* */ /* Code label structure */ /* */ @@ -34,10 +34,12 @@ /* common */ +#include "check.h" #include "xmalloc.h" /* cc65 */ -#include "label.h" +#include "codeent.h" +#include "codelab.h" @@ -82,22 +84,46 @@ void FreeCodeLabel (CodeLabel* L) -unsigned RemoveLabelRef (CodeLabel* L, const struct CodeEntry* E) -/* Remove a reference to this label, return the number of remaining references */ +void AddLabelRef (CodeLabel* L, struct CodeEntry* E) +/* Let the CodeEntry E reference the label L */ { - /* Delete the item */ - CollDeleteItem (&L->JumpFrom, E); + /* The insn at E jumps to this label */ + E->JumpTo = L; - /* Return the number of remaining references */ - return CollCount (&L->JumpFrom); + /* Remember that in the label */ + CollAppend (&L->JumpFrom, E); } -void OutputCodeLabel (FILE* F, const CodeLabel* L) +void MoveLabelRefs (CodeLabel* OldLabel, CodeLabel* NewLabel) +/* Move all references to OldLabel to point to NewLabel. OldLabel will have no + * more references on return. + */ +{ + /* Walk through all instructions referencing the old label */ + unsigned Count = CollCount (&OldLabel->JumpFrom); + while (Count--) { + + /* Get the instruction that references the old label */ + CodeEntry* E = CollAt (&OldLabel->JumpFrom, Count); + + /* Change the reference to the new label */ + CHECK (E->JumpTo == OldLabel); + AddLabelRef (NewLabel, E); + + } + + /* There are no more references to the old label */ + CollDeleteAll (&OldLabel->JumpFrom); +} + + + +void OutputCodeLabel (const CodeLabel* L, FILE* F) /* Output the code label to a file */ { - fprintf (F, "%s:\n", L->Name); + fprintf (F, "%s:", L->Name); }