]> git.sur5r.net Git - cc65/blobdiff - src/cc65/codelab.c
Fixed a bug in signed int compares
[cc65] / src / cc65 / codelab.c
index e02fd794638afddf257cbd4d4e2b9ef4dfa949e5..f4c14ea752ed038bbfaab45b67f6ab8f91803ae6 100644 (file)
@@ -1,6 +1,6 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                 label.c                                  */
+/*                                codelab.c                                 */
 /*                                                                           */
 /*                          Code label structure                            */
 /*                                                                           */
 
 
 /* common */
+#include "check.h"
 #include "xmalloc.h"
 
-/* b6502 */
-#include "codeent.h"    
-#include "label.h"
+/* cc65 */
+#include "codeent.h"
+#include "codelab.h"
 
 
 
@@ -58,7 +59,6 @@ CodeLabel* NewCodeLabel (const char* Name, unsigned Hash)
     L->Next  = 0;
     L->Name  = xstrdup (Name);
     L->Hash  = Hash;
-    L->Flags = 0;
     L->Owner = 0;
     InitCollection (&L->JumpFrom);
 
@@ -83,7 +83,7 @@ void FreeCodeLabel (CodeLabel* L)
 
 
 
-void AddLabelRef (CodeLabel* L, struct CodeEntry* E)
+void CL_AddRef (CodeLabel* L, struct CodeEntry* E)
 /* Let the CodeEntry E reference the label L */
 {
     /* The insn at E jumps to this label */
@@ -95,23 +95,40 @@ 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 CL_MoveRefs (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 = CL_GetRefCount (OldLabel);
+    while (Count--) {
 
-    /* Return the number of remaining references */
-    return CollCount (&L->JumpFrom);
+       /* Get the instruction that references the old label */
+       CodeEntry* E = CL_GetRef (OldLabel, Count);
+
+       /* Change the reference to the new label */
+       CHECK (E->JumpTo == OldLabel);
+       CL_AddRef (NewLabel, E);
+
+    }
+
+    /* There are no more references to the old label */
+    CollDeleteAll (&OldLabel->JumpFrom);
 }
 
 
 
-void OutputCodeLabel (FILE* F, const CodeLabel* L)
+void CL_Output (const CodeLabel* L, FILE* F)
 /* Output the code label to a file */
 {
     fprintf (F, "%s:", L->Name);
+    if (strlen (L->Name) > 6) {
+       /* Label is too long, add a linefeed */
+       fputc ('\n', F);
+    }
 }
 
 
 
+