1/*****************************************************************************/
2/* */
3/* codelab.h */
4/* */
5/* Code label structure */
6/* */
7/* */
8/* */
9/* (C) 2001-2009, Ullrich von Bassewitz */
10/* Roemerstrasse 52 */
11/* D-70794 Filderstadt */
12/* EMail: uz@cc65.org */
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#ifndef CODELAB_H
37#define CODELAB_H
38
39
40
41/* common */
42#include "coll.h"
43
44
45
46/*****************************************************************************/
47/* Forwards */
48/*****************************************************************************/
49
50
51
52struct CodeEntry;
53
54
55
56/*****************************************************************************/
57/* struct CodeLabel */
58/*****************************************************************************/
59
60
61
62/* Label structure */
63typedef struct CodeLabel CodeLabel;
64struct CodeLabel {
65 CodeLabel* Next; /* Next in hash list */
66 char* Name; /* Label name */
67 unsigned Hash; /* Hash over the name */
68 struct CodeEntry* Owner; /* Owner entry */
69 Collection JumpFrom; /* Entries that jump here */
70};
71
72
73
74/*****************************************************************************/
75/* Code */
76/*****************************************************************************/
77
78
79
80CodeLabel* NewCodeLabel (const char* Name, unsigned Hash);
81/* Create a new code label, initialize and return it */
82
83void FreeCodeLabel (CodeLabel* L);
84/* Free the given code label */
85
86#if defined(HAVE_INLINE)
87INLINE unsigned CL_GetRefCount (const CodeLabel* L)
88/* Get the number of references for this label */
89{
90 return CollCount (&L->JumpFrom);
91}
92#else
93# define CL_GetRefCount(L) CollCount (&(L)->JumpFrom)
94#endif
95
96#if defined(HAVE_INLINE)
97INLINE struct CodeEntry* CL_GetRef (CodeLabel* L, unsigned Index)
98/* Get a code entry referencing this label */
99{
100 return CollAt (&L->JumpFrom, Index);
101}
102#else
103# define CL_GetRef(L, Index) CollAt (&(L)->JumpFrom, (Index))
104#endif
105
106void CL_AddRef (CodeLabel* L, struct CodeEntry* E);
107/* Let the CodeEntry E reference the label L */
108
109void CL_MoveRefs (CodeLabel* OldLabel, CodeLabel* NewLabel);
110/* Move all references to OldLabel to point to NewLabel. OldLabel will have no
111** more references on return.
112*/
113
114void CL_Output (const CodeLabel* L);
115/* Output the code label to the output file */
116
117
118
119/* End of codelab.h */
120
121#endif
122