OSDN Git Service

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