Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – /branches/tendra5/src/installers/alpha/common/alphadiags.c – Rev 2

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
/* 	alphadiags.c,v 1.3 1995/06/28 10:19:06 john Exp	 */
32
 
33
#ifndef lint
34
static char vcid[] = "alphadiags.c,v 1.3 1995/06/28 10:19:06 john Exp";
35
#endif /* lint */
36
 
37
 
38
/*
39
  alphadiags.c
40
  This file contains functions to handle code diagnostics for 
41
  alpha/OSF1. (largely based on the mips installer version 
42
  'mipsdiags.c').
43
*/
44
 
45
/*
46
alphadiags.c,v
47
 * Revision 1.3  1995/06/28  10:19:06  john
48
 * Reformatting
49
 *
50
 * Revision 1.2  1995/05/23  10:52:24  john
51
 * Fix to non 64 bit machines
52
 *
53
 * Revision 1.1.1.1  1995/03/23  10:39:01  john
54
 * Entered into CVS
55
 *
56
 * Revision 1.7  1995/01/31  14:24:24  john
57
 * Various portability changes
58
 *
59
 * Revision 1.6  1995/01/26  13:36:38  john
60
 * Minor portability improvements
61
 *
62
*/
63
#include "config.h"
64
#include "common_types.h"
65
#include "exptypes.h"
66
#include "shapemacs.h"
67
#include "expmacs.h"
68
#include "exp.h"
69
#include "procrectypes.h"
70
#include "procrecs.h"
71
#include "tags.h"
72
#include "bitsmacs.h"
73
#include "diagtypes.h"
74
#include "xalloc.h"
75
#include "syms.h"
76
#include "diag_fns.h"
77
#include "locate.h"
78
#include "alphadiags.h"
79
#include "diagglob.h"
80
#include "mark_scope.h"
81
#include "ibinasm.h"
82
#include "out_ba.h"
83
#include "coder.h"
84
#include "cross.h"
85
#include "symbol.h"
86
#include "cross_config.h"
87
 
88
#ifndef CROSS_INCLUDE
89
#include <symconst.h>
90
#else
91
#include CROSS_INCLUDE/symconst.h>
92
#endif
93
 
94
extern FILE * as_file;
95
extern bool last_param PROTO_S ((exp e));
96
extern int currentfile;
97
/* our current fileno  */
98
extern int mainfile;
99
/* default fileno for no diags or shape output */
100
 
101
 
102
int *file_dnos;		/* dense nos for files */
103
 
104
filename * fds;
105
int nofds = 0;
106
int szfds = 0;
107
 
108
 
109
#if 0
110
void collect_files
111
    PROTO_N ( ( f ) )
112
    PROTO_T ( filename f )
113
{
114
  return;
115
}
116
 
117
void OUTPUT_DIAG_TAGS
118
  PROTO_Z ()
119
{
120
  return;
121
}
122
#endif
123
 
124
 
125
void collect_files
126
    PROTO_N ( ( f ) )
127
    PROTO_T ( filename f )
128
{
129
  if (nofds>=szfds) {
130
    fds = (filename*)xrealloc(fds, (size_t)(szfds+=5)*sizeof(filename));
131
  }
132
  fds[nofds++] = f;
133
}
134
 
135
int find_file
136
    PROTO_N ( ( f ) )
137
    PROTO_T ( filename f )
138
{
139
  int i;
140
  for(i=0; i<nofds; i++) {
141
    if (strcmp(f->file.ints.chars, fds[i]->file.ints.chars)==0) return i;
142
  }	
143
  return 0;
144
}
145
 
146
 
147
 
148
/* produce symnos for all text files in compilation */
149
void symnosforfiles
150
    PROTO_Z ()
151
{
152
  int   i;
153
  file_dnos = (int *) xcalloc (nofds, sizeof (int));
154
  for (i = 0; i < nofds; i++) {
155
    file_dnos[i] = new_lsym_d (fds[i]->file.ints.chars, 0, stFile, scText, 
156
			       (diag_type)0, i);
157
  }
158
  return;
159
}
160
 
161
/* used for testing whether o/p worked */
162
static  void x
163
    PROTO_N ( ( i ) )
164
    PROTO_T ( int i )
165
{
166
  if (i == EOF) {
167
    failer ("can't output");
168
    exit (EXIT_FAILURE);
169
  }
170
  return;
171
}
172
 
173
 
174
/* output .file directive for file i */
175
void stab_file
176
    PROTO_N ( ( i ) )
177
    PROTO_T ( int i )
