]> git.sur5r.net Git - cc65/blobdiff - src/cc65/codelab.c
In case of parse errors for structs, don't just set the type of the result to
[cc65] / src / cc65 / codelab.c
index 46c43559a565fff8531d8910d211cfd77c9cba28..9e3b93765f64ebf69b57dd13a45433e4d7b1ec6d 100644 (file)
@@ -1,15 +1,15 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                 label.c                                  */
+/*                                codelab.c                                 */
 /*                                                                           */
 /*                          Code label structure                            */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2001     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
+/* (C) 2001-2009, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 
 
 /* common */
+#include "check.h"
 #include "xmalloc.h"
 
 /* cc65 */
-#include "label.h"
+#include "codeent.h"
+#include "codelab.h"
+#include "output.h"
 
 
 
@@ -57,7 +60,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);
 
@@ -82,11 +84,55 @@ void FreeCodeLabel (CodeLabel* L)
 
 
 
-void OutputCodeLabel (FILE* F, const CodeLabel* L)
-/* Output the code label to a file */
+void CL_AddRef (CodeLabel* L, struct CodeEntry* E)
+/* Let the CodeEntry E reference the label L */
 {
-    fprintf (F, "%s:\n", L->Name);
+    /* The insn at E jumps to this label */
+    E->JumpTo = L;
+
+    /* Replace the code entry argument with the name of the new label */
+    CE_SetArg (E, L->Name);
+
+    /* Remember that in the label */
+    CollAppend (&L->JumpFrom, E);
 }
 
 
 
+void CL_MoveRefs (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 = CL_GetRefCount (OldLabel);
+    while (Count--) {
+
+       /* 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 CL_Output (const CodeLabel* L)
+/* Output the code label to the output file */
+{
+    WriteOutput ("%s:", L->Name);
+    if (strlen (L->Name) > 6) {
+       /* Label is too long, add a linefeed */
+       WriteOutput ("\n");
+    }
+}
+
+
+
+