Subversion Repositories tendra.SVN

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
2
    		 Crown Copyright (c) 1996
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
			    VERSION INFORMATION
31
			    ===================
32
 
33
--------------------------------------------------------------------------
34
$Header: /u/g/release/CVSROOT/Source/src/installers/680x0/common/xdb_types.c,v 1.1.1.1 1998/01/17 15:55:49 release Exp $
35
--------------------------------------------------------------------------
36
$Log: xdb_types.c,v $
37
 * Revision 1.1.1.1  1998/01/17  15:55:49  release
38
 * First version to be checked into rolling release.
39
 *
40
Revision 1.1.1.1  1997/10/13 12:43:02  ma
41
First version.
42
 
43
Revision 1.1.1.1  1997/03/14 07:50:23  ma
44
Imported from DRA
45
 
46
 * Revision 1.1.1.1  1996/09/20  10:57:02  john
47
 *
48
 * Revision 1.2  1996/07/05  14:36:42  john
49
 * Fix to diagnostics
50
 *
51
 * Revision 1.1  95/03/08  16:46:33  ra
52
 * Added missing files.
53
 *
54
 * Revision 1.4  94/02/21  16:09:42  16:09:42  ra (Robert Andrews)
55
 * Put in a number of explicit casts.
56
 *
57
 * Revision 1.3  93/11/19  16:25:34  16:25:34  ra (Robert Andrews)
58
 * Bitfields should have the correct size, not 32.
59
 *
60
 * Revision 1.2  93/04/19  13:40:05  13:40:05  ra (Robert Andrews)
61
 * struct_fields and union_fields have been renamed diag_field.
62
 *
63
 * Revision 1.1  93/02/22  17:17:29  17:17:29  ra (Robert Andrews)
64
 * Initial revision
65
 *
66
--------------------------------------------------------------------------
67
*/
68
 
69
 
70
#include "config.h"
71
#include <time.h>
72
#include "common_types.h"
73
#include "expmacs.h"
74
#include "externs.h"
75
#include "instrs.h"
76
#include "mach.h"
77
#include "mach_ins.h"
78
#include "mach_op.h"
79
#include "output.h"
80
#include "shapemacs.h"
81
#include "utility.h"
82
#include "xdb_output.h"
83
#include "xdb_types.h"
84
#ifndef SEEK_SET
85
#define SEEK_SET 0
86
#endif
87
 
88
 
89
/*
90
    GENERATE A UNIQUE IDENTIFIER
91
*/
92
 
93
static unsigned unique_id
94
    PROTO_Z ()
95
{
96
    static unsigned u = 0 ;
97
    if ( u == 0 ) {
98
	time_t t = time ( ( time_t * ) NULL ) ;
99
	u = ( unsigned ) t ;
100
    }
101
    return ( u ) ;
102
}
103
 
104
 
105
/*
106
    CURRENT POSITIONS IN DIAGNOSTIC NAME TABLES
107
*/
108
 
109
static posn_t dtposn_local = LOCAL_POSN ;
110
static posn_t dtposn_globl = GLOBL_POSN ;
111
 
112
 
113
/*
114
    OUTPUT A DIAGNOSTIC DIRECTIVE
115
*/
116
 
117
posn_t out_dd
118
    PROTO_N ( ( file, n, loc ) )
119
    PROTO_T ( FILE *file X int n X int loc )
120
{
121
    diag_directive *d = dd + n ;
122
    long sz = ( diag_format == DIAG_XDB_NEW ? d->new_size : d->old_size ) ;
123
    posn_t p = ( loc ? dtposn_local : dtposn_globl ) ;
124
    fprintf ( file, "%s", instr_names [ d->instr ] ) ;
125
    if ( loc ) {
126
	dtposn_local = p + sz ;
127
    } else {
128
	dtposn_globl = p + sz ;
129
    }
130
    return ( p ) ;
131
}
132
 
133
 
134
/*
135
     CREATE A NEW TABLE POSITION
136
*/
137
 
138
static table_posn *new_table_posn
139
    PROTO_N ( ( n, sz ) )
140
    PROTO_T ( posn_t n X long sz )
141
{
142
    table_posn *p ;
143
    static int no_tp_free = 0 ;
144
    static table_posn *tp_free ;
145
    if ( no_tp_free == 0 ) {
146
	no_tp_free = 20 ;
147
	tp_free = alloc_nof ( table_posn, no_tp_free ) ;
148
    }
149
    p = tp_free++ ;
150
    no_tp_free-- ;
151
    p->is_lab = 0 ;
152
    p->posn = n ;
153
    p->size = sz ;
154
    return ( p ) ;
155
}
156
 
