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/11 11:03:48 $
34
$Revision: 1.4 $
35
$Log: dw2_types.c,v $
36
 * Revision 1.4  1998/03/11  11:03:48  pwe
37
 * DWARF optimisation info
38
 *
39
 * Revision 1.3  1998/02/11  16:56:40  pwe
40
 * corrections
41
 *
42
 * Revision 1.2  1998/01/21  10:30:09  pwe
43
 * labdiff change
44
 *
45
 * Revision 1.1.1.1  1998/01/17  15:55:48  release
46
 * First version to be checked into rolling release.
47
 *
48
 * Revision 1.11  1998/01/09  09:31:36  pwe
49
 * prep restructure
50
 *
51
 * Revision 1.10  1997/12/08  19:20:28  pwe
52
 * absent v anon generic name
53
 *
54
 * Revision 1.9  1997/12/04  19:41:44  pwe
55
 * ANDF-DE V1.9
56
 *
57
 * Revision 1.8  1997/11/06  09:22:24  pwe
58
 * ANDF-DE V1.8
59
 *
60
 * Revision 1.7  1997/10/23  09:27:51  pwe
61
 * ANDF-DE v1.7, extra diags
62
 *
63
 * Revision 1.6  1997/10/10  18:18:45  pwe
64
 * prep ANDF-DE revision
65
 *
66
 * Revision 1.5  1997/08/23  13:36:56  pwe
67
 * initial ANDF-DE
68
 *
69
 * Revision 1.4  1997/06/16  16:23:57  pwe
70
 * correct sense of bitfield alignment
71
 *
72
 * Revision 1.3  1997/04/17  11:50:35  pwe
73
 * Sparc and 80x86 support
74
 *
75
 * Revision 1.2  1997/03/24  11:10:30  pwe
76
 * struct bitfields
77
 *
78
 * Revision 1.1  1997/03/20  16:09:30  pwe
79
 * first version
80
 *
81
**********************************************************************/
82
 
83
#include "config.h"
84
#include "common_types.h"
85
#include "dw2_config.h"
86
#include "dw2_types.h"
87
#include "dw2_codes.h"
88
#include "dw2_entries.h"
89
#include "dw2_basic.h"
90
#include "dw2_info.h"
91
#include "shapemacs.h"
92
#include "xalloc.h"
93
#include "diag_fns.h"
94
#include "expmacs.h"
95
#include "exp.h"
96
#include "check.h"
97
#include "externs.h"
98
#include "basicread.h"
99
#include "szs_als.h"
100
#include "tags.h"
101
 
102
 
103
static void fail_unimplemented
104
    PROTO_N ( (a1, a2) )
105
    PROTO_T ( long a1 X long a2 )
106
{
107
  IGNORE fprintf (stderr, "%lx  %lx\n", a1, a2);
108
  failer ("unimplemented attribute");
109
  return;
110
}
111
 
112
static dg_type needed_types = (dg_type)0;
113
 
114
static char * sep =  ", ";
115
 
116
 
117
ext_lab dw2_find_type_label
118
    PROTO_N ( (t) )
119
    PROTO_T ( dg_type t )
120
{
121
  if (!(t->outref.u.l)) {
122
    if (t->key == DGT_TAGGED) {
123
      dg_tag tg = t->data.t_tag;
124
      if (tg->done || tg->needed || tg->key == DGK_NONE) {
125
	t->outref = tg->outref;
126
	return t->outref;
127
      }
128
      if (tg->key == DGK_TYPE) {
129
	dg_type ref_t = tg->p.typ;
130
	t->outref = dw2_find_type_label (ref_t);
131
	tg->outref = t->outref;
132
	tg->done = 1;
133
	return t->outref;
134
      }
135
      if (tg->key == DGK_NAME) {
136
	dg_name ref_n = tg->p.nam;
137
	if (ref_n->key == DGN_TYPE && ref_n->idnam.id_key == DG_ID_NONE) {
138
	  dg_type ref_t = tg->p.nam->data.n_typ.raw;
139
	  t->outref = dw2_find_type_label (ref_t);
140
	  tg->outref = t->outref;
141
	  tg->done = 1;
142
	  return t->outref;
143
	}
144
      }
145
      tg->needed = 1;
146
      t->outref.u.l = tg->outref.u.l = next_dwarf_label();
147
      t->outref.k = tg->outref.k = LAB_D;
148
    }
149
    else {
150
      t->outref.u.l = next_dwarf_label();
151
      t->outref.k = LAB_D;
152
    }
153
    t->type_queue = needed_types;
154
    needed_types = t;
155
  }
156
  return t->outref;
157
}
158
 
159
 
160
static void out_classmem
161
    PROTO_N ( (m) )
162
    PROTO_T ( dg_classmem m )
