]> git.sur5r.net Git - cc65/blob - src/ld65/exports.h
075c5ca489029429cf233b68df5c0af9d2f11610
[cc65] / src / ld65 / exports.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 exports.h                                 */
4 /*                                                                           */
5 /*                    Exports handing for the ld65 linker                    */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2000 Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@musoftware.de                                            */
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 "exprdefs.h"
45 #include "filepos.h"
46           
47 /* ld65 */
48 #include "objdata.h"
49 #include "config.h"
50
51
52
53 /*****************************************************************************/
54 /*                                   Data                                    */
55 /*****************************************************************************/
56
57
58
59 /* Import symbol structure */
60 typedef struct Import_ Import;
61 struct Import_ {
62     Import*             Next;           /* Single linked list */
63     ObjData*            Obj;            /* Object file that imports the name */
64     FilePos             Pos;            /* File position of reference */
65     union {
66         struct Export_* Exp;            /* Matching export for this import */
67         const char*     Name;           /* Name if not in table */
68     } V;
69     unsigned char       Type;           /* Type of import */
70 };
71
72
73
74 /* Export symbol structure */
75 typedef struct Export_ Export;
76 struct Export_ {
77     Export*             Next;           /* Hash table link */
78     unsigned            Flags;          /* Generic flags */
79     ObjData*            Obj;            /* Object file that exports the name */
80     unsigned            ImpCount;       /* How many imports for this symbol? */
81     Import*             ImpList;        /* List of imports for this symbol */
82     FilePos             Pos;            /* File position of definition */
83     ExprNode*           Expr;           /* Expression (0 if not def'd) */
84     unsigned char       Type;           /* Type of export */
85     char*               Name;           /* Name - dynamically allocated */
86 };
87
88
89
90 /* Prototype of a function that is called if an undefined symbol is found. It
91  * may check if the symbol is an external symbol (for binary formats that
92  * support externals) and will return zero if the symbol could not be
93  * resolved, or a value != zero if the symbol could be resolved. The
94  * CheckExports routine will print out the missing symbol in the first case.
95  */
96 typedef int (*ExpCheckFunc) (const char* Name, void* Data);
97
98
99
100 /*****************************************************************************/
101 /*                                   Code                                    */
102 /*****************************************************************************/
103
104
105
106 Import* ReadImport (FILE* F, ObjData* Obj);
107 /* Read an import from a file and insert it into the table */
108
109 void InsertImport (Import* I);
110 /* Insert an import into the table */
111
112 Export* ReadExport (FILE* F, ObjData* Obj);
113 /* Read an export from a file */
114
115 void InsertExport (Export* E);
116 /* Insert an exported identifier and check if it's already in the list */
117
118 Export* CreateConstExport (const char* Name, long Value);
119 /* Create an export for a literal date */
120
121 Export* CreateMemExport (const char* Name, Memory* Mem, unsigned long Offs);
122 /* Create an relative export for a memory area offset */
123
124 int IsUnresolved (const char* Name);
125 /* Check if this symbol is an unresolved export */
126
127 int IsConstExport (const Export* E);
128 /* Return true if the expression associated with this export is const */
129
130 long GetExportVal (const Export* E);
131 /* Get the value of this export */
132
133 void CheckExports (ExpCheckFunc F, void* Data);
134 /* Check if there are any unresolved symbols. On unresolved symbols, F is
135  * called (see the comments on ExpCheckFunc in the data section).
136  */
137
138 void PrintExportMap (FILE* F);
139 /* Print an export map to the given file */
140
141 void PrintImportMap (FILE* F);
142 /* Print an import map to the given file */
143
144 void PrintExportLabels (FILE* F);
145 /* Print the exports in a VICE label file */
146
147 void MarkExport (Export* E);
148 /* Mark the export */
149
150 void UnmarkExport (Export* E);
151 /* Remove the mark from the export */
152
153 int ExportHasMark (Export* E);
154 /* Return true if the export has a mark */
155
156 void CircularRefError (const Export* E);
157 /* Print an error about a circular reference using to define the given export */
158
159
160
161 /* End of exports.h */
162
163 #endif
164
165
166