]> git.sur5r.net Git - cc65/blob - src/ca65/lineinfo.h
Started to generalize line info handling. Remove separate FilePos fields and
[cc65] / src / ca65 / lineinfo.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                lineinfo.h                                 */
4 /*                                                                           */
5 /*                      Source file line info structure                      */
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 /* Note: The line infos kept here are additional line infos supplied by the
37  * ".dbg line" command. The native line infos are always kept in the fragments
38  * itself (because one fragment always originates from one line). The
39  * additional line infos (which may not exist if none are supplied in the
40  * source) may have several fragments attached (as is the case with sources
41  * generated by the C compiler).
42  */
43
44
45
46 #ifndef LINEINFO_H
47 #define LINEINFO_H
48
49
50
51 /* common */
52 #include "coll.h"
53 #include "filepos.h"
54
55
56
57 /*****************************************************************************/
58 /*                                   Data                                    */
59 /*****************************************************************************/
60
61
62
63 /* Predefined line info slots. These are allocated when initializing the
64  * module. Beware: Some code relies on the fact that slot zero is the basic
65  * standard line info. It is assumed to be always there.
66  */
67 enum {
68     LI_SLOT_ASM         = 0,            /* Normal assembler source */
69     LI_SLOT_EXT         = 1,            /* Externally supplied line info */
70 };
71
72 /* Types of line infos. The low byte may be used for some sort of depth
73  * counter.
74  */
75 enum {
76     LI_MASK_COUNT       = 0x00FF,       /* Mask to extract the count */
77
78     LI_TYPE_EXT         = 0x0100,       /* Externally supplied line info */
79     LI_TYPE_ASM         = 0x0200,       /* Normal assembler source */
80     LI_TYPE_MACRO       = 0x0300,       /* Macro expansion */
81     LI_MASK_TYPE        = 0x7F00,       /* Mask to extract the type */
82 };
83
84 /* The LineInfo structure is shared between several fragments, so we need a
85  * reference counter.
86  */
87 typedef struct LineInfo LineInfo;
88 struct LineInfo {
89     unsigned    Usage;                  /* Usage counter */
90     unsigned    Type;                   /* Type of line info */
91     unsigned    Index;                  /* Index */
92     FilePos     Pos;                    /* File position */
93 };
94
95
96
97 /*****************************************************************************/
98 /*                                   Code                                    */
99 /*****************************************************************************/
100
101
102
103 void InitLineInfo (void);
104 /* Initialize the line infos */
105
106 unsigned AllocLineInfoSlot (unsigned Type);
107 /* Allocate a line info slot of the given type and return the slot index */
108
109 void FreeLineInfoSlot (unsigned Slot);
110 /* Free the line info in the given slot. Note: Alloc/Free must be used in
111  * FIFO order.
112  */
113
114 void GenLineInfo (unsigned Slot, unsigned File, unsigned long Line, unsigned Col);
115 /* Generate a new line info in the given slot */
116
117 void ClearLineInfo (unsigned Slot);
118 /* Clear the line info in the given slot */
119
120 LineInfo* GetLineInfo (unsigned Slot);
121 /* Get the line info from the given slot */
122
123 void GetFullLineInfo (Collection* LineInfos);
124 /* Return full line infos, that is line infos for all slots in LineInfos. The
125  * function does also increase the usage counter for all line infos returned.
126  */
127
128 LineInfo* UseLineInfo (LineInfo* LI);
129 /* Increase the reference count of the given line info and return it. The
130  * function will gracefully accept NULL pointers and do nothing in this case.
131  */
132
133 LineInfo* ReleaseLineInfo (LineInfo* LI);
134 /* Decrease the reference count of the given line info and return it. The
135  * function will gracefully accept NULL pointers and do nothing in this case.
136  */
137
138 void WriteLineInfo (const Collection* LineInfos);
139 /* Write a list of line infos to the object file. MakeLineInfoIndex has to
140  * be called before!
141  */
142
143 void MakeLineInfoIndex (void);
144 /* Index the line infos */
145
146 void WriteLineInfos (void);
147 /* Write a list of all line infos to the object file. */
148
149
150
151 /* End of lineinfo.h */
152 #endif
153
154
155