163
{
164
  /* within info section */
165
  if (m.tg)
166
    set_ext_address (m.tg);
167
  switch (m.cm_key) {
168
    case DG_CM_FIELD: {
169
      dg_type f = m.d.cm_f.f_typ;
170
      exp off = son (m.d.cm_f.f_offset);
171
      dg_type base = f;
172
      int base_sz = 1;
173
      long attr1 = H_TP, attr2;
174
      if (m.d.cm_f.fnam[0])
175
	attr1 |= H_NM;
176
      if (m.d.cm_f.f_pos.file)
177
	attr1 |= H_XY;
178
      if (name(off) == val_tag)
179
	attr1 |= H_LC;
180
      if (f->key == DGT_BITF) {
181
	attr1 |= H_BF;
182
	base = f->data.t_bitf.expanded;
183
	base_sz = shape_size (f->data.t_bitf.sha);
184
      }
185
      if (m.d.cm_f.acc)
186
	attr1 |= H_AC;
187
      if (m.d.cm_f.discr)
188
	attr1 |= H_DS;
189
#ifdef H_DX
190
      if (m.d.cm_f.dflt) {
191
	if (m.d.cm_f.dflt->span.sp_key == SP_SPAN ||
192
	      (m.d.cm_f.dflt->val && dw_is_const (son(m.d.cm_f.dflt->val)) ))
193
	  attr1 |= H_DF;
194
	else
195
	  attr1 |= H_DX;
196
      }
197
#else
198
      if (m.d.cm_f.dflt)
199
	attr1 |= H_DF;
200
#endif
201
 
202
      attr2 = dw_entry (dwe_member, attr1);
203
#ifdef H_DX
204
      if (attr2 & ~(H_NM|H_XY|H_AC|H_TP|H_LC|H_BF|H_DS|H_DF|H_DX))
205
#else
206
      if (attr2 & ~(H_NM|H_XY|H_AC|H_TP|H_LC|H_BF|H_DS|H_DF))
207
#endif
208
	fail_unimplemented (attr1, attr2);
209
      if (attr2 & H_NM)
210
	dw_at_string (m.d.cm_f.fnam);
211
      if (attr2 & H_XY)
212
	dw_at_decl (m.d.cm_f.f_pos);
213
      if (attr2 & H_AC)
214
	dw_at_data (1, (long)m.d.cm_f.acc);
215
      if (attr2 & H_TP)
216
	dw_at_ext_lab (dw2_find_type_label (base));
217
      if (attr2 & H_LC)
218
	dw_locate_offset (((no (off)) & -base_sz) >> 3);
219
      if (attr2 & H_BF) {
220
#if !little_end
221
	dw_at_data (1, (long)(no (off) & (base_sz - 1)));
222
#else
223
	dw_at_data (1, (long)(base_sz - f->data.t_bitf.bv.bits
224
				- (no (off) & (base_sz - 1))));
225
#endif
226
	dw_at_data (1, (long)f->data.t_bitf.bv.bits);
227
      }
228
      if (attr2 & H_DS)
229
	dw_at_flag (m.d.cm_f.discr);
230
#ifdef H_DX
231
      if (attr2 & H_DX)
232
	dw_at_flag ((m.d.cm_f.dflt && !(attr2 & H_DF)) ? 1 : 0);
233
#endif
234
      if (attr2 & H_DF)
235
	dw_out_default (m.d.cm_f.dflt);
236
      break;
237
    }
238
    case DG_CM_FN: {
239
      dw2_out_name (m.d.cm_fn.fn, MEMBER_NAME);
240
      break;
241
    }
242
    case DG_CM_INDIRECT: {
243
      long attr1 = (H_TP | H_LC), attr2;
244
      if (m.d.cm_ind.nam[0])
245
	attr1 |= H_NM;
246
      if (m.d.cm_ind.pos.file)
247
	attr1 |= H_XY;
248
      attr2 = dw_entry (dwe_ind_mem, attr1);
249
      if (attr2 & ~(H_NM|H_XY|H_TP|H_LC))
250
	fail_unimplemented (attr1, attr2);
251
      if (attr2 & H_NM)
252
	dw_at_string (m.d.cm_ind.nam);
253
      if (attr2 & H_XY)
254
	dw_at_decl (m.d.cm_ind.pos);
255
      if (attr2 & H_TP)
256
	dw_at_ext_lab (dw2_find_type_label (m.d.cm_ind.typ));
257
      if (attr2 & H_LC)
258
	dw_locate_reloffset (son(m.d.cm_ind.ind_loc));
259
      break;
260
    }
261
    case DG_CM_STAT: {
262
      dw2_out_name (m.d.cm_stat, MEMBER_NAME);
263
      break;
264
    }
265
  }
266
  return;
267
}
268
 
269
 
270
static void out_class_data
271
    PROTO_N ( (cd) )
272
    PROTO_T ( class_data * cd )
