]> git.sur5r.net Git - cc65/blob - src/ld65/objdata.h
Write imports out to the debug info file. Add the id of the corresponding
[cc65] / src / ld65 / objdata.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 objdata.h                                 */
4 /*                                                                           */
5 /*               Handling object file data for the ld65 linker               */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2011, 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 OBJDATA_H
37 #define OBJDATA_H
38
39
40
41 /* common */
42 #include "coll.h"
43 #include "inline.h"
44 #include "objdefs.h"
45
46
47
48 /*****************************************************************************/
49 /*                                   Data                                    */
50 /*****************************************************************************/
51
52
53
54 /* Forwards */
55 struct Export;
56 struct Import;
57 struct Library;
58 struct Scope;
59 struct Section;
60
61 /* Values for the Flags field */
62 #define OBJ_REF         0x0001          /* We have a reference to this file */
63
64 /* Internal structure holding object file data */
65 typedef struct ObjData ObjData;
66 struct ObjData {
67     ObjData*            Next;           /* Linked list of all objects */
68     unsigned            Id;             /* Id of this module */
69     unsigned            Name;           /* Module name */
70     struct Library*     Lib;            /* Library where module comes from */
71     unsigned long       MTime;          /* Time of last modification */
72     ObjHeader           Header;         /* Header of file */
73     unsigned long       Start;          /* Start offset of data in library */
74     unsigned            Flags;
75
76     unsigned            SymBaseId;      /* Debug info base id for symbols */
77     unsigned            ScopeBaseId;    /* Debug info base id for scopes */
78     unsigned            SpanBaseId;     /* Debug info base id for spans */
79
80     Collection          Files;          /* List of input files */
81     Collection          Sections;       /* List of all sections */
82     Collection          Exports;        /* List of all exports */
83     Collection          Imports;        /* List of all imports */
84     Collection          DbgSyms;        /* List of debug symbols */
85     Collection          LineInfos;      /* List of line infos */
86     unsigned            StringCount;    /* Count of strings */
87     unsigned*           Strings;        /* List of global string indices */
88     Collection          Assertions;     /* List of module assertions */
89     Collection          Scopes;         /* List of scopes */
90     Collection          Spans;          /* List of spans */
91 };
92
93
94
95 /* Collection containing used ObjData objects */
96 extern Collection       ObjDataList;
97
98
99
100 /*****************************************************************************/
101 /*                                   Code                                    */
102 /*****************************************************************************/
103
104
105
106 ObjData* NewObjData (void);
107 /* Allocate a new structure on the heap, insert it into the list, return it */
108
109 void FreeObjData (ObjData* O);
110 /* Free an ObjData object. NOTE: This function works only for unused object
111  * data, that is, ObjData objects that aren't used because they aren't
112  * referenced.
113  */
114
115 void FreeObjStrings (ObjData* O);
116 /* Free the module string data. Used once the object file is loaded completely
117  * when all strings are converted to global strings.
118  */
119
120 void InsertObjData (ObjData* O);
121 /* Insert the ObjData object into the collection of used ObjData objects. */
122
123 void InsertObjGlobals (ObjData* O);
124 /* Insert imports and exports from the object file into the global import and
125  * export lists.
126  */
127
128 unsigned MakeGlobalStringId (const ObjData* O, unsigned Index);
129 /* Convert a local string id into a global one and return it. */
130
131 const char* GetObjFileName (const ObjData* O);
132 /* Get the name of the object file. Return "[linker generated]" if the object
133  * file is NULL.
134  */
135
136 #if defined(HAVE_INLINE)
137 INLINE int ObjHasFiles (const ObjData* O)
138 /* Return true if the files list does exist */
139 {
140     return (O != 0 && CollCount (&O->Files) != 0);
141 }
142 #else
143 #  define ObjHasFiles(O)       ((O) != 0 && CollCount (&(O)->Files) != 0)
144 #endif
145
146 struct Section* GetObjSection (ObjData* Obj, unsigned Id);
147 /* Get a section from an object file checking for a valid index */
148
149 struct Import* GetObjImport (ObjData* Obj, unsigned Id);
150 /* Get an import from an object file checking for a valid index */
151
152 struct Export* GetObjExport (ObjData* Obj, unsigned Id);
153 /* Get an export from an object file checking for a valid index */
154
155 struct Scope* GetObjScope (ObjData* Obj, unsigned Id);
156 /* Get a scope from an object file checking for a valid index */
157
158 unsigned ObjDataCount (void);
159 /* Return the total number of modules */
160
161 void PrintDbgModules (FILE* F);
162 /* Output the modules to a debug info file */
163
164
165
166 /* End of objdata.h */
167
168 #endif
169
170
171
172
173