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) 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
/**********************************************************************
32
$Author: pwe $
33
$Date: 1998/03/15 16:00:35 $
34
$Revision: 1.5 $
35
$Log: dw2_info.c,v $
36
 * Revision 1.5  1998/03/15  16:00:35  pwe
37
 * regtrack dwarf dagnostics added
38
 *
39
 * Revision 1.4  1998/03/11  11:03:43  pwe
40
 * DWARF optimisation info
41
 *
42
 * Revision 1.3  1998/02/18  11:22:20  pwe
43
 * test corrections
44
 *
45
 * Revision 1.2  1998/01/21  10:30:06  pwe
46
 * labdiff change
47
 *
48
 * Revision 1.1.1.1  1998/01/17  15:55:48  release
49
 * First version to be checked into rolling release.
50
 *
51
 * Revision 1.13  1998/01/09  09:31:32  pwe
52
 * prep restructure
53
 *
54
 * Revision 1.12  1997/12/04  19:41:31  pwe
55
 * ANDF-DE V1.9
56
 *
57
 * Revision 1.11  1997/11/06  09:22:14  pwe
58
 * ANDF-DE V1.8
59
 *
60
 * Revision 1.10  1997/10/28  10:14:22  pwe
61
 * local location corrections
62
 *
63
 * Revision 1.9  1997/10/23  09:27:40  pwe
64
 * ANDF-DE v1.7, extra diags
65
 *
66
 * Revision 1.8  1997/10/10  18:18:38  pwe
67
 * prep ANDF-DE revision
68
 *
69
 * Revision 1.7  1997/08/23  13:36:45  pwe
70
 * initial ANDF-DE
71
 *
72
 * Revision 1.6  1997/06/25  13:05:39  pwe
73
 * constant global floats as well as local
74
 *
75
 * Revision 1.5  1997/06/25  12:16:16  pwe
76
 * constant floats supported, 4-byte only
77
 *
78
 * Revision 1.4  1997/04/17  11:50:25  pwe
79
 * Sparc and 80x86 support
80
 *
81
 * Revision 1.3  1997/04/04  15:17:13  pwe
82
 * another (long)
83
 *
84
 * Revision 1.2  1997/04/01  17:19:40  pwe
85
 * diagnose pl_tests and locate -> platform specific
86
 *
87
 * Revision 1.1  1997/03/20  16:09:18  pwe
88
 * first version
89
 *
90
**********************************************************************/
91
 
92
#include "config.h"
93
#include "common_types.h"
94
#include "dg_aux.h"
95
#include "dw2_config.h"
96
#include "dw2_entries.h"
97
#include "dw2_codes.h"
98
#include "dw2_info.h"
99
#include "dw2_basic.h"
100
#include "dw2_types.h"
101
#include "dw2_lines.h"
102
#include "dw2_iface.h"
103
#include "tags.h"
104
#include "expmacs.h"
105
#include "shapemacs.h"
106
#include "basicread.h"
107
#include "flags.h"
108
#include "flpt.h"
109
#include "flpttypes.h"
110
#include "externs.h"
111
#include "xalloc.h"
112
#include "dg_globs.h"
113
#include "f64.h"
114
#include "dw2_locdata.h"
115
 
116
 
117
long dw2_scope_start = 0;
118
long dw2_scope_end = 0;
119
int dw_doing_branch_tests = 0;
120
 
121
static long local_var_place;
122
static int doing_abstract = 0;
123
static int doing_inline = 0;	/* consistency check only */
124
static dg_info proc_dg_info = (dg_info)0;
125
static dg_type return_type = (dg_type)0;
126
 
127
static dg_default * default_span_list = (dg_default *)0;
128
 
129
static void fail_unimplemented
130
    PROTO_Z ()
131
{
132
  failer ("unimplemented attribute");
133
  return;
134
}
135
 
136
static exp find_id
137
    PROTO_N ( (e) )
138
    PROTO_T ( exp e )
139
{
140
  if (name(e) == name_tag && !isdiscarded(e) && !isvar(son(e)))
141
    return son(e);
142
  if (name(e) == cont_tag && name(son(e)) == name_tag && !isdiscarded(son(e))
143
		&& ( isvar(son(son(e))) || isparam(son(son(e))) ))
144
    return son(son(e));
145
  return nilexp;
146
}
147
 
148
 
149
void dw_out_const
150
    PROTO_N ( (e) )
151
    PROTO_T ( exp e )
152
{
153
  switch (name(e)) {
154
    case real_tag: {
155
      int sw = (shape_size(sh(e)) <= 32 ? 0 : 1);
156
				/* DWARF cannot represent extended reals */
157
      r2l real_parts;
158
      real_parts = real2longs_IEEE (&flptnos[no(e)], sw);
159
      dw_at_form ((sw ? DW_FORM_data8 : DW_FORM_data4));
160
      d_outnl ();
161
      dw_at_data (4, (long)(real_parts.i1));
162
      if (sw)
163
	dw_at_data (4, (long)(real_parts.i2));
164
      break;
165
    }
166
    case val_tag:
167
    case null_tag: {
168
      if (isbigval(e)) {
169
	flt64 x;
170
	int ov;
171
	x = flt_to_f64(no(e), is_signed(sh(e)), &ov);
172
	dw_at_form (DW_FORM_data8); d_outnl ();
173
	dw_at_data (4, (long)(x.small));
174
	dw_at_data (4, (long)(x.big));
175
      }
176
      else
177
      if (is_signed(sh(e))) {
178
	dw_at_form (DW_FORM_sdata); outs (", ");
179
	sleb128 ((long)no(e)); d_outnl();
180
      }
181
      else {
182
	dw_at_form (DW_FORM_udata); outs (", ");
183
	uleb128 ((unsigned long)no(e)); d_outnl();
184
      }
185
      break;
186
    }
187
    default: {
188
      dw_at_form (DW_FORM_block1); d_outnl();
189
      dw2_locate_exp (e, 1, 0);
190
    }
191
  }
192
  return;
193
}
194
 
195
 
196
void dw_out_default
197
    PROTO_N ( (d) )
198
    PROTO_T ( dg_default * d )
199
{
200
  if (d->val && dw_is_const (son(d->val)))
201
    dw_out_const (son(d->val));
202
  else
203
  if (d->span.sp_key != SP_SPAN) {
204
    dw_at_form (DW_FORM_flag); d_outnl();
205
    dw_at_flag (1);
206
  }
207
  else {
208
    if (!d->lab) {
209
      d->lab = next_dwarf_label ();
210
      d->next = default_span_list;
211
      default_span_list = d;
212
    }
213
    dw_at_form (DW_FORM_ref_addr); d_outnl();
214
    dw_at_address (d->lab);
215
  }
216
  return;
217
}
218
 
219
 
220
void complete_defaults
221
    PROTO_Z ()
222
{
223
  while (default_span_list) {
224
    out_dwf_label (default_span_list->lab, 1);
225
    IGNORE dw_entry (dwe_span, (long)0);
226
    IGNORE dw_entry (dwe_span_strt, (long)0);
227
    dw_at_decl (shorten_sourcepos (default_span_list->span));
228
    IGNORE dw_entry (dwe_span_end, (long)0);
229
    dw_at_decl (end_sourcepos (default_span_list->span));
230
    dw_sibling_end ();
231
    default_span_list = default_span_list->next;
232
  }
233
  return;
234
}
235
 
236
 
237
static void out_refblock		/* Not certain this is needed! */
238
    PROTO_N ( (objs, assgn) )
239
    PROTO_T ( objset * objs X int assgn )
240
{
241
  int count = 0;
242
#ifdef NEEDS_DEBUG_ALIGN
243
  long over_lab;
244
#endif
245
  objset * p = objs;
246
  while (p) {
247
    if (p->ass == assgn)
248
      count++;
249
    p = p->next;
250
  }
251
  out16();
252
#ifdef NEEDS_DEBUG_ALIGN
253
  if (count) {
254
    over_lab = next_dwarf_label();
255
    out_dwf_label (over_lab, 0);
256
    outs (" - . - 2");
257
  }
258
  else
259
#endif
260
  outn (count * 4);
261
  d_outnl();
262
  if (count) {
263
    p = objs;
264
    while (p) {
265
      if (p->ass == assgn)
266
	dw_at_ext_address (p->tg);
267
      p = p->next;
268
    }
269
#ifdef NEEDS_DEBUG_ALIGN
270
    out_dwf_label (over_lab, 1);
271
#endif
272
  }
273
  return;
274
}
275
 
276
 
277
static void check_trivial
278
    PROTO_N ( (e) )
279
    PROTO_T ( exp e )
280
{
281
#if 0
282
	/* This is still far too strong; e may be anything with equivalent
283
		already in a register! */
284
  if (e && name(e) != val_tag && name(e) != name_tag &&
285
	(name(e) != cont_tag || name(son(e)) != name_tag) &&
286
	name(e) != goto_tag && name(e) != top_tag ) {
287
    if (name(e) == chvar_tag || name(e) == chfl_tag)
288
      check_trivial (son(e));
289
    else
290
      failer ("lost information?");
291
  }
292
#endif
293
  return;
294
}
295
 
296
static void output_detch PROTO_S ((detch_info *	dl));
297
 
298
static detch_info * sub_detch = (detch_info *)0;
299
 
300
 
301
static void output_info
302
    PROTO_N ( (e, d) )
303
    PROTO_T ( exp e X dg_info d )
