Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | 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_output.c,v 1.1.1.1 1998/01/17 15:55:50 release Exp $
35
--------------------------------------------------------------------------
36
$Log: xdb_output.c,v $
37
 * Revision 1.1.1.1  1998/01/17  15:55:50  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:01  john
47
 *
48
 * Revision 1.2  1996/07/05  14:35:40  john
49
 * Fix to diagnostics
50
 *
51
 * Revision 1.1  95/03/08  16:46:25  ra
52
 * Added missing files.
53
 *
54
 * Revision 1.3  94/02/21  16:09:13  16:09:13  ra (Robert Andrews)
55
 * Put in a number of explicit casts.
56
 *
57
 * Revision 1.2  93/04/19  13:39:31  13:39:31  ra (Robert Andrews)
58
 * crt_fname and crt_line_num are no longer static.
59
 *
60
 * Revision 1.1  93/02/22  17:17:25  17:17:25  ra (Robert Andrews)
61
 * Initial revision
62
 *
63
--------------------------------------------------------------------------
64
*/
65
 
66
 
67
#include "config.h"
68
#include "common_types.h"
69
#include "assembler.h"
70
#include "codex.h"
71
#include "exp.h"
72
#include "expmacs.h"
73
#include "instrs.h"
74
#include "mach.h"
75
#include "mach_ins.h"
76
#include "mach_op.h"
77
#include "output.h"
78
#include "tags.h"
79
#include "utility.h"
80
#include "xdb_types.h"
81
#include "xdb_output.h"
82
#include "stab_types.h"
83
extern int diag_override ;
84
 
85
 
86
/*
87
    WORK OUT WHETHER TO DO A DYNAMIC TEST FOR DIAGNOSTIC FORMAT
88
*/
89
 
90
#if ( default_diag == DIAG_UNKNOWN )
91
#define dynamic_test
92
extern double atof PROTO_S ( ( CONST char * ) ) ;
93
#include <sys/utsname.h>
94
#else
95
#undef dynamic_test
96
#endif
97
 
98
 
99
/*
100
    WHICH DIAGNOSTIC FORMAT SHOULD BE USED?
101
*/
102
 
103
bool diag_format = default_diag ;
104
 
105
 
106
/*
107
    ARRAY OF DIAGNOSTIC DIRECTIVES
108
 
109
    This array gives information on all the available diagnostic directives,
110
    included those which are unused.
111
*/
112
 
113
diag_directive dd [] = {
114
    { m_dd_array, 2, 2 },
115
    { m_dd_begin, 1, 1 },
116
    { m_dd_const, 0, 0 },	/* unknown */
117
    { m_dd_dvar, 2, 2 },
118
    { m_dd_end, 1, 1 },
119
    { m_dd_entry, 0, 0 },	/* unknown */
120
    { m_dd_enum, 1, 1 },
121
    { m_dd_field, 2, 2 },
122
    { m_dd_file, 0, 0 },	/* unknown */
123
    { m_dd_fparam, 2, 2 },
124
    { m_dd_function, 3, 3 },
125
    { m_dd_functype, 2, 2 },
126
    { m_dd_import, 0, 0 },	/* unknown */
127
    { m_dd_label, 0, 0 },	/* unknown */
128
    { m_dd_memenum, 2, 2 },
129
    { m_dd_module, 1, 2 },
130
    { m_dd_pointer, 1, 1 },
131
    { m_dd_set, 0, 0 },		/* unknown */
132
    { m_dd_srcfile, 1, 1 },
133
    { m_dd_struct, 2, 2 },
134
    { m_dd_subrange, 2, 2 },
135
    { m_dd_svar, 2, 2 },
136
    { m_dd_tagdef, 1, 1 },
137
    { m_dd_typedef, 1, 1 },
138
    { m_dd_union, 1, 1 },
139
    { m_dd_variant, 0, 0 }	/* unknown */
140
} ;
141
 
142
 
