Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
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
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
29
 
59
 
30
 
60
 
31
/**** linker.c --- Front end to linking mode of TDF linker.
61
/**** linker.c --- Front end to linking mode of TDF linker.
32
 *
62
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
63
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
64
 *
35
 **** Commentary:
65
 **** Commentary:
36
 *
66
 *
37
 * This file provides the front end to the linking mode of the TDF linker.
67
 * This file provides the front end to the linking mode of the TDF linker.
38
 *
68
 *
39
 **** Change Log:
69
 **** Change Log:
40
 * $Log: linker.c,v $
70
 * $Log: linker.c,v $
41
 * Revision 1.1.1.1  1998/01/17  15:57:16  release
71
 * Revision 1.1.1.1  1998/01/17  15:57:16  release
Line 52... Line 82...
52
 * Initial import of TDF linker 3.5 non shared files.
82
 * Initial import of TDF linker 3.5 non shared files.
53
 *
83
 *
54
**/
84
**/
55
 
85
 
56
/****************************************************************************/
86
/****************************************************************************/
57
 
87
 
58
#include "linker.h"
88
#include "linker.h"
59
#include "capsule.h"
89
#include "capsule.h"
60
#include "debug.h"
90
#include "debug.h"
61
#include "error.h"
91
#include "error.h"
62
#include "file-name.h"
92
#include "file-name.h"
Line 65... Line 95...
65
#include "shape-table.h"
95
#include "shape-table.h"
66
#include "tdf.h"
96
#include "tdf.h"
67
#include "unit-table.h"
97
#include "unit-table.h"
68
 
98
 
69
#include "solve-cycles.h"
99
#include "solve-cycles.h"
70
 
100
 
71
/*--------------------------------------------------------------------------*/
101
/*--------------------------------------------------------------------------*/
72
 
102
 
73
typedef struct RenameClosureT {
103
typedef struct RenameClosureT {
74
    ShapeTableP			shapes;
104
    ShapeTableP			shapes;
75
    ShapeTableP			lib_shapes;
105
    ShapeTableP			lib_shapes;
76
} RenameClosureT, *RenameClosureP;
106
} RenameClosureT, *RenameClosureP;
77
 
107
 
78
/*--------------------------------------------------------------------------*/
108
/*--------------------------------------------------------------------------*/
79
 
109
 
80
static void
110
static void
81
linker_rename_1 PROTO_N ((shape, names, gclosure))
111
linker_rename_1(NStringP         shape,			 NameKeyPairListP names, 
82
		PROTO_T (NStringP         shape X
-
 
83
			 NameKeyPairListP names X
-
 
84
			 GenericP         gclosure)
112
			 GenericP         gclosure)
85
{
113
{
86
    RenameClosureP        closure    = (RenameClosureP) gclosure;
114
    RenameClosureP        closure    = (RenameClosureP)gclosure;
87
    ShapeTableP           shapes     = closure->shapes;
115
    ShapeTableP           shapes     = closure->shapes;
88
    ShapeTableP           lib_shapes = closure->lib_shapes;
116
    ShapeTableP           lib_shapes = closure->lib_shapes;
89
    ShapeEntryP           entry      = shape_table_add (shapes, shape);
117
    ShapeEntryP           entry      = shape_table_add(shapes, shape);
90
    ShapeEntryP           lib_entry  = shape_table_add (lib_shapes, shape);
118
    ShapeEntryP           lib_entry  = shape_table_add(lib_shapes, shape);
91
    NameTableP            table      = shape_entry_name_table (entry);
119
    NameTableP            table      = shape_entry_name_table(entry);
92
    NameTableP            lib_table  = shape_entry_name_table (lib_entry);
120
    NameTableP            lib_table  = shape_entry_name_table(lib_entry);
93
    NameKeyPairListEntryP name       = name_key_pair_list_head (names);
121
    NameKeyPairListEntryP name       = name_key_pair_list_head(names);
94
 
122
 
95
    for (; name; name = name_key_pair_list_entry_next (name)) {
123
    for (; name; name = name_key_pair_list_entry_next(name)) {
96
	NameKeyP from = name_key_pair_list_entry_from (name);
124
	NameKeyP from = name_key_pair_list_entry_from(name);
97
	NameKeyP to   = name_key_pair_list_entry_to (name);
125
	NameKeyP to   = name_key_pair_list_entry_to(name);
98
 
126
 
99
	debug_info_l_rename (shape, from, to);
127
	debug_info_l_rename(shape, from, to);
100
	name_table_add_rename (table, from, to);
128
	name_table_add_rename(table, from, to);
101
	name_table_add_rename (lib_table, from, to);
129
	name_table_add_rename(lib_table, from, to);
102
    }
130
    }
103
    name_table_resolve_renames (table, shape, TRUE);
131
    name_table_resolve_renames(table, shape, TRUE);
104
    name_table_resolve_renames (lib_table, shape, FALSE);
132
    name_table_resolve_renames(lib_table, shape, FALSE);
105
}
133
}
106
 
