OSDN Git Service

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