/*****************************************************************************/
/* */
-/* label.c */
+/* codelab.c */
/* */
/* Code label structure */
/* */
/* common */
+#include "check.h"
#include "xmalloc.h"
/* cc65 */
-#include "label.h"
+#include "codeent.h"
+#include "codelab.h"
L->Next = 0;
L->Name = xstrdup (Name);
L->Hash = Hash;
+ L->Flags = 0;
L->Owner = 0;
InitCollection (&L->JumpFrom);
-void OutputCodeLabel (FILE* F, const CodeLabel* L)
+void AddLabelRef (CodeLabel* L, struct CodeEntry* E)
+/* Let the CodeEntry E reference the label L */
+{
+ /* The insn at E jumps to this label */
+ E->JumpTo = L;
+
+ /* Remember that in the label */
+ CollAppend (&L->JumpFrom, E);
+}
+
+
+
+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);
}