304
{
305
  /* within info section */
306
  if (!d) {
307
    exp t;
308
    if (!e) {
309
      if (sub_detch)
310
	output_detch (sub_detch);
311
      return;
312
    }
313
    if (name(e) == name_tag || name(e) == env_size_tag || 
314
	name(e) == env_offset_tag || (t = son(e), !t))
315
      return;
316
    for (;;) {
317
      output_info (t, dgf(t));
318
      if (last(t) || name(e) == case_tag) return;
319
      t = bro(t);
320
    }
321
  }
322
 
323
  switch (d->key) {
324
 
325
    case DGA_COMP: {
326
      if (!(d->data.i_comp.lo_pc)) {	/* optimised away */
327
	check_trivial (e);
328
	output_info (e, d->more);
329
	break;
330
      }
331
      if (d->data.i_comp.is_tag) {
332
	IGNORE dw_entry (dwe_for_unit, (long)0);
333
	dw_at_address (d->data.i_comp.lo_pc);
334
	dw_at_address (d->data.i_comp.hi_pc);
335
	dw_at_ext_address (d->data.i_comp.corl.comp_tag);
336
      }
337
      else {
338
	IGNORE dw_entry (dwe_for_lang, (long)0);
339
	dw_at_address (d->data.i_comp.lo_pc);
340
	dw_at_address (d->data.i_comp.hi_pc);
341
	dw_at_udata ((unsigned long)d->data.i_comp.corl.comp_lang);
342
      }
343
      output_info (e, d->more);
344
      break;
345
    }
346
 
347
    case DGA_PARAMS: {
348
      output_info (e, d->more);
349
      break;
350
    }
351
 
352
    case DGA_SRC: {
353
      output_info (e, d->more);
354
      break;
355
    }
356
 
357
    case DGA_SCOPE: {
358
      long old_scope1 = dw2_scope_start;
359
      long old_scope2 = dw2_scope_end;
360
      long attr1 = 0, attr2;
361
      char * lexname = d->data.i_scope.lexname;
362
      if (!doing_abstract) {
363
	if (!(d->data.i_scope.start)) {	/* optimised away */
364
	  check_trivial (e);
365
	  output_info (e, d->more);
366
	  break;
367
	}
368
	if (lexname && lexname[0])
369
	  attr1 |= (H_NM | H_XY);
370
	attr1 |= H_PC;
371
	if (d->data.i_scope.begin_st) {
372
	  if (d->data.i_scope.begin_st == (long)(-1))	/* old diags */
373
	    d->data.i_scope.begin_st = (long)0;
374
	  else
375
	    attr1 |= H_BG;
376
	  }
377
      }
378
      dw2_scope_start = d->data.i_scope.start;
379
      dw2_scope_end = d->data.i_scope.end;
380
      attr2 = dw_entry (dwe_scope, attr1);
381
      if (attr2 & ~(H_NM|H_XY|H_PC|H_BG))
382
	fail_unimplemented ();
383
      if (attr2 & H_NM)
384
	dw_at_string (lexname);
385
      if (attr2 & H_XY)
386
	dw_at_decl (d->data.i_scope.lexpos);
387
      if (attr2 & H_PC) {
388
	dw_at_address (dw2_scope_start);
389
	dw_at_address (dw2_scope_end);
390
      }
391
      if (attr2 & H_BG)
392
	dw_at_address (d->data.i_scope.begin_st);
393
      output_info (e, d->more);
394
      dw_sibling_end ();
395
      dw2_scope_start = old_scope1;
396
      dw2_scope_end = old_scope2;
397
      break;
398
    }
399
 
400
    case DGA_EXTRA: {
401
      long old_scope1 = dw2_scope_start;
402
      long old_scope2 = dw2_scope_end;
403
      dw2_scope_start = d->data.i_scope.start;
404
      dw2_scope_end = d->data.i_scope.end;
405
      if (!doing_abstract) {
406
	IGNORE dw_entry (dwe_fragment, (long)0);
407
	dw_at_address (dw2_scope_start);
408
	dw_at_address (dw2_scope_end);
409
      }
410
      output_info (e, d->more);
411
      if (!doing_abstract)
412
	dw_sibling_end ();
413
      dw2_scope_start = old_scope1;
414
      dw2_scope_end = old_scope2;
415
      break;
416
    }
417
 
418
    case DGA_LAB: {
419
      if (!doing_abstract) {
420
	if (d->data.i_scope.start) {
421
	  IGNORE dw_entry (dwe_label, (long)0);
422
	  dw_at_string (d->data.i_scope.lexname);
423
	  dw_at_decl (d->data.i_scope.lexpos);
424
	  dw_at_address (d->data.i_scope.start);
425
	}
426
	else
427
	  check_trivial (e);
428
      }
429
      output_info (e, d->more);
430
      break;
431
    }
432
 
433
    case DGA_NAME: {
434
      local_var_place = d->data.i_nam.scope_start;
435
      dw2_out_name (d->data.i_nam.dnam, (e ? LOCAL_NAME : DEAD_NAME));
436
      output_info (e, d->more);
437
      break;
438
    }
439
 
440
    case DGA_WITH: {
441
      if (!doing_abstract) {
442
	if (!(d->data.i_with.lo_pc) || !e) {	/* optimised away */
443
	  check_trivial (e);
444
	  output_info (e, d->more);
445
	  break;
446
	}
447
	IGNORE dw_entry (dwe_with, (long)0);
448
	dw_at_ext_lab (dw2_find_type_label (d->data.i_with.w_typ));
449
	dw2_locate_exp (son(d->data.i_with.w_exp), 0, 0);
450
	dw_at_address (d->data.i_with.lo_pc);
451
	dw_at_address (d->data.i_with.hi_pc);
452
      }
453
      output_info (e, d->more);
454
      if (!doing_abstract) {
455
	dw_sibling_end ();
456
      }
457
      break;
458
    }
459
 
460
    case DGA_CALL: {
461
      if (doing_abstract)
462
        output_info (e, d->more);
463
      else {
464
	if (!(d->data.i_call.brk)) {	/* optimised away */
465
	  check_trivial (e);
466
	  output_info (e, d->more);
467
	  break;
468
	}
469
	IGNORE dw_entry (dwe_call, (long)0);
470
	dw_at_string (d->data.i_call.clnam);
471
	dw_at_decl (d->data.i_call.pos);
472
	dw_at_udata ((unsigned long)d->data.i_call.ck);
473
	dw_at_address (d->data.i_call.brk);
474
	dw2_locate_val (d->data.i_call.p);
475
	output_info (e, d->more);
476
      }
477
      break;
478
    }
479
 
480
    case DGA_INL_CALL: {
481
      int old_il = doing_inline;
482
      dg_type old_res = return_type;
483
      dg_name_list args = d->data.i_inl.args;
484
      dg_name di;
485
      dg_type p_t, res_t;
486
      long brk = d->data.i_inl.lo_pc;
487
      if (doing_abstract)
488
	break;	/* no recursion */
489
      di = d->data.i_inl.proc->p.nam;
490
      p_t = find_proc_type (di->data.n_proc.typ);
491
      res_t = p_t->data.t_proc.res_type;
492
      return_type = res_t;
493
      if (brk) {			/* sometimes lo = hi */
494
	IGNORE dw_entry (dwe_inl_call, (long)0);
495
	dw_at_ext_address (d->data.i_inl.proc);
496
	dw_at_address (d->data.i_inl.lo_pc);
497
	dw_at_address (d->data.i_inl.hi_pc);
498
      }
499
      else {	/* call compressed into operand, so no breakpoint */
500
	check_trivial (e);
501
	IGNORE dw_entry (dwe_inl_opnd, (long)0);
502
	dw_at_ext_address (d->data.i_inl.proc);
503
      }
504
      doing_inline = 1;
505
      while (args) {
506
	dw2_out_name (args, INL_PARAM_NAME);
507
	args = args->next;
508
      }
509
      if (extra_diags && brk) {
510
	dg_info rets = d->data.i_inl.resref;
511
	long attr1 = H_XY, attr2;
512
	if (rets) {
513
	  attr1 |= H_PC;
514
	  if (res_t)
515
	    attr1 |= H_LC;
516
	}
517
	do {
518
	  attr2 = dw_entry (dwe_return, attr1);
519
	  if (attr2 & ~(H_XY|H_PC|H_LC))
520
	    fail_unimplemented ();
521
	  if (attr2 & H_XY)
522
	    dw_at_decl (di->mor->end_pos);
523
	  if (attr2 & H_PC)
524
	    dw_at_address (rets->data.i_res.brk);
525
	  if (attr2 & H_LC)
526
	    dw2_locate_val (rets->data.i_res.res);
527
	  if (!rets)
528
	    break;
529
	  rets = rets->data.i_res.next;
530
	}
531
	while (rets);
532
      }
533
      output_info (e, d->more);
534
      doing_inline = old_il;
535
      dw_sibling_end ();
536
      return_type = old_res;
537
      break;
538
    }
539
 
540
    case DGA_INL_RES: {
541
      output_info (e, d->more);
542
      break;
543
    }
544
 
545
    case DGA_X_TRY: {
546
      if (!doing_abstract) {
547
	if (!(d->data.i_try.lo_pc)) {	/* optimised away */
548
	  check_trivial (e);
549
	  output_info (e, d->more);
550
	  break;
551
	}
552
	IGNORE dw_entry (dwe_try, (long)0);
553
	dw_at_address (d->data.i_try.lo_pc);
554
	dw_at_address (d->data.i_try.hi_pc);
555
      }
556
      output_info (e, d->more);
557
      if (!doing_abstract)
558
	dw_sibling_end ();
559
      break;
560
    }
561
 
562
    case DGA_X_CATCH: {
563
      if (!doing_abstract) {
564
	if (!(d->data.i_catch.lo_pc)) {	/* optimised away */
565
	  check_trivial (e);
566
	  output_info (e, d->more);
567
	  break;
568
	}
569
	IGNORE dw_entry (dwe_catch, (long)0);
570
	dw_at_address (d->data.i_catch.lo_pc);
571
	dw_at_address (d->data.i_catch.hi_pc);
572
	if (d->data.i_catch.ex)
573
	  dw2_out_name (d->data.i_catch.ex, EXCEPT_NAME);
574
	else
575
	  IGNORE dw_entry (dwe_opt_par, (long)0);
576
      }
577
      output_info (e, d->more);
578
      if (!doing_abstract)
579
	dw_sibling_end ();
580
      break;
581
    }
582
 
583
    case DGA_X_RAISE: {
584
      if (!doing_abstract) {
585
	long attr1 = H_XY, attr2;
586
	if (d->data.i_raise.x_typ)
587
	  attr1 |= H_TP;
588
	if (d->data.i_raise.x_val)
589
	  attr1 |= (dw_is_const (son(d->data.i_raise.x_val)) ? H_CV : H_LC);
590
	attr2 = dw_entry (dwe_throw, attr1);
591
	if (attr2 & ~(H_XY|H_TP|H_LC|H_CV))
592
	  fail_unimplemented ();
593
	if (attr2 & H_XY)
594
	  dw_at_decl (d->data.i_raise.pos);
595
	if (attr2 & H_TP)
596
	  dw_at_ext_lab (dw2_find_type_label (d->data.i_raise.x_typ));
597
	if (attr2 & H_LC)
598
	  dw2_locate_exp (son(d->data.i_raise.x_val), 0, 0);
599
	if (attr2 & H_CV)
600
	  dw_out_const (son(d->data.i_raise.x_val));
601
      }
602
      output_info (e, d->more);
603
      break;
604
    }
605
 
606
    case DGA_BRANCH: {
607
      if (doing_abstract)
608
        output_info (e, d->more);
609
      else {
610
	long brk = d->data.i_brn.brk;
611
	if (brk) {
612
	  IGNORE dw_entry (dwe_branch, (long)0);
613
	  dw_at_decl (d->data.i_brn.pos);
614
	  dw_at_address (brk);
615
	  dw_at_address (d->data.i_brn.cont);
616
	  trace_dw_branch_exits (e);
617
	}
618
	else {
619
	  check_trivial (e);
620
	  IGNORE dw_entry (dwe_branch_0, (long)0);
621
	  dw_at_decl (d->data.i_brn.pos);
622
	}
623
        output_info (e, d->more);
624
	if (brk)
625
	  dw_sibling_end ();
626
      }
627
      break;
628
    }
629
 
630
    case DGA_TEST: {
631
      if (doing_abstract)
632
        output_info (e, d->more);
633
      else {
634
	long brk = d->data.i_tst.brk;
635
	if (brk) {
636
	  IGNORE dw_entry (dwe_test, (long)0);
637
	  dw_at_decl (d->data.i_tst.pos);
638
	  dw_at_address (d->data.i_tst.brk);
639
	  dw_at_address (d->data.i_tst.cont);
640
	  dw_at_ext_lab (d->data.i_tst.jlab);
641
	}
642
	else {
643
	  check_trivial (e);
644
	  IGNORE dw_entry (dwe_test_0, (long)0);
645
	  dw_at_decl (d->data.i_tst.pos);
646
	}
647
	output_info (e, d->more);
648
      }
649
      break;
650
    }
651
 
652
    case DGA_JUMP: {
653
      if (doing_abstract)
654
        output_info (e, d->more);
655
      else {
656
	long brk = d->data.i_tst.brk;
657
	if (brk) {
658
	  IGNORE dw_entry (dwe_jump, (long)0);
659
	  dw_at_decl (d->data.i_tst.pos);
660
	  dw_at_address (d->data.i_tst.brk);
661
	  dw_at_ext_lab (d->data.i_tst.jlab);
662
	}
663
	else {
664
	  check_trivial (e);
665
	  IGNORE dw_entry (dwe_jump_0, (long)0);
666
	  dw_at_decl (d->data.i_tst.pos);
667
	}
668
	output_info (e, d->more);
669
      }
670
      break;
671
    }
672
 
673
    case DGA_LJ: {
674
      if (doing_abstract)
675
        output_info (e, d->more);
676
      else {
677
	long brk = d->data.i_lj.brk;
678
	if (brk) {
679
	  IGNORE dw_entry (dwe_lj, (long)0);
680
	  dw_at_decl (d->data.i_lj.pos);
681
	  dw_at_address (d->data.i_lj.brk);
682
	  dw2_locate_val (d->data.i_lj.j);
683
	}
684
	else {
685
	  check_trivial (e);
686
	  IGNORE dw_entry (dwe_lj_0, (long)0);
687
	  dw_at_decl (d->data.i_lj.pos);
688
	}
689
	output_info (e, d->more);
690
      }
691
      break;
692
    }
693
 
694
    case DGA_DEST: {
695
      if (!doing_abstract) {
696
	long attr1 = 0, attr2;
697
	if (!(d->data.i_dest.brk)) {	/* optimised away */
698
	  check_trivial (e);
699
	  output_info (e, d->more);
700
	  break;
701
	}
702
	if (d->data.i_dest.val) {
703
	  attr1 |= H_TP;
704
	  attr1 |= (dw_is_const (son(d->data.i_dest.val)) ? H_CV : H_LC);
705
	}
706
	attr2 = dw_entry (dwe_destruct, attr1);
707
	if (attr2 & ~(H_XY|H_TP|H_LC|H_CV))
708
	  fail_unimplemented ();
709
	dw_at_decl (d->data.i_dest.pos);
710
	dw_at_address (d->data.i_dest.brk);
711
	if (attr2 & H_TP)
712
	  dw_at_ext_lab (dw2_find_type_label (return_type));
713
	if (attr2 & H_LC)
714
	  dw2_locate_exp (son(d->data.i_dest.val), 0, 0);
715
	if (attr2 & H_CV)
716
	  dw_out_const (son(d->data.i_dest.val));
717
      }
718
      output_info (e, d->more);
719
      if (!doing_abstract)
720
	dw_sibling_end ();
721
      break;
722
    }
723
 
724
    case DGA_RVS: {
725
      if (d->data.i_rvs.has_iv)
726
	break;		/* inverse ref, so don't output here */
727
      if (!doing_abstract) {
728
	abbrev_entry dwe;
729
	int w_alt = 0, w_en = 0, w_kind = 0;
730
	switch (d->data.i_rvs.rvs_key) {
731
	  case DGR_SEL:
732
	    dwe = (d->data.i_rvs.async ? dwe_asynchsel : dwe_select);
733
	    break;
734
	  case DGR_ACC:
735
	    dwe = (d->data.i_rvs.n_code ? dwe_accept_c : dwe_accept);
736
	    w_alt = w_en = 1;
737
	    break;
738
	  case DGR_RTS:
739
	    dwe = dwe_rts;
740
	    w_alt = w_kind = 1;
741
	    if (d->data.i_rvs.en) {
742
	      dwe = dwe_rts_en;
743
	      w_en = 1;
744
	    }
745
	    break;
746
	  case DGR_ALT:
747
	    dwe = (d->data.i_rvs.n_code ? dwe_sel_alt_c : dwe_sel_alt);
748
	    w_kind = 1;
749
	    break;
750
	  case DGR_SGD:
751
	    dwe = dwe_sel_guard;
752
	    break;
753
	  case DGR_TRIG:
754
	    dwe = (d->data.i_rvs.n_code ? dwe_trigger_c : dwe_trigger);
755
	    w_kind = 1;
756
	    break;
757
	  case DGR_ABTL:
758
	    dwe = (d->data.i_rvs.n_code ? dwe_abort_ptc : dwe_abort_pt);
759
	    break;
760
	  case DGR_REQUE:
761
	    dwe = dwe_requeue;
762
	    w_en = 1;
763
	    break;
764
	}
765
	IGNORE dw_entry (dwe, (long)0);
766
	dw_at_decl (d->data.i_rvs.pos);
767
	if (d->data.i_rvs.n_code) {
768
	  dw_at_address (d->data.i_rvs.lo_pc);
769
	  if (d->data.i_rvs.n_code >= 2)
770
	    dw_at_address (d->data.i_rvs.hi_pc);
771
	}
772
	if (w_alt)
773
	  dw_at_flag (d->data.i_rvs.alt);
774
	if (w_en)
775
	  dw_at_ext_address (d->data.i_rvs.en);
776
	if (w_kind)
777
	  dw_at_udata ((unsigned long)d->data.i_rvs.kind);
778
	if (d->data.i_rvs.rvs_key == DGR_ALT)
779
	  dw_out_const (d->data.i_rvs.u2.e);
780
	if (d->data.i_rvs.rvs_key == DGR_REQUE)
781
	  dw_at_flag (d->data.i_rvs.w_abort);
782
	if (d->data.i_rvs.rvs_key == DGR_ACC && d->data.i_rvs.n_code) {
783
	  dg_name_list args = d->data.i_rvs.u2.p;
784
	  while (args) {
785
	    dw2_out_name (args, INL_PARAM_NAME);
786
	    args = args->next;
787
	  }
788
	}
789
	if (d->data.i_rvs.holder) {
790
	  dg_info inner = d->data.i_rvs.u.iv;
791
	  while (inner) {
792
	    if (!inner->data.i_rvs.has_iv)
793
	      failer ("bad RVS invert");
794
	    inner->data.i_rvs.has_iv = 0;
795
	    output_info (inner->data.i_rvs.info_e, inner);
796
	    inner->data.i_rvs.has_iv = 1;
797
	    inner = inner->data.i_rvs.u.iv;
798
	  }
799
	}
800
      }
801
      output_info (e, d->more);
802
      if (!doing_abstract && d->data.i_rvs.rvs_key != DGR_RTS &&
803
		(d->data.i_rvs.n_code || (d->data.i_rvs.rvs_key == DGR_ALT ||
804
			d->data.i_rvs.rvs_key == DGR_TRIG)))
805
	dw_sibling_end ();
806
      break;
807
    }
808
 
809
    case DGA_DETCH: {
810
      if (d->data.i_detch.posn < 0) {
811
	output_detch (d->data.i_detch.dl);
812
	output_info (e, d->more);
813
      }
814
      else {
815
	output_info (e, d->more);
816
	output_detch (d->data.i_detch.dl);
817
      }
818
      break;
819
    }
820
 
821
    case DGA_MOVD:
822
    case DGA_HOIST: {
823
      if (!doing_abstract) {
824
	dg_tag tg = d->data.i_movd.tg;
825
	if (d->this_tag)
826
	  set_ext_address (d->this_tag);
827
	if (d->data.i_movd.lo_pc) {
828
	  IGNORE dw_entry ((tg ? dwe_moved_r : dwe_moved), (long)0);
829
	  dw_at_udata ((unsigned long)d->data.i_movd.reason);
830
	  if (tg)
831
	    dw_at_ext_address (tg);
832
	  dw_at_address (d->data.i_movd.lo_pc);
833
	  dw_at_address (d->data.i_movd.hi_pc);
834
	}
835
	else {
836
	  check_trivial (e);
837
	  IGNORE dw_entry ((tg ? dwe_moved_xr : dwe_moved_x), (long)0);
838
	  dw_at_udata ((unsigned long)d->data.i_movd.reason);
839
	  if (tg)
840
	    dw_at_ext_address (tg);
841
	}
842
      }
843
      output_info (e, d->more);
844
      if (!doing_abstract)
845
	dw_sibling_end ();
846
      break;
847
    }
848
 
849
    case DGA_OPTIM: {
850
      if (!doing_abstract) {
851
	if (d->this_tag)
852
	  set_ext_address (d->this_tag);
853
	if (d->data.i_optim.lo_pc) {
854
	  IGNORE dw_entry (dwe_optim, (long)0);
855
	  dw_at_udata ((unsigned long)d->data.i_optim.reason);
856
	  dw_at_address (d->data.i_optim.lo_pc);
857
	  dw_at_address (d->data.i_optim.hi_pc);
858
	  out_refblock (d->data.i_optim.objs, 0);	/* unassigned refs */
859
	  out_refblock (d->data.i_optim.objs, 1);	/* assigned refs */
860
	}
861
	else {
862
	  check_trivial (e);
863
	  IGNORE dw_entry (dwe_moved_x, (long)0);
864
	  dw_at_udata ((unsigned long)d->data.i_movd.reason);
865
	}
866
      }
867
      output_info (e, d->more);
868
      if (!doing_abstract)
869
	dw_sibling_end ();
870
      break;
871
    }
872
 
873
    case DGA_REMVAL:
874
    case DGA_BEG:
875
    case DGA_BAR:
876
    case DGA_NONE: {
877
      output_info (e, d->more);
878
      break;
879
    }
880
 
881
    default:
882
      failer ("unexpected dg_info");
883
 
884
  };
885
  return;
886
}
887
 
