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
    Copyright (c) 1993 Open Software Foundation, Inc.
32
    Copyright (c) 1993 Open Software Foundation, Inc.
3
 
33
 
4
 
34
 
5
    All Rights Reserved
35
    All Rights Reserved
Line 14... Line 44...
14
 
44
 
15
    OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING
45
    OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING
16
    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
46
    ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
17
    PARTICULAR PURPOSE.
47
    PARTICULAR PURPOSE.
18
 
48
 
19
 
49
 
20
    IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
50
    IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
21
    CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
51
    CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
22
    LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
52
    LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
23
    NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
53
    NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
24
    WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
54
    WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25
*/
55
*/
26
 
56
 
27
/*
57
/*
28
    		 Crown Copyright (c) 1997
58
    		 Crown Copyright (c) 1997
29
    
59
 
30
    This TenDRA(r) Computer Program is subject to Copyright
60
    This TenDRA(r) Computer Program is subject to Copyright
31
    owned by the United Kingdom Secretary of State for Defence
61
    owned by the United Kingdom Secretary of State for Defence
32
    acting through the Defence Evaluation and Research Agency
62
    acting through the Defence Evaluation and Research Agency
33
    (DERA).  It is made available to Recipients with a
63
    (DERA).  It is made available to Recipients with a
34
    royalty-free licence for its use, reproduction, transfer
64
    royalty-free licence for its use, reproduction, transfer
35
    to other parties and amendment for any purpose not excluding
65
    to other parties and amendment for any purpose not excluding
36
    product development provided that any such use et cetera
66
    product development provided that any such use et cetera
37
    shall be deemed to be acceptance of the following conditions:-
67
    shall be deemed to be acceptance of the following conditions:-
38
    
68
 
39
        (1) Its Recipients shall ensure that this Notice is
69
        (1) Its Recipients shall ensure that this Notice is
40
        reproduced upon any copies or amended versions of it;
70
        reproduced upon any copies or amended versions of it;
41
    
71
 
42
        (2) Any amended version of it shall be clearly marked to
72
        (2) Any amended version of it shall be clearly marked to
43
        show both the nature of and the organisation responsible
73
        show both the nature of and the organisation responsible
44
        for the relevant amendment or amendments;
74
        for the relevant amendment or amendments;
45
    
75
 
46
        (3) Its onward transfer from a recipient to another
76
        (3) Its onward transfer from a recipient to another
47
        party shall be deemed to be that party's acceptance of
77
        party shall be deemed to be that party's acceptance of
48
        these conditions;
78
        these conditions;
49
    
79
 
50
        (4) DERA gives no warranty or assurance as to its
80
        (4) DERA gives no warranty or assurance as to its
51
        quality or suitability for any purpose and DERA accepts
81
        quality or suitability for any purpose and DERA accepts
52
        no liability whatsoever in relation to any use to which
82
        no liability whatsoever in relation to any use to which
53
        it may be put.
83
        it may be put.
54
*/
84
*/
Line 83... Line 113...
83
#include CROSS_INCLUDE/dbxstclass.h>
113
#include CROSS_INCLUDE/dbxstclass.h>
84
#include CROSS_INCLUDE/sys/debug.h>
114
#include CROSS_INCLUDE/sys/debug.h>
85
#else
115
#else
86
#include <dbxstclass.h>
116
#include <dbxstclass.h>
87
#include <sys/debug.h>
117
#include <sys/debug.h>
88
#endif
118
#endif
89
 
119
 
90
#include "common_types.h"
120
#include "common_types.h"
91
#include "memtdf.h"
121
#include "memtdf.h"
92
#include "installglob.h"
122
#include "installglob.h"
93
#include "li_types.h"
123
#include "li_types.h"
94
#include "diagtypes.h"
124
#include "diagtypes.h"
Line 109... Line 139...
109
#include "comment.h"
139
#include "comment.h"
110
#include "myassert.h"
140
#include "myassert.h"
111
#include "stack.h"
141
#include "stack.h"
112
#include "diagout.h"
142
#include "diagout.h"
113
 
143
 
114
 
144
 
115
 
145
 
116
/* configuration options */
146
/* configuration options */
117
 
147
 
118
/* maximum .bb/.eb nesting depth in output, negative value implies no limit */
148
/* maximum .bb/.eb nesting depth in output, negative value implies no limit */
119
#ifndef MAX_BLOCK_DEPTH
149
#ifndef MAX_BLOCK_DEPTH
120
#define MAX_BLOCK_DEPTH		1	/* more than one seems to upset dbx */
150
#define MAX_BLOCK_DEPTH		1	/* more than one seems to upset dbx */
121
#endif
151
#endif
122
 
152
 
123
 
153
 
124
 
154
 
125
 
155
 
126
/* special line number codes */
156
/* special line number codes */
127
#define UNKNOWN			(-9999)
157
#define UNKNOWN			(-9999)
128
#define NOT_IN_PROC		(-9998)
158
#define NOT_IN_PROC		(-9998)
129
 
159
 
130
 
160
 
Line 139... Line 169...
139
#define TYPEID_REAL		8
169
#define TYPEID_REAL		8
140
#define TYPEID_DOUBLE		9
170
#define TYPEID_DOUBLE		9
141
#define TYPEID_VOID		10
171
#define TYPEID_VOID		10
142
#define TYPEID_TOKEN		11
172
#define TYPEID_TOKEN		11
143
 
173
 
144
 
174
 
145
 
175
 
146
/* tdfstring -> nul terminated C string (char *) */
176
/* tdfstring -> nul terminated C string (char *) */
147
#define CSTRING(tdfstring)	((tdfstring).ints.chars)
177
#define CSTRING(tdfstring)	((tdfstring).ints.chars)
148
 
178
 
149
/* tdf exp -> C int */
179
/* tdf exp -> C int */
150
#define EXPINT(exp)		(ASSERT(name(exp) == val_tag) , no(exp))
180
#define EXPINT(exp)		(ASSERT(name(exp) == val_tag), no(exp))
151
 
181
 
152
/* tdf nat -> C int */
182
/* tdf nat -> C int */
153
#define NATINT(n)		((n).nat_val.small_nat)
183
#define NATINT(n)		((n).nat_val.small_nat)
154
 
184
 
155
 
185
 
Line 157... Line 187...
157
/*
187
/*
158
 * Query and set "been_outed" field, which may hold
188
 * Query and set "been_outed" field, which may hold
159
 * stabstring TypeNo if type has already been output.
189
 * stabstring TypeNo if type has already been output.
160
 */
190
 */
161
 
191
 
162
#define	CLR_OUTED_NO(dt)	((dt)->been_outed = (OUTPUT_REC)0)
192
#define	CLR_OUTED_NO(dt)	((dt) ->been_outed = (OUTPUT_REC)0)
163
#define	SET_OUTED_NO(dt,i)	((dt)->been_outed = (OUTPUT_REC)(i))
193
#define	SET_OUTED_NO(dt,i)	((dt) ->been_outed = (OUTPUT_REC)(i))
164
#define	OUTED_NO(dt)		((int)(dt)->been_outed)
194
#define	OUTED_NO(dt)		((int)(dt) ->been_outed)
165
#define	IS_OUTED(dt)		((dt)->been_outed != 0)
195
#define	IS_OUTED(dt)		((dt) ->been_outed != 0)
166
 
196
 
167
 
197
 
168
/*
198
/*
169
 * Params for stab_relativeline().
199
 * Params for stab_relativeline().
170
 */
200
 */
Line 198... Line 228...
198
/*
228
/*
199
 * Struct/union type information.
229
 * Struct/union type information.
200
 * (See function OUTPUT_DIAG_TAGS)
230
 * (See function OUTPUT_DIAG_TAGS)
201
 */
231
 */
202
 
232
 
203
static diag_tagdef **su_diags = (diag_tagdef **) 0;
233
static diag_tagdef **su_diags = (diag_tagdef **)0;
204
static int no_of_sus = 0;
234
static int no_of_sus = 0;
205
static int leng_sus = 0;
235
static int leng_sus = 0;
206
 
236
 
207
/*
237
/*
208
 * Typedef information
238
 * Typedef information
209
 * (See function OUTPUT_GLOBALS_TAB)
239
 * (See function OUTPUT_GLOBALS_TAB)
210
 */
240
 */
211
 
241
 
212
static diag_descriptor **typedef_diags = (diag_descriptor ** ) 0;
242
static diag_descriptor **typedef_diags = (diag_descriptor **)0;
213
static int no_of_typedefs = 0;
243
static int no_of_typedefs = 0;
214
static int leng_typedefs = 0;
244
static int leng_typedefs = 0;
215
 
245
 
216
/*
246
/*
217
 * Shapes we need, set in init_diag.
247
 * Shapes we need, set in init_diag.
Line 223... Line 253...
223
 
253
 
224
/*
254
/*
225
 * Static procs.
255
 * Static procs.
226
 */
256
 */
227
 
257
 
228
static diag_descriptor *find_dd PROTO_S ((exp));
258
static diag_descriptor *find_dd(exp);
229
static int find_file PROTO_S ((char *));
259
static int find_file(char *);
230
static void stab_relativeline PROTO_S ((CONST char *));
260
static void stab_relativeline(CONST char *);
231
static void stab_begin_block PROTO_S ((void));
261
static void stab_begin_block(void);
232
static void stab_end_block PROTO_S ((void));
262
static void stab_end_block(void);
233
static void stabn PROTO_S ((int, int));
263
static void stabn(int, int);
234
static void stab_file PROTO_S ((int));
264
static void stab_file(int);
235
static void diagbr_open PROTO_S ((int));
265
static void diagbr_open(int);
236
static void diagbr_close PROTO_S ((int));
266
static void diagbr_close(int);
237
static int next_typen PROTO_S ((void));
267
static int next_typen(void);
238
static int TypeNo_of_shape PROTO_S ((shape));
268
static int TypeNo_of_shape(shape);
239
static bool eq_sutype PROTO_S ((diag_type, diag_type));
269
static bool eq_sutype(diag_type, diag_type);
240
static bool eq_typedef_type PROTO_S ((diag_descriptor *,diag_descriptor *));
270
static bool eq_typedef_type(diag_descriptor *,diag_descriptor *);
241
static int size_dt PROTO_S ((diag_type));
271
static int size_dt(diag_type);
242
static void out_dt_TypeDef_no_recurse PROTO_S ((diag_type));
272
static void out_dt_TypeDef_no_recurse(diag_type);
243
static void out_dt_TypeDef PROTO_S ((diag_type));
273
static void out_dt_TypeDef(diag_type);
244
static void out_dt_NewTypeId PROTO_S ((diag_type, int));
274
static void out_dt_NewTypeId(diag_type, int);
245
static void out_dt_TypeId PROTO_S ((diag_type));
275
static void out_dt_TypeId(diag_type);
246
static void stab_internal_types PROTO_S ((diag_type, bool));
276
static void stab_internal_types(diag_type, bool);
247
static void stab_types PROTO_S ((void));
277
static void stab_types(void);
-
 
278
 
-
 
279
static void number_and_stab_basicshapes(void);
-
 
280
static void number_structs_and_unions(void);
-
 
281
static void stab_structs_and_unions(void);
-
 
282
static void number_typedefs(void);
-
 
283
static void stab_typedefs(void);
-
 
284
static void stab_basicshape(shape,char * ,int,int);
248
 
285
 
249
static void number_and_stab_basicshapes PROTO_S ((void));
-
 
250
static void number_structs_and_unions PROTO_S ((void));
-
 
251
static void stab_structs_and_unions PROTO_S ((void));
-
 
252
static void number_typedefs PROTO_S ((void));
-
 
