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

  1. /* Output variables, constants and external declarations, for GNU compiler.
  2.    Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
  3.    Hacked by Michael Tiemann (tiemann@mcc.com)
  4.  
  5. This file is part of GNU CC.
  6.  
  7. GNU CC 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 1, or (at your option)
  10. any later version.
  11.  
  12. GNU CC 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 GNU CC; see the file COPYING.  If not, write to
  19. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21.  
  22. /* This file handles generation of all the assembler code
  23.    *except* the instructions of a function.
  24.    This includes declarations of variables and their initial values.
  25.  
  26.    We also output the assembler code for constants stored in memory
  27.    and are responsible for combining constants with the same value.  */
  28.  
  29. #include <stdio.h>
  30. /* #include <stab.h> */
  31. #include "config.h"
  32. #include "rtl.h"
  33. #include "tree.h"
  34. #include "cplus-tree.h"
  35. #include "flags.h"
  36. #include "expr.h"
  37. #include "hard-reg-set.h"
  38.  
  39. #include "obstack.h"
  40.  
  41. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  42.  
  43. /* File in which assembler code is being written.  */
  44.  
  45. extern FILE *asm_out_file;
  46.  
  47. extern struct obstack *current_obstack;
  48. extern struct obstack *saveable_obstack;
  49. extern struct obstack permanent_obstack;
  50. #define obstack_chunk_alloc xmalloc
  51. extern int xmalloc ();
  52.  
  53. /* Number for making the label on the next
  54.    constant that is stored in memory.  */
  55.  
  56. int const_labelno;
  57.  
  58. /* Number for making the label on the next
  59.    static variable internal to a function.  */
  60.  
  61. int var_labelno;
  62.  
  63. /* Nonzero if at least one function definition has been seen.  */
  64. static int function_defined;
  65.  
  66. extern FILE *asm_out_file;
  67.  
  68. static char *compare_constant_1 ();
  69. static void record_constant_1 ();
  70. void assemble_name ();
  71. void output_addressed_constants ();
  72. void output_constant ();
  73. void output_constructor ();
  74.  
  75. #ifdef EXTRA_SECTIONS
  76. static enum in_section {no_section, in_text, in_data, EXTRA_SECTIONS} in_section
  77.   = no_section;
  78. #else
  79. static enum in_section {no_section, in_text, in_data} in_section
  80.   = no_section;
  81. #endif
  82.  
  83. /* Define functions like text_section for any extra sections.  */
  84. #ifdef EXTRA_SECTION_FUNCTIONS
  85. EXTRA_SECTION_FUNCTIONS
  86. #endif
  87.  
  88. /* Tell assembler to switch to text section.  */
  89.  
  90. void
  91. text_section ()
  92. {
  93.   if (in_section != in_text)
  94.     {
  95.       fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
  96.       in_section = in_text;
  97.     }
  98. }
  99.  
  100. /* Tell assembler to switch to data section.  */
  101.  
  102. void
  103. data_section ()
  104. {
  105.   if (in_section != in_data)
  106.     {
  107.       if (flag_shared_data)
  108.     {
  109. #ifdef SHARED_SECTION_ASM_OP
  110.       fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
  111. #else
  112.       fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
  113. #endif
  114.     }
  115.       else
  116.     fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
  117.  
  118.       in_section = in_data;
  119.     }
  120. }
  121.  
  122. /* Create the rtl to represent a function, for a function definition.
  123.    DECL is a FUNCTION_DECL node which describes which function.
  124.    The rtl is stored into DECL.  */
  125.  
  126. void
  127. make_function_rtl (decl)
  128.      tree decl;
  129. {
  130.   if (DECL_RTL (decl) == 0)
  131.     DECL_RTL (decl)
  132.       = gen_rtx (MEM, DECL_MODE (decl),
  133.          gen_rtx (SYMBOL_REF, Pmode,
  134.               lang_rtl_name (decl)));
  135.  
  136.   /* Record at least one function has been defined.  */
  137.   function_defined = 1;
  138. }
  139.  
  140. /* Decode an `asm' spec for a declaration as a register name.
  141.    Return the register number, or -1 if nothing specified,
  142.    or -2 if the name is not a register.  */
  143.  
  144. int
  145. decode_reg_name (asmspec)
  146.      char *asmspec;
  147. {
  148.   if (asmspec != 0)
  149.     {
  150.       int i;
  151.       extern char *reg_names[];
  152.  
  153.       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  154.     if (!strcmp (asmspec, reg_names[i]))
  155.       break;
  156.  
  157.       if (i < FIRST_PSEUDO_REGISTER)
  158.     return i;
  159.       else
  160.     return -2;
  161.     }
  162.  
  163.   return -1;
  164. }
  165.  
  166. /* Create the DECL_RTL for a declaration for a static or external variable
  167.    or static or external function.
  168.    ASMSPEC, if not 0, is the string which the user specified
  169.    as the assembler symbol name.
  170.    TOP_LEVEL is nonzero if this is a file-scope variable.  */
  171.  
  172. void
  173. make_decl_rtl (decl, asmspec, top_level)
  174.      tree decl;
  175.      char *asmspec;
  176.      int top_level;
  177. {
  178.   register char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
  179.   int reg_number = decode_reg_name (asmspec);
  180.  
  181.   if (reg_number == -2)
  182.     {
  183.       name = (char *) obstack_alloc (saveable_obstack, strlen (asmspec) + 2);
  184.       name[0] = '*';
  185.       strcpy (&name[1], asmspec);
  186.     }
  187.  
  188.   /* For a duplicate declaration, we can be called twice on the
  189.      same DECL node.  Don't alter the RTL already made
  190.      unless the old mode is wrong (which can happen when
  191.      the previous rtl was made when the type was incomplete).  */
  192.   if (DECL_RTL (decl) == 0
  193.       || GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
  194.     {
  195.       DECL_RTL (decl) = 0;
  196.  
  197.       /* First detect errors in declaring global registers.  */
  198.       if (TREE_REGDECL (decl) && reg_number == -1)
  199.     error_with_decl (decl,
  200.              "register name not specified for `%s'");
  201.       if (TREE_REGDECL (decl) && reg_number == -2)
  202.     error_with_decl (decl,
  203.              "invalid register name for `%s'");
  204.       else if (reg_number >= 0 && ! TREE_REGDECL (decl))
  205.     error_with_decl (decl,
  206.              "register name given for non-register variable `%s'");
  207.       else if (TREE_REGDECL (decl) && TREE_CODE (decl) == FUNCTION_DECL)
  208.     error ("function declared `register'");
  209.       else if (TREE_REGDECL (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
  210.     error_with_decl (decl, "data type of `%s' isn't suitable for a register");
  211.       /* Now handle properly declared static register variables.  */
  212.       else if (TREE_REGDECL (decl))
  213.     {
  214.       int nregs;
  215.       if (pedantic)
  216.         warning ("ANSI C forbids global register variables");
  217.       if (DECL_INITIAL (decl) != 0)
  218.         {
  219.           DECL_INITIAL (decl) = 0;
  220.           error ("global register variable has initial value");
  221.         }
  222.       if (fixed_regs[reg_number] == 0
  223.           && function_defined && top_level)
  224.         error ("global register variable follows a function definition");
  225.       DECL_RTL (decl) = gen_rtx (REG, DECL_MODE (decl), reg_number);
  226.       if (top_level)
  227.         {
  228.           /* Make this register fixed, so not usable for anything else.  */
  229.           nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
  230.           while (nregs > 0)
  231.         global_regs[reg_number + --nregs] = 1;
  232.           init_reg_sets_1 ();
  233.         }
  234.     }
  235.  
  236.       /* Now handle ordinary static variables and functions (in memory).
  237.      Also handle vars declared register invalidly.  */
  238.       if (DECL_RTL (decl) == 0)
  239.     {
  240.       /* Can't use just the variable's own name for a variable
  241.          whose scope is less than the whole file.
  242.          Concatenate a distinguishing number.  */
  243.       if (!top_level && !TREE_EXTERNAL (decl) && asmspec == 0)
  244.         {
  245.           char *label;
  246.  
  247.           ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
  248.           name = obstack_copy0 (saveable_obstack, label, strlen (label));
  249.           var_labelno++;
  250.         }
  251.  
  252.       DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
  253.                      gen_rtx (SYMBOL_REF, Pmode, name));
  254.       if (TREE_VOLATILE (decl))
  255.         MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
  256.       if (TREE_READONLY (decl))
  257.         RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
  258.       MEM_IN_STRUCT_P (DECL_RTL (decl))
  259.         = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  260.            || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
  261.            || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
  262.     }
  263.     }
  264. }
  265.  
  266. /* Output a string of literal assembler code
  267.    for an `asm' keyword used between functions.  */
  268.  
  269. void
  270. assemble_asm (string)
  271.      tree string;
  272. {
  273.   app_enable ();
  274.  
  275.   fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
  276. }
  277.  
  278. /* Output assembler code associated with defining the name of a function
  279.    as described by DECL.  */
  280.  
  281. void
  282. assemble_function (decl)
  283.      tree decl;
  284. {
  285.   rtx x, n;
  286.   char *fnname;
  287.  
  288.   /* Get the function's name, as described by its RTL.
  289.      This may be different from the DECL_NAME name used in the source file.  */
  290.  
  291.   x = DECL_RTL (decl);
  292.   if (GET_CODE (x) != MEM)
  293.     abort ();
  294.   n = XEXP (x, 0);
  295.   if (GET_CODE (n) != SYMBOL_REF)
  296.     abort ();
  297.   fnname = XSTR (n, 0);
  298.  
  299.   /* The following code does not need preprocessing in the assembler.  */
  300.  
  301.   app_disable ();
  302.  
  303.   text_section ();
  304.  
  305. #ifdef SDB_DEBUGGING_INFO
  306.   /* Make sure types are defined for debugger before fcn name is defined.  */
  307.   if (write_symbols == SDB_DEBUG)
  308.     sdbout_tags (gettags ());
  309. #endif
  310.  
  311.   /* Tell assembler to move to target machine's alignment for functions.  */
  312.  
  313.   ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT));
  314.  
  315. #ifdef SDB_DEBUGGING_INFO
  316.   /* Output SDB definition of the function.  */
  317.   if (write_symbols == SDB_DEBUG)
  318.     sdbout_mark_begin_function ();
  319. #endif
  320.  
  321.   /* Make function name accessible from other files, if appropriate.  */
  322.  
  323.   if (TREE_PUBLIC (decl))
  324.     ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
  325.  
  326.   /* Do any machine/system dependent processing of the function name */
  327. #ifdef ASM_DECLARE_FUNCTION_NAME
  328.   ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
  329. #else
  330.   /* Standard thing is just output label for the function.  */
  331.   ASM_OUTPUT_LABEL (asm_out_file, fnname);
  332. #endif /* ASM_DECLARE_FUNCTION_NAME */
  333. }
  334.  
  335. /* Assemble " .int 0\n" or whatever this assembler wants.  */
  336.  
  337. void
  338. assemble_integer_zero ()
  339. {
  340.   ASM_OUTPUT_INT (asm_out_file, const0_rtx);
  341. }
  342.  
  343. /* Assemble a string constant with the specified C string as contents.  */
  344.  
  345. void
  346. assemble_string (p, size)
  347.      unsigned char *p;
  348.      int size;
  349. {
  350.   register int i;
  351.   int excess = 0;
  352.   int pos = 0;
  353.   int maximum = 2000;
  354.  
  355.   /* If the string is very long, split it up.  */
  356.  
  357.   while (pos < size)
  358.     {
  359.       int thissize = size - pos;
  360.       if (thissize > maximum)
  361.     thissize = maximum;
  362.  
  363. #ifdef ASM_OUTPUT_ASCII
  364.       ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
  365. #else
  366.       fprintf (asm_out_file, "\t.ascii \"");
  367.  
  368.       for (i = 0; i < thissize; i++)
  369.     {
  370.       register int c = p[i];
  371.       if (c == '\"' || c == '\\')
  372.         putc ('\\', asm_out_file);
  373.       if (c >= ' ' && c < 0177)
  374.         putc (c, asm_out_file);
  375.       else
  376.         {
  377.           fprintf (asm_out_file, "\\%o", c);
  378.           /* After an octal-escape, if a digit follows,
  379.          terminate one string constant and start another.
  380.          The Vax assembler fails to stop reading the escape
  381.          after three digits, so this is the only way we
  382.          can get it to parse the data properly.  */
  383.           if (i < thissize - 1
  384.           && p[i + 1] >= '0' && p[i + 1] <= '9')
  385.         fprintf (asm_out_file, "\"\n\t.ascii \"");
  386.         }
  387.     }
  388.       fprintf (asm_out_file, "\"\n");
  389. #endif /* no ASM_OUTPUT_ASCII */
  390.  
  391.       pos += thissize;
  392.       p += thissize;
  393.     }
  394. }
  395.  
  396. /* Assemble everything that is needed for a variable or function declaration.
  397.    Not used for automatic variables, and not used for function definitions.
  398.    Should not be called for variables of incomplete structure type.
  399.  
  400.    TOP_LEVEL is nonzero if this variable has file scope.
  401.    WRITE_SYMBOLS is DBX_DEBUG if writing dbx symbol output.
  402.    The dbx data for a file-scope variable is written here.
  403.    AT_END is nonzero if this is the special handling, at end of compilation,
  404.    to define things that have had only tentative definitions.  */
  405.  
  406. void
  407. assemble_variable (decl, top_level, write_symbols, at_end)
  408.      tree decl;
  409.      int top_level;
  410.      enum debugger write_symbols;
  411.      int at_end;
  412. {
  413.   register char *name;
  414.   register int i;
  415.  
  416.   /* Do nothing for global register variables.  */
  417.  
  418.   if (GET_CODE (DECL_RTL (decl)) == REG)
  419.     return;
  420.  
  421.   /* Normally no need to say anything for external references,
  422.      since assembler considers all undefined symbols external.  */
  423.  
  424.   if (TREE_EXTERNAL (decl))
  425.     return;
  426.  
  427.   /* Output no assembler code for a function declaration.
  428.      Only definitions of functions output anything.  */
  429.  
  430.   if (TREE_CODE (decl) == FUNCTION_DECL)
  431.     return;
  432.  
  433.   /* If type was incomplete when the variable was declared,
  434.      see if it is complete now.  */
  435.  
  436.   if (DECL_SIZE (decl) == 0)
  437.     layout_decl (decl, 0);
  438.  
  439.   /* Still incomplete => don't allocate it; treat the tentative defn
  440.      (which is what it must have been) as an `extern' reference.  */
  441.  
  442.   if (DECL_SIZE (decl) == 0)
  443.     {
  444.       error_with_file_and_line (DECL_SOURCE_FILE (decl),
  445.                 DECL_SOURCE_LINE (decl),
  446.                 "storage size of static var `%s' isn't known",
  447.                 IDENTIFIER_POINTER (DECL_NAME (decl)));
  448.       return;
  449.     }
  450.  
  451.   /* The first declaration of a variable that comes through this function
  452.      decides whether it is global (in C, has external linkage)
  453.      or local (in C, has internal linkage).  So do nothing more
  454.      if this function has already run.  */
  455.  
  456.   if (TREE_ASM_WRITTEN (decl))
  457.     return;
  458.  
  459.   TREE_ASM_WRITTEN (decl) = 1;
  460.  
  461. #ifdef DBX_DEBUGGING_INFO
  462.   /* File-scope global variables are output here.  */
  463.   if (write_symbols == DBX_DEBUG && top_level)
  464.     dbxout_symbol (decl, 0);
  465. #endif
  466. #ifdef SDB_DEBUGGING_INFO
  467.   if (write_symbols == SDB_DEBUG && top_level)
  468.     sdbout_symbol (decl, 0);
  469. #endif
  470.   if (write_symbols == GDB_DEBUG)
  471.     /* Make sure the file is known to GDB even if it has no functions.  */
  472.     set_current_gdbfile (DECL_SOURCE_FILE (decl));
  473.  
  474.   /* If storage size is erroneously variable, just continue.
  475.      Error message was already made.  */
  476.  
  477.   if (! TREE_LITERAL (DECL_SIZE (decl)))
  478.     return;
  479.  
  480.   app_disable ();
  481.  
  482.   name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
  483.  
  484.   /* Handle uninitialized definitions.
  485.  
  486.      C++: global variables which take constructors look
  487.      like they are uninitialized.  The GNU loader will not
  488.      load a sub-file of a library if the only variabels
  489.      referenced in that sub-file are in uninitialized
  490.      data space.  We keep the loader fast by placing such
  491.      global variables in initialied data space (initialized to
  492.      all 0), at the expense of creating somewhat larger
  493.      executables.  */
  494.  
  495.   if (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
  496.     {
  497.       int size = (TREE_INT_CST_LOW (DECL_SIZE (decl))
  498.           * DECL_SIZE_UNIT (decl)
  499.           / BITS_PER_UNIT);
  500.       int rounded = size;
  501.       /* Don't allocate zero bytes of common,
  502.      since that means "undefined external" in the linker.  */
  503.       if (size == 0) rounded = 1;
  504.       /* Round size up to multiple of BIGGEST_ALIGNMENT bits
  505.      so that each uninitialized object starts on such a boundary.  */
  506.       rounded = ((rounded + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
  507.          / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
  508.          * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  509.       if (flag_shared_data)
  510.     data_section ();
  511.       if (TREE_PUBLIC (decl))
  512.     if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
  513.       {
  514.         ASM_GLOBALIZE_LABEL (asm_out_file, name);
  515.         data_section ();
  516.         for (i = 0; DECL_ALIGN (decl) >= BITS_PER_UNIT << (i + 1); i++);
  517.         ASM_OUTPUT_ALIGN (asm_out_file, i);
  518.         ASM_OUTPUT_LABEL (asm_out_file, name);
  519.         ASM_OUTPUT_SKIP (asm_out_file, size);
  520.       }
  521.     else
  522.       ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
  523.       else
  524.     ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
  525.       return;
  526.     }
  527.  
  528.   /* Handle initialized definitions.  */
  529.  
  530.   /* First make the assembler name(s) global if appropriate.  */
  531.   if (TREE_PUBLIC (decl) && DECL_NAME (decl))
  532.     ASM_GLOBALIZE_LABEL (asm_out_file, name);
  533. #if 0
  534.   for (d = equivalents; d; d = TREE_CHAIN (d))
  535.     {
  536.       tree e = TREE_VALUE (d);
  537.       if (TREE_PUBLIC (e) && DECL_NAME (e))
  538.     ASM_GLOBALIZE_LABEL (asm_out_file,
  539.                  XSTR (XEXP (DECL_RTL (e), 0), 0));
  540.     }
  541. #endif
  542.  
  543.   /* Output any data that we will need to use the address of.  */
  544.   if (DECL_INITIAL (decl))
  545.     output_addressed_constants (DECL_INITIAL (decl));
  546.  
  547.   /* Switch to the proper section for this data.  */
  548. #ifdef SELECT_SECTION
  549.   SELECT_SECTION (decl);
  550. #else
  551.   if (TREE_READONLY (decl) && ! TREE_VOLATILE (decl))
  552.     text_section ();
  553.   else
  554.     data_section ();
  555. #endif
  556.  
  557.   /* Output the alignment of this data.  */
  558.   for (i = 0; DECL_ALIGN (decl) >= BITS_PER_UNIT << (i + 1); i++);
  559.   ASM_OUTPUT_ALIGN (asm_out_file, i);
  560.  
  561.   /* Output the name(s) of this data.  */
  562.   ASM_OUTPUT_LABEL (asm_out_file, name);
  563. #if 0
  564.   for (d = equivalents; d; d = TREE_CHAIN (d))
  565.     {
  566.       tree e = TREE_VALUE (d);
  567.       ASM_OUTPUT_LABEL (asm_out_file, XSTR (XEXP (DECL_RTL (e), 0), 0));
  568.     }
  569. #endif
  570.  
  571.   if (DECL_INITIAL (decl))
  572.     /* Output the actual data.  */
  573.     output_constant (DECL_INITIAL (decl), int_size_in_bytes (TREE_TYPE (decl)));
  574.   else
  575.     /* Leave space for it.  */
  576.     ASM_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (decl)));
  577. }
  578.  
  579. /* Output something to declare an external symbol to the assembler.
  580.    (Most assemblers don't need this, so we normally output nothing.)  */
  581.  
  582. void
  583. assemble_external (decl)
  584.      tree decl;
  585. {
  586.   rtx rtl = DECL_RTL (decl);
  587.  
  588.   if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF)
  589.     {
  590. #ifdef ASM_OUTPUT_EXTERNAL
  591.       /* Some systems do require some output.  */
  592.       ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
  593. #endif
  594.     }
  595. }
  596.  
  597. /* Output to FILE a reference to the assembler name of a C-level name NAME.
  598.    If NAME starts with a *, the rest of NAME is output verbatim.
  599.    Otherwise NAME is transformed in an implementation-defined way
  600.    (usually by the addition of an underscore).
  601.    Many macros in the tm file are defined to call this function.  */
  602.  
  603. void
  604. assemble_name (file, name)
  605.      FILE *file;
  606.      char *name;
  607. {
  608.   if (name[0] == '*')
  609.     fputs (&name[1], file);
  610.   else
  611.     ASM_OUTPUT_LABELREF (file, name);
  612. }
  613.  
  614. /* Allocate SIZE bytes writable static space with a gensym name
  615.    and return an RTX to refer to its address.  */
  616.  
  617. rtx
  618. assemble_static_space (size)
  619.      int size;
  620. {
  621.   char name[12];
  622.   char *namestring;
  623.   rtx x;
  624.   /* Round size up to multiple of BIGGEST_ALIGNMENT bits
  625.      so that each uninitialized object starts on such a boundary.  */
  626.   int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
  627.          / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
  628.          * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  629.  
  630.   if (flag_shared_data)
  631.     data_section ();
  632.   ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
  633.   ++const_labelno;
  634.  
  635.   namestring = (char *) obstack_alloc (saveable_obstack,
  636.                        strlen (name) + 2);
  637.   strcpy (namestring, name);
  638.   
  639.   x = gen_rtx (SYMBOL_REF, Pmode, namestring);
  640.   ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
  641.   return x;
  642. }
  643.  
  644. /* Here we combine duplicate floating constants to make
  645.    CONST_DOUBLE rtx's, and force those out to memory when necessary.  */
  646.  
  647. /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
  648.    They are chained through the CONST_DOUBLE_CHAIN.
  649.    A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
  650.    In that case, CONST_DOUBLE_MEM is either a MEM,
  651.    or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.  */
  652.  
  653. static rtx real_constant_chain;
  654.  
  655. /* Return a CONST_DOUBLE for a value specified as a pair of ints.  */
  656.  
  657. rtx
  658. immed_double_const (i0, i1, mode)
  659.      int i0, i1;
  660.      enum machine_mode mode;
  661. {
  662.   register rtx r;
  663.  
  664.   if (mode == DImode && i0 == 0 && i1 == 0)
  665.     return const0_rtx;
  666.  
  667.   /* Search the chain for an existing CONST_DOUBLE with the right value.
  668.      If one is found, return it.  */
  669.  
  670.   for (r = real_constant_chain; r; r = CONST_DOUBLE_CHAIN (r))
  671.     if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
  672.     && GET_MODE (r) == mode)
  673.       return r;
  674.  
  675.   /* No; make a new one and add it to the chain.  */
  676.  
  677.   r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
  678.  
  679.   CONST_DOUBLE_CHAIN (r) = real_constant_chain;
  680.   real_constant_chain = r;
  681.  
  682.   /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
  683.      Actual use of mem-slot is only through force_const_double_mem.  */
  684.  
  685.   CONST_DOUBLE_MEM (r) = const0_rtx;
  686.  
  687.   return r;
  688. }
  689.  
  690. /* Return a CONST_DOUBLE for a specified `double' value
  691.    and machine mode.  */
  692.  
  693. rtx
  694. immed_real_const_1 (d, mode)
  695.      REAL_VALUE_TYPE d;
  696.      enum machine_mode mode;
  697. {
  698.   union real_extract u;
  699.   register rtx r;
  700.   REAL_VALUE_TYPE negated;
  701.  
  702.   /* Get the desired `double' value as a sequence of ints
  703.      since that is how they are stored in a CONST_DOUBLE.  */
  704.  
  705.   u.d = d;
  706.  
  707.   /* Detect zero.  */
  708.  
  709.   negated = REAL_VALUE_NEGATE (d);
  710.   if (REAL_VALUES_EQUAL (negated, d))
  711.     return (mode == DFmode ? dconst0_rtx : fconst0_rtx);
  712.  
  713.   if (sizeof u == 2 * sizeof (int))
  714.     return immed_double_const (u.i[0], u.i[1], mode);
  715.  
  716.   /* The rest of this function handles the case where
  717.      a float value requires more than 2 ints of space.
  718.      It will be deleted as dead code on machines that don't need it.  */
  719.  
  720.   /* Search the chain for an existing CONST_DOUBLE with the right value.
  721.      If one is found, return it.  */
  722.  
  723.   for (r = real_constant_chain; r; r = CONST_DOUBLE_CHAIN (r))
  724.     if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
  725.     && GET_MODE (r) == mode)
  726.       return r;
  727.  
  728.   /* No; make a new one and add it to the chain.  */
  729.  
  730.   r = rtx_alloc (CONST_DOUBLE);
  731.   PUT_MODE (r, mode);
  732.   bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
  733.  
  734.   CONST_DOUBLE_CHAIN (r) = real_constant_chain;
  735.   real_constant_chain = r;
  736.  
  737.   /* Store const0_rtx in slot 2 since this CONST_DOUBLE is on the chain.
  738.      Actual use of slot 2 is only through force_const_double_mem.  */
  739.  
  740.   CONST_DOUBLE_MEM (r) = const0_rtx;
  741.  
  742.   return r;
  743. }
  744.  
  745. /* Return a CONST_DOUBLE rtx for a value specified by EXP,
  746.    which must be a REAL_CST tree node.  */
  747.  
  748. rtx
  749. immed_real_const (exp)
  750.      tree exp;
  751. {
  752.   return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
  753. }
  754.  
  755. /* Given a CONST_DOUBLE, cause a constant in memory to be created
  756.    (unless we already have one for the same value)
  757.    and return a MEM rtx to refer to it.
  758.    Put the CONST_DOUBLE on real_constant_chain if it isn't already there.  */
  759.  
  760. rtx
  761. force_const_double_mem (r)
  762.      rtx r;
  763. {
  764.   if (CONST_DOUBLE_MEM (r) == cc0_rtx)
  765.     {
  766.       CONST_DOUBLE_CHAIN (r) = real_constant_chain;
  767.       real_constant_chain = r;
  768.       CONST_DOUBLE_MEM (r) = const0_rtx;
  769.     }
  770.  
  771.   if (CONST_DOUBLE_MEM (r) == const0_rtx)
  772.     {
  773.       CONST_DOUBLE_MEM (r) = force_const_mem (GET_MODE (r), r);
  774.     }
  775.   /* CONST_DOUBLE_MEM (r) is now a MEM with a constant address.
  776.      If that is legitimate, return it.
  777.      Othewise it will need reloading, so return a copy of it.  */
  778.   if (memory_address_p (GET_MODE (r), XEXP (CONST_DOUBLE_MEM (r), 0)))
  779.     return CONST_DOUBLE_MEM (r);
  780.   return gen_rtx (MEM, GET_MODE (r), XEXP (CONST_DOUBLE_MEM (r), 0));
  781. }
  782.  
  783. /* At the end of a function, forget the memory-constants
  784.    previously made for CONST_DOUBLEs.  Mark them as not on real_constant_chain.
  785.    Also clear out real_constant_chain and clear out all the chain-pointers.  */
  786.  
  787. void
  788. clear_const_double_mem ()
  789. {
  790.   register rtx r, next;
  791.  
  792.   for (r = real_constant_chain; r; r = next)
  793.     {
  794.       next = CONST_DOUBLE_CHAIN (r);
  795.       CONST_DOUBLE_CHAIN (r) = 0;
  796.       CONST_DOUBLE_MEM (r) = cc0_rtx;
  797.     }
  798.   real_constant_chain = 0;
  799. }
  800.  
  801. /* Given an expression EXP with a constant value,
  802.    reduce it to the sum of an assembler symbol and an integer.
  803.    Store them both in the structure *VALUE.
  804.    Abort if EXP does not reduce.  */
  805.  
  806. struct addr_const
  807. {
  808.   rtx base;
  809.   int offset;
  810. };
  811.  
  812. static void
  813. decode_addr_const (exp, value)
  814.      tree exp;
  815.      struct addr_const *value;
  816. {
  817.   register tree target = TREE_OPERAND (exp, 0);
  818.   register int offset = 0;
  819.   register rtx x;
  820.  
  821.   while (1)
  822.     {
  823.       if (TREE_CODE (target) == COMPONENT_REF)
  824.     {
  825.       offset += DECL_OFFSET (TREE_OPERAND (target, 1)) / BITS_PER_UNIT;
  826.       target = TREE_OPERAND (target, 0);
  827.     }
  828.       else if (TREE_CODE (target) == ARRAY_REF)
  829.     {
  830.       if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
  831.           || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
  832.         abort ();
  833.       offset += ((TYPE_SIZE_UNIT (TREE_TYPE (target))
  834.               * TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
  835.               * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
  836.              / BITS_PER_UNIT);
  837.       target = TREE_OPERAND (target, 0);
  838.     }
  839.       else break;
  840.     }
  841.  
  842.   if (TREE_CODE (target) == VAR_DECL
  843.       || TREE_CODE (target) == FUNCTION_DECL)
  844.     x = DECL_RTL (target);
  845.   else if (TREE_LITERAL (target))
  846.     x = TREE_CST_RTL (target);
  847.   else
  848.     abort ();
  849.  
  850.   if (GET_CODE (x) != MEM)
  851.     abort ();
  852.   x = XEXP (x, 0);
  853.  
  854.   value->base = x;
  855.   value->offset = offset;
  856. }
  857.  
  858. /* Uniquize all constants that appear in memory.
  859.    Each constant in memory thus far output is recorded
  860.    in `const_hash_table' with a `struct constant_descriptor'
  861.    that contains a polish representation of the value of
  862.    the constant.
  863.  
  864.    We cannot store the trees in the hash table
  865.    because the trees may be temporary.  */
  866.  
  867. struct constant_descriptor
  868. {
  869.   struct constant_descriptor *next;
  870.   char *label;
  871.   char contents[1];
  872. };
  873.  
  874. #define HASHBITS 30
  875. #define MAX_HASH_TABLE 1007
  876. static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
  877.  
  878. /* Compute a hash code for a constant expression.  */
  879.  
  880. int
  881. const_hash (exp)
  882.      tree exp;
  883. {
  884.   register char *p;
  885.   register int len, hi, i;
  886.   register enum tree_code code = TREE_CODE (exp);
  887.  
  888.   if (code == INTEGER_CST)
  889.     {
  890.       p = (char *) &TREE_INT_CST_LOW (exp);
  891.       len = 2 * sizeof TREE_INT_CST_LOW (exp);
  892.     }
  893.   else if (code == REAL_CST)
  894.     {
  895.       p = (char *) &TREE_REAL_CST (exp);
  896.       len = sizeof TREE_REAL_CST (exp);
  897.     }
  898.   else if (code == STRING_CST)
  899.     p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
  900.   else if (code == COMPLEX_CST)
  901.     return const_hash (TREE_REALPART (exp)) * 5
  902.       + const_hash (TREE_IMAGPART (exp));
  903.   else if (code == CONSTRUCTOR)
  904.     {
  905.       register tree link;
  906.       hi = 5;
  907.       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
  908.     hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
  909.       return hi;
  910.     }
  911.   else if (code == ADDR_EXPR)
  912.     {
  913.       struct addr_const value;
  914.       decode_addr_const (exp, &value);
  915.       p = (char *) &value;
  916.       len = sizeof value;
  917.     }
  918.   else if (code == PLUS_EXPR || code == MINUS_EXPR)
  919.     return const_hash (TREE_OPERAND (exp, 0)) * 9
  920.       +  const_hash (TREE_OPERAND (exp, 1));
  921.   else if (code == NOP_EXPR || code == CONVERT_EXPR)
  922.     return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
  923.  
  924.   /* Compute hashing function */
  925.   hi = len;
  926.   for (i = 0; i < len; i++)
  927.     hi = ((hi * 613) + (unsigned)(p[i]));
  928.  
  929.   hi &= (1 << HASHBITS) - 1;
  930.   hi %= MAX_HASH_TABLE;
  931.   return hi;
  932. }
  933.  
  934. /* Compare a constant expression EXP with a constant-descriptor DESC.
  935.    Return 1 if DESC describes a constant with the same value as EXP.  */
  936.  
  937. static int
  938. compare_constant (exp, desc)
  939.      tree exp;
  940.      struct constant_descriptor *desc;
  941. {
  942.   return 0 != compare_constant_1 (exp, desc->contents);
  943. }
  944.  
  945. /* Compare constant expression EXP with a substring P of a constant descriptor.
  946.    If they match, return a pointer to the end of the substring matched.
  947.    If they do not match, return 0.
  948.  
  949.    Since descriptors are written in polish prefix notation,
  950.    this function can be used recursively to test one operand of EXP
  951.    against a subdescriptor, and if it succeeds it returns the
  952.    address of the subdescriptor for the next operand.  */
  953.  
  954. static char *
  955. compare_constant_1 (exp, p)
  956.      tree exp;
  957.      char *p;
  958. {
  959.   register char *strp;
  960.   register int len;
  961.   register enum tree_code code = TREE_CODE (exp);
  962.  
  963.   if (code != (enum tree_code) *p++)
  964.     return 0;
  965.  
  966.   if (code == INTEGER_CST)
  967.     {
  968.       strp = (char *) &TREE_INT_CST_LOW (exp);
  969.       len = 2 * sizeof TREE_INT_CST_LOW (exp);
  970.     }
  971.   else if (code == REAL_CST)
  972.     {
  973.       /* Real constants are the same only if the same width of type.  */
  974.       if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
  975.     return 0;
  976.       strp = (char *) &TREE_REAL_CST (exp);
  977.       len = sizeof TREE_REAL_CST (exp);
  978.     }
  979.   else if (code == STRING_CST)
  980.     {
  981.       if (flag_writable_strings)
  982.     return 0;
  983.       strp = TREE_STRING_POINTER (exp);
  984.       len = TREE_STRING_LENGTH (exp);
  985.       if (bcmp (&TREE_STRING_LENGTH (exp), p,
  986.         sizeof TREE_STRING_LENGTH (exp)))
  987.     return 0;
  988.       p += sizeof TREE_STRING_LENGTH (exp);
  989.     }
  990.   else if (code == COMPLEX_CST)
  991.     {
  992.       p = compare_constant_1 (TREE_REALPART (exp), p);
  993.       if (p == 0) return 0;
  994.       p = compare_constant_1 (TREE_IMAGPART (exp), p);
  995.       return p;
  996.     }
  997.   else if (code == CONSTRUCTOR)
  998.     {
  999.       register tree link;
  1000.       int length = list_length (CONSTRUCTOR_ELTS (exp));
  1001.       if (bcmp (&length, p, sizeof length))
  1002.     return 0;
  1003.       p += sizeof length;
  1004.       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
  1005.     if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
  1006.       return 0;
  1007.       return p;
  1008.     }
  1009.   else if (code == ADDR_EXPR)
  1010.     {
  1011.       struct addr_const value;
  1012.       decode_addr_const (exp, &value);
  1013.       strp = (char *) &value;
  1014.       len = sizeof value;
  1015.     }
  1016.   else if (code == PLUS_EXPR || code == MINUS_EXPR)
  1017.     {
  1018.       if (*p++ != (char) code)
  1019.     return 0;
  1020.       p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
  1021.       if (p == 0) return 0;
  1022.       p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
  1023.       return p;
  1024.     }
  1025.   else if (code == NOP_EXPR || code == CONVERT_EXPR)
  1026.     {
  1027.       if (*p++ != (char) code)
  1028.     return 0;
  1029.       p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
  1030.       return p;
  1031.     }
  1032.  
  1033.   /* Compare constant contents.  */
  1034.   while (--len >= 0)
  1035.     if (*p++ != *strp++)
  1036.       return 0;
  1037.  
  1038.   return p;
  1039. }
  1040.  
  1041. /* Construct a constant descriptor for the expression EXP.
  1042.    It is up to the caller to enter the descriptor in the hash table.  */
  1043.  
  1044. static struct constant_descriptor *
  1045. record_constant (exp)
  1046.      tree exp;
  1047. {
  1048.   struct constant_descriptor *ptr = 0;
  1049.   int buf;
  1050.  
  1051.   obstack_grow (&permanent_obstack, &ptr, sizeof ptr);
  1052.   obstack_grow (&permanent_obstack, &buf, sizeof buf);
  1053.   record_constant_1 (exp);
  1054.   return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
  1055. }
  1056.  
  1057. /* Add a description of constant expression EXP
  1058.    to the object growing in `permanent_obstack'.
  1059.    No need to return its address; the caller will get that
  1060.    from the obstack when the object is complete.  */
  1061.  
  1062. static void
  1063. record_constant_1 (exp)
  1064.      tree exp;
  1065. {
  1066.   register char *strp;
  1067.   register int len;
  1068.   register enum tree_code code = TREE_CODE (exp);
  1069.  
  1070.   obstack_1grow (&permanent_obstack, (unsigned int) code);
  1071.  
  1072.   if (code == INTEGER_CST)
  1073.     {
  1074.       strp = (char *) &TREE_INT_CST_LOW (exp);
  1075.       len = 2 * sizeof TREE_INT_CST_LOW (exp);
  1076.     }
  1077.   else if (code == REAL_CST)
  1078.     {
  1079.       obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
  1080.       strp = (char *) &TREE_REAL_CST (exp);
  1081.       len = sizeof TREE_REAL_CST (exp);
  1082.     }
  1083.   else if (code == STRING_CST)
  1084.     {
  1085.       if (flag_writable_strings)
  1086.     return;
  1087.       strp = TREE_STRING_POINTER (exp);
  1088.       len = TREE_STRING_LENGTH (exp);
  1089.       obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
  1090.             sizeof TREE_STRING_LENGTH (exp));
  1091.     }
  1092.   else if (code == COMPLEX_CST)
  1093.     {
  1094.       record_constant_1 (TREE_REALPART (exp));
  1095.       record_constant_1 (TREE_IMAGPART (exp));
  1096.       return;
  1097.     }
  1098.   else if (code == CONSTRUCTOR)
  1099.     {
  1100.       register tree link;
  1101.       int length = list_length (CONSTRUCTOR_ELTS (exp));
  1102.       obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
  1103.  
  1104.       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
  1105.     record_constant_1 (TREE_VALUE (link));
  1106.       return;
  1107.     }
  1108.   else if (code == ADDR_EXPR)
  1109.     {
  1110.       struct addr_const value;
  1111.       decode_addr_const (exp, &value);
  1112.       strp = (char *) &value;
  1113.       len = sizeof value;
  1114.     }
  1115.   else if (code == PLUS_EXPR || code == MINUS_EXPR)
  1116.     {
  1117.       obstack_1grow (&permanent_obstack, (int) code);
  1118.       record_constant_1 (TREE_OPERAND (exp, 0));
  1119.       record_constant_1 (TREE_OPERAND (exp, 1));
  1120.       return;
  1121.     }
  1122.   else if (code == NOP_EXPR || code == CONVERT_EXPR)
  1123.     {
  1124.       obstack_1grow (&permanent_obstack, (int) code);
  1125.       record_constant_1 (TREE_OPERAND (exp, 0));
  1126.       return;
  1127.     }
  1128.  
  1129.   /* Record constant contents.  */
  1130.   obstack_grow (&permanent_obstack, strp, len);
  1131. }
  1132.  
  1133. /* Return the constant-label-string for constant value EXP.
  1134.    If no constant equal to EXP has yet been output,
  1135.    define a new label and output assembler code for it.
  1136.    The const_hash_table records which constants already have label strings.  */
  1137.  
  1138. static char *
  1139. get_or_assign_label (exp)
  1140.      tree exp;
  1141. {
  1142.   register int hash, i;
  1143.   register struct constant_descriptor *desc;
  1144.   char label[10];
  1145.  
  1146.   /* Make sure any other constants whose addresses appear in EXP
  1147.      are assigned label numbers.  */
  1148.  
  1149.   output_addressed_constants (exp);
  1150.  
  1151.   /* Compute hash code of EXP.  Search the descriptors for that hash code
  1152.      to see if any of them describes EXP.  If yes, the descriptor records
  1153.      the label number already assigned.  */
  1154.  
  1155.   hash = const_hash (exp) % MAX_HASH_TABLE;
  1156.  
  1157.   for (desc = const_hash_table[hash]; desc; desc = desc->next)
  1158.     if (compare_constant (exp, desc))
  1159.       return desc->label;
  1160.  
  1161.   /* No constant equal to EXP is known to have been output.
  1162.      Make a constant descriptor to enter EXP in the hash table.
  1163.      Assign the label number and record it in the descriptor for
  1164.      future calls to this function to find.  */
  1165.  
  1166.   desc = record_constant (exp);
  1167.   desc->next = const_hash_table[hash];
  1168.   const_hash_table[hash] = desc;
  1169.  
  1170.   /* Now output assembler code to define that label
  1171.      and follow it with the data of EXP.  */
  1172.  
  1173.   /* First switch to text section, except for writable strings.  */
  1174. #ifdef SELECT_SECTION
  1175.   SELECT_SECTION (exp);
  1176. #else
  1177.   if ((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
  1178.     data_section ();
  1179.   else
  1180.     text_section ();
  1181. #endif
  1182.  
  1183.   /* Align the location counter as required by EXP's data type.  */
  1184.   for (i = 0; TYPE_ALIGN (TREE_TYPE (exp)) >= BITS_PER_UNIT << (i + 1); i++);
  1185.   ASM_OUTPUT_ALIGN (asm_out_file, i);
  1186.  
  1187.   /* Output the label itself.  */
  1188.   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", const_labelno);
  1189.  
  1190.   /* Output the value of EXP.  */
  1191.   output_constant (exp,
  1192.            (TREE_CODE (exp) == STRING_CST
  1193.             ? TREE_STRING_LENGTH (exp)
  1194.             : int_size_in_bytes (TREE_TYPE (exp))));
  1195.  
  1196.   /* Create a string containing the label name, in LABEL.  */
  1197.   ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
  1198.  
  1199.   ++const_labelno;
  1200.  
  1201.   desc->label
  1202.     = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
  1203.  
  1204.   return desc->label;
  1205. }
  1206.  
  1207. /* Return an rtx representing a reference to constant data in memory
  1208.    for the constant expression EXP.
  1209.    If assembler code for such a constant has already been output,
  1210.    return an rtx to refer to it.
  1211.    Otherwise, output such a constant in memory and generate
  1212.    an rtx for it.  The TREE_CST_RTL of EXP is set up to point to that rtx.  */
  1213.  
  1214. rtx
  1215. output_constant_def (exp)
  1216.      tree exp;
  1217. {
  1218.   register rtx def;
  1219.   int temp_p = allocation_temporary_p ();
  1220.  
  1221.   if (TREE_CODE (exp) == INTEGER_CST)
  1222.     abort ();            /* No TREE_CST_RTL slot in these.  */
  1223.  
  1224.   if (TREE_CST_RTL (exp))
  1225.     return TREE_CST_RTL (exp);
  1226.  
  1227.   if (TREE_PERMANENT (exp))
  1228.     end_temporary_allocation ();
  1229.  
  1230.   def = gen_rtx (SYMBOL_REF, Pmode, get_or_assign_label (exp));
  1231.  
  1232.   TREE_CST_RTL (exp)
  1233.     = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
  1234.   RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
  1235.  
  1236.   if (temp_p && TREE_PERMANENT (exp))
  1237.     resume_temporary_allocation ();
  1238.  
  1239.   return TREE_CST_RTL (exp);
  1240. }
  1241.  
  1242. /* Similar hash facility for making memory-constants
  1243.    from constant rtl-expressions.  It is used on RISC machines
  1244.    where immediate integer arguments and constant addresses are restricted
  1245.    so that such constants must be stored in memory.
  1246.  
  1247.    This pool of constants is reinitialized for each function
  1248.    so each function gets its own constants-pool that comes right before it.  */
  1249.  
  1250. #define MAX_RTX_HASH_TABLE 61
  1251. static struct constant_descriptor *const_rtx_hash_table[MAX_RTX_HASH_TABLE];
  1252.  
  1253. void
  1254. init_const_rtx_hash_table ()
  1255. {
  1256.   bzero (const_rtx_hash_table, sizeof const_rtx_hash_table);
  1257. }
  1258.  
  1259. struct rtx_const
  1260. {
  1261.   enum kind { RTX_DOUBLE, RTX_INT } kind : 16;
  1262.   enum machine_mode mode : 16;
  1263.   union {
  1264.     union real_extract du;
  1265.     struct addr_const addr;
  1266.   } un;
  1267. };
  1268.  
  1269. /* Express an rtx for a constant integer (perhaps symbolic)
  1270.    as the sum of a symbol or label plus an explicit integer.
  1271.    They are stored into VALUE.  */
  1272.  
  1273. static void
  1274. decode_rtx_const (mode, x, value)
  1275.      enum machine_mode mode;
  1276.      rtx x;
  1277.      struct rtx_const *value;
  1278. {
  1279.   /* Clear the whole structure, including any gaps.  */
  1280.  
  1281.   {
  1282.     int *p = (int *) value;
  1283.     int *end = (int *) (value + 1);
  1284.     while (p < end)
  1285.       *p++ = 0;
  1286.   }
  1287.  
  1288.   value->kind = RTX_INT;    /* Most usual kind. */
  1289.   value->mode = mode;
  1290.  
  1291.   switch (GET_CODE (x))
  1292.     {
  1293.     case CONST_DOUBLE:
  1294.       value->kind = RTX_DOUBLE;
  1295.       value->mode = GET_MODE (x);
  1296.       bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
  1297.       break;
  1298.  
  1299.     case CONST_INT:
  1300.       value->un.addr.offset = INTVAL (x);
  1301.       break;
  1302.  
  1303.     case SYMBOL_REF:
  1304.       value->un.addr.base = x;
  1305.       break;
  1306.  
  1307.     case LABEL_REF:
  1308.       value->un.addr.base = x;
  1309.       break;
  1310.     
  1311.     case CONST:
  1312.       x = XEXP (x, 0);
  1313.       if (GET_CODE (x) == PLUS)
  1314.     {
  1315.       value->un.addr.base = XEXP (XEXP (x, 0), 0);
  1316.       if (GET_CODE (XEXP (x, 1)) != CONST_INT)
  1317.         abort ();
  1318.       value->un.addr.offset = INTVAL (XEXP (x, 1));
  1319.     }
  1320.       else if (GET_CODE (x) == MINUS)
  1321.     {
  1322.       value->un.addr.base = XEXP (x, 0);
  1323.       if (GET_CODE (XEXP (x, 1)) != CONST_INT)
  1324.         abort ();
  1325.       value->un.addr.offset = - INTVAL (XEXP (x, 1));
  1326.     }
  1327.       else
  1328.     abort ();
  1329.       break;
  1330.  
  1331.     default:
  1332.       abort ();
  1333.     }
  1334.  
  1335.   if (value->kind == RTX_INT && value->un.addr.base != 0)
  1336.     switch (GET_CODE (value->un.addr.base))
  1337.       {
  1338.       case SYMBOL_REF:
  1339.       case LABEL_REF:
  1340.     /* Use the string's address, not the SYMBOL_REF's address,
  1341.        for the sake of addresses of library routines.
  1342.        For a LABEL_REF, compare labels.  */
  1343.     value->un.addr.base = XEXP (value->un.addr.base, 0);
  1344.       }
  1345. }
  1346.  
  1347. /* Compute a hash code for a constant RTL expression.  */
  1348.  
  1349. int
  1350. const_hash_rtx (mode, x)
  1351.      enum machine_mode mode;
  1352.      rtx x;
  1353. {
  1354.   register int hi, i;
  1355.  
  1356.   struct rtx_const value;
  1357.   decode_rtx_const (mode, x, &value);
  1358.  
  1359.   /* Compute hashing function */
  1360.   hi = 0;
  1361.   for (i = 0; i < sizeof value / sizeof (int); i++)
  1362.     hi += ((int *) &value)[i];
  1363.  
  1364.   hi &= (1 << HASHBITS) - 1;
  1365.   hi %= MAX_RTX_HASH_TABLE;
  1366.   return hi;
  1367. }
  1368.  
  1369. /* Compare a constant rtl object X with a constant-descriptor DESC.
  1370.    Return 1 if DESC describes a constant with the same value as X.  */
  1371.  
  1372. static int
  1373. compare_constant_rtx (mode, x, desc)
  1374.      enum machine_mode mode;
  1375.      rtx x;
  1376.      struct constant_descriptor *desc;
  1377. {
  1378.   register int *p = (int *) desc->contents;
  1379.   register int *strp;
  1380.   register int len;
  1381.   struct rtx_const value;
  1382.  
  1383.   decode_rtx_const (mode, x, &value);
  1384.   strp = (int *) &value;
  1385.   len = sizeof value / sizeof (int);
  1386.  
  1387.   /* Compare constant contents.  */
  1388.   while (--len >= 0)
  1389.     if (*p++ != *strp++)
  1390.       return 0;
  1391.  
  1392.   return 1;
  1393. }
  1394.  
  1395. /* Construct a constant descriptor for the rtl-expression X.
  1396.    It is up to the caller to enter the descriptor in the hash table.  */
  1397.  
  1398. static struct constant_descriptor *
  1399. record_constant_rtx (mode, x)
  1400.      enum machine_mode mode;
  1401.      rtx x;
  1402. {
  1403.   struct constant_descriptor *ptr = 0;
  1404.   int buf;
  1405.   struct rtx_const value;
  1406.  
  1407.   decode_rtx_const (mode, x, &value);
  1408.  
  1409.   obstack_grow (saveable_obstack, &ptr, sizeof ptr);
  1410.   obstack_grow (saveable_obstack, &buf, sizeof buf);
  1411.  
  1412.   /* Record constant contents.  */
  1413.   obstack_grow (saveable_obstack, &value, sizeof value);
  1414.  
  1415.   return (struct constant_descriptor *) obstack_finish (saveable_obstack);
  1416. }
  1417.  
  1418. /* Given a constant rtx X, make (or find) a memory constant for its value
  1419.    and return a MEM rtx to refer to it in memory.  */
  1420.  
  1421. rtx
  1422. force_const_mem (mode, x)
  1423.      enum machine_mode mode;
  1424.      rtx x;
  1425. {
  1426.   register int hash;
  1427.   register struct constant_descriptor *desc;
  1428.   char label[10];
  1429.   char *found = 0;
  1430.   rtx def;
  1431.  
  1432.   if (GET_CODE (x) == CONST_DOUBLE
  1433.       && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM)
  1434.     return CONST_DOUBLE_MEM (x);
  1435.  
  1436.   /* Compute hash code of X.  Search the descriptors for that hash code
  1437.      to see if any of them describes X.  If yes, the descriptor records
  1438.      the label number already assigned.  */
  1439.  
  1440.   hash = const_hash_rtx (mode, x);
  1441.  
  1442.   for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
  1443.     if (compare_constant_rtx (mode, x, desc))
  1444.       {
  1445.     found = desc->label;
  1446.     break;
  1447.       }
  1448.  
  1449.   if (found == 0)
  1450.     {
  1451.       int align;
  1452.  
  1453.       /* No constant equal to X is known to have been output.
  1454.      Make a constant descriptor to enter X in the hash table.
  1455.      Assign the label number and record it in the descriptor for
  1456.      future calls to this function to find.  */
  1457.  
  1458.       desc = record_constant_rtx (mode, x);
  1459.       desc->next = const_rtx_hash_table[hash];
  1460.       const_rtx_hash_table[hash] = desc;
  1461.  
  1462.       /* Now output assembler code to define that label
  1463.      and follow it with the data of EXP.  */
  1464.  
  1465.       /* First switch to text section.  */
  1466.       text_section ();
  1467.  
  1468.       /* Align the location counter as required by EXP's data type.  */
  1469.       align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
  1470.       if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
  1471.     align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  1472.  
  1473.       ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (align));
  1474.  
  1475.       /* Output the label itself.  */
  1476.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", const_labelno);
  1477.  
  1478.       /* Output the value of EXP.  */
  1479.       if (GET_CODE (x) == CONST_DOUBLE)
  1480.     {
  1481.       union real_extract u;
  1482.  
  1483.       bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
  1484.       switch (mode)
  1485.         {
  1486.         case DImode:
  1487. #ifdef ASM_OUTPUT_DOUBLE_INT
  1488.           ASM_OUTPUT_DOUBLE_INT (asm_out_file, u.i[0], u.i[1]);
  1489. #else /* no ASM_OUTPUT_DOUBLE_INT */
  1490. #ifndef WORDS_BIG_ENDIAN
  1491.           /* Output two ints.  */
  1492.           ASM_OUTPUT_INT (asm_out_file,
  1493.                   gen_rtx (CONST_INT, VOIDmode, u.i[0]));
  1494.           ASM_OUTPUT_INT (asm_out_file,
  1495.                   gen_rtx (CONST_INT, VOIDmode, u.i[1]));
  1496. #else
  1497.           /* Output two ints.  */
  1498.           ASM_OUTPUT_INT (asm_out_file,
  1499.                   gen_rtx (CONST_INT, VOIDmode, u.i[1]));
  1500.           ASM_OUTPUT_INT (asm_out_file,
  1501.                   gen_rtx (CONST_INT, VOIDmode, u.i[0]));
  1502. #endif /* WORDS_BIG_ENDIAN */
  1503. #endif /* no ASM_OUTPUT_DOUBLE_INT */
  1504.           break;
  1505.  
  1506.         case DFmode:
  1507.           ASM_OUTPUT_DOUBLE (asm_out_file, u.d);
  1508.           break;
  1509.  
  1510.         case SFmode:
  1511.           ASM_OUTPUT_FLOAT (asm_out_file, u.d);
  1512.         }
  1513.     }
  1514.       else
  1515.     switch (mode)
  1516.       {
  1517.       case SImode:
  1518.         ASM_OUTPUT_INT (asm_out_file, x);
  1519.         break;
  1520.  
  1521.       case HImode:
  1522.         ASM_OUTPUT_SHORT (asm_out_file, x);
  1523.         break;
  1524.  
  1525.       case QImode:
  1526.         ASM_OUTPUT_CHAR (asm_out_file, x);
  1527.         break;
  1528.       }
  1529.  
  1530.       /* Create a string containing the label name, in LABEL.  */
  1531.       ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
  1532.  
  1533.       ++const_labelno;
  1534.  
  1535.       desc->label = found
  1536.     = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
  1537.     }
  1538.  
  1539.   /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
  1540.  
  1541.   def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, desc->label));
  1542.  
  1543.   RTX_UNCHANGING_P (def) = 1;
  1544.   /* Mark the symbol_ref as belonging to this constants pool.  */
  1545.   CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
  1546.  
  1547.   if (GET_CODE (x) == CONST_DOUBLE)
  1548.     {
  1549.       if (CONST_DOUBLE_MEM (x) == cc0_rtx)
  1550.     {
  1551.       CONST_DOUBLE_CHAIN (x) = real_constant_chain;
  1552.       real_constant_chain = x;
  1553.     }
  1554.       CONST_DOUBLE_MEM (x) = def;
  1555.     }
  1556.  
  1557.   return def;
  1558. }
  1559.  
  1560. /* Find all the constants whose addresses are referenced inside of EXP,
  1561.    and make sure assembler code with a label has been output for each one.  */
  1562.  
  1563. void
  1564. output_addressed_constants (exp)
  1565.      tree exp;
  1566. {
  1567.   switch (TREE_CODE (exp))
  1568.     {
  1569.     case ADDR_EXPR:
  1570.       {
  1571.     register tree constant = TREE_OPERAND (exp, 0);
  1572.  
  1573.     while (TREE_CODE (constant) == COMPONENT_REF)
  1574.       {
  1575.         constant = TREE_OPERAND (constant, 0);
  1576.       }
  1577.  
  1578.     if (TREE_LITERAL (constant))
  1579.       /* No need to do anything here
  1580.          for addresses of variables or functions.  */
  1581.       output_constant_def (constant);
  1582.       }
  1583.       break;
  1584.  
  1585.     case PLUS_EXPR:
  1586.     case MINUS_EXPR:
  1587.       output_addressed_constants (TREE_OPERAND (exp, 0));
  1588.       output_addressed_constants (TREE_OPERAND (exp, 1));
  1589.       break;
  1590.  
  1591.     case NOP_EXPR:
  1592.     case CONVERT_EXPR:
  1593.       output_addressed_constants (TREE_OPERAND (exp, 0));
  1594.       break;
  1595.  
  1596.     case CONSTRUCTOR:
  1597.       {
  1598.     register tree link;
  1599.     for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
  1600.       output_addressed_constants (TREE_VALUE (link));
  1601.       }
  1602.       break;
  1603.  
  1604.     case ERROR_MARK:
  1605.       break;
  1606.  
  1607.     default:
  1608.       if (! TREE_LITERAL (exp))
  1609.     abort ();
  1610.     }
  1611. }
  1612.  
  1613. /* Output assembler code for constant EXP to FILE, with no label.
  1614.    This includes the pseudo-op such as ".int" or ".byte", and a newline.
  1615.    Assumes output_addressed_constants has been done on EXP already.
  1616.  
  1617.    Generate exactly SIZE bytes of assembler data, padding at the end
  1618.    with zeros if necessary.  SIZE must always be specified.
  1619.  
  1620.    SIZE is important for structure constructors,
  1621.    since trailing members may have been omitted from the constructor.
  1622.    It is also important for initialization of arrays from string constants
  1623.    since the full length of the string constant might not be wanted.
  1624.    It is also needed for initialization of unions, where the initializer's
  1625.    type is just one member, and that may not be as long as the union.
  1626.  
  1627.    There a case in which we would fail to output exactly SIZE bytes:
  1628.    for a structure constructor that wants to produce more than SIZE bytes.
  1629.    But such constructors will never be generated for any possible input.  */
  1630.  
  1631. void
  1632. output_constant (exp, size)
  1633.      register tree exp;
  1634.      register int size;
  1635. {
  1636.   register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
  1637.   rtx x;
  1638.  
  1639.   if (size == 0)
  1640.     return;
  1641.  
  1642.   /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
  1643.      That way we get the constant (we hope) inside it.  */
  1644.   if (TREE_CODE (exp) == NOP_EXPR
  1645.       && TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)))
  1646.     exp = TREE_OPERAND (exp, 0);
  1647.  
  1648.   switch (code)
  1649.     {
  1650.     case INTEGER_TYPE:
  1651.     case ENUMERAL_TYPE:
  1652.     case POINTER_TYPE:
  1653.       while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
  1654.     exp = TREE_OPERAND (exp, 0);
  1655.     case REFERENCE_TYPE:
  1656.  
  1657.       if (TYPE_MODE (TREE_TYPE (exp)) == DImode)
  1658.     {
  1659.       if (TREE_CODE (exp) == INTEGER_CST)
  1660.         {
  1661. #ifndef WORDS_BIG_ENDIAN
  1662.           ASM_OUTPUT_INT (asm_out_file,
  1663.                   gen_rtx (CONST_INT, VOIDmode,
  1664.                        TREE_INT_CST_LOW (exp)));
  1665.           ASM_OUTPUT_INT (asm_out_file,
  1666.                   gen_rtx (CONST_INT, VOIDmode,
  1667.                        TREE_INT_CST_HIGH (exp)));
  1668. #else
  1669.           ASM_OUTPUT_INT (asm_out_file,
  1670.                   gen_rtx (CONST_INT, VOIDmode,
  1671.                        TREE_INT_CST_HIGH (exp)));
  1672.           ASM_OUTPUT_INT (asm_out_file,
  1673.                   gen_rtx (CONST_INT, VOIDmode,
  1674.                        TREE_INT_CST_LOW (exp)));
  1675. #endif
  1676.           size -= 8;
  1677.           break;
  1678.         }
  1679.       else
  1680.         error ("8-byte integer constant expression too complicated");
  1681.  
  1682.       break;
  1683.     }
  1684.  
  1685.       x = expand_expr (exp, 0, VOIDmode, EXPAND_SUM);
  1686.  
  1687.       if (size == 1)
  1688.     {
  1689.       ASM_OUTPUT_CHAR (asm_out_file, x);
  1690.       size -= 1;
  1691.     }
  1692.       else if (size == 2)
  1693.     {
  1694.       ASM_OUTPUT_SHORT (asm_out_file, x);
  1695.       size -= 2;
  1696.     }
  1697.       else if (size == 4)
  1698.     {
  1699.       ASM_OUTPUT_INT (asm_out_file, x);
  1700.       size -= 4;
  1701.     }
  1702.       else
  1703.     abort ();
  1704.  
  1705.       break;
  1706.  
  1707.     case REAL_TYPE:
  1708.       if (TREE_CODE (exp) != REAL_CST)
  1709.     error ("initializer for floating value is not a floating constant");
  1710.  
  1711.       if (size < 4)
  1712.     break;
  1713.       else if (size < 8)
  1714.     {
  1715.       ASM_OUTPUT_FLOAT (asm_out_file, TREE_REAL_CST (exp));
  1716.       size -= 4;
  1717.     }
  1718.       else
  1719.     {
  1720.       ASM_OUTPUT_DOUBLE (asm_out_file, TREE_REAL_CST (exp));
  1721.       size -= 8;
  1722.     }
  1723.       break;
  1724.  
  1725.     case COMPLEX_TYPE:
  1726.       output_constant (TREE_REALPART (exp), size / 2);
  1727.       output_constant (TREE_IMAGPART (exp), size / 2);
  1728.       size -= (size / 2) * 2;
  1729.       break;
  1730.  
  1731.     case ARRAY_TYPE:
  1732.       if (TREE_CODE (exp) == CONSTRUCTOR)
  1733.     {
  1734.       output_constructor (exp, size);
  1735.       return;
  1736.     }
  1737.       else if (TREE_CODE (exp) == STRING_CST)
  1738.     {
  1739.       int excess = 0;
  1740.  
  1741.       if (size > TREE_STRING_LENGTH (exp))
  1742.         {
  1743.           excess = size - TREE_STRING_LENGTH (exp);
  1744.           size = TREE_STRING_LENGTH (exp);
  1745.         }
  1746.  
  1747.       assemble_string (TREE_STRING_POINTER (exp), size);
  1748.       size = excess;
  1749.     }
  1750.       else
  1751.     abort ();
  1752.       break;
  1753.  
  1754.     case RECORD_TYPE:
  1755.     case UNION_TYPE:
  1756.       if (TREE_CODE (exp) == CONSTRUCTOR)
  1757.     output_constructor (exp, size);
  1758.       else
  1759.     abort ();
  1760.       return;
  1761.     }
  1762.  
  1763.   if (size > 0)
  1764.     ASM_OUTPUT_SKIP (asm_out_file, size);
  1765. }
  1766.  
  1767. /* Subroutine of output_constant, used for CONSTRUCTORs
  1768.    (aggregate constants).
  1769.    Generate at least SIZE bytes, padding if necessary.  */
  1770.  
  1771. void
  1772. output_constructor (exp, size)
  1773.      tree exp;
  1774.      int size;
  1775. {
  1776.   register tree link, field = 0;
  1777.   register int byte;
  1778.   int total_bytes = 0;
  1779.   int byte_offset = -1;
  1780.  
  1781.   if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
  1782.       || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
  1783.     field = TYPE_FIELDS (TREE_TYPE (exp));
  1784.  
  1785.   /* As LINK goes through the elements of the constant,
  1786.      FIELD goes through the structure fields, if the constant is a structure.
  1787.      But the constant could also be an array.  Then FIELD is zero.  */
  1788.   for (link = CONSTRUCTOR_ELTS (exp);
  1789.        link;
  1790.        link = TREE_CHAIN (link),
  1791.        field = field ? TREE_CHAIN (field) : 0)
  1792.     {
  1793.       tree val = TREE_VALUE (link);
  1794.  
  1795.       /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.  */
  1796.       if (TREE_CODE (val) == NOP_EXPR
  1797.       && TREE_TYPE (val) == TREE_TYPE (TREE_OPERAND (val, 0)))
  1798.     val = TREE_OPERAND (val, 0);
  1799.  
  1800.       if (field == 0
  1801.       || (DECL_MODE (field) != BImode))
  1802.     {
  1803.       register int fieldsize;
  1804.  
  1805.       /* An element that is not a bit-field.
  1806.          Output any buffered-up bit-fields preceding it.  */
  1807.       if (byte_offset >= 0)
  1808.         {
  1809.           ASM_OUTPUT_BYTE (asm_out_file, byte);
  1810.           total_bytes++;
  1811.           byte_offset = -1;
  1812.         }
  1813.  
  1814.       /* Align to this element's alignment,
  1815.          if it isn't aligned properly by its predecessors.  */
  1816.       if (field && (total_bytes * BITS_PER_UNIT) % DECL_ALIGN (field) != 0)
  1817.         {
  1818.           int byte_align = DECL_ALIGN (field) / BITS_PER_UNIT;
  1819.           int to_byte = (((total_bytes + byte_align - 1) / byte_align)
  1820.                  * byte_align);
  1821.           ASM_OUTPUT_SKIP (asm_out_file, to_byte - total_bytes);
  1822.           total_bytes = to_byte;
  1823.         }
  1824.  
  1825.       /* Output the element's initial value.  */
  1826.       if (field)
  1827.         {
  1828.           if (! TREE_LITERAL (DECL_SIZE (field)))
  1829.         abort ();
  1830.           fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field))
  1831.         * DECL_SIZE_UNIT (field);
  1832.           fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  1833.         }
  1834.       else
  1835.         fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
  1836.  
  1837.       output_constant (val, fieldsize);
  1838.  
  1839.       /* Count its size.  */
  1840.       total_bytes += fieldsize;
  1841.     }
  1842.       else if (TREE_CODE (val) != INTEGER_CST)
  1843.     error ("invalid initial value for member `%s'",
  1844.            IDENTIFIER_POINTER (DECL_NAME (field)));
  1845.       else
  1846.     {
  1847.       /* Element that is a bit-field.  */
  1848.  
  1849.       int next_offset = DECL_OFFSET (field);
  1850.       int end_offset
  1851.         = (next_offset
  1852.            + (TREE_INT_CST_LOW (DECL_SIZE (field))
  1853.           * DECL_SIZE_UNIT (field)));
  1854.  
  1855.       /* We must split the element into pieces that fall within
  1856.          separate bytes, and combine each byte with previous or
  1857.          following bit-fields.  */
  1858.  
  1859.       /* next_offset is the offset n fbits from the begining of
  1860.          the structure to the next bit of this element to be processed.
  1861.          end_offset is the offset of the first bit past the end of
  1862.          this element.  */
  1863.       while (next_offset < end_offset)
  1864.         {
  1865.           int this_time;
  1866.           int next_byte = next_offset / BITS_PER_UNIT;
  1867.           int next_bit = next_offset % BITS_PER_UNIT;
  1868.           if (byte_offset < 0)
  1869.         {
  1870.           byte_offset = next_byte;
  1871.           byte = 0;
  1872.         }
  1873.           else
  1874.         while (next_byte != byte_offset)
  1875.           {
  1876.             ASM_OUTPUT_BYTE (asm_out_file, byte);
  1877.             byte_offset++;
  1878.             total_bytes++;
  1879.             byte = 0;
  1880.           }
  1881.           /* Number of bits we can process at once
  1882.          (all part of the same byte).  */
  1883.           this_time = MIN (end_offset - next_offset,
  1884.                    BITS_PER_UNIT - next_bit);
  1885. #ifdef BYTES_BIG_ENDIAN
  1886.           /* On big-endian machine, take the most significant bits
  1887.          first (of the bits that are significant)
  1888.          and put them into bytes from the most significant end.  */
  1889.           byte |= (((TREE_INT_CST_LOW (val)
  1890.              >> (end_offset - next_offset - this_time))
  1891.             & ((1 << this_time) - 1))
  1892.                << (BITS_PER_UNIT - this_time - next_bit));
  1893. #else
  1894.           /* On little-endian machines,
  1895.          take first the least significant bits of the value
  1896.          and pack them starting at the least significant
  1897.          bits of the bytes.  */
  1898.           byte |= ((TREE_INT_CST_LOW (val)
  1899.             >> (next_offset - DECL_OFFSET (field)))
  1900.                & ((1 << this_time) - 1)) << next_bit;
  1901. #endif
  1902.           next_offset += this_time;
  1903.         }
  1904.     }
  1905.     }
  1906.   if (byte_offset >= 0)
  1907.     {
  1908.       ASM_OUTPUT_BYTE (asm_out_file, byte);
  1909.       byte_offset = -1;
  1910.       total_bytes++;
  1911.     }
  1912.   if (total_bytes < size)
  1913.     ASM_OUTPUT_SKIP (asm_out_file, size - total_bytes);
  1914. }
  1915.