134
 
107
static void
135
static void
108
linker_rename PROTO_N ((arg_data, shapes, lib_shapes))
136
linker_rename(ArgDataP    arg_data,		       ShapeTableP shapes, 
109
	      PROTO_T (ArgDataP    arg_data X
-
 
110
		       ShapeTableP shapes X
-
 
111
		       ShapeTableP lib_shapes)
137
		       ShapeTableP lib_shapes)
112
{
138
{
113
    RenameClosureT closure;
139
    RenameClosureT closure;
114
 
140
 
115
    closure.shapes     = shapes;
141
    closure.shapes     = shapes;
116
    closure.lib_shapes = lib_shapes;
142
    closure.lib_shapes = lib_shapes;
117
    rename_control_iter (arg_data_get_renames (arg_data), linker_rename_1,
143
    rename_control_iter(arg_data_get_renames(arg_data), linker_rename_1,
118
			 (GenericP) &closure);
144
			(GenericP) &closure);
119
    if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
145
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
120
	exit (EXIT_FAILURE);
146
	exit(EXIT_FAILURE);
121
	UNREACHED;
147
	UNREACHED;
122
    }
148
    }
123
}
149
}
124
 
150
 
125
static void
151
static void
126
linker_read_capsules PROTO_N ((arg_data, units, shapes))
152
linker_read_capsules(ArgDataP    arg_data,			      UnitTableP  units, 
127
		     PROTO_T (ArgDataP    arg_data X
-
 
128
			      UnitTableP  units X
-
 
129
			      ShapeTableP shapes)
153
			      ShapeTableP shapes)
130
{
154
{
131
    unsigned  num_input_files = arg_data_get_num_files (arg_data);
155
    unsigned  num_input_files = arg_data_get_num_files(arg_data);
132
    CStringP *input_files     = arg_data_get_files (arg_data);
156
    CStringP *input_files     = arg_data_get_files(arg_data);
133
    unsigned  i;
157
    unsigned  i;
134
 
158
 
135
    for (i = 0; i < num_input_files; i ++) {
159
    for (i = 0; i < num_input_files; i++) {
136
	CapsuleP capsule;
160
	CapsuleP capsule;
137
 
161
 
138
	if ((capsule = capsule_create_stream_input (input_files [i])) !=
162
	if ((capsule = capsule_create_stream_input(input_files[i])) !=
139
	    NIL (CapsuleP)) {
163
	    NIL(CapsuleP)) {
140
	    capsule_read (capsule, units, shapes);
164
	    capsule_read(capsule, units, shapes);
141
	    capsule_close (capsule);
165
	    capsule_close(capsule);
142
	} else {
166
	} else {
143
	    E_cannot_open_input_file (input_files [i]);
167
	    E_cannot_open_input_file(input_files[i]);
144
	}
168
	}
145
    }
169
    }
146
    if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
170
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
147
	exit (EXIT_FAILURE);
171
	exit(EXIT_FAILURE);
148
	UNREACHED;
172
	UNREACHED;
149
    }
173
    }
150
}
174
}
151
 
175
 
152
static void
176
static void
153
linker_load_libraries PROTO_N ((arg_data, lib_shapes))
177
linker_load_libraries(ArgDataP    arg_data,			       ShapeTableP lib_shapes)
154
		      PROTO_T (ArgDataP    arg_data X
-
 
155
			       ShapeTableP lib_shapes)
-
 
