OSDN Git Service

* combine.c (SUBST): Break out to a real function do_SUBST.
[pf3gnuchains/gcc-fork.git] / gcc / varasm.c
1 /* Output variables, constants and external declarations, for GNU compiler.
2    Copyright (C) 1987, 88, 89, 92-98, 1999 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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21
22 /* This file handles generation of all the assembler code
23    *except* the instructions of a function.
24    This includes declarations of variables and their initial values.
25
26    We also output the assembler code for constants stored in memory
27    and are responsible for combining constants with the same value.  */
28
29 #include "config.h"
30 #include "system.h"
31 #include <setjmp.h>
32 #include "rtl.h"
33 #include "tree.h"
34 #include "flags.h"
35 #include "function.h"
36 #include "expr.h"
37 #include "output.h"
38 #include "hard-reg-set.h"
39 #include "regs.h"
40 #include "defaults.h"
41 #include "real.h"
42 #include "toplev.h"
43 #include "dbxout.h"
44 #include "sdbout.h"
45
46 #include "obstack.h"
47 #include "c-pragma.h"
48 #include "ggc.h"
49
50 #ifdef XCOFF_DEBUGGING_INFO
51 #include "xcoffout.h"
52 #endif
53
54 #ifndef TRAMPOLINE_ALIGNMENT
55 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
56 #endif
57
58 #ifndef ASM_STABS_OP
59 #define ASM_STABS_OP ".stabs"
60 #endif
61
62 /* Define the prefix to use when check_memory_usage_flag is enable.  */
63 #ifdef NO_DOLLAR_IN_LABEL
64 #ifdef NO_DOT_IN_LABEL
65 #define CHKR_PREFIX "chkr_prefix_"
66 #else /* !NO_DOT_IN_LABEL */
67 #define CHKR_PREFIX "chkr."
68 #endif 
69 #else /* !NO_DOLLAR_IN_LABEL */
70 #define CHKR_PREFIX "chkr$"
71 #endif
72 #define CHKR_PREFIX_SIZE (sizeof (CHKR_PREFIX) - 1)
73
74 /* File in which assembler code is being written.  */
75
76 extern FILE *asm_out_file;
77
78 /* The (assembler) name of the first globally-visible object output.  */
79 char *first_global_object_name;
80 char *weak_global_object_name;
81
82 extern struct obstack *current_obstack;
83 extern struct obstack *saveable_obstack;
84 extern struct obstack *rtl_obstack;
85 extern struct obstack permanent_obstack;
86 #define obstack_chunk_alloc xmalloc
87
88 struct addr_const;
89 struct constant_descriptor;
90 struct rtx_const;
91 struct pool_constant;
92
93 #define MAX_RTX_HASH_TABLE 61
94
95 struct varasm_status
96 {
97   /* Hash facility for making memory-constants
98      from constant rtl-expressions.  It is used on RISC machines
99      where immediate integer arguments and constant addresses are restricted
100      so that such constants must be stored in memory.
101
102      This pool of constants is reinitialized for each function
103      so each function gets its own constants-pool that comes right before
104      it.  */
105   struct constant_descriptor **x_const_rtx_hash_table;
106   struct pool_sym **x_const_rtx_sym_hash_table;
107
108   /* Pointers to first and last constant in pool.  */
109   struct pool_constant *x_first_pool, *x_last_pool;
110
111   /* Current offset in constant pool (does not include any machine-specific
112      header.  */
113   int x_pool_offset;
114
115   /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
116      They are chained through the CONST_DOUBLE_CHAIN.
117      A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
118      In that case, CONST_DOUBLE_MEM is either a MEM,
119      or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.  */
120   rtx x_const_double_chain;
121 };
122
123 #define const_rtx_hash_table (current_function->varasm->x_const_rtx_hash_table)
124 #define const_rtx_sym_hash_table (current_function->varasm->x_const_rtx_sym_hash_table)
125 #define first_pool (current_function->varasm->x_first_pool)
126 #define last_pool (current_function->varasm->x_last_pool)
127 #define pool_offset (current_function->varasm->x_pool_offset)
128 #define const_double_chain (current_function->varasm->x_const_double_chain)
129
130 /* Number for making the label on the next
131    constant that is stored in memory.  */
132
133 int const_labelno;
134
135 /* Number for making the label on the next
136    static variable internal to a function.  */
137
138 int var_labelno;
139
140 /* Carry information from ASM_DECLARE_OBJECT_NAME
141    to ASM_FINISH_DECLARE_OBJECT.  */
142
143 int size_directive_output;
144
145 /* The last decl for which assemble_variable was called,
146    if it did ASM_DECLARE_OBJECT_NAME.
147    If the last call to assemble_variable didn't do that,
148    this holds 0.  */
149
150 tree last_assemble_variable_decl;
151
152 /* Nonzero if at least one function definition has been seen.  */
153
154 static int function_defined;
155
156 static const char *strip_reg_name       PROTO((const char *));
157 static int contains_pointers_p          PROTO((tree));
158 static void decode_addr_const           PROTO((tree, struct addr_const *));
159 static int const_hash                   PROTO((tree));
160 static int compare_constant             PROTO((tree,
161                                                struct constant_descriptor *));
162 static char *compare_constant_1         PROTO((tree, char *));
163 static struct constant_descriptor *record_constant PROTO((tree));
164 static void record_constant_1           PROTO((tree));
165 static tree copy_constant               PROTO((tree));
166 static void output_constant_def_contents  PROTO((tree, int, int));
167 static void decode_rtx_const            PROTO((enum machine_mode, rtx,
168                                                struct rtx_const *));
169 static int const_hash_rtx               PROTO((enum machine_mode, rtx));
170 static int compare_constant_rtx         PROTO((enum machine_mode, rtx,
171                                                struct constant_descriptor *));
172 static struct constant_descriptor *record_constant_rtx PROTO((enum machine_mode,
173                                                               rtx));
174 static struct pool_constant *find_pool_constant PROTO((struct function *, rtx));
175 static void mark_constant_pool          PROTO((void));
176 static void mark_constants              PROTO((rtx));
177 static int output_addressed_constants   PROTO((tree));
178 static void output_after_function_constants PROTO((void));
179 static void output_constructor          PROTO((tree, int));
180 static void remove_from_pending_weak_list       PROTO ((char *));
181 #ifdef ASM_OUTPUT_BSS
182 static void asm_output_bss              PROTO((FILE *, tree, char *, int, int));
183 #endif
184 #ifdef BSS_SECTION_ASM_OP
185 #ifdef ASM_OUTPUT_ALIGNED_BSS
186 static void asm_output_aligned_bss      PROTO((FILE *, tree, char *, int, int));
187 #endif
188 #endif /* BSS_SECTION_ASM_OP */
189 static void mark_pool_constant          PROTO((struct pool_constant *));
190 static void mark_pool_sym_hash_table    PROTO((struct pool_sym **));
191 \f
192 static enum in_section { no_section, in_text, in_data, in_named
193 #ifdef BSS_SECTION_ASM_OP
194   , in_bss
195 #endif
196 #ifdef EH_FRAME_SECTION_ASM_OP
197   , in_eh_frame
198 #endif
199 #ifdef EXTRA_SECTIONS
200   , EXTRA_SECTIONS
201 #endif
202 } in_section = no_section;
203
204 /* Return a non-zero value if DECL has a section attribute.  */
205 #define IN_NAMED_SECTION(DECL) \
206   ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
207    && DECL_SECTION_NAME (DECL) != NULL_TREE)
208
209 /* Text of section name when in_section == in_named.  */
210 static char *in_named_name;
211
212 /* Define functions like text_section for any extra sections.  */
213 #ifdef EXTRA_SECTION_FUNCTIONS
214 EXTRA_SECTION_FUNCTIONS
215 #endif
216
217 /* Tell assembler to switch to text section.  */
218
219 void
220 text_section ()
221 {
222   if (in_section != in_text)
223     {
224       fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
225       in_section = in_text;
226     }
227 }
228
229 /* Tell assembler to switch to data section.  */
230
231 void
232 data_section ()
233 {
234   if (in_section != in_data)
235     {
236       if (flag_shared_data)
237         {
238 #ifdef SHARED_SECTION_ASM_OP
239           fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
240 #else
241           fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
242 #endif
243         }
244       else
245         fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
246
247       in_section = in_data;
248     }
249 }
250 /* Tell assembler to ALWAYS switch to data section, in case
251    it's not sure where it it.  */
252
253 void
254 force_data_section ()
255 {
256   in_section = no_section;
257   data_section ();
258 }
259
260 /* Tell assembler to switch to read-only data section.  This is normally
261    the text section.  */
262
263 void
264 readonly_data_section ()
265 {
266 #ifdef READONLY_DATA_SECTION
267   READONLY_DATA_SECTION ();  /* Note this can call data_section.  */
268 #else
269   text_section ();
270 #endif
271 }
272
273 /* Determine if we're in the text section.  */
274
275 int
276 in_text_section ()
277 {
278   return in_section == in_text;
279 }
280
281 /* Determine if we're in the data section.  */
282
283 int
284 in_data_section ()
285 {
286   return in_section == in_data;
287 }
288
289 /* Tell assembler to change to section NAME for DECL.
290    If DECL is NULL, just switch to section NAME.
291    If NAME is NULL, get the name from DECL.
292    If RELOC is 1, the initializer for DECL contains relocs.  */
293
294 void
295 named_section (decl, name, reloc)
296      tree decl;
297      const char *name;
298      int reloc ATTRIBUTE_UNUSED;
299 {
300   if (decl != NULL_TREE
301       && TREE_CODE_CLASS (TREE_CODE (decl)) != 'd')
302     abort ();
303   if (name == NULL)
304     name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
305
306   if (in_section != in_named || strcmp (name, in_named_name))
307     {
308 #ifdef ASM_OUTPUT_SECTION_NAME
309       ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name, reloc);
310 #else
311       /* Section attributes are not supported if this macro isn't provided -
312          some host formats don't support them at all.  The front-end should
313          already have flagged this as an error.  */
314       abort ();
315 #endif
316
317       in_named_name = ggc_alloc_string (name, -1);
318       in_section = in_named;
319     }
320 }
321
322 #ifdef ASM_OUTPUT_SECTION_NAME
323 #ifndef UNIQUE_SECTION
324 #define UNIQUE_SECTION(DECL,RELOC)                              \
325 do {                                                            \
326   int len;                                                      \
327   const char *name;                                             \
328   char *string;                                                 \
329                                                                 \
330   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL));       \
331   /* Strip off any encoding in name.  */                        \
332   STRIP_NAME_ENCODING (name, name);                             \
333                                                                 \
334   len = strlen (name) + 1;                                      \
335   string = alloca (len + 1);                                    \
336   sprintf (string, ".%s", name);                                \
337                                                                 \
338   DECL_SECTION_NAME (DECL) = build_string (len, string);        \
339 } while (0)
340 #endif
341 #ifndef UNIQUE_SECTION_P
342 #define UNIQUE_SECTION_P(DECL) 0
343 #endif
344 #endif
345
346 #ifdef BSS_SECTION_ASM_OP
347
348 /* Tell the assembler to switch to the bss section.  */
349
350 void
351 bss_section ()
352 {
353   if (in_section != in_bss)
354     {
355 #ifdef SHARED_BSS_SECTION_ASM_OP
356       if (flag_shared_data)
357         fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
358       else
359 #endif
360         fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
361
362       in_section = in_bss;
363     }
364 }
365
366 #ifdef ASM_OUTPUT_BSS
367
368 /* Utility function for ASM_OUTPUT_BSS for targets to use if
369    they don't support alignments in .bss.
370    ??? It is believed that this function will work in most cases so such
371    support is localized here.  */
372
373 static void
374 asm_output_bss (file, decl, name, size, rounded)
375      FILE *file;
376      tree decl;
377      char *name;
378      int size, rounded;
379 {
380   ASM_GLOBALIZE_LABEL (file, name);
381   bss_section ();
382 #ifdef ASM_DECLARE_OBJECT_NAME
383   last_assemble_variable_decl = decl;
384   ASM_DECLARE_OBJECT_NAME (file, name, decl);
385 #else
386   /* Standard thing is just output label for the object.  */
387   ASM_OUTPUT_LABEL (file, name);
388 #endif /* ASM_DECLARE_OBJECT_NAME */
389   ASM_OUTPUT_SKIP (file, rounded);
390 }
391
392 #endif
393
394 #ifdef ASM_OUTPUT_ALIGNED_BSS
395
396 /* Utility function for targets to use in implementing
397    ASM_OUTPUT_ALIGNED_BSS.
398    ??? It is believed that this function will work in most cases so such
399    support is localized here.  */
400
401 static void
402 asm_output_aligned_bss (file, decl, name, size, align)
403      FILE *file;
404      tree decl;
405      char *name;
406      int size, align;
407 {
408   ASM_GLOBALIZE_LABEL (file, name);
409   bss_section ();
410   ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
411 #ifdef ASM_DECLARE_OBJECT_NAME
412   last_assemble_variable_decl = decl;
413   ASM_DECLARE_OBJECT_NAME (file, name, decl);
414 #else
415   /* Standard thing is just output label for the object.  */
416   ASM_OUTPUT_LABEL (file, name);
417 #endif /* ASM_DECLARE_OBJECT_NAME */
418   ASM_OUTPUT_SKIP (file, size ? size : 1);
419 }
420
421 #endif
422
423 #endif /* BSS_SECTION_ASM_OP */
424
425 #ifdef EH_FRAME_SECTION_ASM_OP
426 void
427 eh_frame_section ()
428 {
429   if (in_section != in_eh_frame)
430     {
431       fprintf (asm_out_file, "%s\n", EH_FRAME_SECTION_ASM_OP);
432       in_section = in_eh_frame;
433     }
434
435 #endif
436
437 /* Switch to the section for function DECL.
438
439    If DECL is NULL_TREE, switch to the text section.
440    ??? It's not clear that we will ever be passed NULL_TREE, but it's
441    safer to handle it.  */
442
443 void
444 function_section (decl)
445      tree decl;
446 {
447   if (decl != NULL_TREE
448       && DECL_SECTION_NAME (decl) != NULL_TREE)
449     named_section (decl, (char *) 0, 0);
450   else
451     text_section ();
452 }
453
454 /* Switch to section for variable DECL.
455
456    RELOC is the `reloc' argument to SELECT_SECTION.  */
457
458 void
459 variable_section (decl, reloc)
460      tree decl;
461      int reloc;
462 {
463   if (IN_NAMED_SECTION (decl))
464     named_section (decl, NULL, reloc);
465   else
466     {
467       /* C++ can have const variables that get initialized from constructors,
468          and thus can not be in a readonly section.  We prevent this by
469          verifying that the initial value is constant for objects put in a
470          readonly section.
471
472          error_mark_node is used by the C front end to indicate that the
473          initializer has not been seen yet.  In this case, we assume that
474          the initializer must be constant.
475
476          C++ uses error_mark_node for variables that have complicated
477          initializers, but these variables go in BSS so we won't be called
478          for them.  */
479
480 #ifdef SELECT_SECTION
481       SELECT_SECTION (decl, reloc);
482 #else
483       if (DECL_READONLY_SECTION (decl, reloc))
484         readonly_data_section ();
485       else
486         data_section ();
487 #endif
488     }
489 }
490
491 /* Tell assembler to switch to the section for the exception handling
492    table.  */
493
494 void
495 exception_section ()
496 {
497 #if defined (EXCEPTION_SECTION)
498   EXCEPTION_SECTION ();
499 #else
500 #ifdef ASM_OUTPUT_SECTION_NAME
501   named_section (NULL_TREE, ".gcc_except_table", 0);
502 #else
503   if (flag_pic)
504     data_section ();
505   else
506     readonly_data_section ();
507 #endif
508 #endif
509 }
510 \f
511 /* Create the rtl to represent a function, for a function definition.
512    DECL is a FUNCTION_DECL node which describes which function.
513    The rtl is stored into DECL.  */
514
515 void
516 make_function_rtl (decl)
517      tree decl;
518 {
519   char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
520   char *new_name = name;
521
522   /* Rename a nested function to avoid conflicts.  */
523   if (decl_function_context (decl) != 0
524       && DECL_INITIAL (decl) != 0
525       && DECL_RTL (decl) == 0)
526     {
527       char *label;
528
529       name = IDENTIFIER_POINTER (DECL_NAME (decl));
530       ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
531       name = ggc_alloc_string (label, -1);
532       var_labelno++;
533     }
534   else
535     {
536       /* When -fprefix-function-name is used, every function name is
537          prefixed.  Even static functions are prefixed because they
538          could be declared latter.  Note that a nested function name
539          is not prefixed.  */
540       if (flag_prefix_function_name)
541         {
542           size_t name_len = strlen (name);
543
544           new_name = ggc_alloc_string (NULL, name_len + CHKR_PREFIX_SIZE);
545           memcpy (new_name, CHKR_PREFIX, CHKR_PREFIX_SIZE);
546           memcpy (new_name + CHKR_PREFIX_SIZE, name, name_len + 1);
547           name = new_name;
548         }
549     }
550
551   if (DECL_RTL (decl) == 0)
552     {
553       DECL_RTL (decl)
554         = gen_rtx_MEM (DECL_MODE (decl),
555                        gen_rtx_SYMBOL_REF (Pmode, name));
556
557       /* Optionally set flags or add text to the name to record information
558          such as that it is a function name.  If the name is changed, the macro
559          ASM_OUTPUT_LABELREF will have to know how to strip this information.  */
560 #ifdef ENCODE_SECTION_INFO
561       ENCODE_SECTION_INFO (decl);
562 #endif
563     }
564   else
565     {
566       /* ??? Another way to do this would be to do what halfpic.c does
567          and maintain a hashed table of such critters.  */
568       /* ??? Another way to do this would be to pass a flag bit to
569          ENCODE_SECTION_INFO saying whether this is a new decl or not.  */
570       /* Let the target reassign the RTL if it wants.
571          This is necessary, for example, when one machine specific
572          decl attribute overrides another.  */
573 #ifdef REDO_SECTION_INFO_P
574       if (REDO_SECTION_INFO_P (decl))
575         ENCODE_SECTION_INFO (decl);
576 #endif
577     }
578
579   /* Record at least one function has been defined.  */
580   function_defined = 1;
581 }
582
583 /* Given NAME, a putative register name, discard any customary prefixes.  */
584
585 static const char *
586 strip_reg_name (name)
587   const char *name;
588 {
589 #ifdef REGISTER_PREFIX
590   if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
591     name += strlen (REGISTER_PREFIX);
592 #endif
593   if (name[0] == '%' || name[0] == '#')
594     name++;
595   return name;
596 }
597 \f
598 /* Decode an `asm' spec for a declaration as a register name.
599    Return the register number, or -1 if nothing specified,
600    or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
601    or -3 if ASMSPEC is `cc' and is not recognized,
602    or -4 if ASMSPEC is `memory' and is not recognized.
603    Accept an exact spelling or a decimal number.
604    Prefixes such as % are optional.  */
605
606 int
607 decode_reg_name (asmspec)
608   const char *asmspec;
609 {
610   if (asmspec != 0)
611     {
612       int i;
613
614       /* Get rid of confusing prefixes.  */
615       asmspec = strip_reg_name (asmspec);
616         
617       /* Allow a decimal number as a "register name".  */
618       for (i = strlen (asmspec) - 1; i >= 0; i--)
619         if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
620           break;
621       if (asmspec[0] != 0 && i < 0)
622         {
623           i = atoi (asmspec);
624           if (i < FIRST_PSEUDO_REGISTER && i >= 0)
625             return i;
626           else
627             return -2;
628         }
629
630       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
631         if (reg_names[i][0]
632             && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
633           return i;
634
635 #ifdef ADDITIONAL_REGISTER_NAMES
636       {
637         static struct { const char *name; int number; } table[]
638           = ADDITIONAL_REGISTER_NAMES;
639
640         for (i = 0; i < (int)(sizeof (table) / sizeof (table[0])); i++)
641           if (! strcmp (asmspec, table[i].name))
642             return table[i].number;
643       }
644 #endif /* ADDITIONAL_REGISTER_NAMES */
645
646       if (!strcmp (asmspec, "memory"))
647         return -4;
648
649       if (!strcmp (asmspec, "cc"))
650         return -3;
651
652       return -2;
653     }
654
655   return -1;
656 }
657 \f
658 /* Create the DECL_RTL for a declaration for a static or external variable
659    or static or external function.
660    ASMSPEC, if not 0, is the string which the user specified
661    as the assembler symbol name.
662    TOP_LEVEL is nonzero if this is a file-scope variable.
663
664    This is never called for PARM_DECL nodes.  */
665
666 void
667 make_decl_rtl (decl, asmspec, top_level)
668      tree decl;
669      const char *asmspec;
670      int top_level;
671 {
672   register char *name = 0;
673   int reg_number;
674
675   reg_number = decode_reg_name (asmspec);
676
677   if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
678     name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
679
680   if (reg_number == -2)
681     {
682       /* ASMSPEC is given, and not the name of a register.  */
683       size_t len = strlen (asmspec);
684
685       name = ggc_alloc_string (NULL, len + 1);
686       name[0] = '*';
687       memcpy (&name[1], asmspec, len + 1);
688     }
689
690   /* For a duplicate declaration, we can be called twice on the
691      same DECL node.  Don't discard the RTL already made.  */
692   if (DECL_RTL (decl) == 0)
693     {
694       /* First detect errors in declaring global registers.  */
695       if (TREE_CODE (decl) != FUNCTION_DECL
696           && DECL_REGISTER (decl) && reg_number == -1)
697         error_with_decl (decl,
698                          "register name not specified for `%s'");
699       else if (TREE_CODE (decl) != FUNCTION_DECL
700                && DECL_REGISTER (decl) && reg_number < 0)
701         error_with_decl (decl,
702                          "invalid register name for `%s'");
703       else if ((reg_number >= 0 || reg_number == -3)
704                && (TREE_CODE (decl) == FUNCTION_DECL
705                    && ! DECL_REGISTER (decl)))
706         error_with_decl (decl,
707                          "register name given for non-register variable `%s'");
708       else if (TREE_CODE (decl) != FUNCTION_DECL
709                && DECL_REGISTER (decl)
710                && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
711         error_with_decl (decl,
712                          "data type of `%s' isn't suitable for a register");
713       else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)
714                && ! HARD_REGNO_MODE_OK (reg_number,
715                                         TYPE_MODE (TREE_TYPE (decl))))
716         error_with_decl (decl,
717                          "register number for `%s' isn't suitable for data type");
718       /* Now handle properly declared static register variables.  */
719       else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
720         {
721           int nregs;
722
723           if (DECL_INITIAL (decl) != 0 && top_level)
724             {
725               DECL_INITIAL (decl) = 0;
726               error ("global register variable has initial value");
727             }
728           if (fixed_regs[reg_number] == 0
729               && function_defined && top_level)
730             error ("global register variable follows a function definition");
731           if (TREE_THIS_VOLATILE (decl))
732             warning ("volatile register variables don't work as you might wish");
733
734           /* If the user specified one of the eliminables registers here,
735              e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
736              confused with that register and be eliminated.  Although this
737              usage is somewhat suspect, we nevertheless use the following
738              kludge to avoid setting DECL_RTL to frame_pointer_rtx.  */
739
740           DECL_RTL (decl)
741             = gen_rtx_REG (DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
742           REGNO (DECL_RTL (decl)) = reg_number;
743           REG_USERVAR_P (DECL_RTL (decl)) = 1;
744
745           if (top_level)
746             {
747               /* Make this register global, so not usable for anything
748                  else.  */
749 #ifdef ASM_DECLARE_REGISTER_GLOBAL
750               ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
751 #endif
752               nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
753               while (nregs > 0)
754                 globalize_reg (reg_number + --nregs);
755             }
756         }
757       /* Specifying a section attribute on a variable forces it into a
758          non-.bss section, and thus it cannot be common. */
759       else if (TREE_CODE (decl) == VAR_DECL
760                && DECL_SECTION_NAME (decl) != NULL_TREE
761                && DECL_INITIAL (decl) == NULL_TREE
762                && DECL_COMMON (decl))
763           DECL_COMMON (decl) = 0;
764
765       /* Now handle ordinary static variables and functions (in memory).
766          Also handle vars declared register invalidly.  */
767       if (DECL_RTL (decl) == 0)
768         {
769           /* Can't use just the variable's own name for a variable
770              whose scope is less than the whole file.
771              Concatenate a distinguishing number.  */
772           if (!top_level && !TREE_PUBLIC (decl) && asmspec == 0)
773             {
774               char *label;
775
776               ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
777               name = ggc_alloc_string (label, -1);
778               var_labelno++;
779             }
780
781           if (name == 0)
782             abort ();
783
784           /* When -fprefix-function-name is used, the functions
785              names are prefixed.  Only nested function names are not
786              prefixed.  */
787           if (flag_prefix_function_name && TREE_CODE (decl) == FUNCTION_DECL)
788             {
789               size_t name_len = strlen (name);
790               char *new_name;
791
792               new_name = ggc_alloc_string (NULL, name_len + CHKR_PREFIX_SIZE);
793               memcpy (new_name, CHKR_PREFIX, CHKR_PREFIX_SIZE);
794               memcpy (new_name + CHKR_PREFIX_SIZE, name, name_len + 1);
795               name = new_name;
796             }
797
798           DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl),
799                                          gen_rtx_SYMBOL_REF (Pmode, name));
800           MEM_ALIAS_SET (DECL_RTL (decl)) = get_alias_set (decl);
801
802           /* If this variable is to be treated as volatile, show its
803              tree node has side effects.  If it has side effects, either
804              because of this test or from TREE_THIS_VOLATILE also
805              being set, show the MEM is volatile.  */
806           if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
807               && TREE_PUBLIC (decl))
808             TREE_SIDE_EFFECTS (decl) = 1;
809           else if (flag_volatile_static && TREE_CODE (decl) == VAR_DECL
810                && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))
811             TREE_SIDE_EFFECTS (decl) = 1;
812
813           if (TREE_SIDE_EFFECTS (decl))
814             MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
815
816           if (TREE_READONLY (decl))
817             RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
818           MEM_SET_IN_STRUCT_P (DECL_RTL (decl),
819                                AGGREGATE_TYPE_P (TREE_TYPE (decl)));
820
821           /* Optionally set flags or add text to the name to record information
822              such as that it is a function name.
823              If the name is changed, the macro ASM_OUTPUT_LABELREF
824              will have to know how to strip this information.  */
825 #ifdef ENCODE_SECTION_INFO
826           ENCODE_SECTION_INFO (decl);
827 #endif
828         }
829     }
830   else
831     {
832       /* If the old RTL had the wrong mode, fix the mode.  */
833       if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
834         {
835           rtx rtl = DECL_RTL (decl);
836           PUT_MODE (rtl, DECL_MODE (decl));
837         }
838
839       /* ??? Another way to do this would be to do what halfpic.c does
840          and maintain a hashed table of such critters.  */
841       /* ??? Another way to do this would be to pass a flag bit to
842          ENCODE_SECTION_INFO saying whether this is a new decl or not.  */
843       /* Let the target reassign the RTL if it wants.
844          This is necessary, for example, when one machine specific
845          decl attribute overrides another.  */
846 #ifdef REDO_SECTION_INFO_P
847       if (REDO_SECTION_INFO_P (decl))
848         ENCODE_SECTION_INFO (decl);
849 #endif
850     }
851 }
852
853 /* Make the rtl for variable VAR be volatile.
854    Use this only for static variables.  */
855
856 void
857 make_var_volatile (var)
858      tree var;
859 {
860   if (GET_CODE (DECL_RTL (var)) != MEM)
861     abort ();
862
863   MEM_VOLATILE_P (DECL_RTL (var)) = 1;
864 }
865 \f
866 /* Output alignment directive to align for constant expression EXP.  */
867
868 void
869 assemble_constant_align (exp)
870      tree exp;
871 {
872   int align;
873
874   /* Align the location counter as required by EXP's data type.  */
875   align = TYPE_ALIGN (TREE_TYPE (exp));
876 #ifdef CONSTANT_ALIGNMENT
877   align = CONSTANT_ALIGNMENT (exp, align);
878 #endif
879
880   if (align > BITS_PER_UNIT)
881     ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
882 }
883
884 /* Output a string of literal assembler code
885    for an `asm' keyword used between functions.  */
886
887 void
888 assemble_asm (string)
889      tree string;
890 {
891   app_enable ();
892
893   if (TREE_CODE (string) == ADDR_EXPR)
894     string = TREE_OPERAND (string, 0);
895
896   fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
897 }
898
899 #if 0 /* This should no longer be needed, because
900          flag_gnu_linker should be 0 on these systems,
901          which should prevent any output
902          if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent.  */
903 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
904 #ifndef ASM_OUTPUT_CONSTRUCTOR
905 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
906 #endif
907 #ifndef ASM_OUTPUT_DESTRUCTOR
908 #define ASM_OUTPUT_DESTRUCTOR(file, name)
909 #endif
910 #endif
911 #endif /* 0 */
912
913 /* Record an element in the table of global destructors.
914    How this is done depends on what sort of assembler and linker
915    are in use.
916
917    NAME should be the name of a global function to be called
918    at exit time.  This name is output using assemble_name.  */
919
920 void
921 assemble_destructor (name)
922      char *name;
923 {
924 #ifdef ASM_OUTPUT_DESTRUCTOR
925   ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
926 #else
927   if (flag_gnu_linker)
928     {
929       /* Now tell GNU LD that this is part of the static destructor set.  */
930       /* This code works for any machine provided you use GNU as/ld.  */
931       fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
932       assemble_name (asm_out_file, name);
933       fputc ('\n', asm_out_file);
934     }
935 #endif
936 }
937
938 /* Likewise for global constructors.  */
939
940 void
941 assemble_constructor (name)
942      char *name;
943 {
944 #ifdef ASM_OUTPUT_CONSTRUCTOR
945   ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
946 #else
947   if (flag_gnu_linker)
948     {
949       /* Now tell GNU LD that this is part of the static constructor set.  */
950       /* This code works for any machine provided you use GNU as/ld.  */
951       fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
952       assemble_name (asm_out_file, name);
953       fputc ('\n', asm_out_file);
954     }
955 #endif
956 }
957
958 /* Likewise for entries we want to record for garbage collection.
959    Garbage collection is still under development.  */
960
961 void
962 assemble_gc_entry (name)
963      char *name;
964 {
965 #ifdef ASM_OUTPUT_GC_ENTRY
966   ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
967 #else
968   if (flag_gnu_linker)
969     {
970       /* Now tell GNU LD that this is part of the static constructor set.  */
971       fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
972       assemble_name (asm_out_file, name);
973       fputc ('\n', asm_out_file);
974     }
975 #endif
976 }
977 \f
978 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
979    a non-zero value if the constant pool should be output before the
980    start of the function, or a zero value if the pool should output
981    after the end of the function.  The default is to put it before the
982    start.  */
983
984 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
985 #define CONSTANT_POOL_BEFORE_FUNCTION 1
986 #endif
987
988 /* Output assembler code for the constant pool of a function and associated
989    with defining the name of the function.  DECL describes the function.
990    NAME is the function's name.  For the constant pool, we use the current
991    constant pool data.  */
992
993 void
994 assemble_start_function (decl, fnname)
995      tree decl;
996      char *fnname;
997 {
998   int align;
999
1000   /* The following code does not need preprocessing in the assembler.  */
1001
1002   app_disable ();
1003
1004   if (CONSTANT_POOL_BEFORE_FUNCTION)
1005     output_constant_pool (fnname, decl);
1006
1007 #ifdef ASM_OUTPUT_SECTION_NAME
1008   /* If the function is to be put in its own section and it's not in a section
1009      already, indicate so.  */
1010   if ((flag_function_sections
1011        && DECL_SECTION_NAME (decl) == NULL_TREE)
1012       || UNIQUE_SECTION_P (decl))
1013     UNIQUE_SECTION (decl, 0);
1014 #endif
1015
1016   function_section (decl);
1017
1018   /* Tell assembler to move to target machine's alignment for functions.  */
1019   align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1020   if (align > 0)
1021     ASM_OUTPUT_ALIGN (asm_out_file, align);
1022
1023   /* Handle a user-specified function alignment.
1024      Note that we still need to align to FUNCTION_BOUNDARY, as above,
1025      because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all.  */
1026   if (align_functions_log > align)
1027     {
1028 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1029       ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file, 
1030                                  align_functions_log, align_functions-1);
1031 #else
1032       ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1033 #endif
1034     }
1035
1036 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1037   ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1038 #endif
1039
1040 #ifdef SDB_DEBUGGING_INFO
1041   /* Output SDB definition of the function.  */
1042   if (write_symbols == SDB_DEBUG)
1043     sdbout_mark_begin_function ();
1044 #endif
1045
1046 #ifdef DBX_DEBUGGING_INFO
1047   /* Output DBX definition of the function.  */
1048   if (write_symbols == DBX_DEBUG)
1049     dbxout_begin_function (decl);
1050 #endif
1051
1052   /* Make function name accessible from other files, if appropriate.  */
1053
1054   if (TREE_PUBLIC (decl))
1055     {
1056       if (! first_global_object_name)
1057         {
1058           const char *p;
1059           char **name;
1060
1061           if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1062             name = &first_global_object_name;
1063           else
1064             name = &weak_global_object_name;
1065
1066           STRIP_NAME_ENCODING (p, fnname);
1067           *name = permalloc (strlen (p) + 1);
1068           strcpy (*name, p);
1069         }
1070
1071 #ifdef ASM_WEAKEN_LABEL
1072       if (DECL_WEAK (decl))
1073         {
1074           ASM_WEAKEN_LABEL (asm_out_file, fnname);
1075           /* Remove this function from the pending weak list so that
1076              we do not emit multiple .weak directives for it.  */
1077           remove_from_pending_weak_list
1078             (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1079         }
1080       else
1081 #endif
1082       ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
1083     }
1084
1085   /* Do any machine/system dependent processing of the function name */
1086 #ifdef ASM_DECLARE_FUNCTION_NAME
1087   ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1088 #else
1089   /* Standard thing is just output label for the function.  */
1090   ASM_OUTPUT_LABEL (asm_out_file, fnname);
1091 #endif /* ASM_DECLARE_FUNCTION_NAME */
1092 }
1093
1094 /* Output assembler code associated with defining the size of the
1095    function.  DECL describes the function.  NAME is the function's name.  */
1096
1097 void
1098 assemble_end_function (decl, fnname)
1099      tree decl;
1100      char *fnname;
1101 {
1102 #ifdef ASM_DECLARE_FUNCTION_SIZE
1103   ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1104 #endif
1105   if (! CONSTANT_POOL_BEFORE_FUNCTION)
1106     {
1107       output_constant_pool (fnname, decl);
1108       function_section (decl);  /* need to switch back */
1109     }
1110
1111   /* Output any constants which should appear after the function.  */
1112   output_after_function_constants ();
1113 }
1114 \f
1115 /* Assemble code to leave SIZE bytes of zeros.  */
1116
1117 void
1118 assemble_zeros (size)
1119      int size;
1120 {
1121   /* Do no output if -fsyntax-only.  */
1122   if (flag_syntax_only)
1123     return;
1124
1125 #ifdef ASM_NO_SKIP_IN_TEXT
1126   /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1127      so we must output 0s explicitly in the text section.  */
1128   if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1129     {
1130       int i;
1131
1132       for (i = 0; i < size - 20; i += 20)
1133         {
1134 #ifdef ASM_BYTE_OP
1135           fprintf (asm_out_file,
1136                    "%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);
1137 #else
1138           fprintf (asm_out_file,
1139                    "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1140 #endif
1141         }
1142       if (i < size)
1143         {
1144 #ifdef ASM_BYTE_OP
1145           fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
1146 #else
1147           fprintf (asm_out_file, "\tbyte 0");
1148 #endif
1149           i++;
1150           for (; i < size; i++)
1151             fprintf (asm_out_file, ",0");
1152           fprintf (asm_out_file, "\n");
1153         }
1154     }
1155   else
1156 #endif
1157     if (size > 0)
1158       ASM_OUTPUT_SKIP (asm_out_file, size);
1159 }
1160
1161 /* Assemble an alignment pseudo op for an ALIGN-bit boundary.  */
1162
1163 void
1164 assemble_align (align)
1165      int align;
1166 {
1167   if (align > BITS_PER_UNIT)
1168     ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1169 }
1170
1171 /* Assemble a string constant with the specified C string as contents.  */
1172
1173 void
1174 assemble_string (p, size)
1175      const char *p;
1176      int size;
1177 {
1178   int pos = 0;
1179   int maximum = 2000;
1180
1181   /* If the string is very long, split it up.  */
1182
1183   while (pos < size)
1184     {
1185       int thissize = size - pos;
1186       if (thissize > maximum)
1187         thissize = maximum;
1188
1189       ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1190
1191       pos += thissize;
1192       p += thissize;
1193     }
1194 }
1195
1196 \f
1197 /* Assemble everything that is needed for a variable or function declaration.
1198    Not used for automatic variables, and not used for function definitions.
1199    Should not be called for variables of incomplete structure type.
1200
1201    TOP_LEVEL is nonzero if this variable has file scope.
1202    AT_END is nonzero if this is the special handling, at end of compilation,
1203    to define things that have had only tentative definitions.
1204    DONT_OUTPUT_DATA if nonzero means don't actually output the
1205    initial value (that will be done by the caller).  */
1206
1207 void
1208 assemble_variable (decl, top_level, at_end, dont_output_data)
1209      tree decl;
1210      int top_level ATTRIBUTE_UNUSED;
1211      int at_end;
1212      int dont_output_data;
1213 {
1214   register char *name;
1215   unsigned int align;
1216   tree size_tree = NULL_TREE;
1217   int reloc = 0;
1218   enum in_section saved_in_section;
1219
1220   last_assemble_variable_decl = 0;
1221
1222   if (GET_CODE (DECL_RTL (decl)) == REG)
1223     {
1224       /* Do output symbol info for global register variables, but do nothing
1225          else for them.  */
1226
1227       if (TREE_ASM_WRITTEN (decl))
1228         return;
1229       TREE_ASM_WRITTEN (decl) = 1;
1230
1231       /* Do no output if -fsyntax-only.  */
1232       if (flag_syntax_only)
1233         return;
1234
1235 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1236       /* File-scope global variables are output here.  */
1237       if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1238            && top_level)
1239         dbxout_symbol (decl, 0);
1240 #endif
1241 #ifdef SDB_DEBUGGING_INFO
1242       if (write_symbols == SDB_DEBUG && top_level
1243           /* Leave initialized global vars for end of compilation;
1244              see comment in compile_file.  */
1245           && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1246         sdbout_symbol (decl, 0);
1247 #endif
1248
1249       /* Don't output any DWARF debugging information for variables here.
1250          In the case of local variables, the information for them is output
1251          when we do our recursive traversal of the tree representation for
1252          the entire containing function.  In the case of file-scope variables,
1253          we output information for all of them at the very end of compilation
1254          while we are doing our final traversal of the chain of file-scope
1255          declarations.  */
1256
1257       return;
1258     }
1259
1260   /* Normally no need to say anything here for external references,
1261      since assemble_external is called by the language-specific code
1262      when a declaration is first seen.  */
1263
1264   if (DECL_EXTERNAL (decl))
1265     return;
1266
1267   /* Output no assembler code for a function declaration.
1268      Only definitions of functions output anything.  */
1269
1270   if (TREE_CODE (decl) == FUNCTION_DECL)
1271     return;
1272
1273   /* If type was incomplete when the variable was declared,
1274      see if it is complete now.  */
1275
1276   if (DECL_SIZE (decl) == 0)
1277     layout_decl (decl, 0);
1278
1279   /* Still incomplete => don't allocate it; treat the tentative defn
1280      (which is what it must have been) as an `extern' reference.  */
1281
1282   if (!dont_output_data && DECL_SIZE (decl) == 0)
1283     {
1284       error_with_file_and_line (DECL_SOURCE_FILE (decl),
1285                                 DECL_SOURCE_LINE (decl),
1286                                 "storage size of `%s' isn't known",
1287                                 IDENTIFIER_POINTER (DECL_NAME (decl)));
1288       TREE_ASM_WRITTEN (decl) = 1;
1289       return;
1290     }
1291
1292   /* The first declaration of a variable that comes through this function
1293      decides whether it is global (in C, has external linkage)
1294      or local (in C, has internal linkage).  So do nothing more
1295      if this function has already run.  */
1296
1297   if (TREE_ASM_WRITTEN (decl))
1298     return;
1299
1300   TREE_ASM_WRITTEN (decl) = 1;
1301
1302   /* Do no output if -fsyntax-only.  */
1303   if (flag_syntax_only)
1304     return;
1305
1306   app_disable ();
1307
1308   if (! dont_output_data)
1309     {
1310       int size;
1311
1312       if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1313         goto finish;
1314
1315       /* This is better than explicit arithmetic, since it avoids overflow.  */
1316       size_tree = size_binop (CEIL_DIV_EXPR,
1317                               DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1318
1319       size = TREE_INT_CST_LOW (size_tree);
1320       if (TREE_INT_CST_HIGH (size_tree) != 0
1321           || size != TREE_INT_CST_LOW (size_tree))
1322         {
1323           error_with_decl (decl, "size of variable `%s' is too large");
1324           goto finish;
1325         }
1326     }
1327
1328   name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1329
1330   if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1331       && ! first_global_object_name
1332       && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1333                                    || DECL_INITIAL (decl) == error_mark_node))
1334       && ! DECL_WEAK (decl)
1335       && ! DECL_ONE_ONLY (decl))
1336     {
1337       const char *p;
1338
1339       STRIP_NAME_ENCODING (p, name);
1340       first_global_object_name = permalloc (strlen (p) + 1);
1341       strcpy (first_global_object_name, p);
1342     }
1343
1344   /* Compute the alignment of this data.  */
1345
1346   align = DECL_ALIGN (decl);
1347
1348   /* In the case for initialing an array whose length isn't specified,
1349      where we have not yet been able to do the layout,
1350      figure out the proper alignment now.  */
1351   if (dont_output_data && DECL_SIZE (decl) == 0
1352       && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1353     align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1354
1355   /* Some object file formats have a maximum alignment which they support.
1356      In particular, a.out format supports a maximum alignment of 4.  */
1357 #ifndef MAX_OFILE_ALIGNMENT
1358 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1359 #endif
1360   if (align > MAX_OFILE_ALIGNMENT)
1361     {
1362       warning_with_decl (decl,
1363         "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1364                     MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1365       align = MAX_OFILE_ALIGNMENT;
1366     }
1367
1368   /* On some machines, it is good to increase alignment sometimes.  */
1369 #ifdef DATA_ALIGNMENT
1370   align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1371 #endif
1372 #ifdef CONSTANT_ALIGNMENT
1373   if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1374     align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1375 #endif
1376
1377   /* Reset the alignment in case we have made it tighter, so we can benefit
1378      from it in get_pointer_alignment.  */
1379   DECL_ALIGN (decl) = align;
1380
1381   /* Handle uninitialized definitions.  */
1382
1383   if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1384       /* If the target can't output uninitialized but not common global data
1385          in .bss, then we have to use .data.  */
1386 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
1387       && DECL_COMMON (decl)
1388 #endif
1389       && DECL_SECTION_NAME (decl) == 0
1390       && ! dont_output_data)
1391     {
1392       int size = TREE_INT_CST_LOW (size_tree);
1393       int rounded = size;
1394
1395       /* Don't allocate zero bytes of common,
1396          since that means "undefined external" in the linker.  */
1397       if (size == 0) rounded = 1;
1398       /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1399          so that each uninitialized object starts on such a boundary.  */
1400       rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1401       rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1402                  * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1403       
1404 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1405       if ( (DECL_ALIGN (decl) / BITS_PER_UNIT) > rounded)
1406          warning_with_decl 
1407            (decl, "requested alignment for %s is greater than implemented alignment of %d.",rounded);
1408 #endif
1409        
1410 #ifdef DBX_DEBUGGING_INFO
1411       /* File-scope global variables are output here.  */
1412       if (write_symbols == DBX_DEBUG && top_level)
1413         dbxout_symbol (decl, 0);
1414 #endif
1415 #ifdef SDB_DEBUGGING_INFO
1416       if (write_symbols == SDB_DEBUG && top_level
1417           /* Leave initialized global vars for end of compilation;
1418              see comment in compile_file.  */
1419           && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1420         sdbout_symbol (decl, 0);
1421 #endif
1422
1423       /* Don't output any DWARF debugging information for variables here.
1424          In the case of local variables, the information for them is output
1425          when we do our recursive traversal of the tree representation for
1426          the entire containing function.  In the case of file-scope variables,
1427          we output information for all of them at the very end of compilation
1428          while we are doing our final traversal of the chain of file-scope
1429          declarations.  */
1430
1431 #if 0 /* ??? We should either delete this or add a comment describing what
1432          it was intended to do and why we shouldn't delete it.  */
1433       if (flag_shared_data)
1434         data_section ();
1435 #endif
1436
1437       if (TREE_PUBLIC (decl)
1438 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1439           && DECL_COMMON (decl)
1440 #endif
1441           )
1442         {
1443 #ifdef ASM_OUTPUT_SHARED_COMMON
1444           if (flag_shared_data)
1445             ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1446           else
1447 #endif
1448               {
1449 #ifdef ASM_OUTPUT_ALIGNED_DECL_COMMON
1450                 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size,
1451                                                    DECL_ALIGN (decl));
1452 #else
1453 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1454                 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1455                                            DECL_ALIGN (decl));
1456 #else
1457                 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1458 #endif
1459 #endif
1460               }
1461         }
1462 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1463       else if (TREE_PUBLIC (decl))
1464         {
1465 #ifdef ASM_OUTPUT_SHARED_BSS
1466           if (flag_shared_data)
1467             ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1468           else
1469 #endif
1470               {
1471 #ifdef ASM_OUTPUT_ALIGNED_BSS
1472                 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size,
1473                                         DECL_ALIGN (decl));
1474 #else
1475                 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1476 #endif
1477               }
1478         }
1479 #endif /* ASM_OUTPUT_BSS || ASM_OUTPUT_ALIGNED_BSS */
1480       else
1481         {
1482 #ifdef ASM_OUTPUT_SHARED_LOCAL
1483           if (flag_shared_data)
1484             ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1485           else
1486 #endif
1487               {
1488 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1489                 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size,
1490                                                   DECL_ALIGN (decl));
1491 #else
1492 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1493                 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1494                                           DECL_ALIGN (decl));
1495 #else
1496                 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1497 #endif
1498 #endif
1499               }
1500         }
1501       goto finish;
1502     }
1503
1504   /* Handle initialized definitions.
1505      Also handle uninitialized global definitions if -fno-common and the
1506      target doesn't support ASM_OUTPUT_BSS.  */
1507
1508   /* First make the assembler name(s) global if appropriate.  */
1509   if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1510     {
1511 #ifdef ASM_WEAKEN_LABEL
1512       if (DECL_WEAK (decl)) 
1513         {
1514           ASM_WEAKEN_LABEL (asm_out_file, name);
1515            /* Remove this variable from the pending weak list so that
1516               we do not emit multiple .weak directives for it.  */
1517           remove_from_pending_weak_list
1518             (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1519         }
1520       else
1521 #endif
1522       ASM_GLOBALIZE_LABEL (asm_out_file, name);
1523     }
1524 #if 0
1525   for (d = equivalents; d; d = TREE_CHAIN (d))
1526     {
1527       tree e = TREE_VALUE (d);
1528       if (TREE_PUBLIC (e) && DECL_NAME (e))
1529         ASM_GLOBALIZE_LABEL (asm_out_file,
1530                              XSTR (XEXP (DECL_RTL (e), 0), 0));
1531     }
1532 #endif
1533
1534   /* Output any data that we will need to use the address of.  */
1535   if (DECL_INITIAL (decl) == error_mark_node)
1536     reloc = contains_pointers_p (TREE_TYPE (decl));
1537   else if (DECL_INITIAL (decl))
1538     reloc = output_addressed_constants (DECL_INITIAL (decl));
1539
1540 #ifdef ASM_OUTPUT_SECTION_NAME
1541   if ((flag_data_sections != 0
1542        && DECL_SECTION_NAME (decl) == NULL_TREE)
1543       || UNIQUE_SECTION_P (decl))
1544     UNIQUE_SECTION (decl, reloc);
1545 #endif
1546
1547   /* Switch to the appropriate section.  */
1548   variable_section (decl, reloc);
1549
1550   /* dbxout.c needs to know this.  */
1551   if (in_text_section ())
1552     DECL_IN_TEXT_SECTION (decl) = 1;
1553
1554   /* Record current section so we can restore it if dbxout.c clobbers it.  */
1555   saved_in_section = in_section;
1556
1557   /* Output the dbx info now that we have chosen the section.  */
1558
1559 #ifdef DBX_DEBUGGING_INFO
1560   /* File-scope global variables are output here.  */
1561   if (write_symbols == DBX_DEBUG && top_level)
1562     dbxout_symbol (decl, 0);
1563 #endif
1564 #ifdef SDB_DEBUGGING_INFO
1565   if (write_symbols == SDB_DEBUG && top_level
1566       /* Leave initialized global vars for end of compilation;
1567          see comment in compile_file.  */
1568       && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1569     sdbout_symbol (decl, 0);
1570 #endif
1571
1572   /* Don't output any DWARF debugging information for variables here.
1573      In the case of local variables, the information for them is output
1574      when we do our recursive traversal of the tree representation for
1575      the entire containing function.  In the case of file-scope variables,
1576      we output information for all of them at the very end of compilation
1577      while we are doing our final traversal of the chain of file-scope
1578      declarations.  */
1579
1580   /* If the debugging output changed sections, reselect the section
1581      that's supposed to be selected.  */
1582   if (in_section != saved_in_section)
1583     variable_section (decl, reloc);
1584
1585   /* Output the alignment of this data.  */
1586   if (align > BITS_PER_UNIT)
1587     ASM_OUTPUT_ALIGN (asm_out_file,
1588                       floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1589
1590   /* Do any machine/system dependent processing of the object.  */
1591 #ifdef ASM_DECLARE_OBJECT_NAME
1592   last_assemble_variable_decl = decl;
1593   ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1594 #else
1595   /* Standard thing is just output label for the object.  */
1596   ASM_OUTPUT_LABEL (asm_out_file, name);
1597 #endif /* ASM_DECLARE_OBJECT_NAME */
1598
1599   if (!dont_output_data)
1600     {
1601       if (DECL_INITIAL (decl))
1602         /* Output the actual data.  */
1603         output_constant (DECL_INITIAL (decl), TREE_INT_CST_LOW (size_tree));
1604       else
1605         /* Leave space for it.  */
1606         assemble_zeros (TREE_INT_CST_LOW (size_tree));
1607     }
1608
1609  finish:
1610 #ifdef XCOFF_DEBUGGING_INFO
1611   /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1612      declaration.  When something like ".stabx  "aa:S-2",aa,133,0" is emitted 
1613      and `aa' hasn't been output yet, the assembler generates a stab entry with
1614      a value of zero, in addition to creating an unnecessary external entry
1615      for `aa'.  Hence, we must postpone dbxout_symbol to here at the end.  */
1616
1617   /* File-scope global variables are output here.  */
1618   if (write_symbols == XCOFF_DEBUG && top_level)
1619     {
1620       saved_in_section = in_section;
1621
1622       dbxout_symbol (decl, 0);
1623
1624       if (in_section != saved_in_section)
1625         variable_section (decl, reloc);
1626     }
1627 #else
1628   /* There must be a statement after a label.  */
1629   ;
1630 #endif
1631 }
1632
1633 /* Return 1 if type TYPE contains any pointers.  */
1634
1635 static int
1636 contains_pointers_p (type)
1637      tree type;
1638 {
1639   switch (TREE_CODE (type))
1640     {
1641     case POINTER_TYPE:
1642     case REFERENCE_TYPE:
1643       /* I'm not sure whether OFFSET_TYPE needs this treatment,
1644          so I'll play safe and return 1.  */
1645     case OFFSET_TYPE:
1646       return 1;
1647
1648     case RECORD_TYPE:
1649     case UNION_TYPE:
1650     case QUAL_UNION_TYPE:
1651       {
1652         tree fields;
1653         /* For a type that has fields, see if the fields have pointers.  */
1654         for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1655           if (TREE_CODE (fields) == FIELD_DECL
1656               && contains_pointers_p (TREE_TYPE (fields)))
1657             return 1;
1658         return 0;
1659       }
1660
1661     case ARRAY_TYPE:
1662       /* An array type contains pointers if its element type does.  */
1663       return contains_pointers_p (TREE_TYPE (type));
1664
1665     default:
1666       return 0;
1667     }
1668 }
1669
1670 /* Output something to declare an external symbol to the assembler.
1671    (Most assemblers don't need this, so we normally output nothing.)
1672    Do nothing if DECL is not external.  */
1673
1674 void
1675 assemble_external (decl)
1676      tree decl ATTRIBUTE_UNUSED;
1677 {
1678 #ifdef ASM_OUTPUT_EXTERNAL
1679   if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1680       && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1681     {
1682       rtx rtl = DECL_RTL (decl);
1683
1684       if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1685           && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1686         {
1687           /* Some systems do require some output.  */
1688           SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1689           ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1690         }
1691     }
1692 #endif
1693 }
1694
1695 /* Similar, for calling a library function FUN.  */
1696
1697 void
1698 assemble_external_libcall (fun)
1699      rtx fun ATTRIBUTE_UNUSED;
1700 {
1701 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1702   /* Declare library function name external when first used, if nec.  */
1703   if (! SYMBOL_REF_USED (fun))
1704     {
1705       SYMBOL_REF_USED (fun) = 1;
1706       ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1707     }
1708 #endif
1709 }
1710
1711 /* Declare the label NAME global.  */
1712
1713 void
1714 assemble_global (name)
1715      char *name;
1716 {
1717   ASM_GLOBALIZE_LABEL (asm_out_file, name);
1718 }
1719
1720 /* Assemble a label named NAME.  */
1721
1722 void
1723 assemble_label (name)
1724      char *name;
1725 {
1726   ASM_OUTPUT_LABEL (asm_out_file, name);
1727 }
1728
1729 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1730    If NAME starts with a *, the rest of NAME is output verbatim.
1731    Otherwise NAME is transformed in an implementation-defined way
1732    (usually by the addition of an underscore).
1733    Many macros in the tm file are defined to call this function.  */
1734
1735 void
1736 assemble_name (file, name)
1737      FILE *file;
1738      const char *name;
1739 {
1740   const char *real_name;
1741   tree id;
1742
1743   STRIP_NAME_ENCODING (real_name, name);
1744   if (flag_prefix_function_name 
1745       && ! bcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE))
1746     real_name = real_name + CHKR_PREFIX_SIZE;
1747
1748   id = maybe_get_identifier (real_name);
1749   if (id)
1750     TREE_SYMBOL_REFERENCED (id) = 1;
1751
1752   if (name[0] == '*')
1753     fputs (&name[1], file);
1754   else
1755     ASM_OUTPUT_LABELREF (file, name);
1756 }
1757
1758 /* Allocate SIZE bytes writable static space with a gensym name
1759    and return an RTX to refer to its address.  */
1760
1761 rtx
1762 assemble_static_space (size)
1763      int size;
1764 {
1765   char name[12];
1766   char *namestring;
1767   rtx x;
1768
1769 #if 0
1770   if (flag_shared_data)
1771     data_section ();
1772 #endif
1773
1774   ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1775   ++const_labelno;
1776   namestring = ggc_alloc_string (name, -1);
1777
1778   x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1779
1780 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1781   ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1782                                  BIGGEST_ALIGNMENT);
1783 #else
1784 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1785   ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1786 #else
1787   {
1788     /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1789        so that each uninitialized object starts on such a boundary.  */
1790     /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1791     int rounded ATTRIBUTE_UNUSED
1792       = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1793          / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1794          * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1795     ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1796   }
1797 #endif
1798 #endif
1799   return x;
1800 }
1801
1802 /* Assemble the static constant template for function entry trampolines.
1803    This is done at most once per compilation.
1804    Returns an RTX for the address of the template.  */
1805
1806 #ifdef TRAMPOLINE_TEMPLATE
1807 rtx
1808 assemble_trampoline_template ()
1809 {
1810   char label[256];
1811   char *name;
1812   int align;
1813
1814   /* By default, put trampoline templates in read-only data section.  */
1815
1816 #ifdef TRAMPOLINE_SECTION
1817   TRAMPOLINE_SECTION ();
1818 #else
1819   readonly_data_section ();
1820 #endif
1821
1822   /* Write the assembler code to define one.  */
1823   align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1824   if (align > 0)
1825     ASM_OUTPUT_ALIGN (asm_out_file, align);
1826
1827   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1828   TRAMPOLINE_TEMPLATE (asm_out_file);
1829
1830   /* Record the rtl to refer to it.  */
1831   ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1832   name = ggc_alloc_string (label, -1);
1833   return gen_rtx_SYMBOL_REF (Pmode, name);
1834 }
1835 #endif
1836 \f
1837 /* Assemble the integer constant X into an object of SIZE bytes.
1838    X must be either a CONST_INT or CONST_DOUBLE.
1839
1840    Return 1 if we were able to output the constant, otherwise 0.  If FORCE is
1841    non-zero, abort if we can't output the constant.  */
1842
1843 int
1844 assemble_integer (x, size, force)
1845      rtx x;
1846      int size;
1847      int force;
1848 {
1849   /* First try to use the standard 1, 2, 4, 8, and 16 byte
1850      ASM_OUTPUT... macros.  */
1851
1852   switch (size)
1853     {
1854 #ifdef ASM_OUTPUT_CHAR
1855     case 1:
1856       ASM_OUTPUT_CHAR (asm_out_file, x);
1857       return 1;
1858 #endif
1859
1860 #ifdef ASM_OUTPUT_SHORT
1861     case 2:
1862       ASM_OUTPUT_SHORT (asm_out_file, x);
1863       return 1;
1864 #endif
1865
1866 #ifdef ASM_OUTPUT_INT
1867     case 4:
1868       ASM_OUTPUT_INT (asm_out_file, x);
1869       return 1;
1870 #endif
1871
1872 #ifdef ASM_OUTPUT_DOUBLE_INT
1873     case 8:
1874       ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1875       return 1;
1876 #endif
1877
1878 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1879     case 16:
1880       ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1881       return 1;
1882 #endif
1883     }
1884
1885   /* If we couldn't do it that way, there are two other possibilities: First,
1886      if the machine can output an explicit byte and this is a 1 byte constant,
1887      we can use ASM_OUTPUT_BYTE.  */
1888
1889 #ifdef ASM_OUTPUT_BYTE
1890   if (size == 1 && GET_CODE (x) == CONST_INT)
1891     {
1892       ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1893       return 1;
1894     }
1895 #endif
1896
1897   /* Finally, if SIZE is larger than a single word, try to output the constant
1898      one word at a time.  */
1899
1900   if (size > UNITS_PER_WORD)
1901     {
1902       int i;
1903       enum machine_mode mode
1904         = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1905       rtx word;
1906
1907       for (i = 0; i < size / UNITS_PER_WORD; i++)
1908         {
1909           word = operand_subword (x, i, 0, mode);
1910
1911           if (word == 0)
1912             break;
1913
1914           if (! assemble_integer (word, UNITS_PER_WORD, 0))
1915             break;
1916         }
1917
1918       if (i == size / UNITS_PER_WORD)
1919         return 1;
1920       /* If we output at least one word and then could not finish,
1921          there is no valid way to continue.  */
1922       if (i > 0)
1923         abort ();
1924     }
1925
1926   if (force)
1927     abort ();
1928
1929   return 0;
1930 }
1931 \f
1932 /* Assemble the floating-point constant D into an object of size MODE.  */
1933
1934 void
1935 assemble_real (d, mode)
1936      REAL_VALUE_TYPE d;
1937      enum machine_mode mode;
1938 {
1939   jmp_buf output_constant_handler;
1940
1941   if (setjmp (output_constant_handler))
1942     {
1943       error ("floating point trap outputting a constant");
1944 #ifdef REAL_IS_NOT_DOUBLE
1945       bzero ((char *) &d, sizeof d);
1946       d = dconst0;
1947 #else
1948       d = 0;
1949 #endif
1950     }
1951
1952   set_float_handler (output_constant_handler);
1953
1954   switch (mode)
1955     {
1956 #ifdef ASM_OUTPUT_BYTE_FLOAT
1957     case QFmode:
1958       ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1959       break;
1960 #endif
1961 #ifdef ASM_OUTPUT_SHORT_FLOAT
1962     case HFmode:
1963       ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1964       break;
1965 #endif
1966 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1967     case TQFmode:
1968       ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1969       break;
1970 #endif
1971 #ifdef ASM_OUTPUT_FLOAT
1972     case SFmode:
1973       ASM_OUTPUT_FLOAT (asm_out_file, d);
1974       break;
1975 #endif
1976
1977 #ifdef ASM_OUTPUT_DOUBLE
1978     case DFmode:
1979       ASM_OUTPUT_DOUBLE (asm_out_file, d);
1980       break;
1981 #endif
1982
1983 #ifdef ASM_OUTPUT_LONG_DOUBLE
1984     case XFmode:
1985     case TFmode:
1986       ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1987       break;
1988 #endif
1989
1990     default:
1991       abort ();
1992     }
1993
1994   set_float_handler (NULL_PTR);
1995 }
1996 \f
1997 /* Here we combine duplicate floating constants to make
1998    CONST_DOUBLE rtx's, and force those out to memory when necessary.  */
1999
2000 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2001    For an integer, I0 is the low-order word and I1 is the high-order word.
2002    For a real number, I0 is the word with the low address
2003    and I1 is the word with the high address.  */
2004
2005 rtx
2006 immed_double_const (i0, i1, mode)
2007      HOST_WIDE_INT i0, i1;
2008      enum machine_mode mode;
2009 {
2010   register rtx r;
2011
2012   if (GET_MODE_CLASS (mode) == MODE_INT
2013       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
2014     {
2015       /* We clear out all bits that don't belong in MODE, unless they and our
2016          sign bit are all one.  So we get either a reasonable negative value
2017          or a reasonable unsigned value for this mode.  */
2018       int width = GET_MODE_BITSIZE (mode);
2019       if (width < HOST_BITS_PER_WIDE_INT
2020           && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
2021               != ((HOST_WIDE_INT) (-1) << (width - 1))))
2022         i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
2023       else if (width == HOST_BITS_PER_WIDE_INT
2024                && ! (i1 == ~0 && i0 < 0))
2025         i1 = 0;
2026       else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2027         /* We cannot represent this value as a constant.  */
2028         abort ();
2029
2030       /* If this would be an entire word for the target, but is not for
2031          the host, then sign-extend on the host so that the number will look
2032          the same way on the host that it would on the target.
2033
2034          For example, when building a 64 bit alpha hosted 32 bit sparc
2035          targeted compiler, then we want the 32 bit unsigned value -1 to be
2036          represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2037          The later confuses the sparc backend.  */
2038
2039       if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
2040           && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2041         i0 |= ((HOST_WIDE_INT) (-1) << width);
2042
2043       /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2044
2045          ??? Strictly speaking, this is wrong if we create a CONST_INT
2046          for a large unsigned constant with the size of MODE being
2047          HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2048          wider mode.  In that case we will mis-interpret it as a negative
2049          number.
2050
2051          Unfortunately, the only alternative is to make a CONST_DOUBLE
2052          for any constant in any mode if it is an unsigned constant larger
2053          than the maximum signed integer in an int on the host.  However,
2054          doing this will break everyone that always expects to see a CONST_INT
2055          for SImode and smaller.
2056
2057          We have always been making CONST_INTs in this case, so nothing new
2058          is being broken.  */
2059
2060       if (width <= HOST_BITS_PER_WIDE_INT)
2061         i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2062
2063       /* If this integer fits in one word, return a CONST_INT.  */
2064       if ((i1 == 0 && i0 >= 0)
2065           || (i1 == ~0 && i0 < 0))
2066         return GEN_INT (i0);
2067
2068       /* We use VOIDmode for integers.  */
2069       mode = VOIDmode;
2070     }
2071
2072   /* Search the chain for an existing CONST_DOUBLE with the right value.
2073      If one is found, return it.  */
2074   if (current_function != 0)
2075     for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2076       if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2077           && GET_MODE (r) == mode)
2078         return r;
2079
2080   /* No; make a new one and add it to the chain.
2081
2082      We may be called by an optimizer which may be discarding any memory
2083      allocated during its processing (such as combine and loop).  However,
2084      we will be leaving this constant on the chain, so we cannot tolerate
2085      freed memory.  So switch to saveable_obstack for this allocation
2086      and then switch back if we were in current_obstack.  */
2087
2088   push_obstacks_nochange ();
2089   rtl_in_saveable_obstack ();
2090   r = gen_rtx_CONST_DOUBLE (mode, NULL_RTX, i0, i1);
2091   pop_obstacks ();
2092
2093   /* Don't touch const_double_chain if not inside any function.  */
2094   if (current_function_decl != 0)
2095     {
2096       CONST_DOUBLE_CHAIN (r) = const_double_chain;
2097       const_double_chain = r;
2098     }
2099
2100   /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
2101      Actual use of mem-slot is only through force_const_mem.  */
2102
2103   CONST_DOUBLE_MEM (r) = const0_rtx;
2104
2105   return r;
2106 }
2107
2108 /* Return a CONST_DOUBLE for a specified `double' value
2109    and machine mode.  */
2110
2111 rtx
2112 immed_real_const_1 (d, mode)
2113      REAL_VALUE_TYPE d;
2114      enum machine_mode mode;
2115 {
2116   union real_extract u;
2117   register rtx r;
2118
2119   /* Get the desired `double' value as a sequence of ints
2120      since that is how they are stored in a CONST_DOUBLE.  */
2121
2122   u.d = d;
2123
2124   /* Detect special cases.  */
2125
2126   if (REAL_VALUES_IDENTICAL (dconst0, d))
2127     return CONST0_RTX (mode);
2128   /* Check for NaN first, because some ports (specifically the i386) do not
2129      emit correct ieee-fp code by default, and thus will generate a core
2130      dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2131      does a floating point comparison.  */
2132   else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2133     return CONST1_RTX (mode);
2134
2135   if (sizeof u == sizeof (HOST_WIDE_INT))
2136     return immed_double_const (u.i[0], 0, mode);
2137   if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2138     return immed_double_const (u.i[0], u.i[1], mode);
2139
2140   /* The rest of this function handles the case where
2141      a float value requires more than 2 ints of space.
2142      It will be deleted as dead code on machines that don't need it.  */
2143
2144   /* Search the chain for an existing CONST_DOUBLE with the right value.
2145      If one is found, return it.  */
2146   if (current_function != 0)
2147     for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2148       if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2149           && GET_MODE (r) == mode)
2150         return r;
2151
2152   /* No; make a new one and add it to the chain.
2153
2154      We may be called by an optimizer which may be discarding any memory
2155      allocated during its processing (such as combine and loop).  However,
2156      we will be leaving this constant on the chain, so we cannot tolerate
2157      freed memory.  So switch to saveable_obstack for this allocation
2158      and then switch back if we were in current_obstack.  */
2159   push_obstacks_nochange ();
2160   rtl_in_saveable_obstack ();
2161   r = rtx_alloc (CONST_DOUBLE);
2162   pop_obstacks ();
2163   PUT_MODE (r, mode);
2164   bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
2165
2166   /* Don't touch const_double_chain if not inside any function.  */
2167   if (current_function_decl != 0)
2168     {
2169       CONST_DOUBLE_CHAIN (r) = const_double_chain;
2170       const_double_chain = r;
2171     }
2172
2173   /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2174      chain, but has not been allocated memory.  Actual use of CONST_DOUBLE_MEM
2175      is only through force_const_mem.  */
2176
2177   CONST_DOUBLE_MEM (r) = const0_rtx;
2178
2179   return r;
2180 }
2181
2182 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2183    which must be a REAL_CST tree node.  */
2184
2185 rtx
2186 immed_real_const (exp)
2187      tree exp;
2188 {
2189   return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2190 }
2191
2192 /* At the end of a function, forget the memory-constants
2193    previously made for CONST_DOUBLEs.  Mark them as not on real_constant_chain.
2194    Also clear out real_constant_chain and clear out all the chain-pointers.  */
2195
2196 void
2197 clear_const_double_mem ()
2198 {
2199   register rtx r, next;
2200
2201   for (r = const_double_chain; r; r = next)
2202     {
2203       next = CONST_DOUBLE_CHAIN (r);
2204       CONST_DOUBLE_CHAIN (r) = 0;
2205       CONST_DOUBLE_MEM (r) = cc0_rtx;
2206     }
2207   const_double_chain = 0;
2208 }
2209 \f
2210 /* Given an expression EXP with a constant value,
2211    reduce it to the sum of an assembler symbol and an integer.
2212    Store them both in the structure *VALUE.
2213    Abort if EXP does not reduce.  */
2214
2215 struct addr_const
2216 {
2217   rtx base;
2218   HOST_WIDE_INT offset;
2219 };
2220
2221 static void
2222 decode_addr_const (exp, value)
2223      tree exp;
2224      struct addr_const *value;
2225 {
2226   register tree target = TREE_OPERAND (exp, 0);
2227   register int offset = 0;
2228   register rtx x;
2229
2230   while (1)
2231     {
2232       if (TREE_CODE (target) == COMPONENT_REF
2233           && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2234               == INTEGER_CST))
2235         {
2236           offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2237           target = TREE_OPERAND (target, 0);
2238         }
2239       else if (TREE_CODE (target) == ARRAY_REF)
2240         {
2241           if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2242               || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2243             abort ();
2244           offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2245                       * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2246                      / BITS_PER_UNIT);
2247           target = TREE_OPERAND (target, 0);
2248         }
2249       else
2250         break;
2251     }
2252
2253   switch (TREE_CODE (target))
2254     {
2255     case VAR_DECL:
2256     case FUNCTION_DECL:
2257       x = DECL_RTL (target);
2258       break;
2259
2260     case LABEL_DECL:
2261       x = gen_rtx_MEM (FUNCTION_MODE,
2262                        gen_rtx_LABEL_REF (VOIDmode,
2263                                           label_rtx (TREE_OPERAND (exp, 0))));
2264       break;
2265
2266     case REAL_CST:
2267     case STRING_CST:
2268     case COMPLEX_CST:
2269     case CONSTRUCTOR:
2270     case INTEGER_CST:
2271       x = TREE_CST_RTL (target);
2272       break;
2273
2274     default:
2275       abort ();
2276     }
2277
2278   if (GET_CODE (x) != MEM)
2279     abort ();
2280   x = XEXP (x, 0);
2281
2282   value->base = x;
2283   value->offset = offset;
2284 }
2285 \f
2286 /* Uniquize all constants that appear in memory.
2287    Each constant in memory thus far output is recorded
2288    in `const_hash_table' with a `struct constant_descriptor'
2289    that contains a polish representation of the value of
2290    the constant.
2291
2292    We cannot store the trees in the hash table
2293    because the trees may be temporary.  */
2294
2295 struct constant_descriptor
2296 {
2297   struct constant_descriptor *next;
2298   char *label;
2299   char contents[1];
2300 };
2301
2302 #define HASHBITS 30
2303 #define MAX_HASH_TABLE 1009
2304 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2305
2306 /* Mark a const_hash_table descriptor for GC.  */
2307
2308 static void 
2309 mark_const_hash_entry (ptr)
2310      void *ptr;
2311 {
2312   struct constant_descriptor *desc = * (struct constant_descriptor **) ptr;
2313
2314   while (desc)
2315     {
2316       ggc_mark_string (desc->label);
2317       desc = desc->next;
2318     }
2319 }
2320
2321 /* Compute a hash code for a constant expression.  */
2322
2323 static int
2324 const_hash (exp)
2325      tree exp;
2326 {
2327   register char *p;
2328   register int len, hi, i;
2329   register enum tree_code code = TREE_CODE (exp);
2330
2331   /* Either set P and LEN to the address and len of something to hash and
2332      exit the switch or return a value.  */
2333
2334   switch (code)
2335     {
2336     case INTEGER_CST:
2337       p = (char *) &TREE_INT_CST_LOW (exp);
2338       len = 2 * sizeof TREE_INT_CST_LOW (exp);
2339       break;
2340
2341     case REAL_CST:
2342       p = (char *) &TREE_REAL_CST (exp);
2343       len = sizeof TREE_REAL_CST (exp);
2344       break;
2345
2346     case STRING_CST:
2347       p = TREE_STRING_POINTER (exp);
2348       len = TREE_STRING_LENGTH (exp);
2349       break;
2350
2351     case COMPLEX_CST:
2352       return (const_hash (TREE_REALPART (exp)) * 5
2353               + const_hash (TREE_IMAGPART (exp)));
2354
2355     case CONSTRUCTOR:
2356       if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2357         {
2358           len = int_size_in_bytes (TREE_TYPE (exp));
2359           p = (char *) alloca (len);
2360           get_set_constructor_bytes (exp, (unsigned char *) p, len);
2361           break;
2362         }
2363       else
2364         {
2365           register tree link;
2366
2367           /* For record type, include the type in the hashing.
2368              We do not do so for array types
2369              because (1) the sizes of the elements are sufficient
2370              and (2) distinct array types can have the same constructor.
2371              Instead, we include the array size because the constructor could
2372              be shorter.  */
2373           if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2374             hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2375               % MAX_HASH_TABLE;
2376           else
2377             hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2378                   & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2379
2380           for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2381             if (TREE_VALUE (link))
2382               hi
2383                 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2384
2385           return hi;
2386         }
2387
2388     case ADDR_EXPR:
2389       {
2390         struct addr_const value;
2391
2392         decode_addr_const (exp, &value);
2393         if (GET_CODE (value.base) == SYMBOL_REF)
2394           {
2395             /* Don't hash the address of the SYMBOL_REF;
2396                only use the offset and the symbol name.  */
2397             hi = value.offset;
2398             p = XSTR (value.base, 0);
2399             for (i = 0; p[i] != 0; i++)
2400               hi = ((hi * 613) + (unsigned) (p[i]));
2401           }
2402         else if (GET_CODE (value.base) == LABEL_REF)
2403           hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2404         else
2405           abort();
2406
2407         hi &= (1 << HASHBITS) - 1;
2408         hi %= MAX_HASH_TABLE;
2409       }
2410       return hi;
2411
2412     case PLUS_EXPR:
2413     case MINUS_EXPR:
2414       return (const_hash (TREE_OPERAND (exp, 0)) * 9
2415               + const_hash (TREE_OPERAND (exp, 1)));
2416
2417     case NOP_EXPR:
2418     case CONVERT_EXPR:
2419     case NON_LVALUE_EXPR:
2420       return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2421       
2422     default:
2423       abort ();
2424     }
2425
2426   /* Compute hashing function */
2427   hi = len;
2428   for (i = 0; i < len; i++)
2429     hi = ((hi * 613) + (unsigned) (p[i]));
2430
2431   hi &= (1 << HASHBITS) - 1;
2432   hi %= MAX_HASH_TABLE;
2433   return hi;
2434 }
2435 \f
2436 /* Compare a constant expression EXP with a constant-descriptor DESC.
2437    Return 1 if DESC describes a constant with the same value as EXP.  */
2438
2439 static int
2440 compare_constant (exp, desc)
2441      tree exp;
2442      struct constant_descriptor *desc;
2443 {
2444   return 0 != compare_constant_1 (exp, desc->contents);
2445 }
2446
2447 /* Compare constant expression EXP with a substring P of a constant descriptor.
2448    If they match, return a pointer to the end of the substring matched.
2449    If they do not match, return 0.
2450
2451    Since descriptors are written in polish prefix notation,
2452    this function can be used recursively to test one operand of EXP
2453    against a subdescriptor, and if it succeeds it returns the
2454    address of the subdescriptor for the next operand.  */
2455
2456 static char *
2457 compare_constant_1 (exp, p)
2458      tree exp;
2459      char *p;
2460 {
2461   register char *strp;
2462   register int len;
2463   register enum tree_code code = TREE_CODE (exp);
2464
2465   if (code != (enum tree_code) *p++)
2466     return 0;
2467
2468   /* Either set STRP, P and LEN to pointers and length to compare and exit the
2469      switch, or return the result of the comparison.  */
2470
2471   switch (code)
2472     {
2473     case INTEGER_CST:
2474       /* Integer constants are the same only if the same width of type.  */
2475       if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2476         return 0;
2477
2478       strp = (char *) &TREE_INT_CST_LOW (exp);
2479       len = 2 * sizeof TREE_INT_CST_LOW (exp);
2480       break;
2481
2482     case REAL_CST:
2483       /* Real constants are the same only if the same width of type.  */
2484       if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2485         return 0;
2486
2487       strp = (char *) &TREE_REAL_CST (exp);
2488       len = sizeof TREE_REAL_CST (exp);
2489       break;
2490
2491     case STRING_CST:
2492       if (flag_writable_strings)
2493         return 0;
2494
2495       if (*p++ != TYPE_MODE (TREE_TYPE (exp)))
2496         return 0;
2497
2498       strp = TREE_STRING_POINTER (exp);
2499       len = TREE_STRING_LENGTH (exp);
2500       if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2501                 sizeof TREE_STRING_LENGTH (exp)))
2502         return 0;
2503
2504       p += sizeof TREE_STRING_LENGTH (exp);
2505       break;
2506
2507     case COMPLEX_CST:
2508       p = compare_constant_1 (TREE_REALPART (exp), p);
2509       if (p == 0)
2510         return 0;
2511
2512       return compare_constant_1 (TREE_IMAGPART (exp), p);
2513
2514     case CONSTRUCTOR:
2515       if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2516         {
2517           int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2518
2519           strp = (char *) alloca (len);
2520           get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2521           if (bcmp ((char *) &xlen, p, sizeof xlen))
2522             return 0;
2523
2524           p += sizeof xlen;
2525           break;
2526         }
2527       else
2528         {
2529           register tree link;
2530           int length = list_length (CONSTRUCTOR_ELTS (exp));
2531           tree type;
2532           int have_purpose = 0;
2533
2534           for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2535             if (TREE_PURPOSE (link))
2536               have_purpose = 1;
2537
2538           if (bcmp ((char *) &length, p, sizeof length))
2539             return 0;
2540
2541           p += sizeof length;
2542
2543           /* For record constructors, insist that the types match.
2544              For arrays, just verify both constructors are for arrays. 
2545              Then insist that either both or none have any TREE_PURPOSE
2546              values.  */
2547           if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2548             type = TREE_TYPE (exp);
2549           else
2550             type = 0;
2551
2552           if (bcmp ((char *) &type, p, sizeof type))
2553             return 0;
2554
2555           p += sizeof type;
2556
2557           if (bcmp ((char *) &have_purpose, p, sizeof have_purpose))
2558             return 0;
2559
2560           p += sizeof have_purpose;
2561
2562           /* For arrays, insist that the size in bytes match.  */
2563           if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2564             {
2565               HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2566
2567               if (bcmp ((char *) &size, p, sizeof size))
2568                 return 0;
2569
2570               p += sizeof size;
2571             }
2572
2573           for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2574             {
2575               if (TREE_VALUE (link))
2576                 {
2577                   if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2578                     return 0;
2579                 }
2580               else
2581                 {
2582                   tree zero = 0;
2583
2584                   if (bcmp ((char *) &zero, p, sizeof zero))
2585                     return 0;
2586
2587                   p += sizeof zero;
2588                 }
2589
2590               if (TREE_PURPOSE (link)
2591                   && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2592                 {
2593                   if (bcmp ((char *) &TREE_PURPOSE (link), p,
2594                             sizeof TREE_PURPOSE (link)))
2595                     return 0;
2596
2597                   p += sizeof TREE_PURPOSE (link);
2598                 }
2599               else if (TREE_PURPOSE (link))
2600                 {
2601                   if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2602                     return 0;
2603                 }
2604               else if (have_purpose)
2605                 {
2606                   int zero = 0;
2607
2608                   if (bcmp ((char *) &zero, p, sizeof zero))
2609                     return 0;
2610
2611                   p += sizeof zero;
2612                 }
2613             }
2614
2615           return p;
2616         }
2617
2618     case ADDR_EXPR:
2619       {
2620         struct addr_const value;
2621
2622         decode_addr_const (exp, &value);
2623         strp = (char *) &value.offset;
2624         len = sizeof value.offset;
2625         /* Compare the offset.  */
2626         while (--len >= 0)
2627           if (*p++ != *strp++)
2628             return 0;
2629
2630         /* Compare symbol name.  */
2631         strp = XSTR (value.base, 0);
2632         len = strlen (strp) + 1;
2633       }
2634       break;
2635
2636     case PLUS_EXPR:
2637     case MINUS_EXPR:
2638     case RANGE_EXPR:
2639       p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2640       if (p == 0)
2641         return 0;
2642
2643       return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2644
2645     case NOP_EXPR:
2646     case CONVERT_EXPR:
2647     case NON_LVALUE_EXPR:
2648       return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2649
2650     default:
2651       abort ();
2652     }
2653
2654   /* Compare constant contents.  */
2655   while (--len >= 0)
2656     if (*p++ != *strp++)
2657       return 0;
2658
2659   return p;
2660 }
2661 \f
2662 /* Construct a constant descriptor for the expression EXP.
2663    It is up to the caller to enter the descriptor in the hash table.  */
2664
2665 static struct constant_descriptor *
2666 record_constant (exp)
2667      tree exp;
2668 {
2669   struct constant_descriptor *next = 0;
2670   char *label = 0;
2671
2672   /* Make a struct constant_descriptor.  The first two pointers will
2673      be filled in later.  Here we just leave space for them.  */
2674
2675   obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2676   obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2677   record_constant_1 (exp);
2678   return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2679 }
2680
2681 /* Add a description of constant expression EXP
2682    to the object growing in `permanent_obstack'.
2683    No need to return its address; the caller will get that
2684    from the obstack when the object is complete.  */
2685
2686 static void
2687 record_constant_1 (exp)
2688      tree exp;
2689 {
2690   register char *strp;
2691   register int len;
2692   register enum tree_code code = TREE_CODE (exp);
2693
2694   obstack_1grow (&permanent_obstack, (unsigned int) code);
2695
2696   switch (code)
2697     {
2698     case INTEGER_CST:
2699       obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2700       strp = (char *) &TREE_INT_CST_LOW (exp);
2701       len = 2 * sizeof TREE_INT_CST_LOW (exp);
2702       break;
2703
2704     case REAL_CST:
2705       obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2706       strp = (char *) &TREE_REAL_CST (exp);
2707       len = sizeof TREE_REAL_CST (exp);
2708       break;
2709
2710     case STRING_CST:
2711       if (flag_writable_strings)
2712         return;
2713
2714       obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2715       strp = TREE_STRING_POINTER (exp);
2716       len = TREE_STRING_LENGTH (exp);
2717       obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2718                     sizeof TREE_STRING_LENGTH (exp));
2719       break;
2720
2721     case COMPLEX_CST:
2722       record_constant_1 (TREE_REALPART (exp));
2723       record_constant_1 (TREE_IMAGPART (exp));
2724       return;
2725
2726     case CONSTRUCTOR:
2727       if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2728         {
2729           int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2730           obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2731           obstack_blank (&permanent_obstack, nbytes);
2732           get_set_constructor_bytes
2733             (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2734              nbytes);
2735           return;
2736         }
2737       else
2738         {
2739           register tree link;
2740           int length = list_length (CONSTRUCTOR_ELTS (exp));
2741           tree type;
2742           int have_purpose = 0;
2743
2744           for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2745             if (TREE_PURPOSE (link))
2746               have_purpose = 1;
2747
2748           obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2749
2750           /* For record constructors, insist that the types match.
2751              For arrays, just verify both constructors are for arrays. 
2752              Then insist that either both or none have any TREE_PURPOSE
2753              values.  */
2754           if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2755             type = TREE_TYPE (exp);
2756           else
2757             type = 0;
2758           obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2759           obstack_grow (&permanent_obstack, (char *) &have_purpose,
2760                         sizeof have_purpose);
2761
2762           /* For arrays, insist that the size in bytes match.  */
2763           if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2764             {
2765               HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2766               obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2767             }
2768
2769           for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2770             {
2771               if (TREE_VALUE (link))
2772                 record_constant_1 (TREE_VALUE (link));
2773               else
2774                 {
2775                   tree zero = 0;
2776
2777                   obstack_grow (&permanent_obstack,
2778                                 (char *) &zero, sizeof zero);
2779                 }
2780
2781               if (TREE_PURPOSE (link)
2782                   && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2783                 obstack_grow (&permanent_obstack,
2784                               (char *) &TREE_PURPOSE (link),
2785                               sizeof TREE_PURPOSE (link));
2786               else if (TREE_PURPOSE (link))
2787                 record_constant_1 (TREE_PURPOSE (link));
2788               else if (have_purpose)
2789                 {
2790                   int zero = 0;
2791
2792                   obstack_grow (&permanent_obstack,
2793                                 (char *) &zero, sizeof zero);
2794                 }
2795             }
2796         }
2797       return;
2798
2799     case ADDR_EXPR:
2800       {
2801         struct addr_const value;
2802
2803         decode_addr_const (exp, &value);
2804         /* Record the offset.  */
2805         obstack_grow (&permanent_obstack,
2806                       (char *) &value.offset, sizeof value.offset);
2807         /* Record the symbol name.  */
2808         obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2809                       strlen (XSTR (value.base, 0)) + 1);
2810       }
2811       return;
2812
2813     case PLUS_EXPR:
2814     case MINUS_EXPR:
2815     case RANGE_EXPR:
2816       record_constant_1 (TREE_OPERAND (exp, 0));
2817       record_constant_1 (TREE_OPERAND (exp, 1));
2818       return;
2819
2820     case NOP_EXPR:
2821     case CONVERT_EXPR:
2822     case NON_LVALUE_EXPR:
2823       record_constant_1 (TREE_OPERAND (exp, 0));
2824       return;
2825
2826     default:
2827       abort ();
2828     }
2829
2830   /* Record constant contents.  */
2831   obstack_grow (&permanent_obstack, strp, len);
2832 }
2833 \f
2834 /* Record a list of constant expressions that were passed to
2835    output_constant_def but that could not be output right away.  */
2836
2837 struct deferred_constant
2838 {
2839   struct deferred_constant *next;
2840   tree exp;
2841   int reloc;
2842   int labelno;
2843 };
2844
2845 static struct deferred_constant *deferred_constants;
2846
2847 /* Another list of constants which should be output after the
2848    function.  */
2849 static struct deferred_constant *after_function_constants;
2850
2851 /* Nonzero means defer output of addressed subconstants
2852    (i.e., those for which output_constant_def is called.)  */
2853 static int defer_addressed_constants_flag;
2854
2855 /* Start deferring output of subconstants.  */
2856
2857 void
2858 defer_addressed_constants ()
2859 {
2860   defer_addressed_constants_flag++;
2861 }
2862
2863 /* Stop deferring output of subconstants,
2864    and output now all those that have been deferred.  */
2865
2866 void
2867 output_deferred_addressed_constants ()
2868 {
2869   struct deferred_constant *p, *next;
2870
2871   defer_addressed_constants_flag--;
2872
2873   if (defer_addressed_constants_flag > 0)
2874     return;
2875
2876   for (p = deferred_constants; p; p = next)
2877     {
2878       output_constant_def_contents (p->exp, p->reloc, p->labelno);
2879       next = p->next;
2880       free (p);
2881     }
2882
2883   deferred_constants = 0;
2884 }
2885
2886 /* Output any constants which should appear after a function.  */
2887
2888 static void
2889 output_after_function_constants ()
2890 {
2891   struct deferred_constant *p, *next;
2892
2893   for (p = after_function_constants; p; p = next)
2894     {
2895       output_constant_def_contents (p->exp, p->reloc, p->labelno);
2896       next = p->next;
2897       free (p);
2898     }
2899
2900   after_function_constants = 0;
2901 }
2902
2903 /* Make a copy of the whole tree structure for a constant.
2904    This handles the same types of nodes that compare_constant
2905    and record_constant handle.  */
2906
2907 static tree
2908 copy_constant (exp)
2909      tree exp;
2910 {
2911   switch (TREE_CODE (exp))
2912     {
2913     case ADDR_EXPR:
2914       /* For ADDR_EXPR, we do not want to copy the decl whose address
2915          is requested.  We do want to copy constants though.  */
2916       if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2917         return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2918                        copy_constant (TREE_OPERAND (exp, 0)));
2919       else
2920         return copy_node (exp);
2921
2922     case INTEGER_CST:
2923     case REAL_CST:
2924     case STRING_CST:
2925       return copy_node (exp);
2926
2927     case COMPLEX_CST:
2928       return build_complex (TREE_TYPE (exp),
2929                             copy_constant (TREE_REALPART (exp)),
2930                             copy_constant (TREE_IMAGPART (exp)));
2931
2932     case PLUS_EXPR:
2933     case MINUS_EXPR:
2934       return build (TREE_CODE (exp), TREE_TYPE (exp),
2935                     copy_constant (TREE_OPERAND (exp, 0)),
2936                     copy_constant (TREE_OPERAND (exp, 1)));
2937
2938     case NOP_EXPR:
2939     case CONVERT_EXPR:
2940     case NON_LVALUE_EXPR:
2941       return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2942                      copy_constant (TREE_OPERAND (exp, 0)));
2943
2944     case CONSTRUCTOR:
2945       {
2946         tree copy = copy_node (exp);
2947         tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2948         tree tail;
2949
2950         CONSTRUCTOR_ELTS (copy) = list;
2951         for (tail = list; tail; tail = TREE_CHAIN (tail))
2952           TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2953         if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2954           for (tail = list; tail; tail = TREE_CHAIN (tail))
2955             TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2956
2957         return copy;
2958       }
2959
2960     default:
2961       abort ();
2962     }
2963 }
2964 \f
2965 /* Return an rtx representing a reference to constant data in memory
2966    for the constant expression EXP.
2967
2968    If assembler code for such a constant has already been output,
2969    return an rtx to refer to it.
2970    Otherwise, output such a constant in memory (or defer it for later)
2971    and generate an rtx for it.
2972
2973    The TREE_CST_RTL of EXP is set up to point to that rtx.
2974    The const_hash_table records which constants already have label strings.  */
2975
2976 rtx
2977 output_constant_def (exp)
2978      tree exp;
2979 {
2980   register int hash;
2981   register struct constant_descriptor *desc;
2982   char label[256];
2983   char *found = 0;
2984   int reloc;
2985   register rtx def;
2986
2987   if (TREE_CST_RTL (exp))
2988     return TREE_CST_RTL (exp);
2989
2990   /* Make sure any other constants whose addresses appear in EXP
2991      are assigned label numbers.  */
2992
2993   reloc = output_addressed_constants (exp);
2994
2995   /* Compute hash code of EXP.  Search the descriptors for that hash code
2996      to see if any of them describes EXP.  If yes, the descriptor records
2997      the label number already assigned.  */
2998
2999   hash = const_hash (exp) % MAX_HASH_TABLE;
3000       
3001   for (desc = const_hash_table[hash]; desc; desc = desc->next)
3002     if (compare_constant (exp, desc))
3003       {
3004         found = desc->label;
3005         break;
3006       }
3007       
3008   if (found == 0)
3009     {
3010       /* No constant equal to EXP is known to have been output.
3011          Make a constant descriptor to enter EXP in the hash table.
3012          Assign the label number and record it in the descriptor for
3013          future calls to this function to find.  */
3014           
3015       /* Create a string containing the label name, in LABEL.  */
3016       ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3017
3018       desc = record_constant (exp);
3019       desc->next = const_hash_table[hash];
3020       desc->label = ggc_alloc_string (label, -1);
3021       const_hash_table[hash] = desc;
3022     }
3023   
3024   /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
3025
3026   push_obstacks_nochange ();
3027   if (TREE_PERMANENT (exp))
3028     end_temporary_allocation ();
3029
3030   def = gen_rtx_SYMBOL_REF (Pmode, desc->label);
3031       
3032   TREE_CST_RTL (exp)
3033     = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)), def);
3034   RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
3035   if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
3036     MEM_SET_IN_STRUCT_P (TREE_CST_RTL (exp), 1);
3037
3038   pop_obstacks ();
3039
3040   /* Optionally set flags or add text to the name to record information
3041      such as that it is a function name.  If the name is changed, the macro
3042      ASM_OUTPUT_LABELREF will have to know how to strip this information.  */
3043 #ifdef ENCODE_SECTION_INFO
3044   ENCODE_SECTION_INFO (exp);
3045 #endif
3046
3047   /* If this is the first time we've seen this particular constant,
3048      output it (or defer its output for later).  */
3049   if (found == 0)
3050     {
3051       int after_function = 0;
3052
3053 #ifdef CONSTANT_AFTER_FUNCTION_P
3054       if (current_function_decl != 0
3055           && CONSTANT_AFTER_FUNCTION_P (exp))
3056         after_function = 1;
3057 #endif
3058
3059       if (defer_addressed_constants_flag || after_function)
3060         {
3061           struct deferred_constant *p;
3062           p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
3063
3064           push_obstacks_nochange ();
3065           suspend_momentary ();
3066           p->exp = copy_constant (exp);
3067           pop_obstacks ();
3068           p->reloc = reloc;
3069           p->labelno = const_labelno++;
3070           if (after_function)
3071             {
3072               p->next = after_function_constants;
3073               after_function_constants = p;
3074             }
3075           else
3076             {
3077               p->next = deferred_constants;
3078               deferred_constants = p;
3079             }
3080         }
3081       else
3082         {
3083           /* Do no output if -fsyntax-only.  */
3084           if (! flag_syntax_only)
3085             output_constant_def_contents (exp, reloc, const_labelno);
3086           ++const_labelno;
3087         }
3088     }
3089
3090   return TREE_CST_RTL (exp);
3091 }
3092
3093 /* Now output assembler code to define the label for EXP,
3094    and follow it with the data of EXP.  */
3095
3096 static void
3097 output_constant_def_contents (exp, reloc, labelno)
3098      tree exp;
3099      int reloc;
3100      int labelno;
3101 {
3102   int align;
3103
3104   if (IN_NAMED_SECTION (exp))
3105     named_section (exp, NULL, reloc);
3106   else
3107     {
3108       /* First switch to text section, except for writable strings.  */
3109 #ifdef SELECT_SECTION
3110       SELECT_SECTION (exp, reloc);
3111 #else
3112       if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3113           || (flag_pic && reloc))
3114         data_section ();
3115       else
3116         readonly_data_section ();
3117 #endif
3118     }
3119
3120   /* Align the location counter as required by EXP's data type.  */
3121   align = TYPE_ALIGN (TREE_TYPE (exp));
3122 #ifdef CONSTANT_ALIGNMENT
3123   align = CONSTANT_ALIGNMENT (exp, align);
3124 #endif
3125
3126   if (align > BITS_PER_UNIT)
3127     ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3128
3129   /* Output the label itself.  */
3130   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3131
3132   /* Output the value of EXP.  */
3133   output_constant (exp,
3134                    (TREE_CODE (exp) == STRING_CST
3135                     ? TREE_STRING_LENGTH (exp)
3136                     : int_size_in_bytes (TREE_TYPE (exp))));
3137
3138 }
3139 \f
3140 /* Structure to represent sufficient information about a constant so that
3141    it can be output when the constant pool is output, so that function
3142    integration can be done, and to simplify handling on machines that reference
3143    constant pool as base+displacement.  */
3144
3145 struct pool_constant
3146 {
3147   struct constant_descriptor *desc;
3148   struct pool_constant *next;
3149   enum machine_mode mode;
3150   rtx constant;
3151   int labelno;
3152   int align;
3153   int offset;
3154   int mark;
3155 };
3156
3157 /* Structure used to maintain hash table mapping symbols used to their
3158    corresponding constants.  */
3159
3160 struct pool_sym
3161 {
3162   char *label;
3163   struct pool_constant *pool;
3164   struct pool_sym *next;
3165 };
3166
3167 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3168    The argument is XSTR (... , 0)  */
3169
3170 #define SYMHASH(LABEL)  \
3171   ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1))  % MAX_RTX_HASH_TABLE)
3172 \f
3173 /* Initialize constant pool hashing for a new function.  */
3174
3175 void
3176 init_varasm_status (f)
3177      struct function *f;
3178 {
3179   struct varasm_status *p;
3180   p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status));
3181   f->varasm = p;
3182   p->x_const_rtx_hash_table
3183     = ((struct constant_descriptor **)
3184        xmalloc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
3185   p->x_const_rtx_sym_hash_table
3186     = ((struct pool_sym **)
3187        xmalloc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
3188   bzero ((char *) p->x_const_rtx_hash_table,
3189          MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
3190   bzero ((char *) p->x_const_rtx_sym_hash_table,
3191          MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
3192
3193   p->x_first_pool = p->x_last_pool = 0;
3194   p->x_pool_offset = 0;
3195   p->x_const_double_chain = 0;
3196 }
3197
3198 /* Mark PC for GC.  */
3199
3200 static void 
3201 mark_pool_constant (pc)
3202      struct pool_constant *pc;
3203 {
3204   while (pc)
3205     {
3206       ggc_mark_rtx (pc->constant);
3207       pc = pc->next;
3208     }
3209 }
3210
3211 /* Mark PPS for GC.  */
3212
3213 static void
3214 mark_pool_sym_hash_table (pps)
3215      struct pool_sym **pps;
3216 {
3217   struct pool_sym *ps;
3218   int i;
3219
3220   for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3221     for (ps = pps[i]; ps ; ps = ps->next)
3222       ggc_mark_string (ps->label);
3223 }
3224
3225 /* Mark P for GC.  */
3226
3227 void
3228 mark_varasm_state (p)
3229   struct varasm_status *p;
3230 {
3231   mark_pool_constant (p->x_first_pool);
3232   mark_pool_sym_hash_table (p->x_const_rtx_sym_hash_table);
3233   ggc_mark_rtx (p->x_const_double_chain);
3234 }
3235
3236 /* Clear out all parts of the state in F that can safely be discarded
3237    after the function has been compiled, to let garbage collection
3238    reclaim the memory.  D is the declaration for the function just
3239    compiled.  Its output may have been deferred.  */
3240
3241 void
3242 free_varasm_status (f, d)
3243      struct function *f;
3244      tree d;
3245 {
3246   struct varasm_status *p;
3247
3248   if (DECL_DEFER_OUTPUT (d))
3249     return;
3250
3251   p = f->varasm;
3252   free (p->x_const_rtx_hash_table);
3253   free (p->x_const_rtx_sym_hash_table);
3254
3255   p->x_first_pool = p->x_last_pool = 0;
3256   p->x_const_rtx_hash_table = 0;
3257   p->x_const_rtx_sym_hash_table = 0;
3258   p->x_const_double_chain = 0;
3259 }
3260 \f
3261 enum kind { RTX_DOUBLE, RTX_INT };
3262
3263 struct rtx_const
3264 {
3265 #ifdef ONLY_INT_FIELDS
3266   unsigned int kind : 16;
3267   unsigned int mode : 16;
3268 #else
3269   enum kind kind : 16;
3270   enum machine_mode mode : 16;
3271 #endif
3272   union {
3273     union real_extract du;
3274     struct addr_const addr;
3275     struct {HOST_WIDE_INT high, low;} di;
3276   } un;
3277 };
3278
3279 /* Express an rtx for a constant integer (perhaps symbolic)
3280    as the sum of a symbol or label plus an explicit integer.
3281    They are stored into VALUE.  */
3282
3283 static void
3284 decode_rtx_const (mode, x, value)
3285      enum machine_mode mode;
3286      rtx x;
3287      struct rtx_const *value;
3288 {
3289   /* Clear the whole structure, including any gaps.  */
3290
3291   {
3292     int *p = (int *) value;
3293     int *end = (int *) (value + 1);
3294     while (p < end)
3295       *p++ = 0;
3296   }
3297
3298   value->kind = RTX_INT;        /* Most usual kind.  */
3299   value->mode = mode;
3300
3301   switch (GET_CODE (x))
3302     {
3303     case CONST_DOUBLE:
3304       value->kind = RTX_DOUBLE;
3305       if (GET_MODE (x) != VOIDmode)
3306         {
3307           value->mode = GET_MODE (x);
3308           bcopy ((char *) &CONST_DOUBLE_LOW (x),
3309                  (char *) &value->un.du, sizeof value->un.du);
3310         }
3311       else
3312         {
3313           value->un.di.low = CONST_DOUBLE_LOW (x);
3314           value->un.di.high = CONST_DOUBLE_HIGH (x);
3315         }
3316       break;
3317
3318     case CONST_INT:
3319       value->un.addr.offset = INTVAL (x);
3320       break;
3321
3322     case SYMBOL_REF:
3323     case LABEL_REF:
3324     case PC:
3325       value->un.addr.base = x;
3326       break;
3327
3328     case CONST:
3329       x = XEXP (x, 0);
3330       if (GET_CODE (x) == PLUS)
3331         {
3332           value->un.addr.base = XEXP (x, 0);
3333           if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3334             abort ();
3335           value->un.addr.offset = INTVAL (XEXP (x, 1));
3336         }
3337       else if (GET_CODE (x) == MINUS)
3338         {
3339           value->un.addr.base = XEXP (x, 0);
3340           if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3341             abort ();
3342           value->un.addr.offset = - INTVAL (XEXP (x, 1));
3343         }
3344       else
3345         abort ();
3346       break;
3347
3348     default:
3349       abort ();
3350     }
3351
3352   if (value->kind == RTX_INT && value->un.addr.base != 0)
3353     switch (GET_CODE (value->un.addr.base))
3354       {
3355       case SYMBOL_REF:
3356       case LABEL_REF:
3357         /* Use the string's address, not the SYMBOL_REF's address,
3358            for the sake of addresses of library routines.
3359            For a LABEL_REF, compare labels.  */
3360         value->un.addr.base = XEXP (value->un.addr.base, 0);
3361         
3362       default:
3363         break;
3364       }
3365 }
3366
3367 /* Given a MINUS expression, simplify it if both sides
3368    include the same symbol.  */
3369
3370 rtx
3371 simplify_subtraction (x)
3372      rtx x;
3373 {
3374   struct rtx_const val0, val1;
3375
3376   decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3377   decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3378
3379   if (val0.un.addr.base == val1.un.addr.base)
3380     return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3381   return x;
3382 }
3383
3384 /* Compute a hash code for a constant RTL expression.  */
3385
3386 static int
3387 const_hash_rtx (mode, x)
3388      enum machine_mode mode;
3389      rtx x;
3390 {
3391   register int hi;
3392   register size_t i;
3393
3394   struct rtx_const value;
3395   decode_rtx_const (mode, x, &value);
3396
3397   /* Compute hashing function */
3398   hi = 0;
3399   for (i = 0; i < sizeof value / sizeof (int); i++)
3400     hi += ((int *) &value)[i];
3401
3402   hi &= (1 << HASHBITS) - 1;
3403   hi %= MAX_RTX_HASH_TABLE;
3404   return hi;
3405 }
3406
3407 /* Compare a constant rtl object X with a constant-descriptor DESC.
3408    Return 1 if DESC describes a constant with the same value as X.  */
3409
3410 static int
3411 compare_constant_rtx (mode, x, desc)
3412      enum machine_mode mode;
3413      rtx x;
3414      struct constant_descriptor *desc;
3415 {
3416   register int *p = (int *) desc->contents;
3417   register int *strp;
3418   register int len;
3419   struct rtx_const value;
3420
3421   decode_rtx_const (mode, x, &value);
3422   strp = (int *) &value;
3423   len = sizeof value / sizeof (int);
3424
3425   /* Compare constant contents.  */
3426   while (--len >= 0)
3427     if (*p++ != *strp++)
3428       return 0;
3429
3430   return 1;
3431 }
3432
3433 /* Construct a constant descriptor for the rtl-expression X.
3434    It is up to the caller to enter the descriptor in the hash table.  */
3435
3436 static struct constant_descriptor *
3437 record_constant_rtx (mode, x)
3438      enum machine_mode mode;
3439      rtx x;
3440 {
3441   struct constant_descriptor *ptr;
3442   char *label;
3443   struct rtx_const value;
3444
3445   decode_rtx_const (mode, x, &value);
3446
3447   /* Put these things in the saveable obstack so we can ensure it won't
3448      be freed if we are called from combine or some other phase that discards
3449      memory allocated from function_obstack (current_obstack).  */
3450   obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3451   obstack_grow (saveable_obstack, &label, sizeof label);
3452
3453   /* Record constant contents.  */
3454   obstack_grow (saveable_obstack, &value, sizeof value);
3455
3456   return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3457 }
3458 \f
3459 /* Given a constant rtx X, make (or find) a memory constant for its value
3460    and return a MEM rtx to refer to it in memory.  */
3461
3462 rtx
3463 force_const_mem (mode, x)
3464      enum machine_mode mode;
3465      rtx x;
3466 {
3467   register int hash;
3468   register struct constant_descriptor *desc;
3469   char label[256];
3470   char *found = 0;
3471   rtx def;
3472
3473   /* If we want this CONST_DOUBLE in the same mode as it is in memory
3474      (this will always be true for floating CONST_DOUBLEs that have been
3475      placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3476      use the previous copy.  Otherwise, make a new one.  Note that in
3477      the unlikely event that this same CONST_DOUBLE is used in two different
3478      modes in an alternating fashion, we will allocate a lot of different
3479      memory locations, but this should be extremely rare.  */
3480
3481   if (GET_CODE (x) == CONST_DOUBLE
3482       && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3483       && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3484     return CONST_DOUBLE_MEM (x);
3485
3486   /* Compute hash code of X.  Search the descriptors for that hash code
3487      to see if any of them describes X.  If yes, the descriptor records
3488      the label number already assigned.  */
3489
3490   hash = const_hash_rtx (mode, x);
3491
3492   for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3493     if (compare_constant_rtx (mode, x, desc))
3494       {
3495         found = desc->label;
3496         break;
3497       }
3498
3499   if (found == 0)
3500     {
3501       register struct pool_constant *pool;
3502       register struct pool_sym *sym;
3503       int align;
3504
3505       /* No constant equal to X is known to have been output.
3506          Make a constant descriptor to enter X in the hash table.
3507          Assign the label number and record it in the descriptor for
3508          future calls to this function to find.  */
3509
3510       desc = record_constant_rtx (mode, x);
3511       desc->next = const_rtx_hash_table[hash];
3512       const_rtx_hash_table[hash] = desc;
3513
3514       /* Align the location counter as required by EXP's data type.  */
3515       align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3516       if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3517         align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3518 #ifdef CONSTANT_ALIGNMENT
3519       align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x),
3520                                  align * BITS_PER_UNIT) / BITS_PER_UNIT;
3521 #endif
3522
3523       pool_offset += align - 1;
3524       pool_offset &= ~ (align - 1);
3525
3526       /* If RTL is not being placed into the saveable obstack, make a
3527          copy of X that is in the saveable obstack in case we are
3528          being called from combine or some other phase that discards
3529          memory it allocates.  We used to only do this if it is a
3530          CONST; however, reload can allocate a CONST_INT when
3531          eliminating registers.  */
3532       if (rtl_obstack != saveable_obstack
3533           && (GET_CODE (x) == CONST || GET_CODE (x) == CONST_INT))
3534         {
3535           push_obstacks_nochange ();
3536           rtl_in_saveable_obstack ();
3537
3538           if (GET_CODE (x) == CONST)
3539             x = gen_rtx_CONST (GET_MODE (x), 
3540                                gen_rtx_PLUS (GET_MODE (x), 
3541                                              XEXP (XEXP (x, 0), 0),
3542                                              XEXP (XEXP (x, 0), 1)));
3543           else
3544             x = GEN_INT (INTVAL (x));
3545
3546           pop_obstacks ();
3547         }
3548
3549       /* Allocate a pool constant descriptor, fill it in, and chain it in.  */
3550
3551       pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3552       pool->desc = desc;
3553       pool->constant = x;
3554       pool->mode = mode;
3555       pool->labelno = const_labelno;
3556       pool->align = align;
3557       pool->offset = pool_offset;
3558       pool->mark = 1;
3559       pool->next = 0;
3560
3561       if (last_pool == 0)
3562         first_pool = pool;
3563       else
3564         last_pool->next = pool;
3565
3566       last_pool = pool;
3567       pool_offset += GET_MODE_SIZE (mode);
3568
3569       /* Create a string containing the label name, in LABEL.  */
3570       ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3571
3572       ++const_labelno;
3573
3574       desc->label = found = ggc_alloc_string (label, -1);
3575
3576       /* Add label to symbol hash table.  */
3577       hash = SYMHASH (found);
3578       sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3579       sym->label = found;
3580       sym->pool = pool;
3581       sym->next = const_rtx_sym_hash_table[hash];
3582       const_rtx_sym_hash_table[hash] = sym;
3583     }
3584
3585   /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
3586
3587   def = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, found));
3588
3589   RTX_UNCHANGING_P (def) = 1;
3590   /* Mark the symbol_ref as belonging to this constants pool.  */
3591   CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3592   current_function_uses_const_pool = 1;
3593
3594   if (GET_CODE (x) == CONST_DOUBLE)
3595     {
3596       if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3597         {
3598           CONST_DOUBLE_CHAIN (x) = const_double_chain;
3599           const_double_chain = x;
3600         }
3601       CONST_DOUBLE_MEM (x) = def;
3602     }
3603
3604   return def;
3605 }
3606 \f
3607 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3608    the corresponding pool_constant structure.  */
3609
3610 static struct pool_constant *
3611 find_pool_constant (f, addr)
3612      struct function *f;
3613      rtx addr;
3614 {
3615   struct pool_sym *sym;
3616   char *label = XSTR (addr, 0);
3617
3618   for (sym = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3619     if (sym->label == label)
3620       return sym->pool;
3621
3622   abort ();
3623 }
3624
3625 /* Given a constant pool SYMBOL_REF, return the corresponding constant.  */
3626
3627 rtx
3628 get_pool_constant (addr)
3629      rtx addr;
3630 {
3631   return (find_pool_constant (current_function, addr))->constant;
3632 }
3633
3634 /* Likewise, but for the constant pool of a specific function.  */
3635
3636 rtx
3637 get_pool_constant_for_function (f, addr)
3638      struct function *f;
3639      rtx addr;
3640 {
3641   return (find_pool_constant (f, addr))->constant;
3642 }
3643
3644 /* Similar, return the mode.  */
3645
3646 enum machine_mode
3647 get_pool_mode (addr)
3648      rtx addr;
3649 {
3650   return (find_pool_constant (current_function, addr))->mode;
3651 }
3652
3653 enum machine_mode
3654 get_pool_mode_for_function (f, addr)
3655      struct function *f;
3656      rtx addr;
3657 {
3658   return (find_pool_constant (f, addr))->mode;
3659 }
3660
3661 /* Similar, return the offset in the constant pool.  */
3662
3663 int
3664 get_pool_offset (addr)
3665      rtx addr;
3666 {
3667   return (find_pool_constant (current_function, addr))->offset;
3668 }
3669
3670 /* Return the size of the constant pool.  */
3671
3672 int
3673 get_pool_size ()
3674 {
3675   return pool_offset;
3676 }
3677 \f
3678 /* Write all the constants in the constant pool.  */
3679
3680 void
3681 output_constant_pool (fnname, fndecl)
3682   char *fnname ATTRIBUTE_UNUSED;
3683   tree fndecl ATTRIBUTE_UNUSED;
3684 {
3685   struct pool_constant *pool;
3686   rtx x;
3687   union real_extract u;
3688
3689   /* It is possible for gcc to call force_const_mem and then to later
3690      discard the instructions which refer to the constant.  In such a
3691      case we do not need to output the constant.  */
3692   mark_constant_pool ();
3693
3694 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3695   ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3696 #endif
3697
3698   for (pool = first_pool; pool; pool = pool->next)
3699     {
3700       x = pool->constant;
3701
3702       if (! pool->mark)
3703         continue;
3704
3705       /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3706          whose CODE_LABEL has been deleted.  This can occur if a jump table
3707          is eliminated by optimization.  If so, write a constant of zero
3708          instead.  Note that this can also happen by turning the
3709          CODE_LABEL into a NOTE.  */
3710       if (((GET_CODE (x) == LABEL_REF
3711             && (INSN_DELETED_P (XEXP (x, 0))
3712                 || GET_CODE (XEXP (x, 0)) == NOTE)))
3713           || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3714               && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3715               && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3716                   || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3717         x = const0_rtx;
3718
3719       /* First switch to correct section.  */
3720 #ifdef SELECT_RTX_SECTION
3721       SELECT_RTX_SECTION (pool->mode, x);
3722 #else
3723       readonly_data_section ();
3724 #endif
3725
3726 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3727       ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3728                                      pool->align, pool->labelno, done);
3729 #endif
3730
3731       if (pool->align > 1)
3732         ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (pool->align));
3733
3734       /* Output the label.  */
3735       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3736
3737       /* Output the value of the constant itself.  */
3738       switch (GET_MODE_CLASS (pool->mode))
3739         {
3740         case MODE_FLOAT:
3741           if (GET_CODE (x) != CONST_DOUBLE)
3742             abort ();
3743
3744           bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3745           assemble_real (u.d, pool->mode);
3746           break;
3747
3748         case MODE_INT:
3749         case MODE_PARTIAL_INT:
3750           assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3751           break;
3752
3753         default:
3754           abort ();
3755         }
3756
3757 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3758     done: ;
3759 #endif
3760
3761     }
3762
3763 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3764   ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3765 #endif
3766
3767   /* Done with this pool.  */
3768   first_pool = last_pool = 0;
3769 }
3770
3771 /* Look through the instructions for this function, and mark all the
3772    entries in the constant pool which are actually being used.  */
3773
3774 static void
3775 mark_constant_pool ()
3776 {
3777   register rtx insn;
3778   struct pool_constant *pool;
3779
3780   if (first_pool == 0)
3781     return;
3782
3783   for (pool = first_pool; pool; pool = pool->next)
3784     pool->mark = 0;
3785
3786   for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3787     if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3788       mark_constants (PATTERN (insn));
3789
3790   for (insn = current_function_epilogue_delay_list;
3791        insn;
3792        insn = XEXP (insn, 1))
3793     if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3794       mark_constants (PATTERN (insn));
3795
3796   /* It's possible that the only reference to a symbol is in a symbol
3797      that's in the constant pool.  This happens in Fortran under some
3798      situations.  (When the constant contains the address of another
3799      constant, and only the first is used directly in an insn.) 
3800      This is potentially suboptimal if there's ever a possibility of
3801      backwards (in pool order) 2'd level references.  However, it's
3802      not clear that 2'd level references can happen. */
3803   for (pool = first_pool; pool; pool = pool->next)
3804     {
3805       struct pool_sym *sym;
3806       char *label;
3807
3808       /* skip unmarked entries; no insn refers to them. */
3809       if (!pool->mark)
3810           continue;
3811
3812       /* Skip everything except SYMBOL_REFs.  */
3813       if (GET_CODE (pool->constant) != SYMBOL_REF)
3814         continue;
3815       label = XSTR (pool->constant, 0);
3816
3817       /* Be sure the symbol's value is marked. */
3818       for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; 
3819            sym = sym->next)
3820           if (sym->label == label)
3821             sym->pool->mark = 1;
3822       /* If we didn't find it, there's something truly wrong here, but it
3823          will be announced by the assembler. */
3824     }
3825 }
3826
3827 static void
3828 mark_constants (x)
3829      register rtx x;
3830 {
3831   register int i;
3832   register const char *format_ptr;
3833
3834   if (x == 0)
3835     return;
3836
3837   if (GET_CODE (x) == SYMBOL_REF)
3838     {
3839       if (CONSTANT_POOL_ADDRESS_P (x))
3840         find_pool_constant (current_function, x)->mark = 1;
3841       return;
3842     }
3843   /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3844      a MEM, but does not constitute a use of that MEM.  */
3845   else if (GET_CODE (x) == CONST_DOUBLE)
3846     return;
3847
3848   /* Insns may appear inside a SEQUENCE.  Only check the patterns of
3849      insns, not any notes that may be attached.  We don't want to mark
3850      a constant just because it happens to appear in a REG_EQUIV note.  */
3851   if (GET_RTX_CLASS (GET_CODE (x)) == 'i')
3852     {
3853       mark_constants (PATTERN (x));
3854       return;
3855     }
3856
3857   format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3858
3859   for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3860     {
3861       switch (*format_ptr++)
3862         {
3863         case 'e':
3864           mark_constants (XEXP (x, i));
3865           break;
3866
3867         case 'E':
3868           if (XVEC (x, i) != 0)
3869             {
3870               register int j;
3871
3872               for (j = 0; j < XVECLEN (x, i); j++)
3873                 mark_constants (XVECEXP (x, i, j));
3874             }
3875           break;
3876
3877         case 'S':
3878         case 's':
3879         case '0':
3880         case 'i':
3881         case 'w':
3882         case 'n':
3883         case 'u':
3884           break;
3885
3886         default:
3887           abort ();
3888         }
3889     }
3890 }
3891 \f
3892 /* Find all the constants whose addresses are referenced inside of EXP,
3893    and make sure assembler code with a label has been output for each one.
3894    Indicate whether an ADDR_EXPR has been encountered.  */
3895
3896 static int
3897 output_addressed_constants (exp)
3898      tree exp;
3899 {
3900   int reloc = 0;
3901
3902   switch (TREE_CODE (exp))
3903     {
3904     case ADDR_EXPR:
3905       {
3906         register tree constant = TREE_OPERAND (exp, 0);
3907
3908         while (TREE_CODE (constant) == COMPONENT_REF)
3909           {
3910             constant = TREE_OPERAND (constant, 0);
3911           }
3912
3913         if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3914             || TREE_CODE (constant) == CONSTRUCTOR)
3915           /* No need to do anything here
3916              for addresses of variables or functions.  */
3917           output_constant_def (constant);
3918       }
3919       reloc = 1;
3920       break;
3921
3922     case PLUS_EXPR:
3923     case MINUS_EXPR:
3924       reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3925       reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3926       break;
3927
3928     case NOP_EXPR:
3929     case CONVERT_EXPR:
3930     case NON_LVALUE_EXPR:
3931       reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3932       break;
3933
3934     case CONSTRUCTOR:
3935       {
3936         register tree link;
3937         for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3938           if (TREE_VALUE (link) != 0)
3939             reloc |= output_addressed_constants (TREE_VALUE (link));
3940       }
3941       break;
3942
3943     default:
3944       break;
3945     }
3946   return reloc;
3947 }
3948 \f
3949 /* Output assembler code for constant EXP to FILE, with no label.
3950    This includes the pseudo-op such as ".int" or ".byte", and a newline.
3951    Assumes output_addressed_constants has been done on EXP already.
3952
3953    Generate exactly SIZE bytes of assembler data, padding at the end
3954    with zeros if necessary.  SIZE must always be specified.
3955
3956    SIZE is important for structure constructors,
3957    since trailing members may have been omitted from the constructor.
3958    It is also important for initialization of arrays from string constants
3959    since the full length of the string constant might not be wanted.
3960    It is also needed for initialization of unions, where the initializer's
3961    type is just one member, and that may not be as long as the union.
3962
3963    There a case in which we would fail to output exactly SIZE bytes:
3964    for a structure constructor that wants to produce more than SIZE bytes.
3965    But such constructors will never be generated for any possible input.  */
3966
3967 void
3968 output_constant (exp, size)
3969      register tree exp;
3970      register int size;
3971 {
3972   register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3973
3974   /* Some front-ends use constants other than the standard
3975      language-indepdent varieties, but which may still be output
3976      directly.  Give the front-end a chance to convert EXP to a
3977      language-independent representation.  */
3978   if (lang_expand_constant)
3979     exp = (*lang_expand_constant) (exp);
3980
3981   if (size == 0 || flag_syntax_only)
3982     return;
3983
3984   /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3985      That way we get the constant (we hope) inside it.  Also, strip off any
3986      NOP_EXPR that converts between two record, union, array, or set types.  */
3987   while ((TREE_CODE (exp) == NOP_EXPR 
3988           && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3989               || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
3990          || TREE_CODE (exp) == NON_LVALUE_EXPR)
3991     exp = TREE_OPERAND (exp, 0);
3992
3993   /* Allow a constructor with no elements for any data type.
3994      This means to fill the space with zeros.  */
3995   if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3996     {
3997       assemble_zeros (size);
3998       return;
3999     }
4000
4001   switch (code)
4002     {
4003     case CHAR_TYPE:
4004     case BOOLEAN_TYPE:
4005     case INTEGER_TYPE:
4006     case ENUMERAL_TYPE:
4007     case POINTER_TYPE:
4008     case REFERENCE_TYPE:
4009       /* ??? What about       (int)((float)(int)&foo + 4)    */
4010       while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4011              || TREE_CODE (exp) == NON_LVALUE_EXPR)
4012         exp = TREE_OPERAND (exp, 0);
4013
4014       if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4015                                            EXPAND_INITIALIZER),
4016                               size, 0))
4017         error ("initializer for integer value is too complicated");
4018       size = 0;
4019       break;
4020
4021     case REAL_TYPE:
4022       if (TREE_CODE (exp) != REAL_CST)
4023         error ("initializer for floating value is not a floating constant");
4024
4025       assemble_real (TREE_REAL_CST (exp),
4026                      mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
4027       size = 0;
4028       break;
4029
4030     case COMPLEX_TYPE:
4031       output_constant (TREE_REALPART (exp), size / 2);
4032       output_constant (TREE_IMAGPART (exp), size / 2);
4033       size -= (size / 2) * 2;
4034       break;
4035
4036     case ARRAY_TYPE:
4037       if (TREE_CODE (exp) == CONSTRUCTOR)
4038         {
4039           output_constructor (exp, size);
4040           return;
4041         }
4042       else if (TREE_CODE (exp) == STRING_CST)
4043         {
4044           int excess = 0;
4045
4046           if (size > TREE_STRING_LENGTH (exp))
4047             {
4048               excess = size - TREE_STRING_LENGTH (exp);
4049               size = TREE_STRING_LENGTH (exp);
4050             }
4051
4052           assemble_string (TREE_STRING_POINTER (exp), size);
4053           size = excess;
4054         }
4055       else
4056         abort ();
4057       break;
4058
4059     case RECORD_TYPE:
4060     case UNION_TYPE:
4061       if (TREE_CODE (exp) == CONSTRUCTOR)
4062         output_constructor (exp, size);
4063       else
4064         abort ();
4065       return;
4066
4067     case SET_TYPE:
4068       if (TREE_CODE (exp) == INTEGER_CST)
4069         assemble_integer (expand_expr (exp, NULL_RTX,
4070                                        VOIDmode, EXPAND_INITIALIZER),
4071                           size, 1);
4072       else if (TREE_CODE (exp) == CONSTRUCTOR)
4073         {
4074           unsigned char *buffer = (unsigned char *) alloca (size);
4075           if (get_set_constructor_bytes (exp, buffer, size))
4076             abort ();
4077           assemble_string ((char *) buffer, size);
4078         }
4079       else
4080         error ("unknown set constructor type");
4081       return;
4082
4083     default:
4084       break; /* ??? */
4085     }
4086
4087   if (size > 0)
4088     assemble_zeros (size);
4089 }
4090
4091 \f
4092 /* Subroutine of output_constant, used for CONSTRUCTORs
4093    (aggregate constants).
4094    Generate at least SIZE bytes, padding if necessary.  */
4095
4096 static void
4097 output_constructor (exp, size)
4098      tree exp;
4099      int size;
4100 {
4101   register tree link, field = 0;
4102   HOST_WIDE_INT min_index = 0;
4103   /* Number of bytes output or skipped so far.
4104      In other words, current position within the constructor.  */
4105   int total_bytes = 0;
4106   /* Non-zero means BYTE contains part of a byte, to be output.  */
4107   int byte_buffer_in_use = 0;
4108   register int byte;
4109
4110   if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4111     abort ();
4112
4113   if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
4114     field = TYPE_FIELDS (TREE_TYPE (exp));
4115
4116   if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
4117       && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
4118     min_index
4119       = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
4120
4121   /* As LINK goes through the elements of the constant,
4122      FIELD goes through the structure fields, if the constant is a structure.
4123      if the constant is a union, then we override this,
4124      by getting the field from the TREE_LIST element.
4125      But the constant could also be an array.  Then FIELD is zero.
4126
4127      There is always a maximum of one element in the chain LINK for unions
4128      (even if the initializer in a source program incorrectly contains
4129      more one). */
4130   for (link = CONSTRUCTOR_ELTS (exp);
4131        link;
4132        link = TREE_CHAIN (link),
4133        field = field ? TREE_CHAIN (field) : 0)
4134     {
4135       tree val = TREE_VALUE (link);
4136       tree index = 0;
4137
4138       /* the element in a union constructor specifies the proper field.  */
4139
4140       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
4141           || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
4142         {
4143           /* if available, use the type given by link */
4144           if (TREE_PURPOSE (link) != 0)
4145             field = TREE_PURPOSE (link);
4146         }
4147
4148       if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
4149         index = TREE_PURPOSE (link);
4150
4151       /* Eliminate the marker that makes a cast not be an lvalue.  */
4152       if (val != 0)
4153         STRIP_NOPS (val);
4154
4155       if (index && TREE_CODE (index) == RANGE_EXPR)
4156         {
4157           register int fieldsize
4158             = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4159           HOST_WIDE_INT lo_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 0));
4160           HOST_WIDE_INT hi_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 1));
4161           HOST_WIDE_INT index;
4162           for (index = lo_index; index <= hi_index; index++)
4163             {
4164               /* Output the element's initial value.  */
4165               if (val == 0)
4166                 assemble_zeros (fieldsize);
4167               else
4168                 output_constant (val, fieldsize);
4169
4170               /* Count its size.  */
4171               total_bytes += fieldsize;
4172             }
4173         }
4174       else if (field == 0 || !DECL_BIT_FIELD (field))
4175         {
4176           /* An element that is not a bit-field.  */
4177
4178           register int fieldsize;
4179           /* Since this structure is static,
4180              we know the positions are constant.  */
4181           int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
4182                                  / BITS_PER_UNIT)
4183                         : 0);
4184           if (index != 0)
4185             bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
4186                       / BITS_PER_UNIT
4187                       * (TREE_INT_CST_LOW (index) - min_index));
4188
4189           /* Output any buffered-up bit-fields preceding this element.  */
4190           if (byte_buffer_in_use)
4191             {
4192               ASM_OUTPUT_BYTE (asm_out_file, byte);
4193               total_bytes++;
4194               byte_buffer_in_use = 0;
4195             }
4196
4197           /* Advance to offset of this element.
4198              Note no alignment needed in an array, since that is guaranteed
4199              if each element has the proper size.  */
4200           if ((field != 0 || index != 0) && bitpos != total_bytes)
4201             {
4202               assemble_zeros (bitpos - total_bytes);
4203               total_bytes = bitpos;
4204             }
4205
4206           /* Determine size this element should occupy.  */
4207           if (field)
4208             {
4209               if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
4210                 abort ();
4211               if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
4212                 {
4213                   /* This avoids overflow trouble.  */
4214                   tree size_tree = size_binop (CEIL_DIV_EXPR,
4215                                                DECL_SIZE (field),
4216                                                size_int (BITS_PER_UNIT));
4217                   fieldsize = TREE_INT_CST_LOW (size_tree);
4218                 }
4219               else
4220                 {
4221                   fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
4222                   fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4223                 }
4224             }
4225           else
4226             fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4227
4228           /* Output the element's initial value.  */
4229           if (val == 0)
4230             assemble_zeros (fieldsize);
4231           else
4232             output_constant (val, fieldsize);
4233
4234           /* Count its size.  */
4235           total_bytes += fieldsize;
4236         }
4237       else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4238         error ("invalid initial value for member `%s'",
4239                IDENTIFIER_POINTER (DECL_NAME (field)));
4240       else
4241         {
4242           /* Element that is a bit-field.  */
4243
4244           int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
4245           int end_offset
4246             = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
4247
4248           if (val == 0)
4249             val = integer_zero_node;
4250
4251           /* If this field does not start in this (or, next) byte,
4252              skip some bytes.  */
4253           if (next_offset / BITS_PER_UNIT != total_bytes)
4254             {
4255               /* Output remnant of any bit field in previous bytes.  */
4256               if (byte_buffer_in_use)
4257                 {
4258                   ASM_OUTPUT_BYTE (asm_out_file, byte);
4259                   total_bytes++;
4260                   byte_buffer_in_use = 0;
4261                 }
4262
4263               /* If still not at proper byte, advance to there.  */
4264               if (next_offset / BITS_PER_UNIT != total_bytes)
4265                 {
4266                   assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4267                   total_bytes = next_offset / BITS_PER_UNIT;
4268                 }
4269             }
4270
4271           if (! byte_buffer_in_use)
4272             byte = 0;
4273
4274           /* We must split the element into pieces that fall within
4275              separate bytes, and combine each byte with previous or
4276              following bit-fields.  */
4277
4278           /* next_offset is the offset n fbits from the beginning of
4279              the structure to the next bit of this element to be processed.
4280              end_offset is the offset of the first bit past the end of
4281              this element.  */
4282           while (next_offset < end_offset)
4283             {
4284               int this_time;
4285               int shift;
4286               HOST_WIDE_INT value;
4287               int next_byte = next_offset / BITS_PER_UNIT;
4288               int next_bit = next_offset % BITS_PER_UNIT;
4289
4290               /* Advance from byte to byte
4291                  within this element when necessary.  */
4292               while (next_byte != total_bytes)
4293                 {
4294                   ASM_OUTPUT_BYTE (asm_out_file, byte);
4295                   total_bytes++;
4296                   byte = 0;
4297                 }
4298
4299               /* Number of bits we can process at once
4300                  (all part of the same byte).  */
4301               this_time = MIN (end_offset - next_offset,
4302                                BITS_PER_UNIT - next_bit);
4303               if (BYTES_BIG_ENDIAN)
4304                 {
4305                   /* On big-endian machine, take the most significant bits
4306                      first (of the bits that are significant)
4307                      and put them into bytes from the most significant end.  */
4308                   shift = end_offset - next_offset - this_time;
4309                   /* Don't try to take a bunch of bits that cross
4310                      the word boundary in the INTEGER_CST.  */
4311                   if (shift < HOST_BITS_PER_WIDE_INT
4312                       && shift + this_time > HOST_BITS_PER_WIDE_INT)
4313                     {
4314                       this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4315                       shift = HOST_BITS_PER_WIDE_INT;
4316                     }
4317
4318                   /* Now get the bits from the appropriate constant word.  */
4319                   if (shift < HOST_BITS_PER_WIDE_INT)
4320                     {
4321                       value = TREE_INT_CST_LOW (val);
4322                     }
4323                   else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4324                     {
4325                       value = TREE_INT_CST_HIGH (val);
4326                       shift -= HOST_BITS_PER_WIDE_INT;
4327                     }
4328                   else
4329                     abort ();
4330                   byte |= (((value >> shift)
4331                             & (((HOST_WIDE_INT) 1 << this_time) - 1))
4332                            << (BITS_PER_UNIT - this_time - next_bit));
4333                 }
4334               else
4335                 {
4336                   /* On little-endian machines,
4337                      take first the least significant bits of the value
4338                      and pack them starting at the least significant
4339                      bits of the bytes.  */
4340                   shift = (next_offset
4341                            - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
4342                   /* Don't try to take a bunch of bits that cross
4343                      the word boundary in the INTEGER_CST.  */
4344                   if (shift < HOST_BITS_PER_WIDE_INT
4345                       && shift + this_time > HOST_BITS_PER_WIDE_INT)
4346                     {
4347                       this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4348                       shift = HOST_BITS_PER_WIDE_INT;
4349                     }
4350
4351                   /* Now get the bits from the appropriate constant word.  */
4352                   if (shift < HOST_BITS_PER_WIDE_INT)
4353                     value = TREE_INT_CST_LOW (val);
4354                   else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4355                     {
4356                       value = TREE_INT_CST_HIGH (val);
4357                       shift -= HOST_BITS_PER_WIDE_INT;
4358                     }
4359                   else
4360                     abort ();
4361                   byte |= (((value >> shift)
4362                             & (((HOST_WIDE_INT) 1 << this_time) - 1))
4363                            << next_bit);
4364                 }
4365               next_offset += this_time;
4366               byte_buffer_in_use = 1;
4367             }
4368         }
4369     }
4370   if (byte_buffer_in_use)
4371     {
4372       ASM_OUTPUT_BYTE (asm_out_file, byte);
4373       total_bytes++;
4374     }
4375   if (total_bytes < size)
4376     assemble_zeros (size - total_bytes);
4377 }
4378
4379 #ifdef HANDLE_PRAGMA_WEAK
4380 /* Add function NAME to the weak symbols list.  VALUE is a weak alias
4381    associatd with NAME.  */
4382    
4383 int
4384 add_weak (name, value)
4385      char *name;
4386      char *value;
4387 {
4388   struct weak_syms *weak;
4389
4390   weak = (struct weak_syms *) permalloc (sizeof (struct weak_syms));
4391
4392   if (weak == NULL)
4393     return 0;
4394
4395   weak->next = weak_decls;
4396   weak->name = name;
4397   weak->value = value;
4398   weak_decls = weak;
4399
4400   return 1;
4401 }
4402 #endif /* HANDLE_PRAGMA_WEAK */
4403
4404 /* Declare DECL to be a weak symbol.  */
4405
4406 void
4407 declare_weak (decl)
4408      tree decl;
4409 {
4410   if (! TREE_PUBLIC (decl))
4411     error_with_decl (decl, "weak declaration of `%s' must be public");
4412   else if (TREE_ASM_WRITTEN (decl))
4413     error_with_decl (decl, "weak declaration of `%s' must precede definition");
4414   else if (SUPPORTS_WEAK)
4415     DECL_WEAK (decl) = 1;
4416 #ifdef HANDLE_PRAGMA_WEAK
4417    add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
4418 #endif
4419 }
4420
4421 /* Emit any pending weak declarations.  */
4422
4423 #ifdef HANDLE_PRAGMA_WEAK
4424 struct weak_syms * weak_decls;
4425 #endif
4426
4427 void
4428 weak_finish ()
4429 {
4430 #ifdef HANDLE_PRAGMA_WEAK
4431   if (HANDLE_PRAGMA_WEAK)
4432     {
4433       struct weak_syms *t;
4434       for (t = weak_decls; t; t = t->next)
4435         {
4436           if (t->name)
4437             {
4438               ASM_WEAKEN_LABEL (asm_out_file, t->name);
4439               if (t->value)
4440                 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4441             }
4442         }
4443     }
4444 #endif
4445 }
4446
4447 /* Remove NAME from the pending list of weak symbols.  This prevents
4448    the compiler from emitting multiple .weak directives which confuses
4449    some assemblers.  */
4450 static void
4451 remove_from_pending_weak_list (name)
4452      char *name ATTRIBUTE_UNUSED;
4453 {
4454 #ifdef HANDLE_PRAGMA_WEAK
4455   if (HANDLE_PRAGMA_WEAK)
4456     {
4457       struct weak_syms *t;
4458       for (t = weak_decls; t; t = t->next)
4459         {
4460           if (t->name && strcmp (name, t->name) == 0)
4461             t->name = NULL;
4462         }
4463     }
4464 #endif
4465 }
4466
4467 void
4468 assemble_alias (decl, target)
4469      tree decl, target ATTRIBUTE_UNUSED;
4470 {
4471   char *name;
4472
4473   make_decl_rtl (decl, (char *) 0, 1);
4474   name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4475
4476 #ifdef ASM_OUTPUT_DEF
4477   /* Make name accessible from other files, if appropriate.  */
4478
4479   if (TREE_PUBLIC (decl))
4480     {
4481 #ifdef ASM_WEAKEN_LABEL
4482       if (DECL_WEAK (decl))
4483         {
4484           ASM_WEAKEN_LABEL (asm_out_file, name);
4485           /* Remove this function from the pending weak list so that
4486              we do not emit multiple .weak directives for it.  */
4487           remove_from_pending_weak_list
4488             (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4489         }
4490       else
4491 #endif
4492         ASM_GLOBALIZE_LABEL (asm_out_file, name);
4493     }
4494
4495 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4496   ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4497 #else
4498   ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4499 #endif
4500   TREE_ASM_WRITTEN (decl) = 1;
4501 #else
4502 #ifdef ASM_OUTPUT_WEAK_ALIAS
4503   if (! DECL_WEAK (decl))
4504     warning ("only weak aliases are supported in this configuration");
4505
4506   ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4507   TREE_ASM_WRITTEN (decl) = 1;
4508 #else
4509   warning ("alias definitions not supported in this configuration; ignored");
4510 #endif
4511 #endif
4512 }
4513
4514 /* This determines whether or not we support link-once semantics.  */
4515 #ifndef SUPPORTS_ONE_ONLY
4516 #ifdef MAKE_DECL_ONE_ONLY
4517 #define SUPPORTS_ONE_ONLY 1
4518 #else
4519 #define SUPPORTS_ONE_ONLY 0
4520 #endif
4521 #endif
4522
4523 /* Returns 1 if the target configuration supports defining public symbols
4524    so that one of them will be chosen at link time instead of generating a
4525    multiply-defined symbol error, whether through the use of weak symbols or
4526    a target-specific mechanism for having duplicates discarded.  */
4527
4528 int
4529 supports_one_only ()
4530 {
4531   if (SUPPORTS_ONE_ONLY)
4532     return 1;
4533   return SUPPORTS_WEAK;
4534 }
4535
4536 /* Set up DECL as a public symbol that can be defined in multiple
4537    translation units without generating a linker error.  */
4538
4539 void
4540 make_decl_one_only (decl)
4541      tree decl;
4542 {
4543   if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4544     abort ();
4545
4546   TREE_PUBLIC (decl) = 1;
4547
4548   if (TREE_CODE (decl) == VAR_DECL
4549       && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4550     DECL_COMMON (decl) = 1;
4551   else if (SUPPORTS_ONE_ONLY)
4552     {
4553 #ifdef MAKE_DECL_ONE_ONLY
4554       MAKE_DECL_ONE_ONLY (decl);
4555 #endif
4556       DECL_ONE_ONLY (decl) = 1;
4557     }
4558   else if (SUPPORTS_WEAK)
4559     DECL_WEAK (decl) = 1;
4560   else
4561     abort ();
4562 }
4563
4564 void
4565 init_varasm_once ()
4566 {
4567   ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof(const_hash_table[0]),
4568                 mark_const_hash_entry);
4569   ggc_add_string_root (&in_named_name, 1);
4570 }