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