OSDN Git Service

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