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