Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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