]> git.sur5r.net Git - cc65/blob - src/ld65/exports.c
Reworked and improved the SYMBOLS section. The old syntax (using symbol =
[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     InitFilePos (&E->Pos);
294     E->Type     = Type;
295     E->AddrSize = AddrSize;
296     memset (E->ConDes, 0, sizeof (E->ConDes));
297
298     /* Return the new entry */
299     return E;
300 }
301
302
303
304 void FreeExport (Export* E)
305 /* Free an export. NOTE: This won't remove the export from the exports table,
306  * so it may only be called for unused exports (exports from modules that
307  * aren't referenced).
308  */
309 {
310     /* Safety */
311     PRECONDITION ((E->Flags & EXP_INLIST) == 0);
312
313     /* Free the export expression */
314     FreeExpr (E->Expr);
315
316     /* Free the struct */
317     xfree (E);
318 }
319
320
321
322 void InsertExport (Export* E)
323 /* Insert an exported identifier and check if it's already in the list */
324 {
325     Export* L;
326     Export* Last;
327     Import* Imp;
328     unsigned Hash;
329
330     /* Mark the export as inserted */
331     E->Flags |= EXP_INLIST;
332
333     /* Insert the export into any condes tables if needed */
334     if (SYM_IS_CONDES (E->Type)) {
335         ConDesAddExport (E);
336     }
337
338     /* Create a hash value for the given name */
339     Hash = (E->Name & HASHTAB_MASK);
340
341     /* Search through the list in that slot */
342     if (HashTab[Hash] == 0) {
343         /* The slot is empty */
344         HashTab[Hash] = E;
345         ++ExpCount;
346     } else {
347
348         Last = 0;
349         L = HashTab[Hash];
350         do {
351             if (L->Name == E->Name) {
352                 /* This may be an unresolved external */
353                 if (L->Expr == 0) {
354
355                     /* This *is* an unresolved external. Use the actual export
356                      * in E instead of the dummy one in L.
357                      */
358                     E->Next     = L->Next;
359                     E->ImpCount = L->ImpCount;
360                     E->ImpList  = L->ImpList;
361                     if (Last) {
362                         Last->Next = E;
363                     } else {
364                         HashTab[Hash] = E;
365                     }
366                     ImpOpen -= E->ImpCount;     /* Decrease open imports now */
367                     xfree (L);
368                     /* We must run through the import list and change the
369                      * export pointer now.
370                      */
371                     Imp = E->ImpList;
372                     while (Imp) {
373                         Imp->Exp = E;
374                         Imp = Imp->Next;
375                     }
376                 } else {
377                     /* Duplicate entry, ignore it */
378                     Warning ("Duplicate external identifier: `%s'",
379                              GetString (L->Name));
380                 }
381                 return;
382             }
383             Last = L;
384             L = L->Next;
385
386         } while (L);
387
388         /* Insert export at end of queue */
389         Last->Next = E;
390         ++ExpCount;
391     }
392 }
393
394
395
396 Export* ReadExport (FILE* F, ObjData* O)
397 /* Read an export from a file */
398 {
399     unsigned      ConDesCount;
400     Export* E;
401
402     /* Read the type */
403     unsigned char Type = ReadVar (F);
404
405     /* Read the address size */
406     unsigned char AddrSize = Read8 (F);
407
408     /* Create a new export without a name */
409     E = NewExport (Type, AddrSize, INVALID_STRING_ID, O);
410
411     /* Read the constructor/destructor decls if we have any */
412     ConDesCount = SYM_GET_CONDES_COUNT (Type);
413     if (ConDesCount > 0) {
414
415         unsigned char ConDes[CD_TYPE_COUNT];
416         unsigned I;
417
418         /* Read the data into temp storage */
419         ReadData (F, ConDes, ConDesCount);
420
421         /* Re-order the data. In the file, each decl is encoded into a byte
422          * which contains the type and the priority. In memory, we will use
423          * an array of types which contain the priority. This array was
424          * cleared by the constructor (NewExport), so we must only set the
425          * fields that contain values.
426          */
427         for (I = 0; I < ConDesCount; ++I) {
428             unsigned ConDesType = CD_GET_TYPE (ConDes[I]);
429             unsigned ConDesPrio = CD_GET_PRIO (ConDes[I]);
430             E->ConDes[ConDesType] = ConDesPrio;
431         }
432     }
433
434     /* Read the name */
435     E->Name = MakeGlobalStringId (O, ReadVar (F));
436
437     /* Read the value */
438     if (SYM_IS_EXPR (Type)) {
439         E->Expr = ReadExpr (F, O);
440     } else {
441         E->Expr = LiteralExpr (Read32 (F), O);
442     }
443
444     /* Last is the file position where the definition was done */
445     ReadFilePos (F, &E->Pos);
446
447     /* Return the new export */
448     return E;
449 }
450
451
452
453 Export* CreateConstExport (unsigned Name, long Value)
454 /* Create an export for a literal date */
455 {
456     /* Create a new export */
457     Export* E = NewExport (SYM_CONST | SYM_EQUATE, ADDR_SIZE_ABS, Name, 0);
458
459     /* Assign the value */
460     E->Expr = LiteralExpr (Value, 0);
461
462     /* Insert the export */
463     InsertExport (E);
464
465     /* Return the new export */
466     return E;
467 }
468
469
470
471 Export* CreateExprExport (unsigned Name, ExprNode* Expr, unsigned char AddrSize)
472 /* Create an export for an expression */
473 {
474     /* Create a new export */
475     Export* E = NewExport (SYM_EXPR | SYM_EQUATE, AddrSize, Name, 0);
476
477     /* Assign the value expression */
478     E->Expr = Expr;
479
480     /* Insert the export */
481     InsertExport (E);
482
483     /* Return the new export */
484     return E;
485 }
486
487
488
489 Export* CreateMemoryExport (unsigned Name, MemoryArea* Mem, unsigned long Offs)
490 /* Create an relative export for a memory area offset */
491 {
492     /* Create a new export */
493     Export* E = NewExport (SYM_EXPR | SYM_LABEL, ADDR_SIZE_ABS, Name, 0);
494
495     /* Assign the value */
496     E->Expr = MemoryExpr (Mem, Offs, 0);
497
498     /* Insert the export */
499     InsertExport (E);
500
501     /* Return the new export */
502     return E;
503 }
504
505
506
507 Export* CreateSegmentExport (unsigned Name, Segment* Seg, unsigned long Offs)
508 /* Create a relative export to a segment */
509 {
510     /* Create a new export */
511     Export* E = NewExport (SYM_EXPR | SYM_LABEL, Seg->AddrSize, Name, 0);
512
513     /* Assign the value */
514     E->Expr = SegmentExpr (Seg, Offs, 0);
515
516     /* Insert the export */
517     InsertExport (E);
518
519     /* Return the new export */
520     return E;
521 }
522
523
524
525 Export* CreateSectionExport (unsigned Name, Section* Sec, unsigned long Offs)
526 /* Create a relative export to a section */
527 {
528     /* Create a new export */
529     Export* E = NewExport (SYM_EXPR | SYM_LABEL, Sec->AddrSize, Name, 0);
530
531     /* Assign the value */
532     E->Expr = SectionExpr (Sec, Offs, 0);
533
534     /* Insert the export */
535     InsertExport (E);
536
537     /* Return the new export */
538     return E;
539 }
540
541
542
543 Export* FindExport (unsigned Name)
544 /* Check for an identifier in the list. Return 0 if not found, otherwise
545  * return a pointer to the export.
546  */
547 {
548     /* Get a pointer to the list with the symbols hash value */
549     Export* L = HashTab[Name & HASHTAB_MASK];
550     while (L) {
551         /* Search through the list in that slot */
552         if (L->Name == Name) {
553             /* Entry found */
554             return L;
555         }
556         L = L->Next;
557     }
558
559     /* Not found */
560     return 0;
561 }
562
563
564
565 int IsUnresolved (unsigned Name)
566 /* Check if this symbol is an unresolved export */
567 {
568     /* Find the export */
569     return IsUnresolvedExport (FindExport (Name));
570 }
571
572
573
574 int IsUnresolvedExport (const Export* E)
575 /* Return true if the given export is unresolved */
576 {
577     /* Check if it's unresolved */
578     return E != 0 && E->Expr == 0;
579 }
580
581
582
583 int IsConstExport (const Export* E)
584 /* Return true if the expression associated with this export is const */
585 {
586     if (E->Expr == 0) {
587         /* External symbols cannot be const */
588         return 0;
589     } else {
590         return IsConstExpr (E->Expr);
591     }
592 }
593
594
595
596 long GetExportVal (const Export* E)
597 /* Get the value of this export */
598 {
599     if (E->Expr == 0) {
600         /* OOPS */
601         Internal ("`%s' is an undefined external", GetString (E->Name));
602     }
603     return GetExprVal (E->Expr);
604 }
605
606
607
608 static void CheckSymType (const Export* E)
609 /* Check the types for one export */
610 {
611     /* External with matching imports */
612     Import* I = E->ImpList;
613     while (I) {
614         if (E->AddrSize != I->AddrSize) {
615             /* Export and import address sizes do not match */
616             StrBuf ExportLoc = STATIC_STRBUF_INITIALIZER;
617             StrBuf ImportLoc = STATIC_STRBUF_INITIALIZER;
618             const char* ExpAddrSize = AddrSizeToStr (E->AddrSize);
619             const char* ImpAddrSize = AddrSizeToStr (I->AddrSize);
620
621             /* Generate strings that describe the location of the im- and
622              * exports. This depends on the place from where they come:
623              * Object file or linker config.
624              */
625             if (E->Obj) {
626                 /* The export comes from an object file */
627                 SB_Printf (&ExportLoc, "%s, %s(%lu)",
628                            GetString (E->Obj->Name),
629                            GetSourceFileName (E->Obj, E->Pos.Name),
630                            E->Pos.Line);
631             } else {
632                 SB_Printf (&ExportLoc, "%s(%lu)",
633                            GetSourceFileName (E->Obj, E->Pos.Name),
634                            E->Pos.Line);
635             }
636             if (I->Obj) {
637                 /* The import comes from an object file */
638                 SB_Printf (&ImportLoc, "%s, %s(%lu)",
639                            GetString (I->Obj->Name),
640                            GetSourceFileName (I->Obj, I->Pos.Name),
641                            I->Pos.Line);
642             } else {
643                 SB_Printf (&ImportLoc, "%s(%lu)",
644                            GetSourceFileName (I->Obj, I->Pos.Name),
645                            I->Pos.Line);
646             }
647
648             /* Output the diagnostic */
649             Warning ("Address size mismatch for `%s': "
650                      "Exported from %s as `%s', "
651                      "import in %s as `%s'",
652                      GetString (E->Name),
653                      SB_GetConstBuf (&ExportLoc),
654                      ExpAddrSize,
655                      SB_GetConstBuf (&ImportLoc),
656                      ImpAddrSize);
657
658             /* Free the temporary strings */
659             SB_Done (&ExportLoc);
660             SB_Done (&ImportLoc);
661         }
662         I = I->Next;
663     }
664 }
665
666
667
668 static void CheckSymTypes (void)
669 /* Check for symbol tape mismatches */
670 {
671     unsigned I;
672
673     /* Print all open imports */
674     for (I = 0; I < ExpCount; ++I) {
675         const Export* E = ExpPool [I];
676         if (E->Expr != 0 && E->ImpCount > 0) {
677             /* External with matching imports */
678             CheckSymType (E);
679         }
680     }
681 }
682
683
684
685 static void PrintUnresolved (ExpCheckFunc F, void* Data)
686 /* Print a list of unresolved symbols. On unresolved symbols, F is
687  * called (see the comments on ExpCheckFunc in the data section).
688  */
689 {
690     unsigned I;
691
692     /* Print all open imports */
693     for (I = 0; I < ExpCount; ++I) {
694         Export* E = ExpPool [I];
695         if (E->Expr == 0 && E->ImpCount > 0 && F (E->Name, Data) == 0) {
696             /* Unresolved external */
697             Import* Imp = E->ImpList;
698             fprintf (stderr,
699                      "Unresolved external `%s' referenced in:\n",
700                      GetString (E->Name));
701             while (Imp) {
702                 const char* Name = GetSourceFileName (Imp->Obj, Imp->Pos.Name);
703                 fprintf (stderr, "  %s(%lu)\n", Name, Imp->Pos.Line);
704                 Imp = Imp->Next;
705             }
706         }
707     }
708 }
709
710
711
712 static int CmpExpName (const void* K1, const void* K2)
713 /* Compare function for qsort */
714 {
715     return SB_Compare (GetStrBuf ((*(Export**)K1)->Name),
716                        GetStrBuf ((*(Export**)K2)->Name));
717 }
718
719
720
721 static void CreateExportPool (void)
722 /* Create an array with pointer to all exports */
723 {
724     unsigned I, J;
725
726     /* Allocate memory */
727     if (ExpPool) {
728         xfree (ExpPool);
729     }
730     ExpPool = xmalloc (ExpCount * sizeof (Export*));
731
732     /* Walk through the list and insert the exports */
733     for (I = 0, J = 0; I < sizeof (HashTab) / sizeof (HashTab [0]); ++I) {
734         Export* E = HashTab[I];
735         while (E) {
736             CHECK (J < ExpCount);
737             ExpPool[J++] = E;
738             E = E->Next;
739         }
740     }
741
742     /* Sort them by name */
743     qsort (ExpPool, ExpCount, sizeof (Export*), CmpExpName);
744 }
745
746
747
748 void CheckExports (void)
749 /* Setup the list of all exports and check for export/import symbol type
750  * mismatches.
751  */
752 {
753     /* Create an export pool */
754     CreateExportPool ();
755
756     /* Check for symbol type mismatches */
757     CheckSymTypes ();
758 }
759
760
761
762 void CheckUnresolvedImports (ExpCheckFunc F, void* Data)
763 /* Check if there are any unresolved imports. On unresolved imports, F is
764  * called (see the comments on ExpCheckFunc in the data section).
765  */
766 {
767     /* Check for unresolved externals */
768     if (ImpOpen != 0) {
769         /* Print all open imports */
770         PrintUnresolved (F, Data);
771     }
772 }
773
774
775
776 static char GetAddrSizeCode (unsigned char AddrSize)
777 /* Get a one char code for the address size */
778 {
779     switch (AddrSize) {
780         case ADDR_SIZE_ZP:      return 'Z';
781         case ADDR_SIZE_ABS:     return 'A';
782         case ADDR_SIZE_FAR:     return 'F';
783         case ADDR_SIZE_LONG:    return 'L';
784         default:
785             Internal ("Invalid address size: %u", AddrSize);
786             /* NOTREACHED */
787             return '-';
788     }
789 }
790
791
792
793 void PrintExportMap (FILE* F)
794 /* Print an export map to the given file */
795 {
796     unsigned I;
797     unsigned Count;
798
799     /* Print all exports */
800     Count = 0;
801     for (I = 0; I < ExpCount; ++I) {
802         const Export* E = ExpPool [I];
803
804         /* Print unreferenced symbols only if explictly requested */
805         if (VerboseMap || E->ImpCount > 0 || SYM_IS_CONDES (E->Type)) {
806             fprintf (F,
807                      "%-25s %06lX %c%c%c%c   ",
808                      GetString (E->Name),
809                      GetExportVal (E),
810                      E->ImpCount? 'R' : ' ',
811                      SYM_IS_LABEL (E->Type)? 'L' : 'E',
812                      GetAddrSizeCode (E->AddrSize),
813                      SYM_IS_CONDES (E->Type)? 'I' : ' ');
814             if (++Count == 2) {
815                 Count = 0;
816                 fprintf (F, "\n");
817             }
818         }
819     }
820     fprintf (F, "\n");
821 }
822
823
824
825 void PrintImportMap (FILE* F)
826 /* Print an import map to the given file */
827 {
828     unsigned I;
829     const Import* Imp;
830
831     /* Loop over all exports */
832     for (I = 0; I < ExpCount; ++I) {
833
834         /* Get the export */
835         const Export* Exp = ExpPool [I];
836
837         /* Print the symbol only if there are imports, or if a verbose map
838          * file is requested.
839          */
840         if (VerboseMap || Exp->ImpCount > 0) {
841
842             /* Print the export */
843             fprintf (F,
844                      "%s (%s):\n",
845                      GetString (Exp->Name),
846                      GetObjFileName (Exp->Obj));
847
848             /* Print all imports for this symbol */
849             Imp = Exp->ImpList;
850             while (Imp) {
851
852                 /* Print the import */
853                 fprintf (F,
854                          "    %-25s %s(%lu)\n",
855                          GetObjFileName (Imp->Obj),
856                          GetSourceFileName (Imp->Obj, Imp->Pos.Name),
857                          Imp->Pos.Line);
858
859                 /* Next import */
860                 Imp = Imp->Next;
861             }
862         }
863     }
864     fprintf (F, "\n");
865 }
866
867
868
869 void PrintExportLabels (FILE* F)
870 /* Print the exports in a VICE label file */
871 {
872     unsigned I;
873
874     /* Print all exports */
875     for (I = 0; I < ExpCount; ++I) {
876         const Export* E = ExpPool [I];
877         fprintf (F, "al %06lX .%s\n", GetExportVal (E), GetString (E->Name));
878     }
879 }
880
881
882
883 void MarkExport (Export* E)
884 /* Mark the export */
885 {
886     E->Flags |= EXP_USERMARK;
887 }
888
889
890
891 void UnmarkExport (Export* E)
892 /* Remove the mark from the export */
893 {
894     E->Flags &= ~EXP_USERMARK;
895 }
896
897
898
899 int ExportHasMark (Export* E)
900 /* Return true if the export has a mark */
901 {
902     return (E->Flags & EXP_USERMARK) != 0;
903 }
904
905
906
907 void CircularRefError (const Export* E)
908 /* Print an error about a circular reference using to define the given export */
909 {
910     Error ("Circular reference for symbol `%s', %s(%lu)",
911            GetString (E->Name),
912            GetSourceFileName (E->Obj, E->Pos.Name),
913            E->Pos.Line);
914 }
915
916
917
918