143
/*
144
    DIAGNOSTICS FILES
145
 
146
    There are three sections of diagnostic information in the new
147
    diagnostics mode (the vt, lntt and gntt sections).  One temporary
148
    file is used for each.  In the old diagnosics mode there is
149
    only one section (the dntt section), and only one file, diagfp2,
150
    is used.
151
*/
152
 
153
static FILE *diagfp1 ;
154
static FILE *diagfp2 ;
155
static FILE *diagfp3 ;
156
 
157
 
158
/*
159
    INITIALIZE DIAGNOSTICS FILES
160
 
161
    The temporary files are opened, and the headings of the various
162
    sections are printed.
163
*/
164
 
165
void init_diag
166
    PROTO_Z ()
167
{
168
    double vs = ( diag_format == DIAG_XDB_NEW ? 7.40 : 7.05 ) ;
169
 
170
#ifdef dynamic_test
171
    struct utsname u ;
172
    char *os = "HP-UX" ;
173
    uname ( &u ) ;
174
    os = u.sysname ;
175
    vs = atof ( u.release ) ;
176
    if ( strcmp ( os, "HP-UX" ) == 0 ) {
177
	diag_format = ( vs >= 7.40 ? DIAG_XDB_NEW : DIAG_XDB_OLD ) ;
178
    } else {
179
	diag_format = DIAG_UNKNOWN ;
180
   }
181
#endif
182
 
183
    if ( diag_override != DIAG_UNKNOWN ) {
184
	diag_format = diag_override ;
185
	vs = ( diag_format == DIAG_XDB_NEW ? 7.40 : 7.05 ) ;
186
    }
187
    switch ( diag_format ) {
188
 
189
	case DIAG_STAB : {
190
	    /* Temporary files not used */
191
	    break ;
192
	}
193
 
194
	case DIAG_UNKNOWN : {
195
	    warning ( "Unknown diagnostics format" ) ;
196
	    diag_format = DIAG_XDB_NEW ;
197
	    /* Fall through */
198
	}
199
 
200
	case DIAG_XDB_NEW : {
201
	    diagfp1 = tmpfile () ;
202
	    diagfp2 = tmpfile () ;
203
	    diagfp3 = tmpfile () ;
204
	    if ( diagfp1 == null || diagfp2 == null || diagfp3 == null ) {
205
		error ( "Can't open temporary diagnostics file" ) ;
206
		exit ( EXIT_FAILURE ) ;
207
	    }
208
	    fprintf ( diagfp1, "%s\n", instr_names [ m_as_data ] ) ;
209
	    fprintf ( diagfp1, "%s\n", instr_names [ m_dd_vt ] ) ;
210
	    fprintf ( diagfp2, "%s\n", instr_names [ m_dd_lntt ] ) ;
211
	    fprintf ( diagfp3, "%s\n", instr_names [ m_dd_gntt ] ) ;
212
	    break ;
213
	}
214
 
215
	case DIAG_XDB_OLD : {
216
	    diagfp2 = tmpfile () ;
217
	    if ( diagfp2 == null ) {
218
		error ( "Can't open temporary diagnostics file" ) ;
219
		exit ( EXIT_FAILURE ) ;
220
	    }
221
	    fprintf ( diagfp2, "%s\n", instr_names [ m_as_data ] ) ;
222
	    fprintf ( diagfp2, "%s\n", instr_names [ m_dd_start ] ) ;
223
	    break ;
224
	}
225
    }
226
    return ;
227
}
228
 
229
 
230
/*
231
    COPY A FILE
232
 
233
    The the file is copied to the main output file, fpout.
234
*/
235
 
236
static void copy_diag_file
237
    PROTO_N ( ( file ) )
238
    PROTO_T ( FILE *file )
239
{
240
    int c ;
241
    rewind ( file ) ;
242
    while ( c = getc ( file ), c != EOF ) putc ( c, fpout ) ;
243
    fclose ( file ) ;
244
    return ;
245
}
246
 
247
 
248
/*
249
    VT AREA NEWLINE FLAG
250
 
251
    This flag is true if a newline has just been output in the vt area.
252
*/
253
 
254
static int vt_newline = 1 ;
255
 
256
 