888
static void output_detch
889
    PROTO_N ( (dl) )
890
    PROTO_T ( detch_info * dl )
891
{
892
  while (dl) {
893
    int has_child = 0;
894
    int has_dest = 0;
895
    int reason = dl->why;
896
    dg_info d_src = dl->info;
897
    dg_info more_src = (dg_info)0;
898
    dg_tag tg = dl->tg;
899
    while (tg && tg->copy)
900
      tg = tg->copy;
901
    if (tg && tg->p.info->key == DGA_MOVD) {
902
      d_src = tg->p.info;
903
      reason = d_src->data.i_movd.reason;
904
      if (d_src->data.i_movd.lost)
905
	tg = d_src->data.i_movd.tg;
906
      else
907
	has_dest = 1;
908
      d_src = d_src->more;
909
    }
910
    if (has_dest) {
911
      if (d_src->key == DGA_SRC && !doing_abstract) {
912
	IGNORE dw_entry (dwe_displ_x, (long)0);
913
	dw_at_ext_address (tg);
914
	dw_at_decl (d_src->data.i_src.startpos);
915
      }
916
      else
917
      if ( !doing_abstract &&
918
		d_src->key != DGA_INL_RES &&
919
		(d_src->key != DGA_RVS || !d_src->data.i_rvs.has_iv) &&
920
		d_src->key != DGA_BEG && d_src->key != DGA_BAR)
921
      {
922
	IGNORE dw_entry (dwe_displaced, (long)0);
923
	dw_at_ext_address (tg);
924
      }
925
    }
926
    else {
927
      if (d_src->key == DGA_SRC && !doing_abstract) {
928
	IGNORE dw_entry ((tg ? dwe_absent_xr : dwe_absent_x), (long)0);
929
	dw_at_udata ((unsigned long)reason);
930
	if (tg)
931
	  dw_at_ext_address (tg);
932
	dw_at_decl (d_src->data.i_src.startpos);
933
      }
934
      else
935
      if (d_src->key == DGA_NAME)	/* included when doing_abstract */
936
	more_src = d_src;
937
      else
938
      if ( !doing_abstract &&
939
		d_src->key != DGA_INL_RES &&
940
		(d_src->key != DGA_RVS || !d_src->data.i_rvs.has_iv) &&
941
		d_src->key != DGA_BEG && d_src->key != DGA_BAR)
942
      {
943
	has_child = 1;
944
	more_src = d_src;
945
	more_src->more = (dg_info)0;
946
	IGNORE dw_entry ((tg ? dwe_absent_r : dwe_absent), (long)0);
947
	dw_at_udata ((unsigned long)reason);
948
	if (tg)
949
	  dw_at_ext_address (tg);
950
      }
951
    }
952
    {
953
      detch_info * old = sub_detch;
954
      sub_detch = dl->sub;
955
      output_info (nilexp, more_src);
956
      sub_detch = old;
957
    }
958
    if (has_child)
959
      dw_sibling_end ();
960
    dl = dl->next;
961
  }
962
  return;
963
}
964
 
