Subversion Repositories tendra.SVN

Rev

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

Rev Author Line No. Line
2 7u83 1
/*
6 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: release $
63
$Date: 1998/02/04 10:43:37 $
64
$Revision: 1.2 $
65
$Log: dwarf_info.c,v $
66
 * Revision 1.2  1998/02/04  10:43:37  release
67
 * Changes during testing.
68
 *
69
 * Revision 1.1.1.1  1998/01/17  15:55:47  release
70
 * First version to be checked into rolling release.
71
 *
72
 * Revision 1.4  1997/06/02  08:28:44  pwe
73
 * correction re NEWDIAGS
74
 *
75
 * Revision 1.3  1997/02/19  12:53:41  pwe
76
 * NEWDIAGS for debugging optimised code
77
 *
78
 * Revision 1.2  1995/09/28  12:39:37  pwe
79
 * dwarf.h via import, and type changes for tcc checks
80
 *
81
 * Revision 1.1.1.1  1995/08/14  14:30:21  pwe
82
 * transferred from DJCH
83
 *
84
**********************************************************************/
85
 
86
/* LOG 4 July 1994 added dwarf_types.h to unify with sparc version */
87
/* LOG 6/9/93 changes for sparc/ICL port of SVR4.2 djch
88
 comment char is not #... introduced COMMENT_2 macros */
89
 
90
/* LOG 25/11/93 removed redundant expr_buf djch */
91
 
92
#include "config.h"
93
#include "common_types.h"
94
#include "readglob.h"
95
#include "table_fns.h"
96
#include "basicread.h"
97
#include "sortmacs.h"
98
 
99
/* machine dep headers */
100
#include "out.h"
101
#include "expmacs.h"
102
 
103
#include "tags.h"
104
 
105
#include "main_reads.h"
106
#include "check.h"
107
#include "main_reads.h"
108
 
109
#include "dwarf_types.h"
110
#include "dwarf_type.h"
111
#include "dwarf_out.h"
112
#include "diag_fns.h"
113
#include "dwarf_loc.h"
114
#include "dwarf_queue.h"
115
#include "dwarf_mc.h"
116
#include "mark_scope.h"
117
#include "cross_config.h"
118
 
119
#ifdef NEWDIAGS
120
#include "tags.h"
121
#endif
122
 
123
#ifndef CROSS_INCLUDE
124
#include <dwarf.h>
125
#else
126
#include CROSS_INCLUDE/dwarf.h>
127
#endif
128
 
129
int continue_decs;
130
 
131
static long lex_blk_stk_ptr = -1;
132
 
133
static dwarf_label lex_blk_stk[100];
134
 
6 7u83 135
#define PUSH_LEX_BLK	(&lex_blk_stk[++lex_blk_stk_ptr])
136
#define POP_LEX_BLK	(&lex_blk_stk[lex_blk_stk_ptr--])
137
#define TOS_LEX_BLK	(&lex_blk_stk[lex_blk_stk_ptr])
138
#define CHK_LEX_STK	if (lex_blk_stk_ptr < -1) {		\
139
				failer("lex stk underflow")	\
140
			}
2 7u83 141
 
6 7u83 142
static void
143
out_dwarf_start_scope(dwarf_label *l)
2 7u83 144
{
6 7u83 145
	char expr_buf[100];
2 7u83 146
 
6 7u83 147
	if (lex_blk_stk_ptr == -1) {
148
		return;
149
	}
2 7u83 150
 
6 7u83 151
	sprintf(expr_buf, "%s - %s", LAB2CHAR(l->beg),
152
		LAB2CHAR(TOS_LEX_BLK->beg));
153
	OUT_DWARF_ATTR(AT_start_scope);
154
	dwarf4(expr_buf);
2 7u83 155
}
156
 
6 7u83 157
 
2 7u83 158
#ifdef NEWDIAGS
159
 
6 7u83 160
static void
161
comment_end_scope(diag_info *d)
2 7u83 162
{
6 7u83 163
	char expr_buf[100];
164
	sprintf(expr_buf, COMMENT_2("\t", "\tEND diag_info key %d"), d->key);
165
	outs(expr_buf);
166
	outs("\n");	/* avoid 80x86 outnl which has side effect */
2 7u83 167
}
168
 
6 7u83 169
 