257
/*
258
    COPY DIAGNOSTICS FILES
259
 
260
    All the diagnostic files are copied to the main output file.
261
*/
262
 
263
void copy_diag
264
    PROTO_Z ()
265
{
266
    if ( diag_format == DIAG_XDB_NEW ) {
267
	if ( vt_newline ) {
268
	    fprintf ( diagfp1, "%s0\n", instr_names [ m_dd_vtbytes ] ) ;
269
	} else {
270
	    fprintf ( diagfp1, ",0\n" ) ;
271
	}
272
	copy_diag_file ( diagfp1 ) ;
273
	copy_diag_file ( diagfp2 ) ;
274
	copy_diag_file ( diagfp3 ) ;
275
    } else if ( diag_format == DIAG_XDB_OLD ) {
276
	copy_diag_file ( diagfp2 ) ;
277
    }
278
    return ;
279
}
280
 
281
 
282
/*
283
    OUTPUT A DIAGNOSTICS STRING
284
 
285
    Diagnostic strings (eg. procedure and variable names) are dealt with
286
    differently in the two formats.  In the old format they are output
287
    direct, in the new they are added to the vt table and the offset
288
    from the start of the table is used.
289
*/
290
 
291
void diag_string
292
    PROTO_N ( ( file, s ) )
293
    PROTO_T ( FILE *file X char *s )
294
{
295
    if ( diag_format == DIAG_XDB_NEW ) {
296
	static int vtposn = 0 ;
297
	static int vtwidth = 0 ;
298
	if ( vt_newline ) {
299
	    fprintf ( diagfp1, "%s0", instr_names [ m_dd_vtbytes ] ) ;
300
	    vt_newline = 0 ;
301
	} else {
302
	    fprintf ( diagfp1, ",0" ) ;
303
	}
304
	vtposn++ ;
305
	vtwidth++ ;
306
	fprintf ( file, "%d", vtposn ) ;
307
	for ( ; *s ; s++ ) {
308
	    if ( vt_newline ) {
309
		fprintf ( diagfp1, "%s%d", instr_names [ m_dd_vtbytes ], *s ) ;
310
		vt_newline = 0 ;
311
	    } else {
312
		fprintf ( diagfp1, ",%d", *s ) ;
313
	    }
314
	    vtposn++ ;
315
	    vtwidth++ ;
316
	    if ( vtwidth > 12 ) {
317
		fprintf ( diagfp1, "\n" ) ;
318
		vt_newline = 1 ;
319
		vtwidth = 0 ;
320
	    }
321
	}
322
    } else {
323
	fprintf ( file, "\"%s\"", s ) ;
324
    }
325
    return ;
326
}
327
 
328
 
329
/*
330
    CURRENT FILE INDEX AND LINE NUMBER
331
 
332
    These variables record the current position in the source file.
333
*/
334
 
335
char *crt_fname = "" ;
336
long crt_line_num = -1 ;
337
 
338
 
339
/*
340
    NUMBER OF SLT INSTRUCTIONS
341
 
342
    A count of the number of slt instructions is maintained.
343
*/
344
 
345
static int slt_num = 0 ;
346
 
347
 
348
/*
349
    PRINT AN SLT SPECIAL INSTRUCTION
350
 
351
    An sltspecial instruction is output.  This goes straight into the
352
    main output file.
353
*/
354
 
355
static void slt_special
356
    PROTO_N ( ( t, p ) )
357
    PROTO_T ( int t X posn_t p )
358
{
359
    mach_op *op1, *op2, *op3 ;
360
    area ( ptext ) ;
361
    op1 = make_int_data ( t ) ;
362
    op2 = make_int_data ( crt_line_num ) ;
363
    op3 = make_hex_data ( p ) ;
364
    op1->of = op2 ;
365
    op2->of = op3 ;
366
    make_instr ( m_dd_special, op1, null, 0 ) ;
367
    area ( plast ) ;
368
    slt_num++ ;
369
    return ;
370
}
371
 
372
 
