]> git.sur5r.net Git - cc65/blob - src/ld65/exports.h
d71e5d53318f985612c10eb848ef93a4b557bc17
[cc65] / src / ld65 / exports.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 exports.h                                 */
4 /*                                                                           */
5 /*                    Exports handing 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 EXPORTS_H
37 #define EXPORTS_H
38
39
40
41 #include <stdio.h>
42
43 /* common */
44 #include "cddefs.h"
45 #include "coll.h"
46 #include "exprdefs.h"
47
48 /* ld65 */
49 #include "config.h"
50 #include "lineinfo.h"
51 #include "memarea.h"
52 #include "objdata.h"
53
54
55
56 /*****************************************************************************/
57 /*                                   Data                                    */
58 /*****************************************************************************/
59
60
61
62 /* Import symbol structure */
63 typedef struct Import Import;
64 struct Import {
65     Import*             Next;           /* Single linked list */
66     ObjData*            Obj;            /* Object file that imports the name */
67     Collection          LineInfos;      /* Line info of reference */
68     struct Export*      Exp;            /* Matching export for this import */
69     unsigned            Name;           /* Name if not in table */
70     unsigned short      Flags;          /* Generic flags */
71     unsigned short      AddrSize;       /* Address size of import */
72 };
73
74
75
76 /* Export symbol structure */
77 typedef struct Export Export;
78 struct Export {
79     unsigned            Name;           /* Name */
80     Export*             Next;           /* Hash table link */
81     unsigned            Flags;          /* Generic flags */
82     ObjData*            Obj;            /* Object file that exports the name */
83     unsigned            ImpCount;       /* How many imports for this symbol? */
84     Import*             ImpList;        /* List of imports for this symbol */
85     ExprNode*           Expr;           /* Expression (0 if not def'd) */
86     unsigned            Size;           /* Size of the symbol if any */
87     Collection          LineInfos;      /* Line info of definition */
88     unsigned            DbgSymId;       /* Id of debug symbol for this export */
89     unsigned short      Type;           /* Type of export */
90     unsigned short      AddrSize;       /* Address size of export */
91     unsigned char       ConDes[CD_TYPE_COUNT];  /* Constructor/destructor decls */
92 };
93
94
95
96 /* Prototype of a function that is called if an undefined symbol is found. It
97  * may check if the symbol is an external symbol (for binary formats that
98  * support externals) and will return zero if the symbol could not be
99  * resolved, or a value != zero if the symbol could be resolved. The
100  * CheckExports routine will print out the missing symbol in the first case.
101  */
102 typedef int (*ExpCheckFunc) (unsigned Name, void* Data);
103
104
105
106 /*****************************************************************************/
107 /*                                   Code                                    */
108 /*****************************************************************************/
109
110
111
112 void FreeImport (Import* I);
113 /* Free an import. NOTE: This won't remove the import from the exports table,
114  * so it may only be called for unused imports (imports from modules that
115  * aren't referenced).
116  */
117
118 Import* ReadImport (FILE* F, ObjData* Obj);
119 /* Read an import from a file and insert it into the table */
120
121 Import* GenImport (unsigned Name, unsigned char AddrSize);
122 /* Generate a new import with the given name and address size and return it */
123
124 Import* InsertImport (Import* I);
125 /* Insert an import into the table, return I */
126
127 const LineInfo* GetImportPos (const Import* I);
128 /* Return the basic line info of an import */
129
130 void FreeExport (Export* E);
131 /* Free an export. NOTE: This won't remove the export from the exports table,
132  * so it may only be called for unused exports (exports from modules that
133  * aren't referenced).
134  */
135
136 Export* ReadExport (FILE* F, ObjData* Obj);
137 /* Read an export from a file */
138
139 void InsertExport (Export* E);
140 /* Insert an exported identifier and check if it's already in the list */
141
142 const LineInfo* GetExportPos (const Export* E);
143 /* Return the basic line info of an export */
144
145 Export* CreateConstExport (unsigned Name, long Value);
146 /* Create an export for a literal date */
147
148 Export* CreateExprExport (unsigned Name, ExprNode* Expr, unsigned char AddrSize);
149 /* Create an export for an expression */
150
151 Export* CreateMemoryExport (unsigned Name, MemoryArea* Mem, unsigned long Offs);
152 /* Create an relative export for a memory area offset */
153
154 Export* CreateSegmentExport (unsigned Name, Segment* Seg, unsigned long Offs);
155 /* Create a relative export to a segment */
156
157 Export* CreateSectionExport (unsigned Name, Section* S, unsigned long Offs);
158 /* Create a relative export to a section */
159
160 Export* FindExport (unsigned Name);
161 /* Check for an identifier in the list. Return 0 if not found, otherwise
162  * return a pointer to the export.
163  */
164
165 int IsUnresolved (unsigned Name);
166 /* Check if this symbol is an unresolved export */
167
168 int IsUnresolvedExport (const Export* E);
169 /* Return true if the given export is unresolved */
170
171 int IsConstExport (const Export* E);
172 /* Return true if the expression associated with this export is const */
173
174 long GetExportVal (const Export* E);
175 /* Get the value of this export */
176
177 void CheckExports (void);
178 /* Setup the list of all exports and check for export/import symbol type
179  * mismatches.
180  */
181
182 void CheckUnresolvedImports (ExpCheckFunc F, void* Data);
183 /* Check if there are any unresolved imports. On unresolved imports, F is
184  * called (see the comments on ExpCheckFunc in the data section).
185  */
186
187 void PrintExportMap (FILE* F);
188 /* Print an export map to the given file */
189
190 void PrintImportMap (FILE* F);
191 /* Print an import map to the given file */
192
193 void PrintExportLabels (FILE* F);
194 /* Print the exports in a VICE label file */
195
196 void MarkExport (Export* E);
197 /* Mark the export */
198
199 void UnmarkExport (Export* E);
200 /* Remove the mark from the export */
201
202 int ExportHasMark (Export* E);
203 /* Return true if the export has a mark */
204
205 void CircularRefError (const Export* E);
206 /* Print an error about a circular reference using to define the given export */
207
208
209
210 /* End of exports.h */
211
212 #endif
213
214
215
216