965
 
966
static void out_param
967
    PROTO_N ( (p) )
968
    PROTO_T ( dg_param p )
969
{
970
  /* within debug_info */
971
  /* used for declarations only */
972
  long attr1 = (H_TP | H_VP), attr2;
973
  if (p.pnam[0])
974
    attr1 |= H_NM;
975
  if (p.ppos.file)
976
    attr1 |= H_XY;
977
#ifdef H_DX
978
  if (p.p_dflt) {
979
    if (p.p_dflt->span.sp_key == SP_SPAN ||
980
	(p.p_dflt->val && dw_is_const (son(p.p_dflt->val)) ))
981
      attr1 |= H_DF;
982
    else
983
      attr1 |= H_DX;
984
  }
985
#else
986
  if (p.p_dflt)
987
    attr1 |= H_DF;
988
#endif
989
  attr2 = dw_entry (dwe_param, attr1);
990
#ifdef H_DX
991
  if (attr2 & ~(H_NM|H_XY|H_TP|H_VP|H_DF|H_DX))
992
#else
993
  if (attr2 & ~(H_NM|H_XY|H_TP|H_VP|H_DF))
994
#endif
995
    fail_unimplemented ();
996
  if (attr2 & H_NM)
997
    dw_at_string (p.pnam);
998
  if (attr2 & H_XY)
999
    dw_at_decl (p.ppos);
1000
  if (attr2 & H_TP)
1001
    dw_at_ext_lab (dw2_find_type_label (p.p_typ));
1002
  if (attr2 & H_VP) {
1003
    int vp = 0;
1004
    if (p.pmode == DG_OUT_MODE || p.pmode == DG_INOUT_MODE)
1005
      vp = 1;
1006
    dw_at_flag (vp);
1007
  }
1008
#ifdef H_DX
1009
  if (attr2 & H_DX)
1010
    dw_at_flag ((p.p_dflt && !(attr2 & H_DF)) ? 1 : 0);
1011
#endif
1012
  if (attr2 & H_DF)
1013
    dw_out_default (p.p_dflt);
1014
  return;
1015
}
1016
 
1017
 
1018
static void dw2_out_proc
1019
    PROTO_N ( (di) )
1020
    PROTO_T ( dg_name di )
1021
{
1022
				/* within debug_info section */
1023
  int old_il = doing_inline;
1024
  int old_ab = doing_abstract;
1025
  long infolab = 0;
1026
  exp id;
1027
  dg_type p_t, res_t;
1028
  dg_type old_res = return_type;
1029
  long is_callable = DW_CC_normal;
1030
  char* nam;
1031
  char* gnam = "";
1032
  long attr1, attr2;
1033
  dg_instantn * generic = (dg_instantn *)0;
1034
  dg_info old_di = proc_dg_info;
1035
  proc_dg_info = (dg_info)0;
1036
  if (di->idnam.id_key == DG_ID_INST) {
1037
    generic = di->idnam.idd.instance;
1038
    if (generic->nam.id_key == DG_ID_ANON)
1039
      nam = generic->spec.idd.nam;
1040
    else {
1041
      nam = generic->nam.idd.nam;
1042
      gnam = generic->spec.idd.nam;
1043
    }
1044
  }
1045
  else
1046
    nam = di->idnam.idd.nam;
1047
  p_t = find_proc_type (di->data.n_proc.typ);
1048
  res_t = p_t->data.t_proc.res_type;
1049
  return_type = res_t;
1050
  id = di->data.n_proc.obtain_val;
1051
  if (id) {
1052
    exp p;
1053
    if (name(id) != hold_tag || name(son(id)) != name_tag) {
1054
      failer ("wrong proc obtain_tag");
1055
      return;
1056
    }
1057
    id = son(son(id));
1058
    p = son(id);
1059
    if (p) {
1060
      exp t = son(p);
1061
      dw2_prepare_locate (id);
1062
      proc_dg_info = dgf(p);
1063
      if (proc_dg_info && proc_dg_info->key != DGA_PRC)
1064
	failer ("inconsistent proc info");
1065
      if (proc_has_vcallees(p))
1066
	is_callable = DW_CC_nocall;
1067
      while (name(t) == ident_tag && isparam(t) && name(son(t)) != formal_callee_tag)
1068
	t = bro(son(t));
1069
      if (name(t) == ident_tag && name(son(t)) == formal_callee_tag)
1070
	is_callable = DW_CC_nocall;
1071
      if (brog(id)->dec_u.dec_val.extnamed) {
1072
	infolab = next_dwarf_label ();
1073
	exit_section ();
1074
	enter_section ("debug_pubnames");
1075
	out32 (); out_dwf_labdiff (dw_info_start, infolab); d_outnl();
1076
	out_string (nam);
1077
	exit_section ();
1078
	enter_section ("debug_info");
1079
      }
1080
    }
1081
  }
1082
 
1083
  if (p_t->data.t_proc.prps & (f_untidy | f_var_callees))
1084
    is_callable = DW_CC_nocall;
1085
  if (di->mor && di->mor->refspec)
1086
    attr1 = H_SP | H_XY;
1087
  else {
1088
    attr1 = H_NM | H_XY;
1089
    if (res_t)
1090
      attr1 |= H_TP;
1091
    switch (di->idnam.id_key) {
1092
      case DG_ID_EXT:
1093
	attr1 |= H_EX;
1094
	break;
1095
      case DG_ID_ARTFL:
1096
	attr1 |= H_AT;
1097
	break;
1098
      case DG_ID_INST:
1099
	if (gnam[0])
1100
	  attr1 |= H_GN;
1101
	break;
1102
      default:
1103
	break;
1104
    }
1105
    if (p_t->data.t_proc.knowpro)
1106
      attr1 |= H_PT;
1107
    if (p_t->data.t_proc.lang)
1108
      attr1 |= H_LN;
1109
    if (p_t->data.t_proc.ccv) {
1110
      attr1 |= H_CC;
1111
      if (p_t->data.t_proc.ccv != DW_CC_normal)
1112
	is_callable = p_t->data.t_proc.ccv;
1113
    }
1114
  }
1115
  if (is_callable |= DW_CC_normal)
1116
    attr1 |= H_CC;
1117
  if (di->mor && di->mor->isspec)
1118
    attr1 |= H_DC;
1119
  if (di->mor && di->mor->issep)
1120
    attr1 |= H_SE;
1121
  if (di->mor && di->mor->acc)
1122
    attr1 |= H_AC;
1123
  if (di->mor && di->mor->virt)
1124
    attr1 |= H_VT;
1125
  if (di->mor && di->mor->vslot)
1126
    attr1 |= H_VL;
1127
  if (di->mor && di->mor->repn)
1128
    attr1 |= H_RP;
1129
  doing_abstract = 0;
1130
  if (di->mor && di->mor->this_tag) {
1131
    set_ext_address (di->mor->this_tag);
1132
    if (di->mor->this_tag->any_inl) {
1133
      doing_abstract = 1;
1134
      attr1 |= H_IL;
1135
    }
1136
  }
1137
 
1138
  do {
1139
    if (!doing_abstract && proc_dg_info) {
1140
      if (infolab)
1141
	out_dwf_label (infolab, 1);
1142
      attr1 |= H_PC;
1143
      if (proc_dg_info->data.i_prc.p &&
1144
		proc_dg_info->data.i_prc.p->data.i_param.o_env)
1145
	attr1 |= H_SL;
1146
      if (di->mor && di->mor->elabn)
1147
	attr1 |= H_EL;
1148
    }
1149
 
1150
    attr2 = dw_entry (dwe_proc, attr1);
1151
 
1152
    if (attr2 & ~(H_AO|H_SP|H_DC|H_NM|H_XY|H_EX|H_AT|H_AC|H_CC|
1153
		  H_TP|H_PT|H_IL|H_VT|H_VL|H_PC|H_SL|H_EXTN))
1154
      fail_unimplemented ();
1155
    if (attr2 & H_AO)
1156
      dw_at_ext_address (di->mor->this_tag);
1157
    if (attr2 & H_SP)
1158
      dw_at_ext_address (di->mor->refspec);
1159
    if (attr2 & H_DC)
1160
      dw_at_flag ((di->mor && di->mor->isspec ? 1 : 0));
1161
    if (attr2 & H_NM)
1162
      dw_at_string (nam);
1163
    if (attr2 & H_XY)
1164
      dw_at_decl (di->whence);
1165
    if (attr2 & H_EX)
1166
      dw_at_flag ((di->idnam.id_key == DG_ID_EXT ? 1 : 0));
1167
    if (attr2 & H_AT)
1168
      dw_at_flag ((di->idnam.id_key == DG_ID_ARTFL ? 1 : 0));
1169
    if (attr2 & H_AC)
1170
      dw_at_data (1, (long)(di->mor ? di->mor->acc : 0));
1171
    if (attr2 & H_CC)
1172
      dw_at_data (1, is_callable);
1173
    if (attr2 & H_TP)
1174
      dw_at_ext_lab (dw2_find_type_label (res_t));
1175
    if (attr2 & H_PT)
1176
      dw_at_flag (p_t->data.t_proc.yespro);
1177
    if (attr2 & H_IL)
1178
      dw_at_data (1, (long)(di->mor->isinline ? DW_INL_declared_inlined :
1179
					      DW_INL_inlined));
1180
    if (attr2 & H_VT)
1181
      dw_at_data (1, (long)(di->mor ? di->mor->virt : 0));
1182
    if (attr2 & H_VL)
1183
      dw2_locate_exp (son(di->mor->vslot), 0, 0);
1184
    if (attr2 & H_PC) {
1185
      dw_at_address (proc_dg_info->data.i_prc.prc_start);
1186
      dw_at_address (proc_dg_info->data.i_prc.prc_end);
1187
      dw_at_procdetails ();	/* return address and frame_base */
1188
    }
1189
    if (attr2 & H_SL)
1190
      dw2_locate_exp (son(proc_dg_info->data.i_prc.p->data.i_param.o_env), 1, 0);
1191
 
1192
    if (attr2 & H_EXTN) {
1193
      long block_end = next_dwarf_label ();
1194
      attr1 &= ~attr2;
1195
      if (attr1 & ~(H_EL|H_GN|H_RP|H_LN|H_SE))
1196
	fail_unimplemented ();
1197
      out16 (); out_dwf_dist_to_label (block_end); d_outnl();
1198
      if (attr1 & H_EL) {
1199
	set_attribute (DW_AT_DD_elaboration, DW_FORM_ref_addr);
1200
	dw_at_ext_address (di->mor->elabn);
1201
      }
1202
      if (attr1 & H_GN) {
1203
	set_attribute (DW_AT_DD_generic_name, DW_FORM_string);
1204
	dw_at_string (gnam);
1205
      }
1206
      if (attr1 & H_RP) {
1207
	set_attribute (DW_AT_DD_repn, 0);
1208
	dw_out_const (son (di->mor->repn));
1209
      }
1210
      if (attr1 & H_LN) {
1211
	set_attribute (DW_AT_language, DW_FORM_udata);
1212
	dw_at_udata ((unsigned long)(p_t->data.t_proc.lang));
1213
      }
1214
      if (attr1 & H_SE) {
1215
	set_attribute (DW_AT_DD_separate, DW_FORM_flag);
1216
	dw_at_flag ((di->mor && di->mor->issep ? 1 : 0));
1217
      }
1218
      set_attribute (0, 0);
1219
      out_dwf_label (block_end, 1);
1220
    }
1221
 
1222
    if (!doing_abstract && generic)
1223
      dw2_out_generic (generic->params);
1224
 
1225
    if (!doing_abstract && !proc_dg_info && !di->data.n_proc.params) {
1226
		/* must be declaration only */
1227
      dg_param * el = p_t->data.t_proc.params.array;
1228
      int i;
1229
      for (i = 0; i < p_t->data.t_proc.params.len; i++)
1230
	out_param (el[i]);
1231
      if (p_t->data.t_proc.prps & f_var_callers)
1232
	IGNORE dw_entry (dwe_opt_par, (long)0);
1233
 
1234
      if (di->mor && di->mor->en_family)
1235
	dw_out_dim (*(di->mor->en_family));
1236
      dw_sibling_end ();
1237
      break;	/* to return */
1238
    }
1239
    {
1240
      dg_name param = (dg_name)0;
1241
      dg_param * el = p_t->data.t_proc.params.array;
1242
      int w = 0;
1243
      if (proc_dg_info && proc_dg_info->data.i_prc.p)
1244
	param = proc_dg_info->data.i_prc.p->data.i_param.args;
1245
      else
1246
      if (di->data.n_proc.params)
1247
	param = di->data.n_proc.params->data.i_param.args;
1248
      while (param) {
1249
	if (param->key == DGN_OBJECT) {
1250
	  if (w < p_t->data.t_proc.params.len)
1251
	    param->data.n_obj.p = &(el[w]);
1252
	  else
1253
	    param->data.n_obj.p = (dg_param *)0;
1254
	}
1255
	if (doing_abstract) {
1256
	  if (!(param->mor) || !(param->mor->this_tag))
1257
	    failer ("param inlining error");
1258
	  param->mor->inline_ref = param->mor->this_tag;
1259
	}
1260
	dw2_out_name (param, PARAM_NAME);
1261
	param = param->next;
1262
	w++;
1263
      }
1264
    }
1265
    if (p_t->data.t_proc.prps & f_var_callers)
1266
      IGNORE dw_entry (dwe_opt_par, (long)0);
1267
 
1268
    if (!doing_abstract && di->mor && di->mor->exptns.len) {
1269
      dg_type * et = di->mor->exptns.array;
1270
      int i;
1271
      for (i = 0; i < di->mor->exptns.len; i++) {
1272
	IGNORE dw_entry (dwe_thrown_t, (long)0);
1273
	dw_at_ext_lab (dw2_find_type_label (et[i]));
1274
      }
1275
    }
1276
    if (di->mor && di->mor->en_family)
1277
      dw_out_dim (*(di->mor->en_family));
1278
    if (proc_dg_info && proc_dg_info->data.i_prc.barrier) {
1279
      dg_info b = proc_dg_info->data.i_prc.barrier;
1280
      IGNORE dw_entry (dwe_barrier, (long)0);
1281
      dw_at_decl (b->data.i_bar.pos);
1282
      dw_at_address (b->data.i_bar.lo_pc);
1283
      dw_at_address (b->data.i_bar.hi_pc);
1284
    }
1285
 
1286
    if (!doing_abstract && extra_diags && proc_dg_info) {
1287
      long atret1 = H_XY, atret2;
1288
      retrec * rets = proc_dg_info->data.i_prc.returns;
1289
      if (rets) {
1290
	atret1 |= H_PC;
1291
	if (res_t)
1292
	  atret1 |= H_LC;
1293
      }
1294
      do {
1295
	atret2 = dw_entry (dwe_return, atret1);
1296
	if (atret2 & ~(H_XY|H_PC|H_LC))
1297
	  fail_unimplemented ();
1298
	if (atret2 & H_XY)
1299
	  dw_at_decl (di->mor->end_pos);
1300
	if (atret2 & H_PC)
1301
	  dw_at_address (rets->lab);
1302
	if (atret2 & H_LC)
1303
	  dw2_locate_result (pt(son(id)));
1304
	if (!rets)
1305
	  break;
1306
	rets = rets->next;
1307
      }
1308
      while (rets);
1309
    }
1310
 
1311
    if (id && (proc_dg_info || doing_abstract)) {
1312
      output_info (son(id), (proc_dg_info ? dgf(son(id))->more : dgf(son(id))));
1313
    }
1314
 
1315
    dw_sibling_end ();
1316
    if (doing_abstract) {
1317
      doing_abstract = 0;
1318
      doing_inline = 1;
1319
      attr1 = H_AO;
1320
    }
1321
    else
1322
      break;
1323
  }
1324
  while (proc_dg_info);
1325
 
1326
  doing_abstract = old_ab;
1327
  doing_inline = old_il;
1328
  proc_dg_info = old_di;
1329
  return_type = old_res;
1330
  return;
1331
}
1332
 
