Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 243

Warning: Undefined variable $n in /usr/local/www/websvn.planix.org/include/diff_util.php on line 247

Warning: Undefined variable $m in /usr/local/www/websvn.planix.org/include/diff_util.php on line 251
WebSVN – tendra.SVN – Diff – /branches/tendra5/src/utilities/calculus/disk.c – Rev 5 and 6

Subversion Repositories tendra.SVN

Rev

Rev 5 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 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
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
29
 
59
 
30
 
60
 
31
#include "config.h"
61
#include "config.h"
32
#include "calculus.h"
62
#include "calculus.h"
33
#include "code.h"
63
#include "code.h"
34
#include "common.h"
64
#include "common.h"
35
#include "disk.h"
65
#include "disk.h"
36
#include "output.h"
66
#include "output.h"
37
#include "suffix.h"
67
#include "suffix.h"
38
#include "type_ops.h"
68
#include "type_ops.h"
39
 
69
 
40
 
70
 
41
/*
71
/*
42
    OUTPUT ENUMERATION READING ROUTINE
72
 * OUTPUT ENUMERATION READING ROUTINE
43
 
73
 *
44
    This routine outputs code for reading an enumeration type from disk.
74
 * This routine outputs code for reading an enumeration type from disk.
45
    This is done in two sections for long enumeration types.
75
 * This is done in two sections for long enumeration types.
46
*/
76
 */
47
 
77
 
48
static void disk_read_enum
78
static void
49
    PROTO_Z ()
79
disk_read_enum(void)
50
{
80
{
51
    number n = log2 ( DEREF_number ( en_order ( CRT_ENUM ) ) ) ;
81
    number n = log2(DEREF_number(en_order(CRT_ENUM)));
52
    if ( n <= 16 ) {
82
    if (n <= 16) {
53
	output ( "    x_ = ( %EN ) READ_BITS ( %n ) ;\n", n ) ;
83
	output("    x_ = (%EN)READ_BITS(%n);\n", n);
54
    } else {
84
    } else {
55
	n -= 16 ;
85
	n -= 16;
56
	output ( "    x_ = ( %EN ) READ_BITS ( 16 ) ;\n" ) ;
86
	output("    x_ = (%EN)READ_BITS(16);\n");
57
	output ( "    x_ += ( ( ( %EN ) READ_BITS ( %n ) ) << 16 ) ;\n", n ) ;
87
	output("    x_ += (((%EN)READ_BITS(%n)) << 16);\n", n);
58
    }
88
    }
59
    return ;
89
    return;
60
}
90
}
61
 
91
 
62
 
92
 
63
/*
93
/*
64
    OUTPUT STRUCTURE READING ROUTINE
94
 * OUTPUT STRUCTURE READING ROUTINE
65
 
95
 *
66
    This routine outputs code for reading a structure type from disk.
96
 * This routine outputs code for reading a structure type from disk.
67
*/
97
 */
68
 
98
 
69
static void disk_read_struct
99
static void
70
    PROTO_Z ()
100
disk_read_struct(void)
71
{
101
{
72
    LOOP_STRUCTURE_COMPONENT {
102
    LOOP_STRUCTURE_COMPONENT {
73
	TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
103
	TYPE_P t = DEREF_ptr(cmp_type(CRT_COMPONENT));
74
	output ( "    x_.%CN = READ_%TI () ;\n", t ) ;
104
	output("    x_.%CN = READ_%TI();\n", t);
75
    }
105
    }
76
    return ;
106
    return;
77
}
107
}
78
 
108
 
79
 
109
 
80
/*
110
/*
81
    OUTPUT UNION READING ROUTINE
111
 * OUTPUT UNION READING ROUTINE
82
 
112
 *
83
    This routine outputs code for reading a union type from disk.
113
 * This routine outputs code for reading a union type from disk.
84
*/
114
 */
85
 
115
 
86
static void disk_read_union
116
static void
87
    PROTO_Z ()
