]> git.sur5r.net Git - cc65/blob - src/cc65/codelab.c
237e50a326113a3984ef74636fa56fc0878eba28
[cc65] / src / cc65 / codelab.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 codelab.c                                 */
4 /*                                                                           */
5 /*                           Code label structure                            */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001     Ullrich von Bassewitz                                        */
10 /*              Wacholderweg 14                                              */
11 /*              D-70597 Stuttgart                                            */
12 /* EMail:       uz@musoftware.de                                             */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 /* common */
37 #include "xmalloc.h"
38
39 /* cc65 */
40 #include "codeent.h"
41 #include "codelab.h"
42
43
44
45 /*****************************************************************************/
46 /*                                   Code                                    */
47 /*****************************************************************************/
48
49
50
51 CodeLabel* NewCodeLabel (const char* Name, unsigned Hash)
52 /* Create a new code label, initialize and return it */
53 {
54     /* Allocate memory */
55     CodeLabel* L = xmalloc (sizeof (CodeLabel));
56
57     /* Initialize the fields */
58     L->Next  = 0;
59     L->Name  = xstrdup (Name);
60     L->Hash  = Hash;
61     L->Flags = 0;
62     L->Owner = 0;
63     InitCollection (&L->JumpFrom);
64
65     /* Return the new label */
66     return L;
67 }
68
69
70
71 void FreeCodeLabel (CodeLabel* L)
72 /* Free the given code label */
73 {
74     /* Free the name */
75     xfree (L->Name);
76
77     /* Free the collection */
78     DoneCollection (&L->JumpFrom);
79
80     /* Delete the struct */
81     xfree (L);
82 }
83
84
85
86 void AddLabelRef (CodeLabel* L, struct CodeEntry* E)
87 /* Let the CodeEntry E reference the label L */
88 {
89     /* The insn at E jumps to this label */
90     E->JumpTo = L;
91
92     /* Remember that in the label */
93     CollAppend (&L->JumpFrom, E);
94 }
95
96
97
98 unsigned RemoveLabelRef (CodeLabel* L, const struct CodeEntry* E)
99 /* Remove a reference to this label, return the number of remaining references */
100 {
101     /* Delete the item */
102     CollDeleteItem (&L->JumpFrom, E);
103
104     /* Return the number of remaining references */
105     return CollCount (&L->JumpFrom);
106 }
107
108
109
110 void OutputCodeLabel (const CodeLabel* L, FILE* F)
111 /* Output the code label to a file */
112 {
113     fprintf (F, "%s:", L->Name);
114 }
115
116
117