]> git.sur5r.net Git - cc65/blobdiff - src/cc65/codelab.c
Cosmetic changes
[cc65] / src / cc65 / codelab.c
index 55069c3f96e9cab1670df2ae1ad8243042e63ce1..89b45b0e6d4d9a0fb45699aad9460ea584fa11db 100644 (file)
 
 
 /* common */
+#include "check.h"
 #include "xmalloc.h"
 
-/* cc65 */      
+/* cc65 */
 #include "codeent.h"
 #include "codelab.h"
 
@@ -95,19 +96,31 @@ void AddLabelRef (CodeLabel* L, struct CodeEntry* E)
 
 
 
-unsigned RemoveLabelRef (CodeLabel* L, const struct CodeEntry* E)
-/* Remove a reference to this label, return the number of remaining references */
+void MoveLabelRefs (CodeLabel* OldLabel, CodeLabel* NewLabel)
+/* Move all references to OldLabel to point to NewLabel. OldLabel will have no
+ * more references on return.
+ */
 {
-    /* Delete the item */
-    CollDeleteItem (&L->JumpFrom, E);
+    /* Walk through all instructions referencing the old label */
+    unsigned Count = CollCount (&OldLabel->JumpFrom);
+    while (Count--) {
 
-    /* Return the number of remaining references */
-    return CollCount (&L->JumpFrom);
+       /* 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 (FILE* F, const CodeLabel* L)
+void OutputCodeLabel (const CodeLabel* L, FILE* F)
 /* Output the code label to a file */
 {
     fprintf (F, "%s:", L->Name);