1333
 
1334
void dw2_out_generic
1335
    PROTO_N ( (p) )
1336
    PROTO_T ( dg_name_list p )
1337
{
1338
  while (p) {
1339
    switch (p->key) {
1340
      case DGN_OBJECT: {
1341
	IGNORE dw_entry (dwe_tmpl_val, (long)0);
1342
	dw_at_string (idname_chars (p->idnam));
1343
	dw_at_decl (p->whence);
1344
	dw_at_ext_lab (dw2_find_type_label (p->data.n_obj.typ));
1345
	dw_out_const (son (p->data.n_obj.obtain_val));
1346
	break;
1347
      }
1348
      case DGN_TYPE: {
1349
	IGNORE dw_entry (dwe_tmpl_type, (long)0);
1350
	dw_at_string (idname_chars (p->idnam));
1351
	dw_at_decl (p->whence);
1352
	dw_at_ext_lab (dw2_find_type_label (p->data.n_typ.raw));
1353
	break;
1354
      }
1355
      case DGN_PROC: {
1356
	IGNORE dw_entry (dwe_tmpl_proc, (long)0);
1357
	dw_at_string (idname_chars (p->idnam));
1358
	dw_at_decl (p->whence);
1359
	dw_at_ext_address (p->mor->refspec);
1360
	break;
1361
      }
1362
      case DGN_MODULE: {
1363
	IGNORE dw_entry (dwe_tmpl_mod, (long)0);
1364
	dw_at_string (idname_chars (p->idnam));
1365
	dw_at_decl (p->whence);
1366
	dw_at_ext_address (p->mor->refspec);
1367
	break;
1368
      }
1369
      default:
1370
	break;
1371
    }
1372
    p = p->next;
1373
  }
1374
  return;
1375
}
1376
 
1377
 
1378
void dw2_out_name
1379
    PROTO_N ( (di, contex) )
1380
    PROTO_T ( dg_name di X dg_nm_contex contex )
