]> git.sur5r.net Git - cc65/blob - src/ca65/lineinfo.h
Finished implemenation of commands to delete macros. Added the new commands to
[cc65] / src / ca65 / lineinfo.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                lineinfo.h                                 */
4 /*                                                                           */
5 /*                     Source file line info management                      */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2001-2011, Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 52                                           */
11 /*                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 LINEINFO_H
37 #define LINEINFO_H
38
39
40
41 /* common */
42 #include "coll.h"
43 #include "filepos.h"
44 #include "lidefs.h"
45
46
47
48 /*****************************************************************************/
49 /*                                   Data                                    */
50 /*****************************************************************************/
51
52
53
54 /* Predefined line info slots. These are allocated when initializing the
55  * module. Beware: Some code relies on the fact that slot zero is the basic
56  * standard line info. It is assumed to be always there.
57  */
58 enum {
59     LI_SLOT_ASM         = 0,            /* Normal assembler source */
60     LI_SLOT_EXT         = 1,            /* Externally supplied line info */
61 };
62
63 /* The LineInfo structure is shared between several fragments, so we need a
64  * reference counter.
65  */
66 typedef struct LineInfo LineInfo;
67 struct LineInfo {
68     unsigned    Usage;                  /* Usage counter */
69     unsigned    Type;                   /* Type of line info */
70     unsigned    Index;                  /* Index */
71     FilePos     Pos;                    /* File position */
72 };
73
74
75
76 /*****************************************************************************/
77 /*                                   Code                                    */
78 /*****************************************************************************/
79
80
81
82 void InitLineInfo (void);
83 /* Initialize the line infos */
84
85 unsigned AllocLineInfoSlot (unsigned Type, unsigned Count);
86 /* Allocate a line info slot of the given type and return the slot index */
87
88 void FreeLineInfoSlot (unsigned Slot);
89 /* Free the line info in the given slot. Note: Alloc/Free must be used in
90  * FIFO order.
91  */
92
93 void GenLineInfo (unsigned Slot, const FilePos* Pos);
94 /* Generate a new line info in the given slot */
95
96 void ClearLineInfo (unsigned Slot);
97 /* Clear the line info in the given slot */
98
99 void GetFullLineInfo (Collection* LineInfos, unsigned IncUsage);
100 /* Return full line infos, that is line infos for all slots in LineInfos. The
101  * function will clear LineInfos before usage and will increment the usage
102  * counter by IncUsage for all line infos returned.
103  */
104
105 LineInfo* UseLineInfo (LineInfo* LI);
106 /* Increase the reference count of the given line info and return it. The
107  * function will gracefully accept NULL pointers and do nothing in this case.
108  */
109
110 LineInfo* ReleaseLineInfo (LineInfo* LI);
111 /* Decrease the reference count of the given line info and return it. The
112  * function will gracefully accept NULL pointers and do nothing in this case.
113  */
114
115 #if defined(HAVE_INLINE)
116 INLINE const FilePos* GetSourcePos (const LineInfo* LI)
117 /* Return the source file position from the given line info */
118 {
119     return &LI->Pos;
120 }
121 #else
122 #  define GetSourcePos(LI)      (&(LI)->Pos)
123 #endif
124
125 #if defined(HAVE_INLINE)
126 INLINE unsigned GetLineInfoType (const LineInfo* LI)
127 /* Return the type of a line info */
128 {
129     return LI_GET_TYPE (LI->Type);
130 }
131 #else
132 #  define GetLineInfoType(LI)     LI_GET_TYPE ((LI)->Type)
133 #endif
134
135 void WriteLineInfo (const Collection* LineInfos);
136 /* Write a list of line infos to the object file. MakeLineInfoIndex has to
137  * be called before!
138  */
139
140 void MakeLineInfoIndex (void);
141 /* Index the line infos */
142
143 void WriteLineInfos (void);
144 /* Write a list of all line infos to the object file. */
145
146
147
148 /* End of lineinfo.h */
149 #endif
150
151
152