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