home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / gnu / g__src3 / sdbout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-23  |  23.4 KB  |  899 lines

  1. /* Output sdb-format symbol table information from GNU compiler.
  2.    Copyright (C) 1988 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 1, 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.  
  21. #include "config.h"
  22.  
  23. #ifdef SDB_DEBUGGING_INFO
  24.  
  25. #include "tree.h"
  26. #include "rtl.h"
  27. #include "c-tree.h"
  28. #include <stdio.h>
  29. #include <syms.h>
  30. /* #include <storclass.h>  used to be this instead of syms.h.  */
  31.  
  32. /* Line number of beginning of current function, minus one.  */
  33.  
  34. int sdb_begin_function_line = 0;
  35.  
  36. /* Counter to generate unique "names" for nameless struct members.  */
  37.  
  38. static int unnamed_struct_number = 0;
  39.  
  40. extern FILE *asm_out_file;
  41.  
  42. extern tree current_function_decl;
  43.  
  44. void sdbout_init ();
  45. void sdbout_symbol ();
  46. void sdbout_tags();
  47. void sdbout_types();
  48.  
  49. static void sdbout_syms ();
  50. static void sdbout_one_type ();
  51. static int plain_type_1 ();
  52.  
  53. /* Random macros describing parts of SDB data.  */
  54.  
  55. /* Put something here if lines get too long */
  56. #define CONTIN
  57.  
  58. #ifndef PUT_SDB_SCL
  59. #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d;", (a))
  60. #endif
  61.  
  62. #ifndef PUT_SDB_INT_VAL
  63. #define PUT_SDB_INT_VAL(a) fprintf (asm_out_file, "\t.val\t%d;", (a))
  64. #endif
  65.  
  66. #ifndef PUT_SDB_VAL
  67. #define PUT_SDB_VAL(a)                \
  68. ( fputs ("\t.val\t", asm_out_file),        \
  69.   output_addr_const (asm_out_file, (a)),    \
  70.   fputc (';', asm_out_file))
  71. #endif
  72.  
  73. #ifndef PUT_SDB_DEF
  74. #define PUT_SDB_DEF(a)                \
  75. do { fprintf (asm_out_file, "\t.def\t");    \
  76.      ASM_OUTPUT_LABELREF (asm_out_file, a);     \
  77.      fprintf (asm_out_file, ";"); } while (0)
  78. #endif
  79.  
  80. #ifndef PUT_SDB_PLAIN_DEF
  81. #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s;",a)
  82. #endif
  83.  
  84. #ifndef PUT_SDB_ENDEF
  85. #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
  86. #endif
  87.  
  88. #ifndef PUT_SDB_TYPE
  89. #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o;", a)
  90. #endif
  91.  
  92. #ifndef PUT_SDB_SIZE
  93. #define PUT_SDB_SIZE(a) fprintf(asm_out_file, "\t.size\t%d;", a)
  94. #endif
  95.  
  96. #ifndef PUT_SDB_DIM
  97. #define PUT_SDB_DIM(a) fprintf(asm_out_file, "\t.dim\t%d;", a)
  98. #endif
  99.  
  100. #ifndef PUT_SDB_TAG
  101. #define PUT_SDB_TAG(a)                \
  102. do { fprintf (asm_out_file, "\t.tag\t");    \
  103.      ASM_OUTPUT_LABELREF (asm_out_file, a);    \
  104.      fprintf (asm_out_file, ";"); } while (0)
  105. #endif
  106.  
  107. #ifndef PUT_SDB_BLOCK_START
  108. #define PUT_SDB_BLOCK_START(LINE)        \
  109.   fprintf (asm_out_file,            \
  110.        "\t.def\t.bb;\t.val\t.;\t.scl\t100;\t.line\t%d;\t.endef\n",    \
  111.        (LINE))
  112. #endif
  113.  
  114. #ifndef PUT_SDB_BLOCK_END
  115. #define PUT_SDB_BLOCK_END(LINE)            \
  116.   fprintf (asm_out_file,            \
  117.        "\t.def\t.eb;.val\t.;\t.scl\t100;\t.line\t%d;\t.endef\n",    \
  118.        (LINE))
  119. #endif
  120.  
  121. #ifndef PUT_SDB_FUNCTION_START
  122. #define PUT_SDB_FUNCTION_START(LINE)        \
  123.   fprintf (asm_out_file,            \
  124.        "\t.def\t.bf;\t.val\t.;\t.scl\t101;\t.line\t%d;\t.endef\n",    \
  125.        (LINE))
  126. #endif
  127.  
  128. #ifndef PUT_SDB_FUNCTION_END
  129. #define PUT_SDB_FUNCTION_END(LINE)        \
  130.   fprintf (asm_out_file,            \
  131.        "\t.def\t.ef;\t.val\t.;\t.scl\t101;\t.line\t%d;\t.endef\n",    \
  132.        (LINE))
  133. #endif
  134.  
  135. #ifndef PUT_SDB_EPILOGUE_END
  136. #define PUT_SDB_EPILOGUE_END(NAME)        \
  137.   fprintf (asm_out_file,            \
  138.        "\t.def\t%s;\t.val\t.;\t.scl\t-1;\t.endef\n",    \
  139.        (NAME))
  140. #endif
  141.  
  142. #ifndef SDB_GENERATE_FAKE
  143. #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
  144.   sprintf ((BUFFER), ".%dfake", (NUMBER));
  145. #endif
  146.  
  147. /* Return the sdb tag identifier string for TYPE
  148.    if TYPE has already been defined; otherwise return a null pointer.   */
  149.   
  150. #define KNOWN_TYPE_TAG(type) (char *)(TYPE_SYMTAB_ADDRESS (type))
  151.  
  152. /* Set the sdb tag identifier string for TYPE to NAME.  */
  153.  
  154. #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
  155.   (TYPE_SYMTAB_ADDRESS (TYPE) = (int)(NAME))
  156.  
  157. /* Return the name (a string) of the struct, union or enum tag
  158.    described by the TREE_LIST node LINK.  This is 0 for an anonymous one.  */
  159.  
  160. #define TAG_NAME(link) \
  161.   (((link) && TREE_PURPOSE ((link)) \
  162.     && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
  163.    ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
  164.  
  165. /* Return the structure-tag name of a structure, etc.  */
  166.  
  167. #define TYPE_TAG_NAME(type) \
  168.   ((TYPE_NAME (type) != 0 && TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) \
  169.    ? IDENTIFIER_POINTER (TYPE_NAME (type)) : 0)
  170.  
  171. /* Tell the assembler the source file name.
  172.    On systems that use SDB, this is done whether or not -g,
  173.    so it is called by ASM_FILE_START.
  174.  
  175.    ASM_FILE is the assembler code output file,
  176.    INPUT_NAME is the name of the main input file.  */
  177.  
  178. void
  179. sdbout_filename (asm_file, input_name)
  180.      FILE *asm_file;
  181.      char *input_name;
  182. {
  183.   int len = strlen (input_name);
  184.   char *na = input_name + len;
  185.  
  186.   /* NA gets INPUT_NAME sans directory names.  */
  187.   while (na > input_name)
  188.     {
  189.       if (na[-1] == '/')
  190.     break;
  191.       na--;
  192.     }
  193.  
  194. #ifdef ASM_OUTPUT_SOURCE_FILENAME
  195.   ASM_OUTPUT_SOURCE_FILENAME (asm_file, na);
  196. #else
  197.   fprintf (asm_file, "\t.file\t\"%s\"\n", na);
  198. #endif
  199. }
  200.  
  201. /* Set up for SDB output at the start of compilation.  */
  202.  
  203. void
  204. sdbout_init ()
  205. {
  206.   /* Output all the initial permanent types.  */
  207.   sdbout_types (nreverse (get_permanent_types ()));
  208. }
  209.  
  210. #if 0
  211.  
  212. /* return the tag identifier for type
  213.  */
  214.  
  215. {
  216. char *
  217. tag_of_ru_type (type,link)
  218.      tree type,link;
  219. {
  220.   if (TYPE_SYMTAB_ADDRESS (type))
  221.     return (char *)TYPE_SYMTAB_ADDRESS (type);
  222.   if (link &&
  223.       TREE_PURPOSE (link)
  224.       && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
  225.     TYPE_SYMTAB_ADDRESS (type) =
  226.       (int)IDENTIFIER_POINTER (TREE_PURPOSE (link));
  227.   else
  228.     return (char *) TYPE_SYMTAB_ADDRESS (type);
  229. }
  230. #endif
  231.  
  232. /* Return a unique string to name an anonymous type.  */
  233.  
  234. static char *
  235. gen_fake_label ()
  236. {
  237.   char label[10];
  238.   char *labelstr;
  239.   SDB_GENERATE_FAKE (label, unnamed_struct_number);
  240.   unnamed_struct_number++;
  241.   labelstr = (char *) permalloc (strlen (label) + 1);
  242.   strcpy (labelstr, label);
  243.   return labelstr;
  244. }
  245.  
  246. /* Return the number which describes TYPE for SDB.
  247.    For pointers, etc., this function is recursive.
  248.    Each record, union or enumeral type must already have had a
  249.    tag number output.  */
  250.  
  251. /* The number is given by d6d5d4d3d2d1bbbb 
  252.    where bbbb is 4 bit basic type, and di indicate  one of notype,ptr,fn,array.
  253.    Thus, char *foo () has bbbb=T_CHAR
  254.               d1=D_FCN
  255.               d2=D_PTR
  256.  N_BTMASK=     017       1111     basic type field.
  257.  N_TSHIFT=       2                derived type shift
  258.  N_BTSHFT=       4                Basic type shift */
  259.  
  260. /* Produce the number that describes a pointer, function or array type.
  261.    PREV is the number describing the target, value or element type.
  262.    DT_type describes how to transform that type.  */
  263. #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
  264.   ((((PREV)&~N_BTMASK)<<N_TSHIFT)|(DT_type<<N_BTSHFT)|(PREV&N_BTMASK))
  265.  
  266. static int
  267. plain_type (type)
  268.      tree type;
  269. {
  270.   int val = plain_type_1 (type);
  271.   if (TREE_CODE (type) == ARRAY_TYPE)
  272.     {
  273.       PUT_SDB_SIZE (int_size_in_bytes (type));
  274.     }
  275.   return val;
  276. }
  277.  
  278. static void
  279. sdbout_record_type_name (type)
  280.      tree type;
  281. {
  282.   char *name;
  283.   if (KNOWN_TYPE_TAG (type))
  284.     return;
  285.   name = TYPE_TAG_NAME (type);
  286.   if (!name || !*name)
  287.     name = gen_fake_label ();
  288.   SET_KNOWN_TYPE_TAG (type, name);
  289. }
  290.  
  291. static int
  292. plain_type_1 (type)
  293.      tree type;
  294. {
  295.   if (type == 0)  
  296.     type = void_type_node;
  297.   if (type == error_mark_node)
  298.     type = integer_type_node;
  299.   switch (TREE_CODE (type))
  300.     {
  301.     case VOID_TYPE:
  302.       return T_INT;
  303.     case INTEGER_TYPE:
  304.       switch (int_size_in_bytes (type))
  305.     {
  306.     case 4:
  307.       return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
  308.     case 1:
  309.       return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
  310.     case 2:
  311.       return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
  312.     default:
  313.       return 0;
  314.     }
  315.     case REAL_TYPE:
  316.       switch (int_size_in_bytes (type))
  317.     {
  318.     case 4:
  319.       return T_FLOAT;
  320.     default:
  321.       return T_DOUBLE;
  322.     }
  323.     case ARRAY_TYPE:
  324.       {
  325.     int m = plain_type (TREE_TYPE (type));
  326.     PUT_SDB_DIM (TYPE_DOMAIN (type)
  327.              ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) + 1
  328.              : 0);
  329.     return PUSH_DERIVED_LEVEL (DT_ARY, m);
  330.       }
  331.     case RECORD_TYPE:
  332.     case UNION_TYPE:
  333.     case ENUMERAL_TYPE:
  334.       {
  335.     char *tag;
  336.     sdbout_record_type_name (type);
  337.     if (TREE_ASM_WRITTEN (type))
  338.       {
  339.         /* Output the referenced structure tag name
  340.            only if the .def has already been output.
  341.            At least on 386, the Unix assembler
  342.            cannot handle forward references to tags.  */
  343.         tag = KNOWN_TYPE_TAG (type);
  344.         PUT_SDB_TAG (tag);
  345.       }
  346.     PUT_SDB_SIZE (int_size_in_bytes (type));
  347.     return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT :
  348.         (TREE_CODE (type) == UNION_TYPE) ? T_UNION :
  349.         T_ENUM);
  350.       }
  351.     case POINTER_TYPE:
  352.       {
  353.     int m = plain_type (TREE_TYPE (type));
  354.     return PUSH_DERIVED_LEVEL (DT_PTR, m);
  355.       }
  356.     case FUNCTION_TYPE:
  357.       {
  358.     int m = plain_type (TREE_TYPE (type));
  359.     return PUSH_DERIVED_LEVEL (DT_FCN, m);
  360.       }
  361.     default:
  362.       return 0;
  363.     }
  364. }
  365.  
  366. /* Output the symbols defined in block number DO_BLOCK.
  367.    Set NEXT_BLOCK_NUMBER to 0 before calling.
  368.  
  369.    This function works by walking the tree structure,
  370.    counting blocks, until it finds the desired block.  */
  371.  
  372. static int do_block = 0;
  373.  
  374. static int next_block_number;
  375.  
  376. static void
  377. sdbout_block (stmt)
  378.      register tree stmt;
  379. {
  380.   while (stmt)
  381.     {
  382.       switch (TREE_CODE (stmt))
  383.     {
  384.     case COMPOUND_STMT:
  385.     case LOOP_STMT:
  386.       sdbout_block (STMT_BODY (stmt));
  387.       break;
  388.  
  389.     case IF_STMT:
  390.       sdbout_block (STMT_THEN (stmt));
  391.       sdbout_block (STMT_ELSE (stmt));
  392.       break;
  393.  
  394.     case LET_STMT:
  395.       /* When we reach the specified block, output its symbols.  */
  396.       if (next_block_number == do_block)
  397.         {
  398.           sdbout_tags (STMT_TYPE_TAGS (stmt));
  399.           sdbout_syms (STMT_VARS (stmt));
  400.         }
  401.  
  402.       /* If we are past the specified block, stop the scan.  */
  403.       if (next_block_number > do_block)
  404.         return;
  405.  
  406.       next_block_number++;
  407.  
  408.       /* Scan the blocks within this block.  */
  409.       sdbout_block (STMT_BODY (stmt));
  410.     }
  411.       stmt = TREE_CHAIN (stmt);
  412.     }
  413. }
  414.  
  415. /* Call sdbout_symbol on each decl in the chain SYMS.  */
  416.  
  417. static void
  418. sdbout_syms (syms)
  419.      tree syms;
  420. {
  421.   while (syms)
  422.     {
  423.       sdbout_symbol (syms, 1);
  424.       syms = TREE_CHAIN (syms);
  425.     }
  426. }
  427.  
  428. /* Output SDB information for a symbol described by DECL.
  429.    LOCAL is nonzero if the symbol is not file-scope.  */
  430.  
  431. void
  432. sdbout_symbol (decl, local)
  433.      tree decl;
  434.      int local;
  435. {
  436.   int letter = 0;
  437.   tree type = TREE_TYPE (decl);
  438.  
  439.   /* If global, first output all types and all
  440.      struct, enum and union tags that have been created
  441.      and not yet output.  */
  442.  
  443.   if (local == 0)
  444.     {
  445.       sdbout_tags (gettags ());
  446.       sdbout_types (nreverse (get_permanent_types ()));
  447.     }
  448.  
  449.   switch (TREE_CODE (decl))
  450.     {
  451.     case CONST_DECL:
  452.       /* Enum values are defined by defining the enum type.  */
  453.       return;
  454.  
  455.     case FUNCTION_DECL:
  456.       if (TREE_EXTERNAL (decl))
  457.     return;
  458.       if (GET_CODE (DECL_RTL (decl)) != MEM
  459.       || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
  460.     return;
  461.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
  462.       PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
  463.       PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
  464.       break;
  465.  
  466.     case TYPE_DECL:
  467.       /* Output typedef name.  */
  468.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
  469.       PUT_SDB_SCL (C_TPDEF);
  470.       break;
  471.       
  472.     case PARM_DECL:
  473.       /* Parm decls go in their own separate chains
  474.      and are output by sdbout_reg_parms and sdbout_parms.  */
  475.       abort ();
  476.  
  477.     case VAR_DECL:
  478.       /* Don't mention a variable that is external.
  479.      Let the file that defines it describe it.  */
  480.       if (TREE_EXTERNAL (decl))
  481.     return;
  482.  
  483.       /* Don't mention a variable at all
  484.      if it was completely optimized into nothingness.  */
  485.       if (GET_CODE (DECL_RTL (decl)) == REG
  486.       && (REGNO (DECL_RTL (decl)) < 0
  487.           || REGNO (DECL_RTL (decl)) >= FIRST_PSEUDO_REGISTER))
  488.     return;
  489.  
  490.       /* Ok, start a symtab entry and output the variable name.  */
  491.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
  492.  
  493.       if (GET_CODE (DECL_RTL (decl)) == MEM
  494.       && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
  495.     {
  496.       if (TREE_PUBLIC (decl))
  497.         {
  498.           PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
  499.               PUT_SDB_SCL (C_EXT);
  500.         }
  501.       else
  502.         {
  503.           PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
  504.               PUT_SDB_SCL (C_STAT);
  505.         }
  506.     }
  507.       else if (GET_CODE (DECL_RTL (decl)) == REG)
  508.     {
  509.       PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (decl))));
  510.       PUT_SDB_SCL (C_REG);
  511.     }
  512.       else if (GET_CODE (DECL_RTL (decl)) == MEM
  513.            && (GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
  514.            || (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG
  515.                && REGNO (XEXP (DECL_RTL (decl), 0)) != FRAME_POINTER_REGNUM)))
  516.     /* If the value is indirect by memory or by a register
  517.        that isn't the frame pointer
  518.        then it means the object is variable-sized and address through
  519.        that register or stack slot.  DBX has no way to represent this
  520.        so all we can do is output the variable as a pointer.  */
  521.     {
  522.       if (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
  523.         {
  524.           PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (decl))));
  525.           PUT_SDB_SCL (C_REG);
  526.         }
  527.       else
  528.         {
  529.           /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
  530.          (CONST_INT...)))).
  531.          We want the value of that CONST_INT.  */
  532.           /* Encore compiler hates a newline in a macro arg, it seems.  */
  533.           PUT_SDB_INT_VAL (INTVAL (XEXP (XEXP (XEXP (DECL_RTL (decl), 0), 0), 1)));
  534.           PUT_SDB_SCL (C_AUTO);
  535.         }
  536.  
  537.       type = build_pointer_type (TREE_TYPE (decl));
  538.     }
  539.       else if (GET_CODE (DECL_RTL (decl)) == MEM
  540.            && GET_CODE (XEXP (DECL_RTL (decl), 0)) == PLUS
  541.            && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == REG
  542.            && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 1)) == CONST_INT)
  543.     {
  544.       /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))).
  545.          We want the value of that CONST_INT.  */
  546.       PUT_SDB_INT_VAL (INTVAL (XEXP (XEXP (DECL_RTL (decl), 0), 1)));
  547.       PUT_SDB_SCL (C_AUTO);
  548.     }
  549.       else
  550.     {
  551.       /* It is something we don't know how to represent for SDB.  */
  552.     }
  553.       break;
  554.     }
  555.   PUT_SDB_TYPE (plain_type (type));
  556.   PUT_SDB_ENDEF;
  557. }
  558.  
  559. /* Given a list of TREE_LIST nodes that point at types,
  560.    output those types for SDB.
  561.    We must check to include those that have been mentioned already with
  562.    only a cross-reference.  */
  563.  
  564. void
  565. sdbout_tags (tags)
  566.      tree tags;
  567. {
  568.   register tree link;
  569.  
  570.   for (link = tags; link; link = TREE_CHAIN (link))
  571.     {
  572.       register tree type = TREE_VALUE (link);
  573.  
  574.       if (TREE_PURPOSE (link) != 0
  575.       && TYPE_SIZE (type) != 0)
  576.     sdbout_one_type (type, TAG_NAME (link));
  577.     }
  578. }
  579.  
  580. /* Given a chain of ..._TYPE nodes, all of which have names,
  581.    output definitions of those names, as typedefs.  */
  582.  
  583. void
  584. sdbout_types (types)
  585.      register tree types;
  586. {
  587.   register tree link;
  588.  
  589.   for (link = types; link; link = TREE_CHAIN (link))
  590.     sdbout_one_type (link, 0);
  591. }
  592.  
  593. static void
  594. sdbout_type (type)
  595.      tree type;
  596. {
  597.   register tree tem;
  598.   if (type == error_mark_node)
  599.     type = integer_type_node;
  600.   PUT_SDB_TYPE (plain_type (type));
  601. }
  602.  
  603. /* Use this to put out the top level defined record and union types
  604.    for later reference.  If this is a struct with a name, then put that
  605.    name out.  Other unnamed structs will have .xxfake labels generated so
  606.    that they may be referred to later.
  607.    The label will be stored in the KNOWN_TYPE_TAG slot of a type.
  608.    It may NOT be called recursively.  */
  609.  
  610. static void
  611. sdbout_one_type (type, name)
  612.      char *name;
  613.      tree type;
  614. {
  615.   text_section ();
  616.   switch (TREE_CODE (type))
  617.     {
  618.     case RECORD_TYPE:
  619.     case UNION_TYPE:
  620.     case ENUMERAL_TYPE:
  621.       /* Don't output a type twice.  */
  622.       if (TREE_ASM_WRITTEN (type))
  623.     return;
  624.  
  625.       TREE_ASM_WRITTEN (type) = 1;
  626.       sdbout_record_type_name (type);
  627.  
  628.       /* Output a structure type.  */
  629.       {
  630.     int size = int_size_in_bytes (type);
  631.     int member_scl;
  632.     tree tem;
  633.  
  634.     PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
  635.  
  636.     switch (TREE_CODE (type))
  637.       {
  638.       case UNION_TYPE:
  639.         PUT_SDB_SCL (C_UNTAG);
  640.         PUT_SDB_TYPE (T_UNION);
  641.         member_scl = C_MOU;
  642.         break;
  643.  
  644.       case RECORD_TYPE:
  645.         PUT_SDB_SCL (C_STRTAG);
  646.         PUT_SDB_TYPE (T_STRUCT);
  647.         member_scl = C_MOS;
  648.         break;
  649.  
  650.       case ENUMERAL_TYPE:
  651.         PUT_SDB_SCL (C_ENTAG);
  652.         PUT_SDB_TYPE (T_ENUM);
  653.         member_scl = C_MOE;
  654.         break;
  655.       }
  656.  
  657.     PUT_SDB_SIZE (size);
  658.     PUT_SDB_ENDEF;
  659.  
  660.     /* output the individual fields */
  661.  
  662.     if (TREE_CODE (type) == ENUMERAL_TYPE)
  663.       for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
  664.         {
  665.           PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
  666.           PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
  667.           PUT_SDB_SCL (C_MOE);
  668.           PUT_SDB_TYPE (T_MOE);
  669.           PUT_SDB_ENDEF;
  670.         }
  671.       
  672.     else            /* record or union type */
  673.       for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
  674.         /* Output the name, type, position (in bits), size (in bits)
  675.            of each field.  */
  676.         /* Omit here the nameless fields that are used to skip bits.  */
  677.         if (DECL_NAME (tem) != 0)
  678.           {
  679.         CONTIN;
  680.         PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (tem)));
  681.         if (TREE_PACKED (tem))
  682.           {
  683.             PUT_SDB_INT_VAL (DECL_OFFSET (tem));
  684.             PUT_SDB_SCL (C_FIELD);
  685.             sdbout_type (TREE_TYPE (tem));
  686.             PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem))
  687.                   * DECL_SIZE_UNIT (tem));
  688.           }
  689.         else
  690.           {
  691.             PUT_SDB_INT_VAL (DECL_OFFSET (tem) / BITS_PER_UNIT);
  692.             PUT_SDB_SCL (member_scl);
  693.             sdbout_type (TREE_TYPE (tem));
  694.           }
  695.         PUT_SDB_ENDEF;
  696.           }
  697.     /* output end of a structure,union, or enumeral definition */
  698.    
  699.     PUT_SDB_PLAIN_DEF ("eos");
  700.     PUT_SDB_INT_VAL (size);
  701.     PUT_SDB_SCL (C_EOS);
  702.     PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
  703.     PUT_SDB_SIZE (size);
  704.     PUT_SDB_ENDEF;
  705.     break;
  706.       }
  707.     }
  708. }
  709.  
  710. /* Output definitions of all parameters, referring when possible to the
  711.    place where the parameters were passed rather than the copies used
  712.    within the function.     This is done as part of starting the function.
  713.    PARMS is a chain of PARM_DECL nodes.  */
  714.  
  715. static void
  716. sdbout_parms (parms1)
  717.      tree parms1;
  718. {
  719.   tree type;
  720.   tree parms;
  721.  
  722.   for (parms = parms1; parms; parms = TREE_CHAIN (parms))
  723.     {
  724.       int current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
  725.  
  726.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (parms)));
  727.       if (GET_CODE (DECL_RTL (parms)) == REG
  728.       && REGNO (DECL_RTL (parms)) >= 0
  729.       && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  730.     type = DECL_ARG_TYPE (parms);
  731.       else
  732.     {
  733.       /* This is the case where the parm is passed as an int or double
  734.          and it is converted to a char, short or float and stored back
  735.          in the parmlist.  In this case, describe the parm
  736.          with the variable's declared type, and adjust the address
  737.          if the least significant bytes (which we are using) are not
  738.          the first ones.  */
  739. #ifdef BYTES_BIG_ENDIAN
  740.       if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  741.         current_sym_value +=
  742.           (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  743.            - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  744. #endif
  745.       if (GET_CODE (DECL_RTL (parms)) == MEM
  746.           && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
  747.           && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
  748.           && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
  749.           == current_sym_value))
  750.         type = TREE_TYPE (parms);
  751.       else
  752.         {
  753.           current_sym_value = DECL_OFFSET (parms) / BITS_PER_UNIT;
  754.           type = DECL_ARG_TYPE (parms);
  755.         }
  756.     }
  757.      
  758.       PUT_SDB_INT_VAL (current_sym_value);
  759.       PUT_SDB_SCL (C_ARG);
  760.       PUT_SDB_TYPE (plain_type (type));
  761.       PUT_SDB_ENDEF;
  762.     }
  763. }
  764.  
  765. /* Output definitions, referring to registers,
  766.    of all the parms in PARMS which are stored in registers during the function.
  767.    PARMS is a chain of PARM_DECL nodes.
  768.    This is done as part of starting the function.  */
  769.  
  770. static void
  771. sdbout_reg_parms (parms)
  772.      tree parms;
  773. {
  774.   while (parms)
  775.     {
  776.       if (GET_CODE (DECL_RTL (parms)) == REG
  777.       && REGNO (DECL_RTL (parms)) >= 0
  778.       && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
  779.     {
  780.       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (parms)));
  781.       PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
  782.         PUT_SDB_SCL (C_REG);
  783.       PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
  784.       PUT_SDB_ENDEF;
  785.     }
  786.       else if (GET_CODE (DECL_RTL (parms)) == MEM
  787.            && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
  788.            && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT)
  789.     {
  790.       int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
  791.       /* A parm declared char is really passed as an int,
  792.          so it occupies the least significant bytes.
  793.          On a big-endian machine those are not the low-numbered ones.  */
  794. #ifdef BYTES_BIG_ENDIAN
  795.       if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
  796.         offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
  797.                - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
  798. #endif
  799.       if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset)
  800.         {
  801.           PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (parms)));          
  802.           PUT_SDB_INT_VAL (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)));
  803.           PUT_SDB_SCL (C_AUTO);
  804.           PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
  805.           PUT_SDB_ENDEF;
  806.         }
  807.     }
  808.       parms = TREE_CHAIN (parms);
  809.     }
  810. }
  811.  
  812. /* Describe the beginning of an internal block within a function.
  813.    Also output descriptions of variables defined in this block.
  814.  
  815.    N is the number of the block, by order of beginning, counting from 1,
  816.    and not counting the outermost (function top-level) block.
  817.    The blocks match the LET_STMTS in DECL_INITIAL (current_function_decl),
  818.    if the count starts at 0 for the outermost one.  */
  819.  
  820. void
  821. sdbout_begin_block (file, line, n)
  822.      FILE *file;
  823.      int line;
  824.      int n;
  825. {
  826.   tree decl = current_function_decl;
  827.   PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
  828.   if (n == 1)
  829.     {
  830.       /* Include the outermost LET_STMT's variables in block 1.  */
  831.       next_block_number = 0;
  832.       do_block = 0;
  833.       sdbout_block (DECL_INITIAL (decl), DECL_ARGUMENTS (decl));
  834.     }
  835.   next_block_number = 0;
  836.   do_block = n;
  837.   sdbout_block (DECL_INITIAL (decl), DECL_ARGUMENTS (decl));
  838. }
  839.  
  840. /* Describe the end line-number of an internal block within a function.  */
  841.      
  842. void
  843. sdbout_end_block (file, line)
  844.      FILE *file;
  845.      int line;
  846. {
  847.   PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
  848. }
  849.  
  850. /* Output sdb info for the current function name.
  851.    Called from assemble_function.  */
  852.  
  853. void
  854. sdbout_mark_begin_function ()
  855. {
  856.   sdbout_symbol (current_function_decl, 0);
  857. }
  858.  
  859. /* Called at beginning of function body (after prologue).
  860.    Record the function's starting line number, so we can output
  861.    relative line numbers for the other lines.
  862.    Describe beginning of outermost block.
  863.    Also describe the parameter list.  */
  864.  
  865. void
  866. sdbout_begin_function (line)
  867.      int line;
  868. {
  869.   sdb_begin_function_line = line - 1;
  870.   PUT_SDB_FUNCTION_START (line);
  871.   sdbout_parms (DECL_ARGUMENTS (current_function_decl));
  872.   sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
  873. }
  874.  
  875. /* Called at end of function (before epilogue).
  876.    Describe end of outermost block.  */
  877.  
  878. void
  879. sdbout_end_function (line)
  880.      int line;
  881. {
  882.   PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
  883.  
  884.   /* Indicate we are between functions, for line-number output.  */
  885.   sdb_begin_function_line = 0;
  886. }
  887.  
  888. /* Output sdb info for the absolute end of a function.
  889.    Called after the epilogue is output.  */
  890.  
  891. void
  892. sdbout_end_epilogue ()
  893. {
  894.   char *name = IDENTIFIER_POINTER (DECL_NAME (current_function_decl));
  895.   PUT_SDB_EPILOGUE_END (name);
  896. }
  897.  
  898. #endif /* SDB_DEBUGGING_INFO */
  899.