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 |
#include "config.h"
|
|
|
32 |
#include "calculus.h"
|
|
|
33 |
#include "code.h"
|
|
|
34 |
#include "common.h"
|
|
|
35 |
#include "disk.h"
|
|
|
36 |
#include "output.h"
|
|
|
37 |
#include "suffix.h"
|
|
|
38 |
#include "type_ops.h"
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
/*
|
|
|
42 |
OUTPUT ENUMERATION READING ROUTINE
|
|
|
43 |
|
|
|
44 |
This routine outputs code for reading an enumeration type from disk.
|
|
|
45 |
This is done in two sections for long enumeration types.
|
|
|
46 |
*/
|
|
|
47 |
|
|
|
48 |
static void disk_read_enum
|
|
|
49 |
PROTO_Z ()
|
|
|
50 |
{
|
|
|
51 |
number n = log2 ( DEREF_number ( en_order ( CRT_ENUM ) ) ) ;
|
|
|
52 |
if ( n <= 16 ) {
|
|
|
53 |
output ( " x_ = ( %EN ) READ_BITS ( %n ) ;\n", n ) ;
|
|
|
54 |
} else {
|
|
|
55 |
n -= 16 ;
|
|
|
56 |
output ( " x_ = ( %EN ) READ_BITS ( 16 ) ;\n" ) ;
|
|
|
57 |
output ( " x_ += ( ( ( %EN ) READ_BITS ( %n ) ) << 16 ) ;\n", n ) ;
|
|
|
58 |
}
|
|
|
59 |
return ;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
|
|
|
63 |
/*
|
|
|
64 |
OUTPUT STRUCTURE READING ROUTINE
|
|
|
65 |
|
|
|
66 |
This routine outputs code for reading a structure type from disk.
|
|
|
67 |
*/
|
|
|
68 |
|
|
|
69 |
static void disk_read_struct
|
|
|
70 |
PROTO_Z ()
|
|
|
71 |
{
|
|
|
72 |
LOOP_STRUCTURE_COMPONENT {
|
|
|
73 |
TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
|
|
|
74 |
output ( " x_.%CN = READ_%TI () ;\n", t ) ;
|
|
|
75 |
}
|
|
|
76 |
return ;
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
/*
|
|
|
81 |
OUTPUT UNION READING ROUTINE
|
|
|
82 |
|
|
|
83 |
This routine outputs code for reading a union type from disk.
|
|
|
84 |
*/
|
|
|
85 |
|
|
|
86 |
static void disk_read_union
|
|
|
87 |
PROTO_Z ()
|
|
|
88 |
{
|
|
|
89 |
output ( " x_ = NULL_%UM ;\n" ) ;
|
|
|
90 |
output ( " if ( READ_BITS ( 1 ) == 1 ) {\n" ) ;
|
|
|
91 |
LOOP_UNION_COMPONENT output ( "\t%CT %CN ;\n" ) ;
|
|
|
92 |
output ( "\tunsigned tag_ = READ_BITS ( %UO2 ) ;\n" ) ;
|
|
|
93 |
output ( "\tswitch ( tag_ ) {\n" ) ;
|
|
|
94 |
LOOP_UNION_FIELD {
|
|
|
95 |
int al = DEREF_int ( fld_flag ( CRT_FIELD ) ) ;
|
|
|
96 |
output ( "\t case %UM_%FN_tag : {\n" ) ;
|
|
|
97 |
LOOP_FIELD_COMPONENT output ( "\t\t%CT %CN ;\n" ) ;
|
|
|
98 |
|
|
|
99 |
/* Deal with aliasing */
|
|
|
100 |
if ( al ) {
|
|
|
101 |
output ( "\t\tunsigned alias_ = READ_ALIAS () ;\n" ) ;
|
|
|
102 |
output ( "\t\tif ( READ_BITS ( 1 ) == 0 ) {\n" ) ;
|
|
|
103 |
output ( "\t\t x_ = FIND_ALIAS_%UM_%FN ( alias_ ) ;\n" ) ;
|
|
|
104 |
output ( "\t\t break ;\n" ) ;
|
|
|
105 |
output ( "\t\t}\n" ) ;
|
|
|
106 |
if ( al == 2 ) {
|
|
|
107 |
output ( "\t\tUNALIAS_%UM_%FN ( x_ ) ;\n" ) ;
|
|
|
108 |
output ( "\t\tSET_ALIAS_%UM_%FN ( x_, alias_ ) ;\n" ) ;
|
|
|
109 |
} else {
|
|
|
110 |
output ( "\t\tNEW_ALIAS_%UM_%FN ( x_, alias_ ) ;\n" ) ;
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
/* Read the components */
|
|
|
115 |
LOOP_UNION_COMPONENT {
|
|
|
116 |
TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
|
|
|
117 |
output ( "\t\t%CN = READ_%TI () ;\n", t ) ;
|
|
|
118 |
}
|
|
|
119 |
LOOP_FIELD_COMPONENT {
|
|
|
120 |
TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
|
|
|
121 |
output ( "\t\t%CN = READ_%TI () ;\n", t ) ;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
/* Assign components into x_ */
|
|
|
125 |
if ( al == 2 ) {
|
|
|
126 |
output ( "\t\tUNIFY_%UM_%FN ( " ) ;
|
|
|
127 |
LOOP_UNION_COMPONENT output ( "%CN, " ) ;
|
|
|
128 |
LOOP_FIELD_COMPONENT output ( "%CN, " ) ;
|
|
|
129 |
output ( "x_ ) ;\n" ) ;
|
|
|
130 |
output ( "\t\tSET_ALIAS_%UM_%FN ( x_, alias_ ) ;\n" ) ;
|
|
|
131 |
} else if ( al ) {
|
|
|
132 |
LOOP_UNION_COMPONENT {
|
|
|
133 |
TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
|
|
|
134 |
output ( "\t\tCOPY_%TM ( %UM_%CN ( x_ ), %CN ) ;\n", t ) ;
|
|
|
135 |
}
|
|
|
136 |
LOOP_FIELD_COMPONENT {
|
|
|
137 |
TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
|
|
|
138 |
output ( "\t\tCOPY_%TM ( %UM_%FN_%CN ( x_ ), %CN ) ;\n", t ) ;
|
|
|
139 |
}
|
|
|
140 |
} else {
|
|
|
141 |
int def = 0 ;
|
|
|
142 |
output ( "\t\tMAKE_%UM_%FN ( " ) ;
|
|
|
143 |
LOOP_UNION_COMPONENT {
|
|
|
144 |
string v = DEREF_string ( cmp_value ( CRT_COMPONENT ) ) ;
|
|
|
145 |
if ( v == NULL ) {
|
|
|
146 |
output ( "%CN, " ) ;
|
|
|
147 |
} else {
|
|
|
148 |
def = 1 ;
|
|
|
149 |
}
|
|
|
150 |
}
|
|
|
151 |
LOOP_FIELD_COMPONENT {
|
|
|
152 |
string v = DEREF_string ( cmp_value ( CRT_COMPONENT ) ) ;
|
|
|
153 |
if ( v == NULL ) {
|
|
|
154 |
output ( "%CN, " ) ;
|
|
|
155 |
} else {
|
|
|
156 |
def = 1 ;
|
|
|
157 |
}
|
|
|
158 |
}
|
|
|
159 |
output ( "x_ ) ;\n" ) ;
|
|
|
160 |
if ( def ) {
|
|
|
161 |
/* Override default values */
|
|
|
162 |
LOOP_UNION_COMPONENT {
|
|
|
163 |
string v = DEREF_string ( cmp_value ( CRT_COMPONENT ) ) ;
|
|
|
164 |
if ( v ) {
|
|
|
165 |
TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
|
|
|
166 |
output ( "\t\tCOPY_%TM ", t ) ;
|
|
|
167 |
output ( "( %UM_%CN ( x_ ), %CN ) ;\n" ) ;
|
|
|
168 |
}
|
|
|
169 |
}
|
|
|
170 |
LOOP_FIELD_COMPONENT {
|
|
|
171 |
string v = DEREF_string ( cmp_value ( CRT_COMPONENT ) ) ;
|
|
|
172 |
if ( v ) {
|
|
|
173 |
TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
|
|
|
174 |
output ( "\t\tCOPY_%TM ", t ) ;
|
|
|
175 |
output ( "( %UM_%FN_%CN ( x_ ), %CN ) ;\n" ) ;
|
|
|
176 |
}
|
|
|
177 |
}
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
output ( "\t\tbreak ;\n" ) ;
|
|
|
181 |
output ( "\t }\n" ) ;
|
|
|
182 |
}
|
|
|
183 |
output ( "\t}\n" ) ;
|
|
|
184 |
output ( " }\n" ) ;
|
|
|
185 |
return ;
|
|
|
186 |
}
|
|
|
187 |
|
|
|
188 |
|
|
|
189 |
/*
|
|
|
190 |
PRINT THE DISK READING DEFINITIONS
|
|
|
191 |
|
|
|
192 |
This routine prints all the routines for reading the various types
|
|
|
193 |
from disk.
|
|
|
194 |
*/
|
|
|
195 |
|
|
|
196 |
static void disk_read_def
|
|
|
197 |
PROTO_N ( ( dir ) )
|
|
|
198 |
PROTO_T ( char *dir )
|
|
|
199 |
{
|
|
|
200 |
open_file ( dir, READ_PREFIX, DEF_SUFFIX ) ;
|
|
|
201 |
print_include () ;
|
|
|
202 |
|
|
|
203 |
comment ( "Disk reading function declarations" ) ;
|
|
|
204 |
LOOP_TYPE {
|
|
|
205 |
TYPE_P t = CRT_TYPE ;
|
|
|
206 |
TYPE t0 = DEREF_type ( t ) ;
|
|
|
207 |
unsigned tag = TAG_type ( t0 ) ;
|
|
|
208 |
if ( is_identity_type ( t ) ) {
|
|
|
209 |
output ( "#ifndef READ_%TI\n", t ) ;
|
|
|
210 |
output ( "#define READ_%TI() READ_%TJ()\n", t, t ) ;
|
|
|
211 |
output ( "#endif\n\n" ) ;
|
|
|
212 |
} else if ( tag != type_primitive_tag ) {
|
|
|
213 |
output ( "#ifndef READ_%TI\n", t ) ;
|
|
|
214 |
output ( "static %TT READ_%TI PROTO_S ( ( void ) ) ;\n", t, t ) ;
|
|
|
215 |
output ( "#endif\n\n" ) ;
|
|
|
216 |
}
|
|
|
217 |
}
|
|
|
218 |
output ( "\n" ) ;
|
|
|
219 |
|
|
|
220 |
/* Function definitions */
|
|
|
221 |
LOOP_TYPE {
|
|
|
222 |
TYPE_P t = CRT_TYPE ;
|
|
|
223 |
TYPE t0 = DEREF_type ( t ) ;
|
|
|
224 |
unsigned tag = TAG_type ( t0 ) ;
|
|
|
225 |
if ( !is_identity_type ( t ) && tag != type_primitive_tag ) {
|
|
|
226 |
/* Function header */
|
|
|
227 |
output ( "/* Disk reading routine for %TT */\n\n", t ) ;
|
|
|
228 |
output ( "#ifndef READ_%TI\n\n", t ) ;
|
|
|
229 |
output ( "static %TT READ_%TI\n", t, t ) ;
|
|
|
230 |
output ( " PROTO_Z ()\n" ) ;
|
|
|
231 |
output ( "{\n" ) ;
|
|
|
232 |
output ( " %TT x_ ;\n", t ) ;
|
|
|
233 |
|
|
|
234 |
/* Function body */
|
|
|
235 |
switch ( tag ) {
|
|
|
236 |
|
|
|
237 |
case type_enumeration_tag : {
|
|
|
238 |
ENUM_P p = DEREF_ptr ( type_enumeration_en ( t0 ) ) ;
|
|
|
239 |
LOOP_ENUM {
|
|
|
240 |
if ( EQ_ptr ( CRT_ENUM, p ) ) {
|
|
|
241 |
disk_read_enum () ;
|
|
|
242 |
break ;
|
|
|
243 |
}
|
|
|
244 |
}
|
|
|
245 |
break ;
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
case type_structure_tag : {
|
|
|
249 |
STRUCTURE_P p = DEREF_ptr ( type_structure_struc ( t0 ) ) ;
|
|
|
250 |
LOOP_STRUCTURE {
|
|
|
251 |
if ( EQ_ptr ( CRT_STRUCTURE, p ) ) {
|
|
|
252 |
disk_read_struct () ;
|
|
|
253 |
break ;
|
|
|
254 |
}
|
|
|
255 |
}
|
|
|
256 |
break ;
|
|
|
257 |
}
|
|
|
258 |
|
|
|
259 |
case type_onion_tag : {
|
|
|
260 |
UNION_P p = DEREF_ptr ( type_onion_un ( t0 ) ) ;
|
|
|
261 |
LOOP_UNION {
|
|
|
262 |
if ( EQ_ptr ( CRT_UNION, p ) ) {
|
|
|
263 |
disk_read_union () ;
|
|
|
264 |
break ;
|
|
|
265 |
}
|
|
|
266 |
}
|
|
|
267 |
break ;
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
case type_ptr_tag : {
|
|
|
271 |
TYPE_P s = DEREF_ptr ( type_ptr_sub ( t0 ) ) ;
|
|
|
272 |
output ( " if ( READ_BITS ( 1 ) == 0 ) {\n" ) ;
|
|
|
273 |
output ( "\tx_ = NULL_ptr ( %TT ) ;\n", s ) ;
|
|
|
274 |
output ( " } else {\n" ) ;
|
|
|
275 |
output ( "\tx_ = MAKE_ptr ( %TS ) ;\n", s ) ;
|
|
|
276 |
output ( "\tCOPY_%TM ( x_, READ_%TI () ) ;\n", s, s ) ;
|
|
|
277 |
output ( " }\n" ) ;
|
|
|
278 |
break ;
|
|
|
279 |
}
|
|
|
280 |
|
|
|
281 |
case type_list_tag : {
|
|
|
282 |
TYPE_P s = DEREF_ptr ( type_list_sub ( t0 ) ) ;
|
|
|
283 |
output ( " x_ = NULL_list ( %TT ) ;\n", s ) ;
|
|
|
284 |
output ( " while ( READ_BITS ( 1 ) ) {\n" ) ;
|
|
|
285 |
output ( "\t%TT y_ ;\n", s ) ;
|
|
|
286 |
output ( "\t%TT z_ ;\n", t ) ;
|
|
|
287 |
output ( "\ty_ = READ_%TI () ;\n", s ) ;
|
|
|
288 |
output ( "\tCONS_%TM ( y_, NULL_list ( %TT ), z_ ) ;\n",
|
|
|
289 |
s, s ) ;
|
|
|
290 |
output ( "\tx_ = APPEND_list ( x_, z_ ) ;\n" ) ;
|
|
|
291 |
output ( " }\n" ) ;
|
|
|
292 |
break ;
|
|
|
293 |
}
|
|
|
294 |
|
|
|
295 |
case type_stack_tag : {
|
|
|
296 |
TYPE_P s = DEREF_ptr ( type_stack_sub ( t0 ) ) ;
|
|
|
297 |
output ( " LIST ( %TT ) w_ ;\n", s ) ;
|
|
|
298 |
output ( " w_ = NULL_list ( %TT ) ;\n", s ) ;
|
|
|
299 |
output ( " while ( READ_BITS ( 1 ) ) {\n" ) ;
|
|
|
300 |
output ( "\t%TT y_ ;\n", s ) ;
|
|
|
301 |
output ( "\t%TT z_ ;\n", t ) ;
|
|
|
302 |
output ( "\ty_ = READ_%TI () ;\n", s ) ;
|
|
|
303 |
output ( "\tCONS_%TM ( y_, NULL_list ( %TT ), z_ ) ;\n",
|
|
|
304 |
s, s ) ;
|
|
|
305 |
output ( "\tw_ = APPEND_list ( w_, z_ ) ;\n" ) ;
|
|
|
306 |
output ( " }\n" ) ;
|
|
|
307 |
output ( " x_ = STACK_list ( w_ ) ;\n" ) ;
|
|
|
308 |
break ;
|
|
|
309 |
}
|
|
|
310 |
|
|
|
311 |
case type_vec_tag : {
|
|
|
312 |
TYPE_P s = DEREF_ptr ( type_vec_sub ( t0 ) ) ;
|
|
|
313 |
output ( " PTR ( %TT ) y_ ;\n", s ) ;
|
|
|
314 |
output ( " %X_dim n_ = ( %X_dim ) READ_DIM () ;\n" ) ;
|
|
|
315 |
output ( " MAKE_vec ( %TS, n_, x_ ) ;\n", s ) ;
|
|
|
316 |
output ( " y_ = PTR_vec_ptr ( " ) ;
|
|
|
317 |
output ( "VEC_PTR_vec ( x_ ) ) ;\n" ) ;
|
|
|
318 |
output ( " while ( n_-- ) {\n" ) ;
|
|
|
319 |
output ( "\tCOPY_%TM ( y_, READ_%TI () ) ;\n", s, s ) ;
|
|
|
320 |
output ( "\ty_ = STEP_ptr ( y_, %TS ) ;\n", s ) ;
|
|
|
321 |
output ( " }\n" ) ;
|
|
|
322 |
break ;
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
case type_vec_ptr_tag : {
|
|
|
326 |
TYPE_P s = DEREF_ptr ( type_vec_ptr_sub ( t0 ) ) ;
|
|
|
327 |
output ( " VEC ( %TT ) y_ ;\n", s ) ;
|
|
|
328 |
output ( " PTR ( %TT ) z_ ;\n", s ) ;
|
|
|
329 |
output ( " MAKE_vec ( %TS, ( %X_dim ) 1, y_ ) ;\n", s ) ;
|
|
|
330 |
output ( " x_ = VEC_PTR_vec ( y_ ) ;\n" ) ;
|
|
|
331 |
output ( " z_ = PTR_vec_ptr ( x_ ) ;\n" ) ;
|
|
|
332 |
output ( " COPY_%TM ( z_, READ_%TI () ) ;\n", s, s ) ;
|
|
|
333 |
break ;
|
|
|
334 |
}
|
|
|
335 |
}
|
|
|
336 |
|
|
|
337 |
/* Function trailer */
|
|
|
338 |
output ( " return ( x_ ) ;\n" ) ;
|
|
|
339 |
output ( "}\n\n" ) ;
|
|
|
340 |
output ( "#endif\n\n\n", t ) ;
|
|
|
341 |
}
|
|
|
342 |
}
|
|
|
343 |
|
|
|
344 |
close_file () ;
|
|
|
345 |
return ;
|
|
|
346 |
}
|
|
|
347 |
|
|
|
348 |
|
|
|
349 |
/*
|
|
|
350 |
OUTPUT ENUMERATION WRITING ROUTINE
|
|
|
351 |
|
|
|
352 |
This routine outputs code for writing an enumeration type to disk.
|
|
|
353 |
This is done in two sections for long enumeration types.
|
|
|
354 |
*/
|
|
|
355 |
|
|
|
356 |
static void disk_write_enum
|
|
|
357 |
PROTO_Z ()
|
|
|
358 |
{
|
|
|
359 |
number n = log2 ( DEREF_number ( en_order ( CRT_ENUM ) ) ) ;
|
|
|
360 |
if ( n <= 16 ) {
|
|
|
361 |
output ( " WRITE_BITS ( %n, ( unsigned ) x_ ) ;\n", n ) ;
|
|
|
362 |
} else {
|
|
|
363 |
n -= 16 ;
|
|
|
364 |
output ( " WRITE_BITS ( 16, ( unsigned ) ( x_ & 0xffff ) ) ;\n" ) ;
|
|
|
365 |
output ( " WRITE_BITS ( %n, ( unsigned ) ( x_ >> 16 ) ) ;\n", n ) ;
|
|
|
366 |
}
|
|
|
367 |
return ;
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
|
|
|
371 |
/*
|
|
|
372 |
OUTPUT STRUCTURE WRITING ROUTINE
|
|
|
373 |
|
|
|
374 |
This routine outputs code for writing a structure type to disk.
|
|
|
375 |
*/
|
|
|
376 |
|
|
|
377 |
static void disk_write_struct
|
|
|
378 |
PROTO_Z ()
|
|
|
379 |
{
|
|
|
380 |
LOOP_STRUCTURE_COMPONENT {
|
|
|
381 |
TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
|
|
|
382 |
output ( " WRITE_%TI ( x_.%CN ) ;\n", t ) ;
|
|
|
383 |
}
|
|
|
384 |
return ;
|
|
|
385 |
}
|
|
|
386 |
|
|
|
387 |
|
|
|
388 |
/*
|
|
|
389 |
OUTPUT UNION WRITING ROUTINE
|
|
|
390 |
|
|
|
391 |
This routine outputs code for writing a union type to disk.
|
|
|
392 |
*/
|
|
|
393 |
|
|
|
394 |
static void disk_write_union
|
|
|
395 |
PROTO_Z ()
|
|
|
396 |
{
|
|
|
397 |
int have_ucmp = 0 ;
|
|
|
398 |
output ( " if ( IS_NULL_%UM ( x_ ) ) {\n" ) ;
|
|
|
399 |
output ( "\tWRITE_BITS ( 1, ( unsigned ) 0 ) ;\n" ) ;
|
|
|
400 |
output ( " } else {\n" ) ;
|
|
|
401 |
LOOP_UNION_COMPONENT {
|
|
|
402 |
output ( "\t%CT %CN ;\n" ) ;
|
|
|
403 |
have_ucmp = 1 ;
|
|
|
404 |
}
|
|
|
405 |
output ( "\tunsigned tag_ = TAG_%UM ( x_ ) ;\n" ) ;
|
|
|
406 |
output ( "\tWRITE_BITS ( 1, ( unsigned ) 1 ) ;\n" ) ;
|
|
|
407 |
output ( "\tWRITE_BITS ( %UO2, tag_ ) ;\n" ) ;
|
|
|
408 |
output ( "\tswitch ( tag_ ) {\n" ) ;
|
|
|
409 |
LOOP_UNION_FIELD {
|
|
|
410 |
int have_cmp = have_ucmp ;
|
|
|
411 |
int al = DEREF_int ( fld_flag ( CRT_FIELD ) ) ;
|
|
|
412 |
output ( "\t case %UM_%FN_tag : {\n" ) ;
|
|
|
413 |
LOOP_FIELD_COMPONENT {
|
|
|
414 |
output ( "\t\t%CT %CN ;\n" ) ;
|
|
|
415 |
have_cmp = 1 ;
|
|
|
416 |
}
|
|
|
417 |
|
|
|
418 |
/* Deal with aliasing */
|
|
|
419 |
if ( al ) {
|
|
|
420 |
output ( "\t\tunsigned alias_ = GET_ALIAS_%UM_%FN ( x_ ) ;\n" ) ;
|
|
|
421 |
output ( "\t\tif ( alias_ ) {\n" ) ;
|
|
|
422 |
output ( "\t\t WRITE_ALIAS ( alias_ ) ;\n" ) ;
|
|
|
423 |
output ( "\t\t WRITE_BITS ( 1, ( unsigned ) 0 ) ;\n" ) ;
|
|
|
424 |
output ( "\t\t break ;\n" ) ;
|
|
|
425 |
output ( "\t\t}\n" ) ;
|
|
|
426 |
output ( "\t\talias_ = ++crt_%X_alias ;\n" ) ;
|
|
|
427 |
output ( "\t\tSET_ALIAS_%UM_%FN ( x_, alias_ ) ;\n" ) ;
|
|
|
428 |
output ( "\t\tWRITE_ALIAS ( alias_ ) ;\n" ) ;
|
|
|
429 |
output ( "\t\tWRITE_BITS ( 1, ( unsigned ) 1 ) ;\n" ) ;
|
|
|
430 |
}
|
|
|
431 |
|
|
|
432 |
/* Deconstruct union */
|
|
|
433 |
if ( have_cmp ) {
|
|
|
434 |
output ( "\t\tDECONS_%UM_%FN ( " ) ;
|
|
|
435 |
LOOP_UNION_COMPONENT output ( "%CN, " ) ;
|
|
|
436 |
LOOP_FIELD_COMPONENT output ( "%CN, " ) ;
|
|
|
437 |
output ( " x_ ) ;\n" ) ;
|
|
|
438 |
}
|
|
|
439 |
|
|
|
440 |
/* Process further if necessary */
|
|
|
441 |
if ( al == 2 ) {
|
|
|
442 |
output ( "\t\tALIAS_%UM_%FN ( " ) ;
|
|
|
443 |
LOOP_UNION_COMPONENT output ( "%CN, " ) ;
|
|
|
444 |
LOOP_FIELD_COMPONENT output ( "%CN, " ) ;
|
|
|
445 |
output ( " x_ ) ;\n" ) ;
|
|
|
446 |
}
|
|
|
447 |
|
|
|
448 |
/* Write out components */
|
|
|
449 |
LOOP_UNION_COMPONENT {
|
|
|
450 |
TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
|
|
|
451 |
output ( "\t\tWRITE_%TI ( %CN ) ;\n", t ) ;
|
|
|
452 |
}
|
|
|
453 |
LOOP_FIELD_COMPONENT {
|
|
|
454 |
TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
|
|
|
455 |
output ( "\t\tWRITE_%TI ( %CN ) ;\n", t ) ;
|
|
|
456 |
}
|
|
|
457 |
output ( "\t\tbreak ;\n" ) ;
|
|
|
458 |
output ( "\t }\n" ) ;
|
|
|
459 |
}
|
|
|
460 |
output ( "\t}\n" ) ;
|
|
|
461 |
output ( " }\n" ) ;
|
|
|
462 |
return ;
|
|
|
463 |
}
|
|
|
464 |
|
|
|
465 |
|
|
|
466 |
/*
|
|
|
467 |
PRINT THE DISK WRITING DEFINITIONS
|
|
|
468 |
|
|
|
469 |
This routine outputs all the routines for writing the various types
|
|
|
470 |
to disk.
|
|
|
471 |
*/
|
|
|
472 |
|
|
|
473 |
static void disk_write_def
|
|
|
474 |
PROTO_N ( ( dir ) )
|
|
|
475 |
PROTO_T ( char *dir )
|
|
|
476 |
{
|
|
|
477 |
open_file ( dir, WRITE_PREFIX, DEF_SUFFIX ) ;
|
|
|
478 |
print_include () ;
|
|
|
479 |
|
|
|
480 |
comment ( "Disk writing function declarations" ) ;
|
|
|
481 |
LOOP_TYPE {
|
|
|
482 |
TYPE_P t = CRT_TYPE ;
|
|
|
483 |
TYPE t0 = DEREF_type ( t ) ;
|
|
|
484 |
unsigned tag = TAG_type ( t0 ) ;
|
|
|
485 |
if ( is_identity_type ( t ) ) {
|
|
|
486 |
output ( "#ifndef WRITE_%TI\n", t ) ;
|
|
|
487 |
output ( "#define WRITE_%TI( A ) WRITE_%TJ ( A )\n", t, t ) ;
|
|
|
488 |
output ( "#endif\n\n" ) ;
|
|
|
489 |
} else if ( tag != type_primitive_tag ) {
|
|
|
490 |
output ( "#ifndef WRITE_%TI\n", t ) ;
|
|
|
491 |
output ( "static void WRITE_%TI PROTO_S ( ( %TT ) ) ;\n", t, t ) ;
|
|
|
492 |
output ( "#endif\n\n" ) ;
|
|
|
493 |
}
|
|
|
494 |
}
|
|
|
495 |
output ( "\n" ) ;
|
|
|
496 |
|
|
|
497 |
/* Function definitions */
|
|
|
498 |
LOOP_TYPE {
|
|
|
499 |
TYPE_P t = CRT_TYPE ;
|
|
|
500 |
TYPE t0 = DEREF_type ( t ) ;
|
|
|
501 |
unsigned tag = TAG_type ( t0 ) ;
|
|
|
502 |
if ( !is_identity_type ( t ) && tag != type_primitive_tag ) {
|
|
|
503 |
/* Function header */
|
|
|
504 |
output ( "/* Disk writing routine for %TT */\n\n", t ) ;
|
|
|
505 |
output ( "#ifndef WRITE_%TI\n\n", t ) ;
|
|
|
506 |
output ( "static void WRITE_%TI\n", t ) ;
|
|
|
507 |
output ( " PROTO_N ( ( x_ ) )\n" ) ;
|
|
|
508 |
output ( " PROTO_T ( %TT x_ )\n", t ) ;
|
|
|
509 |
output ( "{\n" ) ;
|
|
|
510 |
|
|
|
511 |
/* Function body */
|
|
|
512 |
switch ( tag ) {
|
|
|
513 |
|
|
|
514 |
case type_enumeration_tag : {
|
|
|
515 |
ENUM_P p = DEREF_ptr ( type_enumeration_en ( t0 ) ) ;
|
|
|
516 |
LOOP_ENUM {
|
|
|
517 |
if ( EQ_ptr ( CRT_ENUM, p ) ) {
|
|
|
518 |
disk_write_enum () ;
|
|
|
519 |
break ;
|
|
|
520 |
}
|
|
|
521 |
}
|
|
|
522 |
break ;
|
|
|
523 |
}
|
|
|
524 |
|
|
|
525 |
case type_structure_tag : {
|
|
|
526 |
STRUCTURE_P p = DEREF_ptr ( type_structure_struc ( t0 ) ) ;
|
|
|
527 |
LOOP_STRUCTURE {
|
|
|
528 |
if ( EQ_ptr ( CRT_STRUCTURE, p ) ) {
|
|
|
529 |
disk_write_struct () ;
|
|
|
530 |
break ;
|
|
|
531 |
}
|
|
|
532 |
}
|
|
|
533 |
break ;
|
|
|
534 |
}
|
|
|
535 |
|
|
|
536 |
case type_onion_tag : {
|
|
|
537 |
UNION_P p = DEREF_ptr ( type_onion_un ( t0 ) ) ;
|
|
|
538 |
LOOP_UNION {
|
|
|
539 |
if ( EQ_ptr ( CRT_UNION, p ) ) {
|
|
|
540 |
disk_write_union () ;
|
|
|
541 |
break ;
|
|
|
542 |
}
|
|
|
543 |
}
|
|
|
544 |
break ;
|
|
|
545 |
}
|
|
|
546 |
|
|
|
547 |
case type_ptr_tag : {
|
|
|
548 |
TYPE_P s = DEREF_ptr ( type_ptr_sub ( t0 ) ) ;
|
|
|
549 |
output ( " if ( IS_NULL_ptr ( x_ ) ) {\n" ) ;
|
|
|
550 |
output ( "\tWRITE_BITS ( 1, ( unsigned ) 0 ) ;\n" ) ;
|
|
|
551 |
output ( " } else {\n" ) ;
|
|
|
552 |
output ( "\t%TT y_ ;\n\t", s ) ;
|
|
|
553 |
print_deref ( s, "x_", "y_" ) ;
|
|
|
554 |
output ( "\tWRITE_BITS ( 1, ( unsigned ) 1 ) ;\n" ) ;
|
|
|
555 |
output ( "\tWRITE_%TI ( y_ ) ;\n", s ) ;
|
|
|
556 |
output ( " }\n" ) ;
|
|
|
557 |
break ;
|
|
|
558 |
}
|
|
|
559 |
|
|
|
560 |
case type_list_tag : {
|
|
|
561 |
TYPE_P s = DEREF_ptr ( type_list_sub ( t0 ) ) ;
|
|
|
562 |
output ( " while ( !IS_NULL_list ( x_ ) ) {\n" ) ;
|
|
|
563 |
output ( "\t%TT y_ ;\n\t", s ) ;
|
|
|
564 |
print_deref ( s, "HEAD_list ( x_ )", "y_" ) ;
|
|
|
565 |
output ( "\tWRITE_BITS ( 1, ( unsigned ) 1 ) ;\n" ) ;
|
|
|
566 |
output ( "\tWRITE_%TI ( y_ ) ;\n", s ) ;
|
|
|
567 |
output ( "\tx_ = TAIL_list ( x_ ) ;\n" ) ;
|
|
|
568 |
output ( " }\n" ) ;
|
|
|
569 |
output ( " WRITE_BITS ( 1, ( unsigned ) 0 ) ;\n" ) ;
|
|
|
570 |
break ;
|
|
|
571 |
}
|
|
|
572 |
|
|
|
573 |
case type_stack_tag : {
|
|
|
574 |
TYPE_P s = DEREF_ptr ( type_stack_sub ( t0 ) ) ;
|
|
|
575 |
output ( " LIST ( %TT ) w_ = LIST_stack ( x_ ) ;\n", s ) ;
|
|
|
576 |
output ( " while ( !IS_NULL_list ( w_ ) ) {\n" ) ;
|
|
|
577 |
output ( "\t%TT y_ ;\n\t", s ) ;
|
|
|
578 |
print_deref ( s, "HEAD_list ( w_ )", "y_" ) ;
|
|
|
579 |
output ( "\tWRITE_BITS ( 1, ( unsigned ) 1 ) ;\n" ) ;
|
|
|
580 |
output ( "\tWRITE_%TI ( y_ ) ;\n", s ) ;
|
|
|
581 |
output ( "\tw_ = TAIL_list ( w_ ) ;\n" ) ;
|
|
|
582 |
output ( " }\n" ) ;
|
|
|
583 |
output ( " WRITE_BITS ( 1, ( unsigned ) 0 ) ;\n" ) ;
|
|
|
584 |
break ;
|
|
|
585 |
}
|
|
|
586 |
|
|
|
587 |
case type_vec_tag : {
|
|
|
588 |
TYPE_P s = DEREF_ptr ( type_vec_sub ( t0 ) ) ;
|
|
|
589 |
output ( " %X_dim n_ = DIM_vec ( x_ );\n" ) ;
|
|
|
590 |
output ( " PTR ( %TT ) y_ ", s ) ;
|
|
|
591 |
output ( " = PTR_vec_ptr ( VEC_PTR_vec ( x_ ) ) ;\n" ) ;
|
|
|
592 |
output ( " WRITE_DIM ( ( unsigned ) n_ ) ;\n" ) ;
|
|
|
593 |
output ( " while ( n_-- ) {\n" ) ;
|
|
|
594 |
output ( "\t%TT z_ ;\n\t", s ) ;
|
|
|
595 |
print_deref ( s, "y_", "z_" ) ;
|
|
|
596 |
output ( "\tWRITE_%TI ( z_ ) ;\n", s ) ;
|
|
|
597 |
output ( "\ty_ = STEP_ptr ( y_, %TS ) ;\n", s ) ;
|
|
|
598 |
output ( " }\n" ) ;
|
|
|
599 |
break ;
|
|
|
600 |
}
|
|
|
601 |
|
|
|
602 |
case type_vec_ptr_tag : {
|
|
|
603 |
TYPE_P s = DEREF_ptr ( type_vec_ptr_sub ( t0 ) ) ;
|
|
|
604 |
output ( " PTR ( %TT ) y_ = PTR_vec_ptr ( x_ ) ;\n", s ) ;
|
|
|
605 |
output ( " %TT z_ ;\n ", s ) ;
|
|
|
606 |
print_deref ( s, "y_", "z_" ) ;
|
|
|
607 |
output ( " WRITE_%TI ( z_ ) ;\n", s ) ;
|
|
|
608 |
break ;
|
|
|
609 |
}
|
|
|
610 |
}
|
|
|
611 |
|
|
|
612 |
/* Function trailer */
|
|
|
613 |
output ( " return ;\n" ) ;
|
|
|
614 |
output ( "}\n\n" ) ;
|
|
|
615 |
output ( "#endif\n\n\n" ) ;
|
|
|
616 |
}
|
|
|
617 |
}
|
|
|
618 |
close_file () ;
|
|
|
619 |
return ;
|
|
|
620 |
}
|
|
|
621 |
|
|
|
622 |
|
|
|
623 |
/*
|
|
|
624 |
MAIN DISK ACTION
|
|
|
625 |
|
|
|
626 |
This routine prints all the output files for reading and writing the
|
|
|
627 |
calculus to disk.
|
|
|
628 |
*/
|
|
|
629 |
|
|
|
630 |
void disk_action
|
|
|
631 |
PROTO_N ( ( dir ) )
|
|
|
632 |
PROTO_T ( char *dir )
|
|
|
633 |
{
|
|
|
634 |
disk_read_def ( dir ) ;
|
|
|
635 |
disk_write_def ( dir ) ;
|
|
|
636 |
return ;
|
|
|
637 |
}
|