156
{
178
{
157
    CStringP   *files     = arg_data_library_files (arg_data);
179
    CStringP   *files     = arg_data_library_files(arg_data);
158
    CStringP   *paths     = arg_data_library_paths (arg_data);
180
    CStringP   *paths     = arg_data_library_paths(arg_data);
159
    unsigned    num_files = arg_data_num_library_files (arg_data);
181
    unsigned    num_files = arg_data_num_library_files(arg_data);
160
    unsigned    num_paths = arg_data_num_library_paths (arg_data);
182
    unsigned    num_paths = arg_data_num_library_paths(arg_data);
161
    unsigned    i;
183
    unsigned    i;
162
 
184
 
163
    for (i = 0; i < num_files; i ++) {
185
    for (i = 0; i < num_files; i++) {
164
	LibraryP library = NIL (LibraryP);
186
	LibraryP library = NIL(LibraryP);
165
 
187
 
166
	if (file_name_is_basename (files [i])) {
188
	if (file_name_is_basename(files[i])) {
167
	    unsigned j;
189
	    unsigned j;
168
 
190
 
169
	    for (j = 0; j < num_paths; j ++) {
191
	    for (j = 0; j < num_paths; j++) {
170
		CStringP name = file_name_expand (paths [j], files [i], "tl");
192
		CStringP name = file_name_expand(paths[j], files[i], "tl");
171
 
193
 
172
		if ((library = library_create_stream_input (name)) !=
194
		if ((library = library_create_stream_input(name)) !=
173
		    NIL (LibraryP)) {
195
		    NIL(LibraryP)) {
174
		    goto found;
196
		    goto found;
175
		} else {
197
		} else {
176
		    DEALLOCATE (name);
198
		    DEALLOCATE(name);
177
		}
199
		}
178
	    }
200
	    }
179
	    E_cannot_open_library_file (files [i]);
201
	    E_cannot_open_library_file(files[i]);
180
	} else {
202
	} else {
181
	    if ((library = library_create_stream_input (files [i])) ==
203
	    if ((library = library_create_stream_input(files[i])) ==
182
		NIL (LibraryP)) {
204
		NIL(LibraryP)) {
183
		E_cannot_open_library_file (files [i]);
205
		E_cannot_open_library_file(files[i]);
184
	    }
206
	    }
185
	}
207
	}
186
      found:
208
      found:
187
	if (library) {
209
	if (library) {
188
	    library_read (library, lib_shapes);
210
	    library_read(library, lib_shapes);
189
	    library_close (library);
211
	    library_close(library);
190
	}
212
	}
191
    }
213
    }
192
    if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
214
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
193
	exit (EXIT_FAILURE);
215
	exit(EXIT_FAILURE);
194
	UNREACHED;
216
	UNREACHED;
195
    }
217
    }
196
}
218
}
197
 
219
 
198
static void
220
static void
199
linker_suppress_1 PROTO_N ((shape, all, names, gclosure))
221
linker_suppress_1(NStringP     shape,			   BoolT        all, 
200
		  PROTO_T (NStringP     shape X
-
 
201
			   BoolT        all X
-
 
202
			   NameKeyListP names X
222
			   NameKeyListP names, 
203
			   GenericP     gclosure)
223
			   GenericP     gclosure)
204
{
224
{
205
    ShapeTableP lib_shapes = (ShapeTableP) gclosure;
225
    ShapeTableP lib_shapes = (ShapeTableP)gclosure;
206
    ShapeEntryP entry      = shape_table_get (lib_shapes, shape);
226
    ShapeEntryP entry      = shape_table_get(lib_shapes, shape);
207
 
227
 
208
    if (entry) {
228
    if (entry) {
209
	NameTableP        table = shape_entry_name_table (entry);
229
	NameTableP        table = shape_entry_name_table(entry);
210
	NameKeyListEntryP name  = name_key_list_head (names);
230
	NameKeyListEntryP name  = name_key_list_head(names);
211
 
231
 
212
	if (all) {
232
	if (all) {
213
	    name_table_iter (table, name_entry_suppress, (GenericP) shape);
233
	    name_table_iter(table, name_entry_suppress,(GenericP)shape);
214
	}
234
	}
215
	for (; name; name = name_key_list_entry_next (name)) {
235
	for (; name; name = name_key_list_entry_next(name)) {
216
	    NameKeyP   key        = name_key_list_entry_key (name);
236
	    NameKeyP   key        = name_key_list_entry_key(name);
217
	    NameEntryP name_entry = name_table_get (table, key);
237
	    NameEntryP name_entry = name_table_get(table, key);
218
 
238
 
219
	    if (name_entry) {
239
	    if (name_entry) {
220
		debug_info_l_suppress (shape, key);
240
		debug_info_l_suppress(shape, key);
221
		name_entry_set_lib_definition (name_entry, NIL (LibCapsuleP));
241
		name_entry_set_lib_definition(name_entry, NIL(LibCapsuleP));
222
	    }
242
	    }
223
	}
243
	}
224
    }
244
    }
225
}
245
}
226
 
