]> git.sur5r.net Git - cc65/blob - src/ld65/condes.c
Working on the condes feature
[cc65] / src / ld65 / condes.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 condes.h                                  */
4 /*                                                                           */
5 /*                   Module constructor/destructor support                   */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2000      Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@musoftware.de                                            */
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 /* common */
37 #include "check.h"
38 #include "coll.h"
39 #include "xmalloc.h"
40
41 /* ld65 */
42 #include "exports.h"
43 #include "segments.h"
44 #include "condes.h"
45
46
47
48 /*****************************************************************************/
49 /*                                   Data                                    */
50 /*****************************************************************************/
51
52
53
54 /* Struct describing one condes type */
55 typedef struct ConDesDesc ConDesDesc;
56 struct ConDesDesc {
57     Collection          ExpList;        /* List of exported symbols */
58     char*               Label;          /* Name of table label */
59     char*               SegName;        /* Name of segment the table is in */
60     unsigned char       Enable;         /* Table enabled */
61 };
62
63 /* Array for all types */
64 static ConDesDesc ConDes[CD_TYPE_COUNT] = {
65     { STATIC_COLLECTION_INITIALIZER, 0, 0, 0 },
66     { STATIC_COLLECTION_INITIALIZER, 0, 0, 0 },
67     { STATIC_COLLECTION_INITIALIZER, 0, 0, 0 },
68     { STATIC_COLLECTION_INITIALIZER, 0, 0, 0 },
69     { STATIC_COLLECTION_INITIALIZER, 0, 0, 0 },
70     { STATIC_COLLECTION_INITIALIZER, 0, 0, 0 },
71     { STATIC_COLLECTION_INITIALIZER, 0, 0, 0 },
72 };
73
74
75
76 /*****************************************************************************/
77 /*                                   Code                                    */
78 /*****************************************************************************/
79
80
81
82 void ConDesAddExport (struct Export* E)
83 /* Add the given export to the list of constructors/destructor */
84 {
85     unsigned Type;
86
87     /* Insert the export into all tables for which declarations exist */
88     for (Type = 0; Type < CD_TYPE_COUNT; ++Type) {
89         unsigned Prio = E->ConDes[Type];
90         if (Prio != CD_PRIO_NONE) {
91             CollAppend (&ConDes[Type].ExpList, E);
92         }
93     }
94 }
95
96
97
98 void ConDesSetSegName (unsigned Type, const char* SegName)
99 /* Set the segment name where the table should go */
100 {
101     /* Check the parameters */
102     PRECONDITION (Type >= CD_TYPE_MIN && Type <= CD_TYPE_MAX && SegName != 0);
103
104     /* Setting the segment name twice is bad */
105     CHECK (ConDes[Type].SegName == 0);
106
107     /* Set the name */
108     ConDes[Type].SegName = xstrdup (SegName);
109 }
110
111
112
113 void ConDesSetLabel (unsigned Type, const char* Name)
114 /* Set the label for the given ConDes type */
115 {
116     /* Check the parameters */
117     PRECONDITION (Type >= CD_TYPE_MIN && Type <= CD_TYPE_MAX && Name != 0);
118
119     /* Setting the label twice is bad */
120     CHECK (ConDes[Type].Label == 0);
121
122     /* Set the name */
123     ConDes[Type].Label = xstrdup (Name);
124 }
125
126
127
128 const char* ConDesGetSegName (unsigned Type)
129 /* Return the segment name for the given ConDes type */
130 {
131     /* Check the parameters */
132     PRECONDITION (Type >= CD_TYPE_MIN && Type <= CD_TYPE_MAX);
133
134     /* Return the name */
135     return ConDes[Type].SegName;
136 }
137
138
139
140 const char* ConDesGetLabel (unsigned Type)
141 /* Return the label for the given ConDes type */
142 {
143     /* Check the parameters */
144     PRECONDITION (Type >= CD_TYPE_MIN && Type <= CD_TYPE_MAX);
145
146     /* Return the name */
147     return ConDes[Type].Label;
148 }
149
150
151
152 int ConDesHasSegName (unsigned Type)
153 /* Return true if a segment name is already defined for this ConDes type */
154 {
155     return (ConDesGetSegName(Type) != 0);
156 }
157
158
159
160 int ConDesHasLabel (unsigned Type)
161 /* Return true if a label is already defined for this ConDes type */
162 {
163     return (ConDesGetLabel(Type) != 0);
164 }
165
166
167
168 void ConDesCreate (void)
169 /* Create the condes tables if requested */
170 {
171 }
172
173
174
175 void ConDesDump (void)
176 /* Dump ConDes data to stdout for debugging */
177 {
178     unsigned Type;
179     for (Type = 0; Type < CD_TYPE_COUNT; ++Type) {
180         Collection* ExpList = &ConDes[Type].ExpList;
181         printf ("CONDES(%u): %u symbols\n", Type, CollCount (ExpList));
182     }
183 }
184
185
186
187
188