2 |
7u83 |
1 |
/*
|
|
|
2 |
Crown Copyright (c) 1997
|
|
|
3 |
|
|
|
4 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
5 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
6 |
acting through the Defence Evaluation and Research Agency
|
|
|
7 |
(DERA). It is made available to Recipients with a
|
|
|
8 |
royalty-free licence for its use, reproduction, transfer
|
|
|
9 |
to other parties and amendment for any purpose not excluding
|
|
|
10 |
product development provided that any such use et cetera
|
|
|
11 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
12 |
|
|
|
13 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
14 |
reproduced upon any copies or amended versions of it;
|
|
|
15 |
|
|
|
16 |
(2) Any amended version of it shall be clearly marked to
|
|
|
17 |
show both the nature of and the organisation responsible
|
|
|
18 |
for the relevant amendment or amendments;
|
|
|
19 |
|
|
|
20 |
(3) Its onward transfer from a recipient to another
|
|
|
21 |
party shall be deemed to be that party's acceptance of
|
|
|
22 |
these conditions;
|
|
|
23 |
|
|
|
24 |
(4) DERA gives no warranty or assurance as to its
|
|
|
25 |
quality or suitability for any purpose and DERA accepts
|
|
|
26 |
no liability whatsoever in relation to any use to which
|
|
|
27 |
it may be put.
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
/*** shape-entry.c --- Shape table entry ADT.
|
|
|
32 |
*
|
|
|
33 |
** Author: Steve Folkes <smf@hermes.mod.uk>
|
|
|
34 |
*
|
|
|
35 |
*** Commentary:
|
|
|
36 |
*
|
|
|
37 |
* This file implements the shape table entry routines used by the TDF
|
|
|
38 |
* linker.
|
|
|
39 |
*
|
|
|
40 |
*** Change Log:
|
|
|
41 |
* $Log: shape-entry.c,v $
|
|
|
42 |
* Revision 1.1.1.1 1998/01/17 15:57:20 release
|
|
|
43 |
* First version to be checked into rolling release.
|
|
|
44 |
*
|
|
|
45 |
* Revision 1.3 1995/09/22 08:39:31 smf
|
|
|
46 |
* Fixed problems with incomplete structures (to shut "tcc" up).
|
|
|
47 |
* Fixed some problems in "name-key.c" (no real problems, but rewritten to
|
|
|
48 |
* reduce the warnings that were output by "tcc" and "gcc").
|
|
|
49 |
* Fixed bug CR95_354.tld-common-id-problem (library capsules could be loaded
|
|
|
50 |
* more than once).
|
|
|
51 |
*
|
|
|
52 |
* Revision 1.2 1994/12/12 11:46:46 smf
|
|
|
53 |
* Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
|
|
|
54 |
* OSSG C Coding Standards.
|
|
|
55 |
*
|
|
|
56 |
* Revision 1.1.1.1 1994/07/25 16:03:37 smf
|
|
|
57 |
* Initial import of TDF linker 3.5 non shared files.
|
|
|
58 |
*
|
|
|
59 |
**/
|
|
|
60 |
|
|
|
61 |
/****************************************************************************/
|
|
|
62 |
|
|
|
63 |
#include "shape-entry.h"
|
|
|
64 |
#include "debug.h"
|
|
|
65 |
#include "gen-errors.h"
|
|
|
66 |
#include "unit-table.h"
|
|
|
67 |
|
|
|
68 |
#include "solve-cycles.h"
|
|
|
69 |
|
|
|
70 |
/*--------------------------------------------------------------------------*/
|
|
|
71 |
|
|
|
72 |
ShapeEntryP
|
|
|
73 |
shape_entry_create PROTO_N ((key))
|
|
|
74 |
PROTO_T (NStringP key)
|
|
|
75 |
{
|
|
|
76 |
ShapeEntryP entry = ALLOCATE (ShapeEntryT);
|
|
|
77 |
|
|
|
78 |
entry->next = NIL (ShapeEntryP);
|
|
|
79 |
nstring_copy (shape_entry_key (entry), key);
|
|
|
80 |
entry->names = name_table_create ();
|
|
|
81 |
entry->id_count = 0;
|
|
|
82 |
entry->non_empty = FALSE;
|
|
|
83 |
entry->head = NIL (NameEntryP);
|
|
|
84 |
entry->tail = &(entry->head);
|
|
|
85 |
return (entry);
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
ShapeEntryP
|
|
|
89 |
shape_entry_next PROTO_N ((entry))
|
|
|
90 |
PROTO_T (ShapeEntryP entry)
|
|
|
91 |
{
|
|
|
92 |
return (entry->next);
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
ShapeEntryP *
|
|
|
96 |
shape_entry_next_ref PROTO_N ((entry))
|
|
|
97 |
PROTO_T (ShapeEntryP entry)
|
|
|
98 |
{
|
|
|
99 |
return (&(entry->next));
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
NStringP
|
|
|
103 |
shape_entry_key PROTO_N ((entry))
|
|
|
104 |
PROTO_T (ShapeEntryP entry)
|
|
|
105 |
{
|
|
|
106 |
return (&(entry->key));
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
NameTableP
|
|
|
110 |
shape_entry_name_table PROTO_N ((entry))
|
|
|
111 |
PROTO_T (ShapeEntryP entry)
|
|
|
112 |
{
|
|
|
113 |
return (entry->names);
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
unsigned
|
|
|
117 |
shape_entry_next_id PROTO_N ((entry))
|
|
|
118 |
PROTO_T (ShapeEntryP entry)
|
|
|
119 |
{
|
|
|
120 |
if (entry->id_count == UINT_MAX) {
|
|
|
121 |
E_too_many_ids ();
|
|
|
122 |
}
|
|
|
123 |
return (entry->id_count ++);
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
void
|
|
|
127 |
shape_entry_set_non_empty PROTO_N ((entry))
|
|
|
128 |
PROTO_T (ShapeEntryP entry)
|
|
|
129 |
{
|
|
|
130 |
entry->non_empty = TRUE;
|
|
|
131 |
}
|
|
|
132 |
|
|
|
133 |
BoolT
|
|
|
134 |
shape_entry_get_non_empty PROTO_N ((entry))
|
|
|
135 |
PROTO_T (ShapeEntryP entry)
|
|
|
136 |
{
|
|
|
137 |
return (entry->non_empty);
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
void
|
|
|
141 |
shape_entry_add_to_list PROTO_N ((entry, name_entry))
|
|
|
142 |
PROTO_T (ShapeEntryP entry X
|
|
|
143 |
NameEntryP name_entry)
|
|
|
144 |
{
|
|
|
145 |
*(entry->tail) = name_entry;
|
|
|
146 |
entry->tail = name_entry_list_next_ref (name_entry);
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
NameEntryP
|
|
|
150 |
shape_entry_get_from_list PROTO_N ((entry))
|
|
|
151 |
PROTO_T (ShapeEntryP entry)
|
|
|
152 |
{
|
|
|
153 |
NameEntryP name_entry;
|
|
|
154 |
|
|
|
155 |
if ((name_entry = entry->head) != NIL (NameEntryP)) {
|
|
|
156 |
entry->head = name_entry_list_next (name_entry);
|
|
|
157 |
if (entry->head == NIL (NameEntryP)) {
|
|
|
158 |
entry->tail = (&entry->head);
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
return (name_entry);
|
|
|
162 |
}
|
|
|
163 |
|
|
|
164 |
ShapeEntryP
|
|
|
165 |
shape_entry_deallocate PROTO_N ((entry))
|
|
|
166 |
PROTO_T (ShapeEntryP entry)
|
|
|
167 |
{
|
|
|
168 |
ShapeEntryP next = shape_entry_next (entry);
|
|
|
169 |
|
|
|
170 |
nstring_destroy (shape_entry_key (entry));
|
|
|
171 |
name_table_deallocate (shape_entry_name_table (entry));
|
|
|
172 |
DEALLOCATE (entry);
|
|
|
173 |
return (next);
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
/*--------------------------------------------------------------------------*/
|
|
|
177 |
|
|
|
178 |
void
|
|
|
179 |
shape_entry_do_count PROTO_N ((entry, gclosure))
|
|
|
180 |
PROTO_T (ShapeEntryP entry X
|
|
|
181 |
GenericP gclosure)
|
|
|
182 |
{
|
|
|
183 |
unsigned *count_ref = (unsigned *) gclosure;
|
|
|
184 |
|
|
|
185 |
if ((entry->id_count > 0) || (shape_entry_get_non_empty (entry))) {
|
|
|
186 |
shape_entry_set_non_empty (entry);
|
|
|
187 |
(*count_ref) ++;
|
|
|
188 |
}
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
void
|
|
|
192 |
shape_entry_write_shape PROTO_N ((entry, gclosure))
|
|
|
193 |
PROTO_T (ShapeEntryP entry X
|
|
|
194 |
GenericP gclosure)
|
|
|
195 |
{
|
|
|
196 |
if (shape_entry_get_non_empty (entry)) {
|
|
|
197 |
TDFWriterP writer = (TDFWriterP) gclosure;
|
|
|
198 |
NStringP key = shape_entry_key (entry);
|
|
|
199 |
unsigned num_ids = entry->id_count;
|
|
|
200 |
|
|
|
201 |
debug_info_w_shape (key, num_ids);
|
|
|
202 |
tdf_write_string (writer, key);
|
|
|
203 |
tdf_write_int (writer, num_ids);
|
|
|
204 |
}
|
|
|
205 |
}
|
|
|
206 |
|
|
|
207 |
void
|
|
|
208 |
shape_entry_write_externs PROTO_N ((entry, gclosure))
|
|
|
209 |
PROTO_T (ShapeEntryP entry X
|
|
|
210 |
GenericP gclosure)
|
|
|
211 |
{
|
|
|
212 |
if (shape_entry_get_non_empty (entry)) {
|
|
|
213 |
TDFWriterP writer = (TDFWriterP) gclosure;
|
|
|
214 |
unsigned num_externs = 0;
|
|
|
215 |
NameTableP table = entry->names;
|
|
|
216 |
NStringP key = shape_entry_key (entry);
|
|
|
217 |
|
|
|
218 |
name_table_iter (table, name_entry_do_count, (GenericP) &num_externs);
|
|
|
219 |
debug_info_w_start_shape_names (key, num_externs);
|
|
|
220 |
tdf_write_int (writer, num_externs);
|
|
|
221 |
name_table_iter (table, name_entry_write_name, (GenericP) writer);
|
|
|
222 |
}
|
|
|
223 |
}
|
|
|
224 |
|
|
|
225 |
void
|
|
|
226 |
shape_entry_compute_tld_size PROTO_N ((entry, gclosure))
|
|
|
227 |
PROTO_T (ShapeEntryP entry X
|
|
|
228 |
GenericP gclosure)
|
|
|
229 |
{
|
|
|
230 |
if (shape_entry_get_non_empty (entry)) {
|
|
|
231 |
name_table_iter (entry->names, name_entry_compute_tld_size, gclosure);
|
|
|
232 |
}
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
void
|
|
|
236 |
shape_entry_write_tld PROTO_N ((entry, gclosure))
|
|
|
237 |
PROTO_T (ShapeEntryP entry X
|
|
|
238 |
GenericP gclosure)
|
|
|
239 |
{
|
|
|
240 |
if (shape_entry_get_non_empty (entry)) {
|
|
|
241 |
debug_info_w_start_usages (shape_entry_key (entry));
|
|
|
242 |
name_table_iter (entry->names, name_entry_write_tld, gclosure);
|
|
|
243 |
}
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
void
|
|
|
247 |
shape_entry_write_count PROTO_N ((entry, gclosure))
|
|
|
248 |
PROTO_T (ShapeEntryP entry X
|
|
|
249 |
GenericP gclosure)
|
|
|
250 |
{
|
|
|
251 |
ShapeClosureP closure = (ShapeClosureP) gclosure;
|
|
|
252 |
|
|
|
253 |
if (shape_entry_get_non_empty (entry)) {
|
|
|
254 |
MapTableP table = closure->table;
|
|
|
255 |
TDFWriterP writer = closure->writer;
|
|
|
256 |
MapEntryP map_entry = map_table_get (table, shape_entry_key (entry));
|
|
|
257 |
unsigned count = (map_entry ? map_entry_get_count (map_entry) :
|
|
|
258 |
0);
|
|
|
259 |
NStringP key = shape_entry_key (entry);
|
|
|
260 |
|
|
|
261 |
debug_info_w_count (count, key);
|
|
|
262 |
tdf_write_int (writer, count);
|
|
|
263 |
}
|
|
|
264 |
}
|
|
|
265 |
|
|
|
266 |
void
|
|
|
267 |
shape_entry_write_links PROTO_N ((entry, gclosure))
|
|
|
268 |
PROTO_T (ShapeEntryP entry X
|
|
|
269 |
GenericP gclosure)
|
|
|
270 |
{
|
|
|
271 |
ShapeClosureP closure = (ShapeClosureP) gclosure;
|
|
|
272 |
|
|
|
273 |
if (shape_entry_get_non_empty (entry)) {
|
|
|
274 |
MapTableP table = closure->table;
|
|
|
275 |
TDFWriterP writer = closure->writer;
|
|
|
276 |
MapEntryP map_entry = map_table_get (table, shape_entry_key (entry));
|
|
|
277 |
NStringP key = shape_entry_key (entry);
|
|
|
278 |
|
|
|
279 |
if (map_entry) {
|
|
|
280 |
unsigned num_links = map_entry_get_num_links (map_entry);
|
|
|
281 |
unsigned i;
|
|
|
282 |
|
|
|
283 |
debug_info_w_start_shape_maps (key, num_links);
|
|
|
284 |
tdf_write_int (writer, num_links);
|
|
|
285 |
for (i = 0; i < num_links; i ++) {
|
|
|
286 |
unsigned internal;
|
|
|
287 |
unsigned external;
|
|
|
288 |
|
|
|
289 |
map_entry_get_link (map_entry, i , &internal, &external);
|
|
|
290 |
debug_info_w_map (internal, external);
|
|
|
291 |
tdf_write_int (writer, internal);
|
|
|
292 |
tdf_write_int (writer, external);
|
|
|
293 |
}
|
|
|
294 |
} else {
|
|
|
295 |
debug_info_w_start_shape_maps (key, (unsigned) 0);
|
|
|
296 |
tdf_write_int (writer, (unsigned) 0);
|
|
|
297 |
}
|
|
|
298 |
}
|
|
|
299 |
}
|
|
|
300 |
|
|
|
301 |
void
|
|
|
302 |
shape_entry_check_multi_defs PROTO_N ((entry, gclosure))
|
|
|
303 |
PROTO_T (ShapeEntryP entry X
|
|
|
304 |
GenericP gclosure)
|
|
|
305 |
{
|
|
|
306 |
NameTableP table = shape_entry_name_table (entry);
|
|
|
307 |
NStringP key = shape_entry_key (entry);
|
|
|
308 |
|
|
|
309 |
UNUSED (gclosure);
|
|
|
310 |
name_table_iter (table, name_entry_check_multi_defs, (GenericP) key);
|
|
|
311 |
}
|
|
|
312 |
|
|
|
313 |
void
|
|
|
314 |
shape_entry_do_lib_count PROTO_N ((entry, gclosure))
|
|
|
315 |
PROTO_T (ShapeEntryP entry X
|
|
|
316 |
GenericP gclosure)
|
|
|
317 |
{
|
|
|
318 |
NameTableP table = shape_entry_name_table (entry);
|
|
|
319 |
unsigned num_names = 0;
|
|
|
320 |
|
|
|
321 |
name_table_iter (table, name_entry_do_lib_count, (GenericP) &num_names);
|
|
|
322 |
if (num_names > 0) {
|
|
|
323 |
unsigned *num_shapes_ref = (unsigned *) gclosure;
|
|
|
324 |
|
|
|
325 |
(*num_shapes_ref) ++;
|
|
|
326 |
}
|
|
|
327 |
entry->num_lib_names = num_names;
|
|
|
328 |
}
|
|
|
329 |
|
|
|
330 |
void
|
|
|
331 |
shape_entry_do_lib_write PROTO_N ((entry, gclosure))
|
|
|
332 |
PROTO_T (ShapeEntryP entry X
|
|
|
333 |
GenericP gclosure)
|
|
|
334 |
{
|
|
|
335 |
unsigned num_names = entry->num_lib_names;
|
|
|
336 |
|
|
|
337 |
if (num_names > 0) {
|
|
|
338 |
TDFWriterP writer = (TDFWriterP) gclosure;
|
|
|
339 |
NameTableP table = shape_entry_name_table (entry);
|
|
|
340 |
NStringP key = shape_entry_key (entry);
|
|
|
341 |
|
|
|
342 |
debug_info_w_start_shape_index (key, num_names);
|
|
|
343 |
tdf_write_string (writer, shape_entry_key (entry));
|
|
|
344 |
tdf_write_int (writer, num_names);
|
|
|
345 |
name_table_iter (table, name_entry_do_lib_write, gclosure);
|
|
|
346 |
}
|
|
|
347 |
}
|
|
|
348 |
|
|
|
349 |
void
|
|
|
350 |
shape_entry_resolve_undefined PROTO_N ((entry, gclosure))
|
|
|
351 |
PROTO_T (ShapeEntryP entry X
|
|
|
352 |
GenericP gclosure)
|
|
|
353 |
{
|
|
|
354 |
ShapeLibClosureP closure = (ShapeLibClosureP) gclosure;
|
|
|
355 |
NStringP key = shape_entry_key (entry);
|
|
|
356 |
ShapeEntryP lib_entry = shape_table_get (closure->lib_shapes, key);
|
|
|
357 |
NameTableP table = ((lib_entry != NIL (ShapeEntryP)) ?
|
|
|
358 |
shape_entry_name_table (lib_entry) :
|
|
|
359 |
NIL (NameTableP));
|
|
|
360 |
NameEntryP name_entry;
|
|
|
361 |
|
|
|
362 |
while ((name_entry = shape_entry_get_from_list (entry)) !=
|
|
|
363 |
NIL (NameEntryP)) {
|
|
|
364 |
if (name_entry_resolve_undefined (name_entry, table, closure->units,
|
|
|
365 |
closure->shapes, key)) {
|
|
|
366 |
closure->did_define = TRUE;
|
|
|
367 |
}
|
|
|
368 |
}
|
|
|
369 |
}
|
|
|
370 |
|
|
|
371 |
void
|
|
|
372 |
shape_entry_hide_all_defd PROTO_N ((entry, gclosure))
|
|
|
373 |
PROTO_T (ShapeEntryP entry X
|
|
|
374 |
GenericP gclosure)
|
|
|
375 |
{
|
|
|
376 |
NameTableP table = shape_entry_name_table (entry);
|
|
|
377 |
NStringP shape = shape_entry_key (entry);
|
|
|
378 |
|
|
|
379 |
UNUSED (gclosure);
|
|
|
380 |
name_table_iter (table, name_entry_hide_defd, (GenericP) shape);
|
|
|
381 |
}
|
|
|
382 |
|
|
|
383 |
void
|
|
|
384 |
shape_entry_suppress_mult PROTO_N ((entry, gclosure))
|
|
|
385 |
PROTO_T (ShapeEntryP entry X
|
|
|
386 |
GenericP gclosure)
|
|
|
387 |
{
|
|
|
388 |
NameTableP table = shape_entry_name_table (entry);
|
|
|
389 |
NStringP shape = shape_entry_key (entry);
|
|
|
390 |
|
|
|
391 |
UNUSED (gclosure);
|
|
|
392 |
name_table_iter (table, name_entry_suppress_mult, (GenericP) shape);
|
|
|
393 |
}
|
|
|
394 |
|
|
|
395 |
void
|
|
|
396 |
shape_entry_lib_suppress_mult PROTO_N ((entry, gclosure))
|
|
|
397 |
PROTO_T (ShapeEntryP entry X
|
|
|
398 |
GenericP gclosure)
|
|
|
399 |
{
|
|
|
400 |
NameTableP table = shape_entry_name_table (entry);
|
|
|
401 |
NStringP shape = shape_entry_key (entry);
|
|
|
402 |
|
|
|
403 |
UNUSED (gclosure);
|
|
|
404 |
name_table_iter (table, name_entry_lib_suppress_mult, (GenericP) shape);
|
|
|
405 |
}
|
|
|
406 |
|
|
|
407 |
void
|
|
|
408 |
shape_entry_show_content PROTO_N ((entry, gclosure))
|
|
|
409 |
PROTO_T (ShapeEntryP entry X
|
|
|
410 |
GenericP gclosure)
|
|
|
411 |
{
|
|
|
412 |
UNUSED (gclosure);
|
|
|
413 |
write_nstring (ostream_output, shape_entry_key (entry));
|
|
|
414 |
write_char (ostream_output, ':');
|
|
|
415 |
write_newline (ostream_output);
|
|
|
416 |
name_table_iter (shape_entry_name_table (entry), name_entry_show_content,
|
|
|
417 |
NIL (GenericP));
|
|
|
418 |
}
|
|
|
419 |
|
|
|
420 |
/*
|
|
|
421 |
* Local variables(smf):
|
|
|
422 |
* eval: (include::add-path-entry "../os-interface" "../library")
|
|
|
423 |
* eval: (include::add-path-entry "../generated")
|
|
|
424 |
* end:
|
|
|
425 |
**/
|