Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/algol60/src/tools/tld/linker.c – Rev 7

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
7 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
7 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:-
7 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
7 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;
7 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;
7 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
/**** linker.c --- Front end to linking mode of TDF linker.
62
 *
63
 ** Author: Steve Folkes <smf@hermes.mod.uk>
64
 *
65
 **** Commentary:
66
 *
67
 * This file provides the front end to the linking mode of the TDF linker.
68
 *
69
 **** Change Log:
70
 * $Log: linker.c,v $
71
 * Revision 1.1.1.1  1998/01/17  15:57:16  release
72
 * First version to be checked into rolling release.
73
 *
74
 * Revision 1.3  1995/09/22  08:37:11  smf
75
 * Fixed problems with incomplete structures (to shut "tcc" up).
76
 *
77
 * Revision 1.2  1994/12/12  11:44:06  smf
78
 * Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
79
 * OSSG C Coding Standards.
80
 *
81
 * Revision 1.1.1.1  1994/07/25  16:03:26  smf
82
 * Initial import of TDF linker 3.5 non shared files.
83
 *
84
**/
85
 
86
/****************************************************************************/
87
 
88
#include "linker.h"
89
#include "capsule.h"
90
#include "debug.h"
91
#include "error.h"
92
#include "file-name.h"
93
#include "gen-errors.h"
94
#include "library.h"
95
#include "shape-table.h"
96
#include "tdf.h"
97
#include "unit-table.h"
98
 
99
#include "solve-cycles.h"
100
 
101
/*--------------------------------------------------------------------------*/
102
 
103
typedef struct RenameClosureT {
104
    ShapeTableP			shapes;
105
    ShapeTableP			lib_shapes;
106
} RenameClosureT, *RenameClosureP;
107
 
108
/*--------------------------------------------------------------------------*/
109
 
110
static void
7 7u83 111
linker_rename_1(NStringP         shape,			 NameKeyPairListP names, 
2 7u83 112
			 GenericP         gclosure)
113
{
7 7u83 114
    RenameClosureP        closure    = (RenameClosureP)gclosure;
2 7u83 115
    ShapeTableP           shapes     = closure->shapes;
116
    ShapeTableP           lib_shapes = closure->lib_shapes;
7 7u83 117
    ShapeEntryP           entry      = shape_table_add(shapes, shape);
118
    ShapeEntryP           lib_entry  = shape_table_add(lib_shapes, shape);
119
    NameTableP            table      = shape_entry_name_table(entry);
120
    NameTableP            lib_table  = shape_entry_name_table(lib_entry);
121
    NameKeyPairListEntryP name       = name_key_pair_list_head(names);
2 7u83 122
 
7 7u83 123
    for (; name; name = name_key_pair_list_entry_next(name)) {
124
	NameKeyP from = name_key_pair_list_entry_from(name);
125
	NameKeyP to   = name_key_pair_list_entry_to(name);
2 7u83 126
 
7 7u83 127
	debug_info_l_rename(shape, from, to);
128
	name_table_add_rename(table, from, to);
129
	name_table_add_rename(lib_table, from, to);
2 7u83 130
    }
7 7u83 131
    name_table_resolve_renames(table, shape, TRUE);
132
    name_table_resolve_renames(lib_table, shape, FALSE);
2 7u83 133
}
134
 
135
static void
7 7u83 136
linker_rename(ArgDataP    arg_data,		       ShapeTableP shapes, 
2 7u83 137
		       ShapeTableP lib_shapes)
138
{
139
    RenameClosureT closure;
140
 
141
    closure.shapes     = shapes;
142
    closure.lib_shapes = lib_shapes;
7 7u83 143
    rename_control_iter(arg_data_get_renames(arg_data), linker_rename_1,
144
			(GenericP) &closure);
145
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
146
	exit(EXIT_FAILURE);
2 7u83 147
	UNREACHED;
148
    }
149
}
150
 
151
static void
7 7u83 152
linker_read_capsules(ArgDataP    arg_data,			      UnitTableP  units, 
2 7u83 153
			      ShapeTableP shapes)
154
{
7 7u83 155
    unsigned  num_input_files = arg_data_get_num_files(arg_data);
156
    CStringP *input_files     = arg_data_get_files(arg_data);
2 7u83 157
    unsigned  i;
158
 
7 7u83 159
    for (i = 0; i < num_input_files; i++) {
2 7u83 160
	CapsuleP capsule;
161
 
7 7u83 162
	if ((capsule = capsule_create_stream_input(input_files[i])) !=
163
	    NIL(CapsuleP)) {
164
	    capsule_read(capsule, units, shapes);
165
	    capsule_close(capsule);
2 7u83 166
	} else {
7 7u83 167
	    E_cannot_open_input_file(input_files[i]);
2 7u83 168
	}
169
    }
7 7u83 170
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
171
	exit(EXIT_FAILURE);
2 7u83 172
	UNREACHED;
173
    }