273
{
274
  /* within info section */
275
  exp vtable_exp = nilexp;
276
  int i;
277
  for (i = 0; i < cd->inherits.len; i++) {
278
    dg_class_base cb;
279
    long attr1 = (H_TP | H_LC), attr2;
280
    cb = cd->inherits.array[i];
281
    if (cb.pos.file)
282
      attr1 |= H_XY;
283
    if (cb.acc)
284
      attr1 |= H_AC;
285
    if (cb.virt)
286
      attr1 |= H_VT;
287
    attr2 = dw_entry (dwe_inheritce, attr1);
288
    if (attr2 & ~(H_XY|H_TP|H_LC|H_AC|H_VT))
289
      fail_unimplemented (attr1, attr2);
290
    if (attr2 & H_XY)
291
      dw_at_decl (cb.pos);
292
    if (attr2 & H_TP)
293
      dw_at_ext_address (cb.base);
294
    if (attr2 & H_LC) {
295
      if (cb.location)
296
	dw_locate_reloffset (son(cb.location));
297
      else {
298
	out8(); outn ((long)1); outs(sep);
299
	outn ((long)DW_OP_nop); d_outnl();
300
      }
301
    }
302
    if (attr2 & H_AC)
303
      dw_at_data (1, (long)cb.acc);
304
    if (attr2 & H_VT)
305
      dw_at_data (1, (long)cb.virt);
306
  }
307
  for (i = 0; i < cd->friends.len; i++) {
308
    dg_tag f = cd->friends.array[i];
309
    IGNORE dw_entry (dwe_friend, (long)0);
310
    dw_at_ext_address (f);
311
  }
312
  if (cd->vt_s) {
313
    for (i = 0; i < cd->members.len; i++) {
314
      dg_classmem * cm = &(cd->members.array[i]);
315
      if (cm->cm_key == DG_CM_STAT && cm->d.cm_stat->key == DGN_OBJECT &&
316
	    ((cm->d.cm_stat->mor && cm->d.cm_stat->mor->this_tag == cd->vt_s)
317
		|| cm->tg == cd->vt_s))
318
	vtable_exp = cm->d.cm_stat->data.n_obj.obtain_val;
319
    }
320
    for (i = 0; i < cd->members.len; i++) {
321
      dg_classmem * cm = &(cd->members.array[i]);
322
      if (cm->cm_key == DG_CM_FN && cm->d.cm_fn.fn->key == DGN_PROC &&
323
		cm->d.cm_fn.fn->mor && cm->d.cm_fn.fn->mor->virt) {
324
	exp a, b, c;
325
	if (!vtable_exp || !cm->d.cm_fn.slot ||
326
		name(sh(son(cm->d.cm_fn.slot))) != offsethd)
327
	  failer ("wrong virtual function data");
328
	a = copy (son(vtable_exp));
329
	b = copy (son(cm->d.cm_fn.slot));
330
	c = f_add_to_ptr (a, b);
331
	cm->d.cm_fn.fn->mor->vslot = hold (hold_check (c));
332
      }
333
    }
334
  }
335
  for (i = 0; i < cd->members.len; i++) {
336
    out_classmem (cd->members.array[i]);
337
  }
338
  return;
339
}
340
 
341
 
342
static void out_task_sync_data
343
    PROTO_N ( (td) )
344
    PROTO_T ( task_data * td )
345
{
346
  /* within info section */
347
  int i;
348
  dg_name en = td->entries;
349
  while (en) {
350
    dw2_out_name (en, GLOBAL_NAME);
351
    en = en->next;
352
  }
353
  for (i = 0; i < td->members.len; i++) {
354
    out_classmem (td->members.array[i]);
355
  }
356
  return;
357
}
358
 
359
 
360
 
361
static void out_variant_part
362
    PROTO_N ( (v) )
363
    PROTO_T ( dg_varpart * v )
364
{
365
  /* within info section */
366
  int i, j;
367
  dg_variant * v_el = v->vnts.array;
368
  switch (v->v_key) {
369
    case DG_V_D: {
370
      long l = next_dwarf_label();
371
      IGNORE dw_entry (dwe_varpart, (long)0);
372
      dw_at_address (l);
373
      out_dwf_label (l, 1);
374
      out_classmem (v->u.d);
375
      break;
376
    }
377
    case DG_V_S: {
378
      IGNORE dw_entry (dwe_varpart, (long)0);
379
      dw_at_ext_address (v->u.s);
380
      break;
381
    }
382
    case DG_V_T: {
383
      IGNORE dw_entry (dwe_varpart_t, (long)0);
384
      dw_at_ext_lab (dw2_find_type_label (v->u.t));
385
      break;
386
    }
387
  }
388
  for (i = 0; i < v->vnts.len; i++) {
389
    dg_discrim * d_el = v_el[i].discr.array;
390
    dg_classmem * f_el = v_el[i].fields.array;
391
    if (v_el[i].discr.len == 0)
392
      IGNORE dw_entry (dwe_variant_0, (long)0);
393
    else
394
    if (v_el[i].discr.len == 1 && no(d_el->lower) == no(d_el->upper)) {
395
      IGNORE dw_entry (dwe_variant_1, (long)0);
396
      dw_out_const (d_el->lower);
397
    }
398
    else {
399
      long block_end = next_dwarf_label ();
400
      int ss = (name(sh(d_el->lower)) & 1);
401
      IGNORE dw_entry (dwe_variant_n, (long)0);
402
      out16 (); out_dwf_dist_to_label (block_end); d_outnl();
403
      for (j = 0; j < v_el[i].discr.len; j++) {
404
	out8 ();
405
	if (no(d_el[i].lower) == no(d_el[i].upper)) {
406
	  outn ((long)DW_DSC_label); outs (sep);
407
	  if (ss)
408
	    sleb128 ((long)no(d_el[i].lower));
409
	  else
410
	    uleb128 ((unsigned long)no(d_el[i].lower));
411
	}
412
	else {
413
	  outn ((long)DW_DSC_range); outs (sep);
414
	  if (ss) {
415
	    sleb128 ((long)no(d_el[i].lower));
416
	    outs (sep);
417
	    sleb128 ((long)no(d_el[i].upper));
418
	  }
419
	  else {
420
	    uleb128 ((unsigned long)no(d_el[i].lower));
421
	    outs (sep);
422
	    uleb128 ((unsigned long)no(d_el[i].upper));
423
	  }
424
	}
425
	d_outnl();
426
      }
427
      out_dwf_label (block_end, 1);
428
    }
429
    for (j = 0; j < v_el[i].fields.len; j++) {
430
      out_classmem (f_el[j]);
431
    }
432
    dw_sibling_end ();
433
  }
434
  dw_sibling_end ();
435
  return;
436
}
437
 
