1 /*****************************************************************************/
5 /* Exports handing for the ld65 linker */
9 /* (C) 1998-2003 Ullrich von Bassewitz */
10 /* Römerstrasse 52 */
11 /* D-70794 Filderstadt */
12 /* EMail: uz@cc65.org */
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. */
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: */
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 */
32 /*****************************************************************************/
54 /*****************************************************************************/
56 /*****************************************************************************/
60 /* Import symbol structure */
61 typedef struct Import Import;
63 Import* Next; /* Single linked list */
64 ObjData* Obj; /* Object file that imports the name */
65 FilePos Pos; /* File position of reference */
66 struct Export* Exp; /* Matching export for this import */
67 unsigned Name; /* Name if not in table */
68 unsigned char Type; /* Type of import */
73 /* Export symbol structure */
74 typedef struct Export Export;
76 unsigned Name; /* Name */
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 unsigned char ConDes[CD_TYPE_COUNT]; /* Constructor/destructor decls */
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.
96 typedef int (*ExpCheckFunc) (unsigned Name, void* Data);
100 /*****************************************************************************/
102 /*****************************************************************************/
106 Import* ReadImport (FILE* F, ObjData* Obj);
107 /* Read an import from a file and insert it into the table */
109 void InsertImport (Import* I);
110 /* Insert an import into the table */
112 Export* ReadExport (FILE* F, ObjData* Obj);
113 /* Read an export from a file */
115 void InsertExport (Export* E);
116 /* Insert an exported identifier and check if it's already in the list */
118 Export* CreateConstExport (unsigned Name, long Value);
119 /* Create an export for a literal date */
121 Export* CreateMemoryExport (unsigned Name, Memory* Mem, unsigned long Offs);
122 /* Create an relative export for a memory area offset */
124 Export* CreateSegmentExport (unsigned Name, Segment* Seg, unsigned long Offs);
125 /* Create a relative export to a segment */
127 Export* CreateSectionExport (unsigned Name, Section* S, unsigned long Offs);
128 /* Create a relative export to a section */
130 Export* FindExport (unsigned Name);
131 /* Check for an identifier in the list. Return 0 if not found, otherwise
132 * return a pointer to the export.
135 int IsUnresolved (unsigned Name);
136 /* Check if this symbol is an unresolved export */
138 int IsUnresolvedExport (const Export* E);
139 /* Return true if the given export is unresolved */
141 int IsConstExport (const Export* E);
142 /* Return true if the expression associated with this export is const */
144 long GetExportVal (const Export* E);
145 /* Get the value of this export */
147 void CheckExports (ExpCheckFunc F, void* Data);
148 /* Check if there are any unresolved symbols. On unresolved symbols, F is
149 * called (see the comments on ExpCheckFunc in the data section).
152 void PrintExportMap (FILE* F);
153 /* Print an export map to the given file */
155 void PrintImportMap (FILE* F);
156 /* Print an import map to the given file */
158 void PrintExportLabels (FILE* F);
159 /* Print the exports in a VICE label file */
161 void MarkExport (Export* E);
162 /* Mark the export */
164 void UnmarkExport (Export* E);
165 /* Remove the mark from the export */
167 int ExportHasMark (Export* E);
168 /* Return true if the export has a mark */
170 void CircularRefError (const Export* E);
171 /* Print an error about a circular reference using to define the given export */
175 /* End of exports.h */