1381
{
1382
				/* in debug_info section */
1383
  dg_tag inl_tag = (di->mor ? di->mor->inline_ref : (dg_tag)0);
1384
  if (di->mor && di->mor->this_tag && !di->mor->this_tag->outref.k) {
1385
    di->mor->this_tag->outref.k = LAB_D;
1386
    di->mor->this_tag->outref.u.l = next_dwarf_label ();
1387
  }
1388
 
1389
				/* EXCEPT_NAME, INSTANTN_NAME not done yet */
1390
  if ((contex == LOCAL_NAME || contex == DEAD_NAME) && !doing_abstract) {
1391
    if (!dw2_scope_start)
1392
      failer ("missing scope");
1393
  }
1394
 
1395
  switch (di->key) {
1396
 
1397
    case DGN_OBJECT: {
1398
      exp x = di->data.n_obj.obtain_val;
1399
      dg_type typ = di->data.n_obj.typ;
1400
      dg_param * ppar = (contex == PARAM_NAME ? di->data.n_obj.p : (dg_param *)0);
1401
      char* nam = idname_chars (di->idnam);
1402
      long attr1 = 0, attr2;
1403
      long loclab = 0, loclabext = 0, infolab = 0;
1404
      abbrev_entry dwe;
1405
      if ((inl_tag && !doing_inline && !doing_abstract) || (!inl_tag && doing_inline))
1406
	failer ("inline inconsistency");
1407
 
1408
      if (contex == GLOBAL_NAME && di->idnam.id_key == DG_ID_EXT &&
1409
		x && find_id (son(x))) {
1410
	infolab = next_dwarf_label ();
1411
	exit_section ();
1412
	enter_section ("debug_pubnames");
1413
	out32 (); out_dwf_labdiff (dw_info_start, infolab); d_outnl();
1414
	dw_at_string (nam);
1415
	exit_section ();
1416
	enter_section ("debug_info");
1417
      }
1418
 
1419
      if (contex == PARAM_NAME || contex == INL_PARAM_NAME)
1420
	dwe = dwe_param;
1421
      else
1422
      if (di->mor && di->mor->isconst)
1423
	dwe = dwe_constant;
1424
      else
1425
	dwe = dwe_variable;
1426
 
1427
      if (doing_inline)
1428
	attr1 |= H_AO;
1429
      else {
1430
	if (di->mor && di->mor->refspec)
1431
	  attr1 |= (H_SP | H_XY);
1432
	else {
1433
	  attr1 |= (H_NM | H_XY | H_TP);
1434
	  if (contex == GLOBAL_NAME)
1435
	    attr1 |= H_EX;
1436
	  if (di->idnam.id_key == DG_ID_ARTFL)
1437
	    attr1 |= H_AT;
1438
	}
1439
	if (di->mor && di->mor->isspec)
1440
	  attr1 |= H_DC;
1441
	if (di->mor && di->mor->acc)
1442
	  attr1 |= H_AC;
1443
	if (contex == PARAM_NAME) {
1444
	  attr1 |= H_VP;
1445
#ifdef H_DX
1446
	  if (ppar && ppar->p_dflt) {
1447
	    if (ppar->p_dflt->span.sp_key == SP_SPAN ||
1448
		(ppar->p_dflt->val && dw_is_const (son(ppar->p_dflt->val)) ))
1449
	      attr1 |= H_DF;
1450
	    else
1451
	      attr1 |= H_DX;
1452
	  }
1453
#else
1454
	  if (ppar && ppar->p_dflt)
1455
	    attr1 |= H_DF;
1456
#endif
1457
	}
1458
	if (di->mor && di->mor->repn)
1459
	  attr1 |= H_RP;
1460
      }
1461
      if (!doing_abstract && !(attr1 & H_DC)) {
1462
	if (!x)
1463
	  failer ("obtain_value missing");
1464
	if (contex == LOCAL_NAME || contex == DEAD_NAME)
1465
	  attr1 |= H_SS;
1466
	if (contex != DEAD_NAME && dw_is_const (son(x)))
1467
	  attr1 |= H_CV;
1468
	else {
1469
	  int ll = decide_ll_type (x);
1470
	  if (!ll && contex == PARAM_NAME)
1471
	    ll = 1;
1472
	  attr1 |= (ll ? H_LL : H_LC);
1473
	  if (ll > 1)
1474
	    attr1 |= H_LE;
1475
	}
1476
      }
1477
 
1478
      if (di->mor && di->mor->this_tag) {
1479
	if (doing_abstract)
1480
	  set_abstract_lab (di->mor->this_tag);
1481
	else
1482
	  set_ext_address (di->mor->this_tag);
1483
      }
1484
      if (infolab)
1485
	out_dwf_label (infolab, 1);
1486
      attr2 = dw_entry (dwe, attr1);
1487
      if (attr2 & ~(H_AO|H_SP|H_DC|H_NM|H_XY|H_EX|H_AT|H_AC|H_TP|H_VP|
1488
#ifdef H_DX
1489
		    H_SS|H_LC|H_LL|H_LE|H_CV|H_RP|H_DF|H_DX))
1490
#else
1491
		    H_SS|H_LC|H_LL|H_LE|H_CV|H_RP|H_DF))
1492
#endif
1493
	fail_unimplemented ();
1494
 
1495
      if (attr2 & H_AO)
1496
	dw_at_abstract_lab (inl_tag);
1497
      if (attr2 & H_SP)
1498
	dw_at_ext_address (di->mor->refspec);
1499
      if (attr2 & H_DC)
1500
	dw_at_flag ((di->mor && di->mor->isspec ? 1 : 0));
1501
      if (attr2 & H_NM)
1502
	dw_at_string (nam);
1503
      if (attr2 & H_XY)
1504
	dw_at_decl (di->whence);
1505
      if (attr2 & H_EX)
1506
	dw_at_flag ((infolab ? 1 : 0));
1507
      if (attr2 & H_AT)
1508
	dw_at_flag ((di->idnam.id_key == DG_ID_ARTFL ? 1 : 0));
1509
      if (attr2 & H_AC)
1510
	dw_at_data (1, (long)(di->mor ? di->mor->acc : 0));
1511
      if (attr2 & H_TP)
1512
	dw_at_ext_lab (dw2_find_type_label (typ));
1513
      if (attr2 & H_VP) {
1514
	int vp = 0;
1515
	if (ppar && (ppar->pmode == DG_OUT_MODE || ppar->pmode == DG_INOUT_MODE))
1516
	  vp = 1;
1517
	dw_at_flag (vp);
1518
      }
1519
#ifdef H_DX
1520
      if (attr2 & H_DX)
1521
	dw_at_flag ((ppar && ppar->p_dflt && !(attr2 & H_DF)) ? 1 : 0);
1522
#endif
1523
      if (attr2 & H_DF)
1524
	dw_out_default (ppar->p_dflt);
1525
      if (attr2 & H_SS)
1526
	dw_at_distance (dw2_scope_start, local_var_place);
1527
      if (attr2 & H_CV)
1528
	dw_out_const (son(x));
1529
      if (attr2 & H_LC) {
1530
	if (contex == DEAD_NAME)
1531
	  dw_no_locate ();
1532
	else
1533
	  dw2_locate_exp (son(x), 0, 0);
1534
      }
1535
      if (attr2 & H_LL)
1536
	dw_at_address (loclab = next_dwarf_label ());
1537
      if (attr2 & H_LE)
1538
	dw_at_address (loclabext = next_dwarf_label ());
1539
      if (attr2 & H_RP)
1540
	dw_out_const (son (di->mor->repn));
1541
 
1542
      if (loclab) {
1543
	long lstart, lend;
1544
#if 0
1545
	retrec * rets = proc_dg_info->data.i_prc.returns;
1546
	long rstart = proc_dg_info->data.i_prc.p->data.i_param.b_start, rend;
1547
#endif
1548
	exit_section ();
1549
	enter_section ("debug_loc");
1550
	out_dwf_label (loclab, 1);
1551
	if (contex == PARAM_NAME) {
1552
	  lstart = proc_dg_info->data.i_prc.prc_start;
1553
	  out_loc_range (lstart, lstart, 1);
1554
	  dw2_locate_exp (son(x), 0, 3);
1555
	  lstart = proc_dg_info->data.i_prc.p->data.i_param.b_start;
1556
	  lend = proc_dg_info->data.i_prc.prc_end;
1557
	}
1558
	else {
1559
	  lstart = dw2_scope_start;
1560
	  lend = dw2_scope_end;
1561
	}
1562
	out_obj_loclist (lstart, lend, x);
1563
#if 0
1564
	while (rets) {
1565
	  if (rets->over) {
1566
	    rend = rets->lab;
1567
	    if (rend != rstart) {
1568
	      out_loc_range (rstart, rend, 0);
1569
	      dw2_locate_exp (son(x), 0, 1);
1570
	    }
1571
	    rstart = rets->over;
1572
	  }
1573
	  rets = rets->next;
1574
	}
1575
	rend = proc_dg_info->data.i_prc.prc_end;
1576
	if (rend != rstart) {
1577
	  out_loc_range (rstart, rend, 0);
1578
	  dw2_locate_exp (son(x), 0, 1);
1579
	}
1580
#endif
1581
	out32(); outs("0, 0"); outnl_comment ("loclist end");
1582
	if (loclabext) {
1583
	  out_dwf_label (loclabext, 1);
1584
	  out_obj_extloclist (lstart, lend, x);
1585
	  out32(); outs("0, 0"); outnl_comment ("extension end");
1586
	}
1587
	out_obj_shared_set (di);
1588
	exit_section ();
1589
	enter_section ("debug_info");
1590
      }
1591
      break;
1592
    }
1593
 
1594
    case DGN_PROC: {
1595
      dw2_out_proc (di);
1596
      break;
1597
    }
1598
 
1599
    case DGN_MODULE:
1600
    case DGN_NSP: {
1601
      char* nam;
1602
      char* gnam = "";
1603
      long attr1 = 0, attr2;
1604
      abbrev_entry dwe;
1605
      int has_init_code = 0;
1606
      exp id = di->data.n_mod.init;
1607
      dg_instantn * generic = (dg_instantn *)0;
1608
      dg_name mem;
1609
      if (id && name(id) == hold_tag && name(son(id)) == name_tag) {
1610
	id = son(son(id));
1611
	if (son(id) && (name(son(id)) == apply_tag ||
1612
			name(son(id)) == apply_general_tag)) {
1613
	  dw2_prepare_locate (id);
1614
	  if (dgf(son(id)))
1615
	    has_init_code = 1;
1616
	}
1617
      }
1618
      if (di->key == DGN_MODULE)
1619
	dwe = dwe_module;
1620
      else
1621
	dwe = dwe_namespace;
1622
      if (di->idnam.id_key == DG_ID_INST) {
1623
	generic = di->idnam.idd.instance;
1624
	if (generic->nam.id_key == DG_ID_ANON)
1625
	  nam = generic->spec.idd.nam;
1626
	else {
1627
	  nam = generic->nam.idd.nam;
1628
	  gnam = generic->spec.idd.nam;
1629
        }
1630
      }
1631
      else
1632
	nam = di->idnam.idd.nam;
1633
      if (doing_inline)
1634
	attr1 |= H_AO;
1635
      else {
1636
	if (di->mor && di->mor->refspec)
1637
	  attr1 = H_SP | H_XY;
1638
	else {
1639
	  attr1 = H_NM | H_XY;
1640
	  switch (di->idnam.id_key) {
1641
	    case DG_ID_ARTFL:
1642
	      attr1 |= H_AT;
1643
	      break;
1644
	    case DG_ID_INST:
1645
	      if (gnam[0])
1646
	        attr1 |= H_GN;
1647
	      break;
1648
	    default:
1649
	      break;
1650
	  }
1651
        }
1652
	if (di->mor && di->mor->isspec)
1653
	  attr1 |= H_DC;
1654
	if (di->mor && di->mor->issep)
1655
	  attr1 |= H_SE;
1656
      }
1657
      if (!doing_abstract) {
1658
	if (has_init_code)
1659
	  attr1 |= H_PC;
1660
	if (di->mor && di->mor->elabn)
1661
	  attr1 |= H_EL;
1662
      }
1663
 
1664
      if (di->mor && di->mor->this_tag) {
1665
	if (doing_abstract)
1666
	  set_abstract_lab (di->mor->this_tag);
1667
	else
1668
	  set_ext_address (di->mor->this_tag);
1669
      }
1670
      attr2 = dw_entry (dwe, attr1);
1671
      if (attr2 & ~(H_AO|H_SP|H_DC|H_NM|H_XY|H_AT|H_AC|H_PC|H_EXTN))
1672
	fail_unimplemented ();
1673
 
1674
      if (attr2 & H_AO)
1675
	dw_at_abstract_lab (inl_tag);
1676
      if (attr2 & H_SP)
1677
	dw_at_ext_address (di->mor->refspec);
1678
      if (attr2 & H_DC)
1679
	dw_at_flag ((di->mor && di->mor->isspec ? 1 : 0));
1680
      if (attr2 & H_NM)
1681
	dw_at_string (nam);
1682
      if (attr2 & H_XY)
1683
	dw_at_decl (di->whence);
1684
      if (attr2 & H_AT)
1685
	dw_at_flag ((di->idnam.id_key == DG_ID_ARTFL ? 1 : 0));
1686
      if (attr2 & H_AC)
1687
	dw_at_data (1, (long)(di->mor ? di->mor->acc : 0));
1688
      if (attr2 & H_PC) {
1689
	dg_info pd = dgf(son(id));
1690
	if (pd->key != DGA_PRC)
1691
	  failer ("inconsistent proc info");
1692
	dw_at_address (pd->data.i_prc.prc_start);
1693
	dw_at_address (pd->data.i_prc.prc_end);
1694
      }
1695
      if (attr2 & H_EXTN) {
1696
	long block_end = next_dwarf_label ();
1697
	attr1 &= ~attr2;
1698
	if (attr1 & ~(H_EL|H_GN|H_SE))
1699
	  fail_unimplemented ();
1700
	out16 (); out_dwf_dist_to_label (block_end); d_outnl();
1701
	if (attr1 & H_EL) {
1702
	  set_attribute (DW_AT_DD_elaboration, DW_FORM_ref_addr);
1703
	  dw_at_ext_address (di->mor->elabn);
1704
	}
1705
	if (attr1 & H_GN) {
1706
	  set_attribute (DW_AT_DD_generic_name, DW_FORM_string);
1707
	  dw_at_string (gnam);
1708
	}
1709
	if (attr1 & H_SE) {
1710
	  set_attribute (DW_AT_DD_separate, DW_FORM_flag);
1711
	  dw_at_flag ((di->mor && di->mor->issep ? 1 : 0));
1712
	}
1713
	set_attribute (0, 0);
1714
	out_dwf_label (block_end, 1);
1715
      }
1716
 
1717
      if (!doing_abstract && generic)
1718
	dw2_out_generic (generic->params);
1719
      mem = di->data.n_mod.members;
1720
      while (mem) {
1721
	dw2_out_name (mem, contex);
1722
	mem = mem->next;
1723
      }
1724
      dw_sibling_end ();
1725
      break;
1726
    }
1727
 
