Subversion Repositories tendra.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

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