OSDN Git Service

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