1728
    case DGN_SUBUNIT: {
1729
      abbrev_entry dwe;
1730
      if (di->data.n_sub.child)
1731
        dwe = (di->data.n_sub.acc ? dwe_child_acc : dwe_childunit);
1732
      else
1733
	dwe = dwe_subunit;
1734
      dw_at_ext_address (di->data.n_sub.parent);
1735
      if (di->data.n_sub.child) {
1736
	if (di->data.n_sub.acc)
1737
	  dw_at_data (1, (long)(di->data.n_sub.acc));
1738
      }
1739
      else
1740
	dw_at_flag (di->data.n_sub.split);
1741
      dw2_out_name (di->data.n_sub.sub, contex);
1742
      dw_sibling_end ();
1743
      break;
1744
    }
1745
 
1746
    case DGN_IMPORT: {
1747
      long attr1 = 0, attr2;
1748
      char * nam = idname_chars (di->idnam);
1749
      dg_type p_t = di->data.n_imp.i_typ;
1750
      int params = (p_t && p_t->key == DGT_PROC);
1751
      if (nam[0])
1752
	attr1 |= H_NM;
1753
      if (di->whence.file)
1754
	attr1 |= H_XY;
1755
      if (di->mor && di->mor->acc)
1756
	attr1 |= H_AC;
1757
      if (contex == LOCAL_NAME && !doing_abstract)
1758
	attr1 |= H_SS;
1759
      attr2 = dw_entry ((params ? dwe_import_p : dwe_import), attr1);
1760
      if (attr2 & ~(H_NM|H_XY|H_AC|H_SS))
1761
	fail_unimplemented ();
1762
      if (attr2 & H_NM)
1763
	dw_at_string (nam);
1764
      if (attr2 & H_XY)
1765
	dw_at_decl (di->whence);
1766
      if (attr2 & H_AC)
1767
	dw_at_data (1, (long)(di->mor ? di->mor->acc : 0));
1768
      dw_at_ext_address (di->data.n_imp.import);
1769
      dw_at_udata ((unsigned long)(di->data.n_imp.ik));
1770
      if (attr2 & H_SS)
1771
	dw_at_distance (dw2_scope_start, local_var_place);
1772
 
1773
      if (params) {
1774
	dg_param * el = p_t->data.t_proc.params.array;
1775
	int i;
1776
	for (i = 0; i < p_t->data.t_proc.params.len; i++)
1777
	  out_param (el[i]);
1778
	if (p_t->data.t_proc.prps & f_var_callers)
1779
	  IGNORE dw_entry (dwe_opt_par, (long)0);
1780
	dw_sibling_end ();
1781
      }
1782
      break;
1783
    }
1784
 
1785
    case DGN_TYPE: {
1786
      long attr1 = 0, attr2;
1787
      int ada_derived = 0;
1788
      char * nam = idname_chars (di->idnam);
1789
      if (doing_inline && inl_tag)
1790
	attr1 |= H_AO;
1791
      else {
1792
	if (di->mor && di->mor->refspec)
1793
	  attr1 = H_SP;
1794
	if (di->mor && di->mor->isspec)
1795
	  attr1 |= H_DC;
1796
	if (nam[0])
1797
	  attr1 |= H_NM;
1798
	if (di->whence.file)
1799
	  attr1 |= H_XY;
1800
	if (di->idnam.id_key == DG_ID_ARTFL)
1801
	  attr1 |= H_AT;
1802
	if (di->mor && di->mor->acc)
1803
	  attr1 |= H_AC;
1804
	if (di->data.n_typ.raw)
1805
	  attr1 |= H_TP;
1806
	if (di->mor && di->mor->isnew)
1807
	  attr1 |= H_NW;
1808
	if (di->mor && di->mor->aderiv) {
1809
	  attr1 |= H_AD;
1810
	  ada_derived = 1;
1811
	}
1812
      }
1813
      if ((attr1 == H_TP || (!nam[0] && !(di->mor && di->mor->this_tag))) &&
1814
		!(di->data.n_typ.raw->outref.u.l) &&
1815
		!di->data.n_typ.constraints) {
1816
	if (di->mor && di->mor->this_tag)
1817
	  di->data.n_typ.raw->outref = di->mor->this_tag->outref;
1818
	else {
1819
	  di->data.n_typ.raw->outref.u.l = next_dwarf_label();
1820
	  di->data.n_typ.raw->outref.k = LAB_D;
1821
	}
1822
	dw_out_type (di->data.n_typ.raw);
1823
      }
1824
      else {
1825
	if (di->mor && di->mor->this_tag) {
1826
	  if (doing_abstract)
1827
	    set_abstract_lab (di->mor->this_tag);
1828
	  else
1829
	  if (!(di->mor->this_tag->done)) {
1830
	    set_ext_address (di->mor->this_tag);
1831
	    di->mor->this_tag->done = 1;
1832
	  }
1833
	}
1834
	attr2 = dw_entry ((di->data.n_typ.constraints ? dwe_typecon :
1835
			dwe_typedef), attr1);
1836
	if (attr2 & ~(H_AO|H_SP|H_DC|H_NM|H_XY|H_AT|H_AC|H_TP|H_NW|H_AD))
1837
	  fail_unimplemented ();
1838
 
1839
	if (attr2 & H_AO)
1840
	  dw_at_abstract_lab (inl_tag);
1841
	if (attr2 & H_SP)
1842
	  dw_at_ext_address (di->mor->refspec);
1843
	if (attr2 & H_DC)
1844
	  dw_at_flag ((di->mor && di->mor->isspec ? 1 : 0));
1845
	if (attr2 & H_NM)
1846
	  dw_at_string (nam);
1847
	if (attr2 & H_XY)
1848
	  dw_at_decl (di->whence);
1849
	if (attr2 & H_AT)
1850
	  dw_at_flag ((di->idnam.id_key == DG_ID_ARTFL ? 1 : 0));
1851
	if (attr2 & H_AC)
1852
	  dw_at_data (1, (long)(di->mor ? di->mor->acc : 0));
1853
	if (attr2 & H_TP)
1854
	  dw_at_ext_lab (dw2_find_type_label (di->data.n_typ.raw));
1855
	if (attr2 & H_NW)
1856
	  dw_at_flag ((di->mor && di->mor->isnew ? 1 : ada_derived));
1857
	if (attr2 & H_AD)
1858
	  dw_at_flag (ada_derived);
1859
      }
1860
      if (di->data.n_typ.constraints) {
1861
	dg_constraint c = di->data.n_typ.constraints;
1862
	while (c) {
1863
	  attr1 = (c->is_val ? H_CV : H_TP);
1864
	  if (c->refmem)
1865
	    attr1 |= H_RM;
1866
	  attr2 = dw_entry (dwe_cnstraint, attr1);
1867
	  if (attr2 & ~(H_RM|H_CV|H_TP))
1868
	    fail_unimplemented ();
1869
	  if (attr2 & H_RM)
1870
	    dw_at_ext_address (c->refmem);
1871
	  if (attr2 & H_CV)
1872
	    dw_out_const (son(c->u.val));
1873
	  if (attr2 & H_TP)
1874
	    dw_at_ext_lab (dw2_find_type_label (c->u.typ));
1875
	  c = c->next;
1876
	}
1877
	dw_sibling_end ();
1878
      }
1879
      break;
1880
    }
1881
 
1882
    case DGN_ENTRY: {
1883
      long attr1 = 0, attr2;
1884
      char * nam = idname_chars (di->idnam);
1885
      dg_type p_t = find_proc_type (di->data.n_proc.typ);
1886
      dg_type res_t = p_t->data.t_proc.res_type;
1887
      dg_param * el = p_t->data.t_proc.params.array;
1888
      int i;
1889
 
1890
      attr1 = H_NM | H_XY;
1891
      if (di->mor && di->mor->acc)
1892
	attr1 |= H_AC;
1893
      if (res_t)
1894
	attr1 |= H_TP;
1895
      if (di->mor && di->mor->repn)
1896
	attr1 |= H_RP;
1897
      if (di->mor && di->mor->this_tag)
1898
	set_ext_address (di->mor->this_tag);
1899
      attr2 = dw_entry (dwe_entry, attr1);
1900
      if (attr2 & ~(H_NM|H_XY|H_AC|H_TP|H_RP))
1901
	fail_unimplemented ();
1902
      if (attr2 & H_NM)
1903
	dw_at_string (nam);
1904
      if (attr2 & H_XY)
1905
	dw_at_decl (di->whence);
1906
      if (attr2 & H_AC)
1907
	dw_at_data (1, (long)(di->mor ? di->mor->acc : 0));
1908
      if (attr2 & H_TP)
1909
	dw_at_ext_lab (dw2_find_type_label (res_t));
1910
      if (attr2 & H_RP) {
1911
	dw_out_const (son (di->mor->repn));
1912
      }
1913
 
1914
      for (i = 0; i < p_t->data.t_proc.params.len; i++)
1915
	out_param (el[i]);
1916
      if (di->mor && di->mor->en_family)
1917
	dw_out_dim (*(di->mor->en_family));
1918
      dw_sibling_end ();
1919
      break;
1920
    }
1921
 
1922
    default:
1923
      failer ("unexpected dg_name");
1924
  }
1925
  if (di->mor && di->mor->this_tag)
1926
    di->mor->this_tag->done = 1;
1927
  return;
1928
}
1929
 
1930
 
1931
static retrec ** returns_list;
1932
 
1933
 
1934
void dw2_proc_start
1935
    PROTO_N ( (p, d) )
1936
    PROTO_T ( exp p X dg_name d )
1937
{
1938
  if (dgf(p))
1939
    failer ("unexpected diag info for proc");
1940
  proc_dg_info = dgf(p) = new_dg_info (DGA_PRC);
1941
  proc_dg_info->data.i_prc.prc_start = set_dw_text_label ();
1942
  proc_dg_info->data.i_prc.prc_end = 0;
1943
  proc_dg_info->data.i_prc.returns = (retrec *)0;
1944
  returns_list = &(proc_dg_info->data.i_prc.returns);
1945
  proc_dg_info->data.i_prc.p = proc_dg_info->data.i_prc.barrier = (dg_info)0;
1946
  if (d)
1947
    dw2_source_mark (d->whence, 0);
1948
  return;
1949
}
1950
 
1951
 
1952
void dw2_return_pos
1953
    PROTO_N ( (over) )
1954
    PROTO_T ( long over )
1955
{
1956
  retrec * rec = (retrec *) xmalloc (sizeof (retrec));
1957
  rec->lab = set_dw_text_label ();
1958
  rec->over = over;
1959
  rec->next = (retrec *)0;
1960
  *returns_list = rec;
1961
  returns_list = &(rec->next);
1962
  if (over)
1963
    set_obj_rets (rec);
1964
  return;
1965
}
1966
 
1967
 
1968
void dw2_proc_end
1969
    PROTO_N ( (p) )
1970
    PROTO_T ( exp p )
1971
{
1972
  dgf(p)->data.i_prc.prc_end = set_dw_text_label ();
1973
  proc_dg_info = (dg_info)0;
1974
  return;
1975
}
1976
 
1977
 
1978
static void prepare_detch
1979
    PROTO_N ( (dl) )
1980
    PROTO_T ( detch_info * dl )
