]> git.sur5r.net Git - cc65/blob - src/cc65/codelab.c
bc52e5878688cf68cc811ff7a31712f58da8b301
[cc65] / src / cc65 / codelab.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  label.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 "label.h"
41
42
43
44 /*****************************************************************************/
45 /*                                   Code                                    */
46 /*****************************************************************************/
47
48
49
50 CodeLabel* NewCodeLabel (const char* Name, unsigned Hash)
51 /* Create a new code label, initialize and return it */
52 {
53     /* Allocate memory */
54     CodeLabel* L = xmalloc (sizeof (CodeLabel));
55
56     /* Initialize the fields */
57     L->Next  = 0;
58     L->Name  = xstrdup (Name);
59     L->Hash  = Hash;
60     L->Flags = 0;
61     L->Owner = 0;
62     InitCollection (&L->JumpFrom);
63
64     /* Return the new label */
65     return L;
66 }
67
68
69
70 void FreeCodeLabel (CodeLabel* L)
71 /* Free the given code label */
72 {
73     /* Free the name */
74     xfree (L->Name);
75
76     /* Free the collection */
77     DoneCollection (&L->JumpFrom);
78
79     /* Delete the struct */
80     xfree (L);
81 }
82
83
84
85 unsigned RemoveLabelRef (CodeLabel* L, const struct CodeEntry* E)
86 /* Remove a reference to this label, return the number of remaining references */
87 {
88     /* Delete the item */
89     CollDeleteItem (&L->JumpFrom, E);
90
91     /* Return the number of remaining references */
92     return CollCount (&L->JumpFrom);
93 }
94
95
96
97 void OutputCodeLabel (FILE* F, const CodeLabel* L)
98 /* Output the code label to a file */
99 {
100     fprintf (F, "%s:\n", L->Name);
101 }
102
103
104