174
}
175
 
176
static void
7 7u83 177
linker_load_libraries(ArgDataP    arg_data,			       ShapeTableP lib_shapes)
2 7u83 178
{
7 7u83 179
    CStringP   *files     = arg_data_library_files(arg_data);
180
    CStringP   *paths     = arg_data_library_paths(arg_data);
181
    unsigned    num_files = arg_data_num_library_files(arg_data);
182
    unsigned    num_paths = arg_data_num_library_paths(arg_data);
2 7u83 183
    unsigned    i;
184
 
7 7u83 185
    for (i = 0; i < num_files; i++) {
186
	LibraryP library = NIL(LibraryP);
2 7u83 187
 
7 7u83 188
	if (file_name_is_basename(files[i])) {
2 7u83 189
	    unsigned j;
190
 
7 7u83 191
	    for (j = 0; j < num_paths; j++) {
192
		CStringP name = file_name_expand(paths[j], files[i], "tl");
2 7u83 193
 
7 7u83 194
		if ((library = library_create_stream_input(name)) !=
195
		    NIL(LibraryP)) {
2 7u83 196
		    goto found;
197
		} else {
7 7u83 198
		    DEALLOCATE(name);
2 7u83 199
		}
200
	    }
7 7u83 201
	    E_cannot_open_library_file(files[i]);
2 7u83 202
	} else {
7 7u83 203
	    if ((library = library_create_stream_input(files[i])) ==
204
		NIL(LibraryP)) {
205
		E_cannot_open_library_file(files[i]);
2 7u83 206
	    }
207
	}
208
      found:
209
	if (library) {
7 7u83 210
	    library_read(library, lib_shapes);
211
	    library_close(library);
2 7u83 212
	}
213
    }
7 7u83 214
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
215
	exit(EXIT_FAILURE);
2 7u83 216
	UNREACHED;
217
    }
218
}
219
 
220
static void
7 7u83 221
linker_suppress_1(NStringP     shape,			   BoolT        all, 
222
			   NameKeyListP names, 
2 7u83 223
			   GenericP     gclosure)
224
{
7 7u83 225
    ShapeTableP lib_shapes = (ShapeTableP)gclosure;
226
    ShapeEntryP entry      = shape_table_get(lib_shapes, shape);
2 7u83 227
 
228
    if (entry) {
7 7u83 229
	NameTableP        table = shape_entry_name_table(entry);
230
	NameKeyListEntryP name  = name_key_list_head(names);
2 7u83 231
 
232
	if (all) {
7 7u83 233
	    name_table_iter(table, name_entry_suppress,(GenericP)shape);
2 7u83 234
	}
7 7u83 235
	for (; name; name = name_key_list_entry_next(name)) {
236
	    NameKeyP   key        = name_key_list_entry_key(name);
237
	    NameEntryP name_entry = name_table_get(table, key);
2 7u83 238
 
239
	    if (name_entry) {
7 7u83 240
		debug_info_l_suppress(shape, key);
241
		name_entry_set_lib_definition(name_entry, NIL(LibCapsuleP));
2 7u83 242
	    }
243
	}
244
    }
245
}
246
 
247
static void
7 7u83 248
linker_suppress(ArgDataP    arg_data,			 ShapeTableP lib_shapes)
2 7u83 249
{
7 7u83 250
    if (arg_data_get_suppress_mult(arg_data)) {
251
	shape_table_iter(lib_shapes, shape_entry_lib_suppress_mult,
252
			  NIL(GenericP));
2 7u83 253
    }
7 7u83 254
    shape_control_iter(arg_data_get_suppresses(arg_data), linker_suppress_1,
255
			(GenericP)lib_shapes);
256
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
257
	exit(EXIT_FAILURE);
2 7u83 258
	UNREACHED;
259
    }
260
}
261
 
262
static void
7 7u83 263
linker_resolve_undefined(UnitTableP  units,				  ShapeTableP shapes, 
2 7u83 264
				  ShapeTableP lib_shapes)
265
{
266
    ShapeLibClosureT closure;
267
 
268
    closure.lib_shapes = lib_shapes;
269
    closure.units      = units;
270
    closure.shapes     = shapes;
271
    do {
272
	closure.did_define = FALSE;
7 7u83 273
	shape_table_iter(shapes, shape_entry_resolve_undefined,
274
			 (GenericP) &closure);
2 7u83 275
    } while (closure.did_define);
7 7u83 276
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
277
	exit(EXIT_FAILURE);
2 7u83 278
	UNREACHED;
279
    }
280
}
281
 
282
static void
7 7u83 283
linker_hide(NStringP     shape,		     BoolT        all, 
284
		     NameKeyListP names, 
2 7u83 285
		     GenericP     gclosure)