438
 
439
static void out_ref_bound
440
    PROTO_N ( (tg) )
441
    PROTO_T ( dg_tag tg )
442
{
443
  dw_at_form (DW_FORM_ref_addr); d_outnl ();
444
  dw_at_ext_address (tg);
445
  return;
446
}
447
 
448
 
449
void dw_out_dim
450
    PROTO_N ( (d) )
451
    PROTO_T ( dg_dim d )
452
{
453
  /* within info section */
454
  long attr1 = 0, attr2;
455
  if (d.d_key == DG_DIM_TYPE) {		/* must be array dimension */
456
    if ((d.d_typ->key == DGT_SUBR || d.d_typ->key == DGT_ENUM) &&
457
		!(d.d_typ->outref.u.l)) {
458
      d.d_typ->outref.u.l = next_dwarf_label();
459
      d.d_typ->outref.k = LAB_D;
460
      dw_out_type (d.d_typ);
461
    }
462
    else {
463
      attr1 = H_TP;
464
      attr2 = dw_entry (dwe_typedef, attr1);
465
      if (attr2 != attr1)
466
	fail_unimplemented (attr1, attr2);
467
      dw_at_ext_lab (dw2_find_type_label (d.d_typ));
468
    }
469
    return;
470
  }
471
  if (d.d_typ)
472
    attr1 |= (H_TP | H_SZ);
473
  if (!d.low_ref || d.lower.tg)
474
    attr1 |= H_LB;
475
  if (!d.hi_ref || d.upper.tg)
476
    attr1 |= (d.hi_cnt ? H_CN : H_UB);
477
  attr2 = dw_entry (dwe_subr_type, attr1);
478
  if (attr2 & ~(H_TP|H_SZ|H_LB|H_UB|H_CN))
479
    fail_unimplemented (attr1, attr2);
480
  if (attr2 & H_TP)
481
    dw_at_ext_lab (dw2_find_type_label (d.d_typ));
482
  if (attr2 & H_SZ)
483
    dw_at_udata ((unsigned long)(shape_size (d.sha) >> 3));
484
  if (attr2 & H_LB) {
485
    if (d.low_ref)
486
      out_ref_bound (d.lower.tg);
487
    else
488
      dw_out_const (son(d.lower.x));
489
  }
490
  if (attr2 & (H_UB | H_CN)) {
491
    if (d.hi_ref)
492
      out_ref_bound (d.upper.tg);
493
    else
494
      dw_out_const (son(d.upper.x));
495
  }
496
  return;
497
}
498
 
499
 
500
void dw_out_type
501
    PROTO_N ( (t) )
502
    PROTO_T ( dg_type t )
