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 |
/*** unit-entry.c --- Unit set table entry ADT.
|
|
|
62 |
*
|
|
|
63 |
** Author: Steve Folkes <smf@hermes.mod.uk>
|
|
|
64 |
*
|
|
|
65 |
*** Commentary:
|
|
|
66 |
*
|
|
|
67 |
* This file implements the unit set table entry routines used by the TDF
|
|
|
68 |
* linker.
|
|
|
69 |
*
|
|
|
70 |
*** Change Log:
|
|
|
71 |
* $Log: unit-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:43 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:47:05 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:40 smf
|
|
|
87 |
* Initial import of TDF linker 3.5 non shared files.
|
|
|
88 |
*
|
|
|
89 |
**/
|
|
|
90 |
|
|
|
91 |
/****************************************************************************/
|
|
|
92 |
|
|
|
93 |
#include "unit-entry.h"
|
|
|
94 |
#include "debug.h"
|
|
|
95 |
#include "shape-entry.h"
|
|
|
96 |
#include "tdf.h"
|
|
|
97 |
|
|
|
98 |
#include "solve-cycles.h"
|
|
|
99 |
|
|
|
100 |
/*--------------------------------------------------------------------------*/
|
|
|
101 |
|
|
|
102 |
static void
|
6 |
7u83 |
103 |
unit_write(UnitP unit, ShapeTableP shapes ,
|
|
|
104 |
unsigned num_shapes ,
|
2 |
7u83 |
105 |
TDFWriterP writer)
|
|
|
106 |
{
|
6 |
7u83 |
107 |
unsigned length = nstring_length(& (unit->contents));
|
2 |
7u83 |
108 |
MapTableP table;
|
|
|
109 |
|
6 |
7u83 |
110 |
if ((table = unit->map_table) != NIL(MapTableP)) {
|
2 |
7u83 |
111 |
ShapeClosureT shape_closure;
|
|
|
112 |
|
|
|
113 |
shape_closure.table = table;
|
|
|
114 |
shape_closure.writer = writer;
|
6 |
7u83 |
115 |
debug_info_w_start_counts(num_shapes);
|
|
|
116 |
tdf_write_int(writer, num_shapes);
|
|
|
117 |
shape_table_iter(shapes, shape_entry_write_count,
|
|
|
118 |
(GenericP) &shape_closure);
|
|
|
119 |
debug_info_w_start_maps(num_shapes);
|
|
|
120 |
tdf_write_int(writer, num_shapes);
|
|
|
121 |
shape_table_iter(shapes, shape_entry_write_links,
|
|
|
122 |
(GenericP) &shape_closure);
|
2 |
7u83 |
123 |
} else {
|
6 |
7u83 |
124 |
debug_info_w_start_counts((unsigned)0);
|
|
|
125 |
tdf_write_int(writer,(unsigned)0);
|
|
|
126 |
debug_info_w_start_maps((unsigned)0);
|
|
|
127 |
tdf_write_int(writer,(unsigned)0);
|
2 |
7u83 |
128 |
}
|
6 |
7u83 |
129 |
debug_info_w_unit_body(length);
|
|
|
130 |
tdf_write_int(writer, length);
|
|
|
131 |
tdf_write_bytes(writer, & (unit->contents));
|
2 |
7u83 |
132 |
}
|
|
|
133 |
|
|
|
134 |
/*--------------------------------------------------------------------------*/
|
|
|
135 |
|
|
|
136 |
void
|
6 |
7u83 |
137 |
unit_set_contents(UnitP unit, NStringP nstring)
|
2 |
7u83 |
138 |
{
|
6 |
7u83 |
139 |
nstring_assign(& (unit->contents), nstring);
|
2 |
7u83 |
140 |
}
|
|
|
141 |
|
|
|
142 |
MapTableP
|
6 |
7u83 |
143 |
unit_map_table(UnitP unit)
|
2 |
7u83 |
144 |
{
|
6 |
7u83 |
145 |
return(unit->map_table);
|
2 |
7u83 |
146 |
}
|
|
|
147 |
|
|
|
148 |
UnitEntryP
|
6 |
7u83 |
149 |
unit_entry_create(NStringP key, UnitEntryP next ,
|
2 |
7u83 |
150 |
unsigned order)
|
|
|
151 |
{
|
6 |
7u83 |
152 |
UnitEntryP entry = ALLOCATE(UnitEntryT);
|
2 |
7u83 |
153 |
|
|
|
154 |
entry->next = next;
|
|
|
155 |
entry->order = order;
|
6 |
7u83 |
156 |
nstring_copy(& (entry->key), key);
|
|
|
157 |
entry->head = NIL(UnitP);
|
|
|
158 |
entry->tail = & (entry->head);
|
|
|
159 |
return(entry);
|
2 |
7u83 |
160 |
}
|
|
|
161 |
|
|
|
162 |
UnitEntryP
|
6 |
7u83 |
163 |
unit_entry_next(UnitEntryP entry)
|
2 |
7u83 |
164 |
{
|
6 |
7u83 |
165 |
return(entry->next);
|
2 |
7u83 |
166 |
}
|
|
|
167 |
|
|
|
168 |
NStringP
|
6 |
7u83 |
169 |
unit_entry_key(UnitEntryP entry)
|
2 |
7u83 |
170 |
{
|
6 |
7u83 |
171 |
return(& (entry->key));
|
2 |
7u83 |
172 |
}
|
|
|
173 |
|
|
|
174 |
unsigned
|
6 |
7u83 |
175 |
unit_entry_order(UnitEntryP entry)
|
2 |
7u83 |
176 |
{
|
6 |
7u83 |
177 |
return(entry->order);
|
2 |
7u83 |
178 |
}
|
|
|
179 |
|
|
|
180 |
UnitP
|
6 |
7u83 |
181 |
unit_entry_add_unit(UnitEntryP entry, unsigned num_counts)
|
2 |
7u83 |
182 |
{
|
6 |
7u83 |
183 |
UnitP unit = ALLOCATE(UnitT);
|
2 |
7u83 |
184 |
|
6 |
7u83 |
185 |
unit->next = NIL(UnitP);
|
|
|
186 |
unit->map_table = ((num_counts != 0)?
|
|
|
187 |
map_table_create(): NIL(MapTableP));
|
|
|
188 |
*(entry->tail) = unit;
|
|
|
189 |
entry->tail = & (unit->next);
|
|
|
190 |
return(unit);
|
2 |
7u83 |
191 |
}
|
|
|
192 |
|
|
|
193 |
/*--------------------------------------------------------------------------*/
|
|
|
194 |
|
|
|
195 |
void
|
6 |
7u83 |
196 |
unit_entry_do_count(UnitEntryP entry, GenericP gclosure)
|
2 |
7u83 |
197 |
{
|
6 |
7u83 |
198 |
UnitSetClosureP closure = (UnitSetClosureP)gclosure;
|
2 |
7u83 |
199 |
UnitP unit;
|
|
|
200 |
|
6 |
7u83 |
201 |
if ((unit = entry->head) != NIL(UnitP)) {
|
2 |
7u83 |
202 |
while (unit) {
|
|
|
203 |
MapTableP table;
|
|
|
204 |
|
6 |
7u83 |
205 |
if ((table = unit->map_table) != NIL(MapTableP)) {
|
|
|
206 |
map_table_iter(table, map_entry_check_non_empty,
|
|
|
207 |
(GenericP)closure->shapes);
|
2 |
7u83 |
208 |
}
|
|
|
209 |
unit = unit->next;
|
|
|
210 |
}
|
6 |
7u83 |
211 |
closure->num_unit_sets++;
|
2 |
7u83 |
212 |
}
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
void
|
6 |
7u83 |
216 |
unit_entry_write_unit_set(UnitEntryP entry, UnitEntryP tld_entry ,
|
2 |
7u83 |
217 |
TDFWriterP writer)
|
|
|
218 |
{
|
|
|
219 |
if ((entry->head) || (entry == tld_entry)) {
|
6 |
7u83 |
220 |
NStringP key = unit_entry_key(entry);
|
2 |
7u83 |
221 |
|
6 |
7u83 |
222 |
debug_info_w_unit_dec(key);
|
|
|
223 |
tdf_write_string(writer, key);
|
2 |
7u83 |
224 |
}
|
|
|
225 |
}
|
|
|
226 |
|
|
|
227 |
void
|
6 |
7u83 |
228 |
unit_entry_write_tld_unit(UnitEntryP entry, ShapeTableP shapes ,
|
2 |
7u83 |
229 |
TDFWriterP writer)
|
|
|
230 |
{
|
6 |
7u83 |
231 |
unsigned size = (tdf_int_size((unsigned)1) + 1);
|
|
|
232 |
NStringP key = unit_entry_key(entry);
|
2 |
7u83 |
233 |
|
6 |
7u83 |
234 |
debug_info_w_start_units(key,(unsigned)1);
|
|
|
235 |
tdf_write_int(writer,(unsigned)1);
|
|
|
236 |
debug_info_w_start_unit(key,(unsigned)1,(unsigned)1);
|
|
|
237 |
debug_info_w_start_counts((unsigned)0);
|
|
|
238 |
tdf_write_int(writer,(unsigned)0);
|
|
|
239 |
debug_info_w_start_maps((unsigned)0);
|
|
|
240 |
tdf_write_int(writer,(unsigned)0);
|
|
|
241 |
shape_table_iter(shapes, shape_entry_compute_tld_size,(GenericP) &size);
|
2 |
7u83 |
242 |
size /= 2;
|
6 |
7u83 |
243 |
debug_info_w_unit_body(size);
|
|
|
244 |
tdf_write_int(writer, size);
|
|
|
245 |
tdf_write_align(writer);
|
|
|
246 |
debug_info_w_tld_version((unsigned)1);
|
|
|
247 |
tdf_write_int(writer,(unsigned)1);
|
|
|
248 |
shape_table_iter(shapes, shape_entry_write_tld,(GenericP)writer);
|
|
|
249 |
tdf_write_align(writer);
|
2 |
7u83 |
250 |
}
|
|
|
251 |
|
|
|
252 |
void
|
6 |
7u83 |
253 |
unit_entry_write_units(UnitEntryP entry, ShapeTableP shapes ,
|
|
|
254 |
unsigned num_shapes ,
|
2 |
7u83 |
255 |
TDFWriterP writer)
|
|
|
256 |
{
|
|
|
257 |
unsigned num_units = 0;
|
6 |
7u83 |
258 |
NStringP key = unit_entry_key(entry);
|
2 |
7u83 |
259 |
UnitP unit;
|
|
|
260 |
|
|
|
261 |
for (unit = entry->head; unit; unit = unit->next) {
|
6 |
7u83 |
262 |
num_units++;
|
2 |
7u83 |
263 |
}
|
|
|
264 |
if (num_units > 0) {
|
|
|
265 |
unsigned i;
|
|
|
266 |
|
6 |
7u83 |
267 |
debug_info_w_start_units(key, num_units);
|
|
|
268 |
tdf_write_int(writer, num_units);
|
|
|
269 |
for (unit = entry->head, i = 1; unit; unit = unit->next, i++) {
|
|
|
270 |
debug_info_w_start_unit(key, i, num_units);
|
|
|
271 |
unit_write(unit, shapes, num_shapes, writer);
|
2 |
7u83 |
272 |
}
|
|
|
273 |
}
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
/*
|
|
|
277 |
* Local variables(smf):
|
|
|
278 |
* eval: (include::add-path-entry "../os-interface" "../library")
|
|
|
279 |
* eval: (include::add-path-entry "../generated")
|
|
|
280 |
* end:
|
|
|
281 |
**/
|