157
 
158
/*
159
    OUTPUT A TABLE POSITION
160
*/
161
 
162
void out_posn
163
    PROTO_N ( ( file, p, comma ) )
164
    PROTO_T ( FILE *file X table_posn *p X int comma )
165
{
166
    if ( p->is_lab ) {
167
	fprintf ( file, "LD%d", ( int ) p->posn ) ;
168
    } else {
169
	fprintf ( file, "0x%x", ( unsigned int ) p->posn ) ;
170
    }
171
    fputc ( ( comma ? ',' : '\n' ), file ) ;
172
    return ;
173
}
174
 
175
 
176
/*
177
    GO TO A POSITION IN A FILE AND PRINT A TABLE POSITION
178
*/
179
 
180
void fill_gap
181
    PROTO_N ( ( file, fp, t ) )
182
    PROTO_T ( FILE *file X long fp X posn_t t )
183
{
184
    long fp_old = ftell ( file ) ;
185
    if ( fseek ( file, fp, SEEK_SET ) == -1 ) {
186
	error ( "Internal file seek error" ) ;
187
	return ;
188
    }
189
    fprintf ( file, "0x%x", ( unsigned int ) t ) ;
190
    if ( fseek ( file, fp_old, SEEK_SET ) == -1 ) {
191
	error ( "Internal file seek error" ) ;
192
    }
193
    return ;
194
}
195
 
196
 
197
/*
198
    CURRENT DIAGNOSTICS LABEL NUMBER
199
*/
200
 
201
static long diag_lab = 0 ;
202
 
203
 
204
/*
205
    FIND THE TABLE POSITION OF A TDF SHAPE
206
*/
207
 
208
static table_posn *analyse_diag_shape
209
    PROTO_N ( ( file, sha ) )
210
    PROTO_T ( FILE *file X shape sha )
211
{
212
    posn_t t = NULL_POSN ;
213
    long sz = shape_size ( sha ) ;
214
    switch ( name ( sha ) ) {
215
	case scharhd : t = CHAR_POSN + sz ; break ;
216
	case swordhd :
217
	case slonghd : t = SIGNED_POSN + sz ; break ;
218
	case ucharhd :
219
	case uwordhd :
220
	case ulonghd : t = UNSIGNED_POSN + sz ; break ;
221
	case shrealhd :
222
	case realhd :
223
	case doublehd : t = FLOATING_POSN + sz ; break ;
224
    }
225
    return ( new_table_posn ( t, sz ) ) ;
226
}
227
 
228
 
229
/*
230
    FIND THE TABLE POSITION OF A DIAGNOSTIC TYPE
231
*/
232
 
233
table_posn *analyse_diag_type
234
    PROTO_N ( ( file, dt, loc ) )
235
    PROTO_T ( FILE *file X diag_type dt X int loc )
