Subversion Repositories tendra.SVN

Rev

Rev 5 | Details | Compare with Previous | Last modification | View Log | RSS feed

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