OSDN Git Service

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