178
{
179
  int l;
180
  if (currentfile == i)
181
    return;
182
 
183
  l = (int)strlen (fds[i]->file.ints.chars);
184
 
185
  if (as_file) {
186
    x (fprintf (as_file, "\t.file\t%d \"%s\"\n", file_dnos[i], 
187
		fds[i]->file.ints.chars+1));
188
  }
189
 
190
  out_value (file_dnos[i], ifile, make_INT64(0,l), 0);
191
  out_data (fds[i]->file.ints.chars, l);
192
 
193
  currentfile = i;
194
  return ;
195
}
196
 
197
int currentlno = -1;		/* the last line number output */
198
 
199
void stabd
200
    PROTO_N ( ( findex,lno ) )
201
    PROTO_T ( int findex X int lno )
202
{
203
  if (findex==currentfile && lno==currentlno) return;
204
  stab_file (findex);
205
  if (as_file)
206
    x (fprintf (as_file, "\t.loc\t%d %d\n", file_dnos[findex], lno));
207
  out_loc (file_dnos[findex], (unsigned)lno);
208
  currentlno = lno;
209
}
210
 
211
static char *lexlev = "0";	/* historic !!! */
212
 
213
 
214
void diagbr_open
215
    PROTO_N ( ( findex ) )
216
    PROTO_T ( int findex )
217
{
218
  int symno;
219
  stab_file (findex);
220
  symno = new_lsym_d ((char *) 0, 0, stBlock, scText, (diag_type)0,
221
      currentfile);
222
  lexlev[0]++;
223
  if (as_file){
224
    x (fprintf (as_file, "\t.bgnb\t%d\n", symno));
225
  }
226
  out_ent (symno, ibgnb, 0);
227
}
228
 
229
void diagbr_close
230
    PROTO_N ( ( findex ) )
231
    PROTO_T ( int findex )
232
{
233
  int symno;
234
  stab_file (findex);
235
  symno = new_lsym_d ((char *) 0, 0, stEnd, scText, (diag_type)0,
236
      currentfile);
237
  lexlev[0]--;
238
  if (as_file){
239
    x (fprintf (as_file, "\t.endb\t%d\n", symno));
240
  }
241
  out_ent (symno, iendb, 0);
242
}
243
 
244
 
245
 
246
/* 
247
   output appropriate rubbish to symbol table to indicate the declaration of a
248
   local identifier, nm, defined by id, displaced by disp; findex is the index
249
   of the file containing the declaration.  The text below gives o/p for
250
   identifiers allocated in registers; in fact, with current translator, 
251
   none are used by stab_local. I don't even know whether the MIPS dbx can 
252
   actually use them. 
253
*/
254
void stab_local
255
    PROTO_N ( ( nm,dt,ldid,disp,findex ) )
256
    PROTO_T ( char *nm X diag_type dt X exp ldid X int disp X int findex )
257
{
258
 
259
  int fs = frame_size >> 3;
260
  exp id = son(ldid);
261
  short   sc;
262
  int  v;
263
  disp+=no(ldid);
264
again: 
265
  if (name (id) == ident_tag) {
266
    if ((props (id) & defer_bit) == 0) {
267
      if ((props (id) & inreg_bits) != 0) {
268
	sc = scRegister;
269
	v = no (id);
270
	/*if (as_file){
271
	  x (fprintf (as_file, " # %s is in $%d\n", nm, v));
272
	  }*/
273
      }
274
      else if ((props (id) & infreg_bits) != 0) {
275
	sc = scRegister;
276
	v = (no (id) << 1) + float_register;
277
/*	  if (as_file)
278
	  x (fprintf (as_file, " # %s is in $f%d\n", nm, v - float_register));*/
279
      }
280
      else {
281
	v = ((no (id) & ~0x3f) >> 4) + (locals_offset >> 3) + disp / 8 - fs;
282
	sc = scAbs;
283
/*	  if (as_file)
284
	  x (fprintf (as_file,
285
	  " # %s is in %ld($fp)  == %ld($29)\n", nm,
286
	  v, v + fs));*/
287
 
288
      }
289
      (void)new_lsym_d (nm,v,/*(isparam(id))?stParam :*/stLocal,sc,dt,findex);
290
    }
291
    else {
292
      exp sn = son (id);
293
      int d = disp;
294
      while (sn != nilexp) {
295
	switch (name(sn)) {
296
	  case name_tag: {
297
	    disp = d + no (sn);
298
	    id = son (sn);
299
	    if (isvar (id)) dt = dt->data.ptr.object;
300
	    goto again;
301
	  }	
302
	  case reff_tag: {
303
	    d += no (sn);
304
	    sn = son (sn);
305
	    break;
306
	  }
307
	  case cont_tag: {
308
	    sn = son (sn);
309
	    break;
310
	  }
311
	  default: 
312
	  return;
313
	}
314
      }
315
    }
316
  }
317
}
318
 