1981
{
1982
  while (dl) {
1983
    int reason = dl->why;
1984
    dg_info d = dl->info;
1985
    dg_tag found_tg;
1986
    if (reason >= DGD_MOVD) {
1987
      found_tg = dl->tg;
1988
      while (found_tg->copy)
1989
	found_tg = found_tg->copy;
1990
      d = found_tg->p.info;
1991
      reason = d->data.i_movd.reason;
1992
      d = d->more;
1993
    }
1994
    if (reason < DGD_MOVD) {
1995
      switch (d->key) {
1996
	case DGA_NAME: {
1997
	  d->data.i_nam.scope_start = set_dw_text_label ();
1998
	  break;
1999
	}
2000
	case DGA_SCOPE: {
2001
	  d->data.i_scope.start = set_dw_text_label ();
2002
	  d->data.i_scope.end = set_dw_text_label ();
2003
	  break;
2004
	}
2005
	case DGA_REMVAL: {
2006
	  d->data.i_remval.lo_pc = set_dw_text_label ();
2007
	  set_remval_object (d);
2008
	  break;
2009
	}
2010
	default:
2011
	  break;
2012
      }
2013
    }
2014
    if (dl->sub)
2015
      prepare_detch (dl->sub);
2016
    dl = dl->next;
2017
  }
2018
  return;
2019
}
2020
 
2021
 
2022
void dw2_code_info
2023
    PROTO_N ( (d, mcode, args) )
2024
    PROTO_T ( dg_info d X void (*mcode) PROTO_S((void *)) X void * args )
2025
{
2026
  if (d == nildiag) {
2027
    (*mcode)(args);
2028
    return;
2029
  }
2030
  switch (d->key) {
2031
 
2032
    case DGA_PARAMS: {
2033
      obj_list hold_pars;
2034
      hold_pars.obj = d->data.i_param.args;
2035
      hold_pars.islist = 1;
2036
      hold_pars.next = (obj_list *)0;
2037
      local_objects = &hold_pars;
2038
      set_locdata (hold_pars);
2039
      if (proc_dg_info)
2040
	proc_dg_info->data.i_prc.p = d;
2041
      d->data.i_param.b_start = set_dw_text_label ();
2042
      dw2_code_info (d->more, mcode, args);
2043
      close_locdata (hold_pars);
2044
      local_objects = (obj_list *)0;
2045
      break;
2046
    }
2047
 
2048
    case DGA_COMP: {
2049
      dw2_code_info (d->more, mcode, args);
2050
      break;
2051
    }
2052
 
2053
    case DGA_SRC: {
2054
      if (d->data.i_src.startpos.file)
2055
	dw2_source_mark (d->data.i_src.startpos, d->data.i_src.is_stmt);
2056
      dw2_code_info (d->more, mcode, args);
2057
      if (d->data.i_src.endpos.file)
2058
	dw2_source_mark (d->data.i_src.endpos, 0);
2059
      break;
2060
    }
2061
 
2062
    case DGA_SCOPE:
2063
    case DGA_EXTRA: {
2064
      d->data.i_scope.start = set_dw_text_label ();
2065
      dw2_code_info (d->more, mcode, args);
2066
      d->data.i_scope.end = set_dw_text_label ();
2067
      break;
2068
    }
2069
 
2070
    case DGA_LAB: {
2071
      d->data.i_scope.start = set_dw_text_label ();
2072
      dw2_code_info (d->more, mcode, args);
2073
      break;
2074
    }
2075
 
2076
    case DGA_NAME: {
2077
      obj_list hold_obj;
2078
      hold_obj.obj = d->data.i_nam.dnam;
2079
      hold_obj.islist = 0;
2080
      hold_obj.next = local_objects;
2081
      local_objects = &hold_obj;
2082
      set_locdata (hold_obj);
2083
      d->data.i_nam.scope_start = set_dw_text_label ();
2084
      dw2_code_info (d->more, mcode, args);
2085
      close_locdata (hold_obj);
2086
      local_objects = hold_obj.next;
2087
      break;
2088
    }
2089
 
2090
    case DGA_WITH: {
2091
      d->data.i_with.lo_pc = set_dw_text_label ();
2092
      dw2_code_info (d->more, mcode, args);
2093
      d->data.i_with.hi_pc = set_dw_text_label ();
2094
      break;
2095
    }
2096
 
2097
    case DGA_CALL: {
2098
      dg_info old = current_dg_info;
2099
      current_dg_info = d;
2100
      dw2_code_info (d->more, mcode, args);
2101
      current_dg_info = old;
2102
      break;
2103
    }
2104
 
2105
    case DGA_INL_CALL: {
2106
      obj_list hold_pars;
2107
      hold_pars.obj = d->data.i_inl.args;
2108
      hold_pars.islist = 1;
2109
      hold_pars.next = local_objects;
2110
      local_objects = &hold_pars;
2111
      set_locdata (hold_pars);
2112
      d->data.i_inl.lo_pc = set_dw_text_label ();
2113
      dw2_code_info (d->more, mcode, args);
2114
      d->data.i_inl.hi_pc = set_dw_text_label ();
2115
      close_locdata (hold_pars);
2116
      local_objects = hold_pars.next;
2117
      break;
2118
    }
2119
 
2120
    case DGA_INL_RES: {
2121
      dw2_code_info (d->more, mcode, args);
2122
      d->data.i_res.brk = set_dw_text_label ();
2123
      d->data.i_res.res = find_diag_res (args);
2124
      {
2125
	dg_tag cr = d->data.i_res.call;
2126
	dg_info * dl;
2127
	if (cr->key != DGK_INFO || cr->p.info->key != DGA_INL_CALL)
2128
	  failer ("inline result ref?");
2129
	dl = &(cr->p.info->data.i_inl.resref);
2130
	while (*dl) {
2131
	  if ((*dl)==d) {
2132
	    failer ("impossible cycle");
2133
	    return;
2134
	  }
2135
	  dl = &((*dl)->data.i_res.next);
2136
	}
2137
	*dl = d;
2138
      }
2139
      break;
2140
    }
2141
 
2142
    case DGA_X_TRY: {
2143
      d->data.i_try.lo_pc = set_dw_text_label ();
2144
      dw2_code_info (d->more, mcode, args);
2145
      d->data.i_try.hi_pc = set_dw_text_label ();
2146
      break;
2147
    }
2148
 
2149
    case DGA_X_CATCH: {
2150
      obj_list hold_obj;
2151
      hold_obj.obj = d->data.i_catch.ex;
2152
      hold_obj.islist = 0;
2153
      hold_obj.next = local_objects;
2154
      local_objects = &hold_obj;
2155
      set_locdata (hold_obj);
2156
      d->data.i_catch.lo_pc = set_dw_text_label ();
2157
      dw2_code_info (d->more, mcode, args);
2158
      d->data.i_catch.hi_pc = set_dw_text_label ();
2159
      close_locdata (hold_obj);
2160
      local_objects = hold_obj.next;
2161
      break;
2162
    }
2163
 
2164
    case DGA_X_RAISE: {
2165
      dw2_code_info (d->more, mcode, args);
2166
      break;
2167
    }
2168
 
2169
    case DGA_BRANCH: {
2170
      int old_db = dw_doing_branch_tests;
2171
      dw_doing_branch_tests = 1;
2172
      d->data.i_brn.brk = set_dw_text_label ();
2173
      dw2_code_info (d->more, mcode, args);
2174
      d->data.i_brn.cont = set_dw_text_label ();
2175
      dw_doing_branch_tests = old_db;
2176
      break;
2177
    }
2178
 
2179
    case DGA_TEST:
2180
    case DGA_JUMP:
2181
    case DGA_LJ: {
2182
      dg_info old = current_dg_info;
2183
      current_dg_info = d;
2184
      dw2_code_info (d->more, mcode, args);
2185
      current_dg_info = old;
2186
      break;
2187
    }
2188
 
2189
    case DGA_BEG: {
2190
      dg_tag tg = d->data.i_tg;
2191
      if (tg->key != DGK_INFO || tg->p.info->key != DGA_SCOPE)
2192
	failer ("statement_part_dg?");
2193
      tg->p.info->data.i_scope.begin_st = set_dw_text_label ();
2194
      dw2_code_info (d->more, mcode, args);
2195
      break;
2196
    }
2197
 
2198
    case DGA_DEST: {
2199
      d->data.i_dest.brk = set_dw_text_label ();
2200
      dw2_code_info (d->more, mcode, args);
2201
      break;
2202
    }
2203
 
2204
    case DGA_RVS: {
2205
      obj_list hold_pars;
2206
      hold_pars.next = local_objects;
2207
      if (d->data.i_rvs.rvs_key == DGR_ACC && d->data.i_rvs.n_code) {
2208
	hold_pars.obj = d->data.i_rvs.u2.p;
2209
	hold_pars.islist = 1;
2210
	local_objects = &hold_pars;
2211
	set_locdata (hold_pars);
2212
      }
2213
      if (d->data.i_rvs.n_code)
2214
	d->data.i_rvs.lo_pc = set_dw_text_label ();
2215
      if (d->data.i_rvs.u.tg) {
2216
	dg_info h;
2217
	if (d->data.i_rvs.u.tg->key != DGK_INFO || (
2218
		h = d->data.i_rvs.u.tg->p.info, h->key != DGA_RVS))
2219
	  failer ("incompatible rendezvous sequence");
2220
	d->data.i_rvs.u.iv = h->data.i_rvs.u.iv;
2221
	h->data.i_rvs.u.iv = d;
2222
	h->data.i_rvs.holder = 1;
2223
	d->data.i_rvs.info_e = current_dg_exp;
2224
	d->data.i_rvs.has_iv = 1;
2225
      }
2226
      dw2_code_info (d->more, mcode, args);
2227
      if ((unsigned int)d->data.i_rvs.n_code >= 2)
2228
	d->data.i_rvs.hi_pc = set_dw_text_label ();
2229
      if (d->data.i_rvs.rvs_key == DGR_ACC && d->data.i_rvs.n_code)
2230
	close_locdata (hold_pars);
2231
      local_objects = hold_pars.next;
2232
      break;
2233
    }
2234
 
2235
    case DGA_BAR: {
2236
      d->data.i_bar.lo_pc = set_dw_text_label ();
2237
      if (proc_dg_info) {
2238
	proc_dg_info->data.i_prc.barrier = d;
2239
      }
2240
      dw2_code_info (d->more, mcode, args);
2241
      d->data.i_bar.hi_pc = set_dw_text_label ();
2242
      break;
2243
    }
2244
 
2245
    case DGA_DETCH: {
2246
      if (d->data.i_detch.posn < 0) {
2247
	prepare_detch (d->data.i_detch.dl);
2248
	dw2_code_info (d->more, mcode, args);
2249
      }
2250
      else {
2251
	dw2_code_info (d->more, mcode, args);
2252
	prepare_detch (d->data.i_detch.dl);
2253
      }
2254
      break;
2255
    }
2256
 
2257
    case DGA_MOVD:
2258
    case DGA_HOIST: {
2259
      d->data.i_movd.lo_pc = set_dw_text_label ();
2260
      dw2_code_info (d->more, mcode, args);
2261
      d->data.i_movd.hi_pc = set_dw_text_label ();
2262
      break;
2263
    }
2264
 
2265
    case DGA_OPTIM: {
2266
      d->data.i_optim.lo_pc = set_dw_text_label ();
2267
      set_optim_objects (d, 1);
2268
      dw2_code_info (d->more, mcode, args);
2269
      d->data.i_optim.hi_pc = set_dw_text_label ();
2270
      set_optim_objects (d, 0);
2271
      break;
2272
    }
2273
 
2274
 
2275
    default:
2276
      failer ("unexpected dg_info");
2277
 
2278
  };
2279
  return;
2280
}