OSDN Git Service

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