319
void output_diag
320
    PROTO_N ( ( d, proc_no, e ) )
321
    PROTO_T ( diag_info *d X int proc_no X exp e )
322
{
323
  exp x;
324
  if (d->key == DIAG_INFO_SOURCE) {
325
    sourcemark * s = & d->data.source.beg;
326
    int f = find_file(s->file);
327
    stabd(f, s->line_no.nat_val.small_nat);
328
    return;
329
  }
330
  if (d->key != DIAG_INFO_ID) return;
331
  x = d->data.id_scope.access;
332
  if (isglob(son(x)) || no(son(x))==1) return;
333
  /* can't output global values as local names in dbx
334
     && not only diag use */
335
  mark_scope(e);
336
  if (props(e) & 0x80) {
337
    stabd(currentfile, currentlno+1); /* don't have proper lineno */
338
    diagbr_open(currentfile);
339
  }
340
  stab_local(d->data.id_scope.nme.ints.chars, d->data.id_scope.typ,
341
	     x,0,currentfile);
342
  if (last_param(son(x))) {
343
    stabd(currentfile, currentlno+1); /* don't have proper lineno */
344
  }    
345
  return;
346
}
347
 
348
 
349
void output_end_scope
350
    PROTO_N ( ( d,e ) )
351
    PROTO_T ( diag_info *d X exp e )
352
{
353
  if (d->key == DIAG_INFO_SOURCE) {
354
    sourcemark * s = & d->data.source.end;
355
    int f = find_file(s->file);
356
    int lno = s->line_no.nat_val.small_nat; 
357
    stabd(f, (lno==currentlno)?lno+1:lno); /*approx */
358
    return;
359
  }    	
360
  if (d -> key == DIAG_INFO_ID && props(e) & 0x80) {
361
    diagbr_close(currentfile);
362
  }  			    	 
363
}	
364
 
365
/*
366
  The following procs are concerned with expressing TDF
367
  types as dbx types.  The possible circularity of types and
368
  the vagaries of the type representation contribute to their
369
  complication.
370
*/
371
 
372
typedef struct {
373
  char *n;
374
  int  v;
375
  int   st;
376
  int   sc;
377
  diag_type s;
378
} tsym;
379
static int notsyms = 0;
380
static int nexttsym = 0;
381
static tsym * ats = (tsym *) 0;
382
 
383
 
384
/* 
385
   used to accumulate all the type reprs arising 
386
   from shapes in the program by calling addtsym .... 
387
*/
388
void addtsym
389
    PROTO_N ( ( n,v,st,sc,s ) )
390
    PROTO_T ( char *n X int v X int st X int sc X diag_type s )
391
{
392
  tsym * a;
393
  if (nexttsym >= notsyms) {
394
    ats = (tsym *) xrealloc ((void *) ats, (size_t)(nexttsym + 100) * sizeof (tsym));
395
    notsyms = nexttsym + 100;
396
  }
397
  a = &ats[nexttsym++];
398
  a -> n = n;
399
  a -> v = v;
400
  a -> st = st;
401
  a -> sc = sc;
402
  a -> s = s;
403
  return;
404
}
405
 
406
typedef struct {
407
  diag_type sutype;
408
  int   symindex;
409
} shauxt;
410
static int noshaux = 0;
411
int nextshaux = 0;
412
shauxt * shaux = (shauxt *) 0;
413
 
414
 
415
/* 
416
   used to remember all the indexes into the auxilliary 
417
   symbol table for all the shapes in the program 
418
*/
419
bool eq_sutype
420
    PROTO_N ( ( a,b ) )
421
    PROTO_T ( diag_type a X diag_type b )
422
{
423
 
424
  diag_field_list  fa;
425
  diag_field_list  fb;
426
  int j; 
427
  if (a==b) return 1;
428
  if (a->key != b->key) return 0;
429
  if (a->key != DIAG_TYPE_STRUCT && a->key != DIAG_TYPE_UNION) return 0;
430
   if (strcmp(a->data.t_struct.nme.ints.chars, b->data.t_struct.nme.ints.chars))
431
     return 0;
432
  fa = a->data.t_struct.fields;
433
  fb = b->data.t_struct.fields;
434
  if (fa->lastused != fb->lastused) return 0;
435
  for(j=fa->lastused-1; j>=0; j--) {
436
    diag_field sfa = (fa->array)[j];
437
    diag_field sfb = (fb->array)[j];
438
    if (strcmp(sfa->field_name.ints.chars, sfb->field_name.ints.chars))
439
      return 0;
440
  }
441
  return (bool)eq_shape(a->data.t_struct.tdf_shape,b->data.t_struct.tdf_shape);
442
}     
443
 