236
{
237
    table_posn *res ;
238
    if ( dt->been_outed ) return ( ( table_posn * ) dt->been_outed ) ;
239
 
240
    switch ( dt->key ) {
241
 
242
	case DIAG_TYPE_ARRAY : {
243
	    diag_type dtl = dt->data.array.element_type ;
244
	    long lo = no ( dt->data.array.lower_b ) ;
245
	    long hi = no ( dt->data.array.upper_b ) ;
246
 
247
	    table_posn *p = analyse_diag_type ( file, dtl, loc ) ;
248
	    long sz = ( hi - lo + 1 ) * ( p->size ) ;
249
	    posn_t s, t = out_dd ( file, xdb_subrange, loc ) ;
250
 
251
	    if ( diag_format == DIAG_XDB_NEW ) fprintf ( file, "0,0," ) ;
252
	    fprintf ( file, "%ld,%ld,0x%x,32\n", lo, hi,
253
		      ( unsigned int ) ( SIGNED_POSN + 32 ) ) ;
254
	    s = out_dd ( file, xdb_array, loc ) ;
255
	    if ( diag_format == DIAG_XDB_NEW ) {
256
		fprintf ( file, "0,0,0,0,0,0," ) ;
257
	    }
258
	    fprintf ( file, "0,%ld,0x%x,", sz, ( unsigned int ) t ) ;
259
	    if ( diag_format == DIAG_XDB_NEW ) {
260
		out_posn ( file, p, 1 ) ;
261
		fprintf ( file, "%ld\n", p->size ) ;
262
	    } else {
263
		out_posn ( file, p, 0 ) ;
264
	    }
265
	    res = new_table_posn ( s, sz ) ;
266
	    break ;
267
	}
268
 
269
	case DIAG_TYPE_BITFIELD : {
270
	    long sz = dt->data.bitfield.no_of_bits.nat_val.small_nat ;
271
	    res = new_table_posn ( SIGNED_POSN + 32, sz ) ;
272
	    break ;
273
	}
274
 
275
	case DIAG_TYPE_ENUM : {
276
	    char *nm = dt->data.t_enum.nme.ints.chars ;
277
	    enum_values *fld = dt->data.t_enum.values->array ;
278
	    long i, n = ( long ) dt->data.t_enum.values->lastused ;
279
 
280
	    /* Initialize enumeration information */
281
	    long fp ;
282
	    posn_t t ;
283
	    t = out_dd ( file, xdb_enum, loc ) ;
284
	    fp = ftell ( file ) ;
285
	    fprintf ( file, "%s,32\n", NULL_POSN_STR ) ;
286
	    res = new_table_posn ( t, L32 ) ;
287
 
288
	    /* Deal with enumeration members */
289
	    for ( i = n - 1 ; i >= 0 ; i-- ) {
290
		char *fnm = fld [i]->nme.ints.chars ;
291
		long v = no ( fld [i]->val ) ;
292
		posn_t s = out_dd ( file, xdb_memenum, loc ) ;
293
		fill_gap ( file, fp, s ) ;
294
		if ( diag_format == DIAG_XDB_NEW ) fprintf ( file, "0," ) ;
295
		if ( *fnm ) {
296
		    diag_string ( file, fnm ) ;
297
		} else {
298
		    diag_string ( file, "__unknown" ) ;
299
		}
300
		fprintf ( file, ",%ld,", v ) ;
301
		fp = ftell ( file ) ;
302
		fprintf ( file, "%s\n", NULL_POSN_STR ) ;
303
	    }
304
 
305
	    /* Round off enumeration definition */
306
	    if ( *nm ) {
307
		( void ) out_dd ( file, xdb_tagdef, loc ) ;
308
		fprintf ( file, "0," ) ;
309
		if ( diag_format == DIAG_XDB_NEW ) fprintf ( file, "1," ) ;
310
		diag_string ( file, nm ) ;
311
		fprintf ( file, "," ) ;
312
		out_posn ( file, res, 0 ) ;
313
	    }
314
	    break ;
315
	}
316
 
317
	case DIAG_TYPE_FLOAT : {
318
	    shape sha = f_floating ( dt->data.f_var ) ;
319
	    res = analyse_diag_shape ( file, sha ) ;
320
	    break ;
321
	}
322
 
323
	case DIAG_TYPE_LOC : {
324
	    diag_type dtl = dt->data.loc.object ;
325
	    res = analyse_diag_type ( file, dtl, loc ) ;
326
	    break ;
327
	}
328
 
329
	case DIAG_TYPE_NULL : {
330
	    res = new_table_posn ( NULL_POSN, L0 ) ;
331
	    break ;
332
	}
333
 
334
	case DIAG_TYPE_PROC : {
335
	    diag_type dtl = dt->data.proc.result_type ;
336
	    table_posn *p = analyse_diag_type ( file, dtl, loc ) ;
337
	    posn_t t = out_dd ( file, xdb_functype, loc ) ;
338
	    if ( diag_format == DIAG_XDB_NEW ) fprintf ( file, "0,0," ) ;
339
	    fprintf ( file, "32," ) ;
340
	    out_posn ( file, p, 1 ) ;
341
	    fprintf ( file, "%s\n", NULL_POSN_STR ) ;
342
	    res = new_table_posn ( t, L32 ) ;
343
	    break ;
344
	}
345
 
346
	case DIAG_TYPE_PTR : {
347
	    diag_type dtl = dt->data.ptr.object ;
348
	    table_posn *p = analyse_diag_type ( file, dtl, loc ) ;
349
	    posn_t t = out_dd ( file, xdb_pointer, loc ) ;
350
	    out_posn ( file, p, 1 ) ;
351
	    fprintf ( file, "32\n" ) ;
352
	    res = new_table_posn ( t, L32 ) ;
353
	    break ;
354
	}
355
 
356
	case DIAG_TYPE_STRUCT : {
357
	    shape sha = dt->data.t_struct.tdf_shape ;
358
	    long sz = shape_size ( sha ) ;
359
	    char *nm = dt->data.t_struct.nme.ints.chars ;
360
#if 0
361
	    struct_fields *fld = dt->data.t_struct.fields->array ;
362
#else
363
	    diag_field *fld = dt->data.t_struct.fields->array ;
364
#endif
365
	    long i, n = ( long ) dt->data.t_struct.fields->lastused ;
366
 
367
	    /* Initialize structure information */
368
	    long fp ;
369
	    posn_t t ;
370
	    int taglab = 0 ;
371
	    char nmbuff [50] ;
372
	    long dlab = diag_lab++ ;
373
	    if ( diag_format == DIAG_XDB_NEW ) {
374
		if ( *nm == 0 ) {
375
		    unsigned u = unique_id () ;
376
		    nm = nmbuff ;
377
		    sprintf ( nm, "(%u.%ld)", u, dlab ) ;
378
		}
379
		taglab = 1 ;
380
	    }
381
	    if ( !taglab ) fprintf ( file, "LD%ld:", dlab ) ;
382
	    t = out_dd ( file, xdb_struct, loc ) ;
383
	    fprintf ( file, "0," ) ;
384
	    fp = ftell ( file ) ;
385
	    fprintf ( file, "%s,%s,%s,%ld\n", NULL_POSN_STR, NULL_POSN_STR,
386
		      NULL_POSN_STR, sz ) ;
387
	    res = new_table_posn ( t, sz ) ;
388
 
389
	    /* Print tag information */
390
	    if ( *nm ) {
391
		posn_t tt ;
392
		if ( taglab ) fprintf ( file, "LD%ld:", dlab ) ;
393
		tt = out_dd ( file, xdb_tagdef, loc ) ;
394
		fprintf ( file, "0," ) ;
395
		if ( diag_format == DIAG_XDB_NEW ) fprintf ( file, "1," ) ;
396
		diag_string ( file, nm ) ;
397
		fprintf ( file, "," ) ;
398
		out_posn ( file, res, 0 ) ;
399
		if ( taglab ) t = tt ;
400
	    }
401
 
402
	    /* Set up structure label */
403
	    res->is_lab = 1 ;
404
	    res->posn = ( posn_t ) dlab ;
405
	    dt->been_outed = ( OUTPUT_REC ) res ;
406
 
407
	    /* Deal with structure fields */
408
	    for ( i = n - 1 ; i >= 0 ; i-- ) {
409
		char *fnm = fld [i]->field_name.ints.chars ;
410
		long off = no ( fld [i]->where ) ;
411
		diag_type dtl = fld [i]->field_type ;
412
		table_posn *q = analyse_diag_type ( file, dtl, loc ) ;
413
		posn_t s = out_dd ( file, xdb_field, loc ) ;
414
		fill_gap ( file, fp, s ) ;
415
		if ( diag_format == DIAG_XDB_NEW ) fprintf ( file, "0,0," ) ;
416
		if ( *fnm ) {
417
		    diag_string ( file, fnm ) ;
418
		} else {
419
		    diag_string ( file, "__unknown" ) ;
420
		}
421
		fprintf ( file, ",%ld,", off ) ;
422
		out_posn ( file, q, 1 ) ;
423
		fprintf ( file, "%ld,", q->size ) ;
424
		fp = ftell ( file ) ;
425
		fprintf ( file, "%s\n", NULL_POSN_STR ) ;
426
	    }
427
 
428
	    /* Round off structure definition */
429
	    res->is_lab = 0 ;
430
	    res->posn = t ;
431
	    break ;
432
	}
433
 
434
	case DIAG_TYPE_UNION : {
435
	    shape sha = dt->data.t_union.tdf_shape ;
436
	    long sz = shape_size ( sha ) ;
437
	    char *nm = dt->data.t_union.nme.ints.chars ;
438
#if 0
439
	    union_fields *fld = dt->data.t_union.fields->array ;
440
#else
441
	    diag_field *fld = dt->data.t_union.fields->array ;
442
#endif
443
	    long i, n = ( long ) dt->data.t_union.fields->lastused ;
444
 
445
	    /* Initialize union information */
446
	    long fp ;
447
	    posn_t t ;
448
	    int taglab = 0 ;
449
	    long dlab = diag_lab++ ;
450
	    char nmbuff [50] ;
451
	    if ( diag_format == DIAG_XDB_NEW ) {
452
		if ( *nm == 0 ) {
453
		    unsigned u = unique_id () ;
454
		    nm = nmbuff ;
455
		    sprintf ( nm, "(%u.%ld)", u, dlab ) ;
456
		}
457
		taglab = 1 ;
458
	    }
459
	    if ( !taglab ) fprintf ( file, "LD%ld:", dlab ) ;
460
	    t = out_dd ( file, xdb_union, loc ) ;
461
	    fp = ftell ( file ) ;
462
	    fprintf ( file, "%s,%ld\n", NULL_POSN_STR, sz ) ;
463
	    res = new_table_posn ( t, sz ) ;
464
 
465
	    /* Print tag information */
466
	    if ( *nm ) {
467
		posn_t tt ;
468
		if ( taglab ) fprintf ( file, "LD%ld:", dlab ) ;
469
		tt = out_dd ( file, xdb_tagdef, loc ) ;
470
		fprintf ( file, "0," ) ;
471
		if ( diag_format == DIAG_XDB_NEW ) fprintf ( file, "1," ) ;
472
		diag_string ( file, nm ) ;
473
		fprintf ( file, "," ) ;
474
		out_posn ( file, res, 0 ) ;
475
		if ( taglab ) t = tt ;
476
	    }
477
 
478
	    /* Set up union label */
479
	    res->is_lab = 1 ;
480
	    res->posn = ( posn_t ) dlab ;
481
	    dt->been_outed = ( OUTPUT_REC ) res ;
482
 
483
	    /* Deal with union fields */
484
	    for ( i = n - 1 ; i >= 0 ; i-- ) {
485
		char *fnm = fld [i]->field_name.ints.chars ;
486
		long off = no ( fld [i]->where ) ;
487
		diag_type dtl = fld [i]->field_type ;
488
		table_posn *q = analyse_diag_type ( file, dtl, loc ) ;
489
		posn_t s = out_dd ( file, xdb_field, loc ) ;
490
		fill_gap ( file, fp, s ) ;
491
		if ( diag_format == DIAG_XDB_NEW ) fprintf ( file, "0,0," ) ;
492
		if ( *fnm ) {
493
		    diag_string ( file, fnm ) ;
494
		} else {
495
		    diag_string ( file, "__unknown" ) ;
496
		}
497
		fprintf ( file, ",%ld,", off ) ;
498
		out_posn ( file, q, 1 ) ;
499
		fprintf ( file, "%ld,", q->size ) ;
500
		fp = ftell ( file ) ;
501
		fprintf ( file, "%s\n", NULL_POSN_STR ) ;
502
	    }
503
 
504
	    /* Round off union definition */
505
	    res->is_lab = 0 ;
506
	    res->posn = t ;
507
	    break ;
508
	}
509
 
510
	case DIAG_TYPE_VARIETY : {
511
	    shape sha = f_integer ( dt->data.var ) ;
512
	    res = analyse_diag_shape ( file, sha ) ;
513
	    break ;
514
	}
515
 
516
	default : {
517
	    res = new_table_posn ( NULL_POSN, L0 ) ;
518
	    break ;
519
	}
520
    }
521
 
522
    dt->been_outed = ( OUTPUT_REC ) res ;
523
    return ( res ) ;
524
}
525
 
526
 
527
/*
528
    DIAGNOSTIC SCOPE STACK
529
*/
530
 
531
static dscope *dscope_stack = null ;
532
static int no_dscope = 0 ;
533
static int dscope_stk_size = 0 ;
534
 
535
 
536
/*
537
    PUSH A DIAGNOSTICS SCOPE
538
*/
539
 
540
void push_dscope
541
    PROTO_N ( ( p, t ) )
542
    PROTO_T ( posn_t p X int t )
543
{
544
    int n = no_dscope++ ;
545
    if ( n >= dscope_stk_size ) {
546
	dscope_stk_size += 20 ;
547
	dscope_stack = realloc_nof ( dscope_stack, dscope, dscope_stk_size ) ;
548
    }
549
    dscope_stack [n].posn = p ;
550
    dscope_stack [n].dscope_type = t ;
551
    return ;
552
}
553
 
554
 
555
/*
556
    POP A DIAGNOSTICS SCOPE
557
*/
558
 
559
dscope *pop_dscope
560
    PROTO_Z ()
561
{
562
    int n = no_dscope ;
563
    if ( n == 0 ) return ( null ) ;
564
    no_dscope = ( --n ) ;
565
    return ( dscope_stack + n ) ;
566
}