246
 
227
static void
247
static void
228
linker_suppress PROTO_N ((arg_data, lib_shapes))
248
linker_suppress(ArgDataP    arg_data,			 ShapeTableP lib_shapes)
229
		PROTO_T (ArgDataP    arg_data X
-
 
230
			 ShapeTableP lib_shapes)
-
 
231
{
249
{
232
    if (arg_data_get_suppress_mult (arg_data)) {
250
    if (arg_data_get_suppress_mult(arg_data)) {
233
	shape_table_iter (lib_shapes, shape_entry_lib_suppress_mult,
251
	shape_table_iter(lib_shapes, shape_entry_lib_suppress_mult,
234
			  NIL (GenericP));
252
			  NIL(GenericP));
235
    }
253
    }
236
    shape_control_iter (arg_data_get_suppresses (arg_data), linker_suppress_1,
254
    shape_control_iter(arg_data_get_suppresses(arg_data), linker_suppress_1,
237
			(GenericP) lib_shapes);
255
			(GenericP)lib_shapes);
238
    if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
256
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
239
	exit (EXIT_FAILURE);
257
	exit(EXIT_FAILURE);
240
	UNREACHED;
258
	UNREACHED;
241
    }
259
    }
242
}
260
}
243
 
261
 
244
static void
262
static void
245
linker_resolve_undefined PROTO_N ((units, shapes, lib_shapes))
263
linker_resolve_undefined(UnitTableP  units,				  ShapeTableP shapes, 
246
			 PROTO_T (UnitTableP  units X
-
 
247
				  ShapeTableP shapes X
-
 
248
				  ShapeTableP lib_shapes)
264
				  ShapeTableP lib_shapes)
249
{
265
{
250
    ShapeLibClosureT closure;
266
    ShapeLibClosureT closure;
251
 
267
 
252
    closure.lib_shapes = lib_shapes;
268
    closure.lib_shapes = lib_shapes;
253
    closure.units      = units;
269
    closure.units      = units;
254
    closure.shapes     = shapes;
270
    closure.shapes     = shapes;
255
    do {
271
    do {
256
	closure.did_define = FALSE;
272
	closure.did_define = FALSE;
257
	shape_table_iter (shapes, shape_entry_resolve_undefined,
273
	shape_table_iter(shapes, shape_entry_resolve_undefined,
258
			  (GenericP) &closure);
274
			 (GenericP) &closure);
259
    } while (closure.did_define);
275
    } while (closure.did_define);
260
    if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
276
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
261
	exit (EXIT_FAILURE);
277
	exit(EXIT_FAILURE);
262
	UNREACHED;
278
	UNREACHED;
263
    }
279
    }
264
}
280
}
265
 
281
 
266
static void
282
static void
267
linker_hide PROTO_N ((shape, all, names, gclosure))
283
linker_hide(NStringP     shape,		     BoolT        all, 
268
	    PROTO_T (NStringP     shape X
284
		     NameKeyListP names, 
269
		     BoolT        all X
285
		     GenericP     gclosure)
-
 
286
{
-
 
287
    ShapeTableP shapes = (ShapeTableP)gclosure;
-
 
288
    ShapeEntryP entry  = shape_table_get(shapes, shape);
-
 
289
 
-
 
290
    if (entry == NIL(ShapeEntryP)) {
-
 
291
	E_cannot_hide_shape(shape);
-
 
292
    } else {
-
 
293
	NameTableP        table = shape_entry_name_table(entry);
-
 
294
	NameKeyListEntryP name  = name_key_list_head(names);
-
 
295
 
-
 
296
	if (all) {
-
 
297
	    name_table_iter(table, name_entry_hide_defd,(GenericP)shape);
-
 
298
	}
-
 
299
	for (; name; name = name_key_list_entry_next(name)) {
-
 
300
	    NameKeyP   key        = name_key_list_entry_key(name);
-
 
301
	    NameEntryP name_entry = name_table_get(table, key);
-
 
302
 
-
 
303
	    if (name_entry == NIL(NameEntryP)) {
-
 
304
		E_cannot_hide(shape, key);
-
 
305
	    } else if (name_entry_get_use(name_entry) & U_DEFD) {
-
 
306
		debug_info_l_hide(shape, key);
-
 
307
		name_entry_hide(name_entry);
-
 
308
	    } else {
-
 
309
		E_cannot_hide_undefined(shape, key);
-
 
310
	    }
-
 
311
	}
-
 
312
    }
-
 
313
}
-
 
314
 
-
 
315
static void
-
 
316
linker_keep(NStringP     shape,		     BoolT        all, 
270
		     NameKeyListP names X
317
		     NameKeyListP names, 
271
		     GenericP     gclosure)
318
		     GenericP     gclosure)
