]> git.sur5r.net Git - cc65/blob - src/ld65/exports.c
Merge CfgProcess and CfgAssignSegments because both do some sort of
[cc65] / src / ld65 / exports.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 exports.c                                 */
4 /*                                                                           */
5 /*                   Exports handling for the ld65 linker                    */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2010, 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 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39
40 /* common */
41 #include "addrsize.h"
42 #include "check.h"
43 #include "coll.h"
44 #include "hashstr.h"
45 #include "symdefs.h"
46 #include "xmalloc.h"
47
48 /* ld65 */
49 #include "condes.h"
50 #include "error.h"
51 #include "exports.h"
52 #include "expr.h"
53 #include "fileio.h"
54 #include "global.h"
55 #include "memarea.h"
56 #include "objdata.h"
57 #include "spool.h"
58
59
60
61 /*****************************************************************************/
62 /*                                   Data                                    */
63 /*****************************************************************************/
64
65
66
67 /* Hash table */
68 #define HASHTAB_MASK    0x0FFFU
69 #define HASHTAB_SIZE    (HASHTAB_MASK + 1)
70 static Export*          HashTab[HASHTAB_SIZE];
71
72 /* Import management variables */
73 static unsigned         ImpCount = 0;           /* Import count */
74 static unsigned         ImpOpen  = 0;           /* Count of open imports */
75
76 /* Export management variables */
77 static unsigned         ExpCount = 0;           /* Export count */
78 static Export**         ExpPool  = 0;           /* Exports array */
79
80 /* Defines for the flags in Import */
81 #define IMP_INLIST      0x0001U                 /* Import is in exports list */
82
83 /* Defines for the flags in Export */
84 #define EXP_INLIST      0x0001U                 /* Export is in exports list */
85 #define EXP_USERMARK    0x0002U                 /* User setable flag */
86
87
88
89 /*****************************************************************************/
90 /*                              Import handling                              */
91 /*****************************************************************************/
92
93
94
95 static Export* NewExport (unsigned char Type, unsigned char AddrSize,
96                           unsigned Name, ObjData* Obj);
97 /* Create a new export and initialize it */
98
99
100
101 static Import* NewImport (unsigned char AddrSize, ObjData* Obj)
102 /* Create a new import and initialize it */
103 {
104     /* Allocate memory */
105     Import* I = xmalloc (sizeof (Import));
106
107     /* Initialize the fields */
108     I->Next     = 0;
109     I->Obj      = Obj;
110     InitFilePos (&I->Pos);
111     I->Exp      = 0;
112     I->Name     = INVALID_STRING_ID;
113     I->Flags    = 0;
114     I->AddrSize = AddrSize;
115
116     /* Return the new structure */
117     return I;
118 }
119
120
121
122 void FreeImport (Import* I)
123 /* Free an import. NOTE: This won't remove the import from the exports table,
124  * so it may only be called for unused imports (imports from modules that
125  * aren't referenced).
126  */
127 {
128     /* Safety */
129     PRECONDITION ((I->Flags & IMP_INLIST) == 0);
130
131     /* Free the struct */
132     xfree (I);
133 }
134
135
136
137 Import* ReadImport (FILE* F, ObjData* Obj)
138 /* Read an import from a file and return it */
139 {
140     Import* I;
141
142     /* Read the import address size */
143     unsigned char AddrSize = Read8 (F);
144
145     /* Create a new import */
146     I = NewImport (AddrSize, Obj);
147
148     /* Read the name */
149     I->Name = MakeGlobalStringId (Obj, ReadVar (F));
150
151     /* Read the file position */
152     ReadFilePos (F, &I->Pos);
153
154     /* Check the address size */
155     if (I->AddrSize == ADDR_SIZE_DEFAULT || I->AddrSize > ADDR_SIZE_LONG) {
156         /* Beware: This function may be called in cases where the object file
157          * is not read completely into memory. In this case, the file list is
158          * invalid. Be sure not to access it in this case.
159          */
160         if (ObjHasFiles (I->Obj)) {
161             Error ("Invalid import size in for `%s', imported from %s(%lu): 0x%02X",
162                    GetString (I->Name),
163                    GetSourceFileName (I->Obj, I->Pos.Name),
164                    I->Pos.Line,
165                    I->AddrSize);
166         } else {
167             Error ("Invalid import size in for `%s', imported from %s: 0x%02X",
168                    GetString (I->Name),
169                    GetObjFileName (I->Obj),
170                    I->AddrSize);
171         }
172     }
173
174     /* Return the new import */
175     return I;
176 }
177
178
179
180 Import* GenImport (unsigned Name, unsigned char AddrSize)
181 /* Generate a new import with the given name and address size and return it */
182 {
183     /* Create a new import */
184     Import* I = NewImport (AddrSize, 0);
185
186     /* Read the name */
187     I->Name = Name;
188
189     /* Check the address size */
190     if (I->AddrSize == ADDR_SIZE_DEFAULT || I->AddrSize > ADDR_SIZE_LONG) {
191         /* Beware: This function may be called in cases where the object file
192          * is not read completely into memory. In this case, the file list is
193          * invalid. Be sure not to access it in this case.
194          */
195         if (ObjHasFiles (I->Obj)) {
196             Error ("Invalid import size in for `%s', imported from %s(%lu): 0x%02X",
197                    GetString (I->Name),
198                    GetSourceFileName (I->Obj, I->Pos.Name),
199                    I->Pos.Line,
200                    I->AddrSize);
201         } else {
202             Error ("Invalid import size in for `%s', imported from %s: 0x%02X",
203                    GetString (I->Name),
204                    GetObjFileName (I->Obj),
205                    I->AddrSize);
206         }
207     }
208
209     /* Return the new import */
210     return I;
211 }
212
213
214
215 Import* InsertImport (Import* I)
216 /* Insert an import into the table, return I */
217 {
218     Export* E;
219
220     /* As long as the import is not inserted, V.Name is valid */
221     unsigned Name = I->Name;
222
223     /* Create a hash value for the given name */
224     unsigned Hash = (Name & HASHTAB_MASK);
225
226     /* Search through the list in that slot and print matching duplicates */
227     if (HashTab[Hash] == 0) {
228         /* The slot is empty, we need to insert a dummy export */
229         E = HashTab[Hash] = NewExport (0, ADDR_SIZE_DEFAULT, Name, 0);
230         ++ExpCount;
231     } else {
232         E = HashTab [Hash];
233         while (1) {
234             if (E->Name == Name) {
235                 /* We have an entry, L points to it */
236                 break;
237             }
238             if (E->Next == 0) {
239                 /* End of list an entry not found, insert a dummy */
240                 E->Next = NewExport (0, ADDR_SIZE_DEFAULT, Name, 0);
241                 E = E->Next;            /* Point to dummy */
242                 ++ExpCount;             /* One export more */
243                 break;
244             } else {
245                 E = E->Next;
246             }
247         }
248     }
249
250     /* Ok, E now points to a valid exports entry for the given import. Insert
251      * the import into the imports list and update the counters.
252      */
253     I->Exp     = E;
254     I->Next    = E->ImpList;
255     E->ImpList = I;
256     E->ImpCount++;
257     ++ImpCount;                 /* Total import count */
258     if (E->Expr == 0) {
259         /* This is a dummy export */
260         ++ImpOpen;
261     }
262
263     /* Mark the import so we know it's in the list */
264     I->Flags |= IMP_INLIST;
265
266     /* Return the import to allow shorter code */
267     return I;
268 }
269
270
271
272 /*****************************************************************************/
273 /*                                   Code                                    */
274 /*****************************************************************************/
275
276
277
278 static Export* NewExport (unsigned char Type, unsigned char AddrSize,
279                           unsigned Name, ObjData* Obj)
280 /* Create a new export and initialize it */
281 {
282     /* Allocate memory */
283     Export* E = xmalloc (sizeof (Export));
284
285     /* Initialize the fields */
286     E->Name     = Name;
287     E->Next     = 0;
288     E->Flags    = 0;
289     E->Obj      = Obj;
290     E->ImpCount = 0;
291     E->ImpList  = 0;
292     E->Expr     = 0;
293     E->Type     = Type;
294     E->AddrSize = AddrSize;
295     memset (E->ConDes, 0, sizeof (E->ConDes));
296
297     /* Return the new entry */
298     return E;
299 }
300
301
302
303 void FreeExport (Export* E)
304 /* Free an export. NOTE: This won't remove the export from the exports table,
305  * so it may only be called for unused exports (exports from modules that
306  * aren't referenced).
307  */
308 {
309     /* Safety */
310     PRECONDITION ((E->Flags & EXP_INLIST) == 0);
311
312     /* Free the export expression */
313     FreeExpr (E->Expr);
314
315     /* Free the struct */
316     xfree (E);
317 }
318
319
320
321 void InsertExport (Export* E)
322 /* Insert an exported identifier and check if it's already in the list */
323 {
324     Export* L;
325     Export* Last;
326     Import* Imp;
327     unsigned Hash;
328
329     /* Mark the export as inserted */
330     E->Flags |= EXP_INLIST;
331
332     /* Insert the export into any condes tables if needed */
333     if (SYM_IS_CONDES (E->Type)) {
334         ConDesAddExport (E);
335     }
336
337     /* Create a hash value for the given name */
338     Hash = (E->Name & HASHTAB_MASK);
339
340     /* Search through the list in that slot */
341     if (HashTab[Hash] == 0) {
342         /* The slot is empty */
343         HashTab[Hash] = E;
344         ++ExpCount;
345     } else {
346
347         Last = 0;
348         L = HashTab[Hash];
349         do {
350             if (L->Name == E->Name) {
351                 /* This may be an unresolved external */
352                 if (L->Expr == 0) {
353
354                     /* This *is* an unresolved external. Use the actual export
355                      * in E instead of the dummy one in L.
356                      */
357                     E->Next     = L->Next;
358                     E->ImpCount = L->ImpCount;
359                     E->ImpList  = L->ImpList;
360                     if (Last) {
361                         Last->Next = E;
362                     } else {
363                         HashTab[Hash] = E;
364                     }
365                     ImpOpen -= E->ImpCount;     /* Decrease open imports now */
366                     xfree (L);
367                     /* We must run through the import list and change the
368                      * export pointer now.
369                      */
370                     Imp = E->ImpList;
371                     while (Imp) {
372                         Imp->Exp = E;
373                         Imp = Imp->Next;
374                     }
375                 } else {
376                     /* Duplicate entry, ignore it */
377                     Warning ("Duplicate external identifier: `%s'",
378                              GetString (L->Name));
379                 }
380                 return;
381             }
382             Last = L;
383             L = L->Next;
384
385         } while (L);
386
387         /* Insert export at end of queue */
388         Last->Next = E;
389         ++ExpCount;
390     }
391 }
392
393
394
395 Export* ReadExport (FILE* F, ObjData* O)
396 /* Read an export from a file */
397 {
398     unsigned      ConDesCount;
399     Export* E;
400
401     /* Read the type */
402     unsigned char Type = ReadVar (F);
403
404     /* Read the address size */
405     unsigned char AddrSize = Read8 (F);
406
407     /* Create a new export without a name */
408     E = NewExport (Type, AddrSize, INVALID_STRING_ID, O);
409
410     /* Read the constructor/destructor decls if we have any */
411     ConDesCount = SYM_GET_CONDES_COUNT (Type);
412     if (ConDesCount > 0) {
413
414         unsigned char ConDes[CD_TYPE_COUNT];
415         unsigned I;
416
417         /* Read the data into temp storage */
418         ReadData (F, ConDes, ConDesCount);
419
420         /* Re-order the data. In the file, each decl is encoded into a byte
421          * which contains the type and the priority. In memory, we will use
422          * an array of types which contain the priority. This array was
423          * cleared by the constructor (NewExport), so we must only set the
424          * fields that contain values.
425          */
426         for (I = 0; I < ConDesCount; ++I) {
427             unsigned ConDesType = CD_GET_TYPE (ConDes[I]);
428             unsigned ConDesPrio = CD_GET_PRIO (ConDes[I]);
429             E->ConDes[ConDesType] = ConDesPrio;
430         }
431     }
432
433     /* Read the name */
434     E->Name = MakeGlobalStringId (O, ReadVar (F));
435
436     /* Read the value */
437     if (SYM_IS_EXPR (Type)) {
438         E->Expr = ReadExpr (F, O);
439     } else {
440         E->Expr = LiteralExpr (Read32 (F), O);
441     }
442
443     /* Last is the file position where the definition was done */
444     ReadFilePos (F, &E->Pos);
445
446     /* Return the new export */
447     return E;
448 }
449
450
451
452 Export* CreateConstExport (unsigned Name, long Value)
453 /* Create an export for a literal date */
454 {
455     /* Create a new export */
456     Export* E = NewExport (SYM_CONST | SYM_EQUATE, ADDR_SIZE_ABS, Name, 0);
457
458     /* Assign the value */
459     E->Expr = LiteralExpr (Value, 0);
460
461     /* Insert the export */
462     InsertExport (E);
463
464     /* Return the new export */
465     return E;
466 }
467
468
469
470 Export* CreateMemoryExport (unsigned Name, MemoryArea* Mem, unsigned long Offs)
471 /* Create an relative export for a memory area offset */
472 {
473     /* Create a new export */
474     Export* E = NewExport (SYM_EXPR | SYM_LABEL, ADDR_SIZE_ABS, Name, 0);
475
476     /* Assign the value */
477     E->Expr = MemoryExpr (Mem, Offs, 0);
478
479     /* Insert the export */
480     InsertExport (E);
481
482     /* Return the new export */
483     return E;
484 }
485
486
487
488 Export* CreateSegmentExport (unsigned Name, Segment* Seg, unsigned long Offs)
489 /* Create a relative export to a segment */
490 {
491     /* Create a new export */
492     Export* E = NewExport (SYM_EXPR | SYM_LABEL, Seg->AddrSize, Name, 0);
493
494     /* Assign the value */
495     E->Expr = SegmentExpr (Seg, Offs, 0);
496
497     /* Insert the export */
498     InsertExport (E);
499
500     /* Return the new export */
501     return E;
502 }
503
504
505
506 Export* CreateSectionExport (unsigned Name, Section* Sec, unsigned long Offs)
507 /* Create a relative export to a section */
508 {
509     /* Create a new export */
510     Export* E = NewExport (SYM_EXPR | SYM_LABEL, Sec->AddrSize, Name, 0);
511
512     /* Assign the value */
513     E->Expr = SectionExpr (Sec, Offs, 0);
514
515     /* Insert the export */
516     InsertExport (E);
517
518     /* Return the new export */
519     return E;
520 }
521
522
523
524 Export* FindExport (unsigned Name)
525 /* Check for an identifier in the list. Return 0 if not found, otherwise
526  * return a pointer to the export.
527  */
528 {
529     /* Get a pointer to the list with the symbols hash value */
530     Export* L = HashTab[Name & HASHTAB_MASK];
531     while (L) {
532         /* Search through the list in that slot */
533         if (L->Name == Name) {
534             /* Entry found */
535             return L;
536         }
537         L = L->Next;
538     }
539
540     /* Not found */
541     return 0;
542 }
543
544
545
546 int IsUnresolved (unsigned Name)
547 /* Check if this symbol is an unresolved export */
548 {
549     /* Find the export */
550     return IsUnresolvedExport (FindExport (Name));
551 }
552
553
554
555 int IsUnresolvedExport (const Export* E)
556 /* Return true if the given export is unresolved */
557 {
558     /* Check if it's unresolved */
559     return E != 0 && E->Expr == 0;
560 }
561
562
563
564 int IsConstExport (const Export* E)
565 /* Return true if the expression associated with this export is const */
566 {
567     if (E->Expr == 0) {
568         /* External symbols cannot be const */
569         return 0;
570     } else {
571         return IsConstExpr (E->Expr);
572     }
573 }
574
575
576
577 long GetExportVal (const Export* E)
578 /* Get the value of this export */
579 {
580     if (E->Expr == 0) {
581         /* OOPS */
582         Internal ("`%s' is an undefined external", GetString (E->Name));
583     }
584     return GetExprVal (E->Expr);
585 }
586
587
588
589 static void CheckSymType (const Export* E)
590 /* Check the types for one export */
591 {
592     /* External with matching imports */
593     Import* Imp = E->ImpList;
594     while (Imp) {
595         if (E->AddrSize != Imp->AddrSize) {
596             /* Export is ZP, import is abs or the other way round */
597             const char* ExpAddrSize = AddrSizeToStr (E->AddrSize);
598             const char* ImpAddrSize = AddrSizeToStr (Imp->AddrSize);
599             const char* ExpObjName  = GetObjFileName (E->Obj);
600             const char* ImpObjName  = GetObjFileName (Imp->Obj);
601             if (E->Obj) {
602                 /* User defined export */
603                 Warning ("Address size mismatch for `%s': Exported from %s, "
604                          "%s(%lu) as `%s', import in %s, %s(%lu) as `%s'",
605                          GetString (E->Name),
606                          ExpObjName,
607                          GetSourceFileName (E->Obj, E->Pos.Name),
608                          E->Pos.Line,
609                          ExpAddrSize,
610                          ImpObjName,
611                          GetSourceFileName (Imp->Obj, Imp->Pos.Name),
612                          Imp->Pos.Line,
613                          ImpAddrSize);
614             } else {
615                 /* Export created by the linker */
616                 Warning ("Address size mismatch for `%s': Symbol is `%s'"
617                          ", but imported from %s, %s(%lu) as `%s'",
618                          GetString (E->Name),
619                          ExpAddrSize,
620                          ImpObjName,
621                          GetSourceFileName (Imp->Obj, Imp->Pos.Name),
622                          Imp->Pos.Line,
623                          ImpAddrSize);
624             }
625         }
626         Imp = Imp->Next;
627     }
628 }
629
630
631
632 static void CheckSymTypes (void)
633 /* Check for symbol tape mismatches */
634 {
635     unsigned I;
636
637     /* Print all open imports */
638     for (I = 0; I < ExpCount; ++I) {
639         const Export* E = ExpPool [I];
640         if (E->Expr != 0 && E->ImpCount > 0) {
641             /* External with matching imports */
642             CheckSymType (E);
643         }
644     }
645 }
646
647
648
649 static void PrintUnresolved (ExpCheckFunc F, void* Data)
650 /* Print a list of unresolved symbols. On unresolved symbols, F is
651  * called (see the comments on ExpCheckFunc in the data section).
652  */
653 {
654     unsigned I;
655
656     /* Print all open imports */
657     for (I = 0; I < ExpCount; ++I) {
658         Export* E = ExpPool [I];
659         if (E->Expr == 0 && E->ImpCount > 0 && F (E->Name, Data) == 0) {
660             /* Unresolved external */
661             Import* Imp = E->ImpList;
662             fprintf (stderr,
663                      "Unresolved external `%s' referenced in:\n",
664                      GetString (E->Name));
665             while (Imp) {
666                 const char* Name = GetSourceFileName (Imp->Obj, Imp->Pos.Name);
667                 fprintf (stderr, "  %s(%lu)\n", Name, Imp->Pos.Line);
668                 Imp = Imp->Next;
669             }
670         }
671     }
672 }
673
674
675
676 static int CmpExpName (const void* K1, const void* K2)
677 /* Compare function for qsort */
678 {
679     return SB_Compare (GetStrBuf ((*(Export**)K1)->Name),
680                        GetStrBuf ((*(Export**)K2)->Name));
681 }
682
683
684
685 static void CreateExportPool (void)
686 /* Create an array with pointer to all exports */
687 {
688     unsigned I, J;
689
690     /* Allocate memory */
691     if (ExpPool) {
692         xfree (ExpPool);
693     }
694     ExpPool = xmalloc (ExpCount * sizeof (Export*));
695
696     /* Walk through the list and insert the exports */
697     for (I = 0, J = 0; I < sizeof (HashTab) / sizeof (HashTab [0]); ++I) {
698         Export* E = HashTab[I];
699         while (E) {
700             CHECK (J < ExpCount);
701             ExpPool[J++] = E;
702             E = E->Next;
703         }
704     }
705
706     /* Sort them by name */
707     qsort (ExpPool, ExpCount, sizeof (Export*), CmpExpName);
708 }
709
710
711
712 void CheckExports (void)
713 /* Setup the list of all exports and check for export/import symbol type
714  * mismatches.
715  */
716 {
717     /* Create an export pool */
718     CreateExportPool ();
719
720     /* Check for symbol type mismatches */
721     CheckSymTypes ();
722 }
723
724
725
726 void CheckUnresolvedImports (ExpCheckFunc F, void* Data)
727 /* Check if there are any unresolved imports. On unresolved imports, F is
728  * called (see the comments on ExpCheckFunc in the data section).
729  */
730 {
731     /* Check for unresolved externals */
732     if (ImpOpen != 0) {
733         /* Print all open imports */
734         PrintUnresolved (F, Data);
735     }
736 }
737
738
739
740 static char GetAddrSizeCode (unsigned char AddrSize)
741 /* Get a one char code for the address size */
742 {
743     switch (AddrSize) {
744         case ADDR_SIZE_ZP:      return 'Z';
745         case ADDR_SIZE_ABS:     return 'A';
746         case ADDR_SIZE_FAR:     return 'F';
747         case ADDR_SIZE_LONG:    return 'L';
748         default:
749             Internal ("Invalid address size: %u", AddrSize);
750             /* NOTREACHED */
751             return '-';
752     }
753 }
754
755
756
757 void PrintExportMap (FILE* F)
758 /* Print an export map to the given file */
759 {
760     unsigned I;
761     unsigned Count;
762
763     /* Print all exports */
764     Count = 0;
765     for (I = 0; I < ExpCount; ++I) {
766         const Export* E = ExpPool [I];
767
768         /* Print unreferenced symbols only if explictly requested */
769         if (VerboseMap || E->ImpCount > 0 || SYM_IS_CONDES (E->Type)) {
770             fprintf (F,
771                      "%-25s %06lX %c%c%c%c   ",
772                      GetString (E->Name),
773                      GetExportVal (E),
774                      E->ImpCount? 'R' : ' ',
775                      SYM_IS_LABEL (E->Type)? 'L' : 'E',
776                      GetAddrSizeCode (E->AddrSize),
777                      SYM_IS_CONDES (E->Type)? 'I' : ' ');
778             if (++Count == 2) {
779                 Count = 0;
780                 fprintf (F, "\n");
781             }
782         }
783     }
784     fprintf (F, "\n");
785 }
786
787
788
789 void PrintImportMap (FILE* F)
790 /* Print an import map to the given file */
791 {
792     unsigned I;
793     const Import* Imp;
794
795     /* Loop over all exports */
796     for (I = 0; I < ExpCount; ++I) {
797
798         /* Get the export */
799         const Export* Exp = ExpPool [I];
800
801         /* Print the symbol only if there are imports, or if a verbose map
802          * file is requested.
803          */
804         if (VerboseMap || Exp->ImpCount > 0) {
805
806             /* Print the export */
807             fprintf (F,
808                      "%s (%s):\n",
809                      GetString (Exp->Name),
810                      GetObjFileName (Exp->Obj));
811
812             /* Print all imports for this symbol */
813             Imp = Exp->ImpList;
814             while (Imp) {
815
816                 /* Print the import */
817                 fprintf (F,
818                          "    %-25s %s(%lu)\n",
819                          GetObjFileName (Imp->Obj),
820                          GetSourceFileName (Imp->Obj, Imp->Pos.Name),
821                          Imp->Pos.Line);
822
823                 /* Next import */
824                 Imp = Imp->Next;
825             }
826         }
827     }
828     fprintf (F, "\n");
829 }
830
831
832
833 void PrintExportLabels (FILE* F)
834 /* Print the exports in a VICE label file */
835 {
836     unsigned I;
837
838     /* Print all exports */
839     for (I = 0; I < ExpCount; ++I) {
840         const Export* E = ExpPool [I];
841         fprintf (F, "al %06lX .%s\n", GetExportVal (E), GetString (E->Name));
842     }
843 }
844
845
846
847 void MarkExport (Export* E)
848 /* Mark the export */
849 {
850     E->Flags |= EXP_USERMARK;
851 }
852
853
854
855 void UnmarkExport (Export* E)
856 /* Remove the mark from the export */
857 {
858     E->Flags &= ~EXP_USERMARK;
859 }
860
861
862
863 int ExportHasMark (Export* E)
864 /* Return true if the export has a mark */
865 {
866     return (E->Flags & EXP_USERMARK) != 0;
867 }
868
869
870
871 void CircularRefError (const Export* E)
872 /* Print an error about a circular reference using to define the given export */
873 {
874     Error ("Circular reference for symbol `%s', %s(%lu)",
875            GetString (E->Name),
876            GetSourceFileName (E->Obj, E->Pos.Name),
877            E->Pos.Line);
878 }
879
880
881
882