286
{
7 7u83 287
    ShapeTableP shapes = (ShapeTableP)gclosure;
288
    ShapeEntryP entry  = shape_table_get(shapes, shape);
2 7u83 289
 
7 7u83 290
    if (entry == NIL(ShapeEntryP)) {
291
	E_cannot_hide_shape(shape);
2 7u83 292
    } else {
7 7u83 293
	NameTableP        table = shape_entry_name_table(entry);
294
	NameKeyListEntryP name  = name_key_list_head(names);
2 7u83 295
 
296
	if (all) {
7 7u83 297
	    name_table_iter(table, name_entry_hide_defd,(GenericP)shape);
2 7u83 298
	}
7 7u83 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);
2 7u83 302
 
7 7u83 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);
2 7u83 308
	    } else {
7 7u83 309
		E_cannot_hide_undefined(shape, key);
2 7u83 310
	    }
311
	}
312
    }
313
}
314
 
315
static void
7 7u83 316
linker_keep(NStringP     shape,		     BoolT        all, 
317
		     NameKeyListP names, 
2 7u83 318
		     GenericP     gclosure)
319
{
7 7u83 320
    ShapeTableP shapes = (ShapeTableP)gclosure;
321
    ShapeEntryP entry  = shape_table_get(shapes, shape);
2 7u83 322
 
7 7u83 323
    if (entry == NIL(ShapeEntryP)) {
324
	E_cannot_keep_shape(shape);
2 7u83 325
    } else {
7 7u83 326
	NameTableP        table = shape_entry_name_table(entry);
327
	NameKeyListEntryP name  = name_key_list_head(names);
2 7u83 328
 
329
	if (all) {
7 7u83 330
	    name_table_iter(table, name_entry_keep,(GenericP)shape);
2 7u83 331
	}
7 7u83 332
	for (; name; name = name_key_list_entry_next(name)) {
333
	    NameKeyP   key        = name_key_list_entry_key(name);
334
	    NameEntryP name_entry = name_table_get(table, key);
2 7u83 335
 
7 7u83 336
	    if (name_entry == NIL(NameEntryP)) {
337
		E_cannot_keep(shape, key);
2 7u83 338
	    } else {
7 7u83 339
		debug_info_l_keep(shape, key);
340
		name_entry_unhide(name_entry);
2 7u83 341
	    }
342
	}
343
    }
344
}
345
 
346
static void
7 7u83 347
linker_hide_and_keep(ArgDataP    arg_data,			      ShapeTableP shapes)
2 7u83 348
{
7 7u83 349
    if (arg_data_get_all_hide_defd(arg_data)) {
350
	shape_table_iter(shapes, shape_entry_hide_all_defd, NIL(GenericP));
2 7u83 351
    }
7 7u83 352
    shape_control_iter(arg_data_get_hides(arg_data), linker_hide,
353
			(GenericP)shapes);
354
    shape_control_iter(arg_data_get_keeps(arg_data), linker_keep,
355
			(GenericP)shapes);
356
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
357
	exit(EXIT_FAILURE);
2 7u83 358
	UNREACHED;
359
    }
360
}
361
 
362
static void
7 7u83 363
linker_write_capsule(ArgDataP    arg_data,			      UnitTableP  units, 
2 7u83 364
			      ShapeTableP shapes)
365
{
7 7u83 366
    CStringP output_file = arg_data_get_output_file(arg_data);
2 7u83 367
    CapsuleP capsule;
368
 
7 7u83 369
    if ((capsule = capsule_create_stream_output(output_file)) !=
370
	NIL(CapsuleP)) {
371
	capsule_write(capsule, units, shapes);
372
	capsule_close(capsule);
2 7u83 373
    } else {
7 7u83 374
	E_cannot_open_output_file(output_file);
2 7u83 375
	UNREACHED;
376
    }
7 7u83 377
    if (error_max_reported_severity() >= ERROR_SEVERITY_ERROR) {
378
	exit(EXIT_FAILURE);
2 7u83 379
	UNREACHED;
380
    }
381
}
382
 
383
/*--------------------------------------------------------------------------*/
384
 
385
void
7 7u83 386
linker_main(ArgDataP arg_data)
2 7u83 387
{
7 7u83 388
    UnitTableP  units      = unit_table_create();
389
    ShapeTableP shapes     = shape_table_create();
390
    ShapeTableP lib_shapes = shape_table_create();
2 7u83 391
 
7 7u83 392
    linker_rename(arg_data, shapes, lib_shapes);
393
    linker_read_capsules(arg_data, units, shapes);
394
    linker_load_libraries(arg_data, lib_shapes);
395
    linker_suppress(arg_data, lib_shapes);
396
    linker_resolve_undefined(units, shapes, lib_shapes);
397
    linker_hide_and_keep(arg_data, shapes);
398
    linker_write_capsule(arg_data, units, shapes);
2 7u83 399
}
400
 
401
/*
402
 * Local variables(smf):
403
 * eval: (include::add-path-entry "../os-interface" "../library" "../tdf")
404
 * eval: (include::add-path-entry "../generated")
405
 * End:
406
**/