272
{
319
{
273
    ShapeTableP shapes = (ShapeTableP) gclosure;
320
    ShapeTableP shapes = (ShapeTableP)gclosure;
274
    ShapeEntryP entry  = shape_table_get (shapes, shape);
321
    ShapeEntryP entry  = shape_table_get(shapes, shape);
275
 
322
 
276
    if (entry == NIL (ShapeEntryP)) {
323
    if (entry == NIL(ShapeEntryP)) {
277
	E_cannot_hide_shape (shape);
324
	E_cannot_keep_shape(shape);
278
    } else {
325
    } else {
279
	NameTableP        table = shape_entry_name_table (entry);
326
	NameTableP        table = shape_entry_name_table(entry);
280
	NameKeyListEntryP name  = name_key_list_head (names);
327
	NameKeyListEntryP name  = name_key_list_head(names);
281
 
328
 
282
	if (all) {
329
	if (all) {
283
	    name_table_iter (table, name_entry_hide_defd, (GenericP) shape);
330
	    name_table_iter(table, name_entry_keep,(GenericP)shape);
284
	}
331
	}
285
	for (; name; name = name_key_list_entry_next (name)) {
332
	for (; name; name = name_key_list_entry_next(name)) {
286
	    NameKeyP   key        = name_key_list_entry_key (name);
333
	    NameKeyP   key        = name_key_list_entry_key(name);
287
	    NameEntryP name_entry = name_table_get (table, key);
334
	    NameEntryP name_entry = name_table_get(table, key);
288
 
335
 
289
	    if (name_entry == NIL (NameEntryP)) {
336
	    if (name_entry == NIL(NameEntryP)) {
290
		E_cannot_hide (shape, key);
337
		E_cannot_keep(shape, key);
291
	    } else if (name_entry_get_use (name_entry) & U_DEFD) {
-
 
292
		debug_info_l_hide (shape, key);
-
 
293
		name_entry_hide (name_entry);
-
 
294
	    } else {
338
	    } else {
295
		E_cannot_hide_undefined (shape, key);
339
		debug_info_l_keep(shape, key);
-
 
340
		name_entry_unhide(name_entry);
296
	    }
341
	    }
297
	}
342
	}
298
    }
343
    }
299
}
344
}
300
 
345
 
301
static void
346
static void
302
linker_keep PROTO_N ((shape, all, names, gclosure))
-
 
303
	    PROTO_T (NStringP     shape X
-
 
304
		     BoolT        all X
-
 
305
		     NameKeyListP names X
-
 
306
		     GenericP     gclosure)
-
 
307
{
-
 
308
    ShapeTableP shapes = (ShapeTableP) gclosure;
-
 
309
    ShapeEntryP entry  = shape_table_get (shapes, shape);
-
 
310
 
-
 
311
    if (entry == NIL (ShapeEntryP)) {
-
 
312
	E_cannot_keep_shape (shape);
-
 
313
    } else {
-
 
314
	NameTableP        table = shape_entry_name_table (entry);
-
 
315
	NameKeyListEntryP name  = name_key_list_head (names);
-
 
316
 
-
 
317
	if (all) {
-
 
318
	    name_table_iter (table, name_entry_keep, (GenericP) shape);
-
 
319
	}
-
 
320
	for (; name; name = name_key_list_entry_next (name)) {
-
 
321
	    NameKeyP   key        = name_key_list_entry_key (name);
-
 
322
	    NameEntryP name_entry = name_table_get (table, key);
-
 
323
 
-
 
324
	    if (name_entry == NIL (NameEntryP)) {
-
 
325
		E_cannot_keep (shape, key);
-
 
326
	    } else {
-
 
327
		debug_info_l_keep (shape, key);
-
 
328
		name_entry_unhide (name_entry);
-
 
329
	    }
-
 
330
	}
-
 
331
    }
-
 
332
}
-
 
333
 
-
 
334
static void
-
 
335
linker_hide_and_keep PROTO_N ((arg_data, shapes))
347
linker_hide_and_keep(ArgDataP    arg_data,			      ShapeTableP shapes)
336
		     PROTO_T (ArgDataP    arg_data X
-
 
337
			      ShapeTableP shapes)