253
static void stab_typedefs PROTO_S ((void));
-
 
254
static void stab_basicshape PROTO_S ((shape,char * ,int,int));
-
 
255
 
286
 
256
  
-
 
257
/*(See diag_config.h)
287
/*(See diag_config.h)
258
 * remember a filename so that find_file() can map onto filename number
288
 * remember a filename so that find_file() can map onto filename number
259
 */
289
 */
260
void INSPECT_FILENAME PROTO_N ((f)) PROTO_T (filename f)
290
void INSPECT_FILENAME(filename f)
261
{
291
{
262
  FULLCOMMENT2("INSPECT_FILENAME %d: '%s'", nofds, (int) CSTRING(f->file));
292
  FULLCOMMENT2("INSPECT_FILENAME %d: '%s'", nofds,(int)CSTRING(f->file));
263
  
293
 
264
  if (fds == (filename *) 0)
294
  if (fds == (filename *)0)
265
  {
295
  {
266
    fds = (filename *) xmalloc((szfds += 5) * sizeof (filename));
296
    fds = (filename *)xmalloc((szfds += 5)* sizeof(filename));
267
  }
297
  }
268
  else if (nofds >= szfds)
298
  else if (nofds >= szfds)
269
  {
299
  {
270
    fds = (filename *) xrealloc(fds, (szfds += 5) * sizeof (filename));
300
    fds = (filename *)xrealloc(fds,(szfds += 5)* sizeof(filename));
271
  }
301
  }
272
  
302
 
273
  fds[nofds] = f;
303
  fds[nofds] = f;
274
 
304
 
275
  /*
305
  /*
276
   * The following is taken from trans386/dwarf/dwarf_out.c.
306
   * The following is taken from trans386/dwarf/dwarf_out.c.
277
   * It works out the main source filename. There must be a better way. +++
307
   * It works out the main source filename. There must be a better way. +++
278
   */
308
   */
279
  if (mainfile_fd < 0)
309
  if (mainfile_fd < 0)
280
  {
310
  {
281
    /* use heuristic to see if this is 'main source file' */
311
    /* use heuristic to see if this is 'main source file' */
282
    char *lastdot = strrchr(CSTRING(f->file), '.');
312
    char *lastdot = strrchr(CSTRING(f->file), '.');
283
    
313
 
284
    /* XXX.h not considered 'main source file' */
314
    /* XXX.h not considered 'main source file' */
285
    if (lastdot != 0 && lastdot[1] != 'h')
315
    if (lastdot != 0 && lastdot[1]!= 'h')
286
      mainfile_fd = nofds;
316
      mainfile_fd = nofds;
287
  }
317
  }
288
 
318
 
289
  nofds++;
319
  nofds++;
290
  return;
320
  return;
291
}
321
}
292
 
322
 
293
/*(See diag_config.h)
323
/*(See diag_config.h)
294
 * outputs structs & unions from global level types
324
 * outputs structs & unions from global level types
295
 */
325
 */
