OSDN Git Service

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