170
void
171
code_diag_info(diag_info *d, int proc_no, void(*mcode)(void *), void *args)
2 7u83 172
{
6 7u83 173
	if (d == nildiag) {
174
		(*mcode)(args);
175
		return;
176
	}
177
	switch (d->key) {
178
	case DIAG_INFO_SCOPE:
179
		next_dwarf_lab(PUSH_LEX_BLK);
180
		OUT_DWARF_BEG(TOS_LEX_BLK);
181
		cont_sib_chain(TAG_lexical_block);
182
		OUT_DWARF_ATTR(AT_low_pc);
183
		dwarf4(LAB2CHAR(TOS_LEX_BLK->beg));
184
		OUT_DWARF_ATTR(AT_high_pc);
185
		dwarf4(LAB2CHAR(TOS_LEX_BLK->end));
186
		leave_dwarf_blk();
187
		make_next_new_chain();
188
		code_diag_info(d->more, proc_no, mcode, args);
189
		OUT_DWARF_END(POP_LEX_BLK);
190
		CHK_LEX_STK;
191
		end_sib_chain();
192
		return;
193
	case DIAG_INFO_SOURCE:
194
		out_dwarf_sourcemark(&(d->data.source.beg));
195
		code_diag_info(d->more, proc_no, mcode, args);
196
		comment_end_scope(d);
197
		return;
198
	case DIAG_INFO_ID: {
199
		exp x = d->data.id_scope.access;
200
		dwarf_label tlab;
201
		next_dwarf_lab(&tlab);
202
		OUT_DWARF_BEG(&tlab);	/* always needed for start_scope */
203
		while (1) {
204
			if (name(x) != hold_tag) {
205
				failer("access should be in hold");
206
				break;
207
			}
208
			x = son(x);
209
			if (name(x) == cont_tag && name(son(x)) == name_tag &&
210
			    isvar(son(son(x)))) {
211
				x = son(x);
212
			}
213
			if ((name(x) != name_tag || isdiscarded(x)) &&
214
			    name(x) != val_tag && name(x) != null_tag) {
215
				break;	/* should do better ! */
216
			}
2 7u83 217
 
6 7u83 218
			if ((base_type(d->data.id_scope.typ))->key ==
219
			    DIAG_TYPE_INITED) {
220
				fprintf(stderr, "ERROR: %s has no diagtype... omitting\n",
221
					TDFSTRING2CHAR(d->data.id_scope.nme));
222
				break;
223
			}
224
			if (name(x) == name_tag && isglob(son(x))) {
225
				if (brog(son(x)) ->dec_u.dec_val.extnamed) {
226
					break;
227
				} else {
228
					/* static; goes out as local */
229
					cont_sib_chain(TAG_local_variable);
230
					/* only for local vars */
231
					out_dwarf_start_scope(&tlab);
232
				}
233
			} else if (name(x) == name_tag && isparam(son(x))) {
234
				cont_sib_chain(TAG_formal_parameter);
235
			} else {
236
				cont_sib_chain(TAG_local_variable);
237
				/* only for local vars */
238
				out_dwarf_start_scope(&tlab);
239
			}
240
 
241
			out_dwarf_name_attr(TDFSTRING2CHAR(d->data.id_scope.nme));
242
			out_dwarf_type_attr(d->data.id_scope.typ);
243
			if (!out_dwarf_loc_attr(x, proc_no)) {
244
				fprintf(stderr, "Unable to generate location info for variable '%s'\n",
245
					TDFSTRING2CHAR(d->data.id_scope.nme));
246
			}
247
			leave_dwarf_blk();
248
			dump_type_q();
249
			break;
250
		}
251
		code_diag_info(d->more, proc_no, mcode, args);
252
		comment_end_scope(d);
253
		return;
2 7u83 254
	}
6 7u83 255
	case DIAG_INFO_TYPE: {
256
		dwarf_label tlab;
257
		next_dwarf_lab(&tlab);
258
		OUT_DWARF_BEG(&tlab);	/* always needed for start_scope */
259
		cont_sib_chain(TAG_typedef);
260
		out_dwarf_start_scope(&tlab);
261
		out_dwarf_name_attr(TDFSTRING2CHAR(d->data.type_scope.nme));
262
		out_dwarf_type_attr(d->data.type_scope.typ);
263
		leave_dwarf_blk();
264
		code_diag_info(d->more, proc_no, mcode, args);
265
		comment_end_scope(d);
266
		return;
2 7u83 267
	}
6 7u83 268
		failer("Illegal key in output_diag");
269
		fprintf(stderr, "key was %d\n", d->key);
270
		code_diag_info(d->more, proc_no, mcode, args);
271
	}
2 7u83 272
}
273
 
274
#else
275
 
