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