OSDN Git Service

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