home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 7 / FreshFishVol7.bin / bbs / gnu / gcc-2.3.3-src.lha / GNU / src / amiga / gcc-2.3.3 / sdbout.c < prev    next >
C/C++ Source or Header  |  1994-02-06  |  41KB  |  1,450 lines

  1. /* Output sdb-format symbol table information from GNU compiler.
  2.    Copyright (C) 1988, 1992 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /*  mike@tredysvr.Tredydev.Unisys.COM says:
  21. I modified the struct.c example and have a nm of a .o resulting from the
  22. AT&T C compiler.  From the example below I would conclude the following:
  23.  
  24. 1. All .defs from structures are emitted as scanned.  The example below
  25.    clearly shows the symbol table entries for BoxRec2 are after the first
  26.    function.
  27.  
  28. 2. All functions and their locals (including statics) are emitted as scanned.
  29.  
  30. 3. All nested unnamed union and structure .defs must be emitted before
  31.    the structure in which they are nested.  The AT&T assembler is a
  32.    one pass beast as far as symbolics are concerned.
  33.  
  34. 4. All structure .defs are emitted before the typedefs that refer to them.
  35.  
  36. 5. All top level static and external variable definitions are moved to the
  37.    end of file with all top level statics occurring first before externs.
  38.  
  39. 6. All undefined references are at the end of the file.
  40. */
  41.  
  42. #include "config.h"
  43.  
  44. #ifdef SDB_DEBUGGING_INFO
  45.  
  46. #include "tree.h"
  47. #include "rtl.h"
  48. #include <stdio.h>
  49. #include "regs.h"
  50. #include "flags.h"
  51. #include "insn-config.h"
  52. #include "reload.h"
  53.  
  54. /* Mips systems use the SDB functions to dump out symbols, but
  55.    do not supply usable syms.h include files.  */
  56. #if defined(USG) && !defined(MIPS) && !defined (hpux)
  57. #include <syms.h>
  58. /* Use T_INT if we don't have T_VOID.  */
  59. #ifndef T_VOID
  60. #define T_VOID T_INT
  61. #endif
  62. #else /* not USG, or MIPS */
  63. #include "gsyms.h"
  64. #endif /* not USG, or MIPS */
  65.  
  66. /* #include <storclass.h>  used to be this instead of syms.h.  */
  67.  
  68. /* 1 if PARM is passed to this function in memory.  */
  69.  
  70. #define PARM_PASSED_IN_MEMORY(PARM) \
  71.  (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
  72.  
  73. /* A C expression for the integer offset value of an automatic variable
  74.    (C_AUTO) having address X (an RTX).  */
  75. #ifndef DEBUGGER_AUTO_OFFSET
  76. #define DEBUGGER_AUTO_OFFSET(X) \
  77.   (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
  78. #endif
  79.  
  80. /* A C expression for the integer offset value of an argument (C_ARG)
  81.    having address X (an RTX).  The nominal offset is OFFSET.  */
  82. #ifndef DEBUGGER_ARG_OFFSET
  83. #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
  84. #endif
  85.  
  86. /* Line number of beginning of current function, minus one.
  87.    Negative means not in a function or not using sdb.  */
  88.  
  89. int sdb_begin_function_line = -1;
  90.  
  91. /* Counter to generate unique "names" for nameless struct members.  */
  92.  
  93. static int unnamed_struct_number = 0;
  94.  
  95. extern FILE *asm_out_file;
  96.  
  97. extern tree current_function_decl;
  98.  
  99. void sdbout_init ();
  100. void sdbout_symbol ();
  101. void sdbout_types();
  102.  
  103. static void sdbout_typedefs ();
  104. static void sdbout_syms ();
  105. static void sdbout_one_type ();
  106. static void sdbout_queue_anonymous_type ();
  107. static void sdbout_dequeue_anonymous_types ();
  108. static int plain_type_1 ();
  109.  
  110. /* Define the default sizes for various types.  */
  111.  
  112. #ifndef CHAR_TYPE_SIZE
  113. #define CHAR_TYPE_SIZE BITS_PER_UNIT
  114. #endif
  115.  
  116. #ifndef SHORT_TYPE_SIZE
  117. #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
  118. #endif
  119.  
  120. #ifndef INT_TYPE_SIZE
  121. #define INT_TYPE_SIZE BITS_PER_WORD
  122. #endif
  123.  
  124. #ifndef LONG_TYPE_SIZE
  125. #define LONG_TYPE_SIZE BITS_PER_WORD
  126. #endif
  127.  
  128. #ifndef LONG_LONG_TYPE_SIZE
  129. #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
  130. #endif
  131.  
  132. #ifndef FLOAT_TYPE_SIZE
  133. #define FLOAT_TYPE_SIZE BITS_PER_WORD
  134. #endif
  135.  
  136. #ifndef DOUBLE_TYPE_SIZE
  137. #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  138. #endif
  139.  
  140. #ifndef LONG_DOUBLE_TYPE_SIZE
  141. #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
  142. #endif
  143.  
  144. /* Random macros describing parts of SDB data.  */
  145.  
  146. /* Put something here if lines get too long */
  147. #define CONTIN
  148.  
  149. /* Default value of delimiter is ";".  */
  150. #ifndef SDB_DELIM
  151. #define SDB_DELIM    ";"
  152. #endif
  153.  
  154. /* Maximum number of dimensions the assembler will allow.  */
  155. #ifndef SDB_MAX_DIM
  156. #define SDB_MAX_DIM 4
  157. #endif
  158.  
  159. #ifndef PUT_SDB_SCL
  160. #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
  161. #endif
  162.  
  163. #ifndef PUT_SDB_INT_VAL
  164. #define PUT_SDB_INT_VAL(a) fprintf (asm_out_file, "\t.val\t%d%s", (a), SDB_DELIM)
  165. #endif
  166.  
  167. #ifndef PUT_SDB_VAL
  168. #define PUT_SDB_VAL(a)                \
  169. ( fputs ("\t.val\t", asm_out_file),        \
  170.   output_addr_const (asm_out_file, (a)),    \
  171.   fprintf (asm_out_file, SDB_DELIM))
  172. #endif
  173.  
  174. #ifndef PUT_SDB_DEF
  175. #define PUT_SDB_DEF(a)                \
  176. do { fprintf (asm_out_file, "\t.def\t");    \
  177.      ASM_OUTPUT_LABELREF (asm_out_file, a);     \
  178.      fprintf (asm_out_file, SDB_DELIM); } while (0)
  179. #endif
  180.  
  181. #ifndef PUT_SDB_PLAIN_DEF
  182. #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
  183. #endif
  184.  
  185. #ifndef PUT_SDB_ENDEF
  186. #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
  187. #endif
  188.  
  189. #ifndef PUT_SDB_TYPE
  190. #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
  191. #endif
  192.  
  193. #ifndef PUT_SDB_SIZE
  194. #define PUT_SDB_SIZE(a) fprintf(asm_out_file, "\t.size\t%d%s", a, SDB_DELIM)
  195. #endif
  196.  
  197. #ifndef PUT_SDB_START_DIM
  198. #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
  199. #endif
  200.  
  201. #ifndef PUT_SDB_NEXT_DIM
  202. #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
  203. #endif
  204.  
  205. #ifndef PUT_SDB_LAST_DIM
  206. #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
  207. #endif
  208.  
  209. #ifndef PUT_SDB_TAG
  210. #define PUT_SDB_TAG(a)                \
  211. do { fprintf (asm_out_file, "\t.tag\t");    \
  212.      ASM_OUTPUT_LABELREF (asm_out_file, a);    \
  213.      fprintf (asm_out_file, SDB_DELIM); } while (0)
  214. #endif
  215.  
  216. #ifndef PUT_SDB_BLOCK_START
  217. #define PUT_SDB_BLOCK_START(LINE)        \
  218.   fprintf (asm_out_file,            \
  219.        "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
  220.        SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
  221. #endif
  222.  
  223. #ifndef PUT_SDB_BLOCK_END
  224. #define PUT_SDB_BLOCK_END(LINE)            \
  225.   fprintf (asm_out_file,            \
  226.        "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n",  \
  227.        SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
  228. #endif
  229.  
  230. #ifndef PUT_SDB_FUNCTION_START
  231. #define PUT_SDB_FUNCTION_START(LINE)        \
  232.   fprintf (asm_out_file,            \
  233.        "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
  234.        SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
  235. #endif
  236.  
  237. #ifndef PUT_SDB_FUNCTION_END
  238. #define PUT_SDB_FUNCTION_END(LINE)        \
  239.   fprintf (asm_out_file,            \
  240.        "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
  241.        SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
  242. #endif
  243.  
  244. #ifndef PUT_SDB_EPILOGUE_END
  245. #define PUT_SDB_EPILOGUE_END(NAME)            \
  246. do { fprintf (asm_out_file, "\t.def\t");        \
  247.      ASM_OUTPUT_LABELREF (asm_out_file, NAME);        \
  248.      fprintf (asm_out_file,                \
  249.           "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",    \
  250.           SDB_DELIM, SDB_DELIM, SDB_DELIM); } while (0)
  251. #endif
  252.  
  253. #ifndef SDB_GENERATE_FAKE
  254. #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
  255.   sprintf ((BUFFER), ".%dfake", (NUMBER));
  256. #endif
  257.  
  258. /* Return the sdb tag identifier string for TYPE
  259.    if TYPE has already been defined; otherwise return a null pointer.   */
  260.  
  261. #define KNOWN_TYPE_TAG(type) (char *)(TYPE_SYMTAB_ADDRESS (type))
  262.  
  263. /* Set the sdb tag identifier string for TYPE to NAME.  */
  264.  
  265. #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
  266.   (TYPE_SYMTAB_ADDRESS (TYPE) = (int)(NAME))
  267.  
  268. /* Return the name (a string) of the struct, union or enum tag
  269.    described by the TREE_LIST node LINK.  This is 0 for an anonymous one.  */
  270.  
  271. #define TAG_NAME(link) \
  272.   (((link) && TREE_PURPOSE ((link)) \
  273.     && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
  274.    ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
  275.  
  276. /* Ensure we don't output a negative line number.  */
  277. #define MAKE_LINE_SAFE(line)  \
  278.   if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1
  279.  
  280. /* Set up for