OSDN Git Service

(assemble_start_function, assemble_variable):
[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
1565   STRIP_NAME_ENCODING (real_name, name);
1566   TREE_SYMBOL_REFERENCED (get_identifier (real_name)) = 1;
1567
1568   if (name[0] == '*')
1569     {
1570       if (output_bytecode)
1571         bc_emit_labelref (name);
1572       else
1573         fputs (&name[1], file);
1574     }
1575   else
1576     {
1577       if (output_bytecode)
1578         BC_OUTPUT_LABELREF (file, name);
1579       else
1580         ASM_OUTPUT_LABELREF (file, name);
1581     }
1582 }
1583
1584 /* Allocate SIZE bytes writable static space with a gensym name
1585    and return an RTX to refer to its address.  */
1586
1587 rtx
1588 assemble_static_space (size)
1589      int size;
1590 {
1591   char name[12];
1592   char *namestring;
1593   rtx x;
1594   /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1595      so that each uninitialized object starts on such a boundary.  */
1596   int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1597                  / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1598                  * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1599
1600 #if 0
1601   if (flag_shared_data)
1602     data_section ();
1603 #endif
1604
1605   ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1606   ++const_labelno;
1607
1608   namestring = (char *) obstack_alloc (saveable_obstack,
1609                                        strlen (name) + 2);
1610   strcpy (namestring, name);
1611
1612   if (output_bytecode)
1613     x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1614   else
1615     x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1616
1617   if (output_bytecode)
1618     {
1619       BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1620     }
1621   else
1622     {
1623 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1624       ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1625 #else
1626       ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1627 #endif
1628     }
1629   return x;
1630 }
1631
1632 /* Assemble the static constant template for function entry trampolines.
1633    This is done at most once per compilation.
1634    Returns an RTX for the address of the template.  */
1635
1636 rtx
1637 assemble_trampoline_template ()
1638 {
1639   char label[256];
1640   char *name;
1641   int align;
1642
1643   /* Shouldn't get here */
1644   if (output_bytecode)
1645     abort ();
1646
1647   /* By default, put trampoline templates in read-only data section.  */
1648
1649 #ifdef TRAMPOLINE_SECTION
1650   TRAMPOLINE_SECTION ();
1651 #else
1652   readonly_data_section ();
1653 #endif
1654
1655   /* Write the assembler code to define one.  */
1656   align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1657   if (align > 0)
1658     ASM_OUTPUT_ALIGN (asm_out_file, align);
1659
1660   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1661   TRAMPOLINE_TEMPLATE (asm_out_file);
1662
1663   /* Record the rtl to refer to it.  */
1664   ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1665   name
1666     = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1667   return gen_rtx (SYMBOL_REF, Pmode, name);
1668 }
1669 \f
1670 /* Assemble the integer constant X into an object of SIZE bytes.
1671    X must be either a CONST_INT or CONST_DOUBLE.
1672
1673    Return 1 if we were able to output the constant, otherwise 0.  If FORCE is
1674    non-zero, abort if we can't output the constant.  */
1675
1676 int
1677 assemble_integer (x, size, force)
1678      rtx x;
1679      int size;
1680      int force;
1681 {
1682   /* First try to use the standard 1, 2, 4, 8, and 16 byte
1683      ASM_OUTPUT... macros. */
1684
1685   switch (size)
1686     {
1687 #ifdef ASM_OUTPUT_CHAR
1688     case 1:
1689       ASM_OUTPUT_CHAR (asm_out_file, x);
1690       return 1;
1691 #endif
1692
1693 #ifdef ASM_OUTPUT_SHORT
1694     case 2:
1695       ASM_OUTPUT_SHORT (asm_out_file, x);
1696       return 1;
1697 #endif
1698
1699 #ifdef ASM_OUTPUT_INT
1700     case 4:
1701       ASM_OUTPUT_INT (asm_out_file, x);
1702       return 1;
1703 #endif
1704
1705 #ifdef ASM_OUTPUT_DOUBLE_INT
1706     case 8:
1707       ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1708       return 1;
1709 #endif
1710
1711 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1712     case 16:
1713       ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1714       return 1;
1715 #endif
1716     }
1717
1718   /* If we couldn't do it that way, there are two other possibilities: First,
1719      if the machine can output an explicit byte and this is a 1 byte constant,
1720      we can use ASM_OUTPUT_BYTE.  */
1721
1722 #ifdef ASM_OUTPUT_BYTE
1723   if (size == 1 && GET_CODE (x) == CONST_INT)
1724     {
1725       ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1726       return 1;
1727     }
1728 #endif
1729
1730   /* Finally, if SIZE is larger than a single word, try to output the constant
1731      one word at a time.  */
1732
1733   if (size > UNITS_PER_WORD)
1734     {
1735       int i;
1736       enum machine_mode mode
1737         = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1738       rtx word;
1739
1740       for (i = 0; i < size / UNITS_PER_WORD; i++)
1741         {
1742           word = operand_subword (x, i, 0, mode);
1743
1744           if (word == 0)
1745             break;
1746
1747           if (! assemble_integer (word, UNITS_PER_WORD, 0))
1748             break;
1749         }
1750
1751       if (i == size / UNITS_PER_WORD)
1752         return 1;
1753       /* If we output at least one word and then could not finish,
1754          there is no valid way to continue.  */
1755       if (i > 0)
1756         abort ();
1757     }
1758
1759   if (force)
1760     abort ();
1761
1762   return 0;
1763 }
1764 \f
1765 /* Assemble the floating-point constant D into an object of size MODE.  */
1766
1767 void
1768 assemble_real (d, mode)
1769      REAL_VALUE_TYPE d;
1770      enum machine_mode mode;
1771 {
1772   jmp_buf output_constant_handler;
1773
1774   if (setjmp (output_constant_handler))
1775     {
1776       error ("floating point trap outputting a constant");
1777 #ifdef REAL_IS_NOT_DOUBLE
1778       bzero ((char *) &d, sizeof d);
1779       d = dconst0;
1780 #else
1781       d = 0;
1782 #endif
1783     }
1784
1785   set_float_handler (output_constant_handler);
1786
1787   switch (mode)
1788     {
1789 #ifdef ASM_OUTPUT_BYTE_FLOAT
1790     case QFmode:
1791       ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1792       break;
1793 #endif
1794 #ifdef ASM_OUTPUT_SHORT_FLOAT
1795     case HFmode:
1796       ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1797       break;
1798 #endif
1799 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1800     case TQFmode:
1801       ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1802       break;
1803 #endif
1804 #ifdef ASM_OUTPUT_FLOAT
1805     case SFmode:
1806       ASM_OUTPUT_FLOAT (asm_out_file, d);
1807       break;
1808 #endif
1809
1810 #ifdef ASM_OUTPUT_DOUBLE
1811     case DFmode:
1812       ASM_OUTPUT_DOUBLE (asm_out_file, d);
1813       break;
1814 #endif
1815
1816 #ifdef ASM_OUTPUT_LONG_DOUBLE
1817     case XFmode:
1818     case TFmode:
1819       ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1820       break;
1821 #endif
1822
1823     default:
1824       abort ();
1825     }
1826
1827   set_float_handler (NULL_PTR);
1828 }
1829 \f
1830 /* Here we combine duplicate floating constants to make
1831    CONST_DOUBLE rtx's, and force those out to memory when necessary.  */
1832
1833 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1834    They are chained through the CONST_DOUBLE_CHAIN.
1835    A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1836    In that case, CONST_DOUBLE_MEM is either a MEM,
1837    or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1838
1839    (CONST_DOUBLE_MEM is used only for top-level functions.
1840    See force_const_mem for explanation.)  */
1841
1842 static rtx const_double_chain;
1843
1844 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1845    For an integer, I0 is the low-order word and I1 is the high-order word.
1846    For a real number, I0 is the word with the low address
1847    and I1 is the word with the high address.  */
1848
1849 rtx
1850 immed_double_const (i0, i1, mode)
1851      HOST_WIDE_INT i0, i1;
1852      enum machine_mode mode;
1853 {
1854   register rtx r;
1855   int in_current_obstack;
1856
1857   if (GET_MODE_CLASS (mode) == MODE_INT
1858       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1859     {
1860       /* We clear out all bits that don't belong in MODE, unless they and our
1861          sign bit are all one.  So we get either a reasonable negative value
1862          or a reasonable unsigned value for this mode.  */
1863       int width = GET_MODE_BITSIZE (mode);
1864       if (width < HOST_BITS_PER_WIDE_INT
1865           && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1866               != ((HOST_WIDE_INT) (-1) << (width - 1))))
1867         i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1868       else if (width == HOST_BITS_PER_WIDE_INT
1869                && ! (i1 == ~0 && i0 < 0))
1870         i1 = 0;
1871       else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1872         /* We cannot represent this value as a constant.  */
1873         abort ();
1874
1875       /* If this would be an entire word for the target, but is not for
1876          the host, then sign-extend on the host so that the number will look
1877          the same way on the host that it would on the target.
1878
1879          For example, when building a 64 bit alpha hosted 32 bit sparc
1880          targeted compiler, then we want the 32 bit unsigned value -1 to be
1881          represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1882          The later confuses the sparc backend.  */
1883
1884       if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1885           && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1886         i0 |= ((HOST_WIDE_INT) (-1) << width);
1887
1888       /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1889
1890          ??? Strictly speaking, this is wrong if we create a CONST_INT
1891          for a large unsigned constant with the size of MODE being
1892          HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1893          wider mode.  In that case we will mis-interpret it as a negative
1894          number.
1895
1896          Unfortunately, the only alternative is to make a CONST_DOUBLE
1897          for any constant in any mode if it is an unsigned constant larger
1898          than the maximum signed integer in an int on the host.  However,
1899          doing this will break everyone that always expects to see a CONST_INT
1900          for SImode and smaller.
1901
1902          We have always been making CONST_INTs in this case, so nothing new
1903          is being broken.  */
1904
1905       if (width <= HOST_BITS_PER_WIDE_INT)
1906         i1 = (i0 < 0) ? ~0 : 0;
1907
1908       /* If this integer fits in one word, return a CONST_INT.  */
1909       if ((i1 == 0 && i0 >= 0)
1910           || (i1 == ~0 && i0 < 0))
1911         return GEN_INT (i0);
1912
1913       /* We use VOIDmode for integers.  */
1914       mode = VOIDmode;
1915     }
1916
1917   /* Search the chain for an existing CONST_DOUBLE with the right value.
1918      If one is found, return it.  */
1919
1920   for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1921     if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1922         && GET_MODE (r) == mode)
1923       return r;
1924
1925   /* No; make a new one and add it to the chain.
1926
1927      We may be called by an optimizer which may be discarding any memory
1928      allocated during its processing (such as combine and loop).  However,
1929      we will be leaving this constant on the chain, so we cannot tolerate
1930      freed memory.  So switch to saveable_obstack for this allocation
1931      and then switch back if we were in current_obstack.  */
1932
1933   push_obstacks_nochange ();
1934   rtl_in_saveable_obstack ();
1935   r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1936   pop_obstacks ();
1937
1938   /* Don't touch const_double_chain in nested function; see force_const_mem.
1939      Also, don't touch it if not inside any function.  */
1940   if (outer_function_chain == 0 && current_function_decl != 0)
1941     {
1942       CONST_DOUBLE_CHAIN (r) = const_double_chain;
1943       const_double_chain = r;
1944     }
1945
1946   /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1947      Actual use of mem-slot is only through force_const_mem.  */
1948
1949   CONST_DOUBLE_MEM (r) = const0_rtx;
1950
1951   return r;
1952 }
1953
1954 /* Return a CONST_DOUBLE for a specified `double' value
1955    and machine mode.  */
1956
1957 rtx
1958 immed_real_const_1 (d, mode)
1959      REAL_VALUE_TYPE d;
1960      enum machine_mode mode;
1961 {
1962   union real_extract u;
1963   register rtx r;
1964   int in_current_obstack;
1965
1966   /* Get the desired `double' value as a sequence of ints
1967      since that is how they are stored in a CONST_DOUBLE.  */
1968
1969   u.d = d;
1970
1971   /* Detect special cases.  */
1972
1973   /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero.  */
1974   if (!bcmp ((char *) &dconst0, (char *) &d, sizeof d))
1975     return CONST0_RTX (mode);
1976   /* Check for NaN first, because some ports (specifically the i386) do not
1977      emit correct ieee-fp code by default, and thus will generate a core
1978      dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1979      does a floating point comparison.  */
1980   else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1981     return CONST1_RTX (mode);
1982
1983   if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1984     return immed_double_const (u.i[0], u.i[1], mode);
1985
1986   /* The rest of this function handles the case where
1987      a float value requires more than 2 ints of space.
1988      It will be deleted as dead code on machines that don't need it.  */
1989
1990   /* Search the chain for an existing CONST_DOUBLE with the right value.
1991      If one is found, return it.  */
1992
1993   for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1994     if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
1995         && GET_MODE (r) == mode)
1996       return r;
1997
1998   /* No; make a new one and add it to the chain.
1999
2000      We may be called by an optimizer which may be discarding any memory
2001      allocated during its processing (such as combine and loop).  However,
2002      we will be leaving this constant on the chain, so we cannot tolerate
2003      freed memory.  So switch to saveable_obstack for this allocation
2004      and then switch back if we were in current_obstack.  */
2005
2006   push_obstacks_nochange ();
2007   rtl_in_saveable_obstack ();
2008   r = rtx_alloc (CONST_DOUBLE);
2009   PUT_MODE (r, mode);
2010   bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
2011   pop_obstacks ();
2012
2013   /* Don't touch const_double_chain in nested function; see force_const_mem.
2014      Also, don't touch it if not inside any function.  */
2015   if (outer_function_chain == 0 && current_function_decl != 0)
2016     {
2017       CONST_DOUBLE_CHAIN (r) = const_double_chain;
2018       const_double_chain = r;
2019     }
2020
2021   /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2022      chain, but has not been allocated memory.  Actual use of CONST_DOUBLE_MEM
2023      is only through force_const_mem.  */
2024
2025   CONST_DOUBLE_MEM (r) = const0_rtx;
2026
2027   return r;
2028 }
2029
2030 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2031    which must be a REAL_CST tree node.  */
2032
2033 rtx
2034 immed_real_const (exp)
2035      tree exp;
2036 {
2037   return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2038 }
2039
2040 /* At the end of a function, forget the memory-constants
2041    previously made for CONST_DOUBLEs.  Mark them as not on real_constant_chain.
2042    Also clear out real_constant_chain and clear out all the chain-pointers.  */
2043
2044 void
2045 clear_const_double_mem ()
2046 {
2047   register rtx r, next;
2048
2049   /* Don't touch CONST_DOUBLE_MEM for nested functions.
2050      See force_const_mem for explanation.  */
2051   if (outer_function_chain != 0)
2052     return;
2053
2054   for (r = const_double_chain; r; r = next)
2055     {
2056       next = CONST_DOUBLE_CHAIN (r);
2057       CONST_DOUBLE_CHAIN (r) = 0;
2058       CONST_DOUBLE_MEM (r) = cc0_rtx;
2059     }
2060   const_double_chain = 0;
2061 }
2062 \f
2063 /* Given an expression EXP with a constant value,
2064    reduce it to the sum of an assembler symbol and an integer.
2065    Store them both in the structure *VALUE.
2066    Abort if EXP does not reduce.  */
2067
2068 struct addr_const
2069 {
2070   rtx base;
2071   HOST_WIDE_INT offset;
2072 };
2073
2074 static void
2075 decode_addr_const (exp, value)
2076      tree exp;
2077      struct addr_const *value;
2078 {
2079   register tree target = TREE_OPERAND (exp, 0);
2080   register int offset = 0;
2081   register rtx x;
2082
2083   while (1)
2084     {
2085       if (TREE_CODE (target) == COMPONENT_REF
2086           && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2087               == INTEGER_CST))
2088         {
2089           offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2090           target = TREE_OPERAND (target, 0);
2091         }
2092       else if (TREE_CODE (target) == ARRAY_REF)
2093         {
2094           if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2095               || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2096             abort ();
2097           offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2098                       * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2099                      / BITS_PER_UNIT);
2100           target = TREE_OPERAND (target, 0);
2101         }
2102       else
2103         break;
2104     }
2105
2106   switch (TREE_CODE (target))
2107     {
2108     case VAR_DECL:
2109     case FUNCTION_DECL:
2110       x = DECL_RTL (target);
2111       break;
2112
2113     case LABEL_DECL:
2114       if (output_bytecode)
2115         /* FIXME: this may not be correct, check it */
2116         x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
2117       else
2118         x = gen_rtx (MEM, FUNCTION_MODE,
2119                      gen_rtx (LABEL_REF, VOIDmode,
2120                               label_rtx (TREE_OPERAND (exp, 0))));
2121       break;
2122
2123     case REAL_CST:
2124     case STRING_CST:
2125     case COMPLEX_CST:
2126     case CONSTRUCTOR:
2127       x = TREE_CST_RTL (target);
2128       break;
2129
2130     default:
2131       abort ();
2132     }
2133
2134   if (!output_bytecode)
2135     {
2136       if (GET_CODE (x) != MEM)
2137         abort ();
2138       x = XEXP (x, 0);
2139     }
2140
2141   value->base = x;
2142   value->offset = offset;
2143 }
2144 \f
2145 /* Uniquize all constants that appear in memory.
2146    Each constant in memory thus far output is recorded
2147    in `const_hash_table' with a `struct constant_descriptor'
2148    that contains a polish representation of the value of
2149    the constant.
2150
2151    We cannot store the trees in the hash table
2152    because the trees may be temporary.  */
2153
2154 struct constant_descriptor
2155 {
2156   struct constant_descriptor *next;
2157   char *label;
2158   char contents[1];
2159 };
2160
2161 #define HASHBITS 30
2162 #define MAX_HASH_TABLE 1009
2163 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2164
2165 /* Compute a hash code for a constant expression.  */
2166
2167 static int
2168 const_hash (exp)
2169      tree exp;
2170 {
2171   register char *p;
2172   register int len, hi, i;
2173   register enum tree_code code = TREE_CODE (exp);
2174
2175   if (code == INTEGER_CST)
2176     {
2177       p = (char *) &TREE_INT_CST_LOW (exp);
2178       len = 2 * sizeof TREE_INT_CST_LOW (exp);
2179     }
2180   else if (code == REAL_CST)
2181     {
2182       p = (char *) &TREE_REAL_CST (exp);
2183       len = sizeof TREE_REAL_CST (exp);
2184     }
2185   else if (code == STRING_CST)
2186     p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2187   else if (code == COMPLEX_CST)
2188     return const_hash (TREE_REALPART (exp)) * 5
2189       + const_hash (TREE_IMAGPART (exp));
2190   else if (code == CONSTRUCTOR && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2191     {
2192       len = int_size_in_bytes (TREE_TYPE (exp));
2193       p = (char*) alloca (len);
2194       get_set_constructor_bytes (exp, (unsigned char *) p, len);
2195     }
2196   else if (code == CONSTRUCTOR)
2197     {
2198       register tree link;
2199
2200       /* For record type, include the type in the hashing.
2201          We do not do so for array types
2202          because (1) the sizes of the elements are sufficient
2203          and (2) distinct array types can have the same constructor.
2204          Instead, we include the array size because the constructor could
2205          be shorter.  */
2206       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2207         hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2208           % MAX_HASH_TABLE;
2209       else
2210         hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2211                & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2212
2213       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2214         if (TREE_VALUE (link))
2215           hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2216
2217       return hi;
2218     }
2219   else if (code == ADDR_EXPR)
2220     {
2221       struct addr_const value;
2222       decode_addr_const (exp, &value);
2223       if (GET_CODE (value.base) == SYMBOL_REF)
2224         {
2225           /* Don't hash the address of the SYMBOL_REF;
2226              only use the offset and the symbol name.  */
2227           hi = value.offset;
2228           p = XSTR (value.base, 0);
2229           for (i = 0; p[i] != 0; i++)
2230             hi = ((hi * 613) + (unsigned)(p[i]));
2231         }
2232       else if (GET_CODE (value.base) == LABEL_REF)
2233         hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2234
2235       hi &= (1 << HASHBITS) - 1;
2236       hi %= MAX_HASH_TABLE;
2237       return hi;
2238     }
2239   else if (code == PLUS_EXPR || code == MINUS_EXPR)
2240     return const_hash (TREE_OPERAND (exp, 0)) * 9
2241       +  const_hash (TREE_OPERAND (exp, 1));
2242   else if (code == NOP_EXPR || code == CONVERT_EXPR)
2243     return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2244
2245   /* Compute hashing function */
2246   hi = len;
2247   for (i = 0; i < len; i++)
2248     hi = ((hi * 613) + (unsigned)(p[i]));
2249
2250   hi &= (1 << HASHBITS) - 1;
2251   hi %= MAX_HASH_TABLE;
2252   return hi;
2253 }
2254 \f
2255 /* Compare a constant expression EXP with a constant-descriptor DESC.
2256    Return 1 if DESC describes a constant with the same value as EXP.  */
2257
2258 static int
2259 compare_constant (exp, desc)
2260      tree exp;
2261      struct constant_descriptor *desc;
2262 {
2263   return 0 != compare_constant_1 (exp, desc->contents);
2264 }
2265
2266 /* Compare constant expression EXP with a substring P of a constant descriptor.
2267    If they match, return a pointer to the end of the substring matched.
2268    If they do not match, return 0.
2269
2270    Since descriptors are written in polish prefix notation,
2271    this function can be used recursively to test one operand of EXP
2272    against a subdescriptor, and if it succeeds it returns the
2273    address of the subdescriptor for the next operand.  */
2274
2275 static char *
2276 compare_constant_1 (exp, p)
2277      tree exp;
2278      char *p;
2279 {
2280   register char *strp;
2281   register int len;
2282   register enum tree_code code = TREE_CODE (exp);
2283
2284   if (code != (enum tree_code) *p++)
2285     return 0;
2286
2287   if (code == INTEGER_CST)
2288     {
2289       /* Integer constants are the same only if the same width of type.  */
2290       if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2291         return 0;
2292       strp = (char *) &TREE_INT_CST_LOW (exp);
2293       len = 2 * sizeof TREE_INT_CST_LOW (exp);
2294     }
2295   else if (code == REAL_CST)
2296     {
2297       /* Real constants are the same only if the same width of type.  */
2298       if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2299         return 0;
2300       strp = (char *) &TREE_REAL_CST (exp);
2301       len = sizeof TREE_REAL_CST (exp);
2302     }
2303   else if (code == STRING_CST)
2304     {
2305       if (flag_writable_strings)
2306         return 0;
2307       strp = TREE_STRING_POINTER (exp);
2308       len = TREE_STRING_LENGTH (exp);
2309       if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2310                 sizeof TREE_STRING_LENGTH (exp)))
2311         return 0;
2312       p += sizeof TREE_STRING_LENGTH (exp);
2313     }
2314   else if (code == COMPLEX_CST)
2315     {
2316       p = compare_constant_1 (TREE_REALPART (exp), p);
2317       if (p == 0) return 0;
2318       p = compare_constant_1 (TREE_IMAGPART (exp), p);
2319       return p;
2320     }
2321   else if (code == CONSTRUCTOR && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2322     {
2323       len = int_size_in_bytes (TREE_TYPE (exp));
2324       strp = (char*) alloca (len);
2325       get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2326     }
2327   else if (code == CONSTRUCTOR)
2328     {
2329       register tree link;
2330       int length = list_length (CONSTRUCTOR_ELTS (exp));
2331       tree type;
2332
2333       if (bcmp ((char *) &length, p, sizeof length))
2334         return 0;
2335       p += sizeof length;
2336
2337       /* For record constructors, insist that the types match.
2338          For arrays, just verify both constructors are for arrays.  */
2339       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2340         type = TREE_TYPE (exp);
2341       else
2342         type = 0;
2343       if (bcmp ((char *) &type, p, sizeof type))
2344         return 0;
2345       p += sizeof type;
2346
2347       /* For arrays, insist that the size in bytes match.  */
2348       if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2349         {
2350           int size = int_size_in_bytes (TREE_TYPE (exp));
2351           if (bcmp ((char *) &size, p, sizeof size))
2352             return 0;
2353           p += sizeof size;
2354         }
2355
2356       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2357         {
2358           if (TREE_VALUE (link))
2359             {
2360               if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2361                 return 0;
2362             }
2363           else
2364             {
2365               tree zero = 0;
2366
2367               if (bcmp ((char *) &zero, p, sizeof zero))
2368                 return 0;
2369               p += sizeof zero;
2370             }
2371         }
2372
2373       return p;
2374     }
2375   else if (code == ADDR_EXPR)
2376     {
2377       struct addr_const value;
2378       decode_addr_const (exp, &value);
2379       strp = (char *) &value.offset;
2380       len = sizeof value.offset;
2381       /* Compare the offset.  */
2382       while (--len >= 0)
2383         if (*p++ != *strp++)
2384           return 0;
2385       /* Compare symbol name.  */
2386       strp = XSTR (value.base, 0);
2387       len = strlen (strp) + 1;
2388     }
2389   else if (code == PLUS_EXPR || code == MINUS_EXPR)
2390     {
2391       p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2392       if (p == 0) return 0;
2393       p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2394       return p;
2395     }
2396   else if (code == NOP_EXPR || code == CONVERT_EXPR)
2397     {
2398       p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2399       return p;
2400     }
2401
2402   /* Compare constant contents.  */
2403   while (--len >= 0)
2404     if (*p++ != *strp++)
2405       return 0;
2406
2407   return p;
2408 }
2409 \f
2410 /* Construct a constant descriptor for the expression EXP.
2411    It is up to the caller to enter the descriptor in the hash table.  */
2412
2413 static struct constant_descriptor *
2414 record_constant (exp)
2415      tree exp;
2416 {
2417   struct constant_descriptor *next = 0;
2418   char *label = 0;
2419
2420   /* Make a struct constant_descriptor.  The first two pointers will
2421      be filled in later.  Here we just leave space for them.  */
2422
2423   obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2424   obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2425   record_constant_1 (exp);
2426   return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2427 }
2428
2429 /* Add a description of constant expression EXP
2430    to the object growing in `permanent_obstack'.
2431    No need to return its address; the caller will get that
2432    from the obstack when the object is complete.  */
2433
2434 static void
2435 record_constant_1 (exp)
2436      tree exp;
2437 {
2438   register char *strp;
2439   register int len;
2440   register enum tree_code code = TREE_CODE (exp);
2441
2442   obstack_1grow (&permanent_obstack, (unsigned int) code);
2443
2444   switch (code)
2445     {
2446     case INTEGER_CST:
2447       obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2448       strp = (char *) &TREE_INT_CST_LOW (exp);
2449       len = 2 * sizeof TREE_INT_CST_LOW (exp);
2450       break;
2451
2452     case REAL_CST:
2453       obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2454       strp = (char *) &TREE_REAL_CST (exp);
2455       len = sizeof TREE_REAL_CST (exp);
2456       break;
2457
2458     case STRING_CST:
2459       if (flag_writable_strings)
2460         return;
2461
2462       strp = TREE_STRING_POINTER (exp);
2463       len = TREE_STRING_LENGTH (exp);
2464       obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2465                     sizeof TREE_STRING_LENGTH (exp));
2466       break;
2467
2468     case COMPLEX_CST:
2469       record_constant_1 (TREE_REALPART (exp));
2470       record_constant_1 (TREE_IMAGPART (exp));
2471       return;
2472
2473     case CONSTRUCTOR:
2474       if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2475         {
2476           int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2477           obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2478           obstack_blank (&permanent_obstack, nbytes);
2479           get_set_constructor_bytes
2480             (exp, (unsigned char *) permanent_obstack.next_free, nbytes);
2481           return;
2482         }
2483       else
2484         {
2485           register tree link;
2486           int length = list_length (CONSTRUCTOR_ELTS (exp));
2487           tree type;
2488
2489           obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2490
2491           /* For record constructors, insist that the types match.
2492              For arrays, just verify both constructors are for arrays.  */
2493           if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2494             type = TREE_TYPE (exp);
2495           else
2496             type = 0;
2497           obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2498
2499           /* For arrays, insist that the size in bytes match.  */
2500           if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2501             {
2502               int size = int_size_in_bytes (TREE_TYPE (exp));
2503               obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2504             }
2505
2506           for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2507             {
2508               if (TREE_VALUE (link))
2509                 record_constant_1 (TREE_VALUE (link));
2510               else
2511                 {
2512                   tree zero = 0;
2513
2514                   obstack_grow (&permanent_obstack,
2515                                 (char *) &zero, sizeof zero);
2516                 }
2517             }
2518         }
2519       return;
2520
2521     case ADDR_EXPR:
2522       {
2523         struct addr_const value;
2524
2525         decode_addr_const (exp, &value);
2526         /* Record the offset.  */
2527         obstack_grow (&permanent_obstack,
2528                       (char *) &value.offset, sizeof value.offset);
2529         /* Record the symbol name.  */
2530         obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2531                       strlen (XSTR (value.base, 0)) + 1);
2532       }
2533       return;
2534
2535     case PLUS_EXPR:
2536     case MINUS_EXPR:
2537       record_constant_1 (TREE_OPERAND (exp, 0));
2538       record_constant_1 (TREE_OPERAND (exp, 1));
2539       return;
2540
2541     case NOP_EXPR:
2542     case CONVERT_EXPR:
2543     case NON_LVALUE_EXPR:
2544       record_constant_1 (TREE_OPERAND (exp, 0));
2545       return;
2546
2547     default:
2548       abort ();
2549     }
2550
2551   /* Record constant contents.  */
2552   obstack_grow (&permanent_obstack, strp, len);
2553 }
2554 \f
2555 /* Record a list of constant expressions that were passed to
2556    output_constant_def but that could not be output right away.  */
2557
2558 struct deferred_constant
2559 {
2560   struct deferred_constant *next;
2561   tree exp;
2562   int reloc;
2563   int labelno;
2564 };
2565
2566 static struct deferred_constant *deferred_constants;
2567
2568 /* Nonzero means defer output of addressed subconstants
2569    (i.e., those for which output_constant_def is called.)  */
2570 static int defer_addressed_constants_flag;
2571
2572 /* Start deferring output of subconstants.  */
2573
2574 void
2575 defer_addressed_constants ()
2576 {
2577   defer_addressed_constants_flag++;
2578 }
2579
2580 /* Stop deferring output of subconstants,
2581    and output now all those that have been deferred.  */
2582
2583 void
2584 output_deferred_addressed_constants ()
2585 {
2586   struct deferred_constant *p, *next;
2587
2588   defer_addressed_constants_flag--;
2589
2590   if (defer_addressed_constants_flag > 0)
2591     return;
2592
2593   for (p = deferred_constants; p; p = next)
2594     {
2595       output_constant_def_contents (p->exp, p->reloc, p->labelno);
2596       next = p->next;
2597       free (p);
2598     }
2599
2600   deferred_constants = 0;
2601 }
2602
2603 /* Make a copy of the whole tree structure for a constant.
2604    This handles the same types of nodes that compare_constant
2605    and record_constant handle.  */
2606
2607 static tree
2608 copy_constant (exp)
2609      tree exp;
2610 {
2611   switch (TREE_CODE (exp))
2612     {
2613     case ADDR_EXPR:
2614       /* For ADDR_EXPR, we do not want to copy the decl whose address
2615          is requested.  We do want to copy constants though.  */
2616       if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2617         return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2618                        copy_constant (TREE_OPERAND (exp, 0)));
2619       else
2620         return copy_node (exp);
2621
2622     case INTEGER_CST:
2623     case REAL_CST:
2624     case STRING_CST:
2625       return copy_node (exp);
2626
2627     case COMPLEX_CST:
2628       return build_complex (copy_constant (TREE_REALPART (exp)),
2629                             copy_constant (TREE_IMAGPART (exp)));
2630
2631     case PLUS_EXPR:
2632     case MINUS_EXPR:
2633       return build (TREE_CODE (exp), TREE_TYPE (exp),
2634                     copy_constant (TREE_OPERAND (exp, 0)),
2635                     copy_constant (TREE_OPERAND (exp, 1)));
2636
2637     case NOP_EXPR:
2638     case CONVERT_EXPR:
2639       return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2640                      copy_constant (TREE_OPERAND (exp, 0)));
2641
2642     case CONSTRUCTOR:
2643       {
2644         tree copy = copy_node (exp);
2645         tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2646         tree tail;
2647
2648         CONSTRUCTOR_ELTS (copy) = list;
2649         for (tail = list; tail; tail = TREE_CHAIN (tail))
2650           TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2651         if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2652           for (tail = list; tail; tail = TREE_CHAIN (tail))
2653             TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2654
2655         return copy;
2656       }
2657
2658     default:
2659       abort ();
2660     }
2661 }
2662 \f
2663 /* Return an rtx representing a reference to constant data in memory
2664    for the constant expression EXP.
2665
2666    If assembler code for such a constant has already been output,
2667    return an rtx to refer to it.
2668    Otherwise, output such a constant in memory (or defer it for later)
2669    and generate an rtx for it.
2670
2671    The TREE_CST_RTL of EXP is set up to point to that rtx.
2672    The const_hash_table records which constants already have label strings.  */
2673
2674 rtx
2675 output_constant_def (exp)
2676      tree exp;
2677 {
2678   register int hash;
2679   register struct constant_descriptor *desc;
2680   char label[256];
2681   char *found = 0;
2682   int reloc;
2683   register rtx def;
2684
2685   if (TREE_CODE (exp) == INTEGER_CST)
2686     abort ();                   /* No TREE_CST_RTL slot in these.  */
2687
2688   if (TREE_CST_RTL (exp))
2689     return TREE_CST_RTL (exp);
2690
2691   /* Make sure any other constants whose addresses appear in EXP
2692      are assigned label numbers.  */
2693
2694   reloc = output_addressed_constants (exp);
2695
2696   /* Compute hash code of EXP.  Search the descriptors for that hash code
2697      to see if any of them describes EXP.  If yes, the descriptor records
2698      the label number already assigned.  */
2699
2700   hash = const_hash (exp) % MAX_HASH_TABLE;
2701       
2702   for (desc = const_hash_table[hash]; desc; desc = desc->next)
2703     if (compare_constant (exp, desc))
2704       {
2705         found = desc->label;
2706         break;
2707       }
2708       
2709   if (found == 0)
2710     {
2711       /* No constant equal to EXP is known to have been output.
2712          Make a constant descriptor to enter EXP in the hash table.
2713          Assign the label number and record it in the descriptor for
2714          future calls to this function to find.  */
2715           
2716       /* Create a string containing the label name, in LABEL.  */
2717       ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2718
2719       desc = record_constant (exp);
2720       desc->next = const_hash_table[hash];
2721       desc->label
2722         = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2723       const_hash_table[hash] = desc;
2724     }
2725   else
2726     {
2727       /* Create a string containing the label name, in LABEL.  */
2728       ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2729     }
2730   
2731   /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
2732
2733   push_obstacks_nochange ();
2734   if (TREE_PERMANENT (exp))
2735     end_temporary_allocation ();
2736
2737   def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2738       
2739   TREE_CST_RTL (exp)
2740     = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2741   RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2742   if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2743     MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2744
2745   pop_obstacks ();
2746
2747   /* Optionally set flags or add text to the name to record information
2748      such as that it is a function name.  If the name is changed, the macro
2749      ASM_OUTPUT_LABELREF will have to know how to strip this information.  */
2750 #ifdef ENCODE_SECTION_INFO
2751   ENCODE_SECTION_INFO (exp);
2752 #endif
2753
2754   /* If this is the first time we've seen this particular constant,
2755      output it (or defer its output for later).  */
2756   if (found == 0)
2757     {
2758       if (defer_addressed_constants_flag)
2759         {
2760           struct deferred_constant *p;
2761           p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2762
2763           push_obstacks_nochange ();
2764           suspend_momentary ();
2765           p->exp = copy_constant (exp);
2766           pop_obstacks ();
2767           p->reloc = reloc;
2768           p->labelno = const_labelno++;
2769           p->next = deferred_constants;
2770           deferred_constants = p;
2771         }
2772       else
2773         output_constant_def_contents (exp, reloc, const_labelno++);
2774     }
2775
2776   return TREE_CST_RTL (exp);
2777 }
2778
2779 /* Now output assembler code to define the label for EXP,
2780    and follow it with the data of EXP.  */
2781
2782 static void
2783 output_constant_def_contents (exp, reloc, labelno)
2784      tree exp;
2785      int reloc;
2786      int labelno;
2787 {
2788   int align;
2789
2790   if (IN_NAMED_SECTION (exp))
2791     named_section (exp, NULL);
2792   else
2793     {
2794       /* First switch to text section, except for writable strings.  */
2795 #ifdef SELECT_SECTION
2796       SELECT_SECTION (exp, reloc);
2797 #else
2798       if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2799           || (flag_pic && reloc))
2800         data_section ();
2801       else
2802         readonly_data_section ();
2803 #endif
2804     }
2805
2806   /* Align the location counter as required by EXP's data type.  */
2807   align = TYPE_ALIGN (TREE_TYPE (exp));
2808 #ifdef CONSTANT_ALIGNMENT
2809   align = CONSTANT_ALIGNMENT (exp, align);
2810 #endif
2811
2812   if (align > BITS_PER_UNIT)
2813     {
2814       if (!output_bytecode)
2815         {
2816           ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2817         }
2818       else
2819         {
2820           BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2821         }
2822     }
2823
2824   /* Output the label itself.  */
2825   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2826
2827   /* Output the value of EXP.  */
2828   output_constant (exp,
2829                    (TREE_CODE (exp) == STRING_CST
2830                     ? TREE_STRING_LENGTH (exp)
2831                     : int_size_in_bytes (TREE_TYPE (exp))));
2832
2833 }
2834 \f
2835 /* Similar hash facility for making memory-constants
2836    from constant rtl-expressions.  It is used on RISC machines
2837    where immediate integer arguments and constant addresses are restricted
2838    so that such constants must be stored in memory.
2839
2840    This pool of constants is reinitialized for each function
2841    so each function gets its own constants-pool that comes right before it.
2842
2843    All structures allocated here are discarded when functions are saved for
2844    inlining, so they do not need to be allocated permanently.  */
2845
2846 #define MAX_RTX_HASH_TABLE 61
2847 static struct constant_descriptor **const_rtx_hash_table;
2848
2849 /* Structure to represent sufficient information about a constant so that
2850    it can be output when the constant pool is output, so that function
2851    integration can be done, and to simplify handling on machines that reference
2852    constant pool as base+displacement.  */
2853
2854 struct pool_constant
2855 {
2856   struct constant_descriptor *desc;
2857   struct pool_constant *next;
2858   enum machine_mode mode;
2859   rtx constant;
2860   int labelno;
2861   int align;
2862   int offset;
2863 };
2864
2865 /* Pointers to first and last constant in pool.  */
2866
2867 static struct pool_constant *first_pool, *last_pool;
2868
2869 /* Current offset in constant pool (does not include any machine-specific
2870    header.  */
2871
2872 static int pool_offset;
2873
2874 /* Structure used to maintain hash table mapping symbols used to their
2875    corresponding constants.  */
2876
2877 struct pool_sym
2878 {
2879   char *label;
2880   struct pool_constant *pool;
2881   struct pool_sym *next;
2882 };
2883
2884 static struct pool_sym **const_rtx_sym_hash_table;
2885
2886 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2887    The argument is XSTR (... , 0)  */
2888
2889 #define SYMHASH(LABEL)  \
2890   ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1))  % MAX_RTX_HASH_TABLE)
2891 \f
2892 /* Initialize constant pool hashing for next function.  */
2893
2894 void
2895 init_const_rtx_hash_table ()
2896 {
2897   const_rtx_hash_table
2898     = ((struct constant_descriptor **)
2899        oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2900   const_rtx_sym_hash_table
2901     = ((struct pool_sym **)
2902        oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2903   bzero ((char *) const_rtx_hash_table,
2904          MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2905   bzero ((char *) const_rtx_sym_hash_table,
2906          MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2907
2908   first_pool = last_pool = 0;
2909   pool_offset = 0;
2910 }
2911
2912 /* Save and restore status for a nested function.  */
2913
2914 void
2915 save_varasm_status (p)
2916      struct function *p;
2917 {
2918   p->const_rtx_hash_table = const_rtx_hash_table;
2919   p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2920   p->first_pool = first_pool;
2921   p->last_pool = last_pool;
2922   p->pool_offset = pool_offset;
2923 }
2924
2925 void
2926 restore_varasm_status (p)
2927      struct function *p;
2928 {
2929   const_rtx_hash_table = p->const_rtx_hash_table;
2930   const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2931   first_pool = p->first_pool;
2932   last_pool = p->last_pool;
2933   pool_offset = p->pool_offset;
2934 }
2935 \f
2936 enum kind { RTX_DOUBLE, RTX_INT };
2937
2938 struct rtx_const
2939 {
2940 #ifdef ONLY_INT_FIELDS
2941   unsigned int kind : 16;
2942   unsigned int mode : 16;
2943 #else
2944   enum kind kind : 16;
2945   enum machine_mode mode : 16;
2946 #endif
2947   union {
2948     union real_extract du;
2949     struct addr_const addr;
2950   } un;
2951 };
2952
2953 /* Express an rtx for a constant integer (perhaps symbolic)
2954    as the sum of a symbol or label plus an explicit integer.
2955    They are stored into VALUE.  */
2956
2957 static void
2958 decode_rtx_const (mode, x, value)
2959      enum machine_mode mode;
2960      rtx x;
2961      struct rtx_const *value;
2962 {
2963   /* Clear the whole structure, including any gaps.  */
2964
2965   {
2966     int *p = (int *) value;
2967     int *end = (int *) (value + 1);
2968     while (p < end)
2969       *p++ = 0;
2970   }
2971
2972   value->kind = RTX_INT;        /* Most usual kind. */
2973   value->mode = mode;
2974
2975   switch (GET_CODE (x))
2976     {
2977     case CONST_DOUBLE:
2978       value->kind = RTX_DOUBLE;
2979       if (GET_MODE (x) != VOIDmode)
2980         value->mode = GET_MODE (x);
2981       bcopy ((char *) &CONST_DOUBLE_LOW (x),
2982              (char *) &value->un.du, sizeof value->un.du);
2983       break;
2984
2985     case CONST_INT:
2986       value->un.addr.offset = INTVAL (x);
2987       break;
2988
2989     case SYMBOL_REF:
2990     case LABEL_REF:
2991     case PC:
2992       value->un.addr.base = x;
2993       break;
2994
2995     case CONST:
2996       x = XEXP (x, 0);
2997       if (GET_CODE (x) == PLUS)
2998         {
2999           value->un.addr.base = XEXP (x, 0);
3000           if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3001             abort ();
3002           value->un.addr.offset = INTVAL (XEXP (x, 1));
3003         }
3004       else if (GET_CODE (x) == MINUS)
3005         {
3006           value->un.addr.base = XEXP (x, 0);
3007           if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3008             abort ();
3009           value->un.addr.offset = - INTVAL (XEXP (x, 1));
3010         }
3011       else
3012         abort ();
3013       break;
3014
3015     default:
3016       abort ();
3017     }
3018
3019   if (value->kind == RTX_INT && value->un.addr.base != 0)
3020     switch (GET_CODE (value->un.addr.base))
3021       {
3022       case SYMBOL_REF:
3023       case LABEL_REF:
3024         /* Use the string's address, not the SYMBOL_REF's address,
3025            for the sake of addresses of library routines.
3026            For a LABEL_REF, compare labels.  */
3027         value->un.addr.base = XEXP (value->un.addr.base, 0);
3028       }
3029 }
3030
3031 /* Given a MINUS expression, simplify it if both sides
3032    include the same symbol.  */
3033
3034 rtx
3035 simplify_subtraction (x)
3036      rtx x;
3037 {
3038   struct rtx_const val0, val1;
3039
3040   decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3041   decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3042
3043   if (val0.un.addr.base == val1.un.addr.base)
3044     return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3045   return x;
3046 }
3047
3048 /* Compute a hash code for a constant RTL expression.  */
3049
3050 static int
3051 const_hash_rtx (mode, x)
3052      enum machine_mode mode;
3053      rtx x;
3054 {
3055   register int hi, i;
3056
3057   struct rtx_const value;
3058   decode_rtx_const (mode, x, &value);
3059
3060   /* Compute hashing function */
3061   hi = 0;
3062   for (i = 0; i < sizeof value / sizeof (int); i++)
3063     hi += ((int *) &value)[i];
3064
3065   hi &= (1 << HASHBITS) - 1;
3066   hi %= MAX_RTX_HASH_TABLE;
3067   return hi;
3068 }
3069
3070 /* Compare a constant rtl object X with a constant-descriptor DESC.
3071    Return 1 if DESC describes a constant with the same value as X.  */
3072
3073 static int
3074 compare_constant_rtx (mode, x, desc)
3075      enum machine_mode mode;
3076      rtx x;
3077      struct constant_descriptor *desc;
3078 {
3079   register int *p = (int *) desc->contents;
3080   register int *strp;
3081   register int len;
3082   struct rtx_const value;
3083
3084   decode_rtx_const (mode, x, &value);
3085   strp = (int *) &value;
3086   len = sizeof value / sizeof (int);
3087
3088   /* Compare constant contents.  */
3089   while (--len >= 0)
3090     if (*p++ != *strp++)
3091       return 0;
3092
3093   return 1;
3094 }
3095
3096 /* Construct a constant descriptor for the rtl-expression X.
3097    It is up to the caller to enter the descriptor in the hash table.  */
3098
3099 static struct constant_descriptor *
3100 record_constant_rtx (mode, x)
3101      enum machine_mode mode;
3102      rtx x;
3103 {
3104   struct constant_descriptor *ptr;
3105   char *label;
3106   struct rtx_const value;
3107
3108   decode_rtx_const (mode, x, &value);
3109
3110   /* Put these things in the saveable obstack so we can ensure it won't
3111      be freed if we are called from combine or some other phase that discards
3112      memory allocated from function_obstack (current_obstack).  */
3113   obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3114   obstack_grow (saveable_obstack, &label, sizeof label);
3115
3116   /* Record constant contents.  */
3117   obstack_grow (saveable_obstack, &value, sizeof value);
3118
3119   return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3120 }
3121 \f
3122 /* Given a constant rtx X, make (or find) a memory constant for its value
3123    and return a MEM rtx to refer to it in memory.  */
3124
3125 rtx
3126 force_const_mem (mode, x)
3127      enum machine_mode mode;
3128      rtx x;
3129 {
3130   register int hash;
3131   register struct constant_descriptor *desc;
3132   char label[256];
3133   char *found = 0;
3134   rtx def;
3135
3136   /* If we want this CONST_DOUBLE in the same mode as it is in memory
3137      (this will always be true for floating CONST_DOUBLEs that have been
3138      placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3139      use the previous copy.  Otherwise, make a new one.  Note that in
3140      the unlikely event that this same CONST_DOUBLE is used in two different
3141      modes in an alternating fashion, we will allocate a lot of different
3142      memory locations, but this should be extremely rare.  */
3143
3144   /* Don't use CONST_DOUBLE_MEM in a nested function.
3145      Nested functions have their own constant pools,
3146      so they can't share the same values in CONST_DOUBLE_MEM
3147      with the containing function.  */
3148   if (outer_function_chain == 0)
3149     if (GET_CODE (x) == CONST_DOUBLE
3150         && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3151         && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3152       return CONST_DOUBLE_MEM (x);
3153
3154   /* Compute hash code of X.  Search the descriptors for that hash code
3155      to see if any of them describes X.  If yes, the descriptor records
3156      the label number already assigned.  */
3157
3158   hash = const_hash_rtx (mode, x);
3159
3160   for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3161     if (compare_constant_rtx (mode, x, desc))
3162       {
3163         found = desc->label;
3164         break;
3165       }
3166
3167   if (found == 0)
3168     {
3169       register struct pool_constant *pool;
3170       register struct pool_sym *sym;
3171       int align;
3172
3173       /* No constant equal to X is known to have been output.
3174          Make a constant descriptor to enter X in the hash table.
3175          Assign the label number and record it in the descriptor for
3176          future calls to this function to find.  */
3177
3178       desc = record_constant_rtx (mode, x);
3179       desc->next = const_rtx_hash_table[hash];
3180       const_rtx_hash_table[hash] = desc;
3181
3182       /* Align the location counter as required by EXP's data type.  */
3183       align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3184       if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3185         align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3186
3187       pool_offset += align - 1;
3188       pool_offset &= ~ (align - 1);
3189
3190       /* If RTL is not being placed into the saveable obstack, make a
3191          copy of X that is in the saveable obstack in case we are being
3192          called from combine or some other phase that discards memory
3193          it allocates.  We need only do this if it is a CONST, since
3194          no other RTX should be allocated in this situation. */
3195       if (rtl_obstack != saveable_obstack
3196           && GET_CODE (x) == CONST)
3197         {
3198           push_obstacks_nochange ();
3199           rtl_in_saveable_obstack ();
3200
3201           x = gen_rtx (CONST, GET_MODE (x), 
3202                        gen_rtx (PLUS, GET_MODE (x), 
3203                                 XEXP (XEXP (x, 0), 0), XEXP (XEXP (x, 0), 1)));
3204           pop_obstacks ();
3205         }
3206
3207       /* Allocate a pool constant descriptor, fill it in, and chain it in.  */
3208
3209       pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3210       pool->desc = desc;
3211       pool->constant = x;
3212       pool->mode = mode;
3213       pool->labelno = const_labelno;
3214       pool->align = align;
3215       pool->offset = pool_offset;
3216       pool->next = 0;
3217
3218       if (last_pool == 0)
3219         first_pool = pool;
3220       else
3221         last_pool->next = pool;
3222
3223       last_pool = pool;
3224       pool_offset += GET_MODE_SIZE (mode);
3225
3226       /* Create a string containing the label name, in LABEL.  */
3227       ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3228
3229       ++const_labelno;
3230
3231       desc->label = found
3232         = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3233
3234       /* Add label to symbol hash table.  */
3235       hash = SYMHASH (found);
3236       sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3237       sym->label = found;
3238       sym->pool = pool;
3239       sym->next = const_rtx_sym_hash_table[hash];
3240       const_rtx_sym_hash_table[hash] = sym;
3241     }
3242
3243   /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
3244
3245   def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3246
3247   RTX_UNCHANGING_P (def) = 1;
3248   /* Mark the symbol_ref as belonging to this constants pool.  */
3249   CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3250   current_function_uses_const_pool = 1;
3251
3252   if (outer_function_chain == 0)
3253     if (GET_CODE (x) == CONST_DOUBLE)
3254       {
3255         if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3256           {
3257             CONST_DOUBLE_CHAIN (x) = const_double_chain;
3258             const_double_chain = x;
3259           }
3260         CONST_DOUBLE_MEM (x) = def;
3261       }
3262
3263   return def;
3264 }
3265 \f
3266 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3267    the corresponding pool_constant structure.  */
3268
3269 static struct pool_constant *
3270 find_pool_constant (addr)
3271      rtx addr;
3272 {
3273   struct pool_sym *sym;
3274   char *label = XSTR (addr, 0);
3275
3276   for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3277     if (sym->label == label)
3278       return sym->pool;
3279
3280   abort ();
3281 }
3282
3283 /* Given a constant pool SYMBOL_REF, return the corresponding constant.  */
3284
3285 rtx
3286 get_pool_constant (addr)
3287      rtx addr;
3288 {
3289   return (find_pool_constant (addr))->constant;
3290 }
3291
3292 /* Similar, return the mode.  */
3293
3294 enum machine_mode
3295 get_pool_mode (addr)
3296      rtx addr;
3297 {
3298   return (find_pool_constant (addr))->mode;
3299 }
3300
3301 /* Similar, return the offset in the constant pool.  */
3302
3303 int
3304 get_pool_offset (addr)
3305      rtx addr;
3306 {
3307   return (find_pool_constant (addr))->offset;
3308 }
3309
3310 /* Return the size of the constant pool.  */
3311
3312 int
3313 get_pool_size ()
3314 {
3315   return pool_offset;
3316 }
3317 \f
3318 /* Write all the constants in the constant pool.  */
3319
3320 void
3321 output_constant_pool (fnname, fndecl)
3322      char *fnname;
3323      tree fndecl;
3324 {
3325   struct pool_constant *pool;
3326   rtx x;
3327   union real_extract u;
3328
3329 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3330   ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3331 #endif
3332
3333   for (pool = first_pool; pool; pool = pool->next)
3334     {
3335       x = pool->constant;
3336
3337       /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3338          whose CODE_LABEL has been deleted.  This can occur if a jump table
3339          is eliminated by optimization.  If so, write a constant of zero
3340          instead.  Note that this can also happen by turning the
3341          CODE_LABEL into a NOTE.  */
3342       if (((GET_CODE (x) == LABEL_REF
3343             && (INSN_DELETED_P (XEXP (x, 0))
3344                 || GET_CODE (XEXP (x, 0)) == NOTE)))
3345           || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3346               && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3347               && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3348                   || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3349         x = const0_rtx;
3350
3351       /* First switch to correct section.  */
3352 #ifdef SELECT_RTX_SECTION
3353       SELECT_RTX_SECTION (pool->mode, x);
3354 #else
3355       readonly_data_section ();
3356 #endif
3357
3358 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3359       ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3360                                      pool->align, pool->labelno, done);
3361 #endif
3362
3363       if (pool->align > 1)
3364         ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3365
3366       /* Output the label.  */
3367       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3368
3369       /* Output the value of the constant itself.  */
3370       switch (GET_MODE_CLASS (pool->mode))
3371         {
3372         case MODE_FLOAT:
3373           if (GET_CODE (x) != CONST_DOUBLE)
3374             abort ();
3375
3376           bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3377           assemble_real (u.d, pool->mode);
3378           break;
3379
3380         case MODE_INT:
3381         case MODE_PARTIAL_INT:
3382           assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3383           break;
3384
3385         default:
3386           abort ();
3387         }
3388
3389     done: ;
3390     }
3391
3392   /* Done with this pool.  */
3393   first_pool = last_pool = 0;
3394 }
3395 \f
3396 /* Find all the constants whose addresses are referenced inside of EXP,
3397    and make sure assembler code with a label has been output for each one.
3398    Indicate whether an ADDR_EXPR has been encountered.  */
3399
3400 static int
3401 output_addressed_constants (exp)
3402      tree exp;
3403 {
3404   int reloc = 0;
3405
3406   switch (TREE_CODE (exp))
3407     {
3408     case ADDR_EXPR:
3409       {
3410         register tree constant = TREE_OPERAND (exp, 0);
3411
3412         while (TREE_CODE (constant) == COMPONENT_REF)
3413           {
3414             constant = TREE_OPERAND (constant, 0);
3415           }
3416
3417         if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3418             || TREE_CODE (constant) == CONSTRUCTOR)
3419           /* No need to do anything here
3420              for addresses of variables or functions.  */
3421           output_constant_def (constant);
3422       }
3423       reloc = 1;
3424       break;
3425
3426     case PLUS_EXPR:
3427     case MINUS_EXPR:
3428       reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3429       reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3430       break;
3431
3432     case NOP_EXPR:
3433     case CONVERT_EXPR:
3434     case NON_LVALUE_EXPR:
3435       reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3436       break;
3437
3438     case CONSTRUCTOR:
3439       {
3440         register tree link;
3441         for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3442           if (TREE_VALUE (link) != 0)
3443             reloc |= output_addressed_constants (TREE_VALUE (link));
3444       }
3445       break;
3446
3447     case ERROR_MARK:
3448       break;
3449     }
3450   return reloc;
3451 }
3452 \f
3453 /* Output assembler code for constant EXP to FILE, with no label.
3454    This includes the pseudo-op such as ".int" or ".byte", and a newline.
3455    Assumes output_addressed_constants has been done on EXP already.
3456
3457    Generate exactly SIZE bytes of assembler data, padding at the end
3458    with zeros if necessary.  SIZE must always be specified.
3459
3460    SIZE is important for structure constructors,
3461    since trailing members may have been omitted from the constructor.
3462    It is also important for initialization of arrays from string constants
3463    since the full length of the string constant might not be wanted.
3464    It is also needed for initialization of unions, where the initializer's
3465    type is just one member, and that may not be as long as the union.
3466
3467    There a case in which we would fail to output exactly SIZE bytes:
3468    for a structure constructor that wants to produce more than SIZE bytes.
3469    But such constructors will never be generated for any possible input.  */
3470
3471 void
3472 output_constant (exp, size)
3473      register tree exp;
3474      register int size;
3475 {
3476   register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3477   rtx x;
3478
3479   if (size == 0)
3480     return;
3481
3482   /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3483      That way we get the constant (we hope) inside it.  Also, strip off any
3484      NOP_EXPR that converts between two record, union, array, or set types.  */
3485   while ((TREE_CODE (exp) == NOP_EXPR 
3486           && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3487               || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
3488          || TREE_CODE (exp) == NON_LVALUE_EXPR)
3489     exp = TREE_OPERAND (exp, 0);
3490
3491   /* Allow a constructor with no elements for any data type.
3492      This means to fill the space with zeros.  */
3493   if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3494     {
3495       if (output_bytecode)
3496         bc_emit_const_skip (size);
3497       else
3498         assemble_zeros (size);
3499       return;
3500     }
3501
3502   switch (code)
3503     {
3504     case CHAR_TYPE:
3505     case BOOLEAN_TYPE:
3506     case INTEGER_TYPE:
3507     case ENUMERAL_TYPE:
3508     case POINTER_TYPE:
3509     case REFERENCE_TYPE:
3510       /* ??? What about       (int)((float)(int)&foo + 4)    */
3511       while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3512              || TREE_CODE (exp) == NON_LVALUE_EXPR)
3513         exp = TREE_OPERAND (exp, 0);
3514
3515       if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3516                                            EXPAND_INITIALIZER),
3517                               size, 0))
3518         error ("initializer for integer value is too complicated");
3519       size = 0;
3520       break;
3521
3522     case REAL_TYPE:
3523       if (TREE_CODE (exp) != REAL_CST)
3524         error ("initializer for floating value is not a floating constant");
3525
3526       assemble_real (TREE_REAL_CST (exp),
3527                      mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3528       size = 0;
3529       break;
3530
3531     case COMPLEX_TYPE:
3532       output_constant (TREE_REALPART (exp), size / 2);
3533       output_constant (TREE_IMAGPART (exp), size / 2);
3534       size -= (size / 2) * 2;
3535       break;
3536
3537     case ARRAY_TYPE:
3538       if (TREE_CODE (exp) == CONSTRUCTOR)
3539         {
3540           output_constructor (exp, size);
3541           return;
3542         }
3543       else if (TREE_CODE (exp) == STRING_CST)
3544         {
3545           int excess = 0;
3546
3547           if (size > TREE_STRING_LENGTH (exp))
3548             {
3549               excess = size - TREE_STRING_LENGTH (exp);
3550               size = TREE_STRING_LENGTH (exp);
3551             }
3552
3553           assemble_string (TREE_STRING_POINTER (exp), size);
3554           size = excess;
3555         }
3556       else
3557         abort ();
3558       break;
3559
3560     case RECORD_TYPE:
3561     case UNION_TYPE:
3562       if (TREE_CODE (exp) == CONSTRUCTOR)
3563         output_constructor (exp, size);
3564       else
3565         abort ();
3566       return;
3567
3568     case SET_TYPE:
3569       if (TREE_CODE (exp) == INTEGER_CST)
3570         assemble_integer (expand_expr (exp, NULL_RTX,
3571                                        VOIDmode, EXPAND_INITIALIZER),
3572                           size, 1);
3573       else if (TREE_CODE (exp) == CONSTRUCTOR)
3574         {
3575           unsigned char *buffer = (unsigned char *) alloca (size);
3576           if (get_set_constructor_bytes (exp, buffer, size))
3577             abort ();
3578           assemble_string ((char *) buffer, size);
3579         }
3580       else
3581         error ("unknown set constructor type");
3582       return;
3583     }
3584
3585   if (size > 0)
3586     assemble_zeros (size);
3587 }
3588
3589 /* Bytecode specific code to output assembler for integer. */
3590
3591 static void
3592 bc_assemble_integer (exp, size)
3593     tree exp;
3594     int size;
3595 {
3596   tree const_part;
3597   tree addr_part;
3598   tree tmp;
3599
3600   /* FIXME: is this fold() business going to be as good as the
3601      expand_expr() using EXPAND_SUM above in the RTL case?  I
3602      hate RMS.
3603      FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3604   
3605   exp = fold (exp);
3606   
3607   while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3608     exp = TREE_OPERAND (exp, 0);
3609   if (TREE_CODE (exp) == INTEGER_CST)
3610     {
3611       const_part = exp;
3612       addr_part = 0;
3613     }
3614   else if (TREE_CODE (exp) == PLUS_EXPR)
3615     {
3616       const_part = TREE_OPERAND (exp, 0);
3617       while (TREE_CODE (const_part) == NOP_EXPR
3618              || TREE_CODE (const_part) == CONVERT_EXPR)
3619         const_part = TREE_OPERAND (const_part, 0);
3620       addr_part = TREE_OPERAND (exp, 1);
3621       while (TREE_CODE (addr_part) == NOP_EXPR
3622              || TREE_CODE (addr_part) == CONVERT_EXPR)
3623         addr_part = TREE_OPERAND (addr_part, 0);
3624       if (TREE_CODE (const_part) != INTEGER_CST)
3625         tmp = const_part, const_part = addr_part, addr_part = tmp;
3626       if (TREE_CODE (const_part) != INTEGER_CST
3627           || TREE_CODE (addr_part) != ADDR_EXPR)
3628         abort ();               /* FIXME: we really haven't considered
3629                                    all the possible cases here.  */
3630     }
3631   else if (TREE_CODE (exp) == ADDR_EXPR)
3632     {
3633       const_part = integer_zero_node;
3634       addr_part = exp;
3635     }
3636   else
3637     abort ();           /* FIXME: ditto previous.  */
3638   
3639   if (addr_part == 0)
3640     {
3641       if (size == 1)
3642         {
3643           char c = TREE_INT_CST_LOW (const_part);
3644           bc_emit (&c, 1);
3645           size -= 1;
3646         }
3647       else if (size == 2)
3648         {
3649           short s = TREE_INT_CST_LOW (const_part);
3650           bc_emit ((char *) &s, 2);
3651           size -= 2;
3652         }
3653       else if (size == 4)
3654         {
3655           int i = TREE_INT_CST_LOW (const_part);
3656           bc_emit ((char *) &i, 4);
3657           size -= 4;
3658         }
3659       else if (size == 8)
3660         {
3661           if (WORDS_BIG_ENDIAN)
3662             {
3663               int i = TREE_INT_CST_HIGH (const_part);
3664               bc_emit ((char *) &i, 4);
3665               i = TREE_INT_CST_LOW (const_part);
3666               bc_emit ((char *) &i, 4);
3667             }
3668           else
3669             {
3670               int i = TREE_INT_CST_LOW (const_part);
3671               bc_emit ((char *) &i, 4);
3672               i = TREE_INT_CST_HIGH (const_part);
3673               bc_emit ((char *) &i, 4);
3674             }
3675           size -= 8;
3676         }
3677     }
3678   else
3679     if (size == 4
3680         && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3681       bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3682                         TREE_INT_CST_LOW (const_part));
3683     else
3684       abort ();         /* FIXME: there may be more cases.  */
3685 }
3686 \f
3687 /* Subroutine of output_constant, used for CONSTRUCTORs
3688    (aggregate constants).
3689    Generate at least SIZE bytes, padding if necessary.  */
3690
3691 static void
3692 output_constructor (exp, size)
3693      tree exp;
3694      int size;
3695 {
3696   register tree link, field = 0;
3697   HOST_WIDE_INT min_index = 0;
3698   /* Number of bytes output or skipped so far.
3699      In other words, current position within the constructor.  */
3700   int total_bytes = 0;
3701   /* Non-zero means BYTE contains part of a byte, to be output.  */
3702   int byte_buffer_in_use = 0;
3703   register int byte;
3704
3705   if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3706     abort ();
3707
3708   if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3709     field = TYPE_FIELDS (TREE_TYPE (exp));
3710
3711   if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3712       && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3713     min_index
3714       = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3715
3716   /* As LINK goes through the elements of the constant,
3717      FIELD goes through the structure fields, if the constant is a structure.
3718      if the constant is a union, then we override this,
3719      by getting the field from the TREE_LIST element.
3720      But the constant could also be an array.  Then FIELD is zero.  */
3721   for (link = CONSTRUCTOR_ELTS (exp);
3722        link;
3723        link = TREE_CHAIN (link),
3724        field = field ? TREE_CHAIN (field) : 0)
3725     {
3726       tree val = TREE_VALUE (link);
3727       tree index = 0;
3728
3729       /* the element in a union constructor specifies the proper field.  */
3730
3731       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3732           || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3733         {
3734           /* if available, use the type given by link */
3735           if (TREE_PURPOSE (link) != 0)
3736             field = TREE_PURPOSE (link);
3737         }
3738
3739       if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3740         index = TREE_PURPOSE (link);
3741
3742       /* Eliminate the marker that makes a cast not be an lvalue.  */
3743       if (val != 0)
3744         STRIP_NOPS (val);
3745
3746       if (field == 0 || !DECL_BIT_FIELD (field))
3747         {
3748           /* An element that is not a bit-field.  */
3749
3750           register int fieldsize;
3751           /* Since this structure is static,
3752              we know the positions are constant.  */
3753           int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3754                                  / BITS_PER_UNIT)
3755                         : 0);
3756           if (index != 0)
3757             bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3758                       / BITS_PER_UNIT
3759                       * (TREE_INT_CST_LOW (index) - min_index));
3760
3761           /* Output any buffered-up bit-fields preceding this element.  */
3762           if (byte_buffer_in_use)
3763             {
3764               ASM_OUTPUT_BYTE (asm_out_file, byte);
3765               total_bytes++;
3766               byte_buffer_in_use = 0;
3767             }
3768
3769           /* Advance to offset of this element.
3770              Note no alignment needed in an array, since that is guaranteed
3771              if each element has the proper size.  */
3772           if ((field != 0 || index != 0) && bitpos != total_bytes)
3773             {
3774               if (!output_bytecode)
3775                 assemble_zeros (bitpos - total_bytes);
3776               else
3777                 bc_emit_const_skip (bitpos - total_bytes);
3778               total_bytes = bitpos;
3779             }
3780
3781           /* Determine size this element should occupy.  */
3782           if (field)
3783             {
3784               if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3785                 abort ();
3786               if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3787                 {
3788                   /* This avoids overflow trouble.  */
3789                   tree size_tree = size_binop (CEIL_DIV_EXPR,
3790                                                DECL_SIZE (field),
3791                                                size_int (BITS_PER_UNIT));
3792                   fieldsize = TREE_INT_CST_LOW (size_tree);
3793                 }
3794               else
3795                 {
3796                   fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3797                   fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3798                 }
3799             }
3800           else
3801             fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3802
3803           /* Output the element's initial value.  */
3804           if (val == 0)
3805             assemble_zeros (fieldsize);
3806           else
3807             output_constant (val, fieldsize);
3808
3809           /* Count its size.  */
3810           total_bytes += fieldsize;
3811         }
3812       else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3813         error ("invalid initial value for member `%s'",
3814                IDENTIFIER_POINTER (DECL_NAME (field)));
3815       else
3816         {
3817           /* Element that is a bit-field.  */
3818
3819           int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3820           int end_offset
3821             = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3822
3823           if (val == 0)
3824             val = integer_zero_node;
3825
3826           /* If this field does not start in this (or, next) byte,
3827              skip some bytes.  */
3828           if (next_offset / BITS_PER_UNIT != total_bytes)
3829             {
3830               /* Output remnant of any bit field in previous bytes.  */
3831               if (byte_buffer_in_use)
3832                 {
3833                   ASM_OUTPUT_BYTE (asm_out_file, byte);
3834                   total_bytes++;
3835                   byte_buffer_in_use = 0;
3836                 }
3837
3838               /* If still not at proper byte, advance to there.  */
3839               if (next_offset / BITS_PER_UNIT != total_bytes)
3840                 {
3841                   assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3842                   total_bytes = next_offset / BITS_PER_UNIT;
3843                 }
3844             }
3845
3846           if (! byte_buffer_in_use)
3847             byte = 0;
3848
3849           /* We must split the element into pieces that fall within
3850              separate bytes, and combine each byte with previous or
3851              following bit-fields.  */
3852
3853           /* next_offset is the offset n fbits from the beginning of
3854              the structure to the next bit of this element to be processed.
3855              end_offset is the offset of the first bit past the end of
3856              this element.  */
3857           while (next_offset < end_offset)
3858             {
3859               int this_time;
3860               int shift;
3861               HOST_WIDE_INT value;
3862               int next_byte = next_offset / BITS_PER_UNIT;
3863               int next_bit = next_offset % BITS_PER_UNIT;
3864
3865               /* Advance from byte to byte
3866                  within this element when necessary.  */
3867               while (next_byte != total_bytes)
3868                 {
3869                   ASM_OUTPUT_BYTE (asm_out_file, byte);
3870                   total_bytes++;
3871                   byte = 0;
3872                 }
3873
3874               /* Number of bits we can process at once
3875                  (all part of the same byte).  */
3876               this_time = MIN (end_offset - next_offset,
3877                                BITS_PER_UNIT - next_bit);
3878               if (BYTES_BIG_ENDIAN)
3879                 {
3880                   /* On big-endian machine, take the most significant bits
3881                      first (of the bits that are significant)
3882                      and put them into bytes from the most significant end.  */
3883                   shift = end_offset - next_offset - this_time;
3884                   /* Don't try to take a bunch of bits that cross
3885                      the word boundary in the INTEGER_CST.  */
3886                   if (shift < HOST_BITS_PER_WIDE_INT
3887                       && shift + this_time > HOST_BITS_PER_WIDE_INT)
3888                     {
3889                       this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3890                       shift = HOST_BITS_PER_WIDE_INT;
3891                     }
3892
3893                   /* Now get the bits from the appropriate constant word.  */
3894                   if (shift < HOST_BITS_PER_WIDE_INT)
3895                     {
3896                       value = TREE_INT_CST_LOW (val);
3897                     }
3898                   else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3899                     {
3900                       value = TREE_INT_CST_HIGH (val);
3901                       shift -= HOST_BITS_PER_WIDE_INT;
3902                     }
3903                   else
3904                     abort ();
3905                   byte |= (((value >> shift)
3906                             & (((HOST_WIDE_INT) 1 << this_time) - 1))
3907                            << (BITS_PER_UNIT - this_time - next_bit));
3908                 }
3909               else
3910                 {
3911                   /* On little-endian machines,
3912                      take first the least significant bits of the value
3913                      and pack them starting at the least significant
3914                      bits of the bytes.  */
3915                   shift = (next_offset
3916                            - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3917                   /* Don't try to take a bunch of bits that cross
3918                      the word boundary in the INTEGER_CST.  */
3919                   if (shift < HOST_BITS_PER_WIDE_INT
3920                       && shift + this_time > HOST_BITS_PER_WIDE_INT)
3921                     {
3922                       this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3923                       shift = HOST_BITS_PER_WIDE_INT;
3924                     }
3925
3926                   /* Now get the bits from the appropriate constant word.  */
3927                   if (shift < HOST_BITS_PER_INT)
3928                     value = TREE_INT_CST_LOW (val);
3929                   else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3930                     {
3931                       value = TREE_INT_CST_HIGH (val);
3932                       shift -= HOST_BITS_PER_WIDE_INT;
3933                     }
3934                   else
3935                     abort ();
3936                   byte |= (((value >> shift)
3937                             & (((HOST_WIDE_INT) 1 << this_time) - 1))
3938                            << next_bit);
3939                 }
3940               next_offset += this_time;
3941               byte_buffer_in_use = 1;
3942             }
3943         }
3944     }
3945   if (byte_buffer_in_use)
3946     {
3947       ASM_OUTPUT_BYTE (asm_out_file, byte);
3948       total_bytes++;
3949     }
3950   if (total_bytes < size)
3951     assemble_zeros (size - total_bytes);
3952 }
3953
3954 /* Output asm to handle ``#pragma weak'' */
3955 void
3956 handle_pragma_weak (what, name, value)
3957      enum pragma_state what;
3958      char *name, *value;
3959 {
3960 #ifdef HANDLE_PRAGMA_WEAK
3961   if (what == ps_name || what == ps_value)
3962     {
3963       struct weak_syms *weak =
3964         (struct weak_syms *)permalloc (sizeof (struct weak_syms));
3965       weak->next = weak_decls;
3966       weak->name = permalloc (strlen (name) + 1);
3967       strcpy (weak->name, name);
3968
3969       if (what != ps_value)
3970         weak->value = NULL_PTR;
3971
3972       else
3973         {
3974           weak->value = permalloc (strlen (value) + 1);
3975           strcpy (weak->value, value);
3976         }
3977
3978       weak_decls = weak;
3979     }
3980   else if (! (what == ps_done || what == ps_start))
3981     warning ("malformed `#pragma weak'");
3982 #endif /* HANDLE_PRAGMA_WEAK */
3983 }
3984
3985 /* Declare DECL to be a weak symbol.  */
3986
3987 void
3988 declare_weak (decl)
3989      tree decl;
3990 {
3991   if (! TREE_PUBLIC (decl))
3992     error_with_decl (decl, "weak declaration of `%s' must be public");
3993   else if (TREE_ASM_WRITTEN (decl))
3994     error_with_decl (decl, "weak declaration of `%s' must precede definition");
3995   else if (SUPPORTS_WEAK)
3996     DECL_WEAK (decl) = 1;
3997 }
3998
3999 /* Emit any pending weak declarations.  */
4000
4001 void
4002 weak_finish ()
4003 {
4004 #ifdef HANDLE_PRAGMA_WEAK
4005   if (HANDLE_PRAGMA_WEAK)
4006     {
4007       struct weak_syms *t;
4008       for (t = weak_decls; t; t = t->next)
4009         {
4010           ASM_WEAKEN_LABEL (asm_out_file, t->name);
4011           if (t->value)
4012             ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4013         }
4014     }
4015 #endif
4016 }
4017
4018 void
4019 assemble_alias (decl, target)
4020      tree decl, target;
4021 {
4022 #ifdef ASM_OUTPUT_DEF
4023   char *name;
4024
4025   make_decl_rtl (decl, (char*)0, 1);
4026   name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4027
4028   /* Make name accessible from other files, if appropriate.  */
4029
4030   if (TREE_PUBLIC (decl))
4031     {
4032 #ifdef ASM_WEAKEN_LABEL
4033       if (DECL_WEAK (decl))
4034         ASM_WEAKEN_LABEL (asm_out_file, name);
4035       else
4036 #endif
4037       if (output_bytecode)
4038         BC_GLOBALIZE_LABEL (asm_out_file, name);
4039       else
4040         ASM_GLOBALIZE_LABEL (asm_out_file, name);
4041     }
4042
4043   ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4044   TREE_ASM_WRITTEN (decl) = 1;
4045 #else
4046   warning ("alias definitions not supported in this configuration");
4047 #endif
4048 }