296
void OUTPUT_DIAG_TAGS PROTO_Z ()
326
void OUTPUT_DIAG_TAGS(void)
297
{
327
{
298
  diag_tagdef **di = unit_ind_diagtags;
328
  diag_tagdef **di = unit_ind_diagtags;
299
  unsigned int n = unit_no_of_diagtags;
329
  unsigned int n = unit_no_of_diagtags;
300
  int i;
330
  int i;
301
  int il = no_of_sus; /* There should be no clashes within a single unit so we save a bit of time here */
331
  int il = no_of_sus; /* There should be no clashes within a single unit so we save a bit of time here */
302
  
332
 
303
  for (i = 0; i < n; ++i)
333
  for (i = 0; i < n; ++i)
304
  {
334
  {
305
    diag_type d = di[i]->d_type;
335
    diag_type d = di[i] ->d_type;
306
    
336
 
307
    switch (d->key)
337
    switch (d->key)
308
    {
338
    {
309
     case DIAG_TYPE_STRUCT:
339
     case DIAG_TYPE_STRUCT:
310
     case DIAG_TYPE_UNION:
340
     case DIAG_TYPE_UNION:
311
      {
341
      {
312
	int j;
342
	int j;
313
	
343
 
314
	for (j = 0; j < il; j++)
344
	for (j = 0; j < il; j++)
315
	{
345
	{
316
	  /* Check we have not done already */
346
	  /* Check we have not done already */
317
	  if (eq_sutype(d, su_diags[j]->d_type))
347
	  if (eq_sutype(d, su_diags[j] ->d_type))
318
	  {
348
	  {
319
	    break;
349
	    break;
320
	  }
350
	  }
321
	}
351
	}
322
	if (j != il)
352
	if (j != il)
323
	{
353
	{
324
	  break;
354
	  break;
325
	}
355
	}
326
	if (no_of_sus >= leng_sus)
356
	if (no_of_sus >= leng_sus)
327
	{
357
	{
328
	  if (su_diags == (diag_tagdef **) 0)
358
	  if (su_diags == (diag_tagdef **)0)
329
	  {
359
	  {
330
	    su_diags=(diag_tagdef**)xmalloc((leng_sus+=20)*sizeof(diag_tagdef*));
360
	    su_diags= (diag_tagdef**)xmalloc((leng_sus+=20)*sizeof(diag_tagdef*));
331
	  }
361
	  }
332
	  else
362
	  else
333
	  {
363
	  {
334
	    su_diags=(diag_tagdef**)xrealloc(su_diags,(leng_sus+=20)*sizeof(diag_tagdef*));
364
	    su_diags= (diag_tagdef**)xrealloc(su_diags,(leng_sus+=20)*sizeof(diag_tagdef*));
335
	  }
365
	  }
336
	}
366
	}
337
	/* Set up the appropriate member of the su_diags array */
367
	/* Set up the appropriate member of the su_diags array */
338
	su_diags[no_of_sus++] = di[i];
368
	su_diags[no_of_sus++] = di[i];
339
	break;
369
	break;
Line 345... Line 375...
345
  return;
375
  return;
346
}
376
}
347
/*
377
/*
348
 * Collects information
378
 * Collects information
349
 */
379
 */
350
void OUTPUT_GLOBALS_TAB PROTO_Z ()
380
void OUTPUT_GLOBALS_TAB(void)
351
{
381
{
352
  diag_descriptor * unit_typedef_array = unit_diagvar_tab.array;
382
  diag_descriptor * unit_typedef_array = unit_diagvar_tab.array;
353
  unsigned int no_of_typedefs_in_unit =unit_diagvar_tab.lastused;
383
  unsigned int no_of_typedefs_in_unit =unit_diagvar_tab.lastused;
354
  int i;
384
  int i;
355
  int il = no_of_typedefs;
385
  int il = no_of_typedefs;
356
  
386
 
357
  for(i=0 ; i<=no_of_typedefs_in_unit ; i++)
387
  for (i=0; i<=no_of_typedefs_in_unit; i++)
358
  {
388
  {
359
    diag_descriptor * dd = unit_typedef_array + i;
389
    diag_descriptor * dd = unit_typedef_array + i;
360
    
390
 
361
    switch (dd->key)
391
    switch (dd->key)
362
    {
392
    {
363
     case DIAG_TYPEDEF_KEY:
393
     case DIAG_TYPEDEF_KEY:
364
      {
394
      {
365
	int j;
395
	int j;
366
	
396
 
367
	/* Check that we have not done already */
397
	/* Check that we have not done already */
368
	for(j=0; j < il ; j++)
398
	for (j=0; j < il; j++)
369
	{
399
	{
370
	  if(eq_typedef_type(dd,typedef_diags[j]))
400
	  if (eq_typedef_type(dd,typedef_diags[j]))
371
	  {
401
	  {
372
	    break;
402
	    break;
373
	  }
403
	  }
374
	}
404
	}
375
	if( j != il )
405
	if (j != il)
376
	{
406
	{
377
	  break;
407
	  break;
378
	}
408
	}
379
	
409
 
380
	/* We have a new one */
410
	/* We have a new one */
381
	if (no_of_typedefs >= leng_typedefs)
411
	if (no_of_typedefs >= leng_typedefs)
382
	{ 
412
	{
383
	  if(typedef_diags == (diag_descriptor **) 0)
413
	  if (typedef_diags == (diag_descriptor **)0)
384
	  {
414
	  {
385
	    typedef_diags = (diag_descriptor **)xmalloc ((leng_typedefs+=20)*sizeof(diag_descriptor *));
415
	    typedef_diags = (diag_descriptor **)xmalloc((leng_typedefs+=20)*sizeof(diag_descriptor *));
386
	  }
416
	  }
387
	  else
417
	  else
388
	  {
418
	  {
389
	    typedef_diags = (diag_descriptor **)xrealloc(typedef_diags,(leng_typedefs+=20)*sizeof(diag_descriptor *));
419
	    typedef_diags = (diag_descriptor **)xrealloc(typedef_diags,(leng_typedefs+=20)*sizeof(diag_descriptor *));
390
	  }
420
	  }
391
	}
421
	}
392
	typedef_diags[no_of_typedefs++]=dd;
422
	typedef_diags[no_of_typedefs++] =dd;
393
      }
423
      }
394
      break;
424
      break;
395
     default:
425
     default:
396
      break;
426
      break;
397
    }
427
    }
398
  }
428
  }
399
}
429
}
400
 
430
 
401
 
431
 
402
static void number_and_stab_basicshapes PROTO_Z ()
432
static void number_and_stab_basicshapes(void)
403
{
433
{
404
  /* NOTE: char is unsigned char */
434
  /* NOTE: char is unsigned char */
405
  stab_basicshape(scharsh ,"signed char"   , TYPEID_SCHAR , TP_SCHAR);
435
  stab_basicshape(scharsh ,"signed char"   , TYPEID_SCHAR , TP_SCHAR);
406
  stab_basicshape(ucharsh ,"char"          , TYPEID_UCHAR , TP_CHAR);
436
  stab_basicshape(ucharsh ,"char"          , TYPEID_UCHAR , TP_CHAR);
407
  stab_basicshape(swordsh ,"short"         , TYPEID_SWORD , TP_SHORT);
437
  stab_basicshape(swordsh ,"short"         , TYPEID_SWORD , TP_SHORT);
Line 435... Line 465...
435
    fprintf(as_file, "\",%d,%d,%d\n", 0, C_DECL, 0);
465
    fprintf(as_file, "\",%d,%d,%d\n", 0, C_DECL, 0);
436
  }
466
  }
437
#endif
467
#endif
438
}
468
}
439
 
469
 
440
static void number_structs_and_unions PROTO_Z ()
470
static void number_structs_and_unions(void)
441
{
471
{
442
  int i;
472
  int i;
443
  
473
 
444
  for (i = 0; i < no_of_sus; ++i)
474
  for (i = 0; i < no_of_sus; ++i)
445
  {
475
  {
446
    SET_OUTED_NO(su_diags[i]->d_type, next_typen());
476
    SET_OUTED_NO(su_diags[i] ->d_type, next_typen());
447
  }
477
  }
448
}
478
}
449
static void number_typedefs PROTO_Z ()
479
static void number_typedefs(void)
450
{
480
{
451
  int i;
481
  int i;
452
  
482
 
453
  for (i=0;i<no_of_typedefs; i++)
483
  for (i=0;i<no_of_typedefs; i++)
454
  {
484
  {
455
    if (!IS_OUTED(typedef_diags[i]->data.typ.new_type))
485
    if (!IS_OUTED(typedef_diags[i] ->data.typ.new_type))
456
    {
486
    {
457
      SET_OUTED_NO(typedef_diags[i]->data.typ.new_type,next_typen());
487
      SET_OUTED_NO(typedef_diags[i] ->data.typ.new_type,next_typen());
458
    }
488
    }
459
  }
489
  }
460
}
490
}
461
  
491
 
462
static void stab_structs_and_unions PROTO_Z ()
492
static void stab_structs_and_unions(void)
463
{
493
{
464
  int i;
494
  int i;
465
  
495
 
466
  for (i = 0; i < no_of_sus; ++i)
496
  for (i = 0; i < no_of_sus; ++i)
467
  {
497
  {
468
    int non;
498
    int non;
469
    diag_type dt = su_diags[i]->d_type;
499
    diag_type dt = su_diags[i] ->d_type;
470
    char *nme = (dt->key == DIAG_TYPE_STRUCT)
500
    char *nme = (dt->key == DIAG_TYPE_STRUCT)
471
			? CSTRING(dt->data.t_struct.nme)
501
			? CSTRING(dt->data.t_struct.nme)
472
			: CSTRING(dt->data.t_union.nme);
502
			: CSTRING(dt->data.t_union.nme);
473
 
503
 
474
    COMMENT2("su_diags: is_struct=%d nme='%s'", dt->key == DIAG_TYPE_STRUCT, (int) nme);
504
    COMMENT2("su_diags: is_struct=%d nme='%s'", dt->key == DIAG_TYPE_STRUCT,(int)nme);
475
 
505
 
476
    stab_internal_types(dt, 0);
506
    stab_internal_types(dt, 0);
477
 
507
 
478
    if (nme == (char *) 0 || *nme == (char) 0)
508
    if (nme == (char *)0 || *nme == (char)0)
479
    {
509
    {
480
      /*
510
      /*
481
       * Output unnamed object here for 2 reasons:
511
       * Output unnamed object here for 2 reasons:
482
       *	1) gdb (but not dbx) is confused by Typeid which includes a
512
       *	1) gdb (but not dbx) is confused by Typeid which includes a
483
       *	   full TypeDef and treats it as an anonymous struct.
513
       *	   full TypeDef and treats it as an anonymous struct.
Line 496... Line 526...
496
    CLR_OUTED_NO(dt);			/* avoid identity */
526
    CLR_OUTED_NO(dt);			/* avoid identity */
497
    out_dt_NewTypeId(dt, non);
527
    out_dt_NewTypeId(dt, non);
498
 
528
 
499
    fprintf(as_file, "\",%d,%d,%d\n", 0, C_DECL, 0);
529
    fprintf(as_file, "\",%d,%d,%d\n", 0, C_DECL, 0);
500
  }
530
  }
501
}  
531
}
502
static void stab_typedefs PROTO_Z ()
532
static void stab_typedefs(void)
503
{
533
{
504
  int i;
534
  int i;
505
  for(i=0;i<no_of_typedefs;i++)
535
  for (i=0;i<no_of_typedefs;i++)
506
  {
536
  {
507
    diag_descriptor * dd = typedef_diags[i];
537
    diag_descriptor * dd = typedef_diags[i];
508
    int non;
538
    int non;
509
    diag_type dt = dd->data.typ.new_type;
539
    diag_type dt = dd->data.typ.new_type;
510
    stab_internal_types(dt,0);
540
    stab_internal_types(dt,0);
511
    ASSERT(CSTRING(dd->data.typ.nme)[0]!=0);/* Not an empty string */
541
    ASSERT(CSTRING(dd->data.typ.nme)[0]!=0);/* Not an empty string */
512
 
542
 
513
    fprintf(as_file, "\t.stabx\t\"%s:t", CSTRING(dd->data.typ.nme));
543
    fprintf(as_file, "\t.stabx\t\"%s:t", CSTRING(dd->data.typ.nme));
514
    
544
 
515
    non = OUTED_NO(dt);
545
    non = OUTED_NO(dt);
516
    CLR_OUTED_NO(dt);			/* avoid identity */
546
    CLR_OUTED_NO(dt);			/* avoid identity */
517
    out_dt_NewTypeId(dt, non);
547
    out_dt_NewTypeId(dt, non);
518
    
548
 
519
    fprintf(as_file, "\",%d,%d,%d\n", 0, C_DECL, 0);
549
    fprintf(as_file, "\",%d,%d,%d\n", 0, C_DECL, 0);
520
  }
550
  }
521
}
551
}
522
 
552
 
523
/*
553
/*
524
 * init_diag - used by translate_capsule() to initialise diagnostics.
554
 * init_diag - used by translate_capsule() to initialise diagnostics.
525
 */
555
 */
526
void init_diag PROTO_Z ()
556
void init_diag(void)
527
{
557
{
528
  /* 
558
  /*
529
   * Initialisation of diagnostics 
559
   * Initialisation of diagnostics
530
   */
560
   */
531
  current_fileno = UNKNOWN;
561
  current_fileno = UNKNOWN;
532
  current_procstart_lineno = NOT_IN_PROC;
562
  current_procstart_lineno = NOT_IN_PROC;
533
  current_lineno = NOT_IN_PROC;
563
  current_lineno = NOT_IN_PROC;
534
  files_stabbed = 0;
564
  files_stabbed = 0;
535
  first_fileno = -100;
565
  first_fileno = -100;
536
  stab_file(mainfile_fd);
566
  stab_file(mainfile_fd);
537
  voidsh = getshape(0, 0, 0, TOP_ALIGN, TOP_SZ, tophd);/* very dubious */
567
  voidsh = getshape(0, 0, 0, TOP_ALIGN, TOP_SZ, tophd);/* very dubious */
538
  tokensh = getshape(0, 0, 0, TOP_ALIGN, TOP_SZ, bothd);/* very dubious */
568
  tokensh = getshape(0, 0, 0, TOP_ALIGN, TOP_SZ, bothd);/* very dubious */
539
  stab_types();
569
  stab_types();
540
  return;
570
  return;
541
}
571
}
542
 
572
 
543
 
573
 
544
/*
574
/*
545
 * Correct the name for non externs (eg C static) to keep dbx happy.
575
 * Correct the name for non externs (eg C static) to keep dbx happy.
546
 * gdb happily uses the stab info to override the assembler label,
576
 * gdb happily uses the stab info to override the assembler label,
547
 * but dbx does not.  local_prefix names (eg S.999) upset dbx,
577
 * but dbx does not.  local_prefix names (eg S.999) upset dbx,
548
 * partcularly on stack tracebacks from 'where'.  If we find that
578
 * partcularly on stack tracebacks from 'where'.  If we find that
549
 * the name is already in use, eg possibly from nested C static
579
 * the name is already in use, eg possibly from nested C static
550
 * we change the name to "S.NNN.name" to add meaning, but stay unique.
580
 * we change the name to "S.NNN.name" to add meaning, but stay unique.
551
 */
581
 */
552
void fixup_name PROTO_N ((global,top_def,crt_def)) PROTO_T (exp global X dec * top_def X dec * crt_def)
582
void fixup_name(exp global, dec * top_def, dec * crt_def)
553
{
583
{
554
  diag_descriptor *dd;
584
  diag_descriptor *dd;
555
  dec *d;
585
  dec *d;
556
  char *id = crt_def->dec_u.dec_val.dec_id;	/* assembler label */
586
  char *id = crt_def->dec_u.dec_val.dec_id;	/* assembler label */
557
  char *nm;			/* real name, or uniqued real name */
587
  char *nm;			/* real name, or uniqued real name */
Line 559... Line 589...
559
  /*
589
  /*
560
   * Externs have correct name currently.
590
   * Externs have correct name currently.
561
   * Any name not starting with local_prefix is special, leave it.
591
   * Any name not starting with local_prefix is special, leave it.
562
   */
592
   */
563
  if (crt_def->dec_u.dec_val.extnamed ||
593
  if (crt_def->dec_u.dec_val.extnamed ||
564
      id[0] != local_prefix[0] || id[1] != local_prefix[1])
594
      id[0]!= local_prefix[0] || id[1]!= local_prefix[1])
565
  {
595
  {
566
    return;			/* externs have correct name currently */
596
    return;			/* externs have correct name currently */
567
  }
597
  }
568
 
598
 
569
  dd = find_dd(global);
599
  dd = find_dd(global);
570
 
600
 
571
  if (dd == (diag_descriptor *) 0)
601
  if (dd == (diag_descriptor *)0)
572
  {
602
  {
573
    /* eg string constant or currently static within proc */
603
    /* eg string constant or currently static within proc */
574
    FULLCOMMENT("correct_name: no descriptor");
604
    FULLCOMMENT("correct_name: no descriptor");
575
    return;
605
    return;
576
  }
606
  }
577
 
607
 
578
  nm = CSTRING(dd->data.id.nme);
608
  nm = CSTRING(dd->data.id.nme);
579
 
609
 
580
  /* search def chain to see if name is already used as assembler label */
610
  /* search def chain to see if name is already used as assembler label */
581
  for (d = top_def; d != crt_def && d != (dec *) 0; d = d->def_next)
611
  for (d = top_def; d != crt_def && d != (dec *)0; d = d->def_next)
582
  {
612
  {
583
    if (strcmp(nm, d->dec_u.dec_val.dec_id) == 0)
613
    if (strcmp(nm, d->dec_u.dec_val.dec_id) == 0)
584
    {
614
    {
585
 
615
 
586
      /*
616
      /*
Line 595... Line 625...
595
      strcpy(newid, id);
625
      strcpy(newid, id);
596
      newid[len1] = '.';
626
      newid[len1] = '.';
597
      strcpy(&newid[len1 + 1], nm);
627
      strcpy(&newid[len1 + 1], nm);
598
      nm = newid;
628
      nm = newid;
599
      break;
629
      break;
600
    }
630
    }
601
  }
631
  }
602
 
632
 
603
  crt_def->dec_u.dec_val.dec_id = nm;	/* change label to real identifier
633
  crt_def->dec_u.dec_val.dec_id = nm;	/* change label to real identifier
604
					 * name */
634
					 * name */
605
}
635
}
606
 
636
 
607
 
637
 
608
/*
638
/*
609
 * output_diag - used by make_code() to implement "diagnose_tag".
639
 * output_diag - used by make_code() to implement "diagnose_tag".
610
 */
640
 */
611
void output_diag PROTO_N ((d,proc_no,e)) PROTO_T (diag_info * d X int proc_no X exp e)
641
void output_diag(diag_info * d, int proc_no, exp e)
612
{
642
{
613
  exp id;
643
  exp id;
614
  
644
 
615
  FULLCOMMENT1("output_diag: key=%d", d->key);
645
  FULLCOMMENT1("output_diag: key=%d", d->key);
616
  
646
 
617
  if (d->key == DIAG_INFO_SOURCE)
647
  if (d->key == DIAG_INFO_SOURCE)
618
  {
648
  {
619
    sourcemark *s = &d->data.source.beg;
649
    sourcemark *s = &d->data.source.beg;
620
    int f = find_file(CSTRING(s->file->file));
650
    int f = find_file(CSTRING(s->file->file));
621
 
651
 
622
    stabn(f, NATINT(s->line_no));
652
    stabn(f, NATINT(s->line_no));
623
    return;
653
    return;
624
  }
654
  }
625
 
655
 
626
  if (d->key != DIAG_INFO_ID)
656
  if (d->key != DIAG_INFO_ID)
627
  {
657
  {
628
    FULLCOMMENT1("output_diag: unsupported key=%d", d->key);
658
    FULLCOMMENT1("output_diag: unsupported key=%d", d->key);
629
    return;
659
    return;
630
  }
660
  }
631
 
661
 
632
  id = son(d->data.id_scope.access);
662
  id = son(d->data.id_scope.access);
633
 
663
 
634
  FULLCOMMENT3("output_diag: DIAG_INFO_ID %s isglob(id)=%d no(id)=%d",
664
  FULLCOMMENT3("output_diag: DIAG_INFO_ID %s isglob(id) =%d no(id) =%d",
635
	       (int) CSTRING(d->data.id_scope.nme), isglob(id), no(id));
665
	      (int)CSTRING(d->data.id_scope.nme), isglob(id), no(id));
636
 
666
 
637
  /* can't output global values as local names */
667
  /* can't output global values as local names */
638
  if (isglob(id))
668
  if (isglob(id))
639
  {
669
  {
640
    return;
670
    return;
641
  }
671
  }
642
  
672
 
643
  ASSERT(name(id) == ident_tag);
673
  ASSERT(name(id) == ident_tag);
644
 
674
 
645
  mark_scope(e);
675
  mark_scope(e);
646
  FULLCOMMENT1("output_diag: DIAG_INFO_ID mark_scope props(e)=%#x", props(e));
676
  FULLCOMMENT1("output_diag: DIAG_INFO_ID mark_scope props(e) =%#x", props(e));
647
 
677
 
648
  if (props(e) & 0x80)
678
  if (props(e) & 0x80)
649
  {
679
  {
650
    diagbr_open(current_fileno);
680
    diagbr_open(current_fileno);
651
    stabn(current_fileno, current_lineno + 1);	/* don't have proper lineno */
681
    stabn(current_fileno, current_lineno + 1);	/* don't have proper lineno */
Line 656... Line 686...
656
  {
686
  {
657
    stab_begin_block();
687
    stab_begin_block();
658
  }
688
  }
659
  stab_local(CSTRING(d->data.id_scope.nme), d->data.id_scope.typ,
689
  stab_local(CSTRING(d->data.id_scope.nme), d->data.id_scope.typ,
660
	     id, 0, current_fileno);
690
	     id, 0, current_fileno);
661
  
691
 
662
  if (isparam(id) && last_caller_param(id))
692
  if (isparam(id) && last_caller_param(id))
663
  {
693
  {
664
    if (block_depth == 0)
694
    if (block_depth == 0)
665
    {
695
    {
666
      stab_begin_block();
696
      stab_begin_block();
Line 674... Line 704...
674
 
704
 
675
 
705
 
676
/*
706
/*
677
 * output_end_scope - used by make_code() to make end of diagnose_tag scope.
707
 * output_end_scope - used by make_code() to make end of diagnose_tag scope.
678
 */
708
 */
679
void output_end_scope PROTO_N ((d,e)) PROTO_T (diag_info * d X exp e)
709
void output_end_scope(diag_info * d, exp e)
680
{
710
{
681
  FULLCOMMENT1("output_end_scope key=%d", d->key);
711
  FULLCOMMENT1("output_end_scope key=%d", d->key);
682
  if (d->key == DIAG_INFO_SOURCE)
712
  if (d->key == DIAG_INFO_SOURCE)
683
  {
713
  {
684
    sourcemark *s = &d->data.source.end;
714
    sourcemark *s = &d->data.source.end;
Line 695... Line 725...
695
  }
725
  }
696
}
726
}
697
/*
727
/*
698
 * find_dd
728
 * find_dd
699
 */
729
 */
700
static diag_descriptor *find_dd PROTO_N ((e)) PROTO_T (exp e)
730
static diag_descriptor *find_dd(exp e)
701
{
731
{
702
  if (diag_def==NULL) 
732
  if (diag_def==NULL)
703
  {
733
  {
704
    return NULL;
734
    return NULL;
705
  }
735
  }
706
  return diag_def->dec_u.dec_val.diag_info;
736
  return diag_def->dec_u.dec_val.diag_info;
707
}
737
}
708
 
738
 
709
  
739
 
710
 
740
 
711
 
741
 
712
/*
742
/*
713
 * get filename number
743
 * get filename number
714
 */
744
 */
715
static int find_file PROTO_N ((f)) PROTO_T (char *f)
745
static int find_file(char *f)
716
{
746
{
717
  int i;
747
  int i;
718
 
748
 
719
  for (i = 0; i < nofds; i++)
749
  for (i = 0; i < nofds; i++)
720
  {
750
  {
721
    if (strcmp(f, CSTRING(fds[i]->file)) == 0)
751
    if (strcmp(f, CSTRING(fds[i] ->file)) == 0)
722
    {
752
    {
723
      return i;
753
      return i;
724
    }
754
    }
725
  }
755
  }
726
  return 0;
756
  return 0;
Line 735... Line 765...
735
 
765
 
736
 
766
 
737
/*
767
/*
738
 * output directive using proc start relative linenos
768
 * output directive using proc start relative linenos
739
 */
769
 */
740
static void stab_relativeline PROTO_N ((directive)) PROTO_T (CONST char *directive)
770
static void stab_relativeline(CONST char *directive)
741
{
771
{
742
  int lineinproc = current_lineno - current_procstart_lineno;
772
  int lineinproc = current_lineno - current_procstart_lineno;
743
 
773
 
744
  /* avoid nonsense line nos from unusual header or #line usage */
774
  /* avoid nonsense line nos from unusual header or #line usage */
745
  if (lineinproc >= 0)
775
  if (lineinproc >= 0)
Line 749... Line 779...
749
  else if (directive != line_stab)
779
  else if (directive != line_stab)
750
  {
780
  {
751
    fprintf(as_file, "\t%s\t%d\n", directive, 1);	/* must put out
781
    fprintf(as_file, "\t%s\t%d\n", directive, 1);	/* must put out
752
							 * something to match
782
							 * something to match
753
							 * begin/end */
783
							 * begin/end */
754
  }
784
  }
755
  return;
785
  return;
756
}
786
}
757
 
787
 
758
 
788
 
759
/*
789
/*
760
 * output begin block directive
790
 * output begin block directive
761
 */
791
 */
762
static void stab_begin_block PROTO_Z ()
792
static void stab_begin_block(void)
763
{
793
{
764
#if 0
794
#if 0
765
  if (MAX_BLOCK_DEPTH < 0 || block_depth < MAX_BLOCK_DEPTH)
795
  if (MAX_BLOCK_DEPTH < 0 || block_depth < MAX_BLOCK_DEPTH)
766
#endif
796
#endif
767
  {
797
  {
768
    stab_relativeline(bb_stab);
798
    stab_relativeline(bb_stab);
769
  }
799
  }
770
  block_depth++;
800
  block_depth++;
771
  return;
801
  return;
772
}
802
}
773
 
803
 
774
/*
804
/*
775
 * output end block directive
805
 * output end block directive
776
 */
806
 */
777
static void stab_end_block PROTO_Z ()
807
static void stab_end_block(void)
778
{
808
{
779
  if (block_depth >= 0)
809
  if (block_depth >= 0)
780
  {
810
  {
781
#if 0
811
#if 0
782
    if (MAX_BLOCK_DEPTH < 0 || block_depth <= MAX_BLOCK_DEPTH)
812
    if (MAX_BLOCK_DEPTH < 0 || block_depth <= MAX_BLOCK_DEPTH)
783
#endif
813
#endif
784
    {
814
    {
785
      stab_relativeline(eb_stab);
815
      stab_relativeline(eb_stab);
786
    }
816
    }
787
    block_depth--;
817
    block_depth--;
788
  }
818
  }
789
  return;
819
  return;
790
}
820
}
791
 
821
 
792
 
822
 
793
/*
823
/*
794
 * Generate stabs for current file and line number.
824
 * Generate stabs for current file and line number.
795
 * Note that line number stabs are relative to start of current proc.
825
 * Note that line number stabs are relative to start of current proc.
796
 */
826
 */
797
static void stabn PROTO_N ((findex,lno)) PROTO_T (int findex X int lno)
827
static void stabn(int findex, int lno)
798
{
828
{
799
  if (findex == current_fileno && lno == current_lineno)
829
  if (findex == current_fileno && lno == current_lineno)
800
  {
830
  {
801
    return;
831
    return;
802
  }
832
  }
Line 806... Line 836...
806
  }
836
  }
807
  if (current_procstart_lineno == NOT_IN_PROC)
837
  if (current_procstart_lineno == NOT_IN_PROC)
808
  {
838
  {
809
    return;
839
    return;
810
  }
840
  }
811
  
841
 
812
  current_lineno = lno;
842
  current_lineno = lno;
813
  stab_relativeline(line_stab);
843
  stab_relativeline(line_stab);
814
  return;
844
  return;
815
}
845
}
816
/*
846
/*
817
 * stab_end_file ties up lose ends 
847
 * stab_end_file ties up lose ends
818
 */
848
 */
819
void stab_end_file PROTO_Z ()
849
void stab_end_file(void)
820
{
850
{
821
  if (current_fileno != first_fileno)
851
  if (current_fileno != first_fileno)
822
  {
852
  {
823
    COMMENT("stab_end_file: close the last include file with  a .ei");
853
    COMMENT("stab_end_file: close the last include file with  a .ei");
824
    /* close the last include file */
854
    /* close the last include file */
825
    fprintf(as_file, "\t.ei\t\"%s\"\n", CSTRING(fds[current_fileno]->file));
855
    fprintf(as_file, "\t.ei\t\"%s\"\n", CSTRING(fds[current_fileno] ->file));
826
  }
856
  }
827
  return;
857
  return;
828
}
858
}
829
 
859
 
830
/*
860
/*
831
 * output file name if changed
861
 * output file name if changed
832
 */
862
 */
833
static void stab_file PROTO_N ((findex)) PROTO_T (int findex)
863
static void stab_file(int findex)
834
{
864
{
835
  bool stabbed = 0;
865
  bool stabbed = 0;
836
 
866
 
837
  if ((findex == current_fileno) || (findex < 0) || (findex >= szfds))
867
  if ((findex == current_fileno) || (findex < 0) || (findex >= szfds))
838
  {
868
  {
839
    return;
869
    return;
840
  }
870
  }
841
  
871
 
842
  if (files_stabbed == 0)
872
  if (files_stabbed == 0)
843
  {
873
  {
844
    /* .file */
874
    /* .file */
845
    fprintf(as_file, "\n\t.file\t\"%s\"\n", CSTRING(fds[findex]->file));
875
    fprintf(as_file, "\n\t.file\t\"%s\"\n", CSTRING(fds[findex] ->file));
846
    stabbed = 1;
876
    stabbed = 1;
847
    first_fileno = findex;
877
    first_fileno = findex;
848
  }
878
  }
849
  else
879
  else
850
  {
880
  {
851
    /* .bi (begin include) if appropriate */
881
    /* .bi (begin include) if appropriate */
852
 
882
 
853
    /*
883
    /*
854
     * +++ .bi/.ei causes dbx to core dump, see IBM problem fix (APAR)
884
     * +++ .bi/.ei causes dbx to core dump, see IBM problem fix (APAR)
855
     * +++ IX26109 bosadt: .bi/.ei placement doesn't match xlc, debuggers suffer
885
     * +++ IX26109 bosadt: .bi/.ei placement doesn't match xlc, debuggers suffer
856
     * +++ so we leave them commented out currently.
886
     * +++ so we leave them commented out currently.
857
     */
887
     */
858
 
888
 
859
    /* first end previous .bi if needed */
889
    /* first end previous .bi if needed */
860
    if (current_fileno != first_fileno)
890
    if (current_fileno != first_fileno)
861
    {  
891
    {
862
      fprintf(as_file, "\t.ei\t\"%s\"\n", CSTRING(fds[current_fileno]->file));
892
      fprintf(as_file, "\t.ei\t\"%s\"\n", CSTRING(fds[current_fileno] ->file));
863
    }
893
    }
864
    
894
 
865
    /* .bi if not same as original .file */
895
    /* .bi if not same as original .file */
866
    if (findex != first_fileno)
896
    if (findex != first_fileno)
867
    {
897
    {
868
      fprintf(as_file, "\n\t.bi\t\"%s\"\n", CSTRING(fds[findex]->file));
898
      fprintf(as_file, "\n\t.bi\t\"%s\"\n", CSTRING(fds[findex] ->file));
869
      stabbed = 1;
899
      stabbed = 1;
870
    }
900
    }
871
    else
901
    else
872
    {
902
    {
873
      /* output a comment to indicate back to .file level */
903
      /* output a comment to indicate back to .file level */
874
      fprintf(as_file, "\n#\t.file\t\"%s\"\n", CSTRING(fds[findex]->file));
904
      fprintf(as_file, "\n#\t.file\t\"%s\"\n", CSTRING(fds[findex] ->file));
875
    }
905
    }
876
  }
906
  }
877
 
907
 
878
  files_stabbed++;
908
  files_stabbed++;
879
 
909
 
880
  if (stabbed)
910
  if (stabbed)
881
  {
911
  {
882
    /* output TDF file machine */
912
    /* output TDF file machine */
883
    char *mach = CSTRING(fds[findex]->machine);
913
    char *mach = CSTRING(fds[findex] ->machine);
884
    time_t t = NATINT(fds[findex]->date);
914
    time_t t = NATINT(fds[findex] ->date);
885
 
915
 
886
    /* output machine name if given */
916
    /* output machine name if given */
887
    if (mach != 0 && *mach != '\0')
917
    if (mach != 0 && *mach != '\0')
888
    {
918
    {
889
      fprintf(as_file, "#\tMachine: \"%s\"\n", mach);
919
      fprintf(as_file, "#\tMachine: \"%s\"\n", mach);
890
    }
920
    }
891
    
921
 
892
    /* output TDF file time (ctime appends extra '\n') */
922
    /* output TDF file time (ctime appends extra '\n') */
893
    if (t != 0)
923
    if (t != 0)
894
    {
924
    {
895
      fprintf(as_file, "#\tSource file date: %s\n", ctime(&t));
925
      fprintf(as_file, "#\tSource file date: %s\n", ctime(&t));
896
    }
926
    }
897
  }
927
  }
898
  current_fileno = findex;
928
  current_fileno = findex;
899
  return;
929
  return;
900
}
930
}
901
 
931
 
902
 
932
 
903
/*
933
/*
904
 * start of a new lex level
934
 * start of a new lex level
905
 */
935
 */
906
static void diagbr_open PROTO_N ((findex)) PROTO_T (int findex)
936
static void diagbr_open(int findex)
907
{
937
{
908
  stab_file(findex);
938
  stab_file(findex);
909
  stab_begin_block();
939
  stab_begin_block();
910
  return;
940
  return;
911
}
941
}
912
 
942
 
913
/*
943
/*
914
 * end of a lex level
944
 * end of a lex level
915
 */
945
 */
916
static void diagbr_close PROTO_N ((findex)) PROTO_T (int findex)
946
static void diagbr_close(int findex)
917
{
947
{
918
  stab_file(findex);
948
  stab_file(findex);
919
  stab_end_block();
949
  stab_end_block();
920
  return;
950
  return;
921
}
951
}
Line 929... Line 959...
929
 
959
 
930
 
960
 
931
/*
961
/*
932
 * get the next type number to be used as a stabstring TypeId
962
 * get the next type number to be used as a stabstring TypeId
933
 */
963
 */
934
static int next_typen PROTO_Z ()
964
static int next_typen(void)
935
{
965
{
936
  static int typeno = 0;	/* types are numbered from 1 */
966
  static int typeno = 0;	/* types are numbered from 1 */
937
 
967
 
938
  return ++typeno;
968
  return ++typeno;
939
}
969
}
940
 
970
 
941
 
971
 
942
/*
972
/*
943
 * return standard TypeNo output by stab_types() for simple shapes
973
 * return standard TypeNo output by stab_types() for simple shapes
944
 */
974
 */
945
static int TypeNo_of_shape PROTO_N ((s)) PROTO_T (shape s)
975
static int TypeNo_of_shape(shape s)
946
{
976
{
947
  /* tokensh is special to this module, cannot use name(tokensh) */
977
  /* tokensh is special to this module, cannot use name(tokensh) */
948
  if (s == tokensh)
978
  if (s == tokensh)
949
  {
979
  {
950
    return TYPEID_TOKEN;
980
    return TYPEID_TOKEN;
951
  }
981
  }
952
  
982
 
953
  switch (name(s))
983
  switch (name(s))
954
  {
984
  {
955
   case bothd:		/*FALLTHROUGH*/
985
   case bothd:		/*FALLTHROUGH*/
956
   case tophd:		return TYPEID_VOID;
986
   case tophd:		return TYPEID_VOID;
957
   case scharhd:	return TYPEID_SCHAR;
987
   case scharhd:	return TYPEID_SCHAR;
Line 962... Line 992...
962
   case slonghd:       	return TYPEID_SLONG;
992
   case slonghd:       	return TYPEID_SLONG;
963
   case ulonghd:	return TYPEID_ULONG;
993
   case ulonghd:	return TYPEID_ULONG;
964
   case shrealhd:	return TYPEID_SHREAL;
994
   case shrealhd:	return TYPEID_SHREAL;
965
   case realhd:		return TYPEID_REAL;
995
   case realhd:		return TYPEID_REAL;
966
   case doublehd:	return TYPEID_DOUBLE;
996
   case doublehd:	return TYPEID_DOUBLE;
967
    
997
 
968
   default:
998
   default:
969
    {
999
    {
970
      ASSERT(0);		/* fail if debugging */
1000
      ASSERT(0);		/* fail if debugging */
971
      return TYPEID_VOID;	/* return something that will work */
1001
      return TYPEID_VOID;	/* return something that will work */
972
    }
1002
    }
973
    /* NOTREACHED */ 
1003
    /* NOTREACHED */
974
  }
1004
  }
975
}
1005
}
976
 
1006
 
977
 
1007
 
978
/*
1008
/*
979
 * Are two struct/union types structurally equivalent?
1009
 * Are two struct/union types structurally equivalent?
980
 * That is, the same stab TypeDef would be generated.
1010
 * That is, the same stab TypeDef would be generated.
981
 */
1011
 */
982
static bool eq_sutype PROTO_N ((a,b)) PROTO_T (diag_type a X diag_type b)
1012
static bool eq_sutype(diag_type a, diag_type b)
983
{
1013
{
984
  diag_field_list fa;
1014
  diag_field_list fa;
985
  diag_field_list fb;
1015
  diag_field_list fb;
986
  int j;
1016
  int j;
987
 
1017
 
988
  if (a == b)
1018
  if (a == b)
989
  {
1019
  {
990
    return 1;
1020
    return 1;
991
  }
1021
  }
992
  if (a->key != b->key)
1022
  if (a->key != b->key)
993
  {
1023
  {
994
    return 0;
1024
    return 0;
995
  }
1025
  }
996
  if (a->key != DIAG_TYPE_STRUCT && a->key != DIAG_TYPE_UNION)
1026
  if (a->key != DIAG_TYPE_STRUCT && a->key != DIAG_TYPE_UNION)
997
  {
1027
  {
998
    return 0;
1028
    return 0;
999
  }
1029
  }
1000
  
1030
 
1001
  if (strcmp(CSTRING(a->data.t_struct.nme), CSTRING(b->data.t_struct.nme)))
1031
  if (strcmp(CSTRING(a->data.t_struct.nme), CSTRING(b->data.t_struct.nme)))
1002
  {
1032
  {
1003
    return 0;
1033
    return 0;
1004
  }
1034
  }
1005
  fa = a->data.t_struct.fields;
1035
  fa = a->data.t_struct.fields;
Line 1018... Line 1048...
1018
      return 0;
1048
      return 0;
1019
    }
1049
    }
1020
  }
1050
  }
1021
  return eq_shape(a->data.t_struct.tdf_shape, b->data.t_struct.tdf_shape);
1051
  return eq_shape(a->data.t_struct.tdf_shape, b->data.t_struct.tdf_shape);
1022
}
1052
}
1023
static bool eq_typedef_type PROTO_N ((a,b)) PROTO_T (diag_descriptor * a X diag_descriptor * b)
1053
static bool eq_typedef_type(diag_descriptor * a, diag_descriptor * b)
1024
{
1054
{
1025
  if(a==b)
1055
  if (a==b)
1026
  {
1056
  {
1027
    return 1;
1057
    return 1;
1028
  }
1058
  }
1029
  
1059
 
1030
  if (strcmp(CSTRING(a->data.typ.nme),CSTRING(b->data.typ.nme))==0)
1060
  if (strcmp(CSTRING(a->data.typ.nme),CSTRING(b->data.typ.nme)) ==0)
1031
  {
1061
  {
1032
    return 1;
1062
    return 1;
1033
  }
1063
  }
1034
  return 0;
1064
  return 0;
1035
}
1065
}
1036
 
1066
 
1037
 
1067
 
1038
 
1068
 
1039
/*
1069
/*
1040
 * size in bits of object represented by dt, or negative for unknown size
1070
 * size in bits of object represented by dt, or negative for unknown size
1041
 */
1071
 */
1042
static int size_dt PROTO_N ((dt)) PROTO_T (diag_type dt)
1072
static int size_dt(diag_type dt)
1043
{
1073
{
1044
  switch (dt->key)
1074
  switch (dt->key)
1045
  {
1075
  {
1046
   case DIAG_TYPE_PTR:
1076
   case DIAG_TYPE_PTR:
1047
    {
1077
    {
Line 1051... Line 1081...
1051
    {
1081
    {
1052
      int stride = EXPINT(dt->data.array.stride);
1082
      int stride = EXPINT(dt->data.array.stride);
1053
      int lwb = EXPINT(dt->data.array.lower_b);
1083
      int lwb = EXPINT(dt->data.array.lower_b);
1054
      int upb = EXPINT(dt->data.array.upper_b);
1084
      int upb = EXPINT(dt->data.array.upper_b);
1055
      int nelements = upb - lwb + 1;
1085
      int nelements = upb - lwb + 1;
1056
      
1086
 
1057
      if (nelements < 0)
1087
      if (nelements < 0)
1058
      {
1088
      {
1059
	return 0;		/* avoid negative size from "super-flat" arrays */
1089
	return 0;		/* avoid negative size from "super-flat" arrays */
1060
      }
1090
      }
1061
      
1091
 
1062
      if (stride > 0)
1092
      if (stride > 0)
1063
      {
1093
      {
1064
	ASSERT(stride >= size_dt(dt->data.array.element_type));
1094
	ASSERT(stride >= size_dt(dt->data.array.element_type));
1065
	return nelements * stride;
1095
	return nelements * stride;
1066
      }
1096
      }
1067
      else
1097
      else
1068
      {
1098
      {
1069
	/* stride not expected to be <= 0, but just in case ... */
1099
	/* stride not expected to be <= 0, but just in case ... */
1070
	return nelements * size_dt(dt->data.array.element_type);
1100
	return nelements * size_dt(dt->data.array.element_type);
1071
      }
1101
      }
1072
      /* NOTREACHED */
1102
      /* NOTREACHED */
Line 1076... Line 1106...
1076
      return shape_size(dt->data.t_struct.tdf_shape);
1106
      return shape_size(dt->data.t_struct.tdf_shape);
1077
    }
1107
    }
1078
   case DIAG_TYPE_UNION:
1108
   case DIAG_TYPE_UNION:
1079
    {
1109
    {
1080
      return shape_size(dt->data.t_union.tdf_shape);
1110
      return shape_size(dt->data.t_union.tdf_shape);
1081
    }
1111
    }
1082
   case DIAG_TYPE_ENUM:
1112
   case DIAG_TYPE_ENUM:
1083
    {
1113
    {
1084
      return size_dt(dt->data.t_enum.base_type);
1114
      return size_dt(dt->data.t_enum.base_type);
1085
    }
1115
    }
1086
   case DIAG_TYPE_VARIETY:
1116
   case DIAG_TYPE_VARIETY:
1087
    {
1117
    {
1088
      return shape_size(dt->data.var);
1118
      return shape_size(dt->data.var);
1089
    }
1119
    }
1090
   case DIAG_TYPE_PROC:
1120
   case DIAG_TYPE_PROC:
1091
    {
1121
    {
1092
      return 32;		/* ptr to proc */
1122
      return 32;		/* ptr to proc */
1093
    }
1123
    }
1094
   case DIAG_TYPE_LOC:
1124
   case DIAG_TYPE_LOC:
1095
    {
1125
    {
1096
      return size_dt(dt->data.loc.object);
1126
      return size_dt(dt->data.loc.object);
1097
    }
1127
    }
1098
   case DIAG_TYPE_FLOAT:
1128
   case DIAG_TYPE_FLOAT:
1099
    {
1129
    {
1100
      return shape_size(f_floating(dt->data.f_var));	/* shape for f_var */
1130
      return shape_size(f_floating(dt->data.f_var));	/* shape for f_var */
1101
    }
1131
    }
1102
   case DIAG_TYPE_NULL:
1132
   case DIAG_TYPE_NULL:
1103
    {
1133
    {
1104
      return 0;			/* void has no size */
1134
      return 0;			/* void has no size */
1105
    }
1135
    }
1106
   case DIAG_TYPE_BITFIELD:
1136
   case DIAG_TYPE_BITFIELD:
1107
    {
1137
    {
1108
      return NATINT(dt->data.bitfield.no_of_bits);
1138
      return NATINT(dt->data.bitfield.no_of_bits);
1109
    }
1139
    }
1110
   case DIAG_TYPE_UNINIT:	/* from tokenised type */
1140
   case DIAG_TYPE_UNINIT:	/* from tokenised type */
Line 1117... Line 1147...
1117
      ASSERT(0);		/* fail if in debug mode */
1147
      ASSERT(0);		/* fail if in debug mode */
1118
      return -1;
1148
      return -1;
1119
    }
1149
    }
1120
  }
1150
  }
1121
}
1151
}
1122
 
1152
 
1123
 
1153
 
1124
/*
1154
/*
1125
 * output TypeDef, except as a INTEGER TypeId to avoid recursion
1155
 * output TypeDef, except as a INTEGER TypeId to avoid recursion
1126
 */
1156
 */
1127
static void out_dt_TypeDef_no_recurse PROTO_N ((dt)) PROTO_T (diag_type dt)
1157
static void out_dt_TypeDef_no_recurse(diag_type dt)
1128
{
1158
{
1129
  switch (dt->key)
1159
  switch (dt->key)
1130
  {
1160
  {
1131
   case DIAG_TYPE_PTR:
1161
   case DIAG_TYPE_PTR:
1132
    {
1162
    {
1133
      /* TypeDef:		* TypeId	"Pointer of type TypeId" */
1163
      /* TypeDef:		* TypeId	"Pointer of type TypeId" */
1134
      fprintf(as_file, "*");
1164
      fprintf(as_file, "*");
1135
      out_dt_TypeId(dt->data.ptr.object);
1165
      out_dt_TypeId(dt->data.ptr.object);
1136
      break;
1166
      break;
1137
    }
1167
    }
Line 1140... Line 1170...
1140
      int stride = EXPINT(dt->data.array.stride);
1170
      int stride = EXPINT(dt->data.array.stride);
1141
      int lwb = EXPINT(dt->data.array.lower_b);
1171
      int lwb = EXPINT(dt->data.array.lower_b);
1142
      int upb = EXPINT(dt->data.array.upper_b);
1172
      int upb = EXPINT(dt->data.array.upper_b);
1143
      diag_type index_type = dt->data.array.index_type;
1173
      diag_type index_type = dt->data.array.index_type;
1144
      diag_type element_type = dt->data.array.element_type;
1174
      diag_type element_type = dt->data.array.element_type;
1145
      
1175
 
1146
      ASSERT(stride >= size_dt(element_type));
1176
      ASSERT(stride >= size_dt(element_type));
1147
      
1177
 
1148
#if 0
1178
#if 0
1149
      /* +++ maybe this works better thab Packed array with dbx/gdb, try it */
1179
      /* +++ maybe this works better thab Packed array with dbx/gdb, try it */
1150
      if (stride == 1 && lwb == 0 && upb < 32)
1180
      if (stride == 1 && lwb == 0 && upb < 32)
1151
      {
1181
      {
1152
	/* represent as bitfield */
1182
	/* represent as bitfield */
1153
	fprintf(as_file, "r%d;0;4294967295;", TYPEID_SLONG);
1183
	fprintf(as_file, "r%d;0;4294967295;", TYPEID_SLONG);
1154
	break;
1184
	break;
1155
      }
1185
      }
1156
#endif
1186
#endif
1157
      
1187
 
1158
      /*
1188
      /*
1159
       * TypeDef:		 Array
1189
       * TypeDef:		 Array
1160
       * Array:		a TypeDef ; TypeId		"Array"
1190
       * Array:		a TypeDef ; TypeId		"Array"
1161
       *		|	P TypeDef ; TypeId		"Packed array"
1191
       *		|	P TypeDef ; TypeId		"Packed array"
1162
       *		|	A TypeId			"Open array of TypeId"
1192
       *		|	A TypeId			"Open array of TypeId"
Line 1164... Line 1194...
1164
       * Subrange:	r TypeId ; Bound ; Bound
1194
       * Subrange:	r TypeId ; Bound ; Bound
1165
       * Bound:		INTEGER				"Constant bound"
1195
       * Bound:		INTEGER				"Constant bound"
1166
       */
1196
       */
1167
      if (stride == 1)
1197
      if (stride == 1)
1168
      {
1198
      {
1169
	fprintf(as_file, "Pr");		/* Packed Array - should never happen for C */	
1199
	fprintf(as_file, "Pr");		/* Packed Array - should never happen for C */
1170
      }
1200
      }
1171
      else
1201
      else
1172
      {
1202
      {
1173
	fprintf(as_file, "ar");
1203
	fprintf(as_file, "ar");
1174
      }
1204
      }
Line 1182... Line 1212...
1182
    {
1212
    {
1183
      int i;
1213
      int i;
1184
      char su;
1214
      char su;
1185
      diag_field_list fields;
1215
      diag_field_list fields;
1186
      shape s;
1216
      shape s;
1187
      
1217
 
1188
      /* TypeDef:	Record */
1218
      /* TypeDef:	Record */
1189
 
1219
 
1190
      if (dt->key == DIAG_TYPE_STRUCT)
1220
      if (dt->key == DIAG_TYPE_STRUCT)
1191
      {
1221
      {
1192
	fields = dt->data.t_struct.fields;
1222
	fields = dt->data.t_struct.fields;
Line 1195... Line 1225...
1195
	/* Record:	s NumBytes FieldList ;		"Structure or record definition" */
1225
	/* Record:	s NumBytes FieldList ;		"Structure or record definition" */
1196
	su = 's';
1226
	su = 's';
1197
      }
1227
      }
1198
      else
1228
      else
1199
      {				/* dt->key == DIAG_TYPE_UNION */
1229
      {				/* dt->key == DIAG_TYPE_UNION */
1200
	fields = (diag_field_list) dt->data.t_union.fields;
1230
	fields = (diag_field_list)dt->data.t_union.fields;
1201
	s = dt->data.t_union.tdf_shape;
1231
	s = dt->data.t_union.tdf_shape;
1202
	/* Record:	u NumBytes FieldList ;		"Union" */
1232
	/* Record:	u NumBytes FieldList ;		"Union" */
1203
	su = 'u';
1233
	su = 'u';
1204
      }
1234
      }
1205
 
1235
 
Line 1231... Line 1261...
1231
	  {
1261
	  {
1232
	    next_start = shape_size(s);
1262
	    next_start = shape_size(s);
1233
	  }
1263
	  }
1234
	  else
1264
	  else
1235
	  {
1265
	  {
1236
	    next_start = EXPINT(((fields->array)[i - 1])->where);
1266
	    next_start = EXPINT(((fields->array)[i - 1]) ->where);
1237
	  }
1267
	  }
1238
	  sizetonext = next_start - offset;
1268
	  sizetonext = next_start - offset;
1239
 
1269
 
1240
	  ASSERT(size <= sizetonext);
1270
	  ASSERT(size <= sizetonext);
1241
	}
1271
	}
1242
#endif
1272
#endif
1243
 
1273
 
1244
	if (size < 0)		/* eg from tokenised type */
1274
	if (size < 0)		/* eg from tokenised type */
1245
	{
1275
	{
1246
	  /* guess: space to next field, or end */
1276
	  /* guess: space to next field, or end */
1247
	  int next_start;
1277
	  int next_start;
1248
 
1278
 
1249
	  if (dt->key == DIAG_TYPE_UNION || i == 0)
1279
	  if (dt->key == DIAG_TYPE_UNION || i == 0)
1250
	    next_start = shape_size(s);
1280
	    next_start = shape_size(s);
1251
	  else
1281
	  else
1252
	    next_start = EXPINT(((fields->array)[i - 1])->where);
1282
	    next_start = EXPINT(((fields->array)[i - 1]) ->where);
1253
	  size = next_start - offset;
1283
	  size = next_start - offset;
1254
	}
1284
	}
1255
 
1285
 
1256
	if (size < 0)
1286
	if (size < 0)
1257
	{
1287
	{
1258
	  size = 32;		/* desperate guess */
1288
	  size = 32;		/* desperate guess */
1259
	}
1289
	}
1260
	
1290
 
1261
	/*
1291
	/*
1262
	 * BitOffset:	INTEGER		"Offset in bits from beginning of structure"
1292
	 * BitOffset:	INTEGER		"Offset in bits from beginning of structure"
1263
	 * NumBits:	INTEGER		"Number of bits in item"
1293
	 * NumBits:	INTEGER		"Number of bits in item"
1264
	 */
1294
	 */
1265
	fprintf(as_file, ",%d,%d;", offset, size);	/* bitoff,bitsz */
1295
	fprintf(as_file, ",%d,%d;", offset, size);	/* bitoff,bitsz */
Line 1267... Line 1297...
1267
      fprintf(as_file, ";");
1297
      fprintf(as_file, ";");
1268
      break;
1298
      break;
1269
    }
1299
    }
1270
 
1300
 
1271
  case DIAG_TYPE_ENUM:
1301
  case DIAG_TYPE_ENUM:
1272
    {
1302
    {
1273
#if 1
1303
#if 1
1274
      /* simply output the base integer type */
1304
      /* simply output the base integer type */
1275
      out_dt_TypeDef(dt->data.t_enum.base_type);
1305
      out_dt_TypeDef(dt->data.t_enum.base_type);
1276
#else
1306
#else
1277
 
1307
 
Line 1431... Line 1461...
1431
 
1461
 
1432
 
1462
 
1433
/*
1463
/*
1434
 * generate TypeDef stabstring
1464
 * generate TypeDef stabstring
1435
 */
1465
 */
1436
static void out_dt_TypeDef PROTO_N ((dt)) PROTO_T (diag_type dt)
1466
static void out_dt_TypeDef(diag_type dt)
1437
{
1467
{
1438
  if (IS_OUTED(dt))
1468
  if (IS_OUTED(dt))
1439
  {
1469
  {
1440
 
1470
 
1441
    /*
1471
    /*
Line 1453... Line 1483...
1453
 
1483
 
1454
/*
1484
/*
1455
 * generate TypeId stabstring defining new type number
1485
 * generate TypeId stabstring defining new type number
1456
 * TypeId:	INTEGER = TypeDef	"New type number described by TypeDef"
1486
 * TypeId:	INTEGER = TypeDef	"New type number described by TypeDef"
1457
 */
1487
 */
1458
static void out_dt_NewTypeId PROTO_N ((dt,non)) PROTO_T (diag_type dt X int non)
1488
static void out_dt_NewTypeId(diag_type dt, int non)
1459
{
1489
{
1460
  fprintf(as_file, "%d=", non);
1490
  fprintf(as_file, "%d=", non);
1461
 
1491
 
1462
  if (IS_OUTED(dt))
1492
  if (IS_OUTED(dt))
1463
  {
1493
  {
Line 1478... Line 1508...
1478
 
1508
 
1479
 
1509
 
1480
/*
1510
/*
1481
 * generate TypeId stabstring
1511
 * generate TypeId stabstring
1482
 */
1512
 */
1483
static void out_dt_TypeId PROTO_N ((dt)) PROTO_T (diag_type dt)
1513
static void out_dt_TypeId(diag_type dt)
1484
{
1514
{
1485
  if (IS_OUTED(dt))
1515
  if (IS_OUTED(dt))
1486
  {
1516
  {
1487
 
1517
 
1488
    /*
1518
    /*
Line 1538... Line 1568...
1538
/*
1568
/*
1539
 * Output .bs (begin static block) which must precede stab_global
1569
 * Output .bs (begin static block) which must precede stab_global
1540
 * for tags which have data initialisers.  If such stabs are output
1570
 * for tags which have data initialisers.  If such stabs are output
1541
 * outside .bs/.be gdb and dbx cannot locate tag.
1571
 * outside .bs/.be gdb and dbx cannot locate tag.
1542
 */
1572
 */
1543
void stab_bs PROTO_N ((sectname)) PROTO_T (char *sectname)
1573
void stab_bs(char *sectname)
1544
{
1574
{
1545
  fprintf(as_file, "\t.bs\t%s\n", sectname);
1575
  fprintf(as_file, "\t.bs\t%s\n", sectname);
1546
}
1576
}
1547
 
1577
 
1548
/*
1578
/*
1549
 * Output .es (end static block).
1579
 * Output .es (end static block).
1550
 */
1580
 */
1551
void stab_es PROTO_N ((sectname)) PROTO_T (char *sectname)
1581
void stab_es(char *sectname)
1552
{
1582
{
1553
  fprintf(as_file, "\t.es\n");
1583
  fprintf(as_file, "\t.es\n");
1554
}
1584
}
1555
 
1585
 
1556
 
1586
 
1557
/*
1587
/*
1558
 * Produce diagnostic for ident_tag variable "id" defined by "global";
1588
 * Produce diagnostic for ident_tag variable "id" defined by "global";
1559
 * called from translat().  "ext" tells whether "id" is "static".
1589
 * called from translat().  "ext" tells whether "id" is "static".
1560
 */
1590
 */
1561
void stab_global PROTO_N ((global,id,ext)) PROTO_T (exp global X char *id X bool ext)
1591
void stab_global(exp global, char *id, bool ext)
1562
{
1592
{
1563
  diag_descriptor *dd = find_dd(global);
1593
  diag_descriptor *dd = find_dd(global);
1564
 
1594
 
1565
  if (dd == (diag_descriptor *) 0)
1595
  if (dd == (diag_descriptor *)0)
1566
    return;
1596
    return;
1567
 
1597
 
1568
  /* +++ inefficient */
1598
  /* +++ inefficient */
1569
  stab_file(find_file(CSTRING(dd->data.id.whence.file->file)));
1599
  stab_file(find_file(CSTRING(dd->data.id.whence.file->file)));
1570
 
1600
 
Line 1575... Line 1605...
1575
   *		|	S TypeId	"Module variable of type TypeId (C static global)"
1605
   *		|	S TypeId	"Module variable of type TypeId (C static global)"
1576
   */
1606
   */
1577
  ASSERT(CSTRING(dd->data.id.nme)[0]!=0);
1607
  ASSERT(CSTRING(dd->data.id.nme)[0]!=0);
1578
  fprintf(as_file, "\t.stabx\t\"%s:%c",
1608
  fprintf(as_file, "\t.stabx\t\"%s:%c",
1579
	  CSTRING(dd->data.id.nme),
1609
	  CSTRING(dd->data.id.nme),
1580
	  (ext ? 'G' : 'S'));
1610
	 (ext ? 'G' : 'S'));
1581
  out_dt_TypeId(dd->data.id.new_type);
1611
  out_dt_TypeId(dd->data.id.new_type);
1582
  fprintf(as_file, "\",%s,%d,%d\n",
1612
  fprintf(as_file, "\",%s,%d,%d\n",
1583
	  id,
1613
	  id,
1584
	  (ext ? C_GSYM : C_STSYM),
1614
	 (ext ? C_GSYM : C_STSYM),
1585
	  0);
1615
	  0);
1586
}
1616
}
1587
 
1617
 
1588
 
1618
 
1589
/*
1619
/*
1590
 * switch to correct file prior to proc prelude
1620
 * switch to correct file prior to proc prelude
1591
 */
1621
 */
1592
void stab_proc1 PROTO_N ((proc,id,ext)) PROTO_T (exp proc X char *id X bool ext)
1622
void stab_proc1(exp proc, char *id, bool ext)
1593
{
1623
{
1594
  diag_descriptor *dd = find_dd(proc);
1624
  diag_descriptor *dd = find_dd(proc);
1595
 
1625
 
1596
  block_depth = 0;
1626
  block_depth = 0;
1597
 
1627
 
1598
  if (dd == (diag_descriptor *) 0)
1628
  if (dd == (diag_descriptor *)0)
1599
  {
1629
  {
1600
    COMMENT("stab_proc1: no descriptor");	/* should never happen */
1630
    COMMENT("stab_proc1: no descriptor");	/* should never happen */
1601
    current_procstart_lineno = NOT_IN_PROC;
1631
    current_procstart_lineno = NOT_IN_PROC;
1602
    current_lineno = NOT_IN_PROC;
1632
    current_lineno = NOT_IN_PROC;
1603
    return;
1633
    return;
Line 1612... Line 1642...
1612
 
1642
 
1613
 
1643
 
1614
/*
1644
/*
1615
 * stap proc, after label defined
1645
 * stap proc, after label defined
1616
 */
1646
 */
1617
void stab_proc2 PROTO_N ((proc,id,ext)) PROTO_T (exp proc X char *id X bool ext)
1647
void stab_proc2(exp proc, char *id, bool ext)
1618
{
1648
{
1619
  diag_descriptor *dd = find_dd(proc);
1649
  diag_descriptor *dd = find_dd(proc);
1620
  char *nm;
1650
  char *nm;
1621
  diag_type dt;
1651
  diag_type dt;
1622
 
1652
 
1623
  if (dd == (diag_descriptor *) 0)
1653
  if (dd == (diag_descriptor *)0)
1624
  {
1654
  {
1625
    COMMENT("stab_proc2: no descriptor");	/* should never happen */
1655
    COMMENT("stab_proc2: no descriptor");	/* should never happen */
1626
    return;
1656
    return;
1627
  }
1657
  }
1628
 
1658
 
Line 1643... Line 1673...
1643
   *		|	Q		"Private procedure"
1673
   *		|	Q		"Private procedure"
1644
   */
1674
   */
1645
 
1675
 
1646
  /* +++ when gdb understands, maybe use "P" or "Q" for proc returning void */
1676
  /* +++ when gdb understands, maybe use "P" or "Q" for proc returning void */
1647
 
1677
 
1648
  fprintf(as_file, "\t.stabx\t\"%s:%c", nm, (ext ? 'F' : 'f'));
1678
  fprintf(as_file, "\t.stabx\t\"%s:%c", nm,(ext ? 'F' : 'f'));
1649
 
1679
 
1650
  /*
1680
  /*
1651
   * The meaning of TypeId is not clear from the stabstring syntax document,
1681
   * The meaning of TypeId is not clear from the stabstring syntax document,
1652
   * dbx and gdb work best if it is the result type.
1682
   * dbx and gdb work best if it is the result type.
1653
   */
1683
   */
Line 1690... Line 1720...
1690
 
1720
 
1691
 
1721
 
1692
/*
1722
/*
1693
 * diagnostics for proc end
1723
 * diagnostics for proc end
1694
 */
1724
 */
1695
void stab_endproc PROTO_N ((proc,id,ext)) PROTO_T (exp proc X char *id X bool ext)
1725
void stab_endproc(exp proc, char *id, bool ext)
1696
{
1726
{
1697
  /* end all open blocks */
1727
  /* end all open blocks */
1698
  while (block_depth > 0)
1728
  while (block_depth > 0)
1699
    stab_end_block();
1729
    stab_end_block();
1700
 
1730
 
Line 1709... Line 1739...
1709
    struct tbtable_short tbtable_sht;
1739
    struct tbtable_short tbtable_sht;
1710
    diag_descriptor *dd = find_dd(proc);
1740
    diag_descriptor *dd = find_dd(proc);
1711
    char *nm;
1741
    char *nm;
1712
    int i;
1742
    int i;
1713
 
1743
 
1714
    if (dd == (diag_descriptor *) 0)
1744
    if (dd == (diag_descriptor *)0)
1715
    {
1745
    {
1716
      COMMENT("stab_endproc: no descriptor");	/* should never happen */
1746
      COMMENT("stab_endproc: no descriptor");	/* should never happen */
1717
      return;
1747
      return;
1718
      
1748
 
1719
    }
1749
    }
1720
 
1750
 
1721
    nm = CSTRING(dd->data.id.nme);	/* source proc name, id is just the
1751
    nm = CSTRING(dd->data.id.nme);	/* source proc name, id is just the
1722
					 * assembler label */
1752
					 * assembler label */
1723
    ASSERT(nm[0]!=0);
1753
    ASSERT(nm[0]!=0);
1724
    tbtable_sht = zero_tbtable_short;
1754
    tbtable_sht = zero_tbtable_short;
1725
 
1755
 
1726
    /* +++ set up tbtable_sht more fully */
1756
    /* +++ set up tbtable_sht more fully */
1727
 
1757
 
1728
    tbtable_sht.lang = TB_C;	/* lang C +++ */
1758
    tbtable_sht.lang = TB_C;	/* lang C +++ */
1729
    tbtable_sht.has_tboff = 1;	/* optional tb_offset always given */
1759
    tbtable_sht.has_tboff = 1;	/* optional tb_offset always given */
1730
    tbtable_sht.name_present = 1;	/* optional proc name always given */
1760
    tbtable_sht.name_present = 1;	/* optional proc name always given */
1731
    tbtable_sht.saves_lr =
1761
    tbtable_sht.saves_lr =
1732
      !p_leaf;	/* non-leaf procs store link reg */
1762
      !p_leaf;	/* non-leaf procs store link reg */
1733
    tbtable_sht.stores_bc =
1763
    tbtable_sht.stores_bc =
1734
      !p_leaf;	/* non-leaf procs store stack backchain */
1764
      !p_leaf;	/* non-leaf procs store stack backchain */
1735
 
1765
 
1736
    /* number of float regs saved */
1766
    /* number of float regs saved */
1737
    if (p_sfreg_first_save != FR_NO_REG)
1767
    if (p_sfreg_first_save != FR_NO_REG)
1738
      tbtable_sht.fpr_saved = FR_31 + 1 - p_sfreg_first_save;
1768
      tbtable_sht.fpr_saved = FR_31 + 1 - p_sfreg_first_save;
1739
    
1769
 
1740
    /* number of fixed regs saved */
1770
    /* number of fixed regs saved */
1741
    if (p_sreg_first_save != R_NO_REG)
1771
    if (p_sreg_first_save != R_NO_REG)
1742
      tbtable_sht.gpr_saved = R_31 + 1 - p_sreg_first_save;
1772
      tbtable_sht.gpr_saved = R_31 + 1 - p_sreg_first_save;
1743
    
1773
 
1744
    /* number of fixed and float params passed in regs */
1774
    /* number of fixed and float params passed in regs */
1745
    tbtable_sht.fixedparms = p_fixed_params;
1775
    tbtable_sht.fixedparms = p_fixed_params;
1746
    tbtable_sht.floatparms = p_float_params;
1776
    tbtable_sht.floatparms = p_float_params;
1747
 
1777
 
1748
    tbtable_sht.parmsonstk = 1;	/* -g always stores parameters on stack */
1778
    tbtable_sht.parmsonstk = 1;	/* -g always stores parameters on stack */
Line 1751... Line 1781...
1751
    fprintf(as_file, "#\ttraceback table\n");
1781
    fprintf(as_file, "#\ttraceback table\n");
1752
    fprintf(as_file, "\t.long\t0\n");
1782
    fprintf(as_file, "\t.long\t0\n");
1753
 
1783
 
1754
    /* tbtable_sht as bytes */
1784
    /* tbtable_sht as bytes */
1755
    fprintf(as_file, "\t.byte\t");
1785
    fprintf(as_file, "\t.byte\t");
1756
    for (i = 0; i < sizeof (tbtable_sht) - 1; i++)
1786
    for (i = 0; i < sizeof(tbtable_sht) - 1; i++)
1757
      fprintf(as_file, "%#x,", ((unsigned char *) (&tbtable_sht))[i]);
1787
      fprintf(as_file, "%#x,",((unsigned char *)(&tbtable_sht))[i]);
1758
    fprintf(as_file, "%#x\n", ((unsigned char *) (&tbtable_sht))[i]);
1788
    fprintf(as_file, "%#x\n",((unsigned char *)(&tbtable_sht))[i]);
1759
 
1789
 
1760
    /* optional portions of traceback table */
1790
    /* optional portions of traceback table */
1761
 
1791
 
1762
    /* parminfo */
1792
    /* parminfo */
1763
    if (tbtable_sht.fixedparms || tbtable_sht.floatparms)
1793
    if (tbtable_sht.fixedparms || tbtable_sht.floatparms)
1764
      fprintf(as_file, "\t.long\t0\n");	/* +++ */
1794
      fprintf(as_file, "\t.long\t0\n");	/* +++ */
1765
 
1795
 
1766
    /* tb_offset */
1796
    /* tb_offset */
1767
    fprintf(as_file, "\t.long\tE.%s-.%s\n", id, id);
1797
    fprintf(as_file, "\t.long\tE.%s-.%s\n", id, id);
1768
 
1798
 
1769
    /* we never use hand_mask, ctl_info and ctl_info_disp optional components */
1799
    /* we never use hand_mask, ctl_info and ctl_info_disp optional components */
1770
    ASSERT(!tbtable_sht.int_hndl);
1800
    ASSERT(!tbtable_sht.int_hndl);
1771
    ASSERT(!tbtable_sht.has_ctl);
1801
    ASSERT(!tbtable_sht.has_ctl);
1772
 
1802
 
1773
    /* proc name */
1803
    /* proc name */
1774
    fprintf(as_file, "\t.short\t%d\n", (int)strlen(nm));
1804
    fprintf(as_file, "\t.short\t%d\n",(int)strlen(nm));
1775
    fprintf(as_file, "\t.byte\t\"%s\"\n", nm);
1805
    fprintf(as_file, "\t.byte\t\"%s\"\n", nm);
1776
 
1806
 
1777
    /* alloca_reg */
1807
    /* alloca_reg */
1778
    if (tbtable_sht.uses_alloca)
1808
    if (tbtable_sht.uses_alloca)
1779
      fprintf(as_file, "\t.byte\t0\n");	/* +++ */
1809
      fprintf(as_file, "\t.byte\t0\n");	/* +++ */
Line 1790... Line 1820...
1790
 * index of the file containing the declaration. The code below gives does
1820
 * index of the file containing the declaration. The code below gives does
1791
 * not allow for identifiers allocated in registers; in fact, with
1821
 * not allow for identifiers allocated in registers; in fact, with
1792
 * current translator, none are used by stab_local. I don't even know
1822
 * current translator, none are used by stab_local. I don't even know
1793
 * whether dbx can actually use them.
1823
 * whether dbx can actually use them.
1794
 */
1824
 */
1795
void stab_local PROTO_N ((nm,dt,id,disp,findex)) PROTO_T (char *nm X diag_type dt X exp id X int disp X int findex)
1825
void stab_local(char *nm, diag_type dt, exp id, int disp, int findex)
1796
{
1826
{
1797
  FULLCOMMENT3("stab_local: %s disp=%d boff(id).offset=%d", (long) nm, disp, boff(id).offset);
1827
  FULLCOMMENT3("stab_local: %s disp=%d boff(id).offset=%d",(long)nm, disp, boff(id).offset);
1798
  disp += boff(id).offset;
1828
  disp += boff(id).offset;
1799
again:
1829
again:
1800
  if (name(id) == ident_tag)
1830
  if (name(id) == ident_tag)
1801
  {
1831
  {
1802
    FULLCOMMENT2("stab_local ident_tag: %s disp=%d", (long) nm, disp);
1832
    FULLCOMMENT2("stab_local ident_tag: %s disp=%d",(long)nm, disp);
1803
    if ((props(id) & defer_bit) == 0)
1833
    if ((props(id) & defer_bit) == 0)
1804
    {
1834
    {
1805
      if (isparam(id))
1835
      if (isparam(id))
1806
      {
1836
      {
1807
	fprintf(as_file, "\t.stabx\t\"%s:p", nm);
1837
	fprintf(as_file, "\t.stabx\t\"%s:p", nm);
Line 1846... Line 1876...
1846
	    break;
1876
	    break;
1847
	  }
1877
	  }
1848
	default:
1878
	default:
1849
	  return;
1879
	  return;
1850
	}
1880
	}
1851
      }
1881
      }
1852
    }
1882
    }
1853
  }
1883
  }
1854
}
1884
}
1855
 
1885
 
1856
 
1886
 
1857
/*
1887
/*
1858
 * Output a .stabx for all internal struct/unions not already processed.
1888
 * Output a .stabx for all internal struct/unions not already processed.
1859
 * This avoids extremely long stabstrings from internal struct/unions being
1889
 * This avoids extremely long stabstrings from internal struct/unions being
1860
 * output on the fly for the top level struct/union.
1890
 * output on the fly for the top level struct/union.
1861
 * It also avoids dbx going recursive printing some types.
1891
 * It also avoids dbx going recursive printing some types.
1862
 */
1892
 */
1863
static void stab_internal_types PROTO_N ((dt,stabthislevel)) PROTO_T (diag_type dt X bool stabthislevel)
1893
static void stab_internal_types(diag_type dt, bool stabthislevel)
1864
{
1894
{
1865
  if (IS_OUTED(dt))
1895
  if (IS_OUTED(dt))
1866
    return;				/* already been here */
1896
    return;				/* already been here */
1867
 
1897
 
1868
  switch (dt->key)
1898
  switch (dt->key)
Line 1886... Line 1916...
1886
      }
1916
      }
1887
 
1917
 
1888
      if (dt->key == DIAG_TYPE_STRUCT)
1918
      if (dt->key == DIAG_TYPE_STRUCT)
1889
	fields = dt->data.t_struct.fields;
1919
	fields = dt->data.t_struct.fields;
1890
      else
1920
      else
1891
	fields = (diag_field_list) dt->data.t_union.fields;
1921
	fields = (diag_field_list)dt->data.t_union.fields;
1892
 
1922
 
1893
      for (i = fields->lastused - 1; i >= 0; i--)
1923
      for (i = fields->lastused - 1; i >= 0; i--)
1894
      {
1924
      {
1895
	diag_field sf = (fields->array)[i];
1925
	diag_field sf = (fields->array)[i];
1896
 
1926
 
Line 1909... Line 1939...
1909
	fprintf(as_file, "T%d=", non);
1939
	fprintf(as_file, "T%d=", non);
1910
	out_dt_TypeDef_no_recurse(dt);
1940
	out_dt_TypeDef_no_recurse(dt);
1911
 
1941
 
1912
	fprintf(as_file, "\",%d,%d,%d\n", 0, C_DECL, 0);
1942
	fprintf(as_file, "\",%d,%d,%d\n", 0, C_DECL, 0);
1913
      }
1943
      }
1914
 
1944
 
1915
      break;
1945
      break;
1916
    }
1946
    }
1917
 
1947
 
1918
  case DIAG_TYPE_PTR:
1948
  case DIAG_TYPE_PTR:
1919
    {
1949
    {
Line 1945... Line 1975...
1945
 
1975
 
1946
/*
1976
/*
1947
 * Generate stab for a basic type, for which there is a standard IBM AIX StabNo.
1977
 * Generate stab for a basic type, for which there is a standard IBM AIX StabNo.
1948
 */
1978
 */
1949
static void stab_basicshape
1979
static void stab_basicshape
1950
    PROTO_N ((sha,typename,tdf_typeidnum,ibm_typeidnum))
-
 
1951
    PROTO_T (shape sha X char *typename X int tdf_typeidnum X int ibm_typeidnum)
1980
(shape sha, char *typename, int tdf_typeidnum, int ibm_typeidnum)
1952
{
1981
{
1953
  int n = next_typen();
1982
  int n = next_typen();
1954
 
1983
 
1955
  ASSERT(tdf_typeidnum == n);
1984
  ASSERT(tdf_typeidnum == n);
1956
 
1985
 
Line 1964... Line 1993...
1964
 * Information about procedures is ignored for present;
1993
 * Information about procedures is ignored for present;
1965
 * it is output by stab_procN().
1994
 * it is output by stab_procN().
1966
 *
1995
 *
1967
 * Must be called before any ".stabx" directive attempted.
1996
 * Must be called before any ".stabx" directive attempted.
1968
 */
1997
 */
1969
static void stab_types PROTO_Z ()
1998
static void stab_types(void)
1970
{
1999
{
1971
  /* Numbering and outputing of basicshapes,structs,unions and typedefs */
2000
  /* Numbering and outputing of basicshapes,structs,unions and typedefs */
1972
  (void)number_and_stab_basicshapes();
2001
 (void)number_and_stab_basicshapes();
1973
  (void)number_structs_and_unions();
2002
 (void)number_structs_and_unions();
1974
  (void)number_typedefs();
2003
 (void)number_typedefs();
1975
  (void)stab_structs_and_unions();
2004
 (void)stab_structs_and_unions();
1976
  (void)stab_typedefs();
2005
 (void)stab_typedefs();
1977
}
2006
}
1978
  
2007
 
1979
 
2008