373
/*
374
    OUTPUT A SLT NORMAL INSTRUCTION
375
 
376
    An sltnormal instruction is output.  This goes straight into the
377
    main output file.
378
*/
379
 
380
static void slt_normal
381
    PROTO_Z ()
382
{
383
    mach_op *op ;
384
    area ( ptext ) ;
385
    op = make_int_data ( crt_line_num ) ;
386
    if ( diag_format == DIAG_STAB ) {
387
	mach_op *op1 = make_int_data ( 68 ) ;
388
	op1->of = make_int_data ( 0 ) ;
389
	op1->of->of = op ;
390
	make_instr ( m_stabd, op1, null, 0 ) ;
391
    } else {
392
	make_instr ( m_dd_normal, op, null, 0 ) ;
393
    }
394
    area ( plast ) ;
395
    slt_num++ ;
396
    return ;
397
}
398
 
399
 
400
/*
401
    OUTPUT A SLT EXIT INSTRUCTION
402
 
403
    An sltexit instruction is output (new format only).
404
*/
405
 
406
void slt_exit
407
    PROTO_Z ()
408
{
409
    mach_op *op ;
410
    area ( ptext ) ;
411
    op = make_int_data ( crt_line_num ) ;
412
    make_instr ( m_dd_exit, op, null, 0 ) ;
413
    area ( plast ) ;
414
    slt_num++ ;
415
    return ;
416
}
417
 
418
 
419
/*
420
    OUTPUT A DNT BEGIN INSTRUCTION
421
*/
422
 
423
void dnt_begin
424
    PROTO_Z ()
425
{
426
    if ( diag_format == DIAG_STAB ) {
427
	long lab = next_lab () ;
428
	make_label ( lab ) ;
429
	push_dscope ( ( posn_t ) lab, 0 ) ;
430
    } else {
431
	posn_t p = out_dd ( diagfp2, xdb_begin, 1 ) ;
432
	push_dscope ( p, 4 ) ;
433
	if ( diag_format == DIAG_XDB_NEW ) fprintf ( diagfp2, "0," ) ;
434
	fprintf ( diagfp2, "%d\n", slt_num ) ;
435
	slt_special ( 5, p ) ;
436
    }
437
    return ;
438
}
439
 
440
 
441
/*
442
    OUTPUT A DNT END INSTRUCTION
443
*/
444
 
445
int dnt_end
446
    PROTO_Z ()
447
{
448
    dscope *d = pop_dscope () ;
449
    if ( d == null ) return ( 0 ) ;
450
    if ( diag_format == DIAG_STAB ) {
451
	long lab1 = ( long ) d->posn ;
452
	long lab2 = next_lab () ;
453
	make_label ( lab2 ) ;
454
	make_stabn ( 192, lab1 ) ;
455
	make_stabn ( 224, lab2 ) ;
456
    } else {
457
	posn_t p = out_dd ( diagfp2, xdb_end, 1 ) ;
458
	if ( diag_format == DIAG_XDB_NEW ) {
459
	    fprintf ( diagfp2, "%d,0,", d->dscope_type ) ;
460
	}
461
	fprintf ( diagfp2, "%d,0x%x\n", slt_num,
462
		  ( unsigned int ) d->posn ) ;
463
	slt_special ( 6, p ) ;
464
    }
465
    return ( 1 ) ;
466
}
467
 
468
 
469
/*
470
    FLAG FOR MODULE NAME
471
*/
472
 
473
static bool have_module = 0 ;
474
 
475
 
476
/*
477
    DIAGNOSTICS FOR FILE NAME
478
 
479
    This routine output the necessary instructions to indicate a change
480
    of source file.
481
*/
482
 
483
void diag_source_file
484
    PROTO_N ( ( nm, ln ) )
485
    PROTO_T ( char *nm X long ln )