444
 
445
/* 
446
   finds the index into the auxilliary table for type s 
447
*/
448
int find_aux
449
    PROTO_N ( ( s ) )
450
    PROTO_T ( diag_type s )
451
{
452
  int   i;
453
  for (i = 0; i < nextshaux; i++) {
454
    if (eq_sutype(s, shaux[i].sutype) )
455
      return shaux[i].symindex;
456
  }
457
  return - 1;
458
}
459
 
460
 
461
/* 
462
   remembers ind as index into aux table for shape s 
463
*/
464
static void addaux
465
    PROTO_N ( ( s,ind ) )
466
    PROTO_T ( diag_type s X int ind )
467
{
468
 
469
  shauxt * x;
470
  if (nextshaux >= noshaux) {
471
    shaux = (shauxt *) xrealloc ((void *) shaux, 
472
				 (size_t)(nextshaux + 10) * sizeof (shauxt));
473
  }
474
  x = &shaux[nextshaux++];
475
  x -> sutype = s;
476
  x -> symindex = ind;
477
}
478
 
479
static diag_tagdef ** su_diags = (diag_tagdef**)0;
480
static long no_of_sus = 0;
481
static long leng_sus = 0;
482
 
483
void OUTPUT_DIAG_TAGS
484
    PROTO_Z ()
485
{
486
  /*collects structs & unions */ 
487
  diag_tagdef ** di = unit_ind_diagtags;
488
  long n = unit_no_of_diagtags;
489
  long i;
490
  long il = no_of_sus;
491
 
492
  for (i=0; i<n; ++i){
493
    diag_type d = di[i]->d_type;
494
    switch (d -> key){
495
      case DIAG_TYPE_STRUCT:
496
      case DIAG_TYPE_UNION: {
497
	int j;
498
	for(j=0; j < il; j++) {
499
	  if (eq_sutype(d, su_diags[j]->d_type)) break;
500
	}
501
	if (j!=il) break;
502
	if (no_of_sus >= leng_sus) {
503
	  su_diags = (diag_tagdef**)xrealloc(su_diags, 
504
				 (size_t)(leng_sus+=20)*sizeof(diag_tagdef*));
505
	}	
506
	su_diags[no_of_sus++] = di[i];
507
	break;
508
      }	
509
      default: break;
510
    }
511
  }	
512
  return;
513
}
514
 
515
 
516
 
517
/* 
518
   outputs symbol table info for all struct & union  in program 
519
*/
520
void stab_types
521
    PROTO_Z ()
522
{
523
  int i;
524
  int firsts = get_sym_index (mainfile);
525
  for (i = 0; i < no_of_sus; ++i) {/* treat struct shapes */
526
    int   j;
527
    diag_tagdef * sc = su_diags[i];
528
    switch (sc->d_type->key) {
529
      case DIAG_TYPE_STRUCT: 
530
      case DIAG_TYPE_UNION: {
531
	diag_field_list  fields = sc->d_type->data.t_struct.fields;
532
	shape s = sc->d_type->data.t_struct.tdf_shape;
533
	char * nme = sc->d_type->data.t_struct.nme.ints.chars;
534
	addaux(sc->d_type, nexttsym+firsts);
535
	addtsym(nme, shape_size(s)>>3, stBlock, scInfo, sc->d_type);
536
	for(j=fields->lastused-1; j>=0; j--) {
537
	  diag_field sf = (fields->array)[j];
538
	  addtsym(sf->field_name.ints.chars, no(sf->where), stMember, scInfo, 
539
		  sf->field_type); 
540
	}
541
	break;
542
      }
543
      default: ;
544
    } 
545
    addtsym ("", 0, stEnd, scInfo, (diag_type)0);
546
  }
547
 
548
  for (i = 0; i < nexttsym; i++) {/* output accumulated type info */
549
    tsym * t = &ats[i];
550
    (void) new_lsym (t -> n, t -> v, t -> st, t -> sc, t->s, mainfile);
551
  }
552
 
553
  for (i = 0; i < unit_diagvar_tab.lastused; ++i) {
554
  /* associated names of types */
555
    diag_descriptor * dd = unit_diagvar_tab.array+i;
556
    if (dd->key == DIAG_TYPEDEF_KEY) {
557
      (void)new_lsym_d(dd->data.typ.nme.ints.chars, 0, stTypedef, scInfo, 
558
		       dd->data.typ.new_type, mainfile); 
559
    }
560
  }
561
  free (ats);
562
  return;
563
}
564
 
565
 
566
 
567
 
568
 
569
 
570