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 |
/**** builder.c --- Front end to library construction mode of TDF linker.
|
|
|
32 |
*
|
|
|
33 |
** Author: Steve Folkes <smf@hermes.mod.uk>
|
|
|
34 |
*
|
|
|
35 |
**** Commentary:
|
|
|
36 |
*
|
|
|
37 |
* This file provides the front end to the library construction mode of the
|
|
|
38 |
* TDF linker.
|
|
|
39 |
*
|
|
|
40 |
**** Change Log:
|
|
|
41 |
* $Log: builder.c,v $
|
|
|
42 |
* Revision 1.1.1.1 1998/01/17 15:57:16 release
|
|
|
43 |
* First version to be checked into rolling release.
|
|
|
44 |
*
|
|
|
45 |
* Revision 1.3 1995/09/22 08:37:01 smf
|
|
|
46 |
* Fixed problems with incomplete structures (to shut "tcc" up).
|
|
|
47 |
*
|
|
|
48 |
* Revision 1.2 1994/12/12 11:43:56 smf
|
|
|
49 |
* Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
|
|
|
50 |
* OSSG C Coding Standards.
|
|
|
51 |
*
|
|
|
52 |
* Revision 1.1.1.1 1994/07/25 16:03:23 smf
|
|
|
53 |
* Initial import of TDF linker 3.5 non shared files.
|
|
|
54 |
*
|
|
|
55 |
**/
|
|
|
56 |
|
|
|
57 |
/****************************************************************************/
|
|
|
58 |
|
|
|
59 |
#include "builder.h"
|
|
|
60 |
#include "capsule.h"
|
|
|
61 |
#include "debug.h"
|
|
|
62 |
#include "error.h"
|
|
|
63 |
#include "gen-errors.h"
|
|
|
64 |
#include "library.h"
|
|
|
65 |
#include "shape-table.h"
|
|
|
66 |
#include "unit-table.h"
|
|
|
67 |
|
|
|
68 |
#include "solve-cycles.h"
|
|
|
69 |
|
|
|
70 |
/*--------------------------------------------------------------------------*/
|
|
|
71 |
|
|
|
72 |
static LibraryP *
|
|
|
73 |
builder_read_libraries PROTO_N ((arg_data, num_libs_ref, num_capsules_ref))
|
|
|
74 |
PROTO_T (ArgDataP arg_data X
|
|
|
75 |
unsigned *num_libs_ref X
|
|
|
76 |
unsigned *num_capsules_ref)
|
|
|
77 |
{
|
|
|
78 |
unsigned num_lib_files = arg_data_num_library_files (arg_data);
|
|
|
79 |
CStringP *lib_files = arg_data_library_files (arg_data);
|
|
|
80 |
LibraryP *libraries = ALLOCATE_VECTOR (LibraryP, num_lib_files);
|
|
|
81 |
unsigned num_capsules = 0;
|
|
|
82 |
unsigned i;
|
|
|
83 |
|
|
|
84 |
for (i = 0; i < num_lib_files; i ++) {
|
|
|
85 |
LibraryP library = library_create_stream_input (lib_files [i]);
|
|
|
86 |
|
|
|
87 |
if (library != NIL (LibraryP)) {
|
|
|
88 |
ShapeTableP lib_shapes = shape_table_create ();
|
|
|
89 |
|
|
|
90 |
library_read (library, lib_shapes);
|
|
|
91 |
library_close (library);
|
|
|
92 |
libraries [i] = library;
|
|
|
93 |
num_capsules += library_num_capsules (library);
|
|
|
94 |
shape_table_deallocate (lib_shapes);
|
|
|
95 |
} else {
|
|
|
96 |
libraries [i] = NIL (LibraryP);
|
|
|
97 |
E_cannot_open_input_file (lib_files [i]);
|
|
|
98 |
}
|
|
|
99 |
}
|
|
|
100 |
*num_libs_ref = num_lib_files;
|
|
|
101 |
*num_capsules_ref = num_capsules;
|
|
|
102 |
return (libraries);
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
static void
|
|
|
106 |
builder_read_capsule PROTO_N ((capsule, capsules, capsule_index, units,
|
|
|
107 |
shapes))
|
|
|
108 |
PROTO_T (CapsuleP capsule X
|
|
|
109 |
CapsuleP *capsules X
|
|
|
110 |
unsigned capsule_index X
|
|
|
111 |
UnitTableP units X
|
|
|
112 |
ShapeTableP shapes)
|
|
|
113 |
{
|
|
|
114 |
CStringP name = capsule_name (capsule);
|
|
|
115 |
unsigned i;
|
|
|
116 |
|
|
|
117 |
for (i = 0; i < capsule_index; i ++) {
|
|
|
118 |
if (cstring_equal (name, capsule_name (capsules [i]))) {
|
|
|
119 |
E_duplicate_capsule_name (name);
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
capsule_set_index (capsule, capsule_index);
|
|
|
123 |
capsule_read (capsule, units, shapes);
|
|
|
124 |
capsule_store_contents (capsule);
|
|
|
125 |
capsule_close (capsule);
|
|
|
126 |
capsules [capsule_index] = capsule;
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
static CapsuleP *
|
|
|
130 |
builder_read_capsules PROTO_N ((arg_data, units, shapes, num_capsules_ref))
|
|
|
131 |
PROTO_T (ArgDataP arg_data X
|
|
|
132 |
UnitTableP units X
|
|
|
133 |
ShapeTableP shapes X
|
|
|
134 |
unsigned *num_capsules_ref)
|
|
|
135 |
{
|
|
|
136 |
unsigned num_input_files = arg_data_get_num_files (arg_data);
|
|
|
137 |
CStringP *input_files = arg_data_get_files (arg_data);
|
|
|
138 |
unsigned capsule_index = 0;
|
|
|
139 |
unsigned num_libraries;
|
|
|
140 |
LibraryP *libraries;
|
|
|
141 |
unsigned num_capsules;
|
|
|
142 |
CapsuleP *capsules;
|
|
|
143 |
unsigned i;
|
|
|
144 |
|
|
|
145 |
libraries = builder_read_libraries (arg_data, &num_libraries,
|
|
|
146 |
&num_capsules);
|
|
|
147 |
num_capsules += num_input_files;
|
|
|
148 |
capsules = ALLOCATE_VECTOR (CapsuleP, num_capsules);
|
|
|
149 |
for (i = 0; i < num_libraries; i ++) {
|
|
|
150 |
LibraryP library = libraries [i];
|
|
|
151 |
|
|
|
152 |
if (library != NIL (LibraryP)) {
|
|
|
153 |
unsigned num_lib_capsules = library_num_capsules (library);
|
|
|
154 |
unsigned j;
|
|
|
155 |
|
|
|
156 |
for (j = 0; j < num_lib_capsules; j ++) {
|
|
|
157 |
LibCapsuleP lib_capsule = library_get_capsule (library, j);
|
|
|
158 |
CStringP name = lib_capsule_name (lib_capsule);
|
|
|
159 |
NStringP contents = lib_capsule_contents (lib_capsule);
|
|
|
160 |
CapsuleP capsule;
|
|
|
161 |
|
|
|
162 |
capsule = capsule_create_string_input (name, contents);
|
|
|
163 |
builder_read_capsule (capsule, capsules, capsule_index,
|
|
|
164 |
units, shapes);
|
|
|
165 |
capsule_index ++;
|
|
|
166 |
}
|
|
|
167 |
}
|
|
|
168 |
}
|
|
|
169 |
DEALLOCATE (libraries);
|
|
|
170 |
for (i = 0; i < num_input_files; i ++) {
|
|
|
171 |
CapsuleP capsule;
|
|
|
172 |
|
|
|
173 |
if ((capsule = capsule_create_stream_input (input_files [i])) !=
|
|
|
174 |
NIL (CapsuleP)) {
|
|
|
175 |
builder_read_capsule (capsule, capsules, capsule_index, units,
|
|
|
176 |
shapes);
|
|
|
177 |
capsule_index ++;
|
|
|
178 |
} else {
|
|
|
179 |
E_cannot_open_input_file (input_files [i]);
|
|
|
180 |
}
|
|
|
181 |
}
|
|
|
182 |
if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
|
|
|
183 |
exit (EXIT_FAILURE);
|
|
|
184 |
UNREACHED;
|
|
|
185 |
}
|
|
|
186 |
*num_capsules_ref = num_capsules;
|
|
|
187 |
return (capsules);
|
|
|
188 |
}
|
|
|
189 |
|
|
|
190 |
static void
|
|
|
191 |
builder_check_multi_defs PROTO_N ((shapes))
|
|
|
192 |
PROTO_T (ShapeTableP shapes)
|
|
|
193 |
{
|
|
|
194 |
shape_table_iter (shapes, shape_entry_check_multi_defs, NIL (GenericP));
|
|
|
195 |
if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
|
|
|
196 |
exit (EXIT_FAILURE);
|
|
|
197 |
UNREACHED;
|
|
|
198 |
}
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
static void
|
|
|
202 |
builder_suppress_1 PROTO_N ((shape, all, names, gclosure))
|
|
|
203 |
PROTO_T (NStringP shape X
|
|
|
204 |
BoolT all X
|
|
|
205 |
NameKeyListP names X
|
|
|
206 |
GenericP gclosure)
|
|
|
207 |
{
|
|
|
208 |
ShapeTableP lib_shapes = (ShapeTableP) gclosure;
|
|
|
209 |
ShapeEntryP entry = shape_table_get (lib_shapes, shape);
|
|
|
210 |
|
|
|
211 |
if (entry) {
|
|
|
212 |
NameTableP table = shape_entry_name_table (entry);
|
|
|
213 |
NameKeyListEntryP name = name_key_list_head (names);
|
|
|
214 |
|
|
|
215 |
if (all) {
|
|
|
216 |
name_table_iter (table, name_entry_builder_suppress,
|
|
|
217 |
(GenericP) shape);
|
|
|
218 |
}
|
|
|
219 |
for (; name; name = name_key_list_entry_next (name)) {
|
|
|
220 |
NameKeyP key = name_key_list_entry_key (name);
|
|
|
221 |
NameEntryP name_entry = name_table_get (table, key);
|
|
|
222 |
|
|
|
223 |
if (name_entry) {
|
|
|
224 |
debug_info_l_suppress (shape, key);
|
|
|
225 |
name_entry_set_definition (name_entry, NIL (CapsuleP));
|
|
|
226 |
}
|
|
|
227 |
}
|
|
|
228 |
}
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
static void
|
|
|
232 |
builder_suppress PROTO_N ((arg_data, lib_shapes))
|
|
|
233 |
PROTO_T (ArgDataP arg_data X
|
|
|
234 |
ShapeTableP lib_shapes)
|
|
|
235 |
{
|
|
|
236 |
if (arg_data_get_suppress_mult (arg_data)) {
|
|
|
237 |
shape_table_iter (lib_shapes, shape_entry_suppress_mult,
|
|
|
238 |
NIL (GenericP));
|
|
|
239 |
}
|
|
|
240 |
shape_control_iter (arg_data_get_suppresses (arg_data), builder_suppress_1,
|
|
|
241 |
(GenericP) lib_shapes);
|
|
|
242 |
if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
|
|
|
243 |
exit (EXIT_FAILURE);
|
|
|
244 |
UNREACHED;
|
|
|
245 |
}
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
static void
|
|
|
249 |
builder_write_library PROTO_N ((arg_data, shapes, num_capsules, capsules))
|
|
|
250 |
PROTO_T (ArgDataP arg_data X
|
|
|
251 |
ShapeTableP shapes X
|
|
|
252 |
unsigned num_capsules X
|
|
|
253 |
CapsuleP *capsules)
|
|
|
254 |
{
|
|
|
255 |
CStringP output_file = arg_data_get_output_file (arg_data);
|
|
|
256 |
LibraryP library;
|
|
|
257 |
|
|
|
258 |
if ((library = library_create_stream_output (output_file)) !=
|
|
|
259 |
NIL (LibraryP)) {
|
|
|
260 |
library_write (library, shapes, num_capsules, capsules);
|
|
|
261 |
library_close (library);
|
|
|
262 |
} else {
|
|
|
263 |
E_cannot_open_output_file (output_file);
|
|
|
264 |
UNREACHED;
|
|
|
265 |
}
|
|
|
266 |
if (error_max_reported_severity () >= ERROR_SEVERITY_ERROR) {
|
|
|
267 |
exit (EXIT_FAILURE);
|
|
|
268 |
UNREACHED;
|
|
|
269 |
}
|
|
|
270 |
}
|
|
|
271 |
|
|
|
272 |
/*--------------------------------------------------------------------------*/
|
|
|
273 |
|
|
|
274 |
void
|
|
|
275 |
builder_main PROTO_N ((arg_data))
|
|
|
276 |
PROTO_T (ArgDataP arg_data)
|
|
|
277 |
{
|
|
|
278 |
UnitTableP units = unit_table_create ();
|
|
|
279 |
ShapeTableP shapes = shape_table_create ();
|
|
|
280 |
unsigned num_capsules;
|
|
|
281 |
CapsuleP *capsules;
|
|
|
282 |
|
|
|
283 |
capsules = builder_read_capsules (arg_data, units, shapes, &num_capsules);
|
|
|
284 |
builder_check_multi_defs (shapes);
|
|
|
285 |
builder_suppress (arg_data, shapes);
|
|
|
286 |
builder_write_library (arg_data, shapes, num_capsules, capsules);
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
/*
|
|
|
290 |
* Local variables(smf):
|
|
|
291 |
* eval: (include::add-path-entry "../os-interface" "../library" "../tdf")
|
|
|
292 |
* eval: (include::add-path-entry "../generated")
|
|
|
293 |
* End:
|
|
|
294 |
**/
|