486
{
487
    if ( diag_format == DIAG_STAB ) {
488
	int n = strlen ( nm ) + 3 ;
489
	char *qnm = alloc_nof ( char, n ) ;
490
	mach_op *op = make_extern_data ( "Ltext", 0 ) ;
491
	sprintf ( qnm, "\"%s\"", nm ) ;
492
	make_stabs ( qnm, ( have_module ? 132 : 100 ), L0, op ) ;
493
	if ( !have_module ) {
494
	    make_external_label ( "Ltext" ) ;
495
	    init_stab_types () ;
496
	    have_module = 1 ;
497
	}
498
	crt_fname = nm ;
499
	crt_line_num = ln ;
500
    } else {
501
	posn_t x = out_dd ( diagfp2, xdb_srcfile, 1 ) ;
502
	fprintf ( diagfp2, "1," ) ;
503
	diag_string ( diagfp2, nm ) ;
504
	fprintf ( diagfp2, ",%d\n", slt_num ) ;
505
	crt_fname = nm ;
506
	crt_line_num = ln ;
507
	make_instr ( m_dd_align, null, null, 0 ) ;
508
	slt_special ( 1, x ) ;
509
	if ( !have_module ) {
510
	    x = out_dd ( diagfp2, xdb_module, 1 ) ;
511
	    if ( diag_format == DIAG_XDB_NEW ) {
512
		fprintf ( diagfp2, "0,0" ) ;
513
	    } else {
514
		diag_string ( diagfp2, nm ) ;
515
	    }
516
	    fprintf ( diagfp2, ",%d\n", slt_num ) ;
517
	    push_dscope ( x, 1 ) ;
518
	    slt_special ( 2, x ) ;
519
	    have_module = 1 ;
520
	}
521
    }
522
    return ;
523
}
524
 
525
 
526
/*
527
    DIAGNOSTICS FOR LINE NUMBER
528
 
529
    This routine outputs an instruction indicating the position within
530
    the source file.
531
*/
532
 
533
void diag_source
534
    PROTO_N ( ( nm, ln, d ) )
535
    PROTO_T ( char *nm X long ln X int d )
536
{
537
    if ( have_module && d == 0 ) return ;
538
    if ( !eq ( nm, crt_fname ) ) diag_source_file ( nm, ln ) ;
539
    crt_line_num = ln ;
540
    if ( d ) slt_normal () ;
541
    return ;
542
}
543
 
544
 
545
/*
546
    CURRENT DIAGNOSTICS PROCEDURE LABEL
547
*/
548
 
549
long crt_diag_proc_lab ;
550
 
551
 
552
/*
553
    DIAGNOSTICS FOR A PROCEDURE
554
*/
555
 
556
void diag_proc_main
557
    PROTO_N ( ( dt, e, id, is_glob, val ) )
558
    PROTO_T ( diag_type dt X exp e X char *id X int is_glob X char *val )
