home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / NeXT / GnuSource / cc-61.0.1 / cc / varasm.c < prev    next >
C/C++ Source or Header  |  1991-09-23  |  74KB  |  2,627 lines

  1. /* Output variables, constants and external declarations, for GNU compiler.
  2.    Copyright (C) 1987-1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This file handles generation of all the assembler code
  22.    *except* the instructions of a function.
  23.    This includes declarations of variables and their initial values.
  24.  
  25.    We also output the assembler code for constants stored in memory
  26.    and are responsible for combining constants with the same value.  */
  27.  
  28. #include <stdio.h>
  29. #include <setjmp.h>
  30. /* #include <stab.h> */
  31. #include "config.h"
  32. #include "rtl.h"
  33. #include "tree.h"
  34. #include "flags.h"
  35. #include "expr.h"
  36. #include "hard-reg-set.h"
  37. #include "regs.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. /* The (assembler) name of the first globally-visible object output.  */
  48. char *first_global_object_name;
  49.  
  50. extern struct obstack *current_obstack;
  51. extern struct obstack *saveable_obstack;
  52. extern struct obstack permanent_obstack;
  53. #define obstack_chunk_alloc xmalloc
  54. extern int xmalloc ();
  55.  
  56. /* Number for making the label on the next
  57.    constant that is stored in memory.  */
  58.  
  59. int const_labelno;
  60.  
  61. /* Number for making the label on the next
  62.    static variable internal to a function.  */
  63.  
  64. int var_labelno;
  65.  
  66. /* Nonzero if at least one function definition has been seen.  */
  67. static int function_defined;
  68.  
  69. extern FILE *asm_out_file;
  70.  
  71. static char *compare_constant_1 ();
  72. static void record_constant_1 ();
  73. void output_constant_pool ();
  74. void assemble_name ();
  75. int output_addressed_constants ();
  76. void output_constant ();
  77. void output_constructor ();
  78.  
  79. #ifdef EXTRA_SECTIONS
  80. static enum in_section {no_section, in_text, in_data, EXTRA_SECTIONS} in_section
  81.   = no_section;
  82. #else
  83. static enum in_section {no_section, in_text, in_data} in_section
  84.   = no_section;
  85. #endif
  86.  
  87. /* Define functions like text_section for any extra sections.  */
  88. #ifdef EXTRA_SECTION_FUNCTIONS
  89. EXTRA_SECTION_FUNCTIONS
  90. #endif
  91.  
  92. /* Tell assembler to switch to text section.  */
  93.  
  94. void
  95. text_section ()
  96. {
  97.   if (in_section != in_text)
  98.     {
  99.       fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
  100.       in_section = in_text;
  101.     }
  102. }
  103.  
  104. /* Tell assembler to switch to read-only data section.  This is normally
  105.    the text section.  */
  106.  
  107. void
  108. readonly_data_section ()
  109. {
  110. #ifdef READONLY_DATA_SECTION
  111.   READONLY_DATA_SECTION ();
  112. #else
  113.   text_section ();
  114. #endif
  115. }
  116.  
  117. /* Tell assembler to switch to data section.  */
  118.  
  119. void
  120. data_section ()
  121. {
  122.   if (in_section != in_data)
  123.     {
  124.       if (flag_shared_data)
  125.     {
  126. #ifdef SHARED_SECTION_ASM_OP
  127.       fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
  128. #else
  129.       fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
  130. #endif
  131.     }
  132.       else
  133.     fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
  134.  
  135.       in_section = in_data;
  136.     }
  137. }
  138.  
  139. /* Determine if we're in the text section. */
  140.  
  141. int
  142. in_text_section ()
  143. {
  144.   return in_section == in_text;
  145. }
  146.  
  147. /* Create the rtl to represent a function, for a function definition.
  148.    DECL is a FUNCTION_DECL node which describes which function.
  149.    The rtl is stored into DECL.  */
  150.  
  151. void
  152. make_function_rtl (decl)
  153.      tree decl;
  154. {
  155.   /* Rename a nested function to avoid conflicts.  */
  156.   if (decl_function_context (decl) != 0
  157.       && DECL_INITIAL (decl) != 0
  158.       && DECL_RTL (decl) == 0)
  159.     {
  160.       char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
  161.       char *label;
  162.  
  163.       ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
  164.       DECL_ASSEMBLER_NAME (decl)
  165.     = obstack_copy0 (saveable_obstack, label, strlen (label));
  166.       var_labelno++;
  167.     }
  168.  
  169.   if (DECL_RTL (decl) == 0)
  170.     {
  171.       char *name = DECL_ASSEMBLER_NAME (decl);
  172.  
  173.       DECL_RTL (decl)
  174.     = gen_rtx (MEM, DECL_MODE (decl),
  175.            gen_rtx (SYMBOL_REF, Pmode, name));
  176.  
  177.       /* Optionally set flags or add text to the name to record information
  178.      such as that it is a function name.  If the name is changed, the macro
  179.      ASM_OUTPUT_LABELREF will have to know how to strip this information.
  180.      And if it finds a * at the beginning after doing so, it must handle
  181.      that too.  */
  182. #ifdef ENCODE_SEGMENT_INFO
  183.       ENCODE_SEGMENT_INFO (decl);
  184. #endif
  185.     }
  186.  
  187.   /* Record at least one function has been defined.  */
  188.   function_defined = 1;
  189. }
  190.  
  191. /* Decode an `asm' spec for a declaration as a register name.
  192.    Return the register number, or -1 if nothing specified,
  193.    or -2 if the name is not a register.  */
  194.  
  195. int
  196. decode_reg_name (asmspec)
  197.      char *asmspec;
  198. {
  199.   if (asmspec != 0)
  200.     {
  201.       int i;
  202.  
  203.       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  204.     if (!strcmp (asmspec, reg_names[i]))
  205.       return i;
  206.  
  207.       if (asmspec[0] == '%')
  208.     for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
  209.       if (!strcmp (asmspec + 1, reg_names[i]))
  210.         return i;
  211.  
  212. #ifdef ADDITIONAL_REGISTER_NAMES
  213.       {
  214.     static struct { char *name; int number; } table[]
  215.       = ADDITIONAL_REGISTER_NAMES;
  216.  
  217.     for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
  218.       if (! strcmp (asmspec, table[i].name))
  219.         return table[i].number;
  220.  
  221.     if (asmspec[0] == '%')
  222.       for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
  223.         if (! strcmp (asmspec + 1, table[i].name))
  224.           return table[i].number;
  225.       }
  226. #endif /* ADDITIONAL_REGISTER_NAMES */
  227.  
  228.       return -2;
  229.     }
  230.  
  231.   return -1;
  232. }
  233.  
  234. /* Create the DECL_RTL for a declaration for a static or external variable
  235.    or static or external function.
  236.    ASMSPEC, if not 0, is the string which the user specified
  237.    as the assembler symbol name.
  238.    TOP_LEVEL is nonzero if this is a file-scope variable.
  239.  
  240.    This is never called for PARM_DECL nodes.  */
  241.  
  242. void
  243. make_decl_rtl (decl, asmspec, top_level)
  244.      tree decl;
  245.      char *asmspec;
  246.      int top_level;
  247. {
  248.   register char *name = DECL_ASSEMBLER_NAME (decl);
  249.   int reg_number = decode_reg_name (asmspec);
  250.  
  251.   if (reg_number == -2)
  252.     {
  253.       /* ASMSPEC is given, and not the name of a register.  */
  254.       name = (char *) obstack_alloc (saveable_obstack,
  255.                      strlen (asmspec) + 2);
  256.       name[0] = '*';
  257.       strcpy (&name[1], asmspec);
  258.     }
  259.  
  260.   /* For a duplicate declaration, we can be called twice on the
  261.      same DECL node.  Don't alter the RTL already made
  262.      unless the old mode is wrong (which can happen when
  263.      the previous rtl was made when the type was incomplete).  */
  264.   if (DECL_RTL (decl) == 0
  265.       || GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
  266.     {
  267.       DECL_RTL (decl) = 0;
  268.  
  269.       /* First detect errors in declaring global registers.  */
  270.       if (TREE_REGDECL (decl) && reg_number == -1)
  271.     error_with_decl (decl,
  272.              "register name not specified for `%s'");
  273.       else if (TREE_REGDECL (decl) && reg_number == -2)
  274.     error_with_decl (decl,
  275.              "invalid register name for `%s'");
  276.       else if (reg_number >= 0 && ! TREE_REGDECL (decl))
  277.     error_with_decl (decl,
  278.              "register name given for non-register variable `%s'");
  279.       else if (TREE_REGDECL (decl) && TREE_CODE (decl) == FUNCTION_DECL)
  280.     error ("function declared `register'");
  281.       else if (TREE_REGDECL (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
  282.     error_with_decl (decl, "data type of `%s' isn't suitable for a register");
  283.       /* Now handle properly declared static register variables.  */
  284.       else if (TREE_REGDECL (decl))
  285.     {
  286.       int nregs;
  287.       if (pedantic)
  288.         pedwarn ("ANSI C forbids global register variables");
  289.       if (DECL_INITIAL (decl) != 0)
  290.         {
  291.           DECL_INITIAL (decl) = 0;
  292.           error ("global register variable has initial value");
  293.         }
  294.       if (fixed_regs[reg_number] == 0
  295.           && function_defined && top_level)
  296.         error ("global register variable follows a function definition");
  297.       if (TREE_THIS_VOLATILE (decl))
  298.         warning ("volatile register variables don't work as you might wish");
  299.       DECL_RTL (decl) = gen_rtx (REG, DECL_MODE (decl), reg_number);
  300.       if (top_level)
  301.         {
  302.           /* Make this register fixed, so not usable for anything else.  */
  303.           nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
  304.           while (nregs > 0)
  305.         global_regs[reg_number + --nregs] = 1;
  306.           init_reg_sets_1 ();
  307.         }
  308.     }
  309.  
  310.       /* Now handle ordinary static variables and functions (in memory).
  311.      Also handle vars declared register invalidly.  */
  312.       if (DECL_RTL (decl) == 0)
  313.     {
  314.       /* Can't use just the variable's own name for a variable
  315.          whose scope is less than the whole file.
  316.          Concatenate a distinguishing number.  */
  317.       if (!top_level && !TREE_EXTERNAL (decl) && asmspec == 0)
  318.         {
  319.           char *label;
  320.  
  321.           ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
  322.           name = obstack_copy0 (saveable_obstack, label, strlen (label));
  323.           var_labelno++;
  324.         }
  325.  
  326.       DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
  327.                      gen_rtx (SYMBOL_REF, Pmode, name));
  328.       if (TREE_THIS_VOLATILE (decl))
  329.         MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
  330.       if (TREE_READONLY (decl))
  331.         RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
  332.       MEM_IN_STRUCT_P (DECL_RTL (decl))
  333.         = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  334.            || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
  335.            || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
  336.  
  337.       /* Optionally set flags or add text to the name to record information
  338.          such as that it is a function name.
  339.          If the name is changed, the macro ASM_OUTPUT_LABELREF
  340.          will have to know how to strip this information.
  341.          And if it finds a * at the beginning after doing so,
  342.          it must handle that too.  */
  343. #ifdef ENCODE_SEGMENT_INFO
  344.       ENCODE_SEGMENT_INFO (decl);
  345. #endif
  346.     }
  347.     }
  348. }
  349.  
  350. /* Output a string of literal assembler code
  351.    for an `asm' keyword used between functions.  */
  352.  
  353. void
  354. assemble_asm (string)
  355.      tree string;
  356. {
  357.   app_enable ();
  358.  
  359.   fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
  360. }
  361.  
  362. /* Tiemann: please get rid of this conditional and put appropriate
  363.    definitions in each of the files that should have them.
  364.    The type of debugging format is not the right parameter to
  365.    control how some other aspect of assembler output is done.  */
  366.  
  367. #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
  368. #ifndef ASM_OUTPUT_CONSTRUCTOR
  369. #define ASM_OUTPUT_CONSTRUCTOR(file, name)
  370. #endif
  371. #ifndef ASM_OUTPUT_DESTRUCTOR
  372. #define ASM_OUTPUT_DESTRUCTOR(file, name)
  373. #endif
  374. #endif
  375.  
  376. /* Record an element in the table of global destructors.
  377.    How this is done depends on what sort of assembler and linker
  378.    are in use.  */
  379.  
  380. void
  381. assemble_destructor (name)
  382.      char *name;
  383. {
  384. #ifdef ASM_OUTPUT_DESTRUCTOR
  385.   ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
  386. #else
  387.   /* Now tell GNU LD that this is part of the static destructor set.  */
  388.   fprintf (asm_out_file, ".stabs \"___DTOR_LIST__\",22,0,0,");
  389.   assemble_name (asm_out_file, name);
  390.   fputc ('\n', asm_out_file);
  391. #endif
  392. }
  393.  
  394. /* Likewise for global constructors.  */
  395.  
  396. void
  397. assemble_constructor (name)
  398.      char *name;
  399. {
  400. #ifdef ASM_OUTPUT_CONSTRUCTOR
  401.   ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
  402. #else
  403.   /* Now tell GNU LD that this is part of the static destructor set.  */
  404.   fprintf (asm_out_file, ".stabs \"___CTOR_LIST__\",22,0,0,");
  405.   assemble_name (asm_out_file, name);
  406.   fputc ('\n', asm_out_file);
  407. #endif
  408. }
  409.  
  410. /* Output assembler code for the constant pool of a function and associated
  411.    with defining the name of the function.  DECL describes the function.
  412.    For the constant pool, we use the current constant pool data.  */
  413.  
  414. void
  415. assemble_function (decl)
  416.      tree decl;
  417. {
  418.   rtx x, n;
  419.   char *fnname;
  420.   int align;
  421.  
  422.   /* Get the function's name, as described by its RTL.
  423.      This may be different from the DECL_NAME name used in the source file.  */
  424.  
  425.   x = DECL_RTL (decl);
  426.   if (GET_CODE (x) != MEM)
  427.     abort ();
  428.   n = XEXP (x, 0);
  429.   if (GET_CODE (n) != SYMBOL_REF)
  430.     abort ();
  431.   fnname = XSTR (n, 0);
  432.  
  433.   /* The following code does not need preprocessing in the assembler.  */
  434.  
  435.   app_disable ();
  436.  
  437.   output_constant_pool (fnname, decl);
  438.  
  439.   text_section ();
  440.  
  441. #ifdef SDB_DEBUGGING_INFO
  442.   /* Make sure types are defined for debugger before fcn name is defined.  */
  443.   if (write_symbols == SDB_DEBUG)
  444.     sdbout_tags (gettags ());
  445. #endif
  446.  
  447.   /* Tell assembler to move to target machine's alignment for functions.  */
  448.  
  449.   align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  450.   if (align > 0)
  451.     ASM_OUTPUT_ALIGN (asm_out_file, align);
  452.  
  453. #ifdef SDB_DEBUGGING_INFO
  454.   /* Output SDB definition of the function.  */
  455.   if (write_symbols == SDB_DEBUG)
  456.     sdbout_mark_begin_function ();
  457. #endif
  458.  
  459.   /* Make function name accessible from other files, if appropriate.  */
  460.  
  461.   if (TREE_PUBLIC (decl))
  462.     {
  463.       if (!first_global_object_name)
  464.     first_global_object_name = fnname + (fnname[0] == '*');
  465.       ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
  466.     }
  467.  
  468.   /* Do any machine/system dependent processing of the function name */
  469. #ifdef ASM_DECLARE_FUNCTION_NAME
  470.   ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
  471. #else
  472.   /* Standard thing is just output label for the function.  */
  473.   ASM_OUTPUT_LABEL (asm_out_file, fnname);
  474. #endif /* ASM_DECLARE_FUNCTION_NAME */
  475. }
  476.  
  477. /* Assemble " .int 0\n" or whatever this assembler wants.  */
  478.  
  479. void
  480. assemble_integer_zero ()
  481. {
  482.   ASM_OUTPUT_INT (asm_out_file, const0_rtx);
  483. }
  484.  
  485. /* Assemble code to leave SIZE bytes of zeros.  */
  486.  
  487. void
  488. assemble_zeros (size)
  489.      int size;
  490. {
  491. #ifdef ASM_NO_SKIP_IN_TEXT
  492.   /* The `space' pseudo in the text segment outputs nop insns rather than 0s,
  493.      so we must output 0s explicitly in the text segment.  */
  494.   if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
  495.     {
  496.       int i;
  497.  
  498.       for (i = 0; i < size - 20; i += 20)
  499.     {
  500. #ifdef ASM_BYTE_OP
  501.       fprintf (asm_out_file,
  502.            "%s 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ASM_BYTE_OP);
  503. #else
  504.       fprintf (asm_out_file,
  505.            "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
  506. #endif
  507.     }
  508.       if (i < size)
  509.         {
  510. #ifdef ASM_BYTE_OP
  511.       fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
  512. #else
  513.       fprintf (asm_out_file, "\tbyte 0");
  514. #endif
  515.       i++;
  516.       for (; i < size; i++)
  517.         fprintf (asm_out_file, ",0");
  518.       fprintf (asm_out_file, "\n");
  519.     }
  520.     }
  521.   else
  522. #endif
  523.     ASM_OUTPUT_SKIP (asm_out_file, size);
  524. }
  525.  
  526. /* Assemble a string constant with the specified C string as contents.  */
  527.  
  528. void
  529. assemble_string (p, size)
  530.      unsigned char *p;
  531.      int size;
  532. {
  533.   register int i;
  534.   int pos = 0;
  535.   int maximum = 2000;
  536.  
  537.   /* If the string is very long, split it up.  */
  538.  
  539.   while (pos < size)
  540.     {
  541.       int thissize = size - pos;
  542.       if (thissize > maximum)
  543.     thissize = maximum;
  544.  
  545. #ifdef ASM_OUTPUT_ASCII
  546.       ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
  547. #else
  548.       fprintf (asm_out_file, "\t.ascii \"");
  549.  
  550.       for (i = 0; i < thissize; i++)
  551.     {
  552.       register int c = p[i];
  553.       if (c == '\"' || c == '\\')
  554.         putc ('\\', asm_out_file);
  555.       if (c >= ' ' && c < 0177)
  556.         putc (c, asm_out_file);
  557.       else
  558.         {
  559.           fprintf (asm_out_file, "\\%o", c);
  560.           /* After an octal-escape, if a digit follows,
  561.          terminate one string constant and start another.
  562.          The Vax assembler fails to stop reading the escape
  563.          after three digits, so this is the only way we
  564.          can get it to parse the data properly.  */
  565.           if (i < thissize - 1
  566.           && p[i + 1] >= '0' && p[i + 1] <= '9')
  567.         fprintf (asm_out_file, "\"\n\t.ascii \"");
  568.         }
  569.     }
  570.       fprintf (asm_out_file, "\"\n");
  571. #endif /* no ASM_OUTPUT_ASCII */
  572.  
  573.       pos += thissize;
  574.       p += thissize;
  575.     }
  576. }
  577.  
  578. /* Assemble everything that is needed for a variable or function declaration.
  579.    Not used for automatic variables, and not used for function definitions.
  580.    Should not be called for variables of incomplete structure type.
  581.  
  582.    TOP_LEVEL is nonzero if this variable has file scope.
  583.    WRITE_SYMBOLS is DBX_DEBUG if writing dbx symbol output.
  584.    The dbx data for a file-scope variable is written here.
  585.    AT_END is nonzero if this is the special handling, at end of compilation,
  586.    to define things that have had only tentative definitions.  */
  587.  
  588. void
  589. assemble_variable (decl, top_level, write_symbols, at_end)
  590.      tree decl;
  591.      int top_level;
  592.      enum debugger write_symbols;
  593.      int at_end;
  594. {
  595.   register char *name;
  596.   int align;
  597.   tree size_tree;
  598.   int reloc = 0;
  599.  
  600.   if (GET_CODE (DECL_RTL (decl)) == REG)
  601.     {
  602.       /* Do output symbol info for global register variables, but do nothing
  603.      else for them.  */
  604. #ifdef DBX_DEBUGGING_INFO
  605.       /* File-scope global variables are output here.  */
  606.       if (write_symbols == DBX_DEBUG && top_level)
  607.     dbxout_symbol (decl, 0);
  608. #endif
  609. #ifdef SDB_DEBUGGING_INFO
  610.       if (write_symbols == SDB_DEBUG && top_level
  611.       /* Leave initialized global vars for end of compilation;
  612.          see comment in compile_file.  */
  613.       && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
  614.     sdbout_symbol (decl, 0);
  615. #endif
  616.  
  617.       return;
  618.     }
  619.  
  620.   /* Normally no need to say anything for external references,
  621.      since assembler considers all undefined symbols external.  */
  622.  
  623.   if (TREE_EXTERNAL (decl))
  624.     return;
  625.  
  626.   /* Output no assembler code for a function declaration.
  627.      Only definitions of functions output anything.  */
  628.  
  629.   if (TREE_CODE (decl) == FUNCTION_DECL)
  630.     return;
  631.  
  632.   /* If type was incomplete when the variable was declared,
  633.      see if it is complete now.  */
  634.  
  635.   if (DECL_SIZE (decl) == 0)
  636.     layout_decl (decl, 0);
  637.  
  638.   /* Still incomplete => don't allocate it; treat the tentative defn
  639.      (which is what it must have been) as an `extern' reference.  */
  640.  
  641.   if (DECL_SIZE (decl) == 0)
  642.     {
  643.       error_with_file_and_line (DECL_SOURCE_FILE (decl),
  644.                 DECL_SOURCE_LINE (decl),
  645.                 "storage size of static var `%s' isn't known",
  646.                 IDENTIFIER_POINTER (DECL_NAME (decl)));
  647.       return;
  648.     }
  649.  
  650.   /* The first declaration of a variable that comes through this function
  651.      decides whether it is global (in C, has external linkage)
  652.      or local (in C, has internal linkage).  So do nothing more
  653.      if this function has already run.  */
  654.  
  655.   if (TREE_ASM_WRITTEN (decl))
  656.     return;
  657.  
  658.   TREE_ASM_WRITTEN (decl) = 1;
  659.  
  660. #ifdef DBX_DEBUGGING_INFO
  661.   /* File-scope global variables are output here.  */
  662.   if (write_symbols == DBX_DEBUG && top_level)
  663.     dbxout_symbol (decl, 0);
  664. #endif
  665. #ifdef SDB_DEBUGGING_INFO
  666.   if (write_symbols == SDB_DEBUG && top_level
  667.       /* Leave initialized global vars for end of compilation;
  668.      see comment in compile_file.  */
  669.       && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
  670.     sdbout_symbol (decl, 0);
  671. #endif
  672. #ifdef DWARF_DEBUGGING_INFO
  673.   if (write_symbols == DWARF_DEBUG && top_level)
  674.     dwarfout_file_scope_symbol (decl, 0);
  675. #endif
  676.  
  677.   /* If storage size is erroneously variable, just continue.
  678.      Error message was already made.  */
  679.  
  680.   if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
  681.     return;
  682.  
  683.   app_disable ();
  684.  
  685.   /* This is better than explicit arithmetic, since it avoids overflow.  */
  686.   size_tree = size_binop (CEIL_DIV_EXPR,
  687.               DECL_SIZE (decl), size_int (BITS_PER_UNIT));
  688.  
  689.   if (TREE_INT_CST_HIGH (size_tree) != 0)
  690.     {
  691.       error_with_decl (decl, "size of variable `%s' is too large");
  692.       return;
  693.     }
  694.  
  695.   name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
  696.  
  697.   /* Handle uninitialized definitions.  */
  698.  
  699.   /* ANSI specifies that a tentative definition which is not merged with
  700.      a non-tentative definition behaves exactly like a definition with an
  701.      initializer equal to zero.  (Section 3.7.2)
  702.      -fno-common gives strict ANSI behavior.  Usually you don't want it.  */
  703.   if (! flag_no_common
  704.       && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
  705.     {
  706.       int size = TREE_INT_CST_LOW (size_tree);
  707.       int rounded = size;
  708.  
  709.       if (TREE_INT_CST_HIGH (size_tree) != 0)
  710.     error_with_decl (decl, "size of variable `%s' is too large");
  711.       /* Don't allocate zero bytes of common,
  712.      since that means "undefined external" in the linker.  */
  713.       if (size == 0) rounded = 1;
  714.       /* Round size up to multiple of BIGGEST_ALIGNMENT bits
  715.      so that each uninitialized object starts on such a boundary.  */
  716.       rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
  717.       rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
  718.          * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  719. #if 0
  720.       if (flag_shared_data)
  721.     data_section ();
  722. #endif
  723.       if (TREE_PUBLIC (decl))
  724.     {
  725. #ifdef ASM_OUTPUT_SHARED_COMMON
  726.       if (flag_shared_data)
  727.         ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
  728.       else
  729. #endif
  730.         ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
  731.     }
  732.       else
  733.     {
  734. #ifdef ASM_OUTPUT_SHARED_LOCAL
  735.       if (flag_shared_data)
  736.         ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
  737.       else
  738. #endif
  739. #ifdef ASM_OUTPUT_ALIGNED_LOCAL
  740.         ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
  741.                       DECL_ALIGN (decl));
  742. #else
  743.         ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
  744. #endif
  745.     }
  746.       return;
  747.     }
  748.  
  749.   /* Handle initialized definitions.  */
  750.  
  751.   /* First make the assembler name(s) global if appropriate.  */
  752.   if (TREE_PUBLIC (decl) && DECL_NAME (decl))
  753.     {
  754.       if (!first_global_object_name)
  755.     first_global_object_name = name + (name[0] == '*');
  756.       ASM_GLOBALIZE_LABEL (asm_out_file, name);
  757.     }
  758. #if 0
  759.   for (d = equivalents; d; d = TREE_CHAIN (d))
  760.     {
  761.       tree e = TREE_VALUE (d);
  762.       if (TREE_PUBLIC (e) && DECL_NAME (e))
  763.     ASM_GLOBALIZE_LABEL (asm_out_file,
  764.                  XSTR (XEXP (DECL_RTL (e), 0), 0));
  765.     }
  766. #endif
  767.  
  768.   /* Output any data that we will need to use the address of.  */
  769.   if (DECL_INITIAL (decl))
  770.     reloc = output_addressed_constants (DECL_INITIAL (decl));
  771.  
  772.   /* Switch to the proper section for this data.  */
  773. #ifdef SELECT_SECTION
  774.   SELECT_SECTION (decl, reloc);
  775. #else
  776.   if (TREE_READONLY (decl)
  777.       && ! TREE_THIS_VOLATILE (decl)
  778.       && ! (flag_pic && reloc))
  779.     readonly_data_section ();
  780.   else
  781.     data_section ();
  782. #endif
  783.  
  784.   /* Compute and output the alignment of this data.  */
  785.  
  786.   align = DECL_ALIGN (decl);
  787.   /* Some object file formats have a maximum alignment which they support.
  788.      In particular, a.out format supports a maximum alignment of 4.  */
  789. #ifndef MAX_OFILE_ALIGNMENT
  790. #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
  791. #endif
  792.   if (align > MAX_OFILE_ALIGNMENT)
  793.     {
  794.       warning_with_decl (decl,
  795.       "alignment of `%s' is greater than maximum object file alignment");
  796.       align = MAX_OFILE_ALIGNMENT;
  797.     }
  798. #ifdef DATA_ALIGNMENT
  799.   /* On some machines, it is good to increase alignment sometimes.  */
  800.   align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
  801. #endif
  802. #ifdef CONSTANT_ALIGNMENT
  803.   if (DECL_INITIAL (decl))
  804.     align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
  805. #endif
  806.  
  807.   /* Reset the alignment in case we have made it tighter, so we can benefit
  808.      from it in get_pointer_alignment.  */
  809.   DECL_ALIGN (decl) = align;
  810.  
  811.   if (align > BITS_PER_UNIT)
  812.     ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
  813.  
  814.   /* Do any machine/system dependent processing of the object */
  815. #ifdef ASM_DECLARE_OBJECT_NAME
  816.   ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
  817. #else
  818.   /* Standard thing is just output label for the object.  */
  819.   ASM_OUTPUT_LABEL (asm_out_file, name);
  820. #endif /* ASM_DECLARE_OBJECT_NAME */
  821.  
  822. #if 0
  823.   for (d = equivalents; d; d = TREE_CHAIN (d))
  824.     {
  825.       tree e = TREE_VALUE (d);
  826.       ASM_OUTPUT_LABEL (asm_out_file, XSTR (XEXP (DECL_RTL (e), 0), 0));
  827.     }
  828. #endif
  829.  
  830.   if (DECL_INITIAL (decl))
  831.     /* Output the actual data.  */
  832.     output_constant (DECL_INITIAL (decl),
  833.              int_size_in_bytes (TREE_TYPE (decl)));
  834.   else
  835.     /* Leave space for it.  */
  836.     assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
  837. }
  838.  
  839. /* Output something to declare an external symbol to the assembler.
  840.    (Most assemblers don't need this, so we normally output nothing.)  */
  841.  
  842. void
  843. assemble_external (decl)
  844.      tree decl;
  845. {
  846.   rtx rtl = DECL_RTL (decl);
  847.  
  848. #ifdef ASM_OUTPUT_EXTERNAL
  849.   if (TREE_PUBLIC (decl)
  850.       && GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF)
  851.     {
  852.       /* Some systems do require some output.  */
  853.       ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
  854.     }
  855. #endif
  856. }
  857.  
  858. /* Similar, for calling a library function FUN.  */
  859.  
  860. void
  861. assemble_external_libcall (fun)
  862.      rtx fun;
  863. {
  864. #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
  865.   /* Declare library function name external when first used, if nec.  */
  866.   if (!SYMBOL_REF_USED (fun))
  867.     {
  868.       SYMBOL_REF_USED (fun) = 1;
  869.       ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
  870.     }
  871. #endif
  872. }
  873.  
  874. /* Output to FILE a reference to the assembler name of a C-level name NAME.
  875.    If NAME starts with a *, the rest of NAME is output verbatim.
  876.    Otherwise NAME is transformed in an implementation-defined way
  877.    (usually by the addition of an underscore).
  878.    Many macros in the tm file are defined to call this function.  */
  879.  
  880. void
  881. assemble_name (file, name)
  882.      FILE *file;
  883.      char *name;
  884. {
  885.   if (name[0] == '*')
  886.     fputs (&name[1], file);
  887.   else
  888.     ASM_OUTPUT_LABELREF (file, name);
  889. }
  890.  
  891. /* Allocate SIZE bytes writable static space with a gensym name
  892.    and return an RTX to refer to its address.  */
  893.  
  894. rtx
  895. assemble_static_space (size)
  896.      int size;
  897. {
  898.   char name[12];
  899.   char *namestring;
  900.   rtx x;
  901.   /* Round size up to multiple of BIGGEST_ALIGNMENT bits
  902.      so that each uninitialized object starts on such a boundary.  */
  903.   int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
  904.          / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
  905.          * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  906.  
  907. #if 0
  908.   if (flag_shared_data)
  909.     data_section ();
  910. #endif
  911.  
  912.   ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
  913.   ++const_labelno;
  914.  
  915.   namestring = (char *) obstack_alloc (saveable_obstack,
  916.                        strlen (name) + 2);
  917.   strcpy (namestring, name);
  918.  
  919.   x = gen_rtx (SYMBOL_REF, Pmode, namestring);
  920. #ifdef ASM_OUTPUT_ALIGNED_LOCAL
  921.   ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
  922. #else
  923.   ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
  924. #endif
  925.   return x;
  926. }
  927.  
  928. /* Assemble the static constant template for function entry trampolines.
  929.    This is done at most once per compilation.
  930.    Returns an RTX for the address of the template.  */
  931.  
  932. rtx
  933. assemble_trampoline_template ()
  934. {
  935.   char label[256];
  936.   char *name;
  937.   int align;
  938.  
  939.   /* Write the assembler code to define one.  */
  940.   align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
  941.   if (align > 0)
  942.     ASM_OUTPUT_ALIGN (asm_out_file, align);
  943.  
  944.   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
  945.   TRAMPOLINE_TEMPLATE (asm_out_file);
  946.  
  947.   /* Record the rtl to refer to it.  */
  948.   ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
  949.   name
  950.     = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
  951.   return gen_rtx (SYMBOL_REF, Pmode, name);
  952. }
  953.  
  954. /* Here we combine duplicate floating constants to make
  955.    CONST_DOUBLE rtx's, and force those out to memory when necessary.  */
  956.  
  957. /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
  958.    They are chained through the CONST_DOUBLE_CHAIN.
  959.    A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
  960.    In that case, CONST_DOUBLE_MEM is either a MEM,
  961.    or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.  */
  962.  
  963. static rtx const_double_chain;
  964.  
  965. /* Return a CONST_DOUBLE for a value specified as a pair of ints.
  966.    For an integer, I0 is the low-order word and I1 is the high-order word.
  967.    For a real number, I0 is the word with the low address
  968.    and I1 is the word with the high address.  */
  969.  
  970. rtx
  971. immed_double_const (i0, i1, mode)
  972.      int i0, i1;
  973.      enum machine_mode mode;
  974. {
  975.   register rtx r;
  976.   int in_current_obstack;
  977.  
  978.   if (GET_MODE_CLASS (mode) == MODE_INT)
  979.     {
  980.       /* We clear out all bits that don't belong in MODE, unless they and our
  981.      sign bit are all one.  So we get either a reasonable negative value
  982.      or a reasonable unsigned value for this mode.  */
  983.       int width = GET_MODE_BITSIZE (mode);
  984.       if (width < HOST_BITS_PER_INT
  985.       && ((i0 & ((-1) << (width - 1))) != ((-1) << (width - 1))))
  986.     i0 &= (1 << width) - 1, i1 = 0;
  987.       else if (width == HOST_BITS_PER_INT
  988.            && ! (i1 == ~0 && i0 < 0))
  989.     i1 = 0;
  990.       else if (width > 2 * HOST_BITS_PER_INT)
  991.     /* We cannot represent this value as a constant.  */
  992.     abort ();
  993.  
  994.       /* If MODE fits within BITS_PER_WORD, always use a CONST_INT.
  995.  
  996.      ??? Strictly speaking, this is wrong if we create a CONST_INT
  997.      for a large unsigned constant with the size of MODE being
  998.      BITS_PER_WORD and later try to interpret that constant in a wider
  999.      mode.  In that case we will mis-interpret it as a negative number.
  1000.  
  1001.      Unfortunately, the only alternative is to make a CONST_DOUBLE
  1002.      for any constant in any mode if it is an unsigned constant larger
  1003.      than the maximum signed integer in an int on the host.  However,
  1004.      doing this will break everyone that always expects to see a CONST_INT
  1005.      for SImode and smaller.
  1006.  
  1007.      We have always been making CONST_INTs in this case, so nothing new
  1008.      is being broken.  */
  1009.  
  1010.       if (width <= BITS_PER_WORD)
  1011.     i1 = (i0 < 0) ? ~0 : 0;
  1012.  
  1013.       /* If this integer fits in one word, return a CONST_INT.  */
  1014.       if ((i1 == 0 && i0 >= 0)
  1015.       || (i1 == ~0 && i0 < 0))
  1016.     return gen_rtx (CONST_INT, VOIDmode, i0);
  1017.  
  1018.       /* We use VOIDmode for integers.  */
  1019.       mode = VOIDmode;
  1020.     }
  1021.  
  1022.   /* Search the chain for an existing CONST_DOUBLE with the right value.
  1023.      If one is found, return it.  */
  1024.  
  1025.   for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
  1026.     if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
  1027.     && GET_MODE (r) == mode)
  1028.       return r;
  1029.  
  1030.   /* No; make a new one and add it to the chain.
  1031.  
  1032.      We may be called by an optimizer which may be discarding any memory
  1033.      allocated during its processing (such as combine and loop).  However,
  1034.      we will be leaving this constant on the chain, so we cannot tolerate
  1035.      freed memory.  So switch to saveable_obstack for this allocation
  1036.      and then switch back if we were in current_obstack.  */
  1037.  
  1038.   in_current_obstack = rtl_in_saveable_obstack ();
  1039.   r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
  1040.   if (in_current_obstack)
  1041.     rtl_in_current_obstack ();
  1042.  
  1043.   CONST_DOUBLE_CHAIN (r) = const_double_chain;
  1044.   const_double_chain = r;
  1045.  
  1046.   /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
  1047.      Actual use of mem-slot is only through force_const_mem.  */
  1048.  
  1049.   CONST_DOUBLE_MEM (r) = const0_rtx;
  1050.  
  1051.   return r;
  1052. }
  1053.  
  1054. /* Return a CONST_DOUBLE for a specified `double' value
  1055.    and machine mode.  */
  1056.  
  1057. rtx
  1058. immed_real_const_1 (d, mode)
  1059.      REAL_VALUE_TYPE d;
  1060.      enum machine_mode mode;
  1061. {
  1062.   union real_extract u;
  1063.   register rtx r;
  1064.   int in_current_obstack;
  1065.  
  1066.   /* Get the desired `double' value as a sequence of ints
  1067.      since that is how they are stored in a CONST_DOUBLE.  */
  1068.  
  1069.   u.d = d;
  1070.  
  1071.   /* Detect special cases.  */
  1072.  
  1073.   if (REAL_VALUES_EQUAL (dconst0, d))
  1074.     return (mode == DFmode ? dconst0_rtx : fconst0_rtx);
  1075.   else if (REAL_VALUES_EQUAL (dconst1, d))
  1076.     return (mode == DFmode ? dconst1_rtx : fconst1_rtx);
  1077.  
  1078.   if (sizeof u == 2 * sizeof (int))
  1079.     return immed_double_const (u.i[0], u.i[1], mode);
  1080.  
  1081.   /* The rest of this function handles the case where
  1082.      a float value requires more than 2 ints of space.
  1083.      It will be deleted as dead code on machines that don't need it.  */
  1084.  
  1085.   /* Search the chain for an existing CONST_DOUBLE with the right value.
  1086.      If one is found, return it.  */
  1087.  
  1088.   for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
  1089.     if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
  1090.     && GET_MODE (r) == mode)
  1091.       return r;
  1092.  
  1093.   /* No; make a new one and add it to the chain.
  1094.  
  1095.      We may be called by an optimizer which may be discarding any memory
  1096.      allocated during its processing (such as combine and loop).  However,
  1097.      we will be leaving this constant on the chain, so we cannot tolerate
  1098.      freed memory.  So switch to saveable_obstack for this allocation
  1099.      and then switch back if we were in current_obstack.  */
  1100.  
  1101.   in_current_obstack = rtl_in_saveable_obstack ();
  1102.   r = rtx_alloc (CONST_DOUBLE);
  1103.   PUT_MODE (r, mode);
  1104.   bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
  1105.   if (in_current_obstack)
  1106.     rtl_in_current_obstack ();
  1107.  
  1108.   CONST_DOUBLE_CHAIN (r) = const_double_chain;
  1109.   const_double_chain = r;
  1110.  
  1111.   /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
  1112.      chain, but has not been allocated memory.  Actual use of CONST_DOUBLE_MEM
  1113.      is only through force_const_mem.  */
  1114.  
  1115.   CONST_DOUBLE_MEM (r) = const0_rtx;
  1116.  
  1117.   return r;
  1118. }
  1119.  
  1120. /* Return a CONST_DOUBLE rtx for a value specified by EXP,
  1121.    which must be a REAL_CST tree node.  */
  1122.  
  1123. rtx
  1124. immed_real_const (exp)
  1125.      tree exp;
  1126. {
  1127.   return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
  1128. }
  1129.  
  1130. /* At the end of a function, forget the memory-constants
  1131.    previously made for CONST_DOUBLEs.  Mark them as not on real_constant_chain.
  1132.    Also clear out real_constant_chain and clear out all the chain-pointers.  */
  1133.  
  1134. void
  1135. clear_const_double_mem ()
  1136. {
  1137.   register rtx r, next;
  1138.  
  1139.   for (r = const_double_chain; r; r = next)
  1140.     {
  1141.       next = CONST_DOUBLE_CHAIN (r);
  1142.       CONST_DOUBLE_CHAIN (r) = 0;
  1143.       CONST_DOUBLE_MEM (r) = cc0_rtx;
  1144.     }
  1145.   const_double_chain = 0;
  1146. }
  1147.  
  1148. /* Given an expression EXP with a constant value,
  1149.    reduce it to the sum of an assembler symbol and an integer.
  1150.    Store them both in the structure *VALUE.
  1151.    Abort if EXP does not reduce.  */
  1152.  
  1153. struct addr_const
  1154. {
  1155.   rtx base;
  1156.   int offset;
  1157. };
  1158.  
  1159. static void
  1160. decode_addr_const (exp, value)
  1161.      tree exp;
  1162.      struct addr_const *value;
  1163. {
  1164.   register tree target = TREE_OPERAND (exp, 0);
  1165.   register int offset = 0;
  1166.   register rtx x;
  1167.  
  1168.   while (1)
  1169.     {
  1170.       if (TREE_CODE (target) == COMPONENT_REF
  1171.       && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
  1172.           == INTEGER_CST))
  1173.     {
  1174.       offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
  1175.       target = TREE_OPERAND (target, 0);
  1176.     }
  1177.       else if (TREE_CODE (target) == ARRAY_REF)
  1178.     {
  1179.       if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
  1180.           || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
  1181.         abort ();
  1182.       offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
  1183.               * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
  1184.              / BITS_PER_UNIT);
  1185.       target = TREE_OPERAND (target, 0);
  1186.     }
  1187.       else
  1188.     break;
  1189.     }
  1190.  
  1191.   switch (TREE_CODE (target))
  1192.     {
  1193.     case VAR_DECL:
  1194.     case FUNCTION_DECL:
  1195.       x = DECL_RTL (target);
  1196.       break;
  1197.  
  1198.     case REAL_CST:
  1199.     case STRING_CST:
  1200.     case COMPLEX_CST:
  1201.     case CONSTRUCTOR:
  1202.       x = TREE_CST_RTL (target);
  1203.       break;
  1204.  
  1205.     default:
  1206.       abort ();
  1207.     }
  1208.  
  1209.   if (GET_CODE (x) != MEM)
  1210.     abort ();
  1211.   x = XEXP (x, 0);
  1212.  
  1213.   value->base = x;
  1214.   value->offset = offset;
  1215. }
  1216.  
  1217. /* Uniquize all constants that appear in memory.
  1218.    Each constant in memory thus far output is recorded
  1219.    in `const_hash_table' with a `struct constant_descriptor'
  1220.    that contains a polish representation of the value of
  1221.    the constant.
  1222.  
  1223.    We cannot store the trees in the hash table
  1224.    because the trees may be temporary.  */
  1225.  
  1226. struct constant_descriptor
  1227. {
  1228.   struct constant_descriptor *next;
  1229.   char *label;
  1230.   char contents[1];
  1231. };
  1232.  
  1233. #define HASHBITS 30
  1234. #define MAX_HASH_TABLE 1009
  1235. static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
  1236.  
  1237. /* Compute a hash code for a constant expression.  */
  1238.  
  1239. int
  1240. const_hash (exp)
  1241.      tree exp;
  1242. {
  1243.   register char *p;
  1244.   register int len, hi, i;
  1245.   register enum tree_code code = TREE_CODE (exp);
  1246.  
  1247.   if (code == INTEGER_CST)
  1248.     {
  1249.       p = (char *) &TREE_INT_CST_LOW (exp);
  1250.       len = 2 * sizeof TREE_INT_CST_LOW (exp);
  1251.     }
  1252.   else if (code == REAL_CST)
  1253.     {
  1254.       p = (char *) &TREE_REAL_CST (exp);
  1255.       len = sizeof TREE_REAL_CST (exp);
  1256.     }
  1257.   else if (code == STRING_CST)
  1258.     p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
  1259.   else if (code == COMPLEX_CST)
  1260.     return const_hash (TREE_REALPART (exp)) * 5
  1261.       + const_hash (TREE_IMAGPART (exp));
  1262.   else if (code == CONSTRUCTOR)
  1263.     {
  1264.       register tree link;
  1265.  
  1266.       /* For record type, include the type in the hashing.
  1267.      We do not do so for array types
  1268.      because (1) the sizes of the elements are sufficient
  1269.      and (2) distinct array types can have the same constructor.  */
  1270.       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
  1271.     hi = ((int) TREE_TYPE (exp) & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
  1272.       else
  1273.     hi = 5;
  1274.  
  1275.       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
  1276.     hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
  1277.  
  1278.       return hi;
  1279.     }
  1280.   else if (code == ADDR_EXPR)
  1281.     {
  1282.       struct addr_const value;
  1283.       decode_addr_const (exp, &value);
  1284. #ifdef NeXT
  1285.       /* Don't hash the address of the SYMBOL_REF;
  1286.          only use the offset and the symbol name.  */
  1287.       hi = value.offset;
  1288.       p = XSTR (value.base, 0);
  1289.       for (i = 0; p[i] != 0; i++)
  1290.     hi = ((hi * 613) + (unsigned)(p[i]));
  1291.  
  1292.       hi &= (1 << HASHBITS) - 1;
  1293.       hi %= MAX_HASH_TABLE;
  1294.       return hi;
  1295. #else /* NeXT */
  1296.       p = (char *) &value;
  1297.       len = sizeof value;
  1298. #endif /* NeXT */
  1299.     }
  1300.   else if (code == PLUS_EXPR || code == MINUS_EXPR)
  1301.     return const_hash (TREE_OPERAND (exp, 0)) * 9
  1302.       +  const_hash (TREE_OPERAND (exp, 1));
  1303.   else if (code == NOP_EXPR || code == CONVERT_EXPR)
  1304.     return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
  1305.  
  1306.   /* Compute hashing function */
  1307.   hi = len;
  1308.   for (i = 0; i < len; i++)
  1309.     hi = ((hi * 613) + (unsigned)(p[i]));
  1310.  
  1311.   hi &= (1 << HASHBITS) - 1;
  1312.   hi %= MAX_HASH_TABLE;
  1313.   return hi;
  1314. }
  1315.  
  1316. /* Compare a constant expression EXP with a constant-descriptor DESC.
  1317.    Return 1 if DESC describes a constant with the same value as EXP.  */
  1318.  
  1319. static int
  1320. compare_constant (exp, desc)
  1321.      tree exp;
  1322.      struct constant_descriptor *desc;
  1323. {
  1324.   return 0 != compare_constant_1 (exp, desc->contents);
  1325. }
  1326.  
  1327. /* Compare constant expression EXP with a substring P of a constant descriptor.
  1328.    If they match, return a pointer to the end of the substring matched.
  1329.    If they do not match, return 0.
  1330.  
  1331.    Since descriptors are written in polish prefix notation,
  1332.    this function can be used recursively to test one operand of EXP
  1333.    against a subdescriptor, and if it succeeds it returns the
  1334.    address of the subdescriptor for the next operand.  */
  1335.  
  1336. static char *
  1337. compare_constant_1 (exp, p)
  1338.      tree exp;
  1339.      char *p;
  1340. {
  1341.   register char *strp;
  1342.   register int len;
  1343.   register enum tree_code code = TREE_CODE (exp);
  1344.  
  1345.   if (code != (enum tree_code) *p++)
  1346.     return 0;
  1347.  
  1348.   if (code == INTEGER_CST)
  1349.     {
  1350.       /* Integer constants are the same only if the same width of type.  */
  1351.       if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
  1352.     return 0;
  1353.       strp = (char *) &TREE_INT_CST_LOW (exp);
  1354.       len = 2 * sizeof TREE_INT_CST_LOW (exp);
  1355.     }
  1356.   else if (code == REAL_CST)
  1357.     {
  1358.       /* Real constants are the same only if the same width of type.  */
  1359.       if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
  1360.     return 0;
  1361.       strp = (char *) &TREE_REAL_CST (exp);
  1362.       len = sizeof TREE_REAL_CST (exp);
  1363.     }
  1364.   else if (code == STRING_CST)
  1365.     {
  1366.       if (flag_writable_strings)
  1367.     return 0;
  1368.       strp = TREE_STRING_POINTER (exp);
  1369.       len = TREE_STRING_LENGTH (exp);
  1370.       if (bcmp (&TREE_STRING_LENGTH (exp), p,
  1371.         sizeof TREE_STRING_LENGTH (exp)))
  1372.     return 0;
  1373.       p += sizeof TREE_STRING_LENGTH (exp);
  1374.     }
  1375.   else if (code == COMPLEX_CST)
  1376.     {
  1377.       p = compare_constant_1 (TREE_REALPART (exp), p);
  1378.       if (p == 0) return 0;
  1379.       p = compare_constant_1 (TREE_IMAGPART (exp), p);
  1380.       return p;
  1381.     }
  1382.   else if (code == CONSTRUCTOR)
  1383.     {
  1384.       register tree link;
  1385.       int length = list_length (CONSTRUCTOR_ELTS (exp));
  1386.       tree type;
  1387.  
  1388.       if (bcmp (&length, p, sizeof length))
  1389.     return 0;
  1390.       p += sizeof length;
  1391.  
  1392.       /* For record constructors, insist that the types match.
  1393.      For arrays, just verify both constructors are for arrays.  */
  1394.       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
  1395.     type = TREE_TYPE (exp);
  1396.       else
  1397.     type = 0;
  1398.       if (bcmp (&type, p, sizeof type))
  1399.     return 0;
  1400.       p += sizeof type;
  1401.  
  1402.       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
  1403.     if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
  1404.       return 0;
  1405.       return p;
  1406.     }
  1407.   else if (code == ADDR_EXPR)
  1408.     {
  1409.       struct addr_const value;
  1410.       decode_addr_const (exp, &value);
  1411. #ifdef NeXT
  1412.       strp = (char *) &value.offset;
  1413.       len = sizeof value.offset;
  1414.       /* Compare the offset.  */
  1415. #else /* NeXT */
  1416.       /* Compare SYMBOL_REF address and offset.  */
  1417.       strp = (char *) &value;
  1418.       len = sizeof value;
  1419. #endif /* NeXT */
  1420.       while (--len >= 0)
  1421.     if (*p++ != *strp++)
  1422.       return 0;
  1423.       /* Compare symbol name.  */
  1424.       strp = XSTR (value.base, 0);
  1425.       len = strlen (strp) + 1;
  1426.     }
  1427.   else if (code == PLUS_EXPR || code == MINUS_EXPR)
  1428.     {
  1429.       p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
  1430.       if (p == 0) return 0;
  1431.       p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
  1432.       return p;
  1433.     }
  1434.   else if (code == NOP_EXPR || code == CONVERT_EXPR)
  1435.     {
  1436.       p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
  1437.       return p;
  1438.     }
  1439.  
  1440.   /* Compare constant contents.  */
  1441.   while (--len >= 0)
  1442.     if (*p++ != *strp++)
  1443.       return 0;
  1444.  
  1445.   return p;
  1446. }
  1447.  
  1448. /* Construct a constant descriptor for the expression EXP.
  1449.    It is up to the caller to enter the descriptor in the hash table.  */
  1450.  
  1451. static struct constant_descriptor *
  1452. record_constant (exp)
  1453.      tree exp;
  1454. {
  1455.   struct constant_descriptor *ptr = 0;
  1456.   int buf;
  1457.  
  1458.   obstack_grow (&permanent_obstack, &ptr, sizeof ptr);
  1459.   obstack_grow (&permanent_obstack, &buf, sizeof buf);
  1460.   record_constant_1 (exp);
  1461.   return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
  1462. }
  1463.  
  1464. /* Add a description of constant expression EXP
  1465.    to the object growing in `permanent_obstack'.
  1466.    No need to return its address; the caller will get that
  1467.    from the obstack when the object is complete.  */
  1468.  
  1469. static void
  1470. record_constant_1 (exp)
  1471.      tree exp;
  1472. {
  1473.   register char *strp;
  1474.   register int len;
  1475.   register enum tree_code code = TREE_CODE (exp);
  1476.  
  1477.   obstack_1grow (&permanent_obstack, (unsigned int) code);
  1478.  
  1479.   if (code == INTEGER_CST)
  1480.     {
  1481.       obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
  1482.       strp = (char *) &TREE_INT_CST_LOW (exp);
  1483.       len = 2 * sizeof TREE_INT_CST_LOW (exp);
  1484.     }
  1485.   else if (code == REAL_CST)
  1486.     {
  1487.       obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
  1488.       strp = (char *) &TREE_REAL_CST (exp);
  1489.       len = sizeof TREE_REAL_CST (exp);
  1490.     }
  1491.   else if (code == STRING_CST)
  1492.     {
  1493.       if (flag_writable_strings)
  1494.     return;
  1495.       strp = TREE_STRING_POINTER (exp);
  1496.       len = TREE_STRING_LENGTH (exp);
  1497.       obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
  1498.             sizeof TREE_STRING_LENGTH (exp));
  1499.     }
  1500.   else if (code == COMPLEX_CST)
  1501.     {
  1502.       record_constant_1 (TREE_REALPART (exp));
  1503.       record_constant_1 (TREE_IMAGPART (exp));
  1504.       return;
  1505.     }
  1506.   else if (code == CONSTRUCTOR)
  1507.     {
  1508.       register tree link;
  1509.       int length = list_length (CONSTRUCTOR_ELTS (exp));
  1510.       tree type;
  1511.  
  1512.       obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
  1513.  
  1514.       /* For record constructors, insist that the types match.
  1515.      For arrays, just verify both constructors are for arrays.  */
  1516.       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
  1517.     type = TREE_TYPE (exp);
  1518.       else
  1519.     type = 0;
  1520.       obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
  1521.  
  1522.       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
  1523.     record_constant_1 (TREE_VALUE (link));
  1524.       return;
  1525.     }
  1526.   else if (code == ADDR_EXPR)
  1527.     {
  1528.       struct addr_const value;
  1529.       decode_addr_const (exp, &value);
  1530. #ifdef NeXT
  1531.       /* Record the offset.  */
  1532.       obstack_grow (&permanent_obstack,
  1533.             (char *) &value.offset, sizeof value.offset);
  1534. #else /* NeXT */
  1535.       /* Record the SYMBOL_REF address and the offset.  */
  1536.       obstack_grow (&permanent_obstack, (char *) &value, sizeof value);
  1537. #endif /* NeXT */
  1538.       /* Record the symbol name.  */
  1539.       obstack_grow (&permanent_obstack, XSTR (value.base, 0),
  1540.             strlen (XSTR (value.base, 0)) + 1);
  1541.       return;
  1542.     }
  1543.   else if (code == PLUS_EXPR || code == MINUS_EXPR)
  1544.     {
  1545.       record_constant_1 (TREE_OPERAND (exp, 0));
  1546.       record_constant_1 (TREE_OPERAND (exp, 1));
  1547.       return;
  1548.     }
  1549.   else if (code == NOP_EXPR || code == CONVERT_EXPR)
  1550.     {
  1551.       record_constant_1 (TREE_OPERAND (exp, 0));
  1552.       return;
  1553.     }
  1554.  
  1555.   /* Record constant contents.  */
  1556.   obstack_grow (&permanent_obstack, strp, len);
  1557. }
  1558.  
  1559. /* Return the constant-label-string for constant value EXP.
  1560.    If no constant equal to EXP has yet been output,
  1561.    define a new label and output assembler code for it.
  1562.    The const_hash_table records which constants already have label strings.  */
  1563.  
  1564. static char *
  1565. get_or_assign_label (exp)
  1566.      tree exp;
  1567. {
  1568.   register int hash, align;
  1569.   register struct constant_descriptor *desc;
  1570.   char label[256];
  1571.   int reloc;
  1572.  
  1573.   /* Make sure any other constants whose addresses appear in EXP
  1574.      are assigned label numbers.  */
  1575.  
  1576.   reloc = output_addressed_constants (exp);
  1577.  
  1578.   /* Compute hash code of EXP.  Search the descriptors for that hash code
  1579.      to see if any of them describes EXP.  If yes, the descriptor records
  1580.      the label number already assigned.  */
  1581.  
  1582.   hash = const_hash (exp) % MAX_HASH_TABLE;
  1583.  
  1584.   for (desc = const_hash_table[hash]; desc; desc = desc->next)
  1585.     if (compare_constant (exp, desc))
  1586.       return desc->label;
  1587.  
  1588.   /* No constant equal to EXP is known to have been output.
  1589.      Make a constant descriptor to enter EXP in the hash table.
  1590.      Assign the label number and record it in the descriptor for
  1591.      future calls to this function to find.  */
  1592.  
  1593.   desc = record_constant (exp);
  1594.   desc->next = const_hash_table[hash];
  1595.   const_hash_table[hash] = desc;
  1596.  
  1597.   /* Now output assembler code to define that label
  1598.      and follow it with the data of EXP.  */
  1599.  
  1600.   /* First switch to text section, except for writable strings.  */
  1601. #ifdef SELECT_SECTION
  1602.   SELECT_SECTION (exp, reloc);
  1603. #else
  1604.   if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
  1605.       || (flag_pic && reloc))
  1606.     data_section ();
  1607.   else
  1608.     readonly_data_section ();
  1609. #endif
  1610.  
  1611.   /* Align the location counter as required by EXP's data type.  */
  1612.   align = TYPE_ALIGN (TREE_TYPE (exp));
  1613. #ifdef CONSTANT_ALIGNMENT
  1614.   align = CONSTANT_ALIGNMENT (exp, align);
  1615. #endif
  1616.  
  1617.   if (align > BITS_PER_UNIT)
  1618.     ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
  1619.  
  1620.   /* Output the label itself.  */
  1621.   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", const_labelno);
  1622.  
  1623.   /* Output the value of EXP.  */
  1624.   output_constant (exp,
  1625.            (TREE_CODE (exp) == STRING_CST
  1626.             ? TREE_STRING_LENGTH (exp)
  1627.             : int_size_in_bytes (TREE_TYPE (exp))));
  1628.  
  1629.   /* Create a string containing the label name, in LABEL.  */
  1630.   ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
  1631.  
  1632.   ++const_labelno;
  1633.  
  1634.   desc->label
  1635.     = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
  1636.  
  1637.   return desc->label;
  1638. }
  1639.  
  1640. /* Return an rtx representing a reference to constant data in memory
  1641.    for the constant expression EXP.
  1642.    If assembler code for such a constant has already been output,
  1643.    return an rtx to refer to it.
  1644.    Otherwise, output such a constant in memory and generate
  1645.    an rtx for it.  The TREE_CST_RTL of EXP is set up to point to that rtx.  */
  1646.  
  1647. rtx
  1648. output_constant_def (exp)
  1649.      tree exp;
  1650. {
  1651.   register rtx def;
  1652.   int temp_p = allocation_temporary_p ();
  1653.  
  1654.   if (TREE_CODE (exp) == INTEGER_CST)
  1655.     abort ();            /* No TREE_CST_RTL slot in these.  */
  1656.  
  1657.   if (TREE_CST_RTL (exp))
  1658.     return TREE_CST_RTL (exp);
  1659.  
  1660.   if (TREE_PERMANENT (exp))
  1661.     end_temporary_allocation ();
  1662.  
  1663.   def = gen_rtx (SYMBOL_REF, Pmode, get_or_assign_label (exp));
  1664.  
  1665.   TREE_CST_RTL (exp)
  1666.     = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
  1667.   RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
  1668.  
  1669.   if (temp_p && TREE_PERMANENT (exp))
  1670.     resume_temporary_allocation ();
  1671.  
  1672.   return TREE_CST_RTL (exp);
  1673. }
  1674.  
  1675. /* Similar hash facility for making memory-constants
  1676.    from constant rtl-expressions.  It is used on RISC machines
  1677.    where immediate integer arguments and constant addresses are restricted
  1678.    so that such constants must be stored in memory.
  1679.  
  1680.    This pool of constants is reinitialized for each function
  1681.    so each function gets its own constants-pool that comes right before it.
  1682.  
  1683.    All structures allocated here are discarded when functions are saved for
  1684.    inlining, so they do not need to be allocated permanently.  */
  1685.  
  1686. #define MAX_RTX_HASH_TABLE 61
  1687. static struct constant_descriptor *const_rtx_hash_table[MAX_RTX_HASH_TABLE];
  1688.  
  1689. /* Structure to represent sufficient information about a constant so that
  1690.    it can be output when the constant pool is output, so that function
  1691.    integration can be done, and to simplify handling on machines that reference
  1692.    constant pool as base+displacement.  */
  1693.  
  1694. struct pool_constant
  1695. {
  1696.   struct constant_descriptor *desc;
  1697.   struct pool_constant *next;
  1698.   enum machine_mode mode;
  1699.   rtx constant;
  1700.   int labelno;
  1701.   int align;
  1702.   int offset;
  1703. };
  1704.  
  1705. /* Pointers to first and last constant in pool.  */
  1706.  
  1707. static struct pool_constant *first_pool, *last_pool;
  1708.  
  1709. /* Current offset in constant pool (does not include any machine-specific
  1710.    header.  */
  1711.  
  1712. static int pool_offset;
  1713.  
  1714. /* Structure used to maintain hash table mapping symbols used to their
  1715.    corresponding constants.  */
  1716.  
  1717. struct pool_sym
  1718. {
  1719.   char *label;
  1720.   struct pool_constant *pool;
  1721.   struct pool_sym *next;
  1722. };
  1723.  
  1724. static struct pool_sym *const_rtx_sym_hash_table[MAX_RTX_HASH_TABLE];
  1725.  
  1726. /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
  1727.    The argument is XSTR (... , 0)  */
  1728.  
  1729. #define SYMHASH(LABEL)    \
  1730.   ((((int) (LABEL)) & ((1 << HASHBITS) - 1))  % MAX_RTX_HASH_TABLE)
  1731.  
  1732. /* Initialize constant pool hashing for next function.  */
  1733.  
  1734. void
  1735. init_const_rtx_hash_table ()
  1736. {
  1737.   bzero (const_rtx_hash_table, sizeof const_rtx_hash_table);
  1738.   bzero (const_rtx_sym_hash_table, sizeof const_rtx_sym_hash_table);
  1739.  
  1740.   first_pool = last_pool = 0;
  1741.   pool_offset = 0;
  1742. }
  1743.  
  1744. enum kind { RTX_DOUBLE, RTX_INT };
  1745.  
  1746. struct rtx_const
  1747. {
  1748. #ifdef ONLY_INT_FIELDS
  1749.   unsigned int kind : 16;
  1750.   unsigned int mode : 16;
  1751. #else
  1752.   enum kind kind : 16;
  1753.   enum machine_mode mode : 16;
  1754. #endif
  1755.   union {
  1756.     union real_extract du;
  1757.     struct addr_const addr;
  1758.   } un;
  1759. };
  1760.  
  1761. /* Express an rtx for a constant integer (perhaps symbolic)
  1762.    as the sum of a symbol or label plus an explicit integer.
  1763.    They are stored into VALUE.  */
  1764.  
  1765. static void
  1766. decode_rtx_const (mode, x, value)
  1767.      enum machine_mode mode;
  1768.      rtx x;
  1769.      struct rtx_const *value;
  1770. {
  1771.   /* Clear the whole structure, including any gaps.  */
  1772.  
  1773.   {
  1774.     int *p = (int *) value;
  1775.     int *end = (int *) (value + 1);
  1776.     while (p < end)
  1777.       *p++ = 0;
  1778.   }
  1779.  
  1780.   value->kind = RTX_INT;    /* Most usual kind. */
  1781.   value->mode = mode;
  1782.  
  1783.   switch (GET_CODE (x))
  1784.     {
  1785.     case CONST_DOUBLE:
  1786.       value->kind = RTX_DOUBLE;
  1787.       value->mode = GET_MODE (x);
  1788.       bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
  1789.       break;
  1790.  
  1791.     case CONST_INT:
  1792.       value->un.addr.offset = INTVAL (x);
  1793.       break;
  1794.  
  1795.     case SYMBOL_REF:
  1796.       value->un.addr.base = (rtx) XSTR (x, 0);
  1797.       break;
  1798.  
  1799.     case LABEL_REF:
  1800.       value->un.addr.base = x;
  1801.       break;
  1802.  
  1803.     case CONST:
  1804.       x = XEXP (x, 0);
  1805.       if (GET_CODE (x) == PLUS)
  1806.     {
  1807.       value->un.addr.base = XEXP (x, 0);
  1808.       if (GET_CODE (XEXP (x, 1)) != CONST_INT)
  1809.         abort ();
  1810.       value->un.addr.offset = INTVAL (XEXP (x, 1));
  1811.     }
  1812.       else if (GET_CODE (x) == MINUS)
  1813.     {
  1814.       value->un.addr.base = XEXP (x, 0);
  1815.       if (GET_CODE (XEXP (x, 1)) != CONST_INT)
  1816.         abort ();
  1817.       value->un.addr.offset = - INTVAL (XEXP (x, 1));
  1818.     }
  1819.       else
  1820.     abort ();
  1821.       break;
  1822.  
  1823.     default:
  1824.       abort ();
  1825.     }
  1826.  
  1827.   if (value->kind == RTX_INT && value->un.addr.base != 0)
  1828.     switch (GET_CODE (value->un.addr.base))
  1829.       {
  1830.       case SYMBOL_REF:
  1831.       case LABEL_REF:
  1832.     /* Use the string's address, not the SYMBOL_REF's address,
  1833.        for the sake of addresses of library routines.
  1834.        For a LABEL_REF, compare labels.  */
  1835.     value->un.addr.base = XEXP (value->un.addr.base, 0);
  1836.       }
  1837. }
  1838.  
  1839. /* Compute a hash code for a constant RTL expression.  */
  1840.  
  1841. int
  1842. const_hash_rtx (mode, x)
  1843.      enum machine_mode mode;
  1844.      rtx x;
  1845. {
  1846.   register int hi, i;
  1847.  
  1848.   struct rtx_const value;
  1849.   decode_rtx_const (mode, x, &value);
  1850.  
  1851.   /* Compute hashing function */
  1852.   hi = 0;
  1853.   for (i = 0; i < sizeof value / sizeof (int); i++)
  1854.     hi += ((int *) &value)[i];
  1855.  
  1856.   hi &= (1 << HASHBITS) - 1;
  1857.   hi %= MAX_RTX_HASH_TABLE;
  1858.   return hi;
  1859. }
  1860.  
  1861. /* Compare a constant rtl object X with a constant-descriptor DESC.
  1862.    Return 1 if DESC describes a constant with the same value as X.  */
  1863.  
  1864. static int
  1865. compare_constant_rtx (mode, x, desc)
  1866.      enum machine_mode mode;
  1867.      rtx x;
  1868.      struct constant_descriptor *desc;
  1869. {
  1870.   register int *p = (int *) desc->contents;
  1871.   register int *strp;
  1872.   register int len;
  1873.   struct rtx_const value;
  1874.  
  1875.   decode_rtx_const (mode, x, &value);
  1876.   strp = (int *) &value;
  1877.   len = sizeof value / sizeof (int);
  1878.  
  1879.   /* Compare constant contents.  */
  1880.   while (--len >= 0)
  1881.     if (*p++ != *strp++)
  1882.       return 0;
  1883.  
  1884.   return 1;
  1885. }
  1886.  
  1887. /* Construct a constant descriptor for the rtl-expression X.
  1888.    It is up to the caller to enter the descriptor in the hash table.  */
  1889.  
  1890. static struct constant_descriptor *
  1891. record_constant_rtx (mode, x)
  1892.      enum machine_mode mode;
  1893.      rtx x;
  1894. {
  1895.   struct constant_descriptor *ptr;
  1896.   char *label;
  1897.   struct rtx_const value;
  1898.  
  1899.   decode_rtx_const (mode, x, &value);
  1900.  
  1901.   obstack_grow (current_obstack, &ptr, sizeof ptr);
  1902.   obstack_grow (current_obstack, &label, sizeof label);
  1903.  
  1904.   /* Record constant contents.  */
  1905.   obstack_grow (current_obstack, &value, sizeof value);
  1906.  
  1907.   return (struct constant_descriptor *) obstack_finish (current_obstack);
  1908. }
  1909.  
  1910. /* Given a constant rtx X, make (or find) a memory constant for its value
  1911.    and return a MEM rtx to refer to it in memory.  */
  1912.  
  1913. rtx
  1914. force_const_mem (mode, x)
  1915.      enum machine_mode mode;
  1916.      rtx x;
  1917. {
  1918.   register int hash;
  1919.   register struct constant_descriptor *desc;
  1920.   char label[256];
  1921.   char *found = 0;
  1922.   rtx def;
  1923.  
  1924.   /* If we want this CONST_DOUBLE in the same mode as it is in memory
  1925.      (this will always be true for floating CONST_DOUBLEs that have been
  1926.      placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs), 
  1927.      use the previous copy.  Otherwise, make a new one.  Note that in
  1928.      the unlikely event that this same CONST_DOUBLE is used in two different
  1929.      modes in an alternating fashion, we will allocate a lot of different
  1930.      memory locations, but this should be extremely rare.  */
  1931.  
  1932.   if (GET_CODE (x) == CONST_DOUBLE
  1933.       && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
  1934.       && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
  1935.     return CONST_DOUBLE_MEM (x);
  1936.  
  1937.   /* Compute hash code of X.  Search the descriptors for that hash code
  1938.      to see if any of them describes X.  If yes, the descriptor records
  1939.      the label number already assigned.  */
  1940.  
  1941.   hash = const_hash_rtx (mode, x);
  1942.  
  1943.   for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
  1944.     if (compare_constant_rtx (mode, x, desc))
  1945.       {
  1946.     found = desc->label;
  1947.     break;
  1948.       }
  1949.  
  1950.   if (found == 0)
  1951.     {
  1952.       register struct pool_constant *pool;
  1953.       register struct pool_sym *sym;
  1954.       int align;
  1955.  
  1956.       /* No constant equal to X is known to have been output.
  1957.      Make a constant descriptor to enter X in the hash table.
  1958.      Assign the label number and record it in the descriptor for
  1959.      future calls to this function to find.  */
  1960.  
  1961.       desc = record_constant_rtx (mode, x);
  1962.       desc->next = const_rtx_hash_table[hash];
  1963.       const_rtx_hash_table[hash] = desc;
  1964.  
  1965.       /* Align the location counter as required by EXP's data type.  */
  1966.       align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
  1967.       if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
  1968.     align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
  1969.  
  1970.       pool_offset += align - 1;
  1971.       pool_offset &= ~ (align - 1);
  1972.  
  1973.       /* Allocate a pool constant descriptor, fill it in, and chain it in.  */
  1974.  
  1975.       pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
  1976.       pool->desc = desc;
  1977.       pool->constant = x;
  1978.       pool->mode = mode;
  1979.       pool->labelno = const_labelno;
  1980.       pool->align = align;
  1981.       pool->offset = pool_offset;
  1982.       pool->next = 0;
  1983.  
  1984.       if (last_pool == 0)
  1985.     first_pool = pool;
  1986.       else
  1987.     last_pool->next = pool;
  1988.  
  1989.       last_pool = pool;
  1990.       pool_offset += GET_MODE_SIZE (mode);
  1991.  
  1992.       /* Create a string containing the label name, in LABEL.  */
  1993.       ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
  1994.  
  1995.       ++const_labelno;
  1996.  
  1997.       desc->label = found
  1998.     = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
  1999.  
  2000.       /* Add label to symbol hash table.  */
  2001.       hash = SYMHASH (found);
  2002.       sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
  2003.       sym->label = found;
  2004.       sym->pool = pool;
  2005.       sym->next = const_rtx_sym_hash_table[hash];
  2006.       const_rtx_sym_hash_table[hash] = sym;
  2007.     }
  2008.  
  2009.   /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
  2010.  
  2011.   def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
  2012.  
  2013.   RTX_UNCHANGING_P (def) = 1;
  2014.   /* Mark the symbol_ref as belonging to this constants pool.  */
  2015.   CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
  2016.   current_function_uses_const_pool = 1;
  2017.  
  2018.   if (GET_CODE (x) == CONST_DOUBLE)
  2019.     {
  2020.       if (CONST_DOUBLE_MEM (x) == cc0_rtx)
  2021.     {
  2022.       CONST_DOUBLE_CHAIN (x) = const_double_chain;
  2023.       const_double_chain = x;
  2024.     }
  2025.       CONST_DOUBLE_MEM (x) = def;
  2026.     }
  2027.  
  2028.   return def;
  2029. }
  2030.  
  2031. /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
  2032.    the corresponding pool_constant structure.  */
  2033.  
  2034. static struct pool_constant *
  2035. find_pool_constant (addr)
  2036.      rtx addr;
  2037. {
  2038.   struct pool_sym *sym;
  2039.   char *label = XSTR (addr, 0);
  2040.  
  2041.   for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
  2042.     if (sym->label == label)
  2043.       return sym->pool;
  2044.  
  2045.   abort ();
  2046. }
  2047.  
  2048. /* Given a constant pool SYMBOL_REF, return the corresponding constant.  */
  2049.  
  2050. rtx
  2051. get_pool_constant (addr)
  2052.      rtx addr;
  2053. {
  2054.   return (find_pool_constant (addr))->constant;
  2055. }
  2056.  
  2057. /* Similar, return the mode.  */
  2058.  
  2059. enum machine_mode
  2060. get_pool_mode (addr)
  2061.      rtx addr;
  2062. {
  2063.   return (find_pool_constant (addr))->mode;
  2064. }
  2065.  
  2066. /* Similar, return the offset in the constant pool.  */
  2067.  
  2068. int
  2069. get_pool_offset (addr)
  2070.      rtx addr;
  2071. {
  2072.   return (find_pool_constant (addr))->offset;
  2073. }
  2074.  
  2075. /* Return the size of the constant pool.  */
  2076.  
  2077. int
  2078. get_pool_size ()
  2079. {
  2080.   return pool_offset;
  2081. }
  2082.  
  2083. /* Write all the constants in the constant pool.  */
  2084.  
  2085. void
  2086. output_constant_pool (fnname, fndecl)
  2087.      char *fnname;
  2088.      tree fndecl;
  2089. {
  2090.   struct pool_constant *pool;
  2091.   rtx x;
  2092.  
  2093. #ifdef ASM_OUTPUT_POOL_PROLOGUE
  2094.   ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
  2095. #endif
  2096.  
  2097.   for (pool = first_pool; pool; pool = pool->next)
  2098.     {
  2099.       x = pool->constant;
  2100.  
  2101.       /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
  2102.      whose CODE_LABEL has been deleted.  This can occur if a jump table
  2103.      is eliminated by optimization.  If so, write a constant of zero
  2104.      instead.  */
  2105.       if ((GET_CODE (x) == LABEL_REF && INSN_DELETED_P (XEXP (x, 0)))
  2106.       || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
  2107.           && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
  2108.           && INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))))
  2109.     x = const0_rtx;
  2110.  
  2111.       /* First switch to correct section.  */
  2112. #ifdef SELECT_RTX_SECTION
  2113.       SELECT_RTX_SECTION (pool->mode, x);
  2114. #else
  2115.       readonly_data_section ();
  2116. #endif
  2117.  
  2118. #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
  2119.       ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
  2120.                      pool->align, pool->labelno, done);
  2121. #endif
  2122.  
  2123.       if (pool->align > 1)
  2124.     ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
  2125.  
  2126.       /* Output the label.  */
  2127.       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
  2128.  
  2129.       /* Output the value of the constant itself.  */
  2130.       if (GET_CODE (x) == CONST_DOUBLE)
  2131.     {
  2132.       union real_extract u;
  2133.  
  2134.       bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
  2135.       switch (pool->mode)
  2136.         {
  2137.           /* Perhaps change the following to use
  2138.          CONST_DOUBLE_LOW and CONST_DOUBLE_HIGH, rather than u.i.  */
  2139.         case DImode:
  2140. #ifdef ASM_OUTPUT_DOUBLE_INT
  2141.           ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
  2142. #else /* no ASM_OUTPUT_DOUBLE_INT */
  2143. #if !WORDS_BIG_ENDIAN
  2144.           /* Output two ints.  */
  2145.           ASM_OUTPUT_INT (asm_out_file,
  2146.                   gen_rtx (CONST_INT, VOIDmode, u.i[0]));
  2147.           ASM_OUTPUT_INT (asm_out_file,
  2148.                   gen_rtx (CONST_INT, VOIDmode, u.i[1]));
  2149. #else
  2150.           /* Output two ints.  */
  2151.           ASM_OUTPUT_INT (asm_out_file,
  2152.                   gen_rtx (CONST_INT, VOIDmode, u.i[1]));
  2153.           ASM_OUTPUT_INT (asm_out_file,
  2154.                   gen_rtx (CONST_INT, VOIDmode, u.i[0]));
  2155. #endif /* WORDS_BIG_ENDIAN */
  2156. #endif /* no ASM_OUTPUT_DOUBLE_INT */
  2157.           break;
  2158.  
  2159.         case DFmode:
  2160.           ASM_OUTPUT_DOUBLE (asm_out_file, u.d);
  2161.           break;
  2162.  
  2163.         case SFmode:
  2164.           ASM_OUTPUT_FLOAT (asm_out_file, u.d);
  2165.         }
  2166.     }
  2167.       else
  2168.     switch (pool->mode)
  2169.       {
  2170.       case SImode:
  2171.         ASM_OUTPUT_INT (asm_out_file, x);
  2172.         break;
  2173.  
  2174.       case HImode:
  2175.         ASM_OUTPUT_SHORT (asm_out_file, x);
  2176.         break;
  2177.  
  2178.       case QImode:
  2179.         ASM_OUTPUT_CHAR (asm_out_file, x);
  2180.         break;
  2181.       }
  2182.     done: ;
  2183.     }
  2184.   /* Done with this pool.  */
  2185.   first_pool = last_pool = 0;
  2186. }
  2187.  
  2188. /* Find all the constants whose addresses are referenced inside of EXP,
  2189.    and make sure assembler code with a label has been output for each one.
  2190.    Indicate whether an ADDR_EXPR has been encountered.  */
  2191.  
  2192. int
  2193. output_addressed_constants (exp)
  2194.      tree exp;
  2195. {
  2196.   int reloc = 0;
  2197.  
  2198.   switch (TREE_CODE (exp))
  2199.     {
  2200.     case ADDR_EXPR:
  2201.       {
  2202.     register tree constant = TREE_OPERAND (exp, 0);
  2203.  
  2204.     while (TREE_CODE (constant) == COMPONENT_REF)
  2205.       {
  2206.         constant = TREE_OPERAND (constant, 0);
  2207.       }
  2208.  
  2209. #ifdef NeXT
  2210.     if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
  2211.         || TREE_CODE (constant) == CONSTRUCTOR)
  2212. #else /* NeXT */
  2213.     if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c')
  2214. #endif /* NeXT */
  2215.       /* No need to do anything here
  2216.          for addresses of variables or functions.  */
  2217.       output_constant_def (constant);
  2218.       }
  2219.       reloc = 1;
  2220.       break;
  2221.  
  2222.     case PLUS_EXPR:
  2223.     case MINUS_EXPR:
  2224.       reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
  2225.       reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
  2226.       break;
  2227.  
  2228.     case NOP_EXPR:
  2229.     case CONVERT_EXPR:
  2230.       reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
  2231.       break;
  2232.  
  2233.     case CONSTRUCTOR:
  2234.       {
  2235.     register tree link;
  2236.     for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
  2237.       if (TREE_VALUE (link) != 0)
  2238.         reloc |= output_addressed_constants (TREE_VALUE (link));
  2239.       }
  2240.       break;
  2241.  
  2242.     case ERROR_MARK:
  2243.       break;
  2244.     }
  2245.   return reloc;
  2246. }
  2247.  
  2248. /* Output assembler code for constant EXP to FILE, with no label.
  2249.    This includes the pseudo-op such as ".int" or ".byte", and a newline.
  2250.    Assumes output_addressed_constants has been done on EXP already.
  2251.  
  2252.    Generate exactly SIZE bytes of assembler data, padding at the end
  2253.    with zeros if necessary.  SIZE must always be specified.
  2254.  
  2255.    SIZE is important for structure constructors,
  2256.    since trailing members may have been omitted from the constructor.
  2257.    It is also important for initialization of arrays from string constants
  2258.    since the full length of the string constant might not be wanted.
  2259.    It is also needed for initialization of unions, where the initializer's
  2260.    type is just one member, and that may not be as long as the union.
  2261.  
  2262.    There a case in which we would fail to output exactly SIZE bytes:
  2263.    for a structure constructor that wants to produce more than SIZE bytes.
  2264.    But such constructors will never be generated for any possible input.  */
  2265.  
  2266. void
  2267. output_constant (exp, size)
  2268.      register tree exp;
  2269.      register int size;
  2270. {
  2271.   register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
  2272.   rtx x;
  2273.  
  2274.   if (size == 0)
  2275.     return;
  2276.  
  2277.   /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
  2278.      That way we get the constant (we hope) inside it.  */
  2279.   if (TREE_CODE (exp) == NOP_EXPR
  2280.       && TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)))
  2281.     exp = TREE_OPERAND (exp, 0);
  2282.  
  2283.   switch (code)
  2284.     {
  2285.     case INTEGER_TYPE:
  2286.     case ENUMERAL_TYPE:
  2287.     case POINTER_TYPE:
  2288.     case REFERENCE_TYPE:
  2289.       /* ??? What about       (int)((float)(int)&foo + 4)    */
  2290.       while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
  2291.          || TREE_CODE (exp) == NON_LVALUE_EXPR)
  2292.     exp = TREE_OPERAND (exp, 0);
  2293.  
  2294. #ifndef ASM_OUTPUT_DOUBLE_INT
  2295.       if (TYPE_MODE (TREE_TYPE (exp)) == DImode)
  2296.     {
  2297.       if (TREE_CODE (exp) == INTEGER_CST)
  2298.         {
  2299. #if !WORDS_BIG_ENDIAN
  2300.           ASM_OUTPUT_INT (asm_out_file,
  2301.                   gen_rtx (CONST_INT, VOIDmode,
  2302.                        TREE_INT_CST_LOW (exp)));
  2303.           ASM_OUTPUT_INT (asm_out_file,
  2304.                   gen_rtx (CONST_INT, VOIDmode,
  2305.                        TREE_INT_CST_HIGH (exp)));
  2306. #else
  2307.           ASM_OUTPUT_INT (asm_out_file,
  2308.                   gen_rtx (CONST_INT, VOIDmode,
  2309.                        TREE_INT_CST_HIGH (exp)));
  2310.           ASM_OUTPUT_INT (asm_out_file,
  2311.                   gen_rtx (CONST_INT, VOIDmode,
  2312.                        TREE_INT_CST_LOW (exp)));
  2313. #endif
  2314.           size -= GET_MODE_SIZE (DImode);
  2315.           break;
  2316.         }
  2317.       else
  2318.         error ("8-byte integer constant expression too complicated");
  2319.  
  2320.       break;
  2321.     }
  2322. #endif /* no ASM_OUTPUT_DOUBLE_INT */
  2323.  
  2324.       x = expand_expr (exp, 0, VOIDmode, EXPAND_SUM);
  2325.  
  2326.       if (size == GET_MODE_SIZE (QImode))
  2327.     {
  2328.       ASM_OUTPUT_CHAR (asm_out_file, x);
  2329.       size -= GET_MODE_SIZE (QImode);
  2330.     }
  2331.       else if (size == GET_MODE_SIZE (HImode))
  2332.     {
  2333.       ASM_OUTPUT_SHORT (asm_out_file, x);
  2334.       size -= GET_MODE_SIZE (HImode);
  2335.     }
  2336.       else if (size == GET_MODE_SIZE (SImode))
  2337.     {
  2338.       ASM_OUTPUT_INT (asm_out_file, x);
  2339.       size -= GET_MODE_SIZE (SImode);
  2340.     }
  2341. #ifdef ASM_OUTPUT_DOUBLE_INT
  2342.       else if (size == GET_MODE_SIZE (DImode))
  2343.     {
  2344.       ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
  2345.       size -= GET_MODE_SIZE (DImode);
  2346.     }
  2347. #endif /* ASM_OUTPUT_DOUBLE_INT */
  2348.       else
  2349.     abort ();
  2350.  
  2351.       break;
  2352.  
  2353.     case REAL_TYPE:
  2354.       if (TREE_CODE (exp) != REAL_CST)
  2355.     error ("initializer for floating value is not a floating constant");
  2356.       else
  2357.     {
  2358.       REAL_VALUE_TYPE d;
  2359.       jmp_buf output_constant_handler;
  2360.  
  2361.       d = TREE_REAL_CST (exp);
  2362.       if (setjmp (output_constant_handler))
  2363.         {
  2364.           error ("floating point trap outputting a constant");
  2365. #ifdef REAL_IS_NOT_DOUBLE
  2366.           bzero (&d, sizeof d);
  2367.           d = dconst0;
  2368. #else
  2369.           d = 0;
  2370. #endif
  2371.         }
  2372.       set_float_handler (output_constant_handler);
  2373.  
  2374.       if (size < GET_MODE_SIZE (SFmode))
  2375.         break;
  2376.       else if (size < GET_MODE_SIZE (DFmode))
  2377.         {
  2378.           ASM_OUTPUT_FLOAT (asm_out_file, d);
  2379.           size -= GET_MODE_SIZE (SFmode);
  2380.         }
  2381.       else
  2382.         {
  2383.           ASM_OUTPUT_DOUBLE (asm_out_file, d);
  2384.           size -= GET_MODE_SIZE (DFmode);
  2385.         }
  2386.       set_float_handler (0);
  2387.     }
  2388.       break;
  2389.  
  2390.     case COMPLEX_TYPE:
  2391.       output_constant (TREE_REALPART (exp), size / 2);
  2392.       output_constant (TREE_IMAGPART (exp), size / 2);
  2393.       size -= (size / 2) * 2;
  2394.       break;
  2395.  
  2396.     case ARRAY_TYPE:
  2397.       if (TREE_CODE (exp) == CONSTRUCTOR)
  2398.     {
  2399.       output_constructor (exp, size);
  2400.       return;
  2401.     }
  2402.       else if (TREE_CODE (exp) == STRING_CST)
  2403.     {
  2404.       int excess = 0;
  2405.  
  2406.       if (size > TREE_STRING_LENGTH (exp))
  2407.         {
  2408.           excess = size - TREE_STRING_LENGTH (exp);
  2409.           size = TREE_STRING_LENGTH (exp);
  2410.         }
  2411.  
  2412.       assemble_string (TREE_STRING_POINTER (exp), size);
  2413.       size = excess;
  2414.     }
  2415.       else
  2416.     abort ();
  2417.       break;
  2418.  
  2419.     case RECORD_TYPE:
  2420.     case UNION_TYPE:
  2421.       if (TREE_CODE (exp) == CONSTRUCTOR)
  2422.     output_constructor (exp, size);
  2423.       else
  2424.     abort ();
  2425.       return;
  2426.     }
  2427.  
  2428.   if (size > 0)
  2429.     assemble_zeros (size);
  2430. }
  2431.  
  2432. /* Subroutine of output_constant, used for CONSTRUCTORs
  2433.    (aggregate constants).
  2434.    Generate at least SIZE bytes, padding if necessary.  */
  2435.  
  2436. void
  2437. output_constructor (exp, size)
  2438.      tree exp;
  2439.      int size;
  2440. {
  2441.   register tree link, field = 0;
  2442.   /* Number of bytes output or skipped so far.
  2443.      In other words, current position within the constructor.  */
  2444.   int total_bytes = 0;
  2445.   /* Non-zero means BYTE contains part of a byte, to be output.  */
  2446.   int byte_buffer_in_use = 0;
  2447.   register int byte;
  2448.  
  2449.   if (HOST_BITS_PER_INT < BITS_PER_UNIT)
  2450.     abort ();
  2451.  
  2452.   if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
  2453.     field = TYPE_FIELDS (TREE_TYPE (exp));
  2454.  
  2455.   /* As LINK goes through the elements of the constant,
  2456.      FIELD goes through the structure fields, if the constant is a structure.
  2457.      if the constant is a union, then we override this,
  2458.      by getting the field from the TREE_LIST element.
  2459.      But the constant could also be an array.  Then FIELD is zero.  */
  2460.   for (link = CONSTRUCTOR_ELTS (exp);
  2461.        link;
  2462.        link = TREE_CHAIN (link),
  2463.        field = field ? TREE_CHAIN (field) : 0)
  2464.     {
  2465.       tree val = TREE_VALUE (link);
  2466.       /* the element in a union constructor specifies the proper field.  */
  2467.       if (TREE_PURPOSE (link) != 0)
  2468.     field = TREE_PURPOSE (link);
  2469.  
  2470.       /* Eliminate the marker that makes a cast not be an lvalue.  */
  2471.       if (val != 0 && TREE_CODE (val) == NON_LVALUE_EXPR)
  2472.     val = TREE_OPERAND (val, 0);
  2473.  
  2474.       if (field == 0 || !DECL_BIT_FIELD (field))
  2475.     {
  2476.       register int fieldsize;
  2477.       /* Since this structure is static,
  2478.          we know the positions are constant.  */
  2479.       int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
  2480.                  / BITS_PER_UNIT)
  2481.             : 0);
  2482.  
  2483.       /* An element that is not a bit-field.
  2484.          Output any buffered-up bit-fields preceding it.  */
  2485.       if (byte_buffer_in_use)
  2486.         {
  2487.           ASM_OUTPUT_BYTE (asm_out_file, byte);
  2488.           total_bytes++;
  2489.           byte_buffer_in_use = 0;
  2490.         }
  2491.  
  2492.       /* Advance to offset of this element.
  2493.          Note no alignment needed in an array, since that is guaranteed
  2494.          if each element has the proper size.  */
  2495.       if (field != 0 && bitpos != total_bytes)
  2496.         {
  2497.           assemble_zeros (bitpos - total_bytes);
  2498.           total_bytes = bitpos;
  2499.         }
  2500.  
  2501.       /* Determine size this element should occupy.  */
  2502.       if (field)
  2503.         {
  2504.           if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
  2505.         abort ();
  2506.           if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
  2507.         {
  2508.           /* This avoids overflow trouble.  */
  2509.           tree size_tree = size_binop (CEIL_DIV_EXPR,
  2510.                            DECL_SIZE (field),
  2511.                            size_int (BITS_PER_UNIT));
  2512.           fieldsize = TREE_INT_CST_LOW (size_tree);
  2513.         }
  2514.           else
  2515.         {
  2516.           fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
  2517.           fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
  2518.         }
  2519.         }
  2520.       else
  2521.         fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
  2522.  
  2523.       /* Output the element's initial value.  */
  2524.       if (val == 0)
  2525.         assemble_zeros (fieldsize);
  2526.       else
  2527.         output_constant (val, fieldsize);
  2528.  
  2529.       /* Count its size.  */
  2530.       total_bytes += fieldsize;
  2531.     }
  2532.       else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
  2533.     error ("invalid initial value for member `%s'",
  2534.            IDENTIFIER_POINTER (DECL_NAME (field)));
  2535.       else
  2536.     {
  2537.       /* Element that is a bit-field.  */
  2538.  
  2539.       int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
  2540.       int end_offset
  2541.         = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
  2542.  
  2543.       if (val == 0)
  2544.         val = integer_zero_node;
  2545.  
  2546.       /* If this field does not start in this (or, next) byte,
  2547.          skip some bytes.  */
  2548.       if (next_offset / BITS_PER_UNIT != total_bytes)
  2549.         {
  2550.           /* Output remnant of any bit field in previous bytes.  */
  2551.           if (byte_buffer_in_use)
  2552.         {
  2553.           ASM_OUTPUT_BYTE (asm_out_file, byte);
  2554.           total_bytes++;
  2555.           byte_buffer_in_use = 0;
  2556.         }
  2557.  
  2558.           /* If still not at proper byte, advance to there.  */
  2559.           if (next_offset / BITS_PER_UNIT != total_bytes)
  2560.         {
  2561.           assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
  2562.           total_bytes = next_offset / BITS_PER_UNIT;
  2563.         }
  2564.         }
  2565.  
  2566.       if (! byte_buffer_in_use)
  2567.         byte = 0;
  2568.  
  2569.       /* We must split the element into pieces that fall within
  2570.          separate bytes, and combine each byte with previous or
  2571.          following bit-fields.  */
  2572.  
  2573.       /* next_offset is the offset n fbits from the begining of
  2574.          the structure to the next bit of this element to be processed.
  2575.          end_offset is the offset of the first bit past the end of
  2576.          this element.  */
  2577.       while (next_offset < end_offset)
  2578.         {
  2579.           int this_time;
  2580.           int next_byte = next_offset / BITS_PER_UNIT;
  2581.           int next_bit = next_offset % BITS_PER_UNIT;
  2582.  
  2583.           /* Advance from byte to byte
  2584.          within this element when necessary.  */
  2585.           while (next_byte != total_bytes)
  2586.         {
  2587.           ASM_OUTPUT_BYTE (asm_out_file, byte);
  2588.           total_bytes++;
  2589.           byte = 0;
  2590.         }
  2591.  
  2592.           /* Number of bits we can process at once
  2593.          (all part of the same byte).  */
  2594.           this_time = MIN (end_offset - next_offset,
  2595.                    BITS_PER_UNIT - next_bit);
  2596. #if BYTES_BIG_ENDIAN
  2597.           /* On big-endian machine, take the most significant bits
  2598.          first (of the bits that are significant)
  2599.          and put them into bytes from the most significant end.  */
  2600.           byte |= (((TREE_INT_CST_LOW (val)
  2601.              >> (end_offset - next_offset - this_time))
  2602.             & ((1 << this_time) - 1))
  2603.                << (BITS_PER_UNIT - this_time - next_bit));
  2604. #else
  2605.           /* On little-endian machines,
  2606.          take first the least significant bits of the value
  2607.          and pack them starting at the least significant
  2608.          bits of the bytes.  */
  2609.           byte |= ((TREE_INT_CST_LOW (val)
  2610.             >> (next_offset
  2611.                 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))))
  2612.                & ((1 << this_time) - 1)) << next_bit;
  2613. #endif
  2614.           next_offset += this_time;
  2615.           byte_buffer_in_use = 1;
  2616.         }
  2617.     }
  2618.     }
  2619.   if (byte_buffer_in_use)
  2620.     {
  2621.       ASM_OUTPUT_BYTE (asm_out_file, byte);
  2622.       total_bytes++;
  2623.     }
  2624.   if (total_bytes < size)
  2625.     assemble_zeros (size - total_bytes);
  2626. }
  2627.