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