559
{
560
    exp a ;
561
    posn_t t ;
562
    long fp ;
563
    table_posn *p ;
564
    diag_type dtl ;
565
 
566
    /* Analyse result sort */
567
    if ( dt->key != DIAG_TYPE_PROC ) {
568
	error ( "Illegal procedure type" ) ;
569
	return ;
570
    }
571
    dtl = dt->data.proc.result_type ;
572
 
573
    if ( diag_format == DIAG_STAB ) {
574
	mach_op *op = make_extern_data ( val, 0 ) ;
575
	char *st = analyse_stab_type ( dtl, id, ( is_glob ? "F" : "f" ) ) ;
576
	make_stabs ( st, 36, crt_line_num, op ) ;
577
	dnt_begin () ;
578
    } else {
579
	p = analyse_diag_type ( diagfp2, dtl, 1 ) ;
580
 
581
	/* Create diagnostics procedure label */
582
	crt_diag_proc_lab = next_lab () ;
583
 
584
	/* Output function diagnostic directive */
585
	t = out_dd ( diagfp2, xdb_function, 1 ) ;
586
	fprintf ( diagfp2, "%d,1,", is_glob ) ;
587
	if ( diag_format == DIAG_XDB_NEW ) fprintf ( diagfp2, "0,0,0,0,0," ) ;
588
	diag_string ( diagfp2, id ) ;
589
	if ( strcmp ( id, "main" ) == 0 ) {
590
	    fputc ( ',', diagfp2 ) ;
591
	    diag_string ( diagfp2, "_MAIN_" ) ;
592
	    fputc ( ',', diagfp2 ) ;
593
	} else {
594
	    fprintf ( diagfp2, ",0," ) ;
595
	}
596
	fp = ftell ( diagfp2 ) ;
597
	fprintf ( diagfp2, "%s,%d,%s,", NULL_POSN_STR, slt_num, val ) ;
598
	out_posn ( diagfp2, p, 1 ) ;
599
	if ( diag_format == DIAG_XDB_NEW ) fprintf ( diagfp2, "%s,", val ) ;
600
	fprintf ( diagfp2, "L%ld\n", crt_diag_proc_lab ) ;
601
 
602
	/* Start new diagnostic scope */
603
	push_dscope ( t, 2 ) ;
604
	slt_special ( 3, t ) ;
605
    }
606
 
607
    /* Step over actual procedure arguments */
608
    a = son ( e ) ;
609
    while ( name ( a ) == ident_tag /* && isparam ( a ) */ ) {
610
	a = bro ( son ( a ) ) ;
611
    }
612
 
613
    /* Read procedure argument definitions */
614
    while ( name ( a ) == diagnose_tag ) {
615
	diag_info *di = dno ( a ) ;
616
	if ( di->key == DIAG_INFO_ID ) {
617
	    exp ps = di->data.id_scope.access ;
618
	    if ( isparam ( son ( ps ) ) ) {
619
		diag_type pdt = di->data.id_scope.typ ;
620
		char *pnm = di->data.id_scope.nme.ints.chars ;
621
		long off = 8 + ( no ( ps ) + no ( son ( ps ) ) ) / 8 ;
622
		if ( diag_format == DIAG_STAB ) {
623
		    mach_op *op = make_int_data ( off ) ;
624
		    char *st = analyse_stab_type ( pdt, pnm, "p" ) ;
625
		    make_stabs ( st, 160, L0, op ) ;
626
		} else {
627
		    p = analyse_diag_type ( diagfp2, pdt, 1 ) ;
628
		    t = out_dd ( diagfp2, xdb_fparam, 1 ) ;
629
		    fill_gap ( diagfp2, fp, t ) ;
630
		    if ( diag_format == DIAG_XDB_NEW ) {
631
			fprintf ( diagfp2, "0,0,0,0,0," ) ;
632
		    } else {
633
			fprintf ( diagfp2, "0,0," ) ;
634
		    }
635
		    if ( *pnm ) {
636
			diag_string ( diagfp2, pnm ) ;
637
		    } else {
638
			diag_string ( diagfp2, "__unknown" ) ;
639
		    }
640
		    fprintf ( diagfp2, ",%ld,", off ) ;
641
		    out_posn ( diagfp2, p, 1 ) ;
642
		    fp = ftell ( diagfp2 ) ;
643
		    if ( diag_format == DIAG_XDB_NEW ) {
644
			fprintf ( diagfp2, "%s,0\n", NULL_POSN_STR ) ;
645
		    } else {
646
			fprintf ( diagfp2, "%s\n", NULL_POSN_STR ) ;
647
		    }
648
		}
649
	    }
650
	}
651
	a = son ( a ) ;
652
    }
653
    return ;
654
}
655
 
656
 
657
/*
658
    DIAGNOSTICS FOR A GLOBAL IDENTIFIER
659
*/
660
 
661
void diag_globl_variable
662
    PROTO_N ( ( dt, id, is_glob, val, has_def ) )
663
    PROTO_T ( diag_type dt X char *id X int is_glob X char *val X int has_def )