503
{
504
  /* within info section */
505
  dw_set_ext_lab (t->outref);
506
  switch (t->key) {
507
 
508
    case DGT_TAGGED: {
509
      dg_tag tg = t->data.t_tag;
510
      if (tg->done || tg->key != DGK_NAME || tg->p.nam->key != DGN_TYPE) {
511
	failer ("unexpected out_type");
512
	outnl_comment ("		ERROR");
513
	break;
514
      }
515
      tg->done = 1;
516
      dw2_out_name (tg->p.nam, GLOBAL_NAME);
517
      break;
518
    }
519
 
520
    case DGT_BASIC: {
521
      shape sha = t->data.t_bas.b_sh;
522
      long encoding;
523
      switch (t->data.t_bas.b_key) {
524
	case DG_ADR_T:
525
	  encoding = DW_ATE_address;
526
	  break;
527
	case DG_BOOL_T:
528
	  encoding = DW_ATE_boolean;
529
	  break;
530
	case DG_CHAR_T:
531
	  encoding = (is_signed (sha) ? DW_ATE_signed_char : DW_ATE_unsigned_char);
532
	  break;
533
	case DG_INT_T:
534
	  encoding = (is_signed (sha) ? DW_ATE_signed : DW_ATE_unsigned);
535
	  break;
536
	case DG_FLOAT_T:
537
	  encoding = (is_floating (name(sha)) ? DW_ATE_float : DW_ATE_complex_float);
538
	  break;
539
      }
540
      IGNORE dw_entry (dwe_base_type, (long)0);
541
      dw_at_string (t->data.t_bas.tnam);
542
      dw_at_data (1, encoding);
543
      dw_at_udata ((unsigned long)(shape_size (sha) >> 3));
544
      break;
545
    }
546
 
547
    case DGT_QUAL: {
548
      abbrev_entry dwe;
549
      int flg = 0;
550
      switch (t->data.t_qual.q_key) {
551
	case DG_PTR_T: {
552
	  dwe = dwe_ptr_type;
553
	  break;
554
	}
555
	case DG_HPPTR_T: {
556
	  dwe = dwe_hpptr_t;
557
	  flg = 1;
558
	  break;
559
	}
560
	case DG_REF_T: {
561
	  dwe = dwe_ref_type;
562
	  break;
563
	}
564
	case DG_PACK_T: {
565
	  dwe = dwe_pack_type;
566
	  break;
567
	}
568
	case DG_CONST_T: {
569
	  dwe = dwe_cnst_type;
570
	  break;
571
	}
572
	case DG_VOL_T: {
573
	  dwe = dwe_vol_type;
574
	  break;
575
	}
576
	case DG_ALIAS_T: {
577
	  dwe = dwe_als_type;
578
	  break;
579
	}
580
	case DG_CLWID_T: {
581
	  dwe = dwe_clwd_type;
582
	  break;
583
	}
584
	case DG_LIM_T: {
585
	  dwe = dwe_lim_type;
586
	  break;
587
	}
588
	case N_DG_QUAL_TYPES:
589
	  break;	/* dummy */
590
      }
591
      IGNORE dw_entry (dwe, (long)0);
592
      dw_at_ext_lab (dw2_find_type_label (t->data.t_qual.typ));
593
      if (flg)
594
	dw_at_flag (flg);
595
      break;
596
    }
597
 
598
    case DGT_ARRAY: {
599
      exp stride_e = son(t->data.t_arr.stride);
600
      dg_dim * el = t->data.t_arr.dims.array;
601
      int stride_known = (name(stride_e) == val_tag);
602
      int size_known = stride_known;
603
      unsigned long tot_size = (unsigned long) no(stride_e);
604
      int i;
605
      for (i = 0; i < t->data.t_arr.dims.len && size_known; i++) {
606
	if (el[i].count >= 0)
607
	  tot_size *= (unsigned long) el[i].count;
608
	else
609
	  size_known = 0;
610
      }
611
 
612
      IGNORE dw_entry ((size_known ? dwe_arr_type : dwe_arr_dyn), (long)0);
613
      dw_at_ext_lab (dw2_find_type_label (t->data.t_arr.elem_type));
614
      if (stride_known)
615
	dw_out_const (stride_e);
616
      else
617
	dw2_offset_exp (stride_e);
618
      dw_at_data (1, (long)(t->data.t_arr.rowm ? DW_ORD_row_major : DW_ORD_col_major));
619
      if (size_known)
620
	dw_at_udata ((tot_size + 7) >> 3);
621
 
622
      for (i = 0; i < t->data.t_arr.dims.len; i++)
623
	dw_out_dim (el[i]);
624
      dw_sibling_end ();
625
      break;
626
    }
627
 
628
    case DGT_SUBR: {
629
      dw_out_dim (t->data.t_subr);
630
      break;
631
    }
632
 
633
    case DGT_ENUM: {
634
      long attr1 = H_SZ, attr2;
635
      int i;
636
      dg_enum * el = t->data.t_enum.values.array;
637
      if (t->mor && t->mor->refspec)
638
	attr1 |= H_SP;
639
      if (t->mor && t->mor->isspec)
640
	attr1 |= H_DC;
641
      if (t->data.t_enum.tnam[0])
642
	attr1 |= H_NM;
643
      if (t->data.t_enum.tpos.file)
644
	attr1 |= H_XY;
645
      if (t->mor && t->mor->isnew)
646
	attr1 |= H_NW;
647
      attr2 = dw_entry (dwe_enum_type, attr1);
648
      if (attr2 & ~(H_SP|H_DC|H_NM|H_XY|H_SZ|H_NW))
649
	fail_unimplemented (attr1, attr2);
650
      if (attr2 & H_SP)
651
	dw_at_ext_lab (dw2_find_type_label (t->mor->refspec->p.typ));
652
      if (attr2 & H_DC)
653
	dw_at_flag ((t->mor && t->mor->isspec ? 1 : 0));
654
      if (attr2 & H_NM)
655
	dw_at_string (t->data.t_enum.tnam);
656
      if (attr2 & H_XY)
657
	dw_at_decl (t->data.t_enum.tpos);
658
      if (attr2 & H_SZ)
659
	dw_at_udata ((unsigned long)(shape_size (sh (son(el[0].value))) >> 3));
660
      if (attr2 & H_NW)
661
	dw_at_flag ((t->mor && t->mor->isnew ? 1 : 0));
662
 
663
      for (i = 0; i < t->data.t_enum.values.len; i++) {
664
	if (el[i].tg)
665
	  set_ext_address (el[i].tg);
666
	if (el[i].is_chn) {
667
	  IGNORE dw_entry (dwe_enum_char, (long)0);
668
	  out8(); uleb128 ((unsigned long)el[i].chn); d_outnl();
669
	}
670
	else {
671
	  IGNORE dw_entry (dwe_enum_tor, (long)0);
672
	  dw_at_string (el[i].enam);
673
	}
674
	dw_out_const (son(el[i].value));
675
      }
676
      dw_sibling_end ();
677
      break;
678
    }
679
 
680
    case DGT_STRUCT:
681
    case DGT_CLASS:
682
    case DGT_A_TASK:
683
    case DGT_A_SYNCH: {
684
      abbrev_entry dwe;
685
      int ada_derived = 0;
686
      char* nam;
687
      char* gnam = "";
688
      long attr1 = 0, attr2;
689
      dg_instantn * generic = (dg_instantn *)0;
690
      if (t->data.t_struct.is_union)
691
	dwe = dwe_union_t;
692
      else
693
      switch (t->key) {
694
	case DGT_STRUCT:
695
	  dwe = dwe_struct_t;
696
	  break;
697
	case DGT_CLASS:
698
	  dwe = dwe_class_t;
699
	  break;
700
	case DGT_A_TASK:
701
	  dwe = dwe_task_t;
702
	  break;
703
	default:
704
	  dwe = dwe_synch_t;
705
	  break;
706
      }
707
      if (t->data.t_struct.idnam.id_key == DG_ID_INST) {
708
	generic = t->data.t_struct.idnam.idd.instance;
709
	if (generic->nam.id_key == DG_ID_NONE ||
710
		generic->nam.id_key == DG_ID_ANON)
711
	  nam = generic->spec.idd.nam;
712
        else {
713
	  nam = generic->nam.idd.nam;
714
	  gnam = generic->spec.idd.nam;
715
	}
716
      }
717
      else
718
	nam = t->data.t_struct.idnam.idd.nam;
719
 
720
      if (t->data.t_struct.tpos.file)
721
	attr1 |= H_XY;
722
      if (t->mor && t->mor->refspec)
723
	attr1 |= H_SP;
724
      else {
725
	if (nam[0])
726
	  attr1 |= H_NM;
727
	if (gnam[0])
728
	  attr1 |= H_GN;
729
      }
730
      if (t->mor && t->mor->isspec)
731
	attr1 |= H_DC;
732
      if (t->mor && t->mor->issep)
733
	attr1 |= H_SE;
734
      if (t->data.t_struct.sha)
735
	attr1 |= H_SZ;
736
      if (t->mor && t->mor->elabn)
737
	attr1 |= H_EL;
738
      if (t->mor && t->mor->isnew)
739
	attr1 |= H_NW;
740
      if (t->mor && t->mor->aderiv) {
741
	attr1 |= H_AD;
742
	ada_derived = 1;
743
      }
744
 
745
      if (t->key == DGT_CLASS) {
746
	if (t->data.t_struct.u.cd->vt_s)
747
	  attr1 |= H_VS;
748
	if (t->data.t_struct.u.cd->vt_d)
749
	  attr1 |= H_VD;
750
	if (t->data.t_struct.u.cd->rtti_s)
751
	  attr1 |= H_RS;
752
	if (t->data.t_struct.u.cd->rtti_d)
753
	  attr1 |= H_RD;
754
      }
755
      else
756
      if (t->key != DGT_STRUCT) {
757
	if (t->data.t_struct.u.td->cb)
758
	  attr1 |= H_CB;
759
	if (t->data.t_struct.u.td->id)
760
	  attr1 |= H_ID;
761
      }
762
 
763
      attr2 = dw_entry (dwe, attr1);
764
      if (attr2 & ~(H_SP|H_DC|H_NM|H_XY|H_SZ|H_NW|H_EXTN))
765
	fail_unimplemented (attr1, attr2);
766
      if (attr2 & H_SP)
767
	dw_at_ext_lab (dw2_find_type_label (t->mor->refspec->p.typ));
768
      if (attr2 & H_DC)
769
	dw_at_flag ((t->mor && t->mor->isspec ? 1 : 0));
770
      if (attr2 & H_NM)
771
	dw_at_string (nam);
772
      if (attr2 & H_XY)
773
	dw_at_decl (t->data.t_struct.tpos);
774
      if (attr2 & H_SZ)
775
	dw_at_udata ((unsigned long)(shape_size (t->data.t_struct.sha) >> 3));
776
      if (attr2 & H_NW)
777
	dw_at_flag ((t->mor && t->mor->isnew ? 1 : 0));
778
 
779
      if (attr2 & H_EXTN) {
780
	long block_end = next_dwarf_label ();
781
	out16 (); out_dwf_dist_to_label (block_end); d_outnl();
782
	attr1 &= ~attr2;
783
	if (attr1 & H_NW) {
784
	  set_attribute (DW_AT_DD_newtype, DW_FORM_flag);
785
	  dw_at_flag ((t->mor && t->mor->isnew ? 1 : ada_derived));
786
	}
787
	if (attr1 & H_AD) {
788
	  set_attribute (DW_AT_DD_ada_derived, DW_FORM_flag);
789
	  dw_at_flag (ada_derived);
790
	}
791
	if (attr1 & H_SE) {
792
	  set_attribute (DW_AT_DD_ada_derived, DW_FORM_flag);
793
	  dw_at_flag ((t->mor && t->mor->issep ? 1 : 0));
794
	}
795
	switch (t->key) {
796
	  case DGT_STRUCT: {
797
	    fail_unimplemented (attr1, attr1);
798
	    break;
799
	  }
800
	  case DGT_CLASS: {
801
	    if (attr1 & ~(H_NW|H_VS|H_VD|H_RS|H_RD|H_EL|H_GN|H_AD))
802
	      fail_unimplemented (attr1, attr1);
803
	    if (attr1 & H_VS) {
804
	      set_attribute (DW_AT_DD_vtable_static, DW_FORM_ref_addr);
805
	      dw_at_ext_address (t->data.t_struct.u.cd->vt_s);
806
	    }
807
	    if (attr1 & H_VD) {
808
	      set_attribute (DW_AT_DD_vtable_dynamic, DW_FORM_ref_addr);
809
	      dw_at_ext_address (t->data.t_struct.u.cd->vt_d);
810
	    }
811
	    if (attr1 & H_RS) {
812
	      set_attribute (DW_AT_DD_rtti_static, DW_FORM_ref_addr);
813
	      dw_at_ext_address (t->data.t_struct.u.cd->rtti_s);
814
	    }
815
	    if (attr1 & H_RD) {
816
	      set_attribute (DW_AT_DD_rtti_dynamic, DW_FORM_ref_addr);
817
	      dw_at_ext_address (t->data.t_struct.u.cd->rtti_d);
818
	    }
819
	    break;
820
	  }
821
	  case DGT_A_TASK: {
822
	    if (attr1 & ~(H_NW|H_ID|H_CB|H_EL|H_GN|H_SE))
823
	      fail_unimplemented (attr1, attr1);
824
	    if (attr1 & H_ID) {
825
	      set_attribute (DW_AT_DD_task_id, DW_FORM_ref_addr);
826
	      dw_at_ext_address (t->data.t_struct.u.td->id);
827
	    }
828
	    if (attr1 & H_CB) {
829
	      set_attribute (DW_AT_DD_task_control_block, DW_FORM_ref_addr);
830
	      dw_at_ext_address (t->data.t_struct.u.td->cb);
831
	    }
832
	    break;
833
	  }
834
	  default: {
835
	    if (attr1 & ~(H_NW|H_CB|H_EL|H_GN|H_SE))
836
	      fail_unimplemented (attr1, attr1);
837
	    if (attr1 & H_CB) {
838
	      set_attribute (DW_AT_DD_so_control_block, DW_FORM_ref_addr);
839
	      dw_at_ext_address (t->data.t_struct.u.td->cb);
840
	    }
841
	    break;
842
	  }
843
	}
844
	if (attr1 & H_EL) {
845
	  set_attribute (DW_AT_DD_elaboration, DW_FORM_ref_addr);
846
	  dw_at_ext_address (t->mor->elabn);
847
	}
848
	if (attr1 & H_GN) {
849
	  set_attribute (DW_AT_DD_generic_name, DW_FORM_string);
850
	  dw_at_string (gnam);
851
	}
852
      }
853
 
854
      if (generic)
855
	dw2_out_generic (generic->params);
856
      switch (t->key) {
857
	case DGT_STRUCT: {
858
	  int i;
859
	  dg_classmem * el = t->data.t_struct.u.fields.array;
860
	  for (i = 0; i < t->data.t_struct.u.fields.len; i++)
861
	    out_classmem (el[i]);
862
	  break;
863
	}
864
	case DGT_CLASS: {
865
	  out_class_data (t->data.t_struct.u.cd);
866
	  break;
867
	}
868
	default: {
869
	  out_task_sync_data (t->data.t_struct.u.td);
870
	  break;
871
	}
872
      }
873
      if (t->data.t_struct.vpart)
874
	out_variant_part (t->data.t_struct.vpart);
875
      dw_sibling_end ();
876
      break;
877
    }
878
 
879
    case DGT_PMEM: {
880
      IGNORE dw_entry (dwe_ptrmem_t, (long)0);
881
      dw_at_ext_address (t->data.t_pmem.pclass);
882
      dw_at_ext_lab (dw2_find_type_label (t->data.t_pmem.memtyp));
883
      dw_at_udata ((unsigned long)(shape_size (t->data.t_pmem.sha) >> 3));
884
      break;
885
    }
886
 
887
    case DGT_CONS: {
888
      abbrev_entry dwe;
889
      long attr1 = (H_TP | H_SZ), attr2 = 0;
890
      if (t->data.t_cons.c_key == DG_SET_T)
891
	dwe = dwe_set_t;
892
      else
893
	dwe = dwe_file_t;
894
      if (t->mor && t->mor->refspec)
895
	attr1 |= H_SP;
896
      if (t->mor && t->mor->isspec)
897
	attr1 |= H_DC;
898
      if (t->data.t_enum.tnam[0])
899
      attr2 = dw_entry (dwe, attr1);
900
      if (attr2 & ~(H_SP|H_DC|H_TP|H_SZ))
901
	fail_unimplemented (attr1, attr2);
902
      if (attr2 & H_SP)
903
	dw_at_ext_lab (dw2_find_type_label (t->mor->refspec->p.typ));
904
      if (attr2 & H_DC)
905
	dw_at_flag ((t->mor && t->mor->isspec ? 1 : 0));
906
      if (attr2 & H_TP)
907
	dw_at_ext_lab (dw2_find_type_label (t->data.t_cons.typ));
908
      if (attr2 & H_SZ)
909
	dw_at_udata ((unsigned long)(shape_size (t->data.t_cons.sha) >> 3));
910
      break;
911
    }
912
 
913
    case DGT_PROC: {
914
      int i;
915
      dg_param * el = t->data.t_proc.params.array;
916
      dg_type res_t = t->data.t_proc.res_type;
917
      if (res_t) {
918
	IGNORE dw_entry (dwe_proc_type, (long)0);
919
	dw_at_ext_lab (dw2_find_type_label (res_t));
920
      }
921
      else
922
	IGNORE dw_entry (dwe_procv_t, (long)0);
923
      for (i = 0; i < t->data.t_proc.params.len; i++) {
924
	IGNORE dw_entry (dwe_formal, (long)0);
925
	dw_at_ext_lab (dw2_find_type_label (el[i].p_typ));
926
      }
927
      if (t->data.t_proc.prps & f_var_callers)
928
	IGNORE dw_entry (dwe_opt_par, (long)0);
929
      dw_sibling_end ();
930
      break;
931
    }
932
 
933
    case DGT_BITF: {
934
      failer ("bitfields shouldn't occur here");
935
      break;
936
    }
937
 
938
    case DGT_FIXED: {
939
      long attr1 = 0, attr2;
940
      if (t->data.t_adanum.delta)
941
	attr1 |= H_DF;
942
      if (t->data.t_adanum.digits)
943
	attr1 |= H_DS;
944
      attr2 = dw_entry (dwe_fixpt_t, attr1);
945
      if (attr2 & ~(H_DF|H_DS))
946
	fail_unimplemented (attr1, attr2);
947
      dw_at_ext_lab (dw2_find_type_label (t->data.t_adanum.rept));
948
      dw_out_const (son(t->data.t_adanum.small));
949
      if (attr2 & H_DF)
950
	dw_out_const (son(t->data.t_adanum.delta));
951
      if (attr2 & H_DS)
952
	dw_out_const (son(t->data.t_adanum.digits));
953
      break;
954
    }
955
 
956
    case DGT_FLDIG: {
957
      IGNORE dw_entry (dwe_fldg_t, (long)0);
958
      dw_at_ext_lab (dw2_find_type_label (t->data.t_adanum.rept));
959
      dw_out_const (son(t->data.t_adanum.digits));
960
      break;
961
    }
962
 
963
    case DGT_MOD: {
964
      IGNORE dw_entry (dwe_modular_t, (long)0);
965
      dw_at_ext_lab (dw2_find_type_label (t->data.t_adanum.rept));
966
      dw_out_const (son(t->data.t_adanum.digits));
967
      break;
968
    }
969
 
970
    case DGT_STRING: {
971
      exp l_e = son(t->data.t_string.length);	/* other fields ignored */
972
      if (name(l_e) == val_tag) {
973
	IGNORE dw_entry (dwe_stringc_t, (long)0);
974
	dw_at_udata ((unsigned long)no(l_e));
975
      }
976
      else {
977
	IGNORE dw_entry (dwe_string_t, (long)0);
978
	dw2_locate_exp (l_e, 0, 0);
979
	dw_at_udata ((unsigned long)(shape_size (sh(l_e)) >> 3));
980
      }
981
      break;
982
    }
983
 
984
    case DGT_UNKNOWN: {
985
      IGNORE dw_entry (dwe_unknown_t, (long)0);
986
      break;
987
    }
988
 
989
    default:
990
      failer ("illegal type");
991
  }
992
  return;
993
}
994
 
995
 
996
void dw2_out_all_types
997
    PROTO_Z ()
998
{
999
  while (needed_types) {
1000
    dg_type dt = needed_types;
1001
    needed_types = needed_types->type_queue;
1002
    if (dt->key != DGT_TAGGED || !dt->data.t_tag->done)
1003
      dw_out_type (dt);
1004
  }
1005
  return;
1006
}