| 1 | /* stabshll.c -- Convert GNU-style a.out debug information into
|
|---|
| 2 | IBM OS/2 HLL 3 debug information
|
|---|
| 3 | Copyright (c) 1993-1998 Eberhard Mattes
|
|---|
| 4 |
|
|---|
| 5 | This file is part of emxomf.
|
|---|
| 6 |
|
|---|
| 7 | emxomf is free software; you can redistribute it and/or modify
|
|---|
| 8 | it under the terms of the GNU General Public License as published by
|
|---|
| 9 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 10 | any later version.
|
|---|
| 11 |
|
|---|
| 12 | emxomf is distributed in the hope that it will be useful,
|
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 15 | GNU General Public License for more details.
|
|---|
| 16 |
|
|---|
| 17 | You should have received a copy of the GNU General Public License
|
|---|
| 18 | along with emxomf; see the file COPYING. If not, write to
|
|---|
| 19 | the Free Software Foundation, 59 Temple Place - Suite 330,
|
|---|
| 20 | Boston, MA 02111-1307, USA. */
|
|---|
| 21 | //#define HLL_DEBUG 1
|
|---|
| 22 |
|
|---|
| 23 | /*******************************************************************************
|
|---|
| 24 | * Header Files *
|
|---|
| 25 | *******************************************************************************/
|
|---|
| 26 | #include <stdio.h>
|
|---|
| 27 | #include <stdlib.h>
|
|---|
| 28 | #include <string.h>
|
|---|
| 29 | #include <stdarg.h>
|
|---|
| 30 | #include <time.h>
|
|---|
| 31 | #include <alloca.h>
|
|---|
| 32 | #include <ctype.h>
|
|---|
| 33 | #include "defs.h"
|
|---|
| 34 | #include "emxomf.h"
|
|---|
| 35 | #include "grow.h"
|
|---|
| 36 | #include "stabshll.h"
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | /*******************************************************************************
|
|---|
| 40 | * Defined Constants And Macros *
|
|---|
| 41 | *******************************************************************************/
|
|---|
| 42 | /* Field ID values for the type table. */
|
|---|
| 43 |
|
|---|
| 44 | #define FID_nil 0x80 /* No data */
|
|---|
| 45 | #define FID_void 0x81 /* Type void */
|
|---|
| 46 | #define FID_string 0x82 /* A length-prefixed string follows */
|
|---|
| 47 | #define FID_index 0x83 /* A type index follows */
|
|---|
| 48 | #define FID_span_16u 0x85 /* An unsigned 16-bit number follows */
|
|---|
| 49 | #define FID_span_32u 0x86 /* An unsigned 32-bit number follows */
|
|---|
| 50 | #define FID_span_8s 0x88 /* A signed 8-bit number follows */
|
|---|
| 51 | #define FID_span_16s 0x89 /* A signed 16-bit number follows */
|
|---|
| 52 | #define FID_span_32s 0x8a /* A signed 32-bit number follows */
|
|---|
| 53 | #define FID_span_8u 0x8b /* An unsigned 8-bit number follows */
|
|---|
| 54 |
|
|---|
| 55 | /* Static scope table subrecord types. */
|
|---|
| 56 |
|
|---|
| 57 | #define SST_begin 0x00 /* Begin block */
|
|---|
| 58 | #define SST_proc 0x01 /* Procedure */
|
|---|
| 59 | #define SST_end 0x02 /* End block or end procedure */
|
|---|
| 60 | #define SST_auto 0x04 /* Scoped variable */
|
|---|
| 61 | #define SST_static 0x05 /* Static variable */
|
|---|
| 62 | #define SST_reg 0x0d /* Register variable */
|
|---|
| 63 | #define SST_changseg 0x11 /* Change default segment */
|
|---|
| 64 | #define SST_tag 0x16 /* Structure, union, enum tags */
|
|---|
| 65 | #define SST_tag2 0x19 /* Extended tag for long names (C++ class). */
|
|---|
| 66 | #define SST_memfunc 0x1a /* C++ member function */
|
|---|
| 67 | #define SST_CPPproc 0x1d /* C++ function */
|
|---|
| 68 | #define SST_CPPstatic 0x1e /* C++ static variable */
|
|---|
| 69 | #define SST_cuinfo 0x40 /* Compile unit information */
|
|---|
| 70 |
|
|---|
| 71 | /* Class visibility. */
|
|---|
| 72 |
|
|---|
| 73 | #define VIS_PRIVATE 0x00 /* private */
|
|---|
| 74 | #define VIS_PROTECTED 0x01 /* protected */
|
|---|
| 75 | #define VIS_PUBLIC 0x02 /* public */
|
|---|
| 76 |
|
|---|
| 77 | #define MEMBER_VIS 0x03 /* Member visibility mask */
|
|---|
| 78 | #define MEMBER_FUNCTION 0x08 /* It's a member function */
|
|---|
| 79 | #define MEMBER_VIRTUAL 0x10 /* Member function / base class is virtual */
|
|---|
| 80 | #define MEMBER_VOLATILE 0x20 /* Member function is volatile */
|
|---|
| 81 | #define MEMBER_CONST 0x40 /* Member function is const */
|
|---|
| 82 | #define MEMBER_STATIC 0x80 /* Member is static */
|
|---|
| 83 | #define MEMBER_CTOR 0x100 /* Member function is a constructor */
|
|---|
| 84 | #define MEMBER_DTOR 0x200 /* Member function is a destructor */
|
|---|
| 85 | #define MEMBER_BASE 0x400 /* It's a base class */
|
|---|
| 86 |
|
|---|
| 87 | /* Flags for ty_struc. */
|
|---|
| 88 |
|
|---|
| 89 | #define STRUC_FORWARD 0x01 /* Structure declared forward */
|
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 | /*******************************************************************************
|
|---|
| 93 | * Structures and Typedefs *
|
|---|
| 94 | *******************************************************************************/
|
|---|
| 95 | enum type_tag
|
|---|
| 96 | {
|
|---|
| 97 | ty_stabs_ref, /* Reference to stabs type */
|
|---|
| 98 | ty_prim, /* Primitive type */
|
|---|
| 99 | ty_alias, /* Equivalent type */
|
|---|
| 100 | ty_pointer, /* Pointer type */
|
|---|
| 101 | ty_func, /* Function */
|
|---|
| 102 | ty_args, /* Function arguments */
|
|---|
| 103 | ty_struc, /* Structure or union */
|
|---|
| 104 | ty_types, /* Type list for structure/union */
|
|---|
| 105 | ty_fields, /* Field list for structure/union */
|
|---|
| 106 | ty_enu, /* Enumeration type */
|
|---|
| 107 | ty_values, /* Enumeration values */
|
|---|
| 108 | ty_array, /* Array */
|
|---|
| 109 | ty_bits, /* Bit field / bit string */
|
|---|
| 110 | ty_ref, /* Reference type (C++) */
|
|---|
| 111 | ty_member, /* Member of a C++ class */
|
|---|
| 112 | ty_class, /* A C++ class */
|
|---|
| 113 | ty_memfunc, /* A C++ member function */
|
|---|
| 114 | ty_baseclass, /* A C++ base class */
|
|---|
| 115 | ty_max
|
|---|
| 116 | };
|
|---|
| 117 |
|
|---|
| 118 | /* A structure field. */
|
|---|
| 119 |
|
|---|
| 120 | struct field
|
|---|
| 121 | {
|
|---|
| 122 | dword offset; /* Offset, in bytes */
|
|---|
| 123 | const char *name; /* Field name */
|
|---|
| 124 | };
|
|---|
| 125 |
|
|---|
| 126 | /* An enumeration value. */
|
|---|
| 127 |
|
|---|
| 128 | struct value
|
|---|
| 129 | {
|
|---|
| 130 | long index; /* The value */
|
|---|
| 131 | const char *name; /* The name */
|
|---|
| 132 | };
|
|---|
| 133 |
|
|---|
| 134 | /* Temporary representation of a structure field. */
|
|---|
| 135 |
|
|---|
| 136 | struct tmp_field
|
|---|
| 137 | {
|
|---|
| 138 | struct type *type; /* The internal type */
|
|---|
| 139 | dword offset; /* The offset of the field */
|
|---|
| 140 | const char *name; /* The field name */
|
|---|
| 141 | const char *sname; /* Static name */
|
|---|
| 142 | const char *mnglname; /* Mangled name for methods. (#456) */
|
|---|
| 143 | int flags; /* Member flags (visibility) */
|
|---|
| 144 | };
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 | /* Internal representation of a type. */
|
|---|
| 148 |
|
|---|
| 149 | struct type
|
|---|
| 150 | {
|
|---|
| 151 | enum type_tag tag; /* The type of this type */
|
|---|
| 152 | int index; /* The HLL index for this type */
|
|---|
| 153 | struct type *next; /* All types are chained in a single list */
|
|---|
| 154 | struct type *nexthash; /* All types are chained in the hash list */
|
|---|
| 155 | union
|
|---|
| 156 | {
|
|---|
| 157 | int stabs_ref; /* Reference a stabs type */
|
|---|
| 158 | struct type *pointer; /* Pointer to another type */
|
|---|
| 159 | struct type *alias; /* Alias for another type */
|
|---|
| 160 | struct type *ref; /* Reference to another type */
|
|---|
| 161 | struct
|
|---|
| 162 | { /* Structure */
|
|---|
| 163 | struct type *types; /* Types of the fields */
|
|---|
| 164 | struct type *fields; /* Field names and offsets */
|
|---|
| 165 | dword size; /* Size of the structure, in bytes */
|
|---|
| 166 | word count; /* Number of fields */
|
|---|
| 167 | word flags; /* Flags (STRUC_FORWARD) */
|
|---|
| 168 | const char *name; /* Name of the structure */
|
|---|
| 169 | } struc;
|
|---|
| 170 | struct
|
|---|
| 171 | { /* Class */
|
|---|
| 172 | struct type *members; /* Members */
|
|---|
| 173 | dword size; /* Size of the class, in bytes */
|
|---|
| 174 | word count; /* Number of fields */
|
|---|
| 175 | const char *name; /* Name of the class */
|
|---|
| 176 | } class;
|
|---|
| 177 | struct
|
|---|
| 178 | { /* Enumeration */
|
|---|
| 179 | struct type *type; /* Base type */
|
|---|
| 180 | struct type *values; /* Values */
|
|---|
| 181 | long first; /* Smallest value */
|
|---|
| 182 | long last; /* Biggest value */
|
|---|
| 183 | const char *name; /* Name of the enum */
|
|---|
| 184 | } enu;
|
|---|
| 185 | struct
|
|---|
| 186 | { /* Array */
|
|---|
| 187 | struct type *itype; /* Index type */
|
|---|
| 188 | struct type *etype; /* Element type */
|
|---|
| 189 | long first; /* First index */
|
|---|
| 190 | long last; /* Last index */
|
|---|
| 191 | } array;
|
|---|
| 192 | struct
|
|---|
| 193 | { /* Bitfield */
|
|---|
| 194 | struct type *type; /* Base type */
|
|---|
| 195 | long start; /* First bit */
|
|---|
| 196 | long count; /* Number of bits */
|
|---|
| 197 | } bits;
|
|---|
| 198 | struct
|
|---|
| 199 | { /* Function */
|
|---|
| 200 | struct type *ret; /* Return type */
|
|---|
| 201 | struct type *args; /* Argument types */
|
|---|
| 202 | struct type *domain; /* Domain type (C++ member) (#456) */
|
|---|
| 203 | int arg_count; /* Number of arguments */
|
|---|
| 204 | } func;
|
|---|
| 205 | struct
|
|---|
| 206 | { /* Function arguments */
|
|---|
| 207 | struct type **list; /* Array of argument types */
|
|---|
| 208 | int count; /* Number of arguments */
|
|---|
| 209 | } args;
|
|---|
| 210 | struct
|
|---|
| 211 | { /* List of types */
|
|---|
| 212 | struct type **list; /* Array of types */
|
|---|
| 213 | int count; /* Number of types */
|
|---|
| 214 | } types;
|
|---|
| 215 | struct
|
|---|
| 216 | { /* Structure fields */
|
|---|
| 217 | struct field *list; /* The fields */
|
|---|
| 218 | int count; /* Number of fields */
|
|---|
| 219 | } fields;
|
|---|
| 220 | struct
|
|---|
| 221 | { /* Class member */
|
|---|
| 222 | struct type *type; /* Type of the member */
|
|---|
| 223 | dword offset; /* Offset of the member, in bytes */
|
|---|
| 224 | int flags; /* Member flags (visibility etc.) */
|
|---|
| 225 | const char *name; /* Name of the member */
|
|---|
| 226 | const char *sname; /* Static name */
|
|---|
| 227 | } member;
|
|---|
| 228 | struct
|
|---|
| 229 | { /* Enumeration values */
|
|---|
| 230 | struct value *list; /* Array of values */
|
|---|
| 231 | int count; /* Number of values */
|
|---|
| 232 | } values;
|
|---|
| 233 | struct
|
|---|
| 234 | { /* Member function */
|
|---|
| 235 | struct type *type; /* Function type */
|
|---|
| 236 | dword offset; /* Offset in the virtual table */
|
|---|
| 237 | int flags; /* Member flags (visibility etc.) */
|
|---|
| 238 | const char *name; /* Name of the member function */
|
|---|
| 239 | const char *mnglname; /* Mangled Name of the member function. (#456) */
|
|---|
| 240 | } memfunc;
|
|---|
| 241 | struct
|
|---|
| 242 | { /* Base class */
|
|---|
| 243 | struct type *type; /* The base class */
|
|---|
| 244 | dword offset; /* Offset of the base class */
|
|---|
| 245 | int flags; /* Visibility, virtual */
|
|---|
| 246 | } baseclass;
|
|---|
| 247 | } d;
|
|---|
| 248 | };
|
|---|
| 249 |
|
|---|
| 250 |
|
|---|
| 251 | /* A block. */
|
|---|
| 252 |
|
|---|
| 253 | struct block
|
|---|
| 254 | {
|
|---|
| 255 | dword addr; /* Start address of the block */
|
|---|
| 256 | size_t patch_ptr; /* Index into SST buffer for patching */
|
|---|
| 257 | };
|
|---|
| 258 |
|
|---|
| 259 | /* Timestamp for the compiler unit information SST subrecord. */
|
|---|
| 260 |
|
|---|
| 261 | #pragma pack(1)
|
|---|
| 262 |
|
|---|
| 263 | struct timestamp
|
|---|
| 264 | {
|
|---|
| 265 | byte hours;
|
|---|
| 266 | byte minutes;
|
|---|
| 267 | byte seconds;
|
|---|
| 268 | byte hundredths;
|
|---|
| 269 | byte day;
|
|---|
| 270 | byte month;
|
|---|
| 271 | word year;
|
|---|
| 272 | };
|
|---|
| 273 |
|
|---|
| 274 | #pragma pack()
|
|---|
| 275 |
|
|---|
| 276 |
|
|---|
| 277 | /*******************************************************************************
|
|---|
| 278 | * Global Variables *
|
|---|
| 279 | *******************************************************************************/
|
|---|
| 280 | /* This variable points to the next character of a stabs type being
|
|---|
| 281 | parsed. */
|
|---|
| 282 |
|
|---|
| 283 | static const char *parse_ptr;
|
|---|
| 284 |
|
|---|
| 285 | /* Start of the stabs string we're parsing. Useful when printing
|
|---|
| 286 | messages. */
|
|---|
| 287 | static const char *parse_start;
|
|---|
| 288 |
|
|---|
| 289 | /* Current stabs index. Useful when printing messages. */
|
|---|
| 290 | static int *parse_pindex;
|
|---|
| 291 |
|
|---|
| 292 | /* The next HLL type index. When creating a complex type, this index
|
|---|
| 293 | is used. Then, this variable is incremented. */
|
|---|
| 294 |
|
|---|
| 295 | static int hll_type_index;
|
|---|
| 296 |
|
|---|
| 297 | /* We keep all internal types in a single list. When creating a new
|
|---|
| 298 | type, we first look through the list to find out whether an
|
|---|
| 299 | identical type already exists. Doing a linear search is
|
|---|
| 300 | inefficient, but that doesn't matter here, according to
|
|---|
| 301 | experience. This variable points to the first type of the list. */
|
|---|
| 302 |
|
|---|
| 303 | static struct type *type_head;
|
|---|
| 304 | #define TYPE_HASH_MAX 211
|
|---|
| 305 | static struct type *atype_tag[TYPE_HASH_MAX];
|
|---|
| 306 | #ifdef HASH_DEBUG
|
|---|
| 307 | static int ctypes = 0;
|
|---|
| 308 | static int ctype_tag[TYPE_HASH_MAX];
|
|---|
| 309 | #endif
|
|---|
| 310 |
|
|---|
| 311 | /* This growing array keeps track of stabs vs. internal types. It is
|
|---|
| 312 | indexed by stabs type numbers. */
|
|---|
| 313 |
|
|---|
| 314 | static struct type **stype_list;
|
|---|
| 315 | static struct grow stype_grow;
|
|---|
| 316 |
|
|---|
| 317 | /* We collect function arguments in this growing array. */
|
|---|
| 318 |
|
|---|
| 319 | static struct type **args_list;
|
|---|
| 320 | static struct grow args_grow;
|
|---|
| 321 |
|
|---|
| 322 | /* This stack (implemented with a growing array) keeps track of
|
|---|
| 323 | begin/end block nesting. */
|
|---|
| 324 |
|
|---|
| 325 | static struct block *block_stack;
|
|---|
| 326 | static struct grow block_grow;
|
|---|
| 327 |
|
|---|
| 328 | /* This string pool contains field names etc. */
|
|---|
| 329 |
|
|---|
| 330 | static struct strpool *str_pool;
|
|---|
| 331 |
|
|---|
| 332 | /* This variable holds the sym_ptr index of the most recently
|
|---|
| 333 | encountered N_LBRAC symbol. */
|
|---|
| 334 |
|
|---|
| 335 | static int lbrac_index;
|
|---|
| 336 |
|
|---|
| 337 | /* The index (in sst) of the most recently started SST subrecord. */
|
|---|
| 338 |
|
|---|
| 339 | static size_t subrec_start;
|
|---|
| 340 |
|
|---|
| 341 | /* The proc_patch_base contains the index where the base address and
|
|---|
| 342 | function length are to be patched into the SST. */
|
|---|
| 343 |
|
|---|
| 344 | static size_t proc_patch_base;
|
|---|
| 345 |
|
|---|
| 346 | /* The base address used by the most recently proc record in the
|
|---|
| 347 | SST. */
|
|---|
| 348 |
|
|---|
| 349 | static size_t proc_start_addr;
|
|---|
| 350 |
|
|---|
| 351 | /* The internal type of the most recently defined function. Valid
|
|---|
| 352 | only if last_fun_valid is TRUE. */
|
|---|
| 353 |
|
|---|
| 354 | static struct type last_fun_type;
|
|---|
| 355 |
|
|---|
| 356 | /* This variable is TRUE if a function has recently been defined. */
|
|---|
| 357 |
|
|---|
| 358 | static int last_fun_valid;
|
|---|
| 359 |
|
|---|
| 360 | /* The length of the prologue of the most recently defined
|
|---|
| 361 | function. */
|
|---|
| 362 |
|
|---|
| 363 | static int prologue_length;
|
|---|
| 364 |
|
|---|
| 365 | /* The address of the most recently defined function. */
|
|---|
| 366 |
|
|---|
| 367 | static dword last_fun_addr;
|
|---|
| 368 |
|
|---|
| 369 | /* This variable is non-zero when converting a translated C++
|
|---|
| 370 | program. */
|
|---|
| 371 |
|
|---|
| 372 | static int cplusplus_flag;
|
|---|
| 373 |
|
|---|
| 374 | /* Unnamed structures are numbered sequentially, using this
|
|---|
| 375 | counter. */
|
|---|
| 376 |
|
|---|
| 377 | static int unnamed_struct_number;
|
|---|
| 378 |
|
|---|
| 379 | /* kso #456 2003-06-11: Reversed quiet workaround. */
|
|---|
| 380 | #define no_warning warning_parse
|
|---|
| 381 |
|
|---|
| 382 |
|
|---|
| 383 | /*******************************************************************************
|
|---|
| 384 | * Internal Functions *
|
|---|
| 385 | *******************************************************************************/
|
|---|
| 386 | static void parse_typedef (int *index);
|
|---|
| 387 | static void warning_parse (const char *pszFormat, ...);
|
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 | /**
|
|---|
| 391 | * Report an warning in which might be connecting to parsing.
|
|---|
| 392 | *
|
|---|
| 393 | * @param pszFormat Message string.
|
|---|
| 394 | * @param ... More arguments
|
|---|
| 395 | */
|
|---|
| 396 | static void warning_parse (const char *pszFormat, ...)
|
|---|
| 397 | {
|
|---|
| 398 | va_list args;
|
|---|
| 399 |
|
|---|
| 400 | va_start (args, pszFormat);
|
|---|
| 401 | fprintf (stderr, "emxomf warning: ");
|
|---|
| 402 | vfprintf (stderr, pszFormat, args);
|
|---|
| 403 | va_end (args);
|
|---|
| 404 | fputc ('\n', stderr);
|
|---|
| 405 |
|
|---|
| 406 |
|
|---|
| 407 | if (parse_ptr && parse_start && parse_ptr >= parse_start)
|
|---|
| 408 | {
|
|---|
| 409 | if (parse_pindex && *parse_pindex >= 0 && *parse_pindex < sym_count)
|
|---|
| 410 | fprintf (stderr, "emxomf info: parsing sym no.%d type=%d at char '%c' in position %d:\n%s\n",
|
|---|
| 411 | *parse_pindex, sym_ptr[*parse_pindex].n_type,
|
|---|
| 412 | *parse_ptr, parse_ptr - parse_start, parse_start);
|
|---|
| 413 | else
|
|---|
| 414 | fprintf (stderr, "emxomf info: parsing '%c' at position %d:\n%s\n",
|
|---|
| 415 | *parse_ptr, parse_ptr - parse_start, parse_start);
|
|---|
| 416 | }
|
|---|
| 417 | }
|
|---|
| 418 |
|
|---|
| 419 |
|
|---|
| 420 | /* Start a type table record of type TYPE, with type qualifier QUAL.
|
|---|
| 421 | tt_end() must be called to finish the record after writing the
|
|---|
| 422 | record contents. */
|
|---|
| 423 |
|
|---|
| 424 | static void tt_start (byte type, byte qual)
|
|---|
| 425 | {
|
|---|
| 426 | subrec_start = tt.size;
|
|---|
| 427 | grow_by (&tt_boundary_grow, 1);
|
|---|
| 428 | tt_boundary[tt_boundary_grow.count++] = tt.size;
|
|---|
| 429 | buffer_word (&tt, 0); /* Length of sub-record */
|
|---|
| 430 | buffer_byte (&tt, type); /* Type of sub-record */
|
|---|
| 431 | buffer_byte (&tt, qual); /* Type qualifier */
|
|---|
| 432 | }
|
|---|
| 433 |
|
|---|
| 434 |
|
|---|
| 435 | /* Finish a type table record. This function must be called after
|
|---|
| 436 | tt_start(). */
|
|---|
| 437 |
|
|---|
| 438 | static void tt_end (void)
|
|---|
| 439 | {
|
|---|
| 440 | *(word *)(tt.buf + subrec_start) = tt.size - subrec_start - 2;
|
|---|
| 441 | }
|
|---|
| 442 |
|
|---|
| 443 |
|
|---|
| 444 | /* Put the type index TI into the type table. TI = -1 encodes the
|
|---|
| 445 | `nil' type (no type), 0x97 encodes the `void' type. All other
|
|---|
| 446 | values are type indices. */
|
|---|
| 447 |
|
|---|
| 448 | static void tt_index (int ti)
|
|---|
| 449 | {
|
|---|
| 450 | if (ti == -1) /* nil */
|
|---|
| 451 | buffer_byte (&tt, FID_nil);
|
|---|
| 452 | else if (ti == 0x97) /* void */
|
|---|
| 453 | buffer_byte (&tt, FID_void);
|
|---|
| 454 | else
|
|---|
| 455 | {
|
|---|
| 456 | buffer_byte (&tt, FID_index);
|
|---|
| 457 | buffer_word (&tt, ti);
|
|---|
| 458 | }
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 |
|
|---|
| 462 | /* Put an 8-bit byte into the type table. */
|
|---|
| 463 |
|
|---|
| 464 | static void tt_byte (byte x)
|
|---|
| 465 | {
|
|---|
| 466 | buffer_byte (&tt, x);
|
|---|
| 467 | }
|
|---|
| 468 |
|
|---|
| 469 |
|
|---|
| 470 | /* Put a 16-bit word into the type table. */
|
|---|
| 471 |
|
|---|
| 472 | static void tt_word (word x)
|
|---|
| 473 | {
|
|---|
| 474 | buffer_word (&tt, x);
|
|---|
| 475 | }
|
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 | /* Put a 32-bit double word into the type table. */
|
|---|
| 479 |
|
|---|
| 480 | static void tt_dword (dword x)
|
|---|
| 481 | {
|
|---|
| 482 | buffer_dword (&tt, x);
|
|---|
| 483 | }
|
|---|
| 484 |
|
|---|
| 485 |
|
|---|
| 486 | /* Put the name S into the type table. */
|
|---|
| 487 |
|
|---|
| 488 | static void tt_name (const char *s)
|
|---|
| 489 | {
|
|---|
| 490 | buffer_byte (&tt, FID_string);
|
|---|
| 491 | buffer_nstr (&tt, s);
|
|---|
| 492 | }
|
|---|
| 493 |
|
|---|
| 494 |
|
|---|
| 495 | /* Put the mangled name S into the type table. */
|
|---|
| 496 |
|
|---|
| 497 | static void tt_enc (const char *s)
|
|---|
| 498 | {
|
|---|
| 499 | buffer_enc (&tt, s);
|
|---|
| 500 | }
|
|---|
| 501 |
|
|---|
| 502 |
|
|---|
| 503 | /* Put the unsigned number N into the type table. Depending on the
|
|---|
| 504 | magnitude of N, different encodings are used. */
|
|---|
| 505 |
|
|---|
| 506 | static void tt_unsigned_span (dword n)
|
|---|
| 507 | {
|
|---|
| 508 | if (n <= 0xff)
|
|---|
| 509 | {
|
|---|
| 510 | buffer_byte (&tt, FID_span_8u);
|
|---|
| 511 | buffer_byte (&tt, n);
|
|---|
| 512 | }
|
|---|
| 513 | else if (n <= 0xffff)
|
|---|
| 514 | {
|
|---|
| 515 | buffer_byte (&tt, FID_span_16u);
|
|---|
| 516 | buffer_word (&tt, n);
|
|---|
| 517 | }
|
|---|
| 518 | else
|
|---|
| 519 | {
|
|---|
| 520 | buffer_byte (&tt, FID_span_32u);
|
|---|
| 521 | buffer_dword (&tt, n);
|
|---|
| 522 | }
|
|---|
| 523 | }
|
|---|
| 524 |
|
|---|
| 525 |
|
|---|
| 526 | /* Put the signed number N into the type table. Depending on the
|
|---|
| 527 | magnitude of N, different encodings are used. */
|
|---|
| 528 |
|
|---|
| 529 | static void tt_signed_span (long n)
|
|---|
| 530 | {
|
|---|
| 531 | if (-127 <= n && n <= 127)
|
|---|
| 532 | {
|
|---|
| 533 | buffer_byte (&tt, FID_span_8s);
|
|---|
| 534 | buffer_byte (&tt, n);
|
|---|
| 535 | }
|
|---|
| 536 | else if (-32767 <= n && n <= 32767)
|
|---|
| 537 | {
|
|---|
| 538 | buffer_byte (&tt, FID_span_16s);
|
|---|
| 539 | buffer_word (&tt, n);
|
|---|
| 540 | }
|
|---|
| 541 | else
|
|---|
| 542 | {
|
|---|
| 543 | buffer_byte (&tt, FID_span_32s);
|
|---|
| 544 | buffer_dword (&tt, n);
|
|---|
| 545 | }
|
|---|
| 546 | }
|
|---|
| 547 |
|
|---|
| 548 |
|
|---|
| 549 | /* Start a static scope table subrecord of type TYPE. sst_end() must
|
|---|
| 550 | be called to finish the subrecord after writing the subrecord
|
|---|
| 551 | data. */
|
|---|
| 552 |
|
|---|
| 553 | static void sst_start (byte type)
|
|---|
| 554 | {
|
|---|
| 555 | subrec_start = sst.size;
|
|---|
| 556 | grow_by (&sst_boundary_grow, 1);
|
|---|
| 557 | sst_boundary[sst_boundary_grow.count++] = sst.size;
|
|---|
| 558 | /* Length of sub-record - bird: not sure if HL03 likes this. */
|
|---|
| 559 | buffer_byte (&sst, 0x80);
|
|---|
| 560 | buffer_byte (&sst, 0);
|
|---|
| 561 | /* Type of sub-record */
|
|---|
| 562 | buffer_byte (&sst, type);
|
|---|
| 563 | }
|
|---|
| 564 |
|
|---|
| 565 |
|
|---|
| 566 | /* Finish a static scope table subrecord. This function must be
|
|---|
| 567 | called after sst_start(). */
|
|---|
| 568 |
|
|---|
| 569 | static void sst_end (void)
|
|---|
| 570 | {
|
|---|
| 571 | int len = sst.size - subrec_start - 2;
|
|---|
| 572 | /* -- experimental...
|
|---|
| 573 | if (len > 1000)
|
|---|
| 574 | error ("sst_end: Record too big");
|
|---|
| 575 | */
|
|---|
| 576 | sst.buf[subrec_start] = (len >> 8) | 0x80;
|
|---|
| 577 | sst.buf[subrec_start + 1] = 0xff & len;
|
|---|
| 578 | }
|
|---|
| 579 |
|
|---|
| 580 |
|
|---|
| 581 | /* Define a static variable in the static scope table. NAME is the
|
|---|
| 582 | name of the variable, ADDR is the address of the variable (segment
|
|---|
| 583 | offset), TYPE_INDEX is the HLL type index. If EXT is zero, SYM_SEG
|
|---|
| 584 | is the segment (N_DATA, for instance). If EXT is non-zero, SYM_SEG
|
|---|
| 585 | is the stabs symbol index (for the relocation table). This
|
|---|
| 586 | function also creates appropriate relocation table entries. */
|
|---|
| 587 |
|
|---|
| 588 | static void sst_static (const char *name, dword addr, int type_index,
|
|---|
| 589 | int sym_seg, int ext, const struct nlist *psym)
|
|---|
| 590 | {
|
|---|
| 591 | struct relocation_info r;
|
|---|
| 592 | size_t len = strlen (name);
|
|---|
| 593 |
|
|---|
| 594 | if (!psym)
|
|---|
| 595 | {
|
|---|
| 596 | psym = find_symbol_ex (name, -1, ext);
|
|---|
| 597 | if (!psym)
|
|---|
| 598 | {
|
|---|
| 599 | char *psz = alloca (len + 2);
|
|---|
| 600 | *psz = '_';
|
|---|
| 601 | memcpy(psz + 1, name, len + 1);
|
|---|
| 602 | psym = find_symbol_ex (psz, -1, ext);
|
|---|
| 603 | }
|
|---|
| 604 | }
|
|---|
| 605 | if (psym)
|
|---|
| 606 | set_hll_type (psym - sym_ptr, type_index);
|
|---|
| 607 |
|
|---|
| 608 | if (len > 255)
|
|---|
| 609 | sst_start (SST_CPPstatic);
|
|---|
| 610 | else
|
|---|
| 611 | sst_start (SST_static);
|
|---|
| 612 | r.r_address = sst.size;
|
|---|
| 613 | buffer_dword (&sst, addr); /* Segment offset */
|
|---|
| 614 | buffer_word (&sst, 0); /* Segment address */
|
|---|
| 615 | buffer_word (&sst, type_index); /* Type index */
|
|---|
| 616 | if (len > 255)
|
|---|
| 617 | buffer_enc (&sst, name); /* Symbol name - encoded. */
|
|---|
| 618 | else
|
|---|
| 619 | buffer_nstr (&sst, name); /* Symbol name */
|
|---|
| 620 | sst_end ();
|
|---|
| 621 | r.r_extern = ext;
|
|---|
| 622 | r.r_length = 2;
|
|---|
| 623 | r.r_symbolnum = sym_seg;
|
|---|
| 624 | r.r_pcrel = 0;
|
|---|
| 625 | r.r_pad = 0;
|
|---|
| 626 | buffer_mem (&sst_reloc, &r, sizeof (r));
|
|---|
| 627 | r.r_address += 4;
|
|---|
| 628 | r.r_length = 1;
|
|---|
| 629 | buffer_mem (&sst_reloc, &r, sizeof (r));
|
|---|
| 630 | }
|
|---|
| 631 |
|
|---|
| 632 | /**
|
|---|
| 633 | * Try calculate a good hash (yeah sure).
|
|---|
| 634 | *
|
|---|
| 635 | * @returns hash index.
|
|---|
| 636 | * @param t type
|
|---|
| 637 | */
|
|---|
| 638 | static inline unsigned type_hash (struct type *t)
|
|---|
| 639 | {
|
|---|
| 640 | register unsigned uhash = 0;
|
|---|
| 641 | switch (t->tag)
|
|---|
| 642 | {
|
|---|
| 643 | case ty_alias: uhash = (unsigned)t->d.alias; break;
|
|---|
| 644 | case ty_stabs_ref: uhash = (unsigned)t->d.stabs_ref; break;
|
|---|
| 645 | case ty_prim: uhash = (unsigned)t->index; break;
|
|---|
| 646 | case ty_pointer: uhash = (unsigned)t->d.pointer; break;
|
|---|
| 647 | case ty_ref: uhash = (unsigned)t->d.ref; break;
|
|---|
| 648 | case ty_struc: uhash = (unsigned)t->d.struc.name; break;
|
|---|
| 649 | case ty_class: uhash = (unsigned)t->d.class.name; break;
|
|---|
| 650 | case ty_enu: uhash = (unsigned)t->d.enu.name; break;
|
|---|
| 651 | case ty_array: uhash = (unsigned)t->d.array.etype; break;
|
|---|
| 652 | case ty_bits: uhash = (unsigned)t->d.bits.type; break;
|
|---|
| 653 | case ty_func: uhash = (unsigned)t->d.func.args ^ (unsigned)t->d.func.arg_count ^ (unsigned)t->d.func.ret ^ (unsigned)t->d.func.domain; break;
|
|---|
| 654 | case ty_types: uhash = (unsigned)t->d.types.count << 3; break;
|
|---|
| 655 | case ty_args: uhash = (unsigned)t->d.args.count << 3; break;
|
|---|
| 656 | case ty_fields: uhash = (unsigned)t->d.fields.count << 3; break;
|
|---|
| 657 | case ty_member: uhash = (unsigned)t->d.member.type ^ (unsigned)t->d.member.name >> 7; break;
|
|---|
| 658 | case ty_values: uhash = (unsigned)t->d.values.count << 3; break;
|
|---|
| 659 | case ty_memfunc: uhash = (unsigned)t->d.memfunc.type; break;
|
|---|
| 660 | case ty_baseclass: uhash = (unsigned)t->d.baseclass.type; break;
|
|---|
| 661 | default:break; /* shut up warnings. */
|
|---|
| 662 | }
|
|---|
| 663 | uhash += t->tag;
|
|---|
| 664 | return (uhash ^ uhash >> 13) % TYPE_HASH_MAX;
|
|---|
| 665 | }
|
|---|
| 666 |
|
|---|
| 667 |
|
|---|
| 668 | /**
|
|---|
| 669 | * Search a list for a type.
|
|---|
| 670 | * @returns pointer to the type we found.
|
|---|
| 671 | * @returns NULL if not found.
|
|---|
| 672 | * @param p Pointer to the head list.
|
|---|
| 673 | * @param src Type to find.
|
|---|
| 674 | * @param fhash Whether or not to follow the hash list or the main list.
|
|---|
| 675 | */
|
|---|
| 676 | #ifdef HASH_DEBUG
|
|---|
| 677 | static struct type *type_find (struct type *p, const struct type *src, int fhash)
|
|---|
| 678 | #else
|
|---|
| 679 | static struct type *type_find (struct type *p, const struct type *src)
|
|---|
| 680 | #endif
|
|---|
| 681 | {
|
|---|
| 682 | int i;
|
|---|
| 683 | for (; p != NULL;
|
|---|
| 684 | #ifdef HASH_DEBUG
|
|---|
| 685 | p = fhash ? p->nexthash : p->next )
|
|---|
| 686 | #else
|
|---|
| 687 | p = p->nexthash )
|
|---|
| 688 | #endif
|
|---|
| 689 | if (p->tag == src->tag)
|
|---|
| 690 | switch (p->tag)
|
|---|
| 691 | {
|
|---|
| 692 | case ty_alias:
|
|---|
| 693 | if (p->d.alias == src->d.alias)
|
|---|
| 694 | return p;
|
|---|
| 695 | break;
|
|---|
| 696 | case ty_stabs_ref:
|
|---|
| 697 | if (p->d.stabs_ref == src->d.stabs_ref)
|
|---|
| 698 | return p;
|
|---|
| 699 | break;
|
|---|
| 700 | case ty_prim:
|
|---|
| 701 | if (p->index == src->index)
|
|---|
| 702 | return p;
|
|---|
| 703 | break;
|
|---|
| 704 | case ty_pointer:
|
|---|
| 705 | if (p->d.pointer == src->d.pointer)
|
|---|
| 706 | return p;
|
|---|
| 707 | break;
|
|---|
| 708 | case ty_ref:
|
|---|
| 709 | if (p->d.ref == src->d.ref)
|
|---|
| 710 | return p;
|
|---|
| 711 | break;
|
|---|
| 712 | case ty_struc:
|
|---|
| 713 | if (p->d.struc.fields == src->d.struc.fields
|
|---|
| 714 | && p->d.struc.types == src->d.struc.types
|
|---|
| 715 | && p->d.struc.name == src->d.struc.name
|
|---|
| 716 | && p->d.struc.flags == src->d.struc.flags)
|
|---|
| 717 | return p;
|
|---|
| 718 | break;
|
|---|
| 719 | case ty_class:
|
|---|
| 720 | if (p->d.class.members == src->d.class.members
|
|---|
| 721 | && p->d.class.name == src->d.class.name)
|
|---|
| 722 | return p;
|
|---|
| 723 | break;
|
|---|
| 724 | case ty_enu:
|
|---|
| 725 | if (p->d.enu.type == src->d.enu.type
|
|---|
| 726 | && p->d.enu.values == src->d.enu.values
|
|---|
| 727 | && p->d.enu.name == src->d.enu.name)
|
|---|
| 728 | return p;
|
|---|
| 729 | break;
|
|---|
| 730 | case ty_array:
|
|---|
| 731 | if (p->d.array.etype == src->d.array.etype
|
|---|
| 732 | && p->d.array.itype == src->d.array.itype
|
|---|
| 733 | && p->d.array.first == src->d.array.first
|
|---|
| 734 | && p->d.array.last == src->d.array.last)
|
|---|
| 735 | return p;
|
|---|
| 736 | break;
|
|---|
| 737 | case ty_bits:
|
|---|
| 738 | if (p->d.bits.type == src->d.bits.type
|
|---|
| 739 | && p->d.bits.start == src->d.bits.start
|
|---|
| 740 | && p->d.bits.count == src->d.bits.count)
|
|---|
| 741 | return p;
|
|---|
| 742 | break;
|
|---|
| 743 | case ty_func:
|
|---|
| 744 | if (p->d.func.ret == src->d.func.ret
|
|---|
| 745 | && p->d.func.args == src->d.func.args
|
|---|
| 746 | && p->d.func.domain == src->d.func.domain
|
|---|
| 747 | && p->d.func.arg_count == src->d.func.arg_count)
|
|---|
| 748 | return p;
|
|---|
| 749 | break;
|
|---|
| 750 | case ty_args:
|
|---|
| 751 | if (p->d.args.count == src->d.args.count)
|
|---|
| 752 | {
|
|---|
| 753 | for (i = 0; i < p->d.args.count; ++i)
|
|---|
| 754 | if (p->d.args.list[i] != src->d.args.list[i])
|
|---|
| 755 | break;
|
|---|
| 756 | if (i >= p->d.args.count)
|
|---|
| 757 | return p;
|
|---|
| 758 | }
|
|---|
| 759 | break;
|
|---|
| 760 | case ty_types:
|
|---|
| 761 | if (p->d.types.count == src->d.types.count)
|
|---|
| 762 | {
|
|---|
| 763 | for (i = 0; i < p->d.types.count; ++i)
|
|---|
| 764 | if (p->d.types.list[i] != src->d.types.list[i])
|
|---|
| 765 | break;
|
|---|
| 766 | if (i >= p->d.types.count)
|
|---|
| 767 | return p;
|
|---|
| 768 | }
|
|---|
| 769 | break;
|
|---|
| 770 | case ty_fields:
|
|---|
| 771 | if (p->d.fields.count == src->d.fields.count)
|
|---|
| 772 | {
|
|---|
| 773 | for (i = 0; i < p->d.fields.count; ++i)
|
|---|
| 774 | if (p->d.fields.list[i].offset != src->d.fields.list[i].offset
|
|---|
| 775 | || p->d.fields.list[i].name != src->d.fields.list[i].name)
|
|---|
| 776 | break;
|
|---|
| 777 | if (i >= p->d.fields.count)
|
|---|
| 778 | return p;
|
|---|
| 779 | }
|
|---|
| 780 | break;
|
|---|
| 781 | case ty_member:
|
|---|
| 782 | if (p->d.member.type == src->d.member.type
|
|---|
| 783 | && p->d.member.offset == src->d.member.offset
|
|---|
| 784 | && p->d.member.flags == src->d.member.flags
|
|---|
| 785 | && p->d.member.name == src->d.member.name
|
|---|
| 786 | && p->d.member.sname == src->d.member.sname)
|
|---|
| 787 | return p;
|
|---|
| 788 | break;
|
|---|
| 789 | case ty_values:
|
|---|
| 790 | if (p->d.values.count == src->d.values.count)
|
|---|
| 791 | {
|
|---|
| 792 | for (i = 0; i < p->d.values.count; ++i)
|
|---|
| 793 | if (p->d.values.list[i].index != src->d.values.list[i].index
|
|---|
| 794 | || p->d.values.list[i].name != src->d.values.list[i].name)
|
|---|
| 795 | break;
|
|---|
| 796 | if (i >= p->d.values.count)
|
|---|
| 797 | return p;
|
|---|
| 798 | }
|
|---|
| 799 | break;
|
|---|
| 800 | case ty_memfunc:
|
|---|
| 801 | if (p->d.memfunc.type == src->d.memfunc.type
|
|---|
| 802 | && p->d.memfunc.offset == src->d.memfunc.offset
|
|---|
| 803 | && p->d.memfunc.flags == src->d.memfunc.flags
|
|---|
| 804 | && p->d.memfunc.name == src->d.memfunc.name
|
|---|
| 805 | && p->d.memfunc.mnglname == src->d.memfunc.mnglname)
|
|---|
| 806 | return p;
|
|---|
| 807 | break;
|
|---|
| 808 | case ty_baseclass:
|
|---|
| 809 | if (p->d.baseclass.type == src->d.baseclass.type
|
|---|
| 810 | && p->d.baseclass.offset == src->d.baseclass.offset
|
|---|
| 811 | && p->d.baseclass.flags == src->d.baseclass.flags)
|
|---|
| 812 | return p;
|
|---|
| 813 | break;
|
|---|
| 814 | default:
|
|---|
| 815 | abort ();
|
|---|
| 816 | }
|
|---|
| 817 | return NULL;
|
|---|
| 818 | }
|
|---|
| 819 |
|
|---|
| 820 |
|
|---|
| 821 | /* Add a new internal type to the list of internal types. If an
|
|---|
| 822 | identical type already exists, a pointer to that type is returned.
|
|---|
| 823 | Otherwise, a copy of the new type is added to the list and a
|
|---|
| 824 | pointer to that type is returned. It isn't worth my while to
|
|---|
| 825 | improve the speed of this function, for instance by using
|
|---|
| 826 | hashing.
|
|---|
| 827 |
|
|---|
| 828 | Actually it is worth while optimizing it as it takes 85% of the
|
|---|
| 829 | time here... or rather it was.
|
|---|
| 830 |
|
|---|
| 831 | ctypes=25301 */
|
|---|
| 832 |
|
|---|
| 833 | static struct type *type_add (struct type *src)
|
|---|
| 834 | {
|
|---|
| 835 | struct type *p;
|
|---|
| 836 | unsigned ihash;
|
|---|
| 837 | int i;
|
|---|
| 838 |
|
|---|
| 839 | ihash = type_hash(src);
|
|---|
| 840 | #ifdef HASH_DEBUG
|
|---|
| 841 | p = type_find (atype_tag[ihash], src, 1);
|
|---|
| 842 | #else
|
|---|
| 843 | p = type_find (atype_tag[ihash], src);
|
|---|
| 844 | #endif
|
|---|
| 845 | if (p)
|
|---|
| 846 | {
|
|---|
| 847 | return p;
|
|---|
| 848 | }
|
|---|
| 849 |
|
|---|
| 850 | #ifdef HASH_DEBUG
|
|---|
| 851 | /* {
|
|---|
| 852 | struct type *pcheck = type_find (type_head, src, 0);
|
|---|
| 853 | if (pcheck)
|
|---|
| 854 | {
|
|---|
| 855 | printf("\n\thash algorithm is borked! tag=%d\n", pcheck->tag);
|
|---|
| 856 | return pcheck;
|
|---|
| 857 | }
|
|---|
| 858 | } */
|
|---|
| 859 | ctype_tag[ihash]++;
|
|---|
| 860 | ctypes++;
|
|---|
| 861 | #endif
|
|---|
| 862 |
|
|---|
| 863 | p = xmalloc (sizeof (*p));
|
|---|
| 864 | *p = *src;
|
|---|
| 865 | p->next = type_head;
|
|---|
| 866 | type_head = p;
|
|---|
| 867 | p->nexthash = atype_tag[ihash];
|
|---|
| 868 | atype_tag[ihash] = p;
|
|---|
| 869 | switch (src->tag)
|
|---|
| 870 | {
|
|---|
| 871 | case ty_args:
|
|---|
| 872 | i = src->d.args.count * sizeof (*(src->d.args.list));
|
|---|
| 873 | p->d.args.list = xmalloc (i);
|
|---|
| 874 | memcpy (p->d.args.list, src->d.args.list, i);
|
|---|
| 875 | break;
|
|---|
| 876 | case ty_types:
|
|---|
| 877 | i = src->d.types.count * sizeof (*(src->d.types.list));
|
|---|
| 878 | p->d.types.list = xmalloc (i);
|
|---|
| 879 | memcpy (p->d.types.list, src->d.types.list, i);
|
|---|
| 880 | break;
|
|---|
| 881 | case ty_fields:
|
|---|
| 882 | i = src->d.fields.count * sizeof (*(src->d.fields.list));
|
|---|
| 883 | p->d.fields.list = xmalloc (i);
|
|---|
| 884 | memcpy (p->d.fields.list, src->d.fields.list, i);
|
|---|
| 885 | break;
|
|---|
| 886 | case ty_values:
|
|---|
| 887 | i = src->d.values.count * sizeof (*(src->d.values.list));
|
|---|
| 888 | p->d.values.list = xmalloc (i);
|
|---|
| 889 | memcpy (p->d.values.list, src->d.values.list, i);
|
|---|
| 890 | break;
|
|---|
| 891 | default:
|
|---|
| 892 | break;
|
|---|
| 893 | }
|
|---|
| 894 | return p;
|
|---|
| 895 | }
|
|---|
| 896 |
|
|---|
| 897 |
|
|---|
| 898 | /* Associate the stabs type number NUMBER with the internal type
|
|---|
| 899 | HLL. */
|
|---|
| 900 |
|
|---|
| 901 | static void stype_add (int number, struct type *hll)
|
|---|
| 902 | {
|
|---|
| 903 | int i;
|
|---|
| 904 |
|
|---|
| 905 | /* Stabs type numbers are greater than zero. */
|
|---|
| 906 |
|
|---|
| 907 | if (number < 1)
|
|---|
| 908 | error ("stype_add: Invalid type index %d", number);
|
|---|
| 909 |
|
|---|
| 910 | /* Remember the current size of the table and grow the table as
|
|---|
| 911 | required. */
|
|---|
| 912 |
|
|---|
| 913 | i = stype_grow.alloc;
|
|---|
| 914 | grow_to (&stype_grow, number);
|
|---|
| 915 |
|
|---|
| 916 | /* Initialize the new table entries. */
|
|---|
| 917 |
|
|---|
| 918 | while (i < stype_grow.alloc)
|
|---|
| 919 | stype_list[i++] = NULL;
|
|---|
| 920 |
|
|---|
| 921 | /* Put the type into the table. */
|
|---|
| 922 |
|
|---|
| 923 | #ifdef HLL_DEBUG
|
|---|
| 924 | printf (" type: stabs %d => HLL 0x%x\n", number, hll->index);
|
|---|
| 925 | #endif
|
|---|
| 926 | #if 0 /* not good test... as we do some types twice. */
|
|---|
| 927 | if (stype_list[number-1] != NULL && stype_list[number-1] != hll)
|
|---|
| 928 | warning ("Type stabs %d allready mapped to HLL 0x%x, new HLL 0x%x!!\n", number, stype_list[number-1]->index, hll->index);
|
|---|
| 929 | #endif
|
|---|
| 930 |
|
|---|
| 931 | stype_list[number-1] = hll;
|
|---|
| 932 | }
|
|---|
| 933 |
|
|---|
| 934 |
|
|---|
| 935 | /* Find the internal type associated with the stabs type number
|
|---|
| 936 | NUMBER. If there is no such type, return NULL. */
|
|---|
| 937 |
|
|---|
| 938 | static struct type *stype_find (int number)
|
|---|
| 939 | {
|
|---|
| 940 | /* Stabs type numbers are greater than zero. */
|
|---|
| 941 |
|
|---|
| 942 | if (number < 1)
|
|---|
| 943 | error ("stype_find: Invalid type index %d", number);
|
|---|
| 944 |
|
|---|
| 945 | /* Adjust the index and check if it is within the current size of
|
|---|
| 946 | the table. */
|
|---|
| 947 |
|
|---|
| 948 | --number;
|
|---|
| 949 | if (number >= stype_grow.alloc)
|
|---|
| 950 | return NULL;
|
|---|
| 951 | else
|
|---|
| 952 | return stype_list[number];
|
|---|
| 953 | }
|
|---|
| 954 |
|
|---|
| 955 |
|
|---|
| 956 | /* Dereference stabs references until finding a non-reference. */
|
|---|
| 957 |
|
|---|
| 958 | static const struct type *follow_refs (const struct type *t)
|
|---|
| 959 | {
|
|---|
| 960 | const struct type *t2;
|
|---|
| 961 |
|
|---|
| 962 | while (t->tag == ty_stabs_ref)
|
|---|
| 963 | {
|
|---|
| 964 | t2 = stype_find (t->d.stabs_ref);
|
|---|
| 965 | if (t2 == NULL)
|
|---|
| 966 | break;
|
|---|
| 967 | t = t2;
|
|---|
| 968 | }
|
|---|
| 969 |
|
|---|
| 970 | return t;
|
|---|
| 971 | }
|
|---|
| 972 |
|
|---|
| 973 |
|
|---|
| 974 | #if defined (HLL_DEBUG)
|
|---|
| 975 |
|
|---|
| 976 | /* This function is used to print an internal type for debugging. */
|
|---|
| 977 |
|
|---|
| 978 | static void show_type (struct type *tp)
|
|---|
| 979 | {
|
|---|
| 980 | /* precaution so we don't iterate for ever here when showing classes. */
|
|---|
| 981 | static int fShowClass;
|
|---|
| 982 | int i;
|
|---|
| 983 |
|
|---|
| 984 | /* Currently we crash when showing FILE (stdio.h). So, better not crash here.. */
|
|---|
| 985 | if (!tp)
|
|---|
| 986 | {
|
|---|
| 987 | printf("!!! error! NULL type pointer! !!!");
|
|---|
| 988 | return;
|
|---|
| 989 | }
|
|---|
| 990 |
|
|---|
| 991 | switch (tp->tag)
|
|---|
| 992 | {
|
|---|
| 993 | case ty_prim:
|
|---|
| 994 | printf ("%#x", tp->index);
|
|---|
| 995 | break;
|
|---|
| 996 | case ty_stabs_ref:
|
|---|
| 997 | printf ("t%d", tp->d.stabs_ref);
|
|---|
| 998 | break;
|
|---|
| 999 | case ty_alias:
|
|---|
| 1000 | show_type (tp->d.alias);
|
|---|
| 1001 | break;
|
|---|
| 1002 | case ty_pointer:
|
|---|
| 1003 | printf ("(");
|
|---|
| 1004 | show_type (tp->d.pointer);
|
|---|
| 1005 | printf (")*");
|
|---|
| 1006 | break;
|
|---|
| 1007 | case ty_ref:
|
|---|
| 1008 | printf ("(");
|
|---|
| 1009 | show_type (tp->d.ref);
|
|---|
| 1010 | printf (")&");
|
|---|
| 1011 | break;
|
|---|
| 1012 | case ty_struc:
|
|---|
| 1013 | printf ("{");
|
|---|
| 1014 | show_type (tp->d.struc.types);
|
|---|
| 1015 | printf ("}");
|
|---|
| 1016 | break;
|
|---|
| 1017 | case ty_class:
|
|---|
| 1018 | printf ("{");
|
|---|
| 1019 | if (!fShowClass)
|
|---|
| 1020 | {
|
|---|
| 1021 | fShowClass = 1;
|
|---|
| 1022 | show_type (tp->d.class.members);
|
|---|
| 1023 | fShowClass = 0;
|
|---|
| 1024 | }
|
|---|
| 1025 | else
|
|---|
| 1026 | printf ("<-!-!->");
|
|---|
| 1027 | printf ("}");
|
|---|
| 1028 | break;
|
|---|
| 1029 | case ty_enu:
|
|---|
| 1030 | printf ("{");
|
|---|
| 1031 | show_type (tp->d.enu.values);
|
|---|
| 1032 | printf ("}");
|
|---|
| 1033 | break;
|
|---|
| 1034 | case ty_array:
|
|---|
| 1035 | printf ("(");
|
|---|
| 1036 | show_type (tp->d.array.etype);
|
|---|
| 1037 | printf ("[%ld]", tp->d.array.last + 1 - tp->d.array.first);
|
|---|
| 1038 | break;
|
|---|
| 1039 | case ty_bits:
|
|---|
| 1040 | show_type (tp->d.bits.type);
|
|---|
| 1041 | printf (":%ld:%ld", tp->d.bits.start, tp->d.bits.count);
|
|---|
| 1042 | break;
|
|---|
| 1043 | case ty_func:
|
|---|
| 1044 | show_type (tp->d.func.ret);
|
|---|
| 1045 | printf ("(");
|
|---|
| 1046 | if (tp->d.func.args != NULL)
|
|---|
| 1047 | show_type (tp->d.func.args);
|
|---|
| 1048 | printf (")");
|
|---|
| 1049 | break;
|
|---|
| 1050 | case ty_args:
|
|---|
| 1051 | for (i = 0; i < tp->d.args.count; ++i)
|
|---|
| 1052 | {
|
|---|
| 1053 | if (i != 0)
|
|---|
| 1054 | printf (", ");
|
|---|
| 1055 | show_type (tp->d.args.list[i]);
|
|---|
| 1056 | }
|
|---|
| 1057 | break;
|
|---|
| 1058 | case ty_types:
|
|---|
| 1059 | for (i = 0; i < tp->d.types.count; ++i)
|
|---|
| 1060 | {
|
|---|
| 1061 | if (i != 0)
|
|---|
| 1062 | printf (", ");
|
|---|
| 1063 | show_type (tp->d.types.list[i]);
|
|---|
| 1064 | }
|
|---|
| 1065 | break;
|
|---|
| 1066 | case ty_fields:
|
|---|
| 1067 | for (i = 0; i < tp->d.fields.count; ++i)
|
|---|
| 1068 | {
|
|---|
| 1069 | if (i != 0)
|
|---|
| 1070 | printf (", ");
|
|---|
| 1071 | printf ("%s", tp->d.fields.list[i].name);
|
|---|
| 1072 | }
|
|---|
| 1073 | break;
|
|---|
| 1074 | case ty_member:
|
|---|
| 1075 | printf ("%s", tp->d.member.name);
|
|---|
| 1076 | break;
|
|---|
| 1077 | case ty_values:
|
|---|
| 1078 | for (i = 0; i < tp->d.values.count; ++i)
|
|---|
| 1079 | {
|
|---|
| 1080 | if (i != 0)
|
|---|
| 1081 | printf (", ");
|
|---|
| 1082 | printf ("%s", tp->d.values.list[i].name);
|
|---|
| 1083 | }
|
|---|
| 1084 | break;
|
|---|
| 1085 | case ty_memfunc:
|
|---|
| 1086 | show_type (tp->d.memfunc.type);
|
|---|
| 1087 | break;
|
|---|
| 1088 | case ty_baseclass:
|
|---|
| 1089 | printf ("{");
|
|---|
| 1090 | show_type (tp->d.baseclass.type);
|
|---|
| 1091 | printf ("}");
|
|---|
| 1092 | break;
|
|---|
| 1093 | default:
|
|---|
| 1094 | error ("show_type: Unknown type: %d", tp->tag);
|
|---|
| 1095 | }
|
|---|
| 1096 | }
|
|---|
| 1097 |
|
|---|
| 1098 | #endif
|
|---|
| 1099 |
|
|---|
| 1100 |
|
|---|
| 1101 | /**
|
|---|
| 1102 | * Tries to complete a struct forward reference.
|
|---|
| 1103 | *
|
|---|
| 1104 | * @returns 0 on success
|
|---|
| 1105 | * @returns 1 on failure.
|
|---|
| 1106 | * @param tp Pointer to the struct/class to complete.
|
|---|
| 1107 | * @remark Nasy hack for strstreambuf.
|
|---|
| 1108 | */
|
|---|
| 1109 | static int try_complete_struct(const struct type *tp)
|
|---|
| 1110 | {
|
|---|
| 1111 | int cch;
|
|---|
| 1112 | const char *pszName;
|
|---|
| 1113 | int i;
|
|---|
| 1114 |
|
|---|
| 1115 | if (tp->tag == ty_struc)
|
|---|
| 1116 | return 0;
|
|---|
| 1117 | if (tp->d.struc.flags != STRUC_FORWARD)
|
|---|
| 1118 | return 1;
|
|---|
| 1119 |
|
|---|
| 1120 | pszName = tp->d.struc.name;
|
|---|
| 1121 | cch = strlen(pszName);
|
|---|
| 1122 | for (i = 0; i < sym_count; ++i)
|
|---|
| 1123 | switch (sym_ptr[i].n_type)
|
|---|
| 1124 | {
|
|---|
| 1125 | case N_LSYM:
|
|---|
| 1126 | case N_LCSYM:
|
|---|
| 1127 | case N_GSYM:
|
|---|
| 1128 | case N_PSYM:
|
|---|
| 1129 | case N_RSYM:
|
|---|
| 1130 | case N_STSYM:
|
|---|
| 1131 | case N_FUN:
|
|---|
| 1132 | if ( !memcmp(str_ptr + sym_ptr[i].n_un.n_strx, pszName, cch)
|
|---|
| 1133 | && *(char*)(str_ptr + sym_ptr[i].n_un.n_strx + cch) == ':'
|
|---|
| 1134 | )
|
|---|
| 1135 | {
|
|---|
| 1136 | parse_typedef(&i);
|
|---|
| 1137 | return 1;
|
|---|
| 1138 | } /* if */
|
|---|
| 1139 | } /* switch */
|
|---|
| 1140 |
|
|---|
| 1141 | return 0;
|
|---|
| 1142 | }
|
|---|
| 1143 |
|
|---|
| 1144 |
|
|---|
| 1145 |
|
|---|
| 1146 | /* Return the size of the internal type TP, in bytes. */
|
|---|
| 1147 |
|
|---|
| 1148 | static dword type_size (const struct type *tp)
|
|---|
| 1149 | {
|
|---|
| 1150 | switch (tp->tag)
|
|---|
| 1151 | {
|
|---|
| 1152 | case ty_prim:
|
|---|
| 1153 |
|
|---|
| 1154 | /* Primitive types. */
|
|---|
| 1155 |
|
|---|
| 1156 | if (tp->index >= 0xa0 && tp->index <= 0xbf)
|
|---|
| 1157 | return 4; /* Near pointer */
|
|---|
| 1158 | switch (tp->index)
|
|---|
| 1159 | {
|
|---|
| 1160 | case 0x97: /* void */
|
|---|
| 1161 | return 0;
|
|---|
| 1162 | case 0x80: /* 8 bit signed */
|
|---|
| 1163 | case 0x84: /* 8 bit unsigned */
|
|---|
| 1164 | case 0x90: /* 8 bit boolean */
|
|---|
| 1165 | return 1;
|
|---|
| 1166 | case 0x81: /* 16 bit signed */
|
|---|
| 1167 | case 0x85: /* 16 bit unsigned */
|
|---|
| 1168 | return 2;
|
|---|
| 1169 | case 0x82: /* 32 bit signed */
|
|---|
| 1170 | case 0x86: /* 32 bit unsigned */
|
|---|
| 1171 | case 0x88: /* 32 bit real */
|
|---|
| 1172 | return 4;
|
|---|
| 1173 | case 0x89: /* 64 bit real */
|
|---|
| 1174 | case 0x8c: /* 64 bit complex */
|
|---|
| 1175 | return 8;
|
|---|
| 1176 | case 0x8a: /* 80 bit real (96 bits of storage) */
|
|---|
| 1177 | return 12;
|
|---|
| 1178 | case 0x8d: /* 128 bit complex */
|
|---|
| 1179 | return 16;
|
|---|
| 1180 | case 0x8e: /* 160 bit complex */
|
|---|
| 1181 | return 24;
|
|---|
| 1182 | case 0x8f: /* 256 bit complex (birds invention) */
|
|---|
| 1183 | return 32;
|
|---|
| 1184 | }
|
|---|
| 1185 | error ("type_size: Unknown primitive type: %d", tp->index);
|
|---|
| 1186 |
|
|---|
| 1187 | case ty_stabs_ref:
|
|---|
| 1188 |
|
|---|
| 1189 | #if 0
|
|---|
| 1190 | /* This should not happen. */
|
|---|
| 1191 |
|
|---|
| 1192 | no_warning ("stabs type %d not defined", tp->d.stabs_ref);
|
|---|
| 1193 |
|
|---|
| 1194 | return 4;
|
|---|
| 1195 | #else
|
|---|
| 1196 | /* This seems to happen although it shouldn't... Try do something at least. */
|
|---|
| 1197 |
|
|---|
| 1198 | tp = follow_refs (tp);
|
|---|
| 1199 | if (!tp || tp->tag == ty_stabs_ref)
|
|---|
| 1200 | {
|
|---|
| 1201 | no_warning ("stabs type %d not defined", tp->d.stabs_ref);
|
|---|
| 1202 | return 4;
|
|---|
| 1203 | }
|
|---|
| 1204 | return type_size (tp);
|
|---|
| 1205 | #endif
|
|---|
| 1206 |
|
|---|
| 1207 | case ty_alias:
|
|---|
| 1208 |
|
|---|
| 1209 | /* An alias. Return the size of the referenced type. */
|
|---|
| 1210 |
|
|---|
| 1211 | return type_size (tp->d.alias);
|
|---|
| 1212 |
|
|---|
| 1213 | case ty_pointer:
|
|---|
| 1214 | case ty_ref:
|
|---|
| 1215 |
|
|---|
| 1216 | /* Pointers and references are 32-bit values. */
|
|---|
| 1217 |
|
|---|
| 1218 | return 4;
|
|---|
| 1219 |
|
|---|
| 1220 | case ty_struc:
|
|---|
| 1221 |
|
|---|
| 1222 | /* The size of a structure is stored in the type structure. */
|
|---|
| 1223 |
|
|---|
| 1224 | if ( tp->d.struc.flags & STRUC_FORWARD
|
|---|
| 1225 | && try_complete_struct(tp))
|
|---|
| 1226 | {
|
|---|
| 1227 | no_warning ("size of incomplete structure %s is unknown (off %ld)\n stabs: %s",
|
|---|
| 1228 | tp->d.struc.name, parse_ptr - parse_start, parse_start);
|
|---|
| 1229 | return 0;
|
|---|
| 1230 | }
|
|---|
| 1231 | return tp->d.struc.size;
|
|---|
| 1232 |
|
|---|
| 1233 | case ty_class:
|
|---|
| 1234 |
|
|---|
| 1235 | /* The size of a class is stored in the type structure. */
|
|---|
| 1236 |
|
|---|
| 1237 | return tp->d.class.size;
|
|---|
| 1238 |
|
|---|
| 1239 | case ty_enu:
|
|---|
| 1240 |
|
|---|
| 1241 | /* Return the size of the base type for an enumeration type. */
|
|---|
| 1242 |
|
|---|
| 1243 | return type_size (tp->d.enu.type);
|
|---|
| 1244 |
|
|---|
| 1245 | case ty_array:
|
|---|
| 1246 |
|
|---|
| 1247 | /* Multiply the element size with the number of array elements
|
|---|
| 1248 | for arrays. */
|
|---|
| 1249 |
|
|---|
| 1250 | return ((tp->d.array.last + 1 - tp->d.array.first) *
|
|---|
| 1251 | type_size (tp->d.array.etype));
|
|---|
| 1252 |
|
|---|
| 1253 | case ty_bits:
|
|---|
| 1254 |
|
|---|
| 1255 | /* Use the size of the base type for bitfields. */
|
|---|
| 1256 |
|
|---|
| 1257 | return type_size (tp->d.bits.type);
|
|---|
| 1258 |
|
|---|
| 1259 | case ty_member:
|
|---|
| 1260 |
|
|---|
| 1261 | /* Use the size of the member's type for members. */
|
|---|
| 1262 |
|
|---|
| 1263 | return type_size (tp->d.member.type);
|
|---|
| 1264 |
|
|---|
| 1265 | case ty_baseclass:
|
|---|
| 1266 |
|
|---|
| 1267 | /* The size of a base class is the size of the base class :-) */
|
|---|
| 1268 |
|
|---|
| 1269 | return type_size (tp->d.baseclass.type);
|
|---|
| 1270 |
|
|---|
| 1271 | case ty_func:
|
|---|
| 1272 | case ty_args:
|
|---|
| 1273 | case ty_types:
|
|---|
| 1274 | case ty_fields:
|
|---|
| 1275 | case ty_values:
|
|---|
| 1276 | case ty_memfunc:
|
|---|
| 1277 |
|
|---|
| 1278 | /* This cannot not happen. */
|
|---|
| 1279 |
|
|---|
| 1280 | error ("type_size: cannot compute size for tag %d", tp->tag);
|
|---|
| 1281 |
|
|---|
| 1282 | default:
|
|---|
| 1283 |
|
|---|
| 1284 | /* This cannot happen. */
|
|---|
| 1285 |
|
|---|
| 1286 | error ("type_size: unknown type: %d", tp->tag);
|
|---|
| 1287 | }
|
|---|
| 1288 | }
|
|---|
| 1289 |
|
|---|
| 1290 |
|
|---|
| 1291 | /* Turn a struct into a class. This needs to be done when a struct is
|
|---|
| 1292 | referenced as base class (unfortunately, a simple class looks like
|
|---|
| 1293 | a struct). */
|
|---|
| 1294 |
|
|---|
| 1295 | static void struct_to_class (struct type *tp)
|
|---|
| 1296 | {
|
|---|
| 1297 | struct type t, *t1, **list, **types;
|
|---|
| 1298 | struct field *fields;
|
|---|
| 1299 | int i, n;
|
|---|
| 1300 |
|
|---|
| 1301 | if (tp->index != -1)
|
|---|
| 1302 | {
|
|---|
| 1303 | warning ("Base class cannot be converted from struct");
|
|---|
| 1304 | return;
|
|---|
| 1305 | }
|
|---|
| 1306 | n = tp->d.struc.count;
|
|---|
| 1307 | if (n == 0)
|
|---|
| 1308 | list = NULL;
|
|---|
| 1309 | else
|
|---|
| 1310 | {
|
|---|
| 1311 | if (tp->d.struc.fields->tag != ty_fields
|
|---|
| 1312 | || tp->d.struc.fields->d.fields.count != n)
|
|---|
| 1313 | {
|
|---|
| 1314 | warning ("Invalid struct field list");
|
|---|
| 1315 | return;
|
|---|
| 1316 | }
|
|---|
| 1317 | fields = tp->d.struc.fields->d.fields.list;
|
|---|
| 1318 | if (tp->d.struc.types->tag != ty_types
|
|---|
| 1319 | || tp->d.struc.types->d.types.count != n)
|
|---|
| 1320 | {
|
|---|
| 1321 | warning ("Invalid struct types list");
|
|---|
| 1322 | return;
|
|---|
| 1323 | }
|
|---|
| 1324 | types = tp->d.struc.types->d.types.list;
|
|---|
| 1325 | list = xmalloc (n * sizeof (*list));
|
|---|
| 1326 | for (i = 0; i < n; ++i)
|
|---|
| 1327 | {
|
|---|
| 1328 | t.tag = ty_member;
|
|---|
| 1329 | t.index = -1;
|
|---|
| 1330 | t.d.member.type = types[i];
|
|---|
| 1331 | t.d.member.offset = fields[i].offset;
|
|---|
| 1332 | t.d.member.flags = VIS_PUBLIC;
|
|---|
| 1333 | t.d.member.name = fields[i].name;
|
|---|
| 1334 | t.d.member.sname = NULL;
|
|---|
| 1335 | list[i] = type_add (&t);
|
|---|
| 1336 | }
|
|---|
| 1337 | }
|
|---|
| 1338 |
|
|---|
| 1339 | t.tag = ty_types;
|
|---|
| 1340 | t.index = -1;
|
|---|
| 1341 | t.d.types.count = n;
|
|---|
| 1342 | t.d.types.list = list;
|
|---|
| 1343 | t1 = type_add (&t);
|
|---|
| 1344 | free (list);
|
|---|
| 1345 |
|
|---|
| 1346 | t = *tp;
|
|---|
| 1347 | tp->tag = ty_class;
|
|---|
| 1348 | tp->d.class.members = t1;
|
|---|
| 1349 | tp->d.class.size = t.d.struc.size;
|
|---|
| 1350 | tp->d.class.count = t.d.struc.count;
|
|---|
| 1351 | tp->d.class.name = t.d.struc.name;
|
|---|
| 1352 | }
|
|---|
| 1353 |
|
|---|
| 1354 |
|
|---|
| 1355 | /* Build and return the internal representation of the `long long'
|
|---|
| 1356 | type. As IPMD doesn't know about `long long' we use the following
|
|---|
| 1357 | structure instead:
|
|---|
| 1358 |
|
|---|
| 1359 | struct _long_long
|
|---|
| 1360 | {
|
|---|
| 1361 | unsigned long lo, hi;
|
|---|
| 1362 | };
|
|---|
| 1363 |
|
|---|
| 1364 | This function could be optimized by remembering the type in a
|
|---|
| 1365 | global variable. */
|
|---|
| 1366 |
|
|---|
| 1367 | static struct type *make_long_long (void)
|
|---|
| 1368 | {
|
|---|
| 1369 | struct type t, *t1, *t2, *t3, *types[2];
|
|---|
| 1370 | struct field fields[2];
|
|---|
| 1371 |
|
|---|
| 1372 | /* Let t1 be `unsigned long'. */
|
|---|
| 1373 |
|
|---|
| 1374 | t.tag = ty_prim;
|
|---|
| 1375 | t.index = 0x86; /* 32 bit unsigned */
|
|---|
| 1376 | t1 = type_add (&t);
|
|---|
| 1377 |
|
|---|
| 1378 | /* Let t2 be the field types: unsigned long, unsigned long. */
|
|---|
| 1379 |
|
|---|
| 1380 | types[0] = t1;
|
|---|
| 1381 | types[1] = t1;
|
|---|
| 1382 | t.tag = ty_types;
|
|---|
| 1383 | t.index = -1;
|
|---|
| 1384 | t.d.types.count = 2;
|
|---|
| 1385 | t.d.types.list = types;
|
|---|
| 1386 | t2 = type_add (&t);
|
|---|
| 1387 |
|
|---|
| 1388 | /* Let t3 be the fields: lo (at 0), hi (at 4). */
|
|---|
| 1389 |
|
|---|
| 1390 | fields[0].offset = 0; fields[0].name = strpool_add (str_pool, "lo");
|
|---|
| 1391 | fields[1].offset = 4; fields[1].name = strpool_add (str_pool, "hi");
|
|---|
| 1392 | t.tag = ty_fields;
|
|---|
| 1393 | t.index = -1;
|
|---|
| 1394 | t.d.fields.count = 2;
|
|---|
| 1395 | t.d.fields.list = fields;
|
|---|
| 1396 | t3 = type_add (&t);
|
|---|
| 1397 |
|
|---|
| 1398 | /* Build the structure type from t1, t2 and t3. */
|
|---|
| 1399 |
|
|---|
| 1400 | t.tag = ty_struc;
|
|---|
| 1401 | t.d.struc.count = 2;
|
|---|
| 1402 | t.d.struc.size = 8;
|
|---|
| 1403 | t.d.struc.types = t2;
|
|---|
| 1404 | t.d.struc.fields = t3;
|
|---|
| 1405 | t.d.struc.name = strpool_add (str_pool, "_long_long");
|
|---|
| 1406 | t.d.struc.flags = 0;
|
|---|
| 1407 | return type_add (&t);
|
|---|
| 1408 | }
|
|---|
| 1409 |
|
|---|
| 1410 |
|
|---|
| 1411 | /* Parse a (signed) long long number in a stabs type. The number is
|
|---|
| 1412 | given in octal or decimal notation. The result is stored to
|
|---|
| 1413 | *NUMBER. This function returns TRUE iff successful. We don't
|
|---|
| 1414 | check for overflow. */
|
|---|
| 1415 |
|
|---|
| 1416 | static int parse_long_long (long long *number)
|
|---|
| 1417 | {
|
|---|
| 1418 | long long n;
|
|---|
| 1419 | int neg, base;
|
|---|
| 1420 |
|
|---|
| 1421 | n = 0; neg = FALSE; base = 10;
|
|---|
| 1422 | if (*parse_ptr == '-')
|
|---|
| 1423 | {
|
|---|
| 1424 | neg = TRUE;
|
|---|
| 1425 | ++parse_ptr;
|
|---|
| 1426 | }
|
|---|
| 1427 | if (*parse_ptr == '0')
|
|---|
| 1428 | base = 8;
|
|---|
| 1429 | if (!(*parse_ptr >= '0' && *parse_ptr < base + '0'))
|
|---|
| 1430 | {
|
|---|
| 1431 | *number = 0;
|
|---|
| 1432 | return FALSE;
|
|---|
| 1433 | }
|
|---|
| 1434 | while (*parse_ptr >= '0' && *parse_ptr < base + '0')
|
|---|
| 1435 | {
|
|---|
| 1436 | n = n * base + (*parse_ptr - '0');
|
|---|
| 1437 | ++parse_ptr;
|
|---|
| 1438 | }
|
|---|
| 1439 | *number = (neg ? -n : n);
|
|---|
| 1440 | return TRUE;
|
|---|
| 1441 | }
|
|---|
| 1442 |
|
|---|
| 1443 |
|
|---|
| 1444 | /* Parse a (signed) number in a stabs type. The number is given in
|
|---|
| 1445 | octal or decimal notation. The result is stored to *NUMBER. This
|
|---|
| 1446 | function returns TRUE iff successful. We don't check for
|
|---|
| 1447 | overflow. */
|
|---|
| 1448 |
|
|---|
| 1449 | static int parse_number (long *number)
|
|---|
| 1450 | {
|
|---|
| 1451 | long long n;
|
|---|
| 1452 | int result;
|
|---|
| 1453 |
|
|---|
| 1454 | result = parse_long_long (&n);
|
|---|
| 1455 | *number = (long)n;
|
|---|
| 1456 | return result;
|
|---|
| 1457 | }
|
|---|
| 1458 |
|
|---|
| 1459 |
|
|---|
| 1460 | /* Check the next character in a stabs type for C. If the next
|
|---|
| 1461 | character matches C, the character is skipped and TRUE is
|
|---|
| 1462 | returned. Otherwise, a warning message is displayed and FALSE is
|
|---|
| 1463 | returned. */
|
|---|
| 1464 |
|
|---|
| 1465 | static int parse_char (char c)
|
|---|
| 1466 | {
|
|---|
| 1467 | if (*parse_ptr != c)
|
|---|
| 1468 | {
|
|---|
| 1469 | no_warning ("Invalid symbol data: `%c' expected, found '%c' (off %ld)\n stabs: %s",
|
|---|
| 1470 | c, *parse_ptr, parse_ptr - parse_start, parse_start);
|
|---|
| 1471 | return FALSE;
|
|---|
| 1472 | }
|
|---|
| 1473 | ++parse_ptr;
|
|---|
| 1474 | return TRUE;
|
|---|
| 1475 | }
|
|---|
| 1476 |
|
|---|
| 1477 |
|
|---|
| 1478 | /* Parse mangled arguments of a member functions. For instance, ic
|
|---|
| 1479 | means an `int' argument and a `char' argument. Return FALSE on
|
|---|
| 1480 | failure. */
|
|---|
| 1481 |
|
|---|
| 1482 | static int parse_mangled_args (void)
|
|---|
| 1483 | {
|
|---|
| 1484 | while (*parse_ptr != ';')
|
|---|
| 1485 | {
|
|---|
| 1486 | switch (*parse_ptr)
|
|---|
| 1487 | {
|
|---|
| 1488 | case 0:
|
|---|
| 1489 | warning ("Missing semicolon after mangled arguments");
|
|---|
| 1490 | return FALSE;
|
|---|
| 1491 | default:
|
|---|
| 1492 | /* TODO */
|
|---|
| 1493 | break;
|
|---|
| 1494 | }
|
|---|
| 1495 | ++parse_ptr;
|
|---|
| 1496 | }
|
|---|
| 1497 | ++parse_ptr; /* Skip semicolon */
|
|---|
| 1498 | return TRUE;
|
|---|
| 1499 | }
|
|---|
| 1500 |
|
|---|
| 1501 |
|
|---|
| 1502 | /* Parse the visibility of a class or member. */
|
|---|
| 1503 |
|
|---|
| 1504 | static int parse_visibility (void)
|
|---|
| 1505 | {
|
|---|
| 1506 | switch (*parse_ptr)
|
|---|
| 1507 | {
|
|---|
| 1508 | case '0':
|
|---|
| 1509 | ++parse_ptr;
|
|---|
| 1510 | return VIS_PRIVATE;
|
|---|
| 1511 | case '1':
|
|---|
| 1512 | ++parse_ptr;
|
|---|
| 1513 | return VIS_PROTECTED;
|
|---|
| 1514 | case '2':
|
|---|
| 1515 | ++parse_ptr;
|
|---|
| 1516 | return VIS_PUBLIC;
|
|---|
| 1517 | default:
|
|---|
| 1518 | ++parse_ptr;
|
|---|
| 1519 | no_warning ("Invalid visibility: %c", *parse_ptr);
|
|---|
| 1520 | if (*parse_ptr != 0)
|
|---|
| 1521 | ++parse_ptr;
|
|---|
| 1522 | return VIS_PUBLIC;
|
|---|
| 1523 | }
|
|---|
| 1524 | }
|
|---|
| 1525 |
|
|---|
| 1526 |
|
|---|
| 1527 | /* Add TYPE_NAME to `str_pool', replacing a NULL string with a unique
|
|---|
| 1528 | string. */
|
|---|
| 1529 |
|
|---|
| 1530 | static const char *add_struct_name (const char *type_name)
|
|---|
| 1531 | {
|
|---|
| 1532 | char tmp[32];
|
|---|
| 1533 |
|
|---|
| 1534 | /* Some names have only spaces for gdb safety, let's make an
|
|---|
| 1535 | fake name for those. */
|
|---|
| 1536 | if (type_name != NULL)
|
|---|
| 1537 | {
|
|---|
| 1538 | const char *psz = type_name;
|
|---|
| 1539 | while (*psz == ' ' || *psz == '\t')
|
|---|
| 1540 | psz++;
|
|---|
| 1541 | if (!*psz)
|
|---|
| 1542 | type_name = NULL;
|
|---|
| 1543 | }
|
|---|
| 1544 |
|
|---|
| 1545 | if (type_name == NULL)
|
|---|
| 1546 | {
|
|---|
| 1547 | sprintf (tmp, "__%d", unnamed_struct_number++);
|
|---|
| 1548 | type_name = tmp;
|
|---|
| 1549 | }
|
|---|
| 1550 | return strpool_add (str_pool, type_name);
|
|---|
| 1551 | }
|
|---|
| 1552 |
|
|---|
| 1553 | /**
|
|---|
| 1554 | * Finds the next colon in the string and returns pointer to it.
|
|---|
| 1555 | * For C++ template support, colons within <> are not considered.
|
|---|
| 1556 | *
|
|---|
| 1557 | * @returns Pointer to next colon within psz.
|
|---|
| 1558 | * @returns NULL if not found.
|
|---|
| 1559 | * @param pszString String to search.
|
|---|
| 1560 | * @param chType Type we're parsing. Use '\0' if unknown or it
|
|---|
| 1561 | * should be ignored
|
|---|
| 1562 | * @remark Still a bad hack this.
|
|---|
| 1563 | */
|
|---|
| 1564 | #ifdef COLON_DEBUG
|
|---|
| 1565 | static const char *nextcolon2(const char *pszString, char chType)
|
|---|
| 1566 | {
|
|---|
| 1567 | static const char *_nextcolon2(const char *pszString, char chType);
|
|---|
| 1568 | const char *psz = _nextcolon2(pszString, chType);
|
|---|
| 1569 | fprintf(stderr, "COLON: %.100s\n%.32s\n", pszString, psz);
|
|---|
| 1570 | return psz;
|
|---|
| 1571 | }
|
|---|
| 1572 | static const char *_nextcolon2(const char *pszString, char chType)
|
|---|
| 1573 | #else
|
|---|
| 1574 | static const char *nextcolon2(const char *pszString, char chType)
|
|---|
| 1575 | #endif
|
|---|
| 1576 | {
|
|---|
| 1577 | const char *pszColon;
|
|---|
| 1578 | const char *psz;
|
|---|
| 1579 |
|
|---|
| 1580 | /* permanent operator hack */
|
|---|
| 1581 | if ( pszString[0] == 'o'
|
|---|
| 1582 | && pszString[1] == 'p'
|
|---|
| 1583 | && pszString[2] == 'e'
|
|---|
| 1584 | && pszString[3] == 'r'
|
|---|
| 1585 | && pszString[4] == 'a'
|
|---|
| 1586 | && pszString[5] == 't'
|
|---|
| 1587 | && pszString[6] == 'o'
|
|---|
| 1588 | && pszString[7] == 'r')
|
|---|
| 1589 | {
|
|---|
| 1590 | psz = pszString + 8;
|
|---|
| 1591 | while (*psz && !isalnum(*psz) && *psz != '_') /* potential operator chars */
|
|---|
| 1592 | {
|
|---|
| 1593 | if (*psz == ':')
|
|---|
| 1594 | {
|
|---|
| 1595 | if ( psz - pszString >= 1 + 8
|
|---|
| 1596 | && psz - pszString <= 3 + 8)
|
|---|
| 1597 | return psz;
|
|---|
| 1598 | break;
|
|---|
| 1599 | }
|
|---|
| 1600 | psz++;
|
|---|
| 1601 | }
|
|---|
| 1602 |
|
|---|
| 1603 | }
|
|---|
| 1604 |
|
|---|
| 1605 | /* normal life */
|
|---|
| 1606 | pszColon = strchr(pszString, ':');
|
|---|
| 1607 | if (!pszColon)
|
|---|
| 1608 | return NULL;
|
|---|
| 1609 | psz = strchr(pszString, '<');
|
|---|
| 1610 |
|
|---|
| 1611 | if (psz && psz < pszColon && pszColon[1] == ':')
|
|---|
| 1612 | {
|
|---|
| 1613 | int cNesting = 0; /* <> level */
|
|---|
| 1614 |
|
|---|
| 1615 | for (;;psz++)
|
|---|
| 1616 | {
|
|---|
| 1617 | switch (*psz)
|
|---|
| 1618 | {
|
|---|
| 1619 | case '<': cNesting++; break;
|
|---|
| 1620 | case '>': cNesting--; break;
|
|---|
| 1621 | case ':':
|
|---|
| 1622 | if (cNesting > 0)
|
|---|
| 1623 | break;
|
|---|
| 1624 | /* hack: continue on ">::" (but not on "operator...") */
|
|---|
| 1625 | if ( chType != 'x'
|
|---|
| 1626 | && psz[1] == ':'
|
|---|
| 1627 | && psz > pszString && psz[-1] == '>'
|
|---|
| 1628 | )
|
|---|
| 1629 | {
|
|---|
| 1630 | psz++;
|
|---|
| 1631 | break;
|
|---|
| 1632 | }
|
|---|
| 1633 | return psz;
|
|---|
| 1634 | case '\0':
|
|---|
| 1635 | return NULL;
|
|---|
| 1636 | }
|
|---|
| 1637 | }
|
|---|
| 1638 | }
|
|---|
| 1639 | else
|
|---|
| 1640 | {
|
|---|
| 1641 | if (chType != 'x')
|
|---|
| 1642 | {
|
|---|
| 1643 | /* skip '::' (hack:) if not followed by number. */
|
|---|
| 1644 | while (*pszColon && pszColon[1] == ':' && (pszColon[2] > '9' || pszColon[2] < '0'))
|
|---|
| 1645 | {
|
|---|
| 1646 | pszColon += 2;
|
|---|
| 1647 | while (*pszColon != ':' && *pszColon)
|
|---|
| 1648 | pszColon++;
|
|---|
| 1649 | }
|
|---|
| 1650 | }
|
|---|
| 1651 | }
|
|---|
| 1652 |
|
|---|
| 1653 | return pszColon;
|
|---|
| 1654 | }
|
|---|
| 1655 |
|
|---|
| 1656 | /* old version */
|
|---|
| 1657 | static inline const char *nextcolon(const char *pszString)
|
|---|
| 1658 | {
|
|---|
| 1659 | return nextcolon2(pszString, '\0');
|
|---|
| 1660 | }
|
|---|
| 1661 |
|
|---|
| 1662 |
|
|---|
| 1663 |
|
|---|
| 1664 | /* Parse a stabs type (which is named TYPE_NAME; TYPE_NAME is NULL for
|
|---|
| 1665 | an unnamed type) and return the internal representation of that
|
|---|
| 1666 | type. */
|
|---|
| 1667 |
|
|---|
| 1668 | static struct type *parse_type (const char *type_name)
|
|---|
| 1669 | {
|
|---|
| 1670 | const char *saved_ptr, *p1;
|
|---|
| 1671 | char ch;
|
|---|
| 1672 | struct type t, *result, *t1, *t2, *t3, **tlist;
|
|---|
| 1673 | int i, n, class_flag, is_void;
|
|---|
| 1674 | long num1, num2, size, lo, hi, valid, offset, width, code;
|
|---|
| 1675 | long long range_lo, range_hi;
|
|---|
| 1676 | struct tmp_field *tmp_fields, *tf;
|
|---|
| 1677 | struct value *tmp_values, *tv;
|
|---|
| 1678 | struct grow g1 = GROW_INIT;
|
|---|
| 1679 | enum type_tag tt;
|
|---|
| 1680 |
|
|---|
| 1681 | valid = TRUE; result = NULL;
|
|---|
| 1682 | t.index = -1;
|
|---|
| 1683 | switch (*parse_ptr)
|
|---|
| 1684 | {
|
|---|
| 1685 | case '0': case '1': case '2': case '3': case '4':
|
|---|
| 1686 | case '5': case '6': case '7': case '8': case '9':
|
|---|
| 1687 | if (!parse_number (&num1))
|
|---|
| 1688 | goto syntax;
|
|---|
| 1689 |
|
|---|
| 1690 | /* Special case: self reference => void */
|
|---|
| 1691 | is_void = FALSE;
|
|---|
| 1692 | if (*parse_ptr == '=' && parse_ptr[1] >= '0' && parse_ptr[1] <= '9')
|
|---|
| 1693 | {
|
|---|
| 1694 | saved_ptr = parse_ptr++;
|
|---|
| 1695 | if (!parse_number (&num2))
|
|---|
| 1696 | goto syntax;
|
|---|
| 1697 | if (num2 == num1)
|
|---|
| 1698 | is_void = TRUE;
|
|---|
| 1699 | else
|
|---|
| 1700 | parse_ptr = saved_ptr;
|
|---|
| 1701 | }
|
|---|
| 1702 | if (is_void)
|
|---|
| 1703 | {
|
|---|
| 1704 | t.tag = ty_prim;
|
|---|
| 1705 | t.index = 0x97; /* void */
|
|---|
| 1706 | result = type_add (&t);
|
|---|
| 1707 | stype_add (num1, result);
|
|---|
| 1708 | }
|
|---|
| 1709 | else if (*parse_ptr == '=')
|
|---|
| 1710 | {
|
|---|
| 1711 | /* Nested definition */
|
|---|
| 1712 | ++parse_ptr;
|
|---|
| 1713 | result = parse_type (type_name);
|
|---|
| 1714 | stype_add (num1, result);
|
|---|
| 1715 | }
|
|---|
| 1716 | else
|
|---|
| 1717 | {
|
|---|
| 1718 | result = stype_find (num1);
|
|---|
| 1719 | if (result == NULL)
|
|---|
| 1720 | {
|
|---|
| 1721 | t.tag = ty_stabs_ref;
|
|---|
| 1722 | t.d.stabs_ref = num1;
|
|---|
| 1723 | }
|
|---|
| 1724 | }
|
|---|
| 1725 | break;
|
|---|
| 1726 |
|
|---|
| 1727 | case 'r':
|
|---|
| 1728 |
|
|---|
| 1729 | /* A range type: r<base_type>;<lower_bound>;<upper_bound>;
|
|---|
| 1730 |
|
|---|
| 1731 | Special cases:
|
|---|
| 1732 |
|
|---|
| 1733 | lower_bound | upper_bound | type
|
|---|
| 1734 | ------------+-------------+------------------------
|
|---|
| 1735 | n > 0 | 0 | floating point, n bytes
|
|---|
| 1736 |
|
|---|
| 1737 | */
|
|---|
| 1738 |
|
|---|
| 1739 | ++parse_ptr;
|
|---|
| 1740 | if (!parse_number (&num1) || !parse_char (';')
|
|---|
| 1741 | || !parse_long_long (&range_lo) || !parse_char (';')
|
|---|
| 1742 | || !parse_long_long (&range_hi) || !parse_char (';'))
|
|---|
| 1743 | goto syntax;
|
|---|
| 1744 | t.tag = ty_prim;
|
|---|
| 1745 | if (range_lo == -128 && range_hi == 127)
|
|---|
| 1746 | t.index = 0x80; /* 8 bit signed */
|
|---|
| 1747 | else if (range_lo == -32768 && range_hi == 32767)
|
|---|
| 1748 | t.index = 0x81; /* 16 bit signed */
|
|---|
| 1749 | else if (range_lo == -2147483647 - 1 && range_hi == 2147483647)
|
|---|
| 1750 | t.index = 0x82; /* 32 bit signed */
|
|---|
| 1751 | else if (range_lo == 0 && range_hi == 127)
|
|---|
| 1752 | t.index = 0x84; /* 8 bit character */
|
|---|
| 1753 | else if (range_lo == 0 && range_hi == 255)
|
|---|
| 1754 | t.index = 0x84; /* 8 bit unsigned */
|
|---|
| 1755 | else if (range_lo == 0 && range_hi == 65535)
|
|---|
| 1756 | t.index = 0x85; /* 16 bit unsigned */
|
|---|
| 1757 | else if (range_lo == 0 && range_hi == 0xffffffff)
|
|---|
| 1758 | t.index = 0x86; /* 32 bit unsigned */
|
|---|
| 1759 | else if (range_lo == 0 && range_hi == -1)
|
|---|
| 1760 | {
|
|---|
| 1761 | if (type_name != NULL
|
|---|
| 1762 | && (strcmp (type_name, "long long unsigned int") == 0
|
|---|
| 1763 | || strcmp (type_name, "long long int") == 0))
|
|---|
| 1764 | result = make_long_long ();
|
|---|
| 1765 | else
|
|---|
| 1766 | t.index = 0x86; /* 32 bit unsigned */
|
|---|
| 1767 | }
|
|---|
| 1768 | else if ((unsigned long long)range_lo == 0x8000000000000000ULL
|
|---|
| 1769 | && range_hi == 0x7fffffffffffffffLL)
|
|---|
| 1770 | result = make_long_long ();
|
|---|
| 1771 | else if (range_lo == 4 && range_hi == 0)
|
|---|
| 1772 | t.index = 0x88; /* 32 bit real */
|
|---|
| 1773 | else if (range_lo == 8 && range_hi == 0)
|
|---|
| 1774 | t.index = 0x89; /* 64 bit real */
|
|---|
| 1775 | else if (range_lo == 12 && range_hi == 0)
|
|---|
| 1776 | t.index = 0x8a; /* 80 bit real */
|
|---|
| 1777 | else
|
|---|
| 1778 | {
|
|---|
| 1779 | no_warning ("Unknown range type: %lld..%lld", range_lo, range_hi);
|
|---|
| 1780 | goto syntax;
|
|---|
| 1781 | }
|
|---|
| 1782 | break;
|
|---|
| 1783 |
|
|---|
| 1784 | case 'R':
|
|---|
| 1785 |
|
|---|
| 1786 | /* Complex number: R<?base_type?>;<size bytes>;<0>; */
|
|---|
| 1787 |
|
|---|
| 1788 | ++parse_ptr;
|
|---|
| 1789 | if (!parse_number (&num1) || !parse_char (';')
|
|---|
| 1790 | || !parse_number (&width) || !parse_char (';')
|
|---|
| 1791 | || !parse_number (&code) || !parse_char (';'))
|
|---|
| 1792 | goto syntax;
|
|---|
| 1793 |
|
|---|
| 1794 | /*
|
|---|
| 1795 | * The 192bit type is not defined in the HLL specs, but we assume it for
|
|---|
| 1796 | * convenince right now.
|
|---|
| 1797 | *
|
|---|
| 1798 | * It seems like no debugger acutally supports these types. So, we should,
|
|---|
| 1799 | * when somebody requires it for debugging complex math, make structs out
|
|---|
| 1800 | * of these declarations like GCC does for the 'complex int' type.
|
|---|
| 1801 | *
|
|---|
| 1802 | * .stabs "FakeComplexInt:t21=22=s8real:1,0,32;imag:1,32,32;;",128,0,0,0
|
|---|
| 1803 | * .stabs "FakeComplexFloat:t23=24=s8real:12,0,32;imag:12,32,32;;",128,0,0,0
|
|---|
| 1804 | * .stabs "FakeComplexDouble:t25=26=s16real:13,0,64;imag:13,64,64;;",128,0,0,0
|
|---|
| 1805 | * .stabs "FakeComplexLongDouble:t27=28=s24real:14,0,96;imag:14,96,96;;",128,0,0,0
|
|---|
| 1806 | *
|
|---|
| 1807 | */
|
|---|
| 1808 | t.tag = ty_prim;
|
|---|
| 1809 | if (width == 8 && code == 0)
|
|---|
| 1810 | t.index = 0x8c;
|
|---|
| 1811 | else if (width == 16 && code == 0)
|
|---|
| 1812 | t.index = 0x8d ;
|
|---|
| 1813 | else if (width == 20 && code == 0)
|
|---|
| 1814 | t.index = 0x8e;
|
|---|
| 1815 | else if (width == 24 && code == 0)
|
|---|
| 1816 | t.index = 0x8f; //TODO: bogus!!!
|
|---|
| 1817 | else
|
|---|
| 1818 | {
|
|---|
| 1819 | no_warning ("Unknown complex type: %ld/%ld", width, code);
|
|---|
| 1820 | goto syntax;
|
|---|
| 1821 | }
|
|---|
| 1822 | break;
|
|---|
| 1823 |
|
|---|
| 1824 | case '*':
|
|---|
| 1825 |
|
|---|
| 1826 | /* A pointer type: *<type> */
|
|---|
| 1827 |
|
|---|
| 1828 | ++parse_ptr;
|
|---|
| 1829 | t1 = parse_type (NULL);
|
|---|
| 1830 | t.tag = ty_pointer;
|
|---|
| 1831 | t.d.pointer = t1;
|
|---|
| 1832 | break;
|
|---|
| 1833 |
|
|---|
| 1834 | case 'k':
|
|---|
| 1835 |
|
|---|
| 1836 | /* A const type: k<type>
|
|---|
| 1837 | HLL don't have const typedefs afaik, so we just make it an alias. */
|
|---|
| 1838 |
|
|---|
| 1839 | ++parse_ptr;
|
|---|
| 1840 | t1 = parse_type (NULL);
|
|---|
| 1841 | t.tag = ty_alias;
|
|---|
| 1842 | t.d.alias = t1;
|
|---|
| 1843 | break;
|
|---|
| 1844 |
|
|---|
| 1845 | case 'B':
|
|---|
| 1846 |
|
|---|
| 1847 | /* A volatile type: B<type>
|
|---|
| 1848 | This is a SUN extension, and right now we don't care to generate
|
|---|
| 1849 | specific HLL for it and stick with an alias. */
|
|---|
| 1850 |
|
|---|
| 1851 | ++parse_ptr;
|
|---|
| 1852 | t1 = parse_type (NULL);
|
|---|
| 1853 | t.tag = ty_alias;
|
|---|
| 1854 | t.d.alias = t1;
|
|---|
| 1855 | break;
|
|---|
| 1856 |
|
|---|
| 1857 |
|
|---|
| 1858 | case '&':
|
|---|
| 1859 |
|
|---|
| 1860 | /* A reference type (C++): &<type> */
|
|---|
| 1861 |
|
|---|
| 1862 | ++parse_ptr;
|
|---|
| 1863 | t1 = parse_type (NULL);
|
|---|
| 1864 | t.tag = ty_ref;
|
|---|
| 1865 | t.d.ref = t1;
|
|---|
| 1866 | break;
|
|---|
| 1867 |
|
|---|
| 1868 | case '#':
|
|---|
| 1869 |
|
|---|
| 1870 | /* A member function:
|
|---|
| 1871 |
|
|---|
| 1872 | short format: ##<return_type>;
|
|---|
| 1873 |
|
|---|
| 1874 | long format: #<domain_type>,<return_type>{,<arg_type>};
|
|---|
| 1875 |
|
|---|
| 1876 | */
|
|---|
| 1877 |
|
|---|
| 1878 | ++parse_ptr;
|
|---|
| 1879 | args_grow.count = 0; /* ASSUMES we can safely use args_grow/args_list. */
|
|---|
| 1880 | t2 = NULL; /* t2=Domain type; t1=Return type; */
|
|---|
| 1881 | if (*parse_ptr == '#')
|
|---|
| 1882 | {
|
|---|
| 1883 | ++parse_ptr;
|
|---|
| 1884 | t1 = parse_type (NULL);
|
|---|
| 1885 | if (!parse_char (';'))
|
|---|
| 1886 | goto syntax;
|
|---|
| 1887 | no_warning ("We don't understand '##' methods.");
|
|---|
| 1888 | }
|
|---|
| 1889 | else
|
|---|
| 1890 | {
|
|---|
| 1891 | t2 = parse_type (NULL); /* Domain type */
|
|---|
| 1892 | if (!parse_char (','))
|
|---|
| 1893 | goto syntax;
|
|---|
| 1894 | t1 = parse_type (NULL); /* Return type */
|
|---|
| 1895 | /* Arguments */
|
|---|
| 1896 | while (*parse_ptr != ';')
|
|---|
| 1897 | {
|
|---|
| 1898 | if (!parse_char (','))
|
|---|
| 1899 | goto syntax;
|
|---|
| 1900 | grow_by (&args_grow, 1);
|
|---|
| 1901 | args_list[args_grow.count++] = parse_type (NULL); /* Argument type */
|
|---|
| 1902 | }
|
|---|
| 1903 | ++parse_ptr;
|
|---|
| 1904 | }
|
|---|
| 1905 |
|
|---|
| 1906 | t3 = NULL;
|
|---|
| 1907 | #if 0 /* this doesn't really seems to be required, but can just as well leave it in. */
|
|---|
| 1908 | if (args_grow.count)
|
|---|
| 1909 | {
|
|---|
| 1910 | t.tag = ty_args;
|
|---|
| 1911 | t.index = -1;
|
|---|
| 1912 | t.d.args.count = args_grow.count;
|
|---|
| 1913 | t.d.args.list = xmalloc (args_grow.count * sizeof (*args_list));
|
|---|
| 1914 | memcpy (t.d.args.list, args_list, args_grow.count * sizeof (*args_list));
|
|---|
| 1915 | t3 = type_add (&t);
|
|---|
| 1916 | free (t.d.args.list);
|
|---|
| 1917 | }
|
|---|
| 1918 | #endif
|
|---|
| 1919 |
|
|---|
| 1920 | /* Make a function type from the return type t1 */
|
|---|
| 1921 | t.tag = ty_func;
|
|---|
| 1922 | t.d.func.ret = t1;
|
|---|
| 1923 | t.d.func.domain = t2;
|
|---|
| 1924 | t.d.func.args = t3;
|
|---|
| 1925 | t.d.func.arg_count = args_grow.count;
|
|---|
| 1926 | args_grow.count = 0;
|
|---|
| 1927 | t1 = type_add(&t);
|
|---|
| 1928 |
|
|---|
| 1929 | break;
|
|---|
| 1930 |
|
|---|
| 1931 | case '@':
|
|---|
| 1932 |
|
|---|
| 1933 | /* Special GNU-defined types:
|
|---|
| 1934 |
|
|---|
| 1935 | @s<bits>;<code>;
|
|---|
| 1936 |
|
|---|
| 1937 | BITS: Number of bits
|
|---|
| 1938 | CODE: Identifies the type:
|
|---|
| 1939 | -16 bool
|
|---|
| 1940 | -20 char
|
|---|
| 1941 |
|
|---|
| 1942 | @s<bits>;<range record>
|
|---|
| 1943 | Used for 64 bit ints.
|
|---|
| 1944 |
|
|---|
| 1945 | @<basetype>,<membertype>
|
|---|
| 1946 | Used for addressing class/struct/union members.
|
|---|
| 1947 | */
|
|---|
| 1948 |
|
|---|
| 1949 | ++parse_ptr;
|
|---|
| 1950 | switch (*parse_ptr)
|
|---|
| 1951 | {
|
|---|
| 1952 | case 's':
|
|---|
| 1953 | ++parse_ptr;
|
|---|
| 1954 | if (!parse_number (&size) || !parse_char (';'))
|
|---|
| 1955 | goto syntax;
|
|---|
| 1956 | if (*parse_ptr == 'r')
|
|---|
| 1957 | { /* nested */
|
|---|
| 1958 | return parse_type(type_name);
|
|---|
| 1959 | }
|
|---|
| 1960 |
|
|---|
| 1961 | if (!parse_number (&code))
|
|---|
| 1962 | goto syntax;
|
|---|
| 1963 | if (size == 8 && code == -16)
|
|---|
| 1964 | {
|
|---|
| 1965 | #if 0 /* debugger doesn't understand this game */
|
|---|
| 1966 | t.tag = ty_prim;
|
|---|
| 1967 | t.index = 0x90; /* 8 bit boolean */
|
|---|
| 1968 | #else
|
|---|
| 1969 | t.tag = ty_values;
|
|---|
| 1970 | t.d.values.count = 2;
|
|---|
| 1971 | t.d.values.list = xmalloc (2 * sizeof (*t.d.values.list));
|
|---|
| 1972 | t.d.values.list[0].index = 0;
|
|---|
| 1973 | t.d.values.list[0].name = strpool_add (str_pool, "false");
|
|---|
| 1974 | t.d.values.list[1].index = 1;
|
|---|
| 1975 | t.d.values.list[1].name = strpool_add (str_pool, "true");
|
|---|
| 1976 | t1 = type_add (&t);
|
|---|
| 1977 | free (t.d.values.list);
|
|---|
| 1978 |
|
|---|
| 1979 | t.tag = ty_prim;
|
|---|
| 1980 | t.index = 0x80;
|
|---|
| 1981 | t2 = type_add (&t);
|
|---|
| 1982 |
|
|---|
| 1983 | t.tag = ty_enu;
|
|---|
| 1984 | t.index = -1;
|
|---|
| 1985 | t.d.enu.values = t1;
|
|---|
| 1986 | t.d.enu.type = t2;
|
|---|
| 1987 | t.d.enu.name = add_struct_name (NULL);
|
|---|
| 1988 | t.d.enu.first = 0;
|
|---|
| 1989 | t.d.enu.last = 1;
|
|---|
| 1990 | #endif
|
|---|
| 1991 | }
|
|---|
| 1992 | else
|
|---|
| 1993 | {
|
|---|
| 1994 | warning ("Unknown GNU extension type code: %ld, %ld bits",
|
|---|
| 1995 | code, size);
|
|---|
| 1996 | goto syntax;
|
|---|
| 1997 | }
|
|---|
| 1998 | if (!parse_char (';'))
|
|---|
| 1999 | goto syntax;
|
|---|
| 2000 | break;
|
|---|
| 2001 |
|
|---|
| 2002 | case '0': case '1': case '2': case '3': case '4':
|
|---|
| 2003 | case '5': case '6': case '7': case '8': case '9':
|
|---|
| 2004 | {
|
|---|
| 2005 | /* just make it an integer - see dbxout.c OFFSET_TYPE case. */
|
|---|
| 2006 | if ( parse_number (&num1)
|
|---|
| 2007 | && *parse_ptr == ','
|
|---|
| 2008 | && ++parse_ptr
|
|---|
| 2009 | && parse_number (&num2)
|
|---|
| 2010 | )
|
|---|
| 2011 | {
|
|---|
| 2012 | t.tag = ty_prim;
|
|---|
| 2013 | t.index = 0x82; /* 32 bit signed */
|
|---|
| 2014 | }
|
|---|
| 2015 | else
|
|---|
| 2016 | {
|
|---|
| 2017 | warning_parse ("Invalid BASE_OFFSET GNU extension format!");
|
|---|
| 2018 | goto syntax;
|
|---|
| 2019 | }
|
|---|
| 2020 | break;
|
|---|
| 2021 | }
|
|---|
| 2022 |
|
|---|
| 2023 | default:
|
|---|
| 2024 | warning ("Unknown GNU extension type: @%c", *parse_ptr);
|
|---|
| 2025 | goto syntax;
|
|---|
| 2026 | }
|
|---|
| 2027 | break;
|
|---|
| 2028 |
|
|---|
| 2029 | case 'x':
|
|---|
| 2030 |
|
|---|
| 2031 | /* Incomplete type: xs<name>:
|
|---|
| 2032 | xu<name>:
|
|---|
| 2033 | xe<name>: */
|
|---|
| 2034 |
|
|---|
| 2035 | ++parse_ptr;
|
|---|
| 2036 | ch = *parse_ptr++;
|
|---|
| 2037 | p1 = nextcolon2 (parse_ptr, 'x');
|
|---|
| 2038 | if (p1 == NULL)
|
|---|
| 2039 | {
|
|---|
| 2040 | warning ("Invalid forward reference: missing colon");
|
|---|
| 2041 | goto syntax;
|
|---|
| 2042 | }
|
|---|
| 2043 |
|
|---|
| 2044 | switch (ch)
|
|---|
| 2045 | {
|
|---|
| 2046 | case 's':
|
|---|
| 2047 | case 'u':
|
|---|
| 2048 | {
|
|---|
| 2049 | /* make a fake structure. */
|
|---|
| 2050 | t.tag = ty_prim;
|
|---|
| 2051 | t.index = 0x80;
|
|---|
| 2052 | tlist = xmalloc (1 * sizeof (*t.d.types.list));
|
|---|
| 2053 | tlist[0] = type_add (&t);
|
|---|
| 2054 | t.tag = ty_types;
|
|---|
| 2055 | t.index = -1;
|
|---|
| 2056 | t.d.types.count = 1;
|
|---|
| 2057 | t.d.types.list = tlist;
|
|---|
| 2058 | t1 = type_add (&t);
|
|---|
| 2059 | free (tlist);
|
|---|
| 2060 |
|
|---|
| 2061 | t.tag = ty_fields;
|
|---|
| 2062 | t.index = -1;
|
|---|
| 2063 | t.d.fields.count = 1;
|
|---|
| 2064 | t.d.fields.list = xmalloc (1 * sizeof (*t.d.fields.list));
|
|---|
| 2065 | t.d.fields.list[0].offset = 0;
|
|---|
| 2066 | t.d.fields.list[0].name = strpool_add (str_pool, "This_Is_an_Incomplete_Structure_SORRY");
|
|---|
| 2067 | t2 = type_add (&t);
|
|---|
| 2068 | free (t.d.fields.list);
|
|---|
| 2069 |
|
|---|
| 2070 | t.tag = ty_struc;
|
|---|
| 2071 | t.index = -1;
|
|---|
| 2072 | t.d.struc.types = t1;
|
|---|
| 2073 | t.d.struc.fields = t2;
|
|---|
| 2074 | t.d.struc.size = 1;
|
|---|
| 2075 | t.d.struc.count = 1;
|
|---|
| 2076 | t.d.struc.name = strpool_addn (str_pool, parse_ptr, p1 - parse_ptr);
|
|---|
| 2077 | t.d.struc.flags = STRUC_FORWARD;
|
|---|
| 2078 |
|
|---|
| 2079 | /* Avoid adding an incomplete type if the complete one is
|
|---|
| 2080 | already defined. We're ignoring scoping (TODO). */
|
|---|
| 2081 |
|
|---|
| 2082 | for (t3 = type_head; t3 != NULL; t3 = t3->next)
|
|---|
| 2083 | if ((t3->tag == ty_struc && t3->d.struc.name == t.d.struc.name
|
|---|
| 2084 | && !(t3->d.struc.flags & STRUC_FORWARD))
|
|---|
| 2085 | || (t3->tag == ty_class && t3->d.class.name == t.d.struc.name))
|
|---|
| 2086 | {
|
|---|
| 2087 | result = t3;
|
|---|
| 2088 | break;
|
|---|
| 2089 | }
|
|---|
| 2090 | break;
|
|---|
| 2091 | }
|
|---|
| 2092 |
|
|---|
| 2093 | case 'e':
|
|---|
| 2094 | { /* just make it a primary. */
|
|---|
| 2095 | /** @todo make an enum perhaps? */
|
|---|
| 2096 | t.tag = ty_prim;
|
|---|
| 2097 | t.index = 0x82; /* 32 bit signed */
|
|---|
| 2098 | break;
|
|---|
| 2099 | }
|
|---|
| 2100 |
|
|---|
| 2101 | default:
|
|---|
| 2102 | warning ("Unknown forward reference: %c", ch);
|
|---|
| 2103 | parse_ptr = p1 + 1;
|
|---|
| 2104 | goto syntax;
|
|---|
| 2105 | }
|
|---|
| 2106 | parse_ptr = p1 + 1;
|
|---|
| 2107 | break;
|
|---|
| 2108 |
|
|---|
| 2109 | case 's': /* struct, class */
|
|---|
| 2110 | case 'u': /* union */
|
|---|
| 2111 |
|
|---|
| 2112 | /* Structures, unions and classes:
|
|---|
| 2113 |
|
|---|
| 2114 | s<size>[<baseclasses>]{<field>}{<method>}
|
|---|
| 2115 |
|
|---|
| 2116 | BASECLASSES: !<#baseclasses>,{<baseclass>;}
|
|---|
| 2117 | BASECLASS: <virtuality><visibility><offset>,<type>
|
|---|
| 2118 | FIELD: <name>:[/0|1|2]<type>,<offset>,<width>;
|
|---|
| 2119 | FIELD: <name>:[/0|1|2]<type>:<static_name>;
|
|---|
| 2120 | METHOD: <name>::{<type>:<args>};
|
|---|
| 2121 |
|
|---|
| 2122 | */
|
|---|
| 2123 |
|
|---|
| 2124 | ++parse_ptr;
|
|---|
| 2125 | class_flag = FALSE;
|
|---|
| 2126 | if (!parse_number (&size))
|
|---|
| 2127 | goto syntax;
|
|---|
| 2128 | grow_init (&g1, &tmp_fields, sizeof (*tmp_fields), 8);
|
|---|
| 2129 |
|
|---|
| 2130 | /* Parse the base classes, if present. */
|
|---|
| 2131 |
|
|---|
| 2132 | if (*parse_ptr == '!')
|
|---|
| 2133 | {
|
|---|
| 2134 | long i, n;
|
|---|
| 2135 |
|
|---|
| 2136 | ++parse_ptr;
|
|---|
| 2137 | class_flag = TRUE;
|
|---|
| 2138 | if (!parse_number (&n) || !parse_char (','))
|
|---|
| 2139 | goto syntax;
|
|---|
| 2140 | for (i = 0; i < n; ++i)
|
|---|
| 2141 | {
|
|---|
| 2142 | grow_by (&g1, 1);
|
|---|
| 2143 | tf = &tmp_fields[g1.count++];
|
|---|
| 2144 | tf->flags = MEMBER_BASE;
|
|---|
| 2145 | tf->name = NULL;
|
|---|
| 2146 | tf->sname = NULL;
|
|---|
| 2147 | switch (*parse_ptr)
|
|---|
| 2148 | {
|
|---|
| 2149 | case '0':
|
|---|
| 2150 | ++parse_ptr;
|
|---|
| 2151 | break;
|
|---|
| 2152 | case '1':
|
|---|
| 2153 | tf->flags |= MEMBER_VIRTUAL;
|
|---|
| 2154 | ++parse_ptr;
|
|---|
| 2155 | break;
|
|---|
| 2156 | default:
|
|---|
| 2157 | warning ("Invalid base class visibility: %c", *parse_ptr);
|
|---|
| 2158 | if (*parse_ptr != 0)
|
|---|
| 2159 | ++parse_ptr;
|
|---|
| 2160 | }
|
|---|
| 2161 |
|
|---|
| 2162 | tf->flags |= parse_visibility ();
|
|---|
| 2163 | if (!parse_number (&offset) || !parse_char (','))
|
|---|
| 2164 | goto syntax;
|
|---|
| 2165 | tf->offset = offset >> 3;
|
|---|
| 2166 | t1 = parse_type (NULL);
|
|---|
| 2167 | switch (t1->tag)
|
|---|
| 2168 | {
|
|---|
| 2169 | case ty_class:
|
|---|
| 2170 | break;
|
|---|
| 2171 | case ty_struc:
|
|---|
| 2172 | /* kso #456 2003-06-11: Don't mess with forward defines! */
|
|---|
| 2173 | if (!( (t1->d.struc.flags & STRUC_FORWARD)
|
|---|
| 2174 | /*&& t1->d.struc.types == NULL
|
|---|
| 2175 | && t1->d.struc.fields == NULL*/))
|
|---|
| 2176 | struct_to_class (t1);
|
|---|
| 2177 | break;
|
|---|
| 2178 | default:
|
|---|
| 2179 | warning ("Invalid base class type");
|
|---|
| 2180 | }
|
|---|
| 2181 | tf->type = t1;
|
|---|
| 2182 | if (!parse_char (';'))
|
|---|
| 2183 | goto syntax;
|
|---|
| 2184 | }
|
|---|
| 2185 | }
|
|---|
| 2186 |
|
|---|
| 2187 | while (*parse_ptr != ';')
|
|---|
| 2188 | {
|
|---|
| 2189 | p1 = nextcolon (parse_ptr);
|
|---|
| 2190 | if (p1 == NULL)
|
|---|
| 2191 | {
|
|---|
| 2192 | warning ("Invalid structure type: missing colon");
|
|---|
| 2193 | goto syntax;
|
|---|
| 2194 | }
|
|---|
| 2195 | n = p1 - parse_ptr;
|
|---|
| 2196 | grow_by (&g1, 1);
|
|---|
| 2197 | tf = &tmp_fields[g1.count++];
|
|---|
| 2198 | tf->flags = VIS_PUBLIC;
|
|---|
| 2199 | tf->name = strpool_addn (str_pool, parse_ptr, n);
|
|---|
| 2200 | tf->mnglname = NULL;
|
|---|
| 2201 | parse_ptr = p1 + 1;
|
|---|
| 2202 | if (*parse_ptr == ':')
|
|---|
| 2203 | {
|
|---|
| 2204 | class_flag = TRUE;
|
|---|
| 2205 | ++parse_ptr;
|
|---|
| 2206 | do
|
|---|
| 2207 | {
|
|---|
| 2208 | const char * pszMangled;
|
|---|
| 2209 |
|
|---|
| 2210 | t1 = parse_type (NULL);
|
|---|
| 2211 | offset = 0;
|
|---|
| 2212 | if (t1 == NULL || t1->tag != ty_func)
|
|---|
| 2213 | {
|
|---|
| 2214 | no_warning ("Invalid member function type");
|
|---|
| 2215 | goto syntax;
|
|---|
| 2216 | }
|
|---|
| 2217 |
|
|---|
| 2218 | if (*parse_ptr != ':')
|
|---|
| 2219 | {
|
|---|
| 2220 | no_warning ("Arguments for member function missing");
|
|---|
| 2221 | goto syntax;
|
|---|
| 2222 | }
|
|---|
| 2223 | ++parse_ptr;
|
|---|
| 2224 | pszMangled = parse_ptr;
|
|---|
| 2225 | if (!parse_mangled_args ())
|
|---|
| 2226 | goto syntax;
|
|---|
| 2227 | tf->mnglname = strpool_addn(str_pool, pszMangled, parse_ptr - pszMangled - 1); /* ASSUMES not extra spaces! */
|
|---|
| 2228 | tf->flags = parse_visibility () | MEMBER_FUNCTION;
|
|---|
| 2229 | switch (*parse_ptr)
|
|---|
| 2230 | {
|
|---|
| 2231 | case 'A':
|
|---|
| 2232 | ++parse_ptr;
|
|---|
| 2233 | break;
|
|---|
| 2234 | case 'B':
|
|---|
| 2235 | tf->flags |= MEMBER_CONST;
|
|---|
| 2236 | ++parse_ptr;
|
|---|
| 2237 | break;
|
|---|
| 2238 | case 'C':
|
|---|
| 2239 | tf->flags |= MEMBER_VOLATILE;
|
|---|
| 2240 | ++parse_ptr;
|
|---|
| 2241 | break;
|
|---|
| 2242 | case 'D':
|
|---|
| 2243 | tf->flags |= MEMBER_CONST | MEMBER_VOLATILE;
|
|---|
| 2244 | ++parse_ptr;
|
|---|
| 2245 | break;
|
|---|
| 2246 | default:
|
|---|
| 2247 | no_warning ("Unknown member function qualifier: %c",
|
|---|
| 2248 | *parse_ptr);
|
|---|
| 2249 | if (*parse_ptr != 0)
|
|---|
| 2250 | ++parse_ptr;
|
|---|
| 2251 | }
|
|---|
| 2252 | switch (*parse_ptr)
|
|---|
| 2253 | {
|
|---|
| 2254 | case '.':
|
|---|
| 2255 | ++parse_ptr;
|
|---|
| 2256 | break;
|
|---|
| 2257 | case '*':
|
|---|
| 2258 | tf->flags |= MEMBER_VIRTUAL;
|
|---|
| 2259 | ++parse_ptr;
|
|---|
| 2260 | if (!parse_number (&offset) || !parse_char (';'))
|
|---|
| 2261 | {
|
|---|
| 2262 | warning ("Invalid data for virtual member function");
|
|---|
| 2263 | goto syntax;
|
|---|
| 2264 | }
|
|---|
| 2265 | parse_type (NULL);
|
|---|
| 2266 | if (!parse_char (';'))
|
|---|
| 2267 | {
|
|---|
| 2268 | warning ("Invalid data for virtual member function");
|
|---|
| 2269 | goto syntax;
|
|---|
| 2270 | }
|
|---|
| 2271 | break;
|
|---|
| 2272 | case '?':
|
|---|
| 2273 | tf->flags |= MEMBER_STATIC;
|
|---|
| 2274 | ++parse_ptr;
|
|---|
| 2275 | break;
|
|---|
| 2276 | default:
|
|---|
| 2277 | no_warning ("Unknown member function qualifier: %c",
|
|---|
| 2278 | *parse_ptr);
|
|---|
| 2279 | if (*parse_ptr != 0)
|
|---|
| 2280 | ++parse_ptr;
|
|---|
| 2281 | }
|
|---|
| 2282 | /* Contstructor / Destructor hack -
|
|---|
| 2283 | * TODO: verify that this doesn't really work with overloaded constructors and fix it.
|
|---|
| 2284 | */
|
|---|
| 2285 | if (!(tf->flags & MEMBER_STATIC))
|
|---|
| 2286 | {
|
|---|
| 2287 | /* using the strpool is much faster! */
|
|---|
| 2288 | static const char *pszCompCtor, *pszBaseCtor, *pszCompDtor, *pszBaseDtor = NULL;
|
|---|
| 2289 | if (!pszBaseDtor)
|
|---|
| 2290 | {
|
|---|
| 2291 | pszCompCtor = strpool_addn(str_pool, "__comp_ctor", 11);
|
|---|
| 2292 | pszBaseCtor = strpool_addn(str_pool, "__base_ctor", 11);
|
|---|
| 2293 | pszCompDtor = strpool_addn(str_pool, "__comp_dtor", 11);
|
|---|
| 2294 | pszBaseDtor = strpool_addn(str_pool, "__base_dtor", 11);
|
|---|
| 2295 | }
|
|---|
| 2296 |
|
|---|
| 2297 | if (tf->name == pszCompCtor || tf->name == pszBaseCtor)
|
|---|
| 2298 | tf->flags |= MEMBER_CTOR;
|
|---|
| 2299 | else if (tf->name == pszCompDtor || tf->name == pszBaseDtor)
|
|---|
| 2300 | tf->flags |= MEMBER_DTOR;
|
|---|
| 2301 | }
|
|---|
| 2302 | tf->type = t1;
|
|---|
| 2303 | tf->offset = offset;
|
|---|
| 2304 | if (*parse_ptr != ';')
|
|---|
| 2305 | {
|
|---|
| 2306 | /* Another member function with the same name
|
|---|
| 2307 | follows. */
|
|---|
| 2308 |
|
|---|
| 2309 | grow_by (&g1, 1);
|
|---|
| 2310 | tf = &tmp_fields[g1.count++];
|
|---|
| 2311 | tf->flags = VIS_PUBLIC | MEMBER_FUNCTION;
|
|---|
| 2312 | tf->name = tf[-1].name;
|
|---|
| 2313 | }
|
|---|
| 2314 | } while (*parse_ptr != ';');
|
|---|
| 2315 | ++parse_ptr;
|
|---|
| 2316 | }
|
|---|
| 2317 | else
|
|---|
| 2318 | {
|
|---|
| 2319 | if (*parse_ptr == '/')
|
|---|
| 2320 | {
|
|---|
| 2321 | class_flag = TRUE;
|
|---|
| 2322 | ++parse_ptr;
|
|---|
| 2323 | tf->flags = parse_visibility ();
|
|---|
| 2324 | }
|
|---|
| 2325 | t1 = parse_type (NULL);
|
|---|
| 2326 | if (*parse_ptr == ':')
|
|---|
| 2327 | {
|
|---|
| 2328 | /* Static member */
|
|---|
| 2329 |
|
|---|
| 2330 | ++parse_ptr;
|
|---|
| 2331 | tf->flags |= MEMBER_STATIC;
|
|---|
| 2332 | p1 = strchr (parse_ptr, ';');
|
|---|
| 2333 | if (p1 == NULL)
|
|---|
| 2334 | {
|
|---|
| 2335 | warning ("Invalid static member: missing semicolon");
|
|---|
| 2336 | goto syntax;
|
|---|
| 2337 | }
|
|---|
| 2338 | n = p1 - parse_ptr;
|
|---|
| 2339 | tf->sname = strpool_addn (str_pool, parse_ptr, n);
|
|---|
| 2340 | parse_ptr = p1 + 1;
|
|---|
| 2341 | tf->offset = 0;
|
|---|
| 2342 | }
|
|---|
| 2343 | else
|
|---|
| 2344 | {
|
|---|
| 2345 | if (!parse_char (',') || !parse_number (&offset))
|
|---|
| 2346 | goto syntax;
|
|---|
| 2347 | if (*parse_ptr == ',')
|
|---|
| 2348 | {
|
|---|
| 2349 | ++parse_ptr;
|
|---|
| 2350 | if (!parse_number (&width))
|
|---|
| 2351 | goto syntax;
|
|---|
| 2352 | }
|
|---|
| 2353 | else
|
|---|
| 2354 | width = 0; /* vtable pointer field */
|
|---|
| 2355 | if (!parse_char (';'))
|
|---|
| 2356 | goto syntax;
|
|---|
| 2357 | if ((offset & 7) != 0 || width != 8 * type_size (t1))
|
|---|
| 2358 | {
|
|---|
| 2359 | t.tag = ty_bits;
|
|---|
| 2360 | t.d.bits.type = t1;
|
|---|
| 2361 | t.d.bits.start = offset & 7;
|
|---|
| 2362 | t.d.bits.count = width;
|
|---|
| 2363 | t1 = type_add (&t);
|
|---|
| 2364 | }
|
|---|
| 2365 | tf->offset = offset >> 3;
|
|---|
| 2366 | }
|
|---|
| 2367 | tf->type = t1;
|
|---|
| 2368 | }
|
|---|
| 2369 | }
|
|---|
| 2370 | ++parse_ptr;
|
|---|
| 2371 | if (*parse_ptr == '~')
|
|---|
| 2372 | {
|
|---|
| 2373 | /* Type reference to the first base class. This field is
|
|---|
| 2374 | present for classes which contain virtual functions. */
|
|---|
| 2375 |
|
|---|
| 2376 | ++parse_ptr;
|
|---|
| 2377 | if (!parse_char ('%'))
|
|---|
| 2378 | goto syntax;
|
|---|
| 2379 | t1 = parse_type (NULL);
|
|---|
| 2380 | if (!parse_char (';'))
|
|---|
| 2381 | goto syntax;
|
|---|
| 2382 | }
|
|---|
| 2383 |
|
|---|
| 2384 | if (class_flag)
|
|---|
| 2385 | {
|
|---|
| 2386 | tlist = xmalloc (g1.count * sizeof (*t.d.types.list));
|
|---|
| 2387 | for (i = 0; i < g1.count; ++i)
|
|---|
| 2388 | {
|
|---|
| 2389 | if (tmp_fields[i].flags & MEMBER_FUNCTION)
|
|---|
| 2390 | {
|
|---|
| 2391 | t2 = tmp_fields[i].type;
|
|---|
| 2392 | tt = follow_refs (t2)->tag;
|
|---|
| 2393 | /* TODO: check later if ty_stabs_ref */
|
|---|
| 2394 | if (tt != ty_func && tt != ty_stabs_ref)
|
|---|
| 2395 | error ("Invalid type for member function %s",
|
|---|
| 2396 | tmp_fields[i].name);
|
|---|
| 2397 | t.tag = ty_memfunc;
|
|---|
| 2398 | t.d.memfunc.type = t2;
|
|---|
| 2399 | t.d.memfunc.name = tmp_fields[i].name;
|
|---|
| 2400 | t.d.memfunc.mnglname = tmp_fields[i].mnglname;
|
|---|
| 2401 | t.d.memfunc.flags = tmp_fields[i].flags;
|
|---|
| 2402 | t.d.memfunc.offset = tmp_fields[i].offset;
|
|---|
| 2403 | }
|
|---|
| 2404 | else if (tmp_fields[i].flags & MEMBER_BASE)
|
|---|
| 2405 | {
|
|---|
| 2406 | t.tag = ty_baseclass;
|
|---|
| 2407 | t.d.baseclass.type = tmp_fields[i].type;
|
|---|
| 2408 | t.d.baseclass.flags = tmp_fields[i].flags;
|
|---|
| 2409 | t.d.baseclass.offset = tmp_fields[i].offset;
|
|---|
| 2410 | }
|
|---|
| 2411 | else
|
|---|
| 2412 | {
|
|---|
| 2413 | t.tag = ty_member;
|
|---|
| 2414 | t.d.member.type = tmp_fields[i].type;
|
|---|
| 2415 | t.d.member.offset = tmp_fields[i].offset;
|
|---|
| 2416 | t.d.member.flags = tmp_fields[i].flags;
|
|---|
| 2417 | t.d.member.name = tmp_fields[i].name;
|
|---|
| 2418 | t.d.member.sname = tmp_fields[i].sname;
|
|---|
| 2419 | }
|
|---|
| 2420 | t2 = type_add (&t);
|
|---|
| 2421 | tlist[i] = t2;
|
|---|
| 2422 | }
|
|---|
| 2423 | t.tag = ty_types;
|
|---|
| 2424 | t.d.types.count = g1.count;
|
|---|
| 2425 | t.d.types.list = tlist;
|
|---|
| 2426 | t1 = type_add (&t);
|
|---|
| 2427 | free (tlist);
|
|---|
| 2428 |
|
|---|
| 2429 | t.tag = ty_class;
|
|---|
| 2430 | t.d.class.members = t1;
|
|---|
| 2431 | t.d.class.size = size;
|
|---|
| 2432 | t.d.class.count = g1.count;
|
|---|
| 2433 | t.d.class.name = add_struct_name (type_name);
|
|---|
| 2434 |
|
|---|
| 2435 | /* Check if there is an incomplete type waiting to be filled
|
|---|
| 2436 | in (forward reference). We're ignoring scoping (TODO). */
|
|---|
| 2437 |
|
|---|
| 2438 | for (t3 = type_head; t3 != NULL; t3 = t3->next)
|
|---|
| 2439 | if (t3->tag == ty_struc && t3->d.struc.name == t.d.class.name
|
|---|
| 2440 | /*&& t3->d.struc.types == NULL && t3->d.struc.fields == NULL */
|
|---|
| 2441 | && (t3->d.struc.flags & STRUC_FORWARD))
|
|---|
| 2442 | {
|
|---|
| 2443 | if (t3->index != -1)
|
|---|
| 2444 | warning ("This cannot happen, case 1");
|
|---|
| 2445 | result = t3;
|
|---|
| 2446 | t3->tag = ty_class;
|
|---|
| 2447 | t3->d.class = t.d.class;
|
|---|
| 2448 | break;
|
|---|
| 2449 | }
|
|---|
| 2450 | }
|
|---|
| 2451 | else
|
|---|
| 2452 | {
|
|---|
| 2453 | t.tag = ty_types;
|
|---|
| 2454 | t.d.types.count = g1.count;
|
|---|
| 2455 | t.d.types.list = xmalloc (g1.count * sizeof (*t.d.types.list));
|
|---|
| 2456 | for (i = 0; i < g1.count; ++i)
|
|---|
| 2457 | t.d.types.list[i] = tmp_fields[i].type;
|
|---|
| 2458 | t1 = type_add (&t);
|
|---|
| 2459 | free (t.d.types.list);
|
|---|
| 2460 |
|
|---|
| 2461 | t.tag = ty_fields;
|
|---|
| 2462 | t.d.fields.count = g1.count;
|
|---|
| 2463 | t.d.fields.list = xmalloc (g1.count * sizeof (*t.d.fields.list));
|
|---|
| 2464 | for (i = 0; i < g1.count; ++i)
|
|---|
| 2465 | {
|
|---|
| 2466 | t.d.fields.list[i].offset = tmp_fields[i].offset;
|
|---|
| 2467 | t.d.fields.list[i].name = tmp_fields[i].name;
|
|---|
| 2468 | }
|
|---|
| 2469 | t2 = type_add (&t);
|
|---|
| 2470 | free (t.d.fields.list);
|
|---|
| 2471 |
|
|---|
| 2472 | t.tag = ty_struc;
|
|---|
| 2473 | t.d.struc.count = g1.count;
|
|---|
| 2474 | t.d.struc.size = size;
|
|---|
| 2475 | t.d.struc.types = t1;
|
|---|
| 2476 | t.d.struc.fields = t2;
|
|---|
| 2477 | t.d.struc.name = add_struct_name (type_name);
|
|---|
| 2478 | t.d.struc.flags = 0;
|
|---|
| 2479 |
|
|---|
| 2480 | /* Check if there is an incomplete type waiting to be filled
|
|---|
| 2481 | in (forward reference). We're ignoring scoping (TODO). */
|
|---|
| 2482 |
|
|---|
| 2483 | for (t3 = type_head; t3 != NULL; t3 = t3->next)
|
|---|
| 2484 | if (t3->tag == ty_struc && t3->d.struc.name == t.d.struc.name
|
|---|
| 2485 | /* && t3->d.struc.types == NULL && t3->d.struc.fields == NULL */
|
|---|
| 2486 | && (t3->d.struc.flags & STRUC_FORWARD))
|
|---|
| 2487 | {
|
|---|
| 2488 | if (t3->index != -1)
|
|---|
| 2489 | warning ("This cannot happen, case 1");
|
|---|
| 2490 | result = t3;
|
|---|
| 2491 | t3->d.struc = t.d.struc;
|
|---|
| 2492 | break;
|
|---|
| 2493 | }
|
|---|
| 2494 | }
|
|---|
| 2495 | grow_free (&g1);
|
|---|
| 2496 | break;
|
|---|
| 2497 |
|
|---|
| 2498 | case 'e':
|
|---|
| 2499 |
|
|---|
| 2500 | /* Enumeration type: e{<name>:<value>,}; */
|
|---|
| 2501 |
|
|---|
| 2502 | ++parse_ptr;
|
|---|
| 2503 | grow_init (&g1, &tmp_values, sizeof (*tmp_values), 8);
|
|---|
| 2504 | while (*parse_ptr != ';')
|
|---|
| 2505 | {
|
|---|
| 2506 | p1 = nextcolon (parse_ptr);
|
|---|
| 2507 | if (p1 == NULL)
|
|---|
| 2508 | {
|
|---|
| 2509 | warning ("Invalid enum type: missing colon");
|
|---|
| 2510 | goto syntax;
|
|---|
| 2511 | }
|
|---|
| 2512 | n = p1 - parse_ptr;
|
|---|
| 2513 | grow_by (&g1, 1);
|
|---|
| 2514 | tv = &tmp_values[g1.count++];
|
|---|
| 2515 | tv->name = strpool_addn (str_pool, parse_ptr, n);
|
|---|
| 2516 | parse_ptr = p1 + 1;
|
|---|
| 2517 | if (!parse_number (&tv->index) || !parse_char (','))
|
|---|
| 2518 | goto syntax;
|
|---|
| 2519 | }
|
|---|
| 2520 | ++parse_ptr;
|
|---|
| 2521 | t.tag = ty_values;
|
|---|
| 2522 | t.d.values.count = g1.count;
|
|---|
| 2523 | t.d.values.list = xmalloc (g1.count * sizeof (*t.d.values.list));
|
|---|
| 2524 | if (g1.count == 0)
|
|---|
| 2525 | lo = hi = 0;
|
|---|
| 2526 | else
|
|---|
| 2527 | lo = hi = tmp_values[0].index;
|
|---|
| 2528 | for (i = 0; i < g1.count; ++i)
|
|---|
| 2529 | {
|
|---|
| 2530 | t.d.values.list[i].index = tmp_values[i].index;
|
|---|
| 2531 | t.d.values.list[i].name = tmp_values[i].name;
|
|---|
| 2532 | if (tmp_values[i].index < lo)
|
|---|
| 2533 | lo = tmp_values[i].index;
|
|---|
| 2534 | if (tmp_values[i].index > hi)
|
|---|
| 2535 | hi = tmp_values[i].index;
|
|---|
| 2536 | }
|
|---|
| 2537 | t1 = type_add (&t);
|
|---|
| 2538 | free (t.d.values.list);
|
|---|
| 2539 |
|
|---|
| 2540 | t.tag = ty_prim;
|
|---|
| 2541 | t.index = 0x82; /* 32 bit signed */
|
|---|
| 2542 | t2 = type_add (&t);
|
|---|
| 2543 |
|
|---|
| 2544 | t.tag = ty_enu;
|
|---|
| 2545 | t.index = -1;
|
|---|
| 2546 | t.d.enu.values = t1;
|
|---|
| 2547 | t.d.enu.type = t2;
|
|---|
| 2548 | t.d.enu.name = add_struct_name (type_name);
|
|---|
| 2549 | t.d.enu.first = lo;
|
|---|
| 2550 | t.d.enu.last = hi;
|
|---|
| 2551 | grow_free (&g1);
|
|---|
| 2552 | break;
|
|---|
| 2553 |
|
|---|
| 2554 | case 'a':
|
|---|
| 2555 | /* An array: ar<index_type>;<lower_bound>;<upper_bound>;<el_type> */
|
|---|
| 2556 |
|
|---|
| 2557 | ++parse_ptr;
|
|---|
| 2558 | if (!parse_char ('r'))
|
|---|
| 2559 | goto syntax;
|
|---|
| 2560 | if (strncmp (parse_ptr, "0;", 2) == 0)
|
|---|
| 2561 | {
|
|---|
| 2562 | /* This invalid type index seems to be caused by a bug of
|
|---|
| 2563 | GCC 2.8.1. Replace with a 32-bit signed integer. */
|
|---|
| 2564 |
|
|---|
| 2565 | t.tag = ty_prim;
|
|---|
| 2566 | t.index = 0x82; /* 32 bit signed */
|
|---|
| 2567 | t1 = type_add (&t);
|
|---|
| 2568 | ++parse_ptr;
|
|---|
| 2569 | }
|
|---|
| 2570 | else
|
|---|
| 2571 | t1 = parse_type (NULL); /* Index type */
|
|---|
| 2572 | if (!parse_char (';')
|
|---|
| 2573 | || !parse_number (&lo) || !parse_char (';') /* Lower bound */
|
|---|
| 2574 | || !parse_number (&hi) || !parse_char (';')) /* Upper bound */
|
|---|
| 2575 | goto syntax;
|
|---|
| 2576 | t2 = parse_type (NULL); /* Elements type */
|
|---|
| 2577 | if (lo == 0 && hi == 0) /* Variable-length array */
|
|---|
| 2578 | {
|
|---|
| 2579 | t.tag = ty_pointer; /* Turn into pointer */
|
|---|
| 2580 | t.d.pointer = t2;
|
|---|
| 2581 | }
|
|---|
| 2582 | else
|
|---|
| 2583 | {
|
|---|
| 2584 | t.tag = ty_array;
|
|---|
| 2585 | t.d.array.first = lo;
|
|---|
| 2586 | t.d.array.last = hi;
|
|---|
| 2587 | t.d.array.itype = t1;
|
|---|
| 2588 | t.d.array.etype = t2;
|
|---|
| 2589 | }
|
|---|
| 2590 | break;
|
|---|
| 2591 |
|
|---|
| 2592 | case 'f':
|
|---|
| 2593 |
|
|---|
| 2594 | /* A function: f<return_type> */
|
|---|
| 2595 |
|
|---|
| 2596 | ++parse_ptr;
|
|---|
| 2597 | t1 = parse_type (NULL); /* Return type */
|
|---|
| 2598 | t.tag = ty_func;
|
|---|
| 2599 | t.d.func.ret = t1;
|
|---|
| 2600 | t.d.func.domain = NULL;
|
|---|
| 2601 | t.d.func.args = NULL;
|
|---|
| 2602 | t.d.func.arg_count = 0;
|
|---|
| 2603 | break;
|
|---|
| 2604 |
|
|---|
| 2605 | default:
|
|---|
| 2606 | no_warning ("Unknown type: %c", *parse_ptr);
|
|---|
| 2607 | goto syntax;
|
|---|
| 2608 | }
|
|---|
| 2609 |
|
|---|
| 2610 | /* Add the type to the tables. */
|
|---|
| 2611 |
|
|---|
| 2612 | if (result == NULL)
|
|---|
| 2613 | result = type_add (&t);
|
|---|
| 2614 | return result;
|
|---|
| 2615 |
|
|---|
| 2616 | syntax:
|
|---|
| 2617 | no_warning ("syntax error in stabs: %c (off %ld)\n stabs: %s",
|
|---|
| 2618 | *parse_ptr, parse_ptr - parse_start, parse_start);
|
|---|
| 2619 |
|
|---|
| 2620 | grow_free (&g1);
|
|---|
| 2621 | t.tag = ty_prim;
|
|---|
| 2622 | t.index = 0x82; /* 32 bit signed */
|
|---|
| 2623 | return type_add (&t);
|
|---|
| 2624 | }
|
|---|
| 2625 |
|
|---|
| 2626 |
|
|---|
| 2627 | /* Parse a stabs type (the name of the type is TYPE_NAME, which is
|
|---|
| 2628 | NULL for an unnamed type) and check for end of the string. If not
|
|---|
| 2629 | all characters of the string have been parsed, a warning message is
|
|---|
| 2630 | displayed. Return the internal representation of the type. */
|
|---|
| 2631 |
|
|---|
| 2632 | static struct type *parse_complete_type (const char *type_name)
|
|---|
| 2633 | {
|
|---|
| 2634 | struct type *tp;
|
|---|
| 2635 |
|
|---|
| 2636 | tp = parse_type (type_name);
|
|---|
| 2637 | if (*parse_ptr != 0)
|
|---|
| 2638 | no_warning ("unexpected character at end of stabs type: %c (off %ld)\n stabs: %s",
|
|---|
| 2639 | *parse_ptr, parse_ptr - parse_start, parse_start);
|
|---|
| 2640 | return tp;
|
|---|
| 2641 | }
|
|---|
| 2642 |
|
|---|
| 2643 |
|
|---|
| 2644 | /* Create an HLL type number for type TP. If a type number has already
|
|---|
| 2645 | been assigned to TP, use that number. Otherwise, allocate a new
|
|---|
| 2646 | (complex) type number and define the type in the $$TYPES segment.
|
|---|
| 2647 | The HLL type number us stored to *HLL.
|
|---|
| 2648 |
|
|---|
| 2649 | Note: This function must not be called between sst_start() and
|
|---|
| 2650 | sst_end() or tt_start() and tt_end() as entries are made both in
|
|---|
| 2651 | the SST ($$SYMBOLS) and the type table ($$TYPES). */
|
|---|
| 2652 |
|
|---|
| 2653 | static void make_type (struct type *tp, int *hll)
|
|---|
| 2654 | {
|
|---|
| 2655 | struct type *t1;
|
|---|
| 2656 | int ti_1, ti_2, ti_3, i, qual;
|
|---|
| 2657 | int patch1;
|
|---|
| 2658 |
|
|---|
| 2659 | #define RETURN(X) do {*hll = (X); return;} while (0)
|
|---|
| 2660 |
|
|---|
| 2661 | if (tp->index <= -2)
|
|---|
| 2662 | {
|
|---|
| 2663 | /* bird: A hack where we allow a 2nd recursion of rectain types.
|
|---|
| 2664 | * The normal issue is C++ class references. */
|
|---|
| 2665 | if (tp->tag != ty_alias || tp->index <= -3)
|
|---|
| 2666 | {
|
|---|
| 2667 | warning_parse ("Cycle detected by make_type.");
|
|---|
| 2668 | RETURN (0);
|
|---|
| 2669 | }
|
|---|
| 2670 | }
|
|---|
| 2671 | if (tp->index > -1)
|
|---|
| 2672 | RETURN (tp->index);
|
|---|
| 2673 | tp->index--;
|
|---|
| 2674 | switch (tp->tag)
|
|---|
| 2675 | {
|
|---|
| 2676 | case ty_stabs_ref:
|
|---|
| 2677 | t1 = stype_find (tp->d.stabs_ref);
|
|---|
| 2678 | if (t1 == NULL)
|
|---|
| 2679 | {
|
|---|
| 2680 | warning_parse ("Undefined stabs type %d referenced", tp->d.stabs_ref);
|
|---|
| 2681 | RETURN (0x82); /* 32 bit signed */
|
|---|
| 2682 | }
|
|---|
| 2683 | make_type (t1, &tp->index);
|
|---|
| 2684 | *hll = tp->index;
|
|---|
| 2685 | break;
|
|---|
| 2686 |
|
|---|
| 2687 | case ty_alias:
|
|---|
| 2688 | make_type (tp->d.alias, &tp->index);
|
|---|
| 2689 | *hll = tp->index;
|
|---|
| 2690 | break;
|
|---|
| 2691 |
|
|---|
| 2692 | case ty_pointer:
|
|---|
| 2693 | ti_1 = tp->d.pointer->index;
|
|---|
| 2694 | if (ti_1 >= 0x80 && ti_1 <= 0xa0)
|
|---|
| 2695 | {
|
|---|
| 2696 | tp->index = ti_1 + 0x20;
|
|---|
| 2697 | RETURN (tp->index);
|
|---|
| 2698 | }
|
|---|
| 2699 | *hll = tp->index = hll_type_index++;
|
|---|
| 2700 | tt_start (0x7a, 0x01); /* 32-bit near pointer */
|
|---|
| 2701 | patch1 = tt.size;
|
|---|
| 2702 | tt_index (0);
|
|---|
| 2703 | tt_end ();
|
|---|
| 2704 | make_type (tp->d.pointer, &ti_1);
|
|---|
| 2705 | buffer_patch_word (&tt, patch1+1, ti_1);
|
|---|
| 2706 | break;
|
|---|
| 2707 |
|
|---|
| 2708 | case ty_ref:
|
|---|
| 2709 | *hll = tp->index = hll_type_index++;
|
|---|
| 2710 | tt_start (0x48, 0x00); /* Reference type (C++) */
|
|---|
| 2711 | patch1 = tt.size;
|
|---|
| 2712 | tt_word (0);
|
|---|
| 2713 | tt_end ();
|
|---|
| 2714 | make_type (tp->d.ref, &ti_1);
|
|---|
| 2715 | buffer_patch_word (&tt, patch1, ti_1);
|
|---|
| 2716 | break;
|
|---|
| 2717 |
|
|---|
| 2718 | case ty_struc:
|
|---|
| 2719 | {
|
|---|
| 2720 | struct field *fields = NULL;
|
|---|
| 2721 | struct type **types = NULL;
|
|---|
| 2722 | int cFields = tp->d.struc.count;
|
|---|
| 2723 |
|
|---|
| 2724 | if ( tp->d.struc.fields
|
|---|
| 2725 | && tp->d.struc.fields->tag == ty_fields
|
|---|
| 2726 | && tp->d.struc.fields->d.fields.count == cFields)
|
|---|
| 2727 | fields = tp->d.struc.fields->d.fields.list;
|
|---|
| 2728 | if ( tp->d.struc.types
|
|---|
| 2729 | && tp->d.struc.types->tag == ty_types
|
|---|
| 2730 | && tp->d.struc.types->d.types.count == cFields)
|
|---|
| 2731 | types = tp->d.struc.types->d.types.list;
|
|---|
| 2732 |
|
|---|
| 2733 | if (cplusplus_flag && ((types && fields) || !cFields))
|
|---|
| 2734 | {
|
|---|
| 2735 | struct type t;
|
|---|
| 2736 | struct type **list;
|
|---|
| 2737 | int i;
|
|---|
| 2738 | *hll = tp->index = hll_type_index++;
|
|---|
| 2739 | tt_start (0x40, 0x01); /* Class is-struct */
|
|---|
| 2740 | tt_dword (tp->d.struc.size);
|
|---|
| 2741 | tt_word (tp->d.struc.count);
|
|---|
| 2742 | patch1 = tt.size;
|
|---|
| 2743 | tt_word (0); /* Members */
|
|---|
| 2744 | tt_enc (tp->d.struc.name); /* Class name */
|
|---|
| 2745 | tt_end ();
|
|---|
| 2746 |
|
|---|
| 2747 | list = xmalloc (cFields * sizeof (*list));
|
|---|
| 2748 | for (i = 0; i < cFields; ++i)
|
|---|
| 2749 | {
|
|---|
| 2750 | t.tag = ty_member;
|
|---|
| 2751 | t.index = -1;
|
|---|
| 2752 | t.d.member.type = types[i];
|
|---|
| 2753 | t.d.member.offset = fields[i].offset;
|
|---|
| 2754 | t.d.member.flags = VIS_PUBLIC;
|
|---|
| 2755 | t.d.member.name = fields[i].name;
|
|---|
| 2756 | t.d.member.sname = NULL;
|
|---|
| 2757 | list[i] = type_add (&t);
|
|---|
| 2758 | }
|
|---|
| 2759 |
|
|---|
| 2760 | t.tag = ty_types;
|
|---|
| 2761 | t.index = -1;
|
|---|
| 2762 | t.d.types.count = cFields;
|
|---|
| 2763 | t.d.types.list = list;
|
|---|
| 2764 | t1 = type_add (&t);
|
|---|
| 2765 | free (list);
|
|---|
| 2766 |
|
|---|
| 2767 | make_type (t1, &ti_1);
|
|---|
| 2768 | buffer_patch_word (&tt, patch1, ti_1);
|
|---|
| 2769 | }
|
|---|
| 2770 | else
|
|---|
| 2771 | {
|
|---|
| 2772 | tt_start (0x79, 0x00); /* Structure/Union */
|
|---|
| 2773 | tt_dword (tp->d.struc.size);
|
|---|
| 2774 | tt_word (tp->d.struc.count);
|
|---|
| 2775 | patch1 = tt.size;
|
|---|
| 2776 | tt_index (0);
|
|---|
| 2777 | tt_index (0);
|
|---|
| 2778 | tt_name (tp->d.struc.name);
|
|---|
| 2779 | tt_end ();
|
|---|
| 2780 | *hll = tp->index = hll_type_index++;
|
|---|
| 2781 | if (tp->d.struc.types == NULL && tp->d.struc.fields == NULL)
|
|---|
| 2782 | {
|
|---|
| 2783 | ti_1 = 0;
|
|---|
| 2784 | ti_2 = 1;
|
|---|
| 2785 | }
|
|---|
| 2786 | else
|
|---|
| 2787 | {
|
|---|
| 2788 | make_type (tp->d.struc.types, &ti_1);
|
|---|
| 2789 | make_type (tp->d.struc.fields, &ti_2);
|
|---|
| 2790 | }
|
|---|
| 2791 | buffer_patch_word (&tt, patch1+1, ti_1);
|
|---|
| 2792 | buffer_patch_word (&tt, patch1+4, ti_2);
|
|---|
| 2793 | }
|
|---|
| 2794 | break;
|
|---|
| 2795 | }
|
|---|
| 2796 |
|
|---|
| 2797 | case ty_class:
|
|---|
| 2798 | *hll = tp->index = hll_type_index++;
|
|---|
| 2799 | tt_start (0x40, 0x00); /* Class */
|
|---|
| 2800 | tt_dword (tp->d.class.size);
|
|---|
| 2801 | tt_word (tp->d.class.count);
|
|---|
| 2802 | patch1 = tt.size;
|
|---|
| 2803 | tt_word (0); /* Members */
|
|---|
| 2804 | tt_enc (tp->d.class.name); /* Class name */
|
|---|
| 2805 | tt_end ();
|
|---|
| 2806 | make_type (tp->d.class.members, &ti_1);
|
|---|
| 2807 | buffer_patch_word (&tt, patch1, ti_1);
|
|---|
| 2808 | break;
|
|---|
| 2809 |
|
|---|
| 2810 | case ty_member:
|
|---|
| 2811 | qual = 0;
|
|---|
| 2812 | if (tp->d.member.flags & MEMBER_STATIC)
|
|---|
| 2813 | qual |= 0x01;
|
|---|
| 2814 | tt_start (0x46, qual);
|
|---|
| 2815 | tt_byte (tp->d.member.flags & MEMBER_VIS);
|
|---|
| 2816 | patch1 = tt.size;
|
|---|
| 2817 | tt_word (0);
|
|---|
| 2818 | tt_unsigned_span (tp->d.member.offset);
|
|---|
| 2819 | if (tp->d.member.flags & MEMBER_STATIC)
|
|---|
| 2820 | tt_enc (tp->d.member.sname);
|
|---|
| 2821 | else
|
|---|
| 2822 | tt_enc ("");
|
|---|
| 2823 | tt_enc (tp->d.member.name);
|
|---|
| 2824 | tt_end ();
|
|---|
| 2825 | *hll = tp->index = hll_type_index++;
|
|---|
| 2826 |
|
|---|
| 2827 | make_type (tp->d.member.type, &ti_1);
|
|---|
| 2828 | buffer_patch_word (&tt, patch1, ti_1);
|
|---|
| 2829 | break;
|
|---|
| 2830 |
|
|---|
| 2831 | case ty_enu:
|
|---|
| 2832 | make_type (tp->d.enu.type, &ti_1);
|
|---|
| 2833 | make_type (tp->d.enu.values, &ti_2);
|
|---|
| 2834 | tt_start (0x7b, 0x00); /* Enum */
|
|---|
| 2835 | tt_index (ti_1); /* Element's data type */
|
|---|
| 2836 | tt_index (ti_2); /* List of values */
|
|---|
| 2837 | tt_signed_span (tp->d.enu.first); /* Minimum index */
|
|---|
| 2838 | tt_signed_span (tp->d.enu.last); /* Maximum index */
|
|---|
| 2839 | tt_name (tp->d.enu.name);
|
|---|
| 2840 | tt_end ();
|
|---|
| 2841 | *hll = tp->index = hll_type_index++;
|
|---|
| 2842 | break;
|
|---|
| 2843 |
|
|---|
| 2844 | case ty_array:
|
|---|
| 2845 | make_type (tp->d.array.itype, &ti_1);
|
|---|
| 2846 | make_type (tp->d.array.etype, &ti_2);
|
|---|
| 2847 | tt_start (0x78, 0x00); /* Array */
|
|---|
| 2848 | tt_dword (type_size (tp));
|
|---|
| 2849 | tt_index (ti_1);
|
|---|
| 2850 | tt_index (ti_2);
|
|---|
| 2851 | tt_name (""); /* Name */
|
|---|
| 2852 | tt_end ();
|
|---|
| 2853 | *hll = tp->index = hll_type_index++;
|
|---|
| 2854 | break;
|
|---|
| 2855 |
|
|---|
| 2856 | case ty_bits:
|
|---|
| 2857 | tt_start (0x5c, 0x0a); /* Bit string */
|
|---|
| 2858 | tt_byte (tp->d.bits.start);
|
|---|
| 2859 | tt_unsigned_span (tp->d.bits.count);
|
|---|
| 2860 | tt_end ();
|
|---|
| 2861 | *hll = tp->index = hll_type_index++;
|
|---|
| 2862 | break;
|
|---|
| 2863 |
|
|---|
| 2864 | case ty_func:
|
|---|
| 2865 | tt_start (0x54, 0x05); /* Function */
|
|---|
| 2866 | tt_word (tp->d.func.arg_count); /* Number of parameters */
|
|---|
| 2867 | tt_word (tp->d.func.arg_count); /* Max. Number of parameters */
|
|---|
| 2868 | patch1 = tt.size;
|
|---|
| 2869 | tt_index (0); /* Return value */
|
|---|
| 2870 | tt_index (0); /* Argument list */
|
|---|
| 2871 | tt_end ();
|
|---|
| 2872 | *hll = tp->index = hll_type_index++;
|
|---|
| 2873 |
|
|---|
| 2874 | if (tp->d.func.domain)
|
|---|
| 2875 | make_type (tp->d.func.domain, &ti_3);
|
|---|
| 2876 | make_type (tp->d.func.ret, &ti_1);
|
|---|
| 2877 | if (tp->d.func.args == NULL)
|
|---|
| 2878 | ti_2 = 0;
|
|---|
| 2879 | else
|
|---|
| 2880 | make_type (tp->d.func.args, &ti_2);
|
|---|
| 2881 | buffer_patch_word (&tt, patch1+1, ti_1);
|
|---|
| 2882 | buffer_patch_word (&tt, patch1+4, ti_2);
|
|---|
| 2883 | break;
|
|---|
| 2884 |
|
|---|
| 2885 | case ty_args:
|
|---|
| 2886 | if (tp->d.args.count == 0)
|
|---|
| 2887 | {
|
|---|
| 2888 | tp->index = 0;
|
|---|
| 2889 | RETURN (tp->index);
|
|---|
| 2890 | }
|
|---|
| 2891 | for (i = 0; i < tp->d.args.count; ++i)
|
|---|
| 2892 | make_type (tp->d.args.list[i], &ti_1);
|
|---|
| 2893 | tt_start (0x7f, 0x04); /* List (function parameters) */
|
|---|
| 2894 | for (i = 0; i < tp->d.args.count; ++i)
|
|---|
| 2895 | {
|
|---|
| 2896 | tt_byte (0x01); /* Flag: pass by value, no descriptor */
|
|---|
| 2897 | tt_index (tp->d.args.list[i]->index);
|
|---|
| 2898 | }
|
|---|
| 2899 | tt_end ();
|
|---|
| 2900 | *hll = tp->index = hll_type_index++;
|
|---|
| 2901 | break;
|
|---|
| 2902 |
|
|---|
| 2903 | case ty_types:
|
|---|
| 2904 | if (tp->d.types.count == 0)
|
|---|
| 2905 | {
|
|---|
| 2906 | tp->index = 0;
|
|---|
| 2907 | RETURN (tp->index);
|
|---|
| 2908 | }
|
|---|
| 2909 | *hll = tp->index = hll_type_index++;
|
|---|
| 2910 | tt_start (0x7f, 0x01); /* List (structure field types) */
|
|---|
| 2911 | patch1 = tt.size;
|
|---|
| 2912 | for (i = 0; i < tp->d.types.count; ++i)
|
|---|
| 2913 | tt_index (0);
|
|---|
| 2914 | tt_end ();
|
|---|
| 2915 | for (i = 0; i < tp->d.types.count; ++i)
|
|---|
| 2916 | {
|
|---|
| 2917 | make_type (tp->d.types.list[i], &ti_1);
|
|---|
| 2918 | buffer_patch_word (&tt, patch1 + 1 + 3*i, ti_1);
|
|---|
| 2919 | }
|
|---|
| 2920 | break;
|
|---|
| 2921 |
|
|---|
| 2922 | case ty_fields:
|
|---|
| 2923 | if (tp->d.fields.count == 0)
|
|---|
| 2924 | {
|
|---|
| 2925 | tp->index = 0;
|
|---|
| 2926 | RETURN (tp->index);
|
|---|
| 2927 | }
|
|---|
| 2928 | tt_start (0x7f, 0x02); /* List (structure field names) */
|
|---|
| 2929 | for (i = 0; i < tp->d.fields.count; ++i)
|
|---|
| 2930 | {
|
|---|
| 2931 | tt_name (tp->d.fields.list[i].name);
|
|---|
| 2932 | tt_unsigned_span (tp->d.fields.list[i].offset);
|
|---|
| 2933 | }
|
|---|
| 2934 | tt_end ();
|
|---|
| 2935 | *hll = tp->index = hll_type_index++;
|
|---|
| 2936 | break;
|
|---|
| 2937 |
|
|---|
| 2938 | case ty_values:
|
|---|
| 2939 | if (tp->d.values.count == 0)
|
|---|
| 2940 | {
|
|---|
| 2941 | tp->index = -1;
|
|---|
| 2942 | RETURN (tp->index);
|
|---|
| 2943 | }
|
|---|
| 2944 | tt_start (0x7f, 0x03); /* Enum values */
|
|---|
| 2945 | for (i = 0; i < tp->d.values.count; ++i)
|
|---|
| 2946 | {
|
|---|
| 2947 | tt_name (tp->d.values.list[i].name);
|
|---|
| 2948 | tt_unsigned_span (tp->d.values.list[i].index);
|
|---|
| 2949 | }
|
|---|
| 2950 | tt_end ();
|
|---|
| 2951 | *hll = tp->index = hll_type_index++;
|
|---|
| 2952 | break;
|
|---|
| 2953 |
|
|---|
| 2954 | case ty_memfunc:
|
|---|
| 2955 | make_type (tp->d.memfunc.type, &ti_1);
|
|---|
| 2956 | qual = 0;
|
|---|
| 2957 | if (tp->d.memfunc.flags & MEMBER_STATIC)
|
|---|
| 2958 | qual |= 0x01;
|
|---|
| 2959 | if (tp->d.memfunc.flags & MEMBER_CONST)
|
|---|
| 2960 | qual |= 0x04;
|
|---|
| 2961 | if (tp->d.memfunc.flags & MEMBER_VOLATILE)
|
|---|
| 2962 | qual |= 0x08;
|
|---|
| 2963 | if (tp->d.memfunc.flags & MEMBER_VIRTUAL)
|
|---|
| 2964 | qual |= 0x10;
|
|---|
| 2965 | tt_start (0x45, qual); /* Member Function */
|
|---|
| 2966 | tt_byte (tp->d.memfunc.flags & MEMBER_VIS); /* Protection */
|
|---|
| 2967 | if (tp->d.memfunc.flags & MEMBER_CTOR)
|
|---|
| 2968 | tt_byte (1); /* Constructor */
|
|---|
| 2969 | else if (tp->d.memfunc.flags & MEMBER_DTOR)
|
|---|
| 2970 | tt_byte (2); /* Destructor */
|
|---|
| 2971 | else
|
|---|
| 2972 | tt_byte (0); /* Regular member function */
|
|---|
| 2973 | tt_word (ti_1); /* Type index of function */
|
|---|
| 2974 | if (tp->d.memfunc.flags & MEMBER_VIRTUAL)
|
|---|
| 2975 | tt_unsigned_span (tp->d.memfunc.offset); /* Index into vtable */
|
|---|
| 2976 | tt_enc (tp->d.memfunc.name); /* Name of the function */
|
|---|
| 2977 | tt_end ();
|
|---|
| 2978 | *hll = tp->index = hll_type_index++;
|
|---|
| 2979 | break;
|
|---|
| 2980 |
|
|---|
| 2981 | case ty_baseclass:
|
|---|
| 2982 | make_type (tp->d.baseclass.type, &ti_1);
|
|---|
| 2983 | qual = 0;
|
|---|
| 2984 | if (tp->d.baseclass.flags & MEMBER_VIRTUAL)
|
|---|
| 2985 | qual |= 0x01;
|
|---|
| 2986 | tt_start (0x41, qual); /* Base Class */
|
|---|
| 2987 | tt_byte (tp->d.baseclass.flags & MEMBER_VIS);
|
|---|
| 2988 | tt_word (ti_1); /* Type */
|
|---|
| 2989 | tt_unsigned_span (tp->d.baseclass.offset);
|
|---|
| 2990 | tt_end ();
|
|---|
| 2991 | *hll = tp->index = hll_type_index++;
|
|---|
| 2992 | break;
|
|---|
| 2993 |
|
|---|
| 2994 | default:
|
|---|
| 2995 | error ("make_type: unknown tag %d", tp->tag);
|
|---|
| 2996 | }
|
|---|
| 2997 | }
|
|---|
| 2998 |
|
|---|
| 2999 |
|
|---|
| 3000 | /* Parse an unnamed stabs type and return an HLL type index for it. */
|
|---|
| 3001 |
|
|---|
| 3002 | static int hll_type (void)
|
|---|
| 3003 | {
|
|---|
| 3004 | struct type *tp;
|
|---|
| 3005 | int ti;
|
|---|
| 3006 |
|
|---|
| 3007 | tp = parse_complete_type (NULL);
|
|---|
| 3008 | make_type (tp, &ti);
|
|---|
| 3009 | return ti;
|
|---|
| 3010 | }
|
|---|
| 3011 |
|
|---|
| 3012 |
|
|---|
| 3013 | /* Return the symbol name of symbol *INDEX, concatenating the names of
|
|---|
| 3014 | successive symbol table entries if necessary. A pointer to the
|
|---|
| 3015 | string is stored to *STR. If symbols are concatenated, *INDEX is
|
|---|
| 3016 | adjusted to refer to the last symbol table entry used, in order to
|
|---|
| 3017 | refer to the next symbol after incrementing by one. If TRUE is
|
|---|
| 3018 | returned, the caller should free the string when it is no longer
|
|---|
| 3019 | needed. If FALSE is returned, the string must not be freed. */
|
|---|
| 3020 |
|
|---|
| 3021 | static int concat_symbols (int *index, const char **str)
|
|---|
| 3022 | {
|
|---|
| 3023 | int i, n, len;
|
|---|
| 3024 | char *new;
|
|---|
| 3025 | const char *p;
|
|---|
| 3026 |
|
|---|
| 3027 | len = 0;
|
|---|
| 3028 | for (i = *index; i < sym_count; ++i)
|
|---|
| 3029 | {
|
|---|
| 3030 | p = str_ptr + sym_ptr[i].n_un.n_strx;
|
|---|
| 3031 | n = strlen (p);
|
|---|
| 3032 | if (n > 0 && p[n-1] == '\\')
|
|---|
| 3033 | len += n - 1;
|
|---|
| 3034 | else
|
|---|
| 3035 | {
|
|---|
| 3036 | len += n;
|
|---|
| 3037 | break;
|
|---|
| 3038 | }
|
|---|
| 3039 | }
|
|---|
| 3040 | if (i == *index)
|
|---|
| 3041 | {
|
|---|
| 3042 | *str = str_ptr + sym_ptr[i].n_un.n_strx;
|
|---|
| 3043 | return FALSE;
|
|---|
| 3044 | }
|
|---|
| 3045 | else
|
|---|
| 3046 | {
|
|---|
| 3047 | new = xmalloc (len + 1);
|
|---|
| 3048 | *str = new;
|
|---|
| 3049 | for (i = *index; i < sym_count; ++i)
|
|---|
| 3050 | {
|
|---|
| 3051 | p = str_ptr + sym_ptr[i].n_un.n_strx;
|
|---|
| 3052 | n = strlen (p);
|
|---|
| 3053 | if (n > 0 && p[n-1] == '\\')
|
|---|
| 3054 | {
|
|---|
| 3055 | memcpy (new, p, n - 1);
|
|---|
| 3056 | new += n - 1;
|
|---|
| 3057 | }
|
|---|
| 3058 | else
|
|---|
| 3059 | {
|
|---|
| 3060 | memcpy (new, p, n);
|
|---|
| 3061 | new += n;
|
|---|
| 3062 | break;
|
|---|
| 3063 | }
|
|---|
| 3064 | }
|
|---|
| 3065 | *new = 0;
|
|---|
| 3066 | *index = i;
|
|---|
| 3067 | return TRUE;
|
|---|
| 3068 | }
|
|---|
| 3069 | }
|
|---|
| 3070 |
|
|---|
| 3071 |
|
|---|
| 3072 | /* Parse a stabs type definition and store the internal representation
|
|---|
| 3073 | of that type. The sym_ptr index is passed in INDEX. As we might
|
|---|
| 3074 | have to concatenate successive symbol table entries, *INDEX is
|
|---|
| 3075 | updated to refer to the next symbol. */
|
|---|
| 3076 |
|
|---|
| 3077 | static void parse_typedef (int *index)
|
|---|
| 3078 | {
|
|---|
| 3079 | char *name;
|
|---|
| 3080 | const char *str, *p;
|
|---|
| 3081 | struct type *t;
|
|---|
| 3082 | int n, alloc_flag;
|
|---|
| 3083 |
|
|---|
| 3084 | alloc_flag = concat_symbols (index, &str);
|
|---|
| 3085 | parse_start = str;
|
|---|
| 3086 | parse_pindex = index;
|
|---|
| 3087 | p = nextcolon (str);
|
|---|
| 3088 | if (p != NULL)
|
|---|
| 3089 | {
|
|---|
| 3090 | n = p - str;
|
|---|
| 3091 | name = alloca (n + 1);
|
|---|
| 3092 | memcpy (name, str, n);
|
|---|
| 3093 | name[n] = 0;
|
|---|
| 3094 | #if defined (HLL_DEBUG)
|
|---|
| 3095 | printf ("LSYM/LCSYM/GSYM/PSYM/RSYM/STSYM/FUN %s\n", str);
|
|---|
| 3096 | #endif
|
|---|
| 3097 | parse_ptr = p + 1;
|
|---|
| 3098 | switch (*parse_ptr)
|
|---|
| 3099 | {
|
|---|
| 3100 | case 'f':
|
|---|
| 3101 | case 'F':
|
|---|
| 3102 | ++parse_ptr;
|
|---|
| 3103 | /* Note: don't call parse_complete_type() as there's a comma
|
|---|
| 3104 | at the end for nested functions. */
|
|---|
| 3105 | t = parse_type (NULL);
|
|---|
| 3106 | break;
|
|---|
| 3107 |
|
|---|
| 3108 | case 't':
|
|---|
| 3109 | case 'T':
|
|---|
| 3110 | ++parse_ptr;
|
|---|
| 3111 | if (*parse_ptr == 't')
|
|---|
| 3112 | ++parse_ptr; /* synonymous type */
|
|---|
| 3113 | t = parse_complete_type (name);
|
|---|
| 3114 | #if defined (HLL_DEBUG)
|
|---|
| 3115 | printf (" type: ");
|
|---|
| 3116 | show_type (t);
|
|---|
| 3117 | printf ("\n");
|
|---|
| 3118 | #endif
|
|---|
| 3119 | break;
|
|---|
| 3120 |
|
|---|
| 3121 | case 'p':
|
|---|
| 3122 | case 'r':
|
|---|
| 3123 | case 'G':
|
|---|
| 3124 | case 'S':
|
|---|
| 3125 | case 'V':
|
|---|
| 3126 | ++parse_ptr;
|
|---|
| 3127 | t = parse_complete_type (name);
|
|---|
| 3128 | #if defined (HLL_DEBUG)
|
|---|
| 3129 | printf (" type: ");
|
|---|
| 3130 | show_type (t);
|
|---|
| 3131 | printf ("\n");
|
|---|
| 3132 | #endif
|
|---|
| 3133 | break;
|
|---|
| 3134 |
|
|---|
| 3135 | case '0': case '1': case '2': case '3': case '4':
|
|---|
| 3136 | case '5': case '6': case '7': case '8': case '9':
|
|---|
| 3137 | t = parse_complete_type (name);
|
|---|
| 3138 | #if defined (HLL_DEBUG)
|
|---|
| 3139 | printf (" type: ");
|
|---|
| 3140 | show_type (t);
|
|---|
| 3141 | printf ("\n");
|
|---|
| 3142 | #endif
|
|---|
| 3143 | break;
|
|---|
| 3144 | }
|
|---|
| 3145 | }
|
|---|
| 3146 | if (alloc_flag)
|
|---|
| 3147 | free ((void *)str); /* remove const attribute */
|
|---|
| 3148 | }
|
|---|
| 3149 |
|
|---|
| 3150 |
|
|---|
| 3151 | /* Write a `begin' subrecord to the SST. The block begins at ADDR in
|
|---|
| 3152 | the text segment. */
|
|---|
| 3153 |
|
|---|
| 3154 | static size_t hll_begin (dword addr)
|
|---|
| 3155 | {
|
|---|
| 3156 | size_t ptr;
|
|---|
| 3157 | struct relocation_info r;
|
|---|
| 3158 |
|
|---|
| 3159 | sst_start (SST_begin);
|
|---|
| 3160 | r.r_address = sst.size;
|
|---|
| 3161 | ptr = sst.size;
|
|---|
| 3162 | buffer_dword (&sst, addr); /* Segment offset */
|
|---|
| 3163 | buffer_dword (&sst, 0); /* Length of block -- patched later */
|
|---|
| 3164 | #if 1
|
|---|
| 3165 | buffer_nstr (&sst, ""); /* Name of block (optional) */
|
|---|
| 3166 | #endif
|
|---|
| 3167 | sst_end ();
|
|---|
| 3168 |
|
|---|
| 3169 | r.r_extern = 0;
|
|---|
| 3170 | r.r_length = 2;
|
|---|
| 3171 | r.r_symbolnum = N_TEXT;
|
|---|
| 3172 | r.r_pcrel = 0;
|
|---|
| 3173 | r.r_pad = 0;
|
|---|
| 3174 | buffer_mem (&sst_reloc, &r, sizeof (r));
|
|---|
| 3175 | return ptr;
|
|---|
| 3176 | }
|
|---|
| 3177 |
|
|---|
| 3178 |
|
|---|
| 3179 | /* Start of a block. Write a `begin' subrecord to the SST. The block
|
|---|
| 3180 | begins at ADDR in the text segment. Push the block onto the block
|
|---|
| 3181 | stack. */
|
|---|
| 3182 |
|
|---|
| 3183 | static void block_begin (dword addr)
|
|---|
| 3184 | {
|
|---|
| 3185 | size_t ptr;
|
|---|
| 3186 |
|
|---|
| 3187 | ptr = hll_begin (addr);
|
|---|
| 3188 | grow_by (&block_grow, 1);
|
|---|
| 3189 | block_stack[block_grow.count].patch_ptr = ptr;
|
|---|
| 3190 | block_stack[block_grow.count].addr = addr;
|
|---|
| 3191 | ++block_grow.count;
|
|---|
| 3192 | }
|
|---|
| 3193 |
|
|---|
| 3194 |
|
|---|
| 3195 | /* Write an `end' subrecord to the SST. PATCH_PTR is the sst index of
|
|---|
| 3196 | the `begin' subrecord for this block. Add ADD_START to the start
|
|---|
| 3197 | address of the block and set the length of the block to LENGTH, in
|
|---|
| 3198 | bytes. */
|
|---|
| 3199 |
|
|---|
| 3200 | static void hll_end (size_t patch_ptr, int add_start, size_t length)
|
|---|
| 3201 | {
|
|---|
| 3202 | *(dword *)(sst.buf+patch_ptr+0) += add_start;
|
|---|
| 3203 | *(dword *)(sst.buf+patch_ptr+4) = length;
|
|---|
| 3204 | sst_start (SST_end);
|
|---|
| 3205 | sst_end ();
|
|---|
| 3206 | }
|
|---|
| 3207 |
|
|---|
| 3208 |
|
|---|
| 3209 | /* Return TRUE iff symbol table entry S defines a function. */
|
|---|
| 3210 |
|
|---|
| 3211 | static int is_fun (const struct nlist *s)
|
|---|
| 3212 | {
|
|---|
| 3213 | const char *p;
|
|---|
| 3214 |
|
|---|
| 3215 | if (s->n_type != N_FUN)
|
|---|
| 3216 | return FALSE;
|
|---|
| 3217 | p = nextcolon (str_ptr + s->n_un.n_strx);
|
|---|
| 3218 | if (p == NULL)
|
|---|
| 3219 | return FALSE;
|
|---|
| 3220 | return (p[1] == 'F' || p[1] == 'f');
|
|---|
| 3221 | }
|
|---|
| 3222 |
|
|---|
| 3223 |
|
|---|
| 3224 | /* Approximate a function prologue length by examining the code. The
|
|---|
| 3225 | function starts at START and ends at END. */
|
|---|
| 3226 |
|
|---|
| 3227 | static int get_prologue_length (dword start, dword end)
|
|---|
| 3228 | {
|
|---|
| 3229 | dword i;
|
|---|
| 3230 |
|
|---|
| 3231 | if (end > text_size)
|
|---|
| 3232 | end = text_size;
|
|---|
| 3233 | i = start;
|
|---|
| 3234 | if (i < end && text_ptr[i] == 0x55) ++i; /* PUSH EBP */
|
|---|
| 3235 | if (i + 1 < end && text_ptr[i+0] == 0x89
|
|---|
| 3236 | && text_ptr[i+1] == 0xe5) /* MOV EBP, ESP */
|
|---|
| 3237 | i += 2;
|
|---|
| 3238 | if (i + 2 < end && text_ptr[i+0] == 0x83
|
|---|
| 3239 | && text_ptr[i+1] == 0xec) /* SUB ESP, n8 */
|
|---|
| 3240 | i += 3;
|
|---|
| 3241 | return i - start;
|
|---|
| 3242 | }
|
|---|
| 3243 |
|
|---|
| 3244 |
|
|---|
| 3245 | /* End of a function reached. Try to find the function length. I is
|
|---|
| 3246 | the sym_ptr index of the current symbol -- we search the symbol
|
|---|
| 3247 | table starting at I to find the next function for estimating the
|
|---|
| 3248 | function length. */
|
|---|
| 3249 |
|
|---|
| 3250 | static void fun_end (int i)
|
|---|
| 3251 | {
|
|---|
| 3252 | int p_len;
|
|---|
| 3253 | dword addr;
|
|---|
| 3254 |
|
|---|
| 3255 | addr = text_size;
|
|---|
| 3256 | while (i < sym_count)
|
|---|
| 3257 | {
|
|---|
| 3258 | if (is_fun (&sym_ptr[i]))
|
|---|
| 3259 | {
|
|---|
| 3260 | addr = sym_ptr[i].n_value;
|
|---|
| 3261 | break;
|
|---|
| 3262 | }
|
|---|
| 3263 | ++i;
|
|---|
| 3264 | }
|
|---|
| 3265 | if (prologue_length != -1)
|
|---|
| 3266 | p_len = prologue_length;
|
|---|
| 3267 | else
|
|---|
| 3268 | p_len = get_prologue_length (proc_start_addr, addr);
|
|---|
| 3269 | *(dword *)(sst.buf+proc_patch_base + 0) = addr - proc_start_addr;
|
|---|
| 3270 | *(word *)(sst.buf+proc_patch_base + 4) = p_len;
|
|---|
| 3271 | *(dword *)(sst.buf+proc_patch_base + 6) = addr - proc_start_addr;
|
|---|
| 3272 | proc_patch_base = 0;
|
|---|
| 3273 | sst_start (SST_end);
|
|---|
| 3274 | sst_end ();
|
|---|
| 3275 | }
|
|---|
| 3276 |
|
|---|
| 3277 |
|
|---|
| 3278 | /* End of a block (N_RBRAC encountered). I is the sym_ptr index of
|
|---|
| 3279 | the N_RBRAC symbol. If we reach the outmost block level, we call
|
|---|
| 3280 | fun_end(). */
|
|---|
| 3281 |
|
|---|
| 3282 | static void block_end (int i)
|
|---|
| 3283 | {
|
|---|
| 3284 | if (block_grow.count == 0)
|
|---|
| 3285 | {
|
|---|
| 3286 | /** @todo fix this - broken after my last change (bird 2003-10-06) */
|
|---|
| 3287 | /* warning ("Invalid N_RBRAC without N_LBRAC"); */
|
|---|
| 3288 | }
|
|---|
| 3289 | else
|
|---|
| 3290 | {
|
|---|
| 3291 | --block_grow.count;
|
|---|
| 3292 | hll_end (block_stack[block_grow.count].patch_ptr, 0,
|
|---|
| 3293 | sym_ptr[i].n_value - block_stack[block_grow.count].addr);
|
|---|
| 3294 | if (block_grow.count == 1) /* we make one extra begin */
|
|---|
| 3295 | {
|
|---|
| 3296 | --block_grow.count;
|
|---|
| 3297 | hll_end (block_stack[block_grow.count].patch_ptr, 0,
|
|---|
| 3298 | sym_ptr[i].n_value - block_stack[block_grow.count].addr);
|
|---|
| 3299 | }
|
|---|
| 3300 | if (block_grow.count == 0 && proc_patch_base != 0)
|
|---|
| 3301 | fun_end (i);
|
|---|
| 3302 | }
|
|---|
| 3303 | }
|
|---|
| 3304 |
|
|---|
| 3305 |
|
|---|
| 3306 | /* Define a function. SYMBOL points to the sym_ptr entry. The
|
|---|
| 3307 | function arguments are taken from the args_list array. Several
|
|---|
| 3308 | fields of the SST entry are filled-in later, when reaching the end
|
|---|
| 3309 | of the function. proc_patch_base is used for remembering the place
|
|---|
| 3310 | where to patch the SST entry. */
|
|---|
| 3311 |
|
|---|
| 3312 | static void define_fun (const struct nlist *symbol)
|
|---|
| 3313 | {
|
|---|
| 3314 | struct type t, *t1, *t2, *t3;
|
|---|
| 3315 | struct relocation_info r;
|
|---|
| 3316 | const char *str, *p, *p2;
|
|---|
| 3317 | const char *name;
|
|---|
| 3318 | int n, /* size of name. */
|
|---|
| 3319 | ti,
|
|---|
| 3320 | ticlass;
|
|---|
| 3321 |
|
|---|
| 3322 | str = str_ptr + symbol->n_un.n_strx;
|
|---|
| 3323 | p = nextcolon (str);
|
|---|
| 3324 | if (p == NULL)
|
|---|
| 3325 | abort ();
|
|---|
| 3326 | n = p - str;
|
|---|
| 3327 |
|
|---|
| 3328 | /** @todo name demangling */
|
|---|
| 3329 | name = strpool_addn (str_pool, str, n);
|
|---|
| 3330 | proc_start_addr = symbol->n_value;
|
|---|
| 3331 |
|
|---|
| 3332 | /* now let's see if there is a memfunc for this name. */
|
|---|
| 3333 | for (t1 = type_head; t1; t1 = t1->next)
|
|---|
| 3334 | if ( t1->tag == ty_memfunc
|
|---|
| 3335 | && t1->d.memfunc.mnglname == name)
|
|---|
| 3336 | break;
|
|---|
| 3337 |
|
|---|
| 3338 | if (t1)
|
|---|
| 3339 | { /* C++ member function */
|
|---|
| 3340 | t2 = t1->d.memfunc.type;
|
|---|
| 3341 | if (t2 && t2->tag == ty_func && t2->d.func.domain)
|
|---|
| 3342 | make_type (t2->d.func.domain, &ticlass);
|
|---|
| 3343 | else
|
|---|
| 3344 | { /* the hard way - search for the freaking string in suitable .stabs.
|
|---|
| 3345 | * I think this is rather slow when done for many members.. :/ */
|
|---|
| 3346 | int i;
|
|---|
| 3347 | for (i = 0, t3 = NULL, ticlass = -1; !t3 && i < sym_count; ++i)
|
|---|
| 3348 | switch (sym_ptr[i].n_type)
|
|---|
| 3349 | {
|
|---|
| 3350 | case N_LSYM:
|
|---|
| 3351 | {
|
|---|
| 3352 | str = str_ptr + sym_ptr[i].n_un.n_strx;
|
|---|
| 3353 | p = nextcolon (str);
|
|---|
| 3354 | if (p && p[1] == 'T' && p[2] == 't')
|
|---|
| 3355 | {
|
|---|
| 3356 | /* Now, there can be several name which NAME is a
|
|---|
| 3357 | * substring in.
|
|---|
| 3358 | */
|
|---|
| 3359 | /** @todo: the string parsing still is a bit spooky. */
|
|---|
| 3360 | for (p2 = p; (p2 = strstr (p2, name)) != NULL; p2 += n)
|
|---|
| 3361 | if (p2[-1] == ':' && p2[n] == ';')
|
|---|
| 3362 | {
|
|---|
| 3363 | int stab = atoi (&p[3]);
|
|---|
| 3364 | t3 = stype_find (stab);
|
|---|
| 3365 | break;
|
|---|
| 3366 | }
|
|---|
| 3367 | }
|
|---|
| 3368 | break;
|
|---|
| 3369 | }
|
|---|
| 3370 | }
|
|---|
| 3371 | if (t3)
|
|---|
| 3372 | make_type (t3, &ticlass);
|
|---|
| 3373 | if (ticlass < 0)
|
|---|
| 3374 | {
|
|---|
| 3375 | warning (" Can't figure out which class method '%s' is a member of!", name);
|
|---|
| 3376 | ticlass = 0;
|
|---|
| 3377 | }
|
|---|
| 3378 | }
|
|---|
| 3379 |
|
|---|
| 3380 | make_type (t1, &ti);
|
|---|
| 3381 | sst_start (SST_memfunc);
|
|---|
| 3382 | r.r_address = sst.size;
|
|---|
| 3383 | buffer_dword (&sst, symbol->n_value); /* Segment offset */
|
|---|
| 3384 | buffer_word (&sst, ti); /* Type index */
|
|---|
| 3385 | proc_patch_base = sst.size;
|
|---|
| 3386 | buffer_dword (&sst, 0); /* Length of proc */
|
|---|
| 3387 | buffer_word (&sst, 0); /* Length of prologue */
|
|---|
| 3388 | buffer_dword (&sst, 0); /* Length of prologue and body */
|
|---|
| 3389 | buffer_word (&sst, ticlass); /* Class type (for member functions) */
|
|---|
| 3390 | buffer_byte (&sst, 8); /* 32-bit near */
|
|---|
| 3391 | buffer_enc (&sst, name); /* Proc name */
|
|---|
| 3392 | sst_end ();
|
|---|
| 3393 | }
|
|---|
| 3394 | else
|
|---|
| 3395 | {
|
|---|
| 3396 | if (args_grow.count == 0)
|
|---|
| 3397 | t1 = NULL;
|
|---|
| 3398 | else
|
|---|
| 3399 | {
|
|---|
| 3400 | t.tag = ty_args;
|
|---|
| 3401 | t.index = -1;
|
|---|
| 3402 | t.d.args.count = args_grow.count;
|
|---|
| 3403 | t.d.args.list = xmalloc (args_grow.count * sizeof (*args_list));
|
|---|
| 3404 | memcpy (t.d.args.list, args_list, args_grow.count * sizeof (*args_list));
|
|---|
| 3405 | t1 = type_add (&t);
|
|---|
| 3406 | free (t.d.args.list);
|
|---|
| 3407 | }
|
|---|
| 3408 | last_fun_type.d.func.args = t1;
|
|---|
| 3409 | last_fun_type.d.func.arg_count = args_grow.count;
|
|---|
| 3410 | t2 = type_add (&last_fun_type);
|
|---|
| 3411 | make_type (t2, &ti);
|
|---|
| 3412 |
|
|---|
| 3413 | sst_start (cplusplus_flag || n > 255 ? SST_CPPproc : SST_proc);
|
|---|
| 3414 | r.r_address = sst.size;
|
|---|
| 3415 | buffer_dword (&sst, symbol->n_value); /* Segment offset */
|
|---|
| 3416 | buffer_word (&sst, ti); /* Type index */
|
|---|
| 3417 | proc_patch_base = sst.size;
|
|---|
| 3418 | buffer_dword (&sst, 0); /* Length of proc */
|
|---|
| 3419 | buffer_word (&sst, 0); /* Length of prologue */
|
|---|
| 3420 | buffer_dword (&sst, 0); /* Length of prologue and body */
|
|---|
| 3421 | buffer_word (&sst, 0); /* Class type (for member functions) */
|
|---|
| 3422 | buffer_byte (&sst, 8); /* 32-bit near */
|
|---|
| 3423 | if (cplusplus_flag || n > 255)
|
|---|
| 3424 | buffer_enc (&sst, name); /* Proc name */
|
|---|
| 3425 | else
|
|---|
| 3426 | buffer_nstr (&sst, name); /* Proc name */
|
|---|
| 3427 | sst_end ();
|
|---|
| 3428 | }
|
|---|
| 3429 | r.r_extern = 0;
|
|---|
| 3430 | r.r_length = 2;
|
|---|
| 3431 | r.r_symbolnum = N_TEXT;
|
|---|
| 3432 | r.r_pcrel = 0;
|
|---|
| 3433 | r.r_pad = 0;
|
|---|
| 3434 | buffer_mem (&sst_reloc, &r, sizeof (r));
|
|---|
| 3435 | set_hll_type (symbol - sym_ptr, ti);
|
|---|
| 3436 | }
|
|---|
| 3437 |
|
|---|
| 3438 |
|
|---|
| 3439 | /* Locate the next N_LBRAC starting at symbol I. If found, set
|
|---|
| 3440 | lbrac_index to the index of N_LBRAC and start a new block. If
|
|---|
| 3441 | there is no N_LBRAC, set lbrac_index to -1. */
|
|---|
| 3442 |
|
|---|
| 3443 | static void next_lbrac (int i)
|
|---|
| 3444 | {
|
|---|
| 3445 | lbrac_index = -1;
|
|---|
| 3446 | for (; i < sym_count; ++i)
|
|---|
| 3447 | if (sym_ptr[i].n_type == N_RBRAC || is_fun (&sym_ptr[i]))
|
|---|
| 3448 | return;
|
|---|
| 3449 | else if (sym_ptr[i].n_type == N_LBRAC)
|
|---|
| 3450 | {
|
|---|
| 3451 | lbrac_index = i;
|
|---|
| 3452 | block_begin (sym_ptr[i].n_value);
|
|---|
| 3453 | return;
|
|---|
| 3454 | }
|
|---|
| 3455 | }
|
|---|
| 3456 |
|
|---|
| 3457 |
|
|---|
| 3458 | /* Parse a stabs symbol. The sym_ptr index is passed in INDEX. As we
|
|---|
| 3459 | might have to concatenate successive symbol table entries, *INDEX
|
|---|
| 3460 | is updated to refer to the next symbol. WHERE is the segment where
|
|---|
| 3461 | the symbol is defined (N_DATA, for instance). If WHERE is -1,
|
|---|
| 3462 | there is no segment. MSG is used for warning messages. This
|
|---|
| 3463 | function is called recursively for static functions (F) There's up
|
|---|
| 3464 | to one level of recursion. The arguments of a function are read
|
|---|
| 3465 | twice: If FLAG is TRUE, we turn the arguments into local symbols;
|
|---|
| 3466 | if FLAG is FALSE, we put arguments into the args_list array. */
|
|---|
| 3467 |
|
|---|
| 3468 | static void parse_symbol (int *index, int where, const char *msg, int flag)
|
|---|
| 3469 | {
|
|---|
| 3470 | char *name;
|
|---|
| 3471 | const char *str, *p;
|
|---|
| 3472 | const struct nlist *symbol;
|
|---|
| 3473 | struct type *t1;
|
|---|
| 3474 | int i, n, ti, alloc_flag;
|
|---|
| 3475 |
|
|---|
| 3476 | symbol = &sym_ptr[*index];
|
|---|
| 3477 | alloc_flag = concat_symbols (index, &str);
|
|---|
| 3478 | parse_start = str;
|
|---|
| 3479 | parse_pindex = index;
|
|---|
| 3480 | p = nextcolon (str);
|
|---|
| 3481 | if (p != NULL)
|
|---|
| 3482 | {
|
|---|
| 3483 | n = p - str;
|
|---|
| 3484 | name = alloca (n + 1);
|
|---|
| 3485 | memcpy (name, str, n);
|
|---|
| 3486 | name[n] = 0;
|
|---|
| 3487 | #if defined (HLL_DEBUG)
|
|---|
| 3488 | printf ("%s %s\n", msg, str);
|
|---|
| 3489 | #endif
|
|---|
| 3490 |
|
|---|
| 3491 | parse_ptr = p + 1;
|
|---|
| 3492 | switch (*parse_ptr)
|
|---|
| 3493 | {
|
|---|
| 3494 | case 'G':
|
|---|
| 3495 | /* Static storage, global scope */
|
|---|
| 3496 | {
|
|---|
| 3497 | const struct nlist *sym2 = NULL;
|
|---|
| 3498 | ++parse_ptr;
|
|---|
| 3499 | ti = hll_type ();
|
|---|
| 3500 | #if defined (HLL_DEBUG)
|
|---|
| 3501 | printf (" type=%#x\n", ti);
|
|---|
| 3502 | #endif
|
|---|
| 3503 |
|
|---|
| 3504 | /* Check for a ugly hack in dbxout.c which allow us to resolve
|
|---|
| 3505 | communal and global variables more accuratly. The n_value is -12357
|
|---|
| 3506 | and the previous entry is 0xfe. What the previous entry contains
|
|---|
| 3507 | is the assembly name of the symbol.
|
|---|
| 3508 |
|
|---|
| 3509 | Another part of that hack is that n_value is contains the
|
|---|
| 3510 | symbol value so we don't need to look up the symbol for that
|
|---|
| 3511 | reason (but as it turns out we have to look it up to see where
|
|---|
| 3512 | it is in most cases, bah). */
|
|---|
| 3513 | if ( symbol->n_value == -12357
|
|---|
| 3514 | && *index >= 1
|
|---|
| 3515 | && symbol[-1].n_type == 0xfe)
|
|---|
| 3516 | {
|
|---|
| 3517 | sym2 = find_symbol_ex (symbol[-1].n_un.n_strx + str_ptr, *index - 1, 1);
|
|---|
| 3518 | if (!sym2)
|
|---|
| 3519 | {
|
|---|
| 3520 | warning ("Cannot find address of communal/external variable %s", name);
|
|---|
| 3521 | return;
|
|---|
| 3522 | }
|
|---|
| 3523 | }
|
|---|
| 3524 | else if (where == -1)
|
|---|
| 3525 | { /* This is not very nice, we have to look up the symbol
|
|---|
| 3526 | like we used to do in order to the the segment right.
|
|---|
| 3527 | Should probably just use the external/communal hack above
|
|---|
| 3528 | for everything or change the n_type of the 'G' stab... However,
|
|---|
| 3529 | this will work for most cases and it will be compatible with
|
|---|
| 3530 | the unmodified dbxout.c code. */
|
|---|
| 3531 | if (symbol->n_type == N_FUN) /* in case GCC change... */
|
|---|
| 3532 | where = N_TEXT;
|
|---|
| 3533 | else
|
|---|
| 3534 | {
|
|---|
| 3535 | size_t cch = strlen (name);
|
|---|
| 3536 | char *psz = alloca (cch + 2);
|
|---|
| 3537 | *psz = '_';
|
|---|
| 3538 | memcpy (psz + 1, name, cch + 1);
|
|---|
| 3539 | sym2 = find_symbol (psz);
|
|---|
| 3540 | if (!sym2)
|
|---|
| 3541 | sym2 = find_symbol (psz + 1);
|
|---|
| 3542 | where = N_DATA;
|
|---|
| 3543 | }
|
|---|
| 3544 | }
|
|---|
| 3545 | /* if we're lucky we've got a symbol... */
|
|---|
| 3546 | if (sym2)
|
|---|
| 3547 | {
|
|---|
| 3548 | if (sym2->n_type == N_EXT)
|
|---|
| 3549 | sst_static (name, 0, ti, sym2 - sym_ptr, 1, sym2);
|
|---|
| 3550 | else
|
|---|
| 3551 | sst_static (name, sym2->n_value, ti, sym2->n_type, 0, sym2);
|
|---|
| 3552 | }
|
|---|
| 3553 | else
|
|---|
| 3554 | sst_static (name, symbol->n_value, ti, where, 0, NULL);
|
|---|
| 3555 | break;
|
|---|
| 3556 | }
|
|---|
| 3557 |
|
|---|
| 3558 | case 'S':
|
|---|
| 3559 | case 'V':
|
|---|
| 3560 |
|
|---|
| 3561 | /* S = static storage, file scope,
|
|---|
| 3562 | V = static storage, local scope */
|
|---|
| 3563 |
|
|---|
| 3564 | if (where == -1)
|
|---|
| 3565 | {
|
|---|
| 3566 | warning ("Cannot use symbol type %c with N_%s", *parse_ptr, msg);
|
|---|
| 3567 | return;
|
|---|
| 3568 | }
|
|---|
| 3569 | ++parse_ptr;
|
|---|
| 3570 | ti = hll_type ();
|
|---|
| 3571 | #if defined (HLL_DEBUG)
|
|---|
| 3572 | printf (" type=%#x\n", ti);
|
|---|
| 3573 | #endif
|
|---|
| 3574 | sst_static (name, symbol->n_value, ti, where, 0, NULL);
|
|---|
| 3575 | break;
|
|---|
| 3576 |
|
|---|
| 3577 | case 'p':
|
|---|
| 3578 |
|
|---|
| 3579 | /* Function argument. */
|
|---|
| 3580 |
|
|---|
| 3581 | if (where != -1)
|
|---|
| 3582 | {
|
|---|
| 3583 | warning ("Cannot use argument symbol with N_%s", msg);
|
|---|
| 3584 | return;
|
|---|
| 3585 | }
|
|---|
| 3586 | ++parse_ptr;
|
|---|
| 3587 | if (flag)
|
|---|
| 3588 | {
|
|---|
| 3589 | ti = hll_type ();
|
|---|
| 3590 | #if defined (HLL_DEBUG)
|
|---|
| 3591 | printf (" type=%#x\n", ti);
|
|---|
| 3592 | #endif
|
|---|
| 3593 | sst_start (SST_auto);
|
|---|
| 3594 | buffer_dword (&sst, symbol->n_value);/* Offset into stk frame */
|
|---|
| 3595 | buffer_word (&sst, ti); /* Type index */
|
|---|
| 3596 | buffer_nstr (&sst, name); /* Symbol name */
|
|---|
| 3597 | sst_end ();
|
|---|
| 3598 | }
|
|---|
| 3599 | else
|
|---|
| 3600 | {
|
|---|
| 3601 | t1 = parse_complete_type (NULL);
|
|---|
| 3602 | grow_by (&args_grow, 1);
|
|---|
| 3603 | args_list[args_grow.count++] = t1;
|
|---|
| 3604 | }
|
|---|
| 3605 | break;
|
|---|
| 3606 |
|
|---|
| 3607 | case 'r':
|
|---|
| 3608 |
|
|---|
| 3609 | /* Register variable. */
|
|---|
| 3610 |
|
|---|
| 3611 | if (where != -1)
|
|---|
| 3612 | {
|
|---|
| 3613 | warning ("Cannot use register symbol with N_%s", msg);
|
|---|
| 3614 | return;
|
|---|
| 3615 | }
|
|---|
| 3616 | ++parse_ptr;
|
|---|
| 3617 | ti = hll_type ();
|
|---|
| 3618 | switch (symbol->n_value)
|
|---|
| 3619 | {
|
|---|
| 3620 | case 0: /* EAX */
|
|---|
| 3621 | i = 0x10;
|
|---|
| 3622 | break;
|
|---|
| 3623 | case 1: /* ECX */
|
|---|
| 3624 | i = 0x11;
|
|---|
| 3625 | break;
|
|---|
| 3626 | case 2: /* EDX */
|
|---|
| 3627 | i = 0x12;
|
|---|
| 3628 | break;
|
|---|
| 3629 | case 3: /* EBX */
|
|---|
| 3630 | i = 0x13;
|
|---|
| 3631 | break;
|
|---|
| 3632 | case 4: /* ESP */
|
|---|
| 3633 | i = 0x14;
|
|---|
| 3634 | break;
|
|---|
| 3635 | case 5: /* EBP */
|
|---|
| 3636 | i = 0x15;
|
|---|
| 3637 | break;
|
|---|
| 3638 | case 6: /* ESI */
|
|---|
| 3639 | i = 0x16;
|
|---|
| 3640 | break;
|
|---|
| 3641 | case 7: /* EDI */
|
|---|
| 3642 | i = 0x17;
|
|---|
| 3643 | break;
|
|---|
| 3644 | case 12: /* ST(0) */
|
|---|
| 3645 | i = 0x80;
|
|---|
| 3646 | break;
|
|---|
| 3647 | case 13: /* ST(1) */
|
|---|
| 3648 | i = 0x81;
|
|---|
| 3649 | break;
|
|---|
| 3650 | case 14: /* ST(2) */
|
|---|
| 3651 | i = 0x82;
|
|---|
| 3652 | break;
|
|---|
| 3653 | case 15: /* ST(3) */
|
|---|
| 3654 | i = 0x83;
|
|---|
| 3655 | break;
|
|---|
| 3656 | case 16: /* ST(4) */
|
|---|
| 3657 | i = 0x84;
|
|---|
| 3658 | break;
|
|---|
| 3659 | case 17: /* ST(5) */
|
|---|
| 3660 | i = 0x85;
|
|---|
| 3661 | break;
|
|---|
| 3662 | case 18: /* ST(6) */
|
|---|
| 3663 | i = 0x86;
|
|---|
| 3664 | break;
|
|---|
| 3665 | case 19: /* ST(7) */
|
|---|
| 3666 | i = 0x87;
|
|---|
| 3667 | break;
|
|---|
| 3668 | default:
|
|---|
| 3669 | warning ("unknown register %lu", symbol->n_value);
|
|---|
| 3670 | return;
|
|---|
| 3671 | }
|
|---|
| 3672 | sst_start (SST_reg); /* Register variable */
|
|---|
| 3673 | buffer_word (&sst, ti); /* Type index */
|
|---|
| 3674 | buffer_byte (&sst, i); /* Register number */
|
|---|
| 3675 | buffer_nstr (&sst, name); /* Symbol name */
|
|---|
| 3676 | sst_end ();
|
|---|
| 3677 | break;
|
|---|
| 3678 |
|
|---|
| 3679 | case '0': case '1': case '2': case '3': case '4':
|
|---|
| 3680 | case '5': case '6': case '7': case '8': case '9':
|
|---|
| 3681 |
|
|---|
| 3682 | /* Local symbol. */
|
|---|
| 3683 |
|
|---|
| 3684 | if (where != -1)
|
|---|
| 3685 | {
|
|---|
| 3686 | warning ("Cannot use local symbol with N_%s", msg);
|
|---|
| 3687 | return;
|
|---|
| 3688 | }
|
|---|
| 3689 | ti = hll_type ();
|
|---|
| 3690 | #if defined (HLL_DEBUG)
|
|---|
| 3691 | printf (" type=%#x\n", ti);
|
|---|
| 3692 | #endif
|
|---|
| 3693 | sst_start (SST_auto);
|
|---|
| 3694 | buffer_dword (&sst, symbol->n_value); /* Offset into stk frame */
|
|---|
| 3695 | buffer_word (&sst, ti); /* Type index */
|
|---|
| 3696 | buffer_nstr (&sst, name); /* Symbol name */
|
|---|
| 3697 | sst_end ();
|
|---|
| 3698 | break;
|
|---|
| 3699 |
|
|---|
| 3700 | case 'F':
|
|---|
| 3701 | case 'f':
|
|---|
| 3702 |
|
|---|
| 3703 | /* Function. */
|
|---|
| 3704 |
|
|---|
| 3705 | ++parse_ptr;
|
|---|
| 3706 | if (where != N_TEXT)
|
|---|
| 3707 | {
|
|---|
| 3708 | warning ("Cannot use function with N_%s", msg);
|
|---|
| 3709 | return;
|
|---|
| 3710 | }
|
|---|
| 3711 | last_fun_type.tag = ty_func;
|
|---|
| 3712 | last_fun_type.index = -1;
|
|---|
| 3713 | last_fun_type.d.func.domain = NULL;
|
|---|
| 3714 | last_fun_type.d.func.ret = parse_type (NULL);
|
|---|
| 3715 |
|
|---|
| 3716 | /* Don't check for end of string -- parse_ptr points to a
|
|---|
| 3717 | comma for nested functions! */
|
|---|
| 3718 |
|
|---|
| 3719 | last_fun_type.d.func.args = NULL;
|
|---|
| 3720 | last_fun_type.d.func.arg_count = 0;
|
|---|
| 3721 | last_fun_valid = TRUE;
|
|---|
| 3722 | args_grow.count = 0;
|
|---|
| 3723 | last_fun_addr = symbol->n_value;
|
|---|
| 3724 | prologue_length = -1;
|
|---|
| 3725 |
|
|---|
| 3726 | for (i = *index + 1; i < sym_count && sym_ptr[i].n_type == N_PSYM; ++i)
|
|---|
| 3727 | parse_symbol (&i, -1, "PSYM", FALSE);
|
|---|
| 3728 |
|
|---|
| 3729 | define_fun (symbol);
|
|---|
| 3730 |
|
|---|
| 3731 | /* Now look for N_LBRAC */
|
|---|
| 3732 | next_lbrac (i);
|
|---|
| 3733 | if (lbrac_index != -1)
|
|---|
| 3734 | {
|
|---|
| 3735 | if (prologue_length == -1)
|
|---|
| 3736 | prologue_length = sym_ptr[lbrac_index].n_value - last_fun_addr;
|
|---|
| 3737 | }
|
|---|
| 3738 | else
|
|---|
| 3739 | {/* kso #456 2003-06-05: We need a begin to catch the parameters. */
|
|---|
| 3740 | prologue_length = 0;
|
|---|
| 3741 | block_begin (proc_start_addr);
|
|---|
| 3742 | }
|
|---|
| 3743 |
|
|---|
| 3744 | /* Parameters */
|
|---|
| 3745 | while (*index + 1 < sym_count && sym_ptr[*index+1].n_type == N_PSYM)
|
|---|
| 3746 | {
|
|---|
| 3747 | ++(*index);
|
|---|
| 3748 | parse_symbol (index, -1, "PSYM", TRUE);
|
|---|
| 3749 | }
|
|---|
| 3750 |
|
|---|
| 3751 | /* Start another block for the local variables. This is to work
|
|---|
| 3752 | around some missing bracets in stabs and to fix problem with
|
|---|
| 3753 | C++ bool type. */
|
|---|
| 3754 | dword addr = proc_start_addr + prologue_length;
|
|---|
| 3755 | if (lbrac_index >= 0 && sym_ptr[lbrac_index].n_value > addr)
|
|---|
| 3756 | addr = sym_ptr[lbrac_index].n_value;
|
|---|
| 3757 | block_begin (addr);
|
|---|
| 3758 |
|
|---|
| 3759 | /* Local variables (fix for boolparam testcase too). */
|
|---|
| 3760 | while (*index + 1 < sym_count && sym_ptr[*index+1].n_type == N_LSYM)
|
|---|
| 3761 | {
|
|---|
| 3762 | ++(*index);
|
|---|
| 3763 | parse_symbol (index, -1, "LSYM", TRUE);
|
|---|
| 3764 | }
|
|---|
| 3765 |
|
|---|
| 3766 | /* If there's no N_LBRAC, write SST_end now */
|
|---|
| 3767 | if (lbrac_index == -1)
|
|---|
| 3768 | {/* kso #456 2003-06-05: We need a begin to catch the parameters. */
|
|---|
| 3769 | while (block_grow.count > 0)
|
|---|
| 3770 | block_end (*index+1);
|
|---|
| 3771 | }
|
|---|
| 3772 | break;
|
|---|
| 3773 | }
|
|---|
| 3774 | }
|
|---|
| 3775 | if (alloc_flag)
|
|---|
| 3776 | free ((void *)str); /* Remove the const attribute */
|
|---|
| 3777 | }
|
|---|
| 3778 |
|
|---|
| 3779 |
|
|---|
| 3780 | /* Create a type tag for HLL type index INDEX. TYPE is either SST_tag
|
|---|
| 3781 | (for structures and unions) or SST_tag2 (for classes). NAME is
|
|---|
| 3782 | the name of the structure, union or class. */
|
|---|
| 3783 |
|
|---|
| 3784 | static void type_tag (int type, int index, const char *name)
|
|---|
| 3785 | {
|
|---|
| 3786 | if (name != NULL)
|
|---|
| 3787 | {
|
|---|
| 3788 | size_t cch;
|
|---|
| 3789 | if (type == SST_tag2 || (cch = strlen(name)) > 250)
|
|---|
| 3790 | {
|
|---|
| 3791 | sst_start (SST_tag2);
|
|---|
| 3792 | buffer_word (&sst, index);
|
|---|
| 3793 | buffer_enc (&sst, name);
|
|---|
| 3794 | }
|
|---|
| 3795 | else
|
|---|
| 3796 | {
|
|---|
| 3797 | char achName[256];
|
|---|
| 3798 | memcpy (achName, name, cch);
|
|---|
| 3799 | achName[cch] = '\0';
|
|---|
| 3800 |
|
|---|
| 3801 | sst_start (type);
|
|---|
| 3802 | buffer_word (&sst, index);
|
|---|
| 3803 | buffer_nstr (&sst, achName);
|
|---|
| 3804 | }
|
|---|
| 3805 | sst_end ();
|
|---|
| 3806 | }
|
|---|
| 3807 | }
|
|---|
| 3808 |
|
|---|
| 3809 |
|
|---|
| 3810 | /* Write a CuInfo SST entry to tell the debugger what compiler (C or
|
|---|
| 3811 | C++) has been used. */
|
|---|
| 3812 |
|
|---|
| 3813 | static void write_cuinfo (void)
|
|---|
| 3814 | {
|
|---|
| 3815 | struct timestamp ts;
|
|---|
| 3816 | time_t now;
|
|---|
| 3817 | struct tm *tp;
|
|---|
| 3818 | byte lang;
|
|---|
| 3819 |
|
|---|
| 3820 | if (cplusplus_flag)
|
|---|
| 3821 | lang = 0x02; /* C++ */
|
|---|
| 3822 | else
|
|---|
| 3823 | lang = 0x01; /* C */
|
|---|
| 3824 |
|
|---|
| 3825 | time (&now);
|
|---|
| 3826 | tp = localtime (&now);
|
|---|
| 3827 | ts.year = tp->tm_year + 1900;
|
|---|
| 3828 | ts.month = tp->tm_mon + 1;
|
|---|
| 3829 | ts.day = tp->tm_mday;
|
|---|
| 3830 | ts.hours = tp->tm_hour;
|
|---|
| 3831 | ts.minutes = tp->tm_min;
|
|---|
| 3832 | ts.seconds = tp->tm_sec;
|
|---|
| 3833 | ts.hundredths = 0;
|
|---|
| 3834 | sst_start (SST_cuinfo);
|
|---|
| 3835 | buffer_byte (&sst, lang);
|
|---|
| 3836 | buffer_nstr (&sst, " "); /* Compiler options */
|
|---|
| 3837 | buffer_nstr (&sst, __DATE__); /* Compiler date */
|
|---|
| 3838 | buffer_mem (&sst, &ts, sizeof (ts));
|
|---|
| 3839 | sst_end ();
|
|---|
| 3840 | }
|
|---|
| 3841 |
|
|---|
| 3842 |
|
|---|
| 3843 | /* Write a ChangSeg SST entry to define the text segment. */
|
|---|
| 3844 |
|
|---|
| 3845 | static void write_changseg (void)
|
|---|
| 3846 | {
|
|---|
| 3847 | struct relocation_info r;
|
|---|
| 3848 |
|
|---|
| 3849 | sst_start (SST_changseg);
|
|---|
| 3850 | r.r_address = sst.size;
|
|---|
| 3851 | buffer_word (&sst, 0); /* Segment number */
|
|---|
| 3852 | buffer_word (&sst, 0); /* Reserved */
|
|---|
| 3853 | sst_end ();
|
|---|
| 3854 | r.r_extern = 0;
|
|---|
| 3855 | r.r_length = 1;
|
|---|
| 3856 | r.r_symbolnum = N_TEXT;
|
|---|
| 3857 | r.r_pcrel = 0;
|
|---|
| 3858 | r.r_pad = 0;
|
|---|
| 3859 | buffer_mem (&sst_reloc, &r, sizeof (r));
|
|---|
| 3860 | }
|
|---|
| 3861 |
|
|---|
| 3862 |
|
|---|
| 3863 | /* Convert debug information. The data is taken from the symbol and
|
|---|
| 3864 | string tables of the current a.out module. Output is put into the
|
|---|
| 3865 | tt, sst etc. buffers. */
|
|---|
| 3866 |
|
|---|
| 3867 | void convert_debug (void)
|
|---|
| 3868 | {
|
|---|
| 3869 | int i;
|
|---|
| 3870 | struct type *t1, *t2;
|
|---|
| 3871 | #if defined (HLL_DEBUG)
|
|---|
| 3872 | setvbuf(stdout, NULL, _IONBF, 256);
|
|---|
| 3873 | #endif
|
|---|
| 3874 |
|
|---|
| 3875 | str_pool = strpool_init ();
|
|---|
| 3876 | grow_init (&stype_grow, &stype_list, sizeof (*stype_list), 32);
|
|---|
| 3877 | type_head = NULL; hll_type_index = 512;
|
|---|
| 3878 | grow_init (&block_grow, &block_stack, sizeof (*block_stack), 16);
|
|---|
| 3879 | grow_init (&args_grow, &args_list, sizeof (*args_list), 16);
|
|---|
| 3880 | last_fun_valid = FALSE; prologue_length = -1;
|
|---|
| 3881 | unnamed_struct_number = 1;
|
|---|
| 3882 |
|
|---|
| 3883 | /* Check whether converting a translated C++ program. */
|
|---|
| 3884 | #if 1 /* kso #465 2003-06-04: pretend everything is C++, that symbols is no longer present. */
|
|---|
| 3885 | cplusplus_flag = 1;
|
|---|
| 3886 | #else
|
|---|
| 3887 | cplusplus_flag = (find_symbol ("__gnu_compiled_cplusplus") != NULL);
|
|---|
| 3888 | #endif
|
|---|
| 3889 |
|
|---|
| 3890 |
|
|---|
| 3891 | /* Parse the typedefs to avoid forward references. */
|
|---|
| 3892 |
|
|---|
| 3893 | for (i = 0; i < sym_count; ++i)
|
|---|
| 3894 | switch (sym_ptr[i].n_type)
|
|---|
| 3895 | {
|
|---|
| 3896 | case N_LSYM:
|
|---|
| 3897 | case N_LCSYM:
|
|---|
| 3898 | case N_GSYM:
|
|---|
| 3899 | case N_PSYM:
|
|---|
| 3900 | case N_RSYM:
|
|---|
| 3901 | case N_STSYM:
|
|---|
| 3902 | case N_FUN:
|
|---|
| 3903 | parse_typedef (&i);
|
|---|
| 3904 | break;
|
|---|
| 3905 | }
|
|---|
| 3906 |
|
|---|
| 3907 | /* Provide information about the compiler. */
|
|---|
| 3908 |
|
|---|
| 3909 | write_cuinfo ();
|
|---|
| 3910 |
|
|---|
| 3911 | /* Change the default segment. */
|
|---|
| 3912 |
|
|---|
| 3913 | write_changseg ();
|
|---|
| 3914 |
|
|---|
| 3915 | /* Parse the other symbol table entries. */
|
|---|
| 3916 |
|
|---|
| 3917 | lbrac_index = -1; block_grow.count = 0; proc_patch_base = 0;
|
|---|
| 3918 | for (i = 0; i < sym_count; ++i)
|
|---|
| 3919 | switch (sym_ptr[i].n_type)
|
|---|
| 3920 | {
|
|---|
| 3921 | case N_LSYM:
|
|---|
| 3922 | parse_symbol (&i, -1, "LSYM", TRUE);
|
|---|
| 3923 | break;
|
|---|
| 3924 |
|
|---|
| 3925 | case N_GSYM:
|
|---|
| 3926 | parse_symbol (&i, -1, "GSYM", TRUE);
|
|---|
| 3927 | break;
|
|---|
| 3928 |
|
|---|
| 3929 | case N_LCSYM:
|
|---|
| 3930 | parse_symbol (&i, N_BSS, "LCSYM", TRUE);
|
|---|
| 3931 | break;
|
|---|
| 3932 |
|
|---|
| 3933 | case N_STSYM:
|
|---|
| 3934 | parse_symbol (&i, N_DATA, "STSYM", TRUE);
|
|---|
| 3935 | break;
|
|---|
| 3936 |
|
|---|
| 3937 | case N_RSYM:
|
|---|
| 3938 | parse_symbol (&i, -1, "RSYM", TRUE);
|
|---|
| 3939 | break;
|
|---|
| 3940 |
|
|---|
| 3941 | case N_LBRAC:
|
|---|
| 3942 | if (lbrac_index == -1) /* N_LBRAC without local symbols */
|
|---|
| 3943 | block_begin (sym_ptr[i].n_value);
|
|---|
| 3944 | else if (i != lbrac_index)
|
|---|
| 3945 | warning ("Invalid N_LBRAC");
|
|---|
| 3946 | next_lbrac (i + 1);
|
|---|
| 3947 | break;
|
|---|
| 3948 |
|
|---|
| 3949 | case N_RBRAC:
|
|---|
| 3950 | block_end (i);
|
|---|
| 3951 | next_lbrac (i + 1);
|
|---|
| 3952 | break;
|
|---|
| 3953 |
|
|---|
| 3954 | case N_FUN:
|
|---|
| 3955 | parse_symbol (&i, N_TEXT, "FUN", TRUE);
|
|---|
| 3956 | break;
|
|---|
| 3957 | }
|
|---|
| 3958 |
|
|---|
| 3959 | #ifdef HASH_DEBUG
|
|---|
| 3960 | fprintf(stderr, "\n");
|
|---|
| 3961 | for (i = 0; i < TYPE_HASH_MAX; i++)
|
|---|
| 3962 | if (i % 7 == 6)
|
|---|
| 3963 | fprintf(stderr, "%3d: %4d\n", i, ctype_tag[i]);
|
|---|
| 3964 | else
|
|---|
| 3965 | fprintf(stderr, "%3d: %4d ", i, ctype_tag[i]);
|
|---|
| 3966 | fprintf(stderr, "\nctypes=%d\n", ctypes);
|
|---|
| 3967 | for (i = 0; i < TYPE_HASH_MAX; i++)
|
|---|
| 3968 | if (ctype_tag[i] > 1000)
|
|---|
| 3969 | {
|
|---|
| 3970 | int j;
|
|---|
| 3971 | unsigned au[ty_max];
|
|---|
| 3972 | memset(&au[0], 0, sizeof(au));
|
|---|
| 3973 | for (t1 = atype_tag[i]; t1 != NULL; t1 = t1->nexthash)
|
|---|
| 3974 | au[t1->tag]++;
|
|---|
| 3975 |
|
|---|
| 3976 | fprintf(stderr, "\nIndex %d is overpopulated (%d):\n", i, ctype_tag[i]);
|
|---|
| 3977 | for (j = 0; j < 18; j++)
|
|---|
| 3978 | if (j % 7 == 6)
|
|---|
| 3979 | fprintf(stderr, "%2d: %4d\n", j, au[j]);
|
|---|
| 3980 | else
|
|---|
| 3981 | fprintf(stderr, "%2d: %4d ", j, au[j]);
|
|---|
| 3982 | }
|
|---|
| 3983 | #endif
|
|---|
| 3984 |
|
|---|
| 3985 | /* Create tags for structures, unions and classes. */
|
|---|
| 3986 |
|
|---|
| 3987 | for (t1 = type_head; t1 != NULL; t1 = t1->next)
|
|---|
| 3988 | if (t1->index != -1)
|
|---|
| 3989 | switch (t1->tag)
|
|---|
| 3990 | {
|
|---|
| 3991 | case ty_struc:
|
|---|
| 3992 | type_tag (SST_tag, t1->index, t1->d.struc.name);
|
|---|
| 3993 | break;
|
|---|
| 3994 | case ty_class:
|
|---|
| 3995 | type_tag (SST_tag2, t1->index, t1->d.class.name);
|
|---|
| 3996 | break;
|
|---|
| 3997 | case ty_enu:
|
|---|
| 3998 | type_tag (SST_tag, t1->index, t1->d.enu.name);
|
|---|
| 3999 | break;
|
|---|
| 4000 | default:
|
|---|
| 4001 | break;
|
|---|
| 4002 | }
|
|---|
| 4003 |
|
|---|
| 4004 | #ifdef HLL_DEBUG
|
|---|
| 4005 | printf ("Stabs to HLL type mappings: %d/%d\n", stype_grow.count, stype_grow.alloc);
|
|---|
| 4006 | for (i = 0; i < stype_grow.alloc; i++)
|
|---|
| 4007 | if (stype_list[i])
|
|---|
| 4008 | {
|
|---|
| 4009 | printf (" %3d => 0x%03x/%-3d ", i + 1, stype_list[i]->index, stype_list[i]->index);
|
|---|
| 4010 | show_type (stype_list[i]);
|
|---|
| 4011 | printf("\n");
|
|---|
| 4012 | }
|
|---|
| 4013 | #endif
|
|---|
| 4014 |
|
|---|
| 4015 |
|
|---|
| 4016 | /* Deallocate memory. */
|
|---|
| 4017 |
|
|---|
| 4018 | grow_free (&stype_grow);
|
|---|
| 4019 | grow_free (&args_grow);
|
|---|
| 4020 | grow_free (&block_grow);
|
|---|
| 4021 | for (t1 = type_head; t1 != NULL; t1 = t2)
|
|---|
| 4022 | {
|
|---|
| 4023 | t2 = t1->next;
|
|---|
| 4024 | switch (t1->tag)
|
|---|
| 4025 | {
|
|---|
| 4026 | case ty_args:
|
|---|
| 4027 | if (t1->d.args.list != NULL)
|
|---|
| 4028 | free (t1->d.args.list);
|
|---|
| 4029 | break;
|
|---|
| 4030 | case ty_types:
|
|---|
| 4031 | if (t1->d.types.list != NULL)
|
|---|
| 4032 | free (t1->d.types.list);
|
|---|
| 4033 | break;
|
|---|
| 4034 | case ty_fields:
|
|---|
| 4035 | if (t1->d.fields.list != NULL)
|
|---|
| 4036 | free (t1->d.fields.list);
|
|---|
| 4037 | break;
|
|---|
| 4038 | case ty_values:
|
|---|
| 4039 | if (t1->d.values.list != NULL)
|
|---|
| 4040 | free (t1->d.values.list);
|
|---|
| 4041 | break;
|
|---|
| 4042 | default:
|
|---|
| 4043 | break;
|
|---|
| 4044 | }
|
|---|
| 4045 | free (t1);
|
|---|
| 4046 | }
|
|---|
| 4047 | type_head = NULL;
|
|---|
| 4048 | memset (&atype_tag, 0, sizeof(atype_tag));
|
|---|
| 4049 | strpool_free (str_pool);
|
|---|
| 4050 | str_pool = NULL;
|
|---|
| 4051 | }
|
|---|