Subversion Repositories tendra.SVN

Rev

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

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