-
 
338
{
348
{
339
    if (arg_data_get_all_hide_defd (arg_data)) {
349
    if (arg_data_get_all_hide_defd(arg_data)) {
340
	shape_table_iter (shapes, shape_entry_hide_all_defd, NIL (GenericP));
350
	shape_table_iter(shapes, shape_entry_hide_all_defd, NIL(GenericP));
341
    }
351
    }
342
    shape_control_iter (arg_data_get_hides (arg_data), linker_hide,
352
    shape_control_iter(arg_data_get_hides(arg_data), linker_hide,
343
			(GenericP) shapes);
353
			(GenericP)shapes);
344
    shape_control_iter (arg_data_get_keeps (arg_data), linker_keep,
354
    shape_control_iter(arg_data_get_keeps(arg_data), linker_keep,
345
			(GenericP) shapes);
355
			(GenericP)shapes);
346
    if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
356
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
347
	exit (EXIT_FAILURE);
357
	exit(EXIT_FAILURE);
348
	UNREACHED;
358
	UNREACHED;
349
    }
359
    }
350
}
360
}
351
 
361
 
352
static void
362
static void
353
linker_write_capsule PROTO_N ((arg_data, units, shapes))
363
linker_write_capsule(ArgDataP    arg_data,			      UnitTableP  units, 
354
		     PROTO_T (ArgDataP    arg_data X
-
 
355
			      UnitTableP  units X
-
 
356
			      ShapeTableP shapes)
364
			      ShapeTableP shapes)
357
{
365
{
358
    CStringP output_file = arg_data_get_output_file (arg_data);
366
    CStringP output_file = arg_data_get_output_file(arg_data);
359
    CapsuleP capsule;
367
    CapsuleP capsule;
360
 
368
 
361
    if ((capsule = capsule_create_stream_output (output_file)) !=
369
    if ((capsule = capsule_create_stream_output(output_file)) !=
362
	NIL (CapsuleP)) {
370
	NIL(CapsuleP)) {
363
	capsule_write (capsule, units, shapes);
371
	capsule_write(capsule, units, shapes);
364
	capsule_close (capsule);
372
	capsule_close(capsule);
365
    } else {
373
    } else {
366
	E_cannot_open_output_file (output_file);
374
	E_cannot_open_output_file(output_file);
367
	UNREACHED;
375
	UNREACHED;
368
    }
376
    }
369
    if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
377
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
370
	exit (EXIT_FAILURE);
378
	exit(EXIT_FAILURE);
371
	UNREACHED;
379
	UNREACHED;
372
    }
380
    }
373
}
381
}
374
 
382
 
375
/*--------------------------------------------------------------------------*/
383
/*--------------------------------------------------------------------------*/
376
 
384
 
377
void
385
void
378
linker_main PROTO_N ((arg_data))
386
linker_main(ArgDataP arg_data)
379
	    PROTO_T (ArgDataP arg_data)
-
 
380
{
387
{
381
    UnitTableP  units      = unit_table_create ();
388
    UnitTableP  units      = unit_table_create();
382
    ShapeTableP shapes     = shape_table_create ();
389
    ShapeTableP shapes     = shape_table_create();
383
    ShapeTableP lib_shapes = shape_table_create ();
390
    ShapeTableP lib_shapes = shape_table_create();
384
 
391
 
385
    linker_rename (arg_data, shapes, lib_shapes);
392
    linker_rename(arg_data, shapes, lib_shapes);
386
    linker_read_capsules (arg_data, units, shapes);
393
    linker_read_capsules(arg_data, units, shapes);
387
    linker_load_libraries (arg_data, lib_shapes);
394
    linker_load_libraries(arg_data, lib_shapes);
388
    linker_suppress (arg_data, lib_shapes);
395
    linker_suppress(arg_data, lib_shapes);
389
    linker_resolve_undefined (units, shapes, lib_shapes);
396
    linker_resolve_undefined(units, shapes, lib_shapes);
390
    linker_hide_and_keep (arg_data, shapes);
397
    linker_hide_and_keep(arg_data, shapes);
391
    linker_write_capsule (arg_data, units, shapes);
398
    linker_write_capsule(arg_data, units, shapes);
392
}
399
}
393

400

394
/*
401
/*
395
 * Local variables(smf):
402
 * Local variables(smf):
396
 * eval: (include::add-path-entry "../os-interface" "../library" "../tdf")
403
 * eval: (include::add-path-entry "../os-interface" "../library" "../tdf")