OSDN Git Service

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