117
disk_read_union(void)
88
{
118
{
89
    output ( "    x_ = NULL_%UM ;\n" ) ;
119
    output("    x_ = NULL_%UM;\n");
90
    output ( "    if ( READ_BITS ( 1 ) == 1 ) {\n" ) ;
120
    output("    if (READ_BITS(1) == 1) {\n");
91
    LOOP_UNION_COMPONENT output ( "\t%CT %CN ;\n" ) ;
121
    LOOP_UNION_COMPONENT output("\t%CT %CN;\n");
92
    output ( "\tunsigned tag_ = READ_BITS ( %UO2 ) ;\n" ) ;
122
    output("\tunsigned tag_ = READ_BITS(%UO2);\n");
93
    output ( "\tswitch ( tag_ ) {\n" ) ;
123
    output("\tswitch (tag_) {\n");
94
    LOOP_UNION_FIELD {
124
    LOOP_UNION_FIELD {
95
	int al = DEREF_int ( fld_flag ( CRT_FIELD ) ) ;
125
	int al = DEREF_int(fld_flag(CRT_FIELD));
96
	output ( "\t    case %UM_%FN_tag : {\n" ) ;
126
	output("\t    case %UM_%FN_tag: {\n");
97
	LOOP_FIELD_COMPONENT output ( "\t\t%CT %CN ;\n" ) ;
127
	LOOP_FIELD_COMPONENT output("\t\t%CT %CN;\n");
98
 
128
 
99
	/* Deal with aliasing */
129
	/* Deal with aliasing */
100
	if ( al ) {
130
	if (al) {
101
	    output ( "\t\tunsigned alias_ = READ_ALIAS () ;\n" ) ;
131
	    output("\t\tunsigned alias_ = READ_ALIAS();\n");
102
	    output ( "\t\tif ( READ_BITS ( 1 ) == 0 ) {\n" ) ;
132
	    output("\t\tif (READ_BITS(1) == 0) {\n");
103
	    output ( "\t\t    x_ = FIND_ALIAS_%UM_%FN ( alias_ ) ;\n" ) ;
133
	    output("\t\t    x_ = FIND_ALIAS_%UM_%FN(alias_);\n");
104
	    output ( "\t\t    break ;\n" ) ;
134
	    output("\t\t    break;\n");
105
	    output ( "\t\t}\n" ) ;
135
	    output("\t\t}\n");
106
	    if ( al == 2 ) {
136
	    if (al == 2) {
107
		output ( "\t\tUNALIAS_%UM_%FN ( x_ ) ;\n" ) ;
137
		output("\t\tUNALIAS_%UM_%FN(x_);\n");
108
		output ( "\t\tSET_ALIAS_%UM_%FN ( x_, alias_ ) ;\n" ) ;
138
		output("\t\tSET_ALIAS_%UM_%FN(x_, alias_);\n");
109
	    } else {
139
	    } else {
110
		output ( "\t\tNEW_ALIAS_%UM_%FN ( x_, alias_ ) ;\n" ) ;
140
		output("\t\tNEW_ALIAS_%UM_%FN(x_, alias_);\n");
111
	    }
141
	    }
112
	}
142
	}
113
 
143
 
114
	/* Read the components */
144
	/* Read the components */
115
	LOOP_UNION_COMPONENT {
145
	LOOP_UNION_COMPONENT {
116
	    TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
146
	    TYPE_P t = DEREF_ptr(cmp_type(CRT_COMPONENT));
117
	    output ( "\t\t%CN = READ_%TI () ;\n", t ) ;
147
	    output("\t\t%CN = READ_%TI();\n", t);
118
	}
148
	}
119
	LOOP_FIELD_COMPONENT {
149
	LOOP_FIELD_COMPONENT {
120
	    TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
150
	    TYPE_P t = DEREF_ptr(cmp_type(CRT_COMPONENT));
121
	    output ( "\t\t%CN = READ_%TI () ;\n", t ) ;
151
	    output("\t\t%CN = READ_%TI();\n", t);
122
	}
152
	}
123
 
153
 
124
	/* Assign components into x_ */
154
	/* Assign components into x_ */
125
	if ( al == 2 ) {
155
	if (al == 2) {
126
	    output ( "\t\tUNIFY_%UM_%FN ( " ) ;
156
	    output("\t\tUNIFY_%UM_%FN(");
127
	    LOOP_UNION_COMPONENT output ( "%CN, " ) ;
157
	    LOOP_UNION_COMPONENT output("%CN, ");
128
	    LOOP_FIELD_COMPONENT output ( "%CN, " ) ;
158
	    LOOP_FIELD_COMPONENT output("%CN, ");
129
	    output ( "x_ ) ;\n" ) ;
159
	    output("x_);\n");
130
	    output ( "\t\tSET_ALIAS_%UM_%FN ( x_, alias_ ) ;\n" ) ;
160
	    output("\t\tSET_ALIAS_%UM_%FN(x_, alias_);\n");
131
	} else if ( al ) {
161
	} else if (al) {
132
	    LOOP_UNION_COMPONENT {
162
	    LOOP_UNION_COMPONENT {
133
		TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
163
		TYPE_P t = DEREF_ptr(cmp_type(CRT_COMPONENT));
134
		output ( "\t\tCOPY_%TM ( %UM_%CN ( x_ ), %CN ) ;\n", t ) ;
164
		output("\t\tCOPY_%TM(%UM_%CN(x_), %CN);\n", t);
135
	    }
165
	    }
136
	    LOOP_FIELD_COMPONENT {
166
	    LOOP_FIELD_COMPONENT {
137
		TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
167
		TYPE_P t = DEREF_ptr(cmp_type(CRT_COMPONENT));
138
		output ( "\t\tCOPY_%TM ( %UM_%FN_%CN ( x_ ), %CN ) ;\n", t ) ;
168
		output("\t\tCOPY_%TM(%UM_%FN_%CN(x_), %CN);\n", t);
139
	    }
169
	    }
140
	} else {
170
	} else {
141
	    int def = 0 ;
171
	    int def = 0;
142
	    output ( "\t\tMAKE_%UM_%FN ( " ) ;
172
	    output("\t\tMAKE_%UM_%FN(");
143
	    LOOP_UNION_COMPONENT {
173
	    LOOP_UNION_COMPONENT {
144
		string v = DEREF_string ( cmp_value ( CRT_COMPONENT ) ) ;
174
		string v = DEREF_string(cmp_value(CRT_COMPONENT));
145
		if ( v == NULL ) {
175
		if (v == NULL) {
146
		    output ( "%CN, " ) ;
176
		    output("%CN, ");
147
		} else {
177
		} else {
148
		    def = 1 ;
178
		    def = 1;
149
		}
179
		}
150
	    }
180
	    }
151
	    LOOP_FIELD_COMPONENT {
181
	    LOOP_FIELD_COMPONENT {
152
		string v = DEREF_string ( cmp_value ( CRT_COMPONENT ) ) ;
182
		string v = DEREF_string(cmp_value(CRT_COMPONENT));
153
		if ( v == NULL ) {
183
		if (v == NULL) {
154
		    output ( "%CN, " ) ;
184
		    output("%CN, ");
155
		} else {
185
		} else {
156
		    def = 1 ;
186
		    def = 1;
157
		}
187
		}
158
	    }
188
	    }
159
	    output ( "x_ ) ;\n" ) ;
189
	    output("x_ );\n");
160
	    if ( def ) {
190
	    if (def) {
161
		/* Override default values */
191
		/* Override default values */
162
		LOOP_UNION_COMPONENT {
192
		LOOP_UNION_COMPONENT {
163
		    string v = DEREF_string ( cmp_value ( CRT_COMPONENT ) ) ;
193
		    string v = DEREF_string(cmp_value(CRT_COMPONENT));
164
		    if ( v ) {
194
		    if (v) {
165
			TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
195
			TYPE_P t = DEREF_ptr(cmp_type(CRT_COMPONENT));
166
			output ( "\t\tCOPY_%TM ", t ) ;
196
			output("\t\tCOPY_%TM ", t);
167
			output ( "( %UM_%CN ( x_ ), %CN ) ;\n" ) ;
197
			output("(%UM_%CN(x_), %CN);\n");
-
 
198
		    }
-
 
199
		}
-
 
200
		LOOP_FIELD_COMPONENT {
-
 
201
		    string v = DEREF_string(cmp_value(CRT_COMPONENT));
-
 
202
		    if (v) {
-
 
203
			TYPE_P t = DEREF_ptr(cmp_type(CRT_COMPONENT));
-
 
204
			output("\t\tCOPY_%TM ", t);
-
 
205
			output("(%UM_%FN_%CN(x_), %CN);\n");
-
 
206
		    }
-
 
207
		}
-
 
208
	    }
-
 
209
	}
-
 
210
	output("\t\tbreak;\n");
-
 
211
	output("\t    }\n");
-
 
212
    }
-
 
213
    output("\t}\n");
-
 
214
    output("    }\n");
-
 
215
    return;
-
 
216
}
-
 
217
 
-
 
218
 
-
 
219
/*
-
 
220
 * PRINT THE DISK READING DEFINITIONS
-
 
221
 *
-
 
222
 * This routine prints all the routines for reading the various types
-
 
223
 * from disk.
-
 
224
 */
-
 
225
 
-
 
226
static void
-
 
227
disk_read_def(char *dir)
-
 
228
{
-
 
229
    open_file(dir, READ_PREFIX, DEF_SUFFIX);
-
 
230
    print_include();
-
 
231
 
-
 
232
    comment("Disk reading function declarations");
-
 
233
    LOOP_TYPE {
-
 
234
	TYPE_P t = CRT_TYPE;
-
 
235
	TYPE t0 = DEREF_type(t);
-
 
236
	unsigned tag = TAG_type(t0);
-
 
237
	if (is_identity_type(t)) {
-
 
238
	    output("#ifndef READ_%TI\n", t);
-
 
239
	    output("#define READ_%TI() READ_%TJ()\n", t, t);
-
 
240
	    output("#endif\n\n");
-
 
241
	} else if (tag != type_primitive_tag) {
-
 
242
	    output("#ifndef READ_%TI\n", t);
-
 
243
	    output("static %TT READ_%TI(void);\n", t, t);
-
 
244
	    output("#endif\n\n");
-
 
245
	}
-
 
246
    }
-
 
247
    output("\n");
-
 
248
 
-
 
249
    /* Function definitions */
-
 
250
    LOOP_TYPE {
-
 
251
	TYPE_P t = CRT_TYPE;
-
 
252
	TYPE t0 = DEREF_type(t);
-
 
253
	unsigned tag = TAG_type(t0);
-
 
254
	if (!is_identity_type(t) && tag != type_primitive_tag) {
-
 
255
	    /* Function header */
-
 
256
	    output("/* Disk reading routine for %TT */\n\n", t);
-
 
257
	    output("#ifndef READ_%TI\n\n", t);
-
 
258
	    output("static %TT READ_%TI\n", t, t);
-
 
259
	    output("(void)\n");
-
 
260
	    output("{\n");
-
 
261
	    output("    %TT x_;\n", t);
-
 
262
 
-
 
263
	    /* Function body */
-
 
264
	    switch (tag) {
-
 
265
 
-
 
266
		case type_enumeration_tag: {
-
 
267
		    ENUM_P p = DEREF_ptr(type_enumeration_en(t0));
-
 
268
		    LOOP_ENUM {
-
 
269
			if (EQ_ptr(CRT_ENUM, p)) {
-
 
270
			    disk_read_enum();
-
 
271
			    break;
-
 
272
			}
168
		    }
273
		    }
-
 
274
		    break;
169
		}
275
		}
342
    }
395
    }
343
 
-
 
344
    close_file () ;
-
 
345
    return ;
396
    return;
346
}
397
}
347
 
398
 
348
 
399
 
349
/*
400
/*
350
    OUTPUT ENUMERATION WRITING ROUTINE
401
 * OUTPUT STRUCTURE 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
/*
402
 *
372
    OUTPUT STRUCTURE WRITING ROUTINE
-
 
373
 
-
 
374
    This routine outputs code for writing a structure type to disk.
403
 * This routine outputs code for writing a structure type to disk.
375
*/
404
 */
376
 
405
 
377
static void disk_write_struct
406
static void
378
    PROTO_Z ()
407
disk_write_struct(void)
379
{
408
{
380
    LOOP_STRUCTURE_COMPONENT {
409
    LOOP_STRUCTURE_COMPONENT {
381
	TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
410
	TYPE_P t = DEREF_ptr(cmp_type(CRT_COMPONENT));
382
	output ( "    WRITE_%TI ( x_.%CN ) ;\n", t ) ;
411
	output("    WRITE_%TI(x_.%CN);\n", t);
383
    }
412
    }
384
    return ;
413
    return;
385
}
414
}
386
 
415
 
387
 
416
 
388
/*
417
/*
389
    OUTPUT UNION WRITING ROUTINE
418
 * OUTPUT UNION WRITING ROUTINE
390
 
419
 *
391
    This routine outputs code for writing a union type to disk.
420
 * This routine outputs code for writing a union type to disk.
392
*/
421
 */
393
 
422
 
394
static void disk_write_union
423
static void
395
    PROTO_Z ()
424
disk_write_union(void)
396
{
425
{
397
    int have_ucmp = 0 ;
426
    int have_ucmp = 0;
398
    output ( "    if ( IS_NULL_%UM ( x_ ) ) {\n" ) ;
427
    output("    if (IS_NULL_%UM(x_)) {\n");
399
    output ( "\tWRITE_BITS ( 1, ( unsigned ) 0 ) ;\n" ) ;
428
    output("\tWRITE_BITS(1, (unsigned)0);\n");
400
    output ( "    } else {\n" ) ;
429
    output("    } else {\n");
401
    LOOP_UNION_COMPONENT {
430
    LOOP_UNION_COMPONENT {
402
	output ( "\t%CT %CN ;\n" ) ;
431
	output("\t%CT %CN;\n");
403
	have_ucmp = 1 ;
432
	have_ucmp = 1;
404
    }
433
    }
405
    output ( "\tunsigned tag_ = TAG_%UM ( x_ ) ;\n" ) ;
434
    output("\tunsigned tag_ = TAG_%UM(x_);\n");
406
    output ( "\tWRITE_BITS ( 1, ( unsigned ) 1 ) ;\n" ) ;
435
    output("\tWRITE_BITS(1, (unsigned)1);\n");
407
    output ( "\tWRITE_BITS ( %UO2, tag_ ) ;\n" ) ;
436
    output("\tWRITE_BITS(%UO2, tag_);\n");
408
    output ( "\tswitch ( tag_ ) {\n" ) ;
437
    output("\tswitch (tag_) {\n");
409
    LOOP_UNION_FIELD {
438
    LOOP_UNION_FIELD {
410
	int have_cmp = have_ucmp ;
439
	int have_cmp = have_ucmp;
411
	int al = DEREF_int ( fld_flag ( CRT_FIELD ) ) ;
440
	int al = DEREF_int(fld_flag(CRT_FIELD));
412
	output ( "\t    case %UM_%FN_tag : {\n" ) ;
441
	output("\t    case %UM_%FN_tag: {\n");
413
	LOOP_FIELD_COMPONENT {
442
	LOOP_FIELD_COMPONENT {
414
	    output ( "\t\t%CT %CN ;\n" ) ;
443
	    output("\t\t%CT %CN;\n");
415
	    have_cmp = 1 ;
444
	    have_cmp = 1;
416
	}
445
	}
417
 
446
 
418
	/* Deal with aliasing */
447
	/* Deal with aliasing */
419
	if ( al ) {
448
	if (al) {
420
	    output ( "\t\tunsigned alias_ = GET_ALIAS_%UM_%FN ( x_ ) ;\n" ) ;
449
	    output("\t\tunsigned alias_ = GET_ALIAS_%UM_%FN(x_);\n");
421
	    output ( "\t\tif ( alias_ ) {\n" ) ;
450
	    output("\t\tif (alias_) {\n");
422
	    output ( "\t\t    WRITE_ALIAS ( alias_ ) ;\n" ) ;
451
	    output("\t\t    WRITE_ALIAS(alias_);\n");
423
	    output ( "\t\t    WRITE_BITS ( 1, ( unsigned ) 0 ) ;\n" ) ;
452
	    output("\t\t    WRITE_BITS(1, (unsigned)0);\n");
424
	    output ( "\t\t    break ;\n" ) ;
453
	    output("\t\t    break;\n");
425
	    output ( "\t\t}\n" ) ;
454
	    output("\t\t}\n");
426
	    output ( "\t\talias_ = ++crt_%X_alias ;\n" ) ;
455
	    output("\t\talias_ = ++crt_%X_alias;\n");
427
	    output ( "\t\tSET_ALIAS_%UM_%FN ( x_, alias_ ) ;\n" ) ;
456
	    output("\t\tSET_ALIAS_%UM_%FN(x_, alias_);\n");
428
	    output ( "\t\tWRITE_ALIAS ( alias_ ) ;\n" ) ;
457
	    output("\t\tWRITE_ALIAS(alias_);\n");
429
	    output ( "\t\tWRITE_BITS ( 1, ( unsigned ) 1 ) ;\n" ) ;
458
	    output("\t\tWRITE_BITS(1, (unsigned)1);\n");
430
	}
459
	}
431
	
460
 
432
	/* Deconstruct union */
461
	/* Deconstruct union */
433
	if ( have_cmp ) {
462
	if (have_cmp) {
434
	    output ( "\t\tDECONS_%UM_%FN ( " ) ;
463
	    output("\t\tDECONS_%UM_%FN(");
435
	    LOOP_UNION_COMPONENT output ( "%CN, " ) ;
464
	    LOOP_UNION_COMPONENT output("%CN, ");
436
	    LOOP_FIELD_COMPONENT output ( "%CN, " ) ;
465
	    LOOP_FIELD_COMPONENT output("%CN, ");
437
	    output ( " x_ ) ;\n" ) ;
466
	    output(" x_);\n");
438
	}
467
	}
439
 
468
 
440
	/* Process further if necessary */
469
	/* Process further if necessary */
441
	if ( al == 2 ) {
470
	if (al == 2) {
442
	    output ( "\t\tALIAS_%UM_%FN ( " ) ;
471
	    output("\t\tALIAS_%UM_%FN(");
443
	    LOOP_UNION_COMPONENT output ( "%CN, " ) ;
472
	    LOOP_UNION_COMPONENT output("%CN, ");
444
	    LOOP_FIELD_COMPONENT output ( "%CN, " ) ;
473
	    LOOP_FIELD_COMPONENT output("%CN, ");
445
	    output ( " x_ ) ;\n" ) ;
474
	    output(" x_);\n");
446
	}
475
	}
447
 
476
 
448
	/* Write out components */
477
	/* Write out components */
449
	LOOP_UNION_COMPONENT {
478
	LOOP_UNION_COMPONENT {
450
	    TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
479
	    TYPE_P t = DEREF_ptr(cmp_type(CRT_COMPONENT));
451
	    output ( "\t\tWRITE_%TI ( %CN ) ;\n", t ) ;
480
	    output("\t\tWRITE_%TI(%CN);\n", t);
452
	}
481
	}
453
	LOOP_FIELD_COMPONENT {
482
	LOOP_FIELD_COMPONENT {
454
	    TYPE_P t = DEREF_ptr ( cmp_type ( CRT_COMPONENT ) ) ;
483
	    TYPE_P t = DEREF_ptr(cmp_type(CRT_COMPONENT));
455
	    output ( "\t\tWRITE_%TI ( %CN ) ;\n", t ) ;
484
	    output("\t\tWRITE_%TI(%CN);\n", t);
456
	}
485
	}
457
	output ( "\t\tbreak ;\n" ) ;
486
	output("\t\tbreak;\n");
458
	output ( "\t    }\n" ) ;
487
	output("\t    }\n");
459
    }
488
    }
460
    output ( "\t}\n" ) ;
489
    output("\t}\n");
461
    output ( "    }\n" ) ;
490
    output("    }\n");
462
    return ;
491
    return;
463
}
492
}
464
 
493
 
465
 
494
 
466
/*
495
/*
467
    PRINT THE DISK WRITING DEFINITIONS
496
 * PRINT THE DISK WRITING DEFINITIONS
-
 
497
 *
-
 
498
 * This routine outputs all the routines for writing the various types
-
 
499
 * to disk.
-
 
500
 */
-
 
501
 
-
 
502
static void
-
 
503
disk_write_def(char *dir)
-
 
504
{
-
 
505
    open_file(dir, WRITE_PREFIX, DEF_SUFFIX);
-
 
506
    print_include();
468
 
507
 
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" ) ;
508
    comment("Disk writing function declarations");
481
    LOOP_TYPE {
509
    LOOP_TYPE {
482
	TYPE_P t = CRT_TYPE ;
510
	TYPE_P t = CRT_TYPE;
483
	TYPE t0 = DEREF_type ( t ) ;
511
	TYPE t0 = DEREF_type(t);
484
	unsigned tag = TAG_type ( t0 ) ;
512
	unsigned tag = TAG_type(t0);
485
	if ( is_identity_type ( t ) ) {
513
	if (is_identity_type(t)) {
486
	    output ( "#ifndef WRITE_%TI\n", t ) ;
514
	    output("#ifndef WRITE_%TI\n", t);
487
	    output ( "#define WRITE_%TI( A ) WRITE_%TJ ( A )\n", t, t ) ;
515
	    output("#define WRITE_%TI(A) WRITE_%TJ(A)\n", t, t);
488
	    output ( "#endif\n\n" ) ;
516
	    output("#endif\n\n");
489
	} else if ( tag != type_primitive_tag ) {
517
	} else if (tag != type_primitive_tag) {
490
	    output ( "#ifndef WRITE_%TI\n", t ) ;
518
	    output("#ifndef WRITE_%TI\n", t);
491
	    output ( "static void WRITE_%TI PROTO_S ( ( %TT ) ) ;\n", t, t ) ;
519
	    output("static void WRITE_%TI(%TT);\n", t, t);
492
	    output ( "#endif\n\n" ) ;
520
	    output("#endif\n\n");
493
	}
521
	}
494
    }
522
    }
495
    output ( "\n" ) ;
523
    output("\n");
496
 
524
 
497
    /* Function definitions */
525
    /* Function definitions */
498
    LOOP_TYPE {
526
    LOOP_TYPE {
499
	TYPE_P t = CRT_TYPE ;
527
	TYPE_P t = CRT_TYPE;
500
	TYPE t0 = DEREF_type ( t ) ;
528
	TYPE t0 = DEREF_type(t);
501
	unsigned tag = TAG_type ( t0 ) ;
529
	unsigned tag = TAG_type(t0);
502
	if ( !is_identity_type ( t ) && tag != type_primitive_tag ) {
530
	if (!is_identity_type(t) && tag != type_primitive_tag) {
503
	    /* Function header */
531
	    /* Function header */
504
	    output ( "/* Disk writing routine for %TT */\n\n", t ) ;
532
	    output ("/* Disk writing routine for %TT */\n\n", t );
505
	    output ( "#ifndef WRITE_%TI\n\n", t ) ;
533
	    output("#ifndef WRITE_%TI\n\n", t);
506
	    output ( "static void WRITE_%TI\n", t ) ;
534
	    output("static void WRITE_%TI\n", t);
507
	    output ( "    PROTO_N ( ( x_ ) )\n" ) ;
535
	    output("\n");
508
	    output ( "    PROTO_T ( %TT x_ )\n", t ) ;
536
	    output("(%TT x_)\n", t);
509
	    output ( "{\n" ) ;
537
	    output("{\n");
510
 
538
 
511
	    /* Function body */
539
	    /* Function body */
512
	    switch ( tag ) {
540
	    switch (tag) {
513
 
541
 
514
		case type_enumeration_tag : {
542
		case type_enumeration_tag: {
515
		    ENUM_P p = DEREF_ptr ( type_enumeration_en ( t0 ) ) ;
543
		    ENUM_P p = DEREF_ptr(type_enumeration_en(t0));
516
		    LOOP_ENUM {
544
		    LOOP_ENUM {
517
			if ( EQ_ptr ( CRT_ENUM, p ) ) {
545
			if (EQ_ptr(CRT_ENUM, p)) {
518
			    disk_write_enum () ;
546
			    disk_write_enum();
-
 
547
			    break;
-
 
548
			}
-
 
549
		    }
-
 
550
		    break;
-
 
551
		}
-
 
552
 
-
 
553
		case type_structure_tag: {
-
 
554
		    STRUCTURE_P p = DEREF_ptr(type_structure_struc(t0));
-
 
555
		    LOOP_STRUCTURE {
-
 
556
			if (EQ_ptr(CRT_STRUCTURE, p)) {
-
 
557
			    disk_write_struct();
519
			    break ;
558
			    break;
520
			}
559
			}
521
		    }
560
		    }
522
		    break ;
561
		    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
		}
562
		}
535
 
563
 
536
		case type_onion_tag : {
564
		case type_onion_tag: {
537
		    UNION_P p = DEREF_ptr ( type_onion_un ( t0 ) ) ;
565
		    UNION_P p = DEREF_ptr(type_onion_un(t0));
538
		    LOOP_UNION {
566
		    LOOP_UNION {
539
			if ( EQ_ptr ( CRT_UNION, p ) ) {
567
			if (EQ_ptr(CRT_UNION, p)) {
540
			    disk_write_union () ;
568
			    disk_write_union();
541
			    break ;
569
			    break;
542
			}
570
			}
543
		    }
571
		    }
-
 
572
		    break;
-
 
573
		}
-
 
574
 
-
 
575
		case type_ptr_tag: {
-
 
576
		    TYPE_P s = DEREF_ptr(type_ptr_sub(t0));
-
 
577
		    output("    if (IS_NULL_ptr(x_)) {\n");
-
 
578
		    output("\tWRITE_BITS(1, (unsigned)0);\n");
-
 
579
		    output("    } else {\n");
-
 
580
		    output("\t%TT y_;\n\t", s);
-
 
581
		    print_deref(s, "x_", "y_");
-
 
582
		    output("\tWRITE_BITS(1, (unsigned)1);\n");
-
 
583
		    output("\tWRITE_%TI(y_);\n", s);
-
 
584
		    output("    }\n");
-
 
585
		    break;
-
 
586
		}
-
 
587
 
-
 
588
		case type_list_tag: {
-
 
589
		    TYPE_P s = DEREF_ptr(type_list_sub(t0));
-
 
590
		    output("    while (!IS_NULL_list(x_)) {\n");
-
 
591
		    output("\t%TT y_;\n\t", s);
-
 
592
		    print_deref(s, "HEAD_list(x_)", "y_");
-
 
593
		    output("\tWRITE_BITS(1, (unsigned)1);\n");
-
 
594
		    output("\tWRITE_%TI(y_);\n", s);
-
 
595
		    output("\tx_ = TAIL_list(x_);\n");
-
 
596
		    output("    }\n");
-
 
597
		    output("    WRITE_BITS(1, (unsigned)0);\n");
-
 
598
		    break;
-
 
599
		}
-
 
600
 
-
 
601
		case type_stack_tag: {
-
 
602
		    TYPE_P s = DEREF_ptr(type_stack_sub(t0));
-
 
603
		    output("    LIST(%TT) w_ = LIST_stack(x_);\n", s);
-
 
604
		    output("    while (!IS_NULL_list(w_)) {\n");
-
 
605
		    output("\t%TT y_;\n\t", s);
-
 
606
		    print_deref(s, "HEAD_list(w_)", "y_");
-
 
607
		    output("\tWRITE_BITS(1, (unsigned)1);\n");
-
 
608
		    output("\tWRITE_%TI(y_);\n", s);
-
 
609
		    output("\tw_ = TAIL_list(w_);\n");
-
 
610
		    output("    }\n");
-
 
611
		    output("    WRITE_BITS(1, (unsigned)0);\n");
-
 
612
		    break;
-
 
613
		}
-
 
614
 
-
 
615
		case type_vec_tag: {
-
 
616
		    TYPE_P s = DEREF_ptr(type_vec_sub(t0));
-
 
617
		    output("    %X_dim n_ = DIM_vec(x_);\n");
-
 
618
		    output("    PTR(%TT)y_ ", s);
-
 
619
		    output(" = PTR_vec_ptr(VEC_PTR_vec(x_));\n");
-
 
620
		    output("    WRITE_DIM((unsigned)n_);\n");
-
 
621
		    output("    while (n_--) {\n");
-
 
622
		    output("\t%TT z_;\n\t", s);
-
 
623
		    print_deref(s, "y_", "z_");
-
 
624
		    output("\tWRITE_%TI(z_);\n", s);
-
 
625
		    output("\ty_ = STEP_ptr(y_, %TS);\n", s);
-
 
626
		    output("    }\n");
-
 
627
		    break;
-
 
628
		}
-
 
629
 
-
 
630
		case type_vec_ptr_tag: {
-
 
631
		    TYPE_P s = DEREF_ptr(type_vec_ptr_sub(t0));
-
 
632
		    output("    PTR(%TT)y_ = PTR_vec_ptr(x_);\n", s);
-
 
633
		    output("    %TT z_;\n    ", s);
-
 
634
		    print_deref(s, "y_", "z_");
-
 
635
		    output("    WRITE_%TI(z_);\n", s);
544
		    break ;
636
		    break;
545
		}
637
		}
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
	    }
638
	    }
611
 
639
 
612
	    /* Function trailer */
640
	    /* Function trailer */
613
	    output ( "    return ;\n" ) ;
641
	    output("    return;\n");
614
	    output ( "}\n\n" ) ;
642
	    output("}\n\n");
615
	    output ( "#endif\n\n\n" ) ;
643
	    output("#endif\n\n\n");
616
	}
644
	}
617
    }
645
    }
618
    close_file () ;
646
    close_file();
619
    return ;
647
    return;
620
}
648
}
621
 
649
 
622
 
650
 
623
/*
651
/*
624
    MAIN DISK ACTION
652
 * MAIN DISK ACTION
625
 
653
 *
626
    This routine prints all the output files for reading and writing the
654
 * This routine prints all the output files for reading and writing the
627
    calculus to disk.
655
 * calculus to disk.
628
*/
656
 */
629
 
657
 
630
void disk_action
658
void
631
    PROTO_N ( ( dir ) )
-
 
632
    PROTO_T ( char *dir )
659
disk_action(char *dir)
633
{
660
{
634
    disk_read_def ( dir ) ;
661
    disk_read_def(dir);
635
    disk_write_def ( dir ) ;
662
    disk_write_def(dir);
636
    return ;
663
    return;
637
}
664
}