1/*****************************************************************************/
2/* */
3/* lineinfo.h */
4/* */
5/* Source file line info structure */
6/* */
7/* */
8/* */
9/* (C) 2001-2012, 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 LINEINFO_H
37#define LINEINFO_H
38
39
40
41#include <stdio.h>
42
43/* common */
44#include "coll.h"
45#include "filepos.h"
46
47/* ld65 */
48#include "span.h"
49#include "spool.h"
50
51
52
53/*****************************************************************************/
54/* Forwards */
55/*****************************************************************************/
56
57
58
59struct ObjData;
60struct Segment;
61
62
63
64/*****************************************************************************/
65/* Data */
66/*****************************************************************************/
67
68
69
70/* Structure holding line information. The Pos.Name field is always the
71** global string id of the file name. If the line info was read from the
72** object file, the File pointer is valid, otherwise it is NULL.
73*/
74typedef struct LineInfo LineInfo;
75struct LineInfo {
76 unsigned Id; /* Line info id */
77 struct FileInfo* File; /* File struct for this line if any */
78 unsigned Type; /* Type of line info */
79 FilePos Pos; /* Position in file */
80 unsigned* Spans; /* Spans for this line */
81};
82
83
84
85/*****************************************************************************/
86/* Code */
87/*****************************************************************************/
88
89
90
91LineInfo* GenLineInfo (const FilePos* Pos);
92/* Generate a new (internally used) line info with the given information */
93
94LineInfo* ReadLineInfo (FILE* F, struct ObjData* O);
95/* Read a line info from a file and return it */
96
97void FreeLineInfo (LineInfo* LI);
98/* Free a LineInfo structure. */
99
100LineInfo* DupLineInfo (const LineInfo* LI);
101/* Creates a duplicate of a line info structure */
102
103void ReadLineInfoList (FILE* F, struct ObjData* O, Collection* LineInfos);
104/* Read a list of line infos stored as a list of indices in the object file,
105** make real line infos from them and place them into the passed collection.
106*/
107
108const LineInfo* GetAsmLineInfo (const Collection* LineInfos);
109/* Find a line info of type LI_TYPE_ASM and count zero in the given collection
110** and return it. Return NULL if no such line info was found.
111*/
112
113#if defined(HAVE_INLINE)
114INLINE const FilePos* GetSourcePos (const LineInfo* LI)
115/* Return the source file position from the given line info */
116{
117 return &LI->Pos;
118}
119#else
120# define GetSourcePos(LI) (&(LI)->Pos)
121#endif
122
123#if defined(HAVE_INLINE)
124INLINE const char* GetSourceName (const LineInfo* LI)
125/* Return the name of a source file from the given line info */
126{
127 return GetString (LI->Pos.Name);
128}
129#else
130# define GetSourceName(LI) (GetString ((LI)->Pos.Name))
131#endif
132
133#if defined(HAVE_INLINE)
134INLINE unsigned GetSourceLine (const LineInfo* LI)
135/* Return the source file line from the given line info */
136{
137 return LI->Pos.Line;
138}
139#else
140# define GetSourceLine(LI) ((LI)->Pos.Line)
141#endif
142
143#if defined(HAVE_INLINE)
144INLINE unsigned GetSourceCol (const LineInfo* LI)
145/* Return the source file column from the given line info */
146{
147 return LI->Pos.Col;
148}
149#else
150# define GetSourceCol(LI) ((LI)->Pos.Col)
151#endif
152
153#if defined(HAVE_INLINE)
154INLINE const char* GetSourceNameFromList (const Collection* LineInfos)
155/* Return the name of a source file from a list of line infos */
156{
157 /* The relevant entry is in slot zero */
158 return GetSourceName (CollConstAt (LineInfos, 0));
159}
160#else
161# define GetSourceNameFromList(LineInfos) \
162 GetSourceName ((const LineInfo*) CollConstAt ((LineInfos), 0))
163#endif
164
165#if defined(HAVE_INLINE)
166INLINE unsigned GetSourceLineFromList (const Collection* LineInfos)
167/* Return the source file line from a list of line infos */
168{
169 /* The relevant entry is in slot zero */
170 return GetSourceLine (CollConstAt (LineInfos, 0));
171}
172#else
173# define GetSourceLineFromList(LineInfos) \
174 GetSourceLine ((const LineInfo*) CollConstAt ((LineInfos), 0))
175#endif
176
177unsigned LineInfoCount (void);
178/* Return the total number of line infos */
179
180void AssignLineInfoIds (void);
181/* Assign the ids to the line infos */
182
183void PrintDbgLineInfo (FILE* F);
184/* Output the line infos to a debug info file */
185
186
187
188/* End of lineinfo.h */
189
190#endif
191