664
{
665
    if ( diag_format == DIAG_STAB ) {
666
	if ( is_glob ) {
667
	    char *st = analyse_stab_type ( dt, id, "G" ) ;
668
	    make_stabs ( st, 32, crt_line_num, null ) ;
669
	} else {
670
	    mach_op *op = make_extern_data ( val, 0 ) ;
671
	    char *st = analyse_stab_type ( dt, id, "S" ) ;
672
	    make_stabs ( st, 38, crt_line_num, op ) ;
673
	}
674
    } else {
675
	int loc ;
676
	FILE *file ;
677
	table_posn *x ;
678
	if ( diag_format == DIAG_XDB_NEW ) {
679
	    loc = ( is_glob ? 0 : 1 ) ;
680
	    file = ( is_glob ? diagfp3 : diagfp2 ) ;
681
	} else {
682
	    loc = 1 ;
683
	    file = diagfp2 ;
684
	}
685
	x = analyse_diag_type ( file, dt, loc ) ;
686
	( void ) out_dd ( file, xdb_svar, loc ) ;
687
	if ( diag_format == DIAG_XDB_NEW ) {
688
	    fprintf ( file, "%d,0,0,0,0,", is_glob ) ;
689
	} else {
690
	    fprintf ( file, "%d,0,", is_glob ) ;
691
	}
692
	diag_string ( file, id ) ;
693
	if ( has_def ) {
694
	    fprintf ( file, ",%s,", val ) ;
695
	} else {
696
	    fprintf ( file, ",-1," ) ;
697
	}
698
	out_posn ( file, x, 1 ) ;
699
	fprintf ( file, "0,0\n" ) ;
700
    }
701
    return ;
702
}
703
 
704
 
705
/*
706
    DIAGNOSTICS FOR A LOCAL IDENTIFIER
707
*/
708
 
709
void diag_local_variable
710
    PROTO_N ( ( dt, id, fp ) )
711
    PROTO_T ( diag_type dt X char *id X long fp )
712
{
713
    if ( diag_format == DIAG_STAB ) {
714
	mach_op *op = make_int_data ( -fp ) ;
715
	char *st = analyse_stab_type ( dt, id, "l" ) ;
716
	make_stabs ( st, 128, crt_line_num, op ) ;
717
    } else {
718
	table_posn *x = analyse_diag_type ( diagfp2, dt, 1 ) ;
719
	( void ) out_dd ( diagfp2, xdb_dvar, 1 ) ;
720
	if ( diag_format == DIAG_XDB_NEW ) {
721
	    fprintf ( diagfp2, "0,0,0,0," ) ;
722
	} else {
723
	    fprintf ( diagfp2, "0,0,0," ) ;
724
	}
725
	diag_string ( diagfp2, id ) ;
726
	fprintf ( diagfp2, ",%ld,", -fp ) ;
727
	if ( diag_format == DIAG_XDB_NEW ) {
728
	    out_posn ( diagfp2, x, 1 ) ;
729
	    fprintf ( diagfp2, "0\n" ) ;
730
	} else {
731
	    out_posn ( diagfp2, x, 0 ) ;
732
	}
733
    }
734
    return ;
735
}
736
 
737
 
738
/*
739
    DIAGNOSTICS FOR A TYPE DEFINITION
740
*/
741
 
742
void diag_type_defn
743
    PROTO_N ( ( nm, dt ) )
744
    PROTO_T ( char *nm X diag_type dt )
745
{
746
    switch ( dt->key ) {
747
 
748
	case DIAG_TYPE_UNINIT :
749
	case DIAG_TYPE_INITED : {
750
	    /* Ignore unused types */
751
	    break ;
752
	}
753
 
754
	default : {
755
	    if ( diag_format == DIAG_STAB ) {
756
		char *st = analyse_stab_type ( dt, nm, "t" ) ;
757
		make_stabs ( st, 128, L1, null ) ;
758
	    } else {
759
		int loc = ( diag_format == DIAG_XDB_NEW ? 0 : 1 ) ;
760
		FILE *file = ( loc ? diagfp2 : diagfp3 ) ;
761
		table_posn *p = analyse_diag_type ( file, dt, loc ) ;
762
		( void ) out_dd ( file, xdb_typedef, loc ) ;
763
		fprintf ( file, "0," ) ;
764
		diag_string ( file, nm ) ;
765
		fprintf ( file, "," ) ;
766
		out_posn ( file, p, 0 ) ;
767
	    }
768
	    break ;
769
	}
770
    }
771
    return ;
772
}