6 7u83 276
void
277
output_diag(diag_info *d, int proc_no, exp e)
2 7u83 278
{
6 7u83 279
	if (d->key == DIAG_INFO_SOURCE) {
280
		out_dwarf_sourcemark(&(d->data.source.beg));
281
		return;
282
	}
283
	{
284
		dwarf_label tlab;
2 7u83 285
 
6 7u83 286
		mark_scope(e);
2 7u83 287
 
6 7u83 288
		if (props(e) & 0x80) {
289
			next_dwarf_lab(PUSH_LEX_BLK);
290
			OUT_DWARF_BEG(TOS_LEX_BLK);
291
			cont_sib_chain(TAG_lexical_block);
292
			OUT_DWARF_ATTR(AT_low_pc);
293
			dwarf4(LAB2CHAR(TOS_LEX_BLK->beg));
294
			OUT_DWARF_ATTR(AT_high_pc);
295
			dwarf4(LAB2CHAR(TOS_LEX_BLK->end));
296
			leave_dwarf_blk();
297
			make_next_new_chain();
298
		};
2 7u83 299
 
6 7u83 300
		next_dwarf_lab(&tlab);
301
		OUT_DWARF_BEG(&tlab);	/* always needed for start_scope */
302
		switch (d->key)
303
		{
304
		case DIAG_INFO_ID: {
305
			exp x = d->data.id_scope.access;
2 7u83 306
 
6 7u83 307
			if (name(x) != name_tag) {
308
				failer("diagnosing non-identifier");
309
				return;
310
			}
2 7u83 311
 
6 7u83 312
			if ((base_type(d->data.id_scope.typ))->key ==
313
			    DIAG_TYPE_INITED) {
314
				fprintf(stderr, "ERROR: %s %s has no diagtype... omitting\n",
315
					isparam(son(x)) ? "Formal parameter" :
316
					"Local variable",
317
					TDFSTRING2CHAR(d->data.id_scope.nme));
318
				break;
319
			}
320
			if (isglob(son(x))) {
321
				if (brog(son(x)) ->dec_u.dec_val.extnamed) {
322
					break;
323
				} else {
324
					/* static; goes out as local */
325
					cont_sib_chain(TAG_local_variable);
326
					/* only for local vars */
327
					out_dwarf_start_scope(&tlab);
328
				}
329
			} else if (isparam(son(x))) {
330
				cont_sib_chain(TAG_formal_parameter);
331
			} else {
332
				cont_sib_chain(TAG_local_variable);
333
				/* only for local vars */
334
				out_dwarf_start_scope(&tlab);
335
			}
336
 
337
			out_dwarf_name_attr(TDFSTRING2CHAR(d->data.id_scope.nme));
338
			out_dwarf_type_attr(d->data.id_scope.typ);
339
			if (!out_dwarf_loc_attr(x, proc_no)) {
340
				fprintf(stderr, "Unable to generate location info for variable '%s'\n",
341
					TDFSTRING2CHAR(d->data.id_scope.nme));
342
			}
343
			leave_dwarf_blk();
344
			dump_type_q();
345
		}
346
			break;
347
		case DIAG_INFO_TYPE:
348
			cont_sib_chain(TAG_typedef);
349
			out_dwarf_start_scope(&tlab);
350
			out_dwarf_name_attr(TDFSTRING2CHAR(d->data.type_scope.nme));
351
			out_dwarf_type_attr(d->data.type_scope.typ);
352
			leave_dwarf_blk();
353
			break;
354
		case DIAG_INFO_TAG:
355
			fprintf(stderr, "diag_info_tag named %s\n",
356
				TDFSTRING2CHAR(d->data.tag_scope.nme));
357
			if (!strcmp(TDFSTRING2CHAR(d->data.tag_scope.nme),
358
				    TDFSTRING2CHAR(d->data.tag_scope.typ->data.t_struct.nme)))
359
			{
360
				fprintf(stderr, "diag type gives name as %s\n",
361
					TDFSTRING2CHAR(d->data.tag_scope.typ->data.t_struct.nme));
362
				failer("different names in output_diag");
363
			}
364
			out_dwarf_user_type(d->data.tag_scope.typ);
365
			break;
366
		default:
367
			failer("Illegal key in output_diag");
368
			fprintf(stderr, "key was %d\n", d->key);
369
		}
2 7u83 370
	}
371
}
372
 
6 7u83 373
 
374
void
375
output_end_scope(diag_info *d, exp e)
2 7u83 376
{
6 7u83 377
	char expr_buf[100];
2 7u83 378
 
6 7u83 379
	sprintf(expr_buf, COMMENT_2("\t", "\tEND diag_info key %d"), d->key);
380
	outs(expr_buf);
381
	outnl();
2 7u83 382
 
6 7u83 383
	if (d->key != DIAG_INFO_SOURCE && props(e) & 0x80) {
384
		OUT_DWARF_END(POP_LEX_BLK);
385
		CHK_LEX_STK;
386
		end_sib_chain();
387
	}
2 7u83 388
}
389
 
390
#endif