1 /*****************************************************************************/
5 /* Exports handing for the ld65 linker */
9 /* (C) 1998-2011, Ullrich von Bassewitz */
10 /* Roemerstrasse 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 /*****************************************************************************/
56 /*****************************************************************************/
58 /*****************************************************************************/
62 /* Import symbol structure */
63 typedef struct Import 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 char Flags; /* Generic flags */
71 unsigned char AddrSize; /* Address size of import */
76 /* Export symbol structure */
77 typedef struct Export 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 long Size; /* Size of the symbol if any */
87 Collection LineInfos; /* Line info of definition */
88 unsigned char Type; /* Type of export */
89 unsigned char AddrSize; /* Address size of export */
90 unsigned char ConDes[CD_TYPE_COUNT]; /* Constructor/destructor decls */
95 /* Prototype of a function that is called if an undefined symbol is found. It
96 * may check if the symbol is an external symbol (for binary formats that
97 * support externals) and will return zero if the symbol could not be
98 * resolved, or a value != zero if the symbol could be resolved. The
99 * CheckExports routine will print out the missing symbol in the first case.
101 typedef int (*ExpCheckFunc) (unsigned Name, void* Data);
105 /*****************************************************************************/
107 /*****************************************************************************/
111 void FreeImport (Import* I);
112 /* Free an import. NOTE: This won't remove the import from the exports table,
113 * so it may only be called for unused imports (imports from modules that
114 * aren't referenced).
117 Import* ReadImport (FILE* F, ObjData* Obj);
118 /* Read an import from a file and insert it into the table */
120 Import* GenImport (unsigned Name, unsigned char AddrSize);
121 /* Generate a new import with the given name and address size and return it */
123 Import* InsertImport (Import* I);
124 /* Insert an import into the table, return I */
126 const LineInfo* GetImportPos (const Import* I);
127 /* Return the basic line info of an import */
129 void FreeExport (Export* E);
130 /* Free an export. NOTE: This won't remove the export from the exports table,
131 * so it may only be called for unused exports (exports from modules that
132 * aren't referenced).
135 Export* ReadExport (FILE* F, ObjData* Obj);
136 /* Read an export from a file */
138 void InsertExport (Export* E);
139 /* Insert an exported identifier and check if it's already in the list */
141 const LineInfo* GetExportPos (const Export* E);
142 /* Return the basic line info of an export */
144 Export* CreateConstExport (unsigned Name, long Value);
145 /* Create an export for a literal date */
147 Export* CreateExprExport (unsigned Name, ExprNode* Expr, unsigned char AddrSize);
148 /* Create an export for an expression */
150 Export* CreateMemoryExport (unsigned Name, MemoryArea* Mem, unsigned long Offs);
151 /* Create an relative export for a memory area offset */
153 Export* CreateSegmentExport (unsigned Name, Segment* Seg, unsigned long Offs);
154 /* Create a relative export to a segment */
156 Export* CreateSectionExport (unsigned Name, Section* S, unsigned long Offs);
157 /* Create a relative export to a section */
159 Export* FindExport (unsigned Name);
160 /* Check for an identifier in the list. Return 0 if not found, otherwise
161 * return a pointer to the export.
164 int IsUnresolved (unsigned Name);
165 /* Check if this symbol is an unresolved export */
167 int IsUnresolvedExport (const Export* E);
168 /* Return true if the given export is unresolved */
170 int IsConstExport (const Export* E);
171 /* Return true if the expression associated with this export is const */
173 long GetExportVal (const Export* E);
174 /* Get the value of this export */
176 void CheckExports (void);
177 /* Setup the list of all exports and check for export/import symbol type
181 void CheckUnresolvedImports (ExpCheckFunc F, void* Data);
182 /* Check if there are any unresolved imports. On unresolved imports, F is
183 * called (see the comments on ExpCheckFunc in the data section).
186 void PrintExportMap (FILE* F);
187 /* Print an export map to the given file */
189 void PrintImportMap (FILE* F);
190 /* Print an import map to the given file */
192 void PrintExportLabels (FILE* F);
193 /* Print the exports in a VICE label file */
195 void MarkExport (Export* E);
196 /* Mark the export */
198 void UnmarkExport (Export* E);
199 /* Remove the mark from the export */
201 int ExportHasMark (Export* E);
202 /* Return true if the export has a mark */
204 void CircularRefError (const Export* E);
205 /* Print an error about a circular reference using to define the given export */
209 /* End of exports.h */