OSDN Git Service

(output_constant_def_contents): New function.
[pf3gnuchains/gcc-fork.git] / gcc / varasm.c
1 /* Output variables, constants and external declarations, for GNU compiler.
2    Copyright (C) 1987, 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20
21 /* This file handles generation of all the assembler code
22    *except* the instructions of a function.
23    This includes declarations of variables and their initial values.
24
25    We also output the assembler code for constants stored in memory
26    and are responsible for combining constants with the same value.  */
27
28 #include <stdio.h>
29 #include <setjmp.h>
30 /* #include <stab.h> */
31 #include "config.h"
32 #include "rtl.h"
33 #include "tree.h"
34 #include "flags.h"
35 #include "function.h"
36 #include "expr.h"
37 #include "hard-reg-set.h"
38 #include "regs.h"
39 #include "defaults.h"
40 #include "real.h"
41
42 #include "obstack.h"
43
44 #ifdef XCOFF_DEBUGGING_INFO
45 #include "xcoffout.h"
46 #endif
47
48 #include <ctype.h>
49
50 #ifndef ASM_STABS_OP
51 #define ASM_STABS_OP ".stabs"
52 #endif
53
54 /* This macro gets just the user-specified name
55    out of the string in a SYMBOL_REF.  On most machines,
56    we discard the * if any and that's all.  */
57 #ifndef STRIP_NAME_ENCODING
58 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
59   (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
60 #endif
61
62 /* File in which assembler code is being written.  */
63
64 extern FILE *asm_out_file;
65
66 /* The (assembler) name of the first globally-visible object output.  */
67 char *first_global_object_name;
68
69 extern struct obstack *current_obstack;
70 extern struct obstack *saveable_obstack;
71 extern struct obstack permanent_obstack;
72 #define obstack_chunk_alloc xmalloc
73
74 /* Number for making the label on the next
75    constant that is stored in memory.  */
76
77 int const_labelno;
78
79 /* Number for making the label on the next
80    static variable internal to a function.  */
81
82 int var_labelno;
83
84 /* Nonzero if at least one function definition has been seen.  */
85 static int function_defined;
86
87 extern FILE *asm_out_file;
88
89 static char *compare_constant_1 ();
90 static void record_constant_1 ();
91 static void output_constant_def_contents ();
92
93 void output_constant_pool ();
94 void assemble_name ();
95 int output_addressed_constants ();
96 void output_constant ();
97 void output_constructor ();
98 void text_section ();
99 void readonly_data_section ();
100 void data_section ();
101 \f
102 #ifdef EXTRA_SECTIONS
103 static enum in_section {no_section, in_text, in_data, EXTRA_SECTIONS} in_section
104   = no_section;
105 #else
106 static enum in_section {no_section, in_text, in_data} in_section
107   = no_section;
108 #endif
109
110 /* Define functions like text_section for any extra sections.  */
111 #ifdef EXTRA_SECTION_FUNCTIONS
112 EXTRA_SECTION_FUNCTIONS
113 #endif
114
115 /* Tell assembler to switch to text section.  */
116
117 void
118 text_section ()
119 {
120   if (in_section != in_text)
121     {
122       fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
123       in_section = in_text;
124     }
125 }
126
127 /* Tell assembler to switch to data section.  */
128
129 void
130 data_section ()
131 {
132   if (in_section != in_data)
133     {
134       if (flag_shared_data)
135         {
136 #ifdef SHARED_SECTION_ASM_OP
137           fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
138 #else
139           fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
140 #endif
141         }
142       else
143         fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
144
145       in_section = in_data;
146     }
147 }
148
149 /* Tell assembler to switch to read-only data section.  This is normally
150    the text section.  */
151
152 void
153 readonly_data_section ()
154 {
155 #ifdef READONLY_DATA_SECTION
156   READONLY_DATA_SECTION ();  /* Note this can call data_section.  */
157 #else
158   text_section ();
159 #endif
160 }
161
162 /* Determine if we're in the text section. */
163
164 int
165 in_text_section ()
166 {
167   return in_section == in_text;
168 }
169 \f
170 /* Create the rtl to represent a function, for a function definition.
171    DECL is a FUNCTION_DECL node which describes which function.
172    The rtl is stored into DECL.  */
173
174 void
175 make_function_rtl (decl)
176      tree decl;
177 {
178   char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
179
180   /* Rename a nested function to avoid conflicts.  */
181   if (decl_function_context (decl) != 0
182       && DECL_INITIAL (decl) != 0
183       && DECL_RTL (decl) == 0)
184     {
185       char *label;
186
187       name = IDENTIFIER_POINTER (DECL_NAME (decl));
188       ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
189       name = obstack_copy0 (saveable_obstack, label, strlen (label));
190       var_labelno++;
191     }
192
193   if (DECL_RTL (decl) == 0)
194     {
195       DECL_RTL (decl)
196         = gen_rtx (MEM, DECL_MODE (decl),
197                    gen_rtx (SYMBOL_REF, Pmode, name));
198
199       /* Optionally set flags or add text to the name to record information
200          such as that it is a function name.  If the name is changed, the macro
201          ASM_OUTPUT_LABELREF will have to know how to strip this information.
202          And if it finds a * at the beginning after doing so, it must handle
203          that too.  */
204 #ifdef ENCODE_SECTION_INFO
205       ENCODE_SECTION_INFO (decl);
206 #endif
207     }
208
209   /* Record at least one function has been defined.  */
210   function_defined = 1;
211 }
212
213 /* Given NAME, a putative register name, discard any customary prefixes.  */
214
215 static char *
216 strip_reg_name (name)
217      char *name;
218 {
219 #ifdef REGISTER_PREFIX
220   if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
221     name += strlen (REGISTER_PREFIX);
222 #endif
223   if (name[0] == '%' || name[0] == '#')
224     name++;
225   return name;
226 }
227 \f
228 /* Decode an `asm' spec for a declaration as a register name.
229    Return the register number, or -1 if nothing specified,
230    or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
231    or -3 if ASMSPEC is `cc' and is not recognized,
232    or -4 if ASMSPEC is `memory' and is not recognized.
233    Accept an exact spelling or a decimal number.
234    Prefixes such as % are optional.  */
235
236 int
237 decode_reg_name (asmspec)
238      char *asmspec;
239 {
240   if (asmspec != 0)
241     {
242       int i;
243
244       /* Get rid of confusing prefixes.  */
245       asmspec = strip_reg_name (asmspec);
246         
247       /* Allow a decimal number as a "register name".  */
248       for (i = strlen (asmspec) - 1; i >= 0; i--)
249         if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
250           break;
251       if (asmspec[0] != 0 && i < 0)
252         {
253           i = atoi (asmspec);
254           if (i < FIRST_PSEUDO_REGISTER && i >= 0)
255             return i;
256           else
257             return -2;
258         }
259
260       for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
261         if (reg_names[i][0]
262             && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
263           return i;
264
265 #ifdef ADDITIONAL_REGISTER_NAMES
266       {
267         static struct { char *name; int number; } table[]
268           = ADDITIONAL_REGISTER_NAMES;
269
270         for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
271           if (! strcmp (asmspec, table[i].name))
272             return table[i].number;
273       }
274 #endif /* ADDITIONAL_REGISTER_NAMES */
275
276       if (!strcmp (asmspec, "memory"))
277         return -4;
278
279       if (!strcmp (asmspec, "cc"))
280         return -3;
281
282       return -2;
283     }
284
285   return -1;
286 }
287 \f
288 /* Create the DECL_RTL for a declaration for a static or external variable
289    or static or external function.
290    ASMSPEC, if not 0, is the string which the user specified
291    as the assembler symbol name.
292    TOP_LEVEL is nonzero if this is a file-scope variable.
293
294    This is never called for PARM_DECL nodes.  */
295
296 void
297 make_decl_rtl (decl, asmspec, top_level)
298      tree decl;
299      char *asmspec;
300      int top_level;
301 {
302   register char *name;
303   int reg_number = decode_reg_name (asmspec);
304
305   if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
306     name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
307
308   if (reg_number == -2)
309     {
310       /* ASMSPEC is given, and not the name of a register.  */
311       name = (char *) obstack_alloc (saveable_obstack,
312                                      strlen (asmspec) + 2);
313       name[0] = '*';
314       strcpy (&name[1], asmspec);
315     }
316
317   /* For a duplicate declaration, we can be called twice on the
318      same DECL node.  Don't discard the RTL already made.  */
319   if (DECL_RTL (decl) == 0)
320     {
321       DECL_RTL (decl) = 0;
322
323       /* First detect errors in declaring global registers.  */
324       if (DECL_REGISTER (decl) && reg_number == -1)
325         error_with_decl (decl,
326                          "register name not specified for `%s'");
327       else if (DECL_REGISTER (decl) && reg_number < 0)
328         error_with_decl (decl,
329                          "invalid register name for `%s'");
330       else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
331         error_with_decl (decl,
332                          "register name given for non-register variable `%s'");
333       else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
334         error ("function declared `register'");
335       else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
336         error_with_decl (decl, "data type of `%s' isn't suitable for a register");
337       else if (DECL_REGISTER (decl)
338                && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
339         error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
340       /* Now handle properly declared static register variables.  */
341       else if (DECL_REGISTER (decl))
342         {
343           int nregs;
344 #if 0 /* yylex should print the warning for this */
345           if (pedantic)
346             pedwarn ("ANSI C forbids global register variables");
347 #endif
348           if (DECL_INITIAL (decl) != 0 && top_level)
349             {
350               DECL_INITIAL (decl) = 0;
351               error ("global register variable has initial value");
352             }
353           if (fixed_regs[reg_number] == 0
354               && function_defined && top_level)
355             error ("global register variable follows a function definition");
356           if (TREE_THIS_VOLATILE (decl))
357             warning ("volatile register variables don't work as you might wish");
358
359           /* If the user specified one of the eliminables registers here,
360              e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
361              confused with that register and be eliminated.  Although this
362              usage is somewhat suspect, we nevertheless use the following
363              kludge to avoid setting DECL_RTL to frame_pointer_rtx.  */
364
365           DECL_RTL (decl)
366             = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
367           REGNO (DECL_RTL (decl)) = reg_number;
368           REG_USERVAR_P (DECL_RTL (decl)) = 1;
369
370           if (top_level)
371             {
372               /* Make this register fixed, so not usable for anything else.  */
373               nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
374               while (nregs > 0)
375                 global_regs[reg_number + --nregs] = 1;
376               init_reg_sets_1 ();
377             }
378         }
379
380       /* Now handle ordinary static variables and functions (in memory).
381          Also handle vars declared register invalidly.  */
382       if (DECL_RTL (decl) == 0)
383         {
384           /* Can't use just the variable's own name for a variable
385              whose scope is less than the whole file.
386              Concatenate a distinguishing number.  */
387           if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
388             {
389               char *label;
390
391               ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
392               name = obstack_copy0 (saveable_obstack, label, strlen (label));
393               var_labelno++;
394             }
395
396           DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
397                                      gen_rtx (SYMBOL_REF, Pmode, name));
398           if (TREE_THIS_VOLATILE (decl)
399             || (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
400                 && TREE_PUBLIC (decl)))
401             MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
402           if (TREE_READONLY (decl))
403             RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
404           MEM_IN_STRUCT_P (DECL_RTL (decl))
405             = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
406                || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
407                || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
408                || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE);
409
410           /* Optionally set flags or add text to the name to record information
411              such as that it is a function name.
412              If the name is changed, the macro ASM_OUTPUT_LABELREF
413              will have to know how to strip this information.
414              And if it finds a * at the beginning after doing so,
415              it must handle that too.  */
416 #ifdef ENCODE_SECTION_INFO
417           ENCODE_SECTION_INFO (decl);
418 #endif
419         }
420     }
421   /* If the old RTL had the wrong mode, fix the mode.  */
422   else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
423     {
424       rtx rtl = DECL_RTL (decl);
425       PUT_MODE (rtl, DECL_MODE (decl));
426     }
427 }
428
429 /* Make the rtl for variable VAR be volatile.
430    Use this only for static variables.  */
431
432 void
433 make_var_volatile (var)
434      tree var;
435 {
436   if (GET_CODE (DECL_RTL (var)) != MEM)
437     abort ();
438
439   MEM_VOLATILE_P (DECL_RTL (var)) = 1;
440 }
441 \f
442 /* Output alignment directive to align for constant expression EXP.  */
443
444 void
445 assemble_constant_align (exp)
446      tree exp;
447 {
448   int align;
449
450   /* Align the location counter as required by EXP's data type.  */
451   align = TYPE_ALIGN (TREE_TYPE (exp));
452 #ifdef CONSTANT_ALIGNMENT
453   align = CONSTANT_ALIGNMENT (exp, align);
454 #endif
455
456   if (align > BITS_PER_UNIT)
457     ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
458 }
459
460 /* Output a string of literal assembler code
461    for an `asm' keyword used between functions.  */
462
463 void
464 assemble_asm (string)
465      tree string;
466 {
467   app_enable ();
468
469   if (TREE_CODE (string) == ADDR_EXPR)
470     string = TREE_OPERAND (string, 0);
471
472   fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
473 }
474
475 #if 0 /* This should no longer be needed, because
476          flag_gnu_linker should be 0 on these systems,
477          which should prevent any output
478          if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent.  */
479 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
480 #ifndef ASM_OUTPUT_CONSTRUCTOR
481 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
482 #endif
483 #ifndef ASM_OUTPUT_DESTRUCTOR
484 #define ASM_OUTPUT_DESTRUCTOR(file, name)
485 #endif
486 #endif
487 #endif /* 0 */
488
489 /* Record an element in the table of global destructors.
490    How this is done depends on what sort of assembler and linker
491    are in use.
492
493    NAME should be the name of a global function to be called
494    at exit time.  This name is output using assemble_name.  */
495
496 void
497 assemble_destructor (name)
498      char *name;
499 {
500 #ifdef ASM_OUTPUT_DESTRUCTOR
501   ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
502 #else
503   if (flag_gnu_linker)
504     {
505       /* Now tell GNU LD that this is part of the static destructor set.  */
506       /* This code works for any machine provided you use GNU as/ld.  */
507       fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
508       assemble_name (asm_out_file, name);
509       fputc ('\n', asm_out_file);
510     }
511 #endif
512 }
513
514 /* Likewise for global constructors.  */
515
516 void
517 assemble_constructor (name)
518      char *name;
519 {
520 #ifdef ASM_OUTPUT_CONSTRUCTOR
521   ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
522 #else
523   if (flag_gnu_linker)
524     {
525       /* Now tell GNU LD that this is part of the static constructor set.  */
526       /* This code works for any machine provided you use GNU as/ld.  */
527       fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
528       assemble_name (asm_out_file, name);
529       fputc ('\n', asm_out_file);
530     }
531 #endif
532 }
533
534 /* Likewise for entries we want to record for garbage collection.
535    Garbage collection is still under development.  */
536
537 void
538 assemble_gc_entry (name)
539      char *name;
540 {
541 #ifdef ASM_OUTPUT_GC_ENTRY
542   ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
543 #else
544   if (flag_gnu_linker)
545     {
546       /* Now tell GNU LD that this is part of the static constructor set.  */
547       fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
548       assemble_name (asm_out_file, name);
549       fputc ('\n', asm_out_file);
550     }
551 #endif
552 }
553 \f
554 /* Output assembler code for the constant pool of a function and associated
555    with defining the name of the function.  DECL describes the function.
556    NAME is the function's name.  For the constant pool, we use the current
557    constant pool data.  */
558
559 void
560 assemble_start_function (decl, fnname)
561      tree decl;
562      char *fnname;
563 {
564   int align;
565
566   /* The following code does not need preprocessing in the assembler.  */
567
568   app_disable ();
569
570   output_constant_pool (fnname, decl);
571
572   text_section ();
573
574
575   /* Tell assembler to move to target machine's alignment for functions.  */
576   align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
577   if (align > 0)
578     ASM_OUTPUT_ALIGN (asm_out_file, align);
579
580 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
581   ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
582 #endif
583
584 #ifdef SDB_DEBUGGING_INFO
585   /* Output SDB definition of the function.  */
586   if (write_symbols == SDB_DEBUG)
587     sdbout_mark_begin_function ();
588 #endif
589
590 #ifdef DBX_DEBUGGING_INFO
591   /* Output DBX definition of the function.  */
592   if (write_symbols == DBX_DEBUG)
593     dbxout_begin_function (decl);
594 #endif
595
596   /* Make function name accessible from other files, if appropriate.  */
597
598   if (TREE_PUBLIC (decl))
599     {
600       if (!first_global_object_name)
601         STRIP_NAME_ENCODING (first_global_object_name, fnname);
602       ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
603     }
604
605   /* Do any machine/system dependent processing of the function name */
606 #ifdef ASM_DECLARE_FUNCTION_NAME
607   ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
608 #else
609   /* Standard thing is just output label for the function.  */
610   ASM_OUTPUT_LABEL (asm_out_file, fnname);
611 #endif /* ASM_DECLARE_FUNCTION_NAME */
612 }
613
614 /* Output assembler code associated with defining the size of the
615    function.  DECL describes the function.  NAME is the function's name.  */
616
617 void
618 assemble_end_function (decl, fnname)
619      tree decl;
620      char *fnname;
621 {
622 #ifdef ASM_DECLARE_FUNCTION_SIZE
623   ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
624 #endif
625 }
626 \f
627 /* Assemble code to leave SIZE bytes of zeros.  */
628
629 void
630 assemble_zeros (size)
631      int size;
632 {
633 #ifdef ASM_NO_SKIP_IN_TEXT
634   /* The `space' pseudo in the text section outputs nop insns rather than 0s,
635      so we must output 0s explicitly in the text section.  */
636   if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
637     {
638       int i;
639
640       for (i = 0; i < size - 20; i += 20)
641         {
642 #ifdef ASM_BYTE_OP
643           fprintf (asm_out_file,
644                    "%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);
645 #else
646           fprintf (asm_out_file,
647                    "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
648 #endif
649         }
650       if (i < size)
651         {
652 #ifdef ASM_BYTE_OP
653           fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
654 #else
655           fprintf (asm_out_file, "\tbyte 0");
656 #endif
657           i++;
658           for (; i < size; i++)
659             fprintf (asm_out_file, ",0");
660           fprintf (asm_out_file, "\n");
661         }
662     }
663   else
664 #endif
665     if (size > 0)
666       ASM_OUTPUT_SKIP (asm_out_file, size);
667 }
668
669 /* Assemble a string constant with the specified C string as contents.  */
670
671 void
672 assemble_string (p, size)
673      char *p;
674      int size;
675 {
676   register int i;
677   int pos = 0;
678   int maximum = 2000;
679
680   /* If the string is very long, split it up.  */
681
682   while (pos < size)
683     {
684       int thissize = size - pos;
685       if (thissize > maximum)
686         thissize = maximum;
687
688       ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
689
690       pos += thissize;
691       p += thissize;
692     }
693 }
694 \f
695 /* Assemble everything that is needed for a variable or function declaration.
696    Not used for automatic variables, and not used for function definitions.
697    Should not be called for variables of incomplete structure type.
698
699    TOP_LEVEL is nonzero if this variable has file scope.
700    AT_END is nonzero if this is the special handling, at end of compilation,
701    to define things that have had only tentative definitions.
702    DONT_OUTPUT_DATA if nonzero means don't actually output the
703    initial value (that will be done by the caller).  */
704
705 void
706 assemble_variable (decl, top_level, at_end, dont_output_data)
707      tree decl;
708      int top_level;
709      int at_end;
710 {
711   register char *name;
712   int align;
713   tree size_tree;
714   int reloc = 0;
715   enum in_section saved_in_section;
716
717   if (GET_CODE (DECL_RTL (decl)) == REG)
718     {
719       /* Do output symbol info for global register variables, but do nothing
720          else for them.  */
721
722       if (TREE_ASM_WRITTEN (decl))
723         return;
724       TREE_ASM_WRITTEN (decl) = 1;
725
726 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
727       /* File-scope global variables are output here.  */
728       if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
729           && top_level)
730         dbxout_symbol (decl, 0);
731 #endif
732 #ifdef SDB_DEBUGGING_INFO
733       if (write_symbols == SDB_DEBUG && top_level
734           /* Leave initialized global vars for end of compilation;
735              see comment in compile_file.  */
736           && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
737         sdbout_symbol (decl, 0);
738 #endif
739
740       /* Don't output any DWARF debugging information for variables here.
741          In the case of local variables, the information for them is output
742          when we do our recursive traversal of the tree representation for
743          the entire containing function.  In the case of file-scope variables,
744          we output information for all of them at the very end of compilation
745          while we are doing our final traversal of the chain of file-scope
746          declarations.  */
747
748       return;
749     }
750
751   /* Normally no need to say anything here for external references,
752      since assemble_external is called by the langauge-specific code
753      when a declaration is first seen.  */
754
755   if (DECL_EXTERNAL (decl))
756     return;
757
758   /* Output no assembler code for a function declaration.
759      Only definitions of functions output anything.  */
760
761   if (TREE_CODE (decl) == FUNCTION_DECL)
762     return;
763
764   /* If type was incomplete when the variable was declared,
765      see if it is complete now.  */
766
767   if (DECL_SIZE (decl) == 0)
768     layout_decl (decl, 0);
769
770   /* Still incomplete => don't allocate it; treat the tentative defn
771      (which is what it must have been) as an `extern' reference.  */
772
773   if (!dont_output_data && DECL_SIZE (decl) == 0)
774     {
775       error_with_file_and_line (DECL_SOURCE_FILE (decl),
776                                 DECL_SOURCE_LINE (decl),
777                                 "storage size of `%s' isn't known",
778                                 IDENTIFIER_POINTER (DECL_NAME (decl)));
779       return;
780     }
781
782   /* The first declaration of a variable that comes through this function
783      decides whether it is global (in C, has external linkage)
784      or local (in C, has internal linkage).  So do nothing more
785      if this function has already run.  */
786
787   if (TREE_ASM_WRITTEN (decl))
788     return;
789
790   TREE_ASM_WRITTEN (decl) = 1;
791
792   /* If storage size is erroneously variable, just continue.
793      Error message was already made.  */
794
795   if (DECL_SIZE (decl))
796     {
797       if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
798         goto finish;
799
800       app_disable ();
801
802       /* This is better than explicit arithmetic, since it avoids overflow.  */
803       size_tree = size_binop (CEIL_DIV_EXPR,
804                               DECL_SIZE (decl), size_int (BITS_PER_UNIT));
805
806       if (TREE_INT_CST_HIGH (size_tree) != 0)
807         {
808           error_with_decl (decl, "size of variable `%s' is too large");
809           goto finish;
810         }
811     }
812
813   name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
814
815   /* Handle uninitialized definitions.  */
816
817   /* ANSI specifies that a tentative definition which is not merged with
818      a non-tentative definition behaves exactly like a definition with an
819      initializer equal to zero.  (Section 3.7.2)
820      -fno-common gives strict ANSI behavior.  Usually you don't want it.  */
821   if (! flag_no_common
822       && ! dont_output_data
823       && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
824     {
825       int size = TREE_INT_CST_LOW (size_tree);
826       int rounded = size;
827
828       if (TREE_INT_CST_HIGH (size_tree) != 0)
829         error_with_decl (decl, "size of variable `%s' is too large");
830       /* Don't allocate zero bytes of common,
831          since that means "undefined external" in the linker.  */
832       if (size == 0) rounded = 1;
833       /* Round size up to multiple of BIGGEST_ALIGNMENT bits
834          so that each uninitialized object starts on such a boundary.  */
835       rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
836       rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
837                  * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
838
839 #ifdef DBX_DEBUGGING_INFO
840       /* File-scope global variables are output here.  */
841       if (write_symbols == DBX_DEBUG && top_level)
842         dbxout_symbol (decl, 0);
843 #endif
844 #ifdef SDB_DEBUGGING_INFO
845       if (write_symbols == SDB_DEBUG && top_level
846           /* Leave initialized global vars for end of compilation;
847              see comment in compile_file.  */
848           && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
849         sdbout_symbol (decl, 0);
850 #endif
851
852       /* Don't output any DWARF debugging information for variables here.
853          In the case of local variables, the information for them is output
854          when we do our recursive traversal of the tree representation for
855          the entire containing function.  In the case of file-scope variables,
856          we output information for all of them at the very end of compilation
857          while we are doing our final traversal of the chain of file-scope
858          declarations.  */
859
860 #if 0
861       if (flag_shared_data)
862         data_section ();
863 #endif
864       if (TREE_PUBLIC (decl))
865         {
866 #ifdef ASM_OUTPUT_SHARED_COMMON
867           if (flag_shared_data)
868             ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
869           else
870 #endif
871 #ifdef ASM_OUTPUT_ALIGNED_COMMON
872             ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
873                                        DECL_ALIGN (decl));
874 #else
875             ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
876 #endif
877         }
878       else
879         {
880 #ifdef ASM_OUTPUT_SHARED_LOCAL
881           if (flag_shared_data)
882             ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
883           else
884 #endif
885 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
886             ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
887                                       DECL_ALIGN (decl));
888 #else
889             ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
890 #endif
891         }
892       goto finish;
893     }
894
895   /* Handle initialized definitions.  */
896
897   /* First make the assembler name(s) global if appropriate.  */
898   if (TREE_PUBLIC (decl) && DECL_NAME (decl))
899     {
900       if (!first_global_object_name)
901         STRIP_NAME_ENCODING(first_global_object_name, name);
902       ASM_GLOBALIZE_LABEL (asm_out_file, name);
903     }
904 #if 0
905   for (d = equivalents; d; d = TREE_CHAIN (d))
906     {
907       tree e = TREE_VALUE (d);
908       if (TREE_PUBLIC (e) && DECL_NAME (e))
909         ASM_GLOBALIZE_LABEL (asm_out_file,
910                              XSTR (XEXP (DECL_RTL (e), 0), 0));
911     }
912 #endif
913
914   /* Output any data that we will need to use the address of.  */
915   if (DECL_INITIAL (decl))
916     reloc = output_addressed_constants (DECL_INITIAL (decl));
917
918   /* Switch to the proper section for this data.  */
919 #ifdef SELECT_SECTION
920   SELECT_SECTION (decl, reloc);
921 #else
922   if (TREE_READONLY (decl)
923       && ! TREE_THIS_VOLATILE (decl)
924       && ! (flag_pic && reloc))
925     readonly_data_section ();
926   else
927     data_section ();
928 #endif
929
930   /* Record current section so we can restore it if dbxout.c clobbers it.  */
931   saved_in_section = in_section;
932
933   /* Output the dbx info now that we have chosen the section.  */
934
935 #ifdef DBX_DEBUGGING_INFO
936   /* File-scope global variables are output here.  */
937   if (write_symbols == DBX_DEBUG && top_level)
938     dbxout_symbol (decl, 0);
939 #endif
940 #ifdef SDB_DEBUGGING_INFO
941   if (write_symbols == SDB_DEBUG && top_level
942       /* Leave initialized global vars for end of compilation;
943          see comment in compile_file.  */
944       && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
945     sdbout_symbol (decl, 0);
946 #endif
947
948   /* Don't output any DWARF debugging information for variables here.
949      In the case of local variables, the information for them is output
950      when we do our recursive traversal of the tree representation for
951      the entire containing function.  In the case of file-scope variables,
952      we output information for all of them at the very end of compilation
953      while we are doing our final traversal of the chain of file-scope
954      declarations.  */
955
956   if (in_section != saved_in_section)
957     {
958       /* Switch to the proper section for this data.  */
959 #ifdef SELECT_SECTION
960       SELECT_SECTION (decl, reloc);
961 #else
962       if (TREE_READONLY (decl)
963           && ! TREE_THIS_VOLATILE (decl)
964           && ! (flag_pic && reloc))
965         readonly_data_section ();
966       else
967         data_section ();
968 #endif
969     }
970
971   /* Compute and output the alignment of this data.  */
972
973   align = DECL_ALIGN (decl);
974   /* Some object file formats have a maximum alignment which they support.
975      In particular, a.out format supports a maximum alignment of 4.  */
976 #ifndef MAX_OFILE_ALIGNMENT
977 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
978 #endif
979   if (align > MAX_OFILE_ALIGNMENT)
980     {
981       warning_with_decl (decl,
982           "alignment of `%s' is greater than maximum object file alignment");
983       align = MAX_OFILE_ALIGNMENT;
984     }
985 #ifdef DATA_ALIGNMENT
986   /* On some machines, it is good to increase alignment sometimes.  */
987   align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
988 #endif
989 #ifdef CONSTANT_ALIGNMENT
990   if (DECL_INITIAL (decl))
991     align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
992 #endif
993
994   /* Reset the alignment in case we have made it tighter, so we can benefit
995      from it in get_pointer_alignment.  */
996   DECL_ALIGN (decl) = align;
997
998   if (align > BITS_PER_UNIT)
999     ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1000
1001   /* Do any machine/system dependent processing of the object.  */
1002 #ifdef ASM_DECLARE_OBJECT_NAME
1003   ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1004 #else
1005   /* Standard thing is just output label for the object.  */
1006   ASM_OUTPUT_LABEL (asm_out_file, name);
1007 #endif /* ASM_DECLARE_OBJECT_NAME */
1008
1009   if (!dont_output_data)
1010     {
1011       if (DECL_INITIAL (decl))
1012         /* Output the actual data.  */
1013         output_constant (DECL_INITIAL (decl),
1014                          int_size_in_bytes (TREE_TYPE (decl)));
1015       else
1016         /* Leave space for it.  */
1017         assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1018     }
1019
1020  finish:
1021 #ifdef XCOFF_DEBUGGING_INFO
1022   /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1023      declaration.  When something like ".stabx  "aa:S-2",aa,133,0" is emitted 
1024      and `aa' hasn't been output yet, the assembler generates a stab entry with
1025      a value of zero, in addition to creating an unnecessary external entry
1026      for `aa'.  Hence, we must postpone dbxout_symbol to here at the end.  */
1027
1028   /* File-scope global variables are output here.  */
1029   if (write_symbols == XCOFF_DEBUG && top_level)
1030     dbxout_symbol (decl, 0);
1031 #else
1032   /* There must be a statement after a label.  */
1033   ;
1034 #endif
1035 }
1036
1037 /* Output something to declare an external symbol to the assembler.
1038    (Most assemblers don't need this, so we normally output nothing.)
1039    Do nothing if DECL is not external.  */
1040
1041 void
1042 assemble_external (decl)
1043      tree decl;
1044 {
1045 #ifdef ASM_OUTPUT_EXTERNAL
1046   if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1047       && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1048     {
1049       rtx rtl = DECL_RTL (decl);
1050
1051       if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1052           && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1053         {
1054           /* Some systems do require some output.  */
1055           SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1056           ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1057         }
1058     }
1059 #endif
1060 }
1061
1062 /* Similar, for calling a library function FUN.  */
1063
1064 void
1065 assemble_external_libcall (fun)
1066      rtx fun;
1067 {
1068 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1069   /* Declare library function name external when first used, if nec.  */
1070   if (! SYMBOL_REF_USED (fun))
1071     {
1072       SYMBOL_REF_USED (fun) = 1;
1073       ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1074     }
1075 #endif
1076 }
1077
1078 /* Declare the label NAME global.  */
1079
1080 void
1081 assemble_global (name)
1082      char *name;
1083 {
1084   ASM_GLOBALIZE_LABEL (asm_out_file, name);
1085 }
1086
1087 /* Assemble a label named NAME.  */
1088
1089 void
1090 assemble_label (name)
1091      char *name;
1092 {
1093   ASM_OUTPUT_LABEL (asm_out_file, name);
1094 }
1095
1096 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1097    If NAME starts with a *, the rest of NAME is output verbatim.
1098    Otherwise NAME is transformed in an implementation-defined way
1099    (usually by the addition of an underscore).
1100    Many macros in the tm file are defined to call this function.  */
1101
1102 void
1103 assemble_name (file, name)
1104      FILE *file;
1105      char *name;
1106 {
1107   if (name[0] == '*')
1108     fputs (&name[1], file);
1109   else
1110     ASM_OUTPUT_LABELREF (file, name);
1111 }
1112
1113 /* Allocate SIZE bytes writable static space with a gensym name
1114    and return an RTX to refer to its address.  */
1115
1116 rtx
1117 assemble_static_space (size)
1118      int size;
1119 {
1120   char name[12];
1121   char *namestring;
1122   rtx x;
1123   /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1124      so that each uninitialized object starts on such a boundary.  */
1125   int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1126                  / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1127                  * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1128
1129 #if 0
1130   if (flag_shared_data)
1131     data_section ();
1132 #endif
1133
1134   ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1135   ++const_labelno;
1136
1137   namestring = (char *) obstack_alloc (saveable_obstack,
1138                                        strlen (name) + 2);
1139   strcpy (namestring, name);
1140
1141   x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1142 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1143   ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1144 #else
1145   ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1146 #endif
1147   return x;
1148 }
1149
1150 /* Assemble the static constant template for function entry trampolines.
1151    This is done at most once per compilation.
1152    Returns an RTX for the address of the template.  */
1153
1154 rtx
1155 assemble_trampoline_template ()
1156 {
1157   char label[256];
1158   char *name;
1159   int align;
1160
1161   /* By default, put trampoline templates in read-only data section.  */
1162
1163 #ifdef TRAMPOLINE_SECTION
1164   TRAMPOLINE_SECTION ();
1165 #else
1166   readonly_data_section ();
1167 #endif
1168
1169   /* Write the assembler code to define one.  */
1170   align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1171   if (align > 0)
1172     ASM_OUTPUT_ALIGN (asm_out_file, align);
1173
1174   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1175   TRAMPOLINE_TEMPLATE (asm_out_file);
1176
1177   /* Record the rtl to refer to it.  */
1178   ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1179   name
1180     = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1181   return gen_rtx (SYMBOL_REF, Pmode, name);
1182 }
1183 \f
1184 /* Assemble the integer constant X into an object of SIZE bytes.
1185    X must be either a CONST_INT or CONST_DOUBLE.
1186
1187    Return 1 if we were able to output the constant, otherwise 0.  If FORCE is
1188    non-zero, abort if we can't output the constant.  */
1189
1190 int
1191 assemble_integer (x, size, force)
1192      rtx x;
1193      int size;
1194      int force;
1195 {
1196   /* First try to use the standard 1, 2, 4, 8, and 16 byte
1197      ASM_OUTPUT... macros. */
1198
1199   switch (size)
1200     {
1201 #ifdef ASM_OUTPUT_CHAR
1202     case 1:
1203       ASM_OUTPUT_CHAR (asm_out_file, x);
1204       return 1;
1205 #endif
1206
1207 #ifdef ASM_OUTPUT_SHORT
1208     case 2:
1209       ASM_OUTPUT_SHORT (asm_out_file, x);
1210       return 1;
1211 #endif
1212
1213 #ifdef ASM_OUTPUT_INT
1214     case 4:
1215       ASM_OUTPUT_INT (asm_out_file, x);
1216       return 1;
1217 #endif
1218
1219 #ifdef ASM_OUTPUT_DOUBLE_INT
1220     case 8:
1221       ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1222       return 1;
1223 #endif
1224
1225 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1226     case 16:
1227       ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1228       return 1;
1229 #endif
1230     }
1231
1232   /* If we couldn't do it that way, there are two other possibilities: First,
1233      if the machine can output an explicit byte and this is a 1 byte constant,
1234      we can use ASM_OUTPUT_BYTE.  */
1235
1236 #ifdef ASM_OUTPUT_BYTE
1237   if (size == 1 && GET_CODE (x) == CONST_INT)
1238     {
1239       ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1240       return 1;
1241     }
1242 #endif
1243
1244   /* Finally, if SIZE is larger than a single word, try to output the constant
1245      one word at a time.  */
1246
1247   if (size > UNITS_PER_WORD)
1248     {
1249       int i;
1250       enum machine_mode mode
1251         = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1252       rtx word;
1253
1254       for (i = 0; i < size / UNITS_PER_WORD; i++)
1255         {
1256           word = operand_subword (x, i, 0, mode);
1257
1258           if (word == 0)
1259             break;
1260
1261           if (! assemble_integer (word, UNITS_PER_WORD, 0))
1262             break;
1263         }
1264
1265       if (i == size / UNITS_PER_WORD)
1266         return 1;
1267       /* If we output at least one word and then could not finish,
1268          there is no valid way to continue.  */
1269       if (i > 0)
1270         abort ();
1271     }
1272
1273   if (force)
1274     abort ();
1275
1276   return 0;
1277 }
1278 \f
1279 /* Assemble the floating-point constant D into an object of size MODE.  */
1280
1281 void
1282 assemble_real (d, mode)
1283      REAL_VALUE_TYPE d;
1284      enum machine_mode mode;
1285 {
1286   jmp_buf output_constant_handler;
1287
1288   if (setjmp (output_constant_handler))
1289     {
1290       error ("floating point trap outputting a constant");
1291 #ifdef REAL_IS_NOT_DOUBLE
1292       bzero (&d, sizeof d);
1293       d = dconst0;
1294 #else
1295       d = 0;
1296 #endif
1297     }
1298
1299   set_float_handler (output_constant_handler);
1300
1301   switch (mode)
1302     {
1303 #ifdef ASM_OUTPUT_BYTE_FLOAT
1304     case QFmode:
1305       ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1306       break;
1307 #endif
1308 #ifdef ASM_OUTPUT_SHORT_FLOAT
1309     case HFmode:
1310       ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1311       break;
1312 #endif
1313 #ifdef ASM_OUTPUT_FLOAT
1314     case SFmode:
1315       ASM_OUTPUT_FLOAT (asm_out_file, d);
1316       break;
1317 #endif
1318
1319 #ifdef ASM_OUTPUT_DOUBLE
1320     case DFmode:
1321       ASM_OUTPUT_DOUBLE (asm_out_file, d);
1322       break;
1323 #endif
1324
1325 #ifdef ASM_OUTPUT_LONG_DOUBLE
1326     case XFmode:
1327     case TFmode:
1328       ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1329       break;
1330 #endif
1331
1332     default:
1333       abort ();
1334     }
1335
1336   set_float_handler (NULL_PTR);
1337 }
1338 \f
1339 /* Here we combine duplicate floating constants to make
1340    CONST_DOUBLE rtx's, and force those out to memory when necessary.  */
1341
1342 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1343    They are chained through the CONST_DOUBLE_CHAIN.
1344    A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1345    In that case, CONST_DOUBLE_MEM is either a MEM,
1346    or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1347
1348    (CONST_DOUBLE_MEM is used only for top-level functions.
1349    See force_const_mem for explanation.)  */
1350
1351 static rtx const_double_chain;
1352
1353 /* Return a CONST_DOUBLE for a value specified as a pair of ints.
1354    For an integer, I0 is the low-order word and I1 is the high-order word.
1355    For a real number, I0 is the word with the low address
1356    and I1 is the word with the high address.  */
1357
1358 rtx
1359 immed_double_const (i0, i1, mode)
1360      HOST_WIDE_INT i0, i1;
1361      enum machine_mode mode;
1362 {
1363   register rtx r;
1364   int in_current_obstack;
1365
1366   if (GET_MODE_CLASS (mode) == MODE_INT
1367       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1368     {
1369       /* We clear out all bits that don't belong in MODE, unless they and our
1370          sign bit are all one.  So we get either a reasonable negative value
1371          or a reasonable unsigned value for this mode.  */
1372       int width = GET_MODE_BITSIZE (mode);
1373       if (width < HOST_BITS_PER_WIDE_INT
1374           && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1375               != ((HOST_WIDE_INT) (-1) << (width - 1))))
1376         i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1377       else if (width == HOST_BITS_PER_WIDE_INT
1378                && ! (i1 == ~0 && i0 < 0))
1379         i1 = 0;
1380       else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1381         /* We cannot represent this value as a constant.  */
1382         abort ();
1383
1384       /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1385
1386          ??? Strictly speaking, this is wrong if we create a CONST_INT
1387          for a large unsigned constant with the size of MODE being
1388          HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1389          wider mode.  In that case we will mis-interpret it as a negative
1390          number.
1391
1392          Unfortunately, the only alternative is to make a CONST_DOUBLE
1393          for any constant in any mode if it is an unsigned constant larger
1394          than the maximum signed integer in an int on the host.  However,
1395          doing this will break everyone that always expects to see a CONST_INT
1396          for SImode and smaller.
1397
1398          We have always been making CONST_INTs in this case, so nothing new
1399          is being broken.  */
1400
1401       if (width <= HOST_BITS_PER_WIDE_INT)
1402         i1 = (i0 < 0) ? ~0 : 0;
1403
1404       /* If this integer fits in one word, return a CONST_INT.  */
1405       if ((i1 == 0 && i0 >= 0)
1406           || (i1 == ~0 && i0 < 0))
1407         return GEN_INT (i0);
1408
1409       /* We use VOIDmode for integers.  */
1410       mode = VOIDmode;
1411     }
1412
1413   /* Search the chain for an existing CONST_DOUBLE with the right value.
1414      If one is found, return it.  */
1415
1416   for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1417     if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1418         && GET_MODE (r) == mode)
1419       return r;
1420
1421   /* No; make a new one and add it to the chain.
1422
1423      We may be called by an optimizer which may be discarding any memory
1424      allocated during its processing (such as combine and loop).  However,
1425      we will be leaving this constant on the chain, so we cannot tolerate
1426      freed memory.  So switch to saveable_obstack for this allocation
1427      and then switch back if we were in current_obstack.  */
1428
1429   push_obstacks_nochange ();
1430   rtl_in_saveable_obstack ();
1431   r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1432   pop_obstacks ();
1433
1434   /* Don't touch const_double_chain in nested function;
1435      see force_const_mem.  */
1436   if (outer_function_chain == 0)
1437     {
1438       CONST_DOUBLE_CHAIN (r) = const_double_chain;
1439       const_double_chain = r;
1440     }
1441
1442   /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1443      Actual use of mem-slot is only through force_const_mem.  */
1444
1445   CONST_DOUBLE_MEM (r) = const0_rtx;
1446
1447   return r;
1448 }
1449
1450 /* Return a CONST_DOUBLE for a specified `double' value
1451    and machine mode.  */
1452
1453 rtx
1454 immed_real_const_1 (d, mode)
1455      REAL_VALUE_TYPE d;
1456      enum machine_mode mode;
1457 {
1458   union real_extract u;
1459   register rtx r;
1460   int in_current_obstack;
1461
1462   /* Get the desired `double' value as a sequence of ints
1463      since that is how they are stored in a CONST_DOUBLE.  */
1464
1465   u.d = d;
1466
1467   /* Detect special cases.  */
1468
1469   /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero.  */
1470   if (!bcmp (&dconst0, &d, sizeof d))
1471     return CONST0_RTX (mode);
1472   /* Check for NaN first, because some ports (specifically the i386) do not
1473      emit correct ieee-fp code by default, and thus will generate a core
1474      dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1475      does a floating point comparison.  */
1476   else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1477     return CONST1_RTX (mode);
1478
1479   if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1480     return immed_double_const (u.i[0], u.i[1], mode);
1481
1482   /* The rest of this function handles the case where
1483      a float value requires more than 2 ints of space.
1484      It will be deleted as dead code on machines that don't need it.  */
1485
1486   /* Search the chain for an existing CONST_DOUBLE with the right value.
1487      If one is found, return it.  */
1488
1489   for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1490     if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
1491         && GET_MODE (r) == mode)
1492       return r;
1493
1494   /* No; make a new one and add it to the chain.
1495
1496      We may be called by an optimizer which may be discarding any memory
1497      allocated during its processing (such as combine and loop).  However,
1498      we will be leaving this constant on the chain, so we cannot tolerate
1499      freed memory.  So switch to saveable_obstack for this allocation
1500      and then switch back if we were in current_obstack.  */
1501
1502   push_obstacks_nochange ();
1503   rtl_in_saveable_obstack ();
1504   r = rtx_alloc (CONST_DOUBLE);
1505   PUT_MODE (r, mode);
1506   bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
1507   pop_obstacks ();
1508
1509   /* Don't touch const_double_chain in nested function;
1510      see force_const_mem.  */
1511   if (outer_function_chain == 0)
1512     {
1513       CONST_DOUBLE_CHAIN (r) = const_double_chain;
1514       const_double_chain = r;
1515     }
1516
1517   /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1518      chain, but has not been allocated memory.  Actual use of CONST_DOUBLE_MEM
1519      is only through force_const_mem.  */
1520
1521   CONST_DOUBLE_MEM (r) = const0_rtx;
1522
1523   return r;
1524 }
1525
1526 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1527    which must be a REAL_CST tree node.  */
1528
1529 rtx
1530 immed_real_const (exp)
1531      tree exp;
1532 {
1533   return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1534 }
1535
1536 /* At the end of a function, forget the memory-constants
1537    previously made for CONST_DOUBLEs.  Mark them as not on real_constant_chain.
1538    Also clear out real_constant_chain and clear out all the chain-pointers.  */
1539
1540 void
1541 clear_const_double_mem ()
1542 {
1543   register rtx r, next;
1544
1545   /* Don't touch CONST_DOUBLE_MEM for nested functions.
1546      See force_const_mem for explanation.  */
1547   if (outer_function_chain != 0)
1548     return;
1549
1550   for (r = const_double_chain; r; r = next)
1551     {
1552       next = CONST_DOUBLE_CHAIN (r);
1553       CONST_DOUBLE_CHAIN (r) = 0;
1554       CONST_DOUBLE_MEM (r) = cc0_rtx;
1555     }
1556   const_double_chain = 0;
1557 }
1558 \f
1559 /* Given an expression EXP with a constant value,
1560    reduce it to the sum of an assembler symbol and an integer.
1561    Store them both in the structure *VALUE.
1562    Abort if EXP does not reduce.  */
1563
1564 struct addr_const
1565 {
1566   rtx base;
1567   HOST_WIDE_INT offset;
1568 };
1569
1570 static void
1571 decode_addr_const (exp, value)
1572      tree exp;
1573      struct addr_const *value;
1574 {
1575   register tree target = TREE_OPERAND (exp, 0);
1576   register int offset = 0;
1577   register rtx x;
1578
1579   while (1)
1580     {
1581       if (TREE_CODE (target) == COMPONENT_REF
1582           && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
1583               == INTEGER_CST))
1584         {
1585           offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
1586           target = TREE_OPERAND (target, 0);
1587         }
1588       else if (TREE_CODE (target) == ARRAY_REF)
1589         {
1590           if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
1591               || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
1592             abort ();
1593           offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
1594                       * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
1595                      / BITS_PER_UNIT);
1596           target = TREE_OPERAND (target, 0);
1597         }
1598       else
1599         break;
1600     }
1601
1602   switch (TREE_CODE (target))
1603     {
1604     case VAR_DECL:
1605     case FUNCTION_DECL:
1606       x = DECL_RTL (target);
1607       break;
1608
1609     case LABEL_DECL:
1610       x = gen_rtx (MEM, FUNCTION_MODE,
1611                    gen_rtx (LABEL_REF, VOIDmode,
1612                             label_rtx (TREE_OPERAND (exp, 0))));
1613       break;
1614
1615     case REAL_CST:
1616     case STRING_CST:
1617     case COMPLEX_CST:
1618     case CONSTRUCTOR:
1619       x = TREE_CST_RTL (target);
1620       break;
1621
1622     default:
1623       abort ();
1624     }
1625
1626   if (GET_CODE (x) != MEM)
1627     abort ();
1628   x = XEXP (x, 0);
1629
1630   value->base = x;
1631   value->offset = offset;
1632 }
1633 \f
1634 /* Uniquize all constants that appear in memory.
1635    Each constant in memory thus far output is recorded
1636    in `const_hash_table' with a `struct constant_descriptor'
1637    that contains a polish representation of the value of
1638    the constant.
1639
1640    We cannot store the trees in the hash table
1641    because the trees may be temporary.  */
1642
1643 struct constant_descriptor
1644 {
1645   struct constant_descriptor *next;
1646   char *label;
1647   char contents[1];
1648 };
1649
1650 #define HASHBITS 30
1651 #define MAX_HASH_TABLE 1009
1652 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
1653
1654 /* Compute a hash code for a constant expression.  */
1655
1656 int
1657 const_hash (exp)
1658      tree exp;
1659 {
1660   register char *p;
1661   register int len, hi, i;
1662   register enum tree_code code = TREE_CODE (exp);
1663
1664   if (code == INTEGER_CST)
1665     {
1666       p = (char *) &TREE_INT_CST_LOW (exp);
1667       len = 2 * sizeof TREE_INT_CST_LOW (exp);
1668     }
1669   else if (code == REAL_CST)
1670     {
1671       p = (char *) &TREE_REAL_CST (exp);
1672       len = sizeof TREE_REAL_CST (exp);
1673     }
1674   else if (code == STRING_CST)
1675     p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
1676   else if (code == COMPLEX_CST)
1677     return const_hash (TREE_REALPART (exp)) * 5
1678       + const_hash (TREE_IMAGPART (exp));
1679   else if (code == CONSTRUCTOR)
1680     {
1681       register tree link;
1682
1683       /* For record type, include the type in the hashing.
1684          We do not do so for array types
1685          because (1) the sizes of the elements are sufficient
1686          and (2) distinct array types can have the same constructor.
1687          Instead, we include the array size because the constructor could
1688          be shorter.  */
1689       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1690         hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
1691           % MAX_HASH_TABLE;
1692       else
1693         hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
1694                & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
1695
1696       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
1697         if (TREE_VALUE (link))
1698           hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
1699
1700       return hi;
1701     }
1702   else if (code == ADDR_EXPR)
1703     {
1704       struct addr_const value;
1705       decode_addr_const (exp, &value);
1706       if (GET_CODE (value.base) == SYMBOL_REF)
1707         {
1708           /* Don't hash the address of the SYMBOL_REF;
1709              only use the offset and the symbol name.  */
1710           hi = value.offset;
1711           p = XSTR (value.base, 0);
1712           for (i = 0; p[i] != 0; i++)
1713             hi = ((hi * 613) + (unsigned)(p[i]));
1714         }
1715       else if (GET_CODE (value.base) == LABEL_REF)
1716         hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
1717
1718       hi &= (1 << HASHBITS) - 1;
1719       hi %= MAX_HASH_TABLE;
1720       return hi;
1721     }
1722   else if (code == PLUS_EXPR || code == MINUS_EXPR)
1723     return const_hash (TREE_OPERAND (exp, 0)) * 9
1724       +  const_hash (TREE_OPERAND (exp, 1));
1725   else if (code == NOP_EXPR || code == CONVERT_EXPR)
1726     return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
1727
1728   /* Compute hashing function */
1729   hi = len;
1730   for (i = 0; i < len; i++)
1731     hi = ((hi * 613) + (unsigned)(p[i]));
1732
1733   hi &= (1 << HASHBITS) - 1;
1734   hi %= MAX_HASH_TABLE;
1735   return hi;
1736 }
1737 \f
1738 /* Compare a constant expression EXP with a constant-descriptor DESC.
1739    Return 1 if DESC describes a constant with the same value as EXP.  */
1740
1741 static int
1742 compare_constant (exp, desc)
1743      tree exp;
1744      struct constant_descriptor *desc;
1745 {
1746   return 0 != compare_constant_1 (exp, desc->contents);
1747 }
1748
1749 /* Compare constant expression EXP with a substring P of a constant descriptor.
1750    If they match, return a pointer to the end of the substring matched.
1751    If they do not match, return 0.
1752
1753    Since descriptors are written in polish prefix notation,
1754    this function can be used recursively to test one operand of EXP
1755    against a subdescriptor, and if it succeeds it returns the
1756    address of the subdescriptor for the next operand.  */
1757
1758 static char *
1759 compare_constant_1 (exp, p)
1760      tree exp;
1761      char *p;
1762 {
1763   register char *strp;
1764   register int len;
1765   register enum tree_code code = TREE_CODE (exp);
1766
1767   if (code != (enum tree_code) *p++)
1768     return 0;
1769
1770   if (code == INTEGER_CST)
1771     {
1772       /* Integer constants are the same only if the same width of type.  */
1773       if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
1774         return 0;
1775       strp = (char *) &TREE_INT_CST_LOW (exp);
1776       len = 2 * sizeof TREE_INT_CST_LOW (exp);
1777     }
1778   else if (code == REAL_CST)
1779     {
1780       /* Real constants are the same only if the same width of type.  */
1781       if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
1782         return 0;
1783       strp = (char *) &TREE_REAL_CST (exp);
1784       len = sizeof TREE_REAL_CST (exp);
1785     }
1786   else if (code == STRING_CST)
1787     {
1788       if (flag_writable_strings)
1789         return 0;
1790       strp = TREE_STRING_POINTER (exp);
1791       len = TREE_STRING_LENGTH (exp);
1792       if (bcmp (&TREE_STRING_LENGTH (exp), p,
1793                 sizeof TREE_STRING_LENGTH (exp)))
1794         return 0;
1795       p += sizeof TREE_STRING_LENGTH (exp);
1796     }
1797   else if (code == COMPLEX_CST)
1798     {
1799       p = compare_constant_1 (TREE_REALPART (exp), p);
1800       if (p == 0) return 0;
1801       p = compare_constant_1 (TREE_IMAGPART (exp), p);
1802       return p;
1803     }
1804   else if (code == CONSTRUCTOR)
1805     {
1806       register tree link;
1807       int length = list_length (CONSTRUCTOR_ELTS (exp));
1808       tree type;
1809
1810       if (bcmp (&length, p, sizeof length))
1811         return 0;
1812       p += sizeof length;
1813
1814       /* For record constructors, insist that the types match.
1815          For arrays, just verify both constructors are for arrays.  */
1816       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1817         type = TREE_TYPE (exp);
1818       else
1819         type = 0;
1820       if (bcmp (&type, p, sizeof type))
1821         return 0;
1822       p += sizeof type;
1823
1824       /* For arrays, insist that the size in bytes match.  */
1825       if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
1826         {
1827           int size = int_size_in_bytes (TREE_TYPE (exp));
1828           if (bcmp (&size, p, sizeof size))
1829             return 0;
1830           p += sizeof size;
1831         }
1832
1833       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
1834         {
1835           if (TREE_VALUE (link))
1836             {
1837               if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
1838                 return 0;
1839             }
1840           else
1841             {
1842               tree zero = 0;
1843
1844               if (bcmp (&zero, p, sizeof zero))
1845                 return 0;
1846               p += sizeof zero;
1847             }
1848         }
1849
1850       return p;
1851     }
1852   else if (code == ADDR_EXPR)
1853     {
1854       struct addr_const value;
1855       decode_addr_const (exp, &value);
1856       strp = (char *) &value.offset;
1857       len = sizeof value.offset;
1858       /* Compare the offset.  */
1859       while (--len >= 0)
1860         if (*p++ != *strp++)
1861           return 0;
1862       /* Compare symbol name.  */
1863       strp = XSTR (value.base, 0);
1864       len = strlen (strp) + 1;
1865     }
1866   else if (code == PLUS_EXPR || code == MINUS_EXPR)
1867     {
1868       p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
1869       if (p == 0) return 0;
1870       p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
1871       return p;
1872     }
1873   else if (code == NOP_EXPR || code == CONVERT_EXPR)
1874     {
1875       p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
1876       return p;
1877     }
1878
1879   /* Compare constant contents.  */
1880   while (--len >= 0)
1881     if (*p++ != *strp++)
1882       return 0;
1883
1884   return p;
1885 }
1886 \f
1887 /* Construct a constant descriptor for the expression EXP.
1888    It is up to the caller to enter the descriptor in the hash table.  */
1889
1890 static struct constant_descriptor *
1891 record_constant (exp)
1892      tree exp;
1893 {
1894   struct constant_descriptor *next = 0;
1895   char *label = 0;
1896
1897   /* Make a struct constant_descriptor.  The first two pointers will
1898      be filled in later.  Here we just leave space for them.  */
1899
1900   obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
1901   obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
1902   record_constant_1 (exp);
1903   return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
1904 }
1905
1906 /* Add a description of constant expression EXP
1907    to the object growing in `permanent_obstack'.
1908    No need to return its address; the caller will get that
1909    from the obstack when the object is complete.  */
1910
1911 static void
1912 record_constant_1 (exp)
1913      tree exp;
1914 {
1915   register char *strp;
1916   register int len;
1917   register enum tree_code code = TREE_CODE (exp);
1918
1919   obstack_1grow (&permanent_obstack, (unsigned int) code);
1920
1921   if (code == INTEGER_CST)
1922     {
1923       obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
1924       strp = (char *) &TREE_INT_CST_LOW (exp);
1925       len = 2 * sizeof TREE_INT_CST_LOW (exp);
1926     }
1927   else if (code == REAL_CST)
1928     {
1929       obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
1930       strp = (char *) &TREE_REAL_CST (exp);
1931       len = sizeof TREE_REAL_CST (exp);
1932     }
1933   else if (code == STRING_CST)
1934     {
1935       if (flag_writable_strings)
1936         return;
1937       strp = TREE_STRING_POINTER (exp);
1938       len = TREE_STRING_LENGTH (exp);
1939       obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
1940                     sizeof TREE_STRING_LENGTH (exp));
1941     }
1942   else if (code == COMPLEX_CST)
1943     {
1944       record_constant_1 (TREE_REALPART (exp));
1945       record_constant_1 (TREE_IMAGPART (exp));
1946       return;
1947     }
1948   else if (code == CONSTRUCTOR)
1949     {
1950       register tree link;
1951       int length = list_length (CONSTRUCTOR_ELTS (exp));
1952       tree type;
1953
1954       obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
1955
1956       /* For record constructors, insist that the types match.
1957          For arrays, just verify both constructors are for arrays.  */
1958       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1959         type = TREE_TYPE (exp);
1960       else
1961         type = 0;
1962       obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
1963
1964       /* For arrays, insist that the size in bytes match.  */
1965       if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
1966         {
1967           int size = int_size_in_bytes (TREE_TYPE (exp));
1968           obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
1969         }
1970
1971       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
1972         {
1973           if (TREE_VALUE (link))
1974             record_constant_1 (TREE_VALUE (link));
1975           else
1976             {
1977               tree zero = 0;
1978
1979               obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
1980             }
1981         }
1982
1983       return;
1984     }
1985   else if (code == ADDR_EXPR)
1986     {
1987       struct addr_const value;
1988       decode_addr_const (exp, &value);
1989       /* Record the offset.  */
1990       obstack_grow (&permanent_obstack,
1991                     (char *) &value.offset, sizeof value.offset);
1992       /* Record the symbol name.  */
1993       obstack_grow (&permanent_obstack, XSTR (value.base, 0),
1994                     strlen (XSTR (value.base, 0)) + 1);
1995       return;
1996     }
1997   else if (code == PLUS_EXPR || code == MINUS_EXPR)
1998     {
1999       record_constant_1 (TREE_OPERAND (exp, 0));
2000       record_constant_1 (TREE_OPERAND (exp, 1));
2001       return;
2002     }
2003   else if (code == NOP_EXPR || code == CONVERT_EXPR)
2004     {
2005       record_constant_1 (TREE_OPERAND (exp, 0));
2006       return;
2007     }
2008
2009   /* Record constant contents.  */
2010   obstack_grow (&permanent_obstack, strp, len);
2011 }
2012 \f
2013 /* Record a list of constant expressions that were passed to
2014    output_constant_def but that could not be output right away.  */
2015
2016 struct deferred_constant
2017 {
2018   struct deferred_constant *next;
2019   tree exp;
2020   int reloc;
2021   int labelno;
2022 };
2023
2024 static struct deferred_constant *deferred_constants;
2025
2026 /* Nonzero means defer output of addressed subconstants
2027    (i.e., those for which output_constant_def is called.)  */
2028 static int defer_addressed_constants_flag;
2029
2030 /* Start deferring output of subconstants.  */
2031
2032 void
2033 defer_addressed_constants ()
2034 {
2035   defer_addressed_constants_flag++;
2036 }
2037
2038 /* Stop deferring output of subconstants,
2039    and output now all those that have been deferred.  */
2040
2041 void
2042 output_deferred_addressed_constants ()
2043 {
2044   struct deferred_constant *p, *next;
2045
2046   defer_addressed_constants_flag--;
2047
2048   if (defer_addressed_constants_flag > 0)
2049     return;
2050
2051   for (p = deferred_constants; p; p = next)
2052     {
2053       output_constant_def_contents (p->exp, p->reloc, p->labelno);
2054       next = p->next;
2055       free (p);
2056     }
2057
2058   deferred_constants = 0;
2059 }
2060 \f
2061 /* Return an rtx representing a reference to constant data in memory
2062    for the constant expression EXP.
2063
2064    If assembler code for such a constant has already been output,
2065    return an rtx to refer to it.
2066    Otherwise, output such a constant in memory (or defer it for later)
2067    and generate an rtx for it.
2068
2069    The TREE_CST_RTL of EXP is set up to point to that rtx.
2070    The const_hash_table records which constants already have label strings.  */
2071
2072 rtx
2073 output_constant_def (exp)
2074      tree exp;
2075 {
2076   register int hash;
2077   register struct constant_descriptor *desc;
2078   char label[256];
2079   char *found = 0;
2080   int reloc;
2081   register rtx def;
2082
2083   if (TREE_CODE (exp) == INTEGER_CST)
2084     abort ();                   /* No TREE_CST_RTL slot in these.  */
2085
2086   if (TREE_CST_RTL (exp))
2087     return TREE_CST_RTL (exp);
2088
2089   /* Make sure any other constants whose addresses appear in EXP
2090      are assigned label numbers.  */
2091
2092   reloc = output_addressed_constants (exp);
2093
2094   /* Compute hash code of EXP.  Search the descriptors for that hash code
2095      to see if any of them describes EXP.  If yes, the descriptor records
2096      the label number already assigned.  */
2097
2098   hash = const_hash (exp) % MAX_HASH_TABLE;
2099
2100   for (desc = const_hash_table[hash]; desc; desc = desc->next)
2101     if (compare_constant (exp, desc))
2102       {
2103         found = desc->label;
2104         break;
2105       }
2106
2107   if (found == 0)
2108     {
2109       /* No constant equal to EXP is known to have been output.
2110          Make a constant descriptor to enter EXP in the hash table.
2111          Assign the label number and record it in the descriptor for
2112          future calls to this function to find.  */
2113
2114       /* Create a string containing the label name, in LABEL.  */
2115       ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2116
2117       desc = record_constant (exp);
2118       desc->next = const_hash_table[hash];
2119       desc->label
2120         = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2121       const_hash_table[hash] = desc;
2122     }
2123
2124   /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
2125
2126   push_obstacks_nochange ();
2127   if (TREE_PERMANENT (exp))
2128     end_temporary_allocation ();
2129
2130   def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2131
2132   TREE_CST_RTL (exp)
2133     = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2134   RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2135   if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
2136       || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2137     MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2138
2139   pop_obstacks ();
2140
2141   /* Optionally set flags or add text to the name to record information
2142      such as that it is a function name.  If the name is changed, the macro
2143      ASM_OUTPUT_LABELREF will have to know how to strip this information.
2144      And if it finds a * at the beginning after doing so, it must handle
2145      that too.  */
2146 #ifdef ENCODE_SECTION_INFO
2147   ENCODE_SECTION_INFO (exp);
2148 #endif
2149
2150   /* If this is the first time we've seen this particular constant,
2151      output it (or defer its output for later).  */
2152   if (found == 0)
2153     {
2154       if (defer_addressed_constants_flag)
2155         {
2156           struct deferred_constant *p;
2157           p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2158
2159           /* We really should copy trees in depth here,
2160              but since this case is the only one that should happen now,
2161              let's do it later.  */
2162           if (TREE_CODE (exp) != STRING_CST)
2163             abort ();
2164
2165           push_obstacks_nochange ();
2166           suspend_momentary ();
2167           p->exp = copy_node (exp);
2168           pop_obstacks ();
2169           p->reloc = reloc;
2170           p->labelno = const_labelno++;
2171           p->next = deferred_constants;
2172           deferred_constants = p;
2173         }
2174       else
2175         output_constant_def_contents (exp, reloc, const_labelno++);
2176     }
2177
2178   return TREE_CST_RTL (exp);
2179 }
2180
2181 /* Now output assembler code to define the label for EXP,
2182    and follow it with the data of EXP.  */
2183
2184 static void
2185 output_constant_def_contents (exp, reloc, labelno)
2186      tree exp;
2187      int reloc;
2188      int labelno;
2189 {
2190   int align;
2191
2192   /* First switch to text section, except for writable strings.  */
2193 #ifdef SELECT_SECTION
2194   SELECT_SECTION (exp, reloc);
2195 #else
2196   if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2197       || (flag_pic && reloc))
2198     data_section ();
2199   else
2200     readonly_data_section ();
2201 #endif
2202
2203   /* Align the location counter as required by EXP's data type.  */
2204   align = TYPE_ALIGN (TREE_TYPE (exp));
2205 #ifdef CONSTANT_ALIGNMENT
2206   align = CONSTANT_ALIGNMENT (exp, align);
2207 #endif
2208
2209   if (align > BITS_PER_UNIT)
2210     ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2211
2212   /* Output the label itself.  */
2213   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2214
2215   /* Output the value of EXP.  */
2216   output_constant (exp,
2217                    (TREE_CODE (exp) == STRING_CST
2218                     ? TREE_STRING_LENGTH (exp)
2219                     : int_size_in_bytes (TREE_TYPE (exp))));
2220
2221 }
2222 \f
2223 /* Similar hash facility for making memory-constants
2224    from constant rtl-expressions.  It is used on RISC machines
2225    where immediate integer arguments and constant addresses are restricted
2226    so that such constants must be stored in memory.
2227
2228    This pool of constants is reinitialized for each function
2229    so each function gets its own constants-pool that comes right before it.
2230
2231    All structures allocated here are discarded when functions are saved for
2232    inlining, so they do not need to be allocated permanently.  */
2233
2234 #define MAX_RTX_HASH_TABLE 61
2235 static struct constant_descriptor **const_rtx_hash_table;
2236
2237 /* Structure to represent sufficient information about a constant so that
2238    it can be output when the constant pool is output, so that function
2239    integration can be done, and to simplify handling on machines that reference
2240    constant pool as base+displacement.  */
2241
2242 struct pool_constant
2243 {
2244   struct constant_descriptor *desc;
2245   struct pool_constant *next;
2246   enum machine_mode mode;
2247   rtx constant;
2248   int labelno;
2249   int align;
2250   int offset;
2251 };
2252
2253 /* Pointers to first and last constant in pool.  */
2254
2255 static struct pool_constant *first_pool, *last_pool;
2256
2257 /* Current offset in constant pool (does not include any machine-specific
2258    header.  */
2259
2260 static int pool_offset;
2261
2262 /* Structure used to maintain hash table mapping symbols used to their
2263    corresponding constants.  */
2264
2265 struct pool_sym
2266 {
2267   char *label;
2268   struct pool_constant *pool;
2269   struct pool_sym *next;
2270 };
2271
2272 static struct pool_sym **const_rtx_sym_hash_table;
2273
2274 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2275    The argument is XSTR (... , 0)  */
2276
2277 #define SYMHASH(LABEL)  \
2278   ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1))  % MAX_RTX_HASH_TABLE)
2279 \f
2280 /* Initialize constant pool hashing for next function.  */
2281
2282 void
2283 init_const_rtx_hash_table ()
2284 {
2285   const_rtx_hash_table
2286     = ((struct constant_descriptor **)
2287        oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2288   const_rtx_sym_hash_table
2289     = ((struct pool_sym **)
2290        oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2291   bzero (const_rtx_hash_table,
2292          MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2293   bzero (const_rtx_sym_hash_table,
2294          MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2295
2296   first_pool = last_pool = 0;
2297   pool_offset = 0;
2298 }
2299
2300 /* Save and restore it for a nested function.  */
2301
2302 void
2303 save_varasm_status (p)
2304      struct function *p;
2305 {
2306   p->const_rtx_hash_table = const_rtx_hash_table;
2307   p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2308   p->first_pool = first_pool;
2309   p->last_pool = last_pool;
2310   p->pool_offset = pool_offset;
2311 }
2312
2313 void
2314 restore_varasm_status (p)
2315      struct function *p;
2316 {
2317   const_rtx_hash_table = p->const_rtx_hash_table;
2318   const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2319   first_pool = p->first_pool;
2320   last_pool = p->last_pool;
2321   pool_offset = p->pool_offset;
2322 }
2323 \f
2324 enum kind { RTX_DOUBLE, RTX_INT };
2325
2326 struct rtx_const
2327 {
2328 #ifdef ONLY_INT_FIELDS
2329   unsigned int kind : 16;
2330   unsigned int mode : 16;
2331 #else
2332   enum kind kind : 16;
2333   enum machine_mode mode : 16;
2334 #endif
2335   union {
2336     union real_extract du;
2337     struct addr_const addr;
2338   } un;
2339 };
2340
2341 /* Express an rtx for a constant integer (perhaps symbolic)
2342    as the sum of a symbol or label plus an explicit integer.
2343    They are stored into VALUE.  */
2344
2345 static void
2346 decode_rtx_const (mode, x, value)
2347      enum machine_mode mode;
2348      rtx x;
2349      struct rtx_const *value;
2350 {
2351   /* Clear the whole structure, including any gaps.  */
2352
2353   {
2354     int *p = (int *) value;
2355     int *end = (int *) (value + 1);
2356     while (p < end)
2357       *p++ = 0;
2358   }
2359
2360   value->kind = RTX_INT;        /* Most usual kind. */
2361   value->mode = mode;
2362
2363   switch (GET_CODE (x))
2364     {
2365     case CONST_DOUBLE:
2366       value->kind = RTX_DOUBLE;
2367       value->mode = GET_MODE (x);
2368       bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
2369       break;
2370
2371     case CONST_INT:
2372       value->un.addr.offset = INTVAL (x);
2373       break;
2374
2375     case SYMBOL_REF:
2376     case LABEL_REF:
2377     case PC:
2378       value->un.addr.base = x;
2379       break;
2380
2381     case CONST:
2382       x = XEXP (x, 0);
2383       if (GET_CODE (x) == PLUS)
2384         {
2385           value->un.addr.base = XEXP (x, 0);
2386           if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2387             abort ();
2388           value->un.addr.offset = INTVAL (XEXP (x, 1));
2389         }
2390       else if (GET_CODE (x) == MINUS)
2391         {
2392           value->un.addr.base = XEXP (x, 0);
2393           if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2394             abort ();
2395           value->un.addr.offset = - INTVAL (XEXP (x, 1));
2396         }
2397       else
2398         abort ();
2399       break;
2400
2401     default:
2402       abort ();
2403     }
2404
2405   if (value->kind == RTX_INT && value->un.addr.base != 0)
2406     switch (GET_CODE (value->un.addr.base))
2407       {
2408       case SYMBOL_REF:
2409       case LABEL_REF:
2410         /* Use the string's address, not the SYMBOL_REF's address,
2411            for the sake of addresses of library routines.
2412            For a LABEL_REF, compare labels.  */
2413         value->un.addr.base = XEXP (value->un.addr.base, 0);
2414       }
2415 }
2416
2417 /* Given a MINUS expression, simplify it if both sides
2418    include the same symbol.  */
2419
2420 rtx
2421 simplify_subtraction (x)
2422      rtx x;
2423 {
2424   struct rtx_const val0, val1;
2425
2426   decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2427   decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2428
2429   if (val0.un.addr.base == val1.un.addr.base)
2430     return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2431   return x;
2432 }
2433
2434 /* Compute a hash code for a constant RTL expression.  */
2435
2436 int
2437 const_hash_rtx (mode, x)
2438      enum machine_mode mode;
2439      rtx x;
2440 {
2441   register int hi, i;
2442
2443   struct rtx_const value;
2444   decode_rtx_const (mode, x, &value);
2445
2446   /* Compute hashing function */
2447   hi = 0;
2448   for (i = 0; i < sizeof value / sizeof (int); i++)
2449     hi += ((int *) &value)[i];
2450
2451   hi &= (1 << HASHBITS) - 1;
2452   hi %= MAX_RTX_HASH_TABLE;
2453   return hi;
2454 }
2455
2456 /* Compare a constant rtl object X with a constant-descriptor DESC.
2457    Return 1 if DESC describes a constant with the same value as X.  */
2458
2459 static int
2460 compare_constant_rtx (mode, x, desc)
2461      enum machine_mode mode;
2462      rtx x;
2463      struct constant_descriptor *desc;
2464 {
2465   register int *p = (int *) desc->contents;
2466   register int *strp;
2467   register int len;
2468   struct rtx_const value;
2469
2470   decode_rtx_const (mode, x, &value);
2471   strp = (int *) &value;
2472   len = sizeof value / sizeof (int);
2473
2474   /* Compare constant contents.  */
2475   while (--len >= 0)
2476     if (*p++ != *strp++)
2477       return 0;
2478
2479   return 1;
2480 }
2481
2482 /* Construct a constant descriptor for the rtl-expression X.
2483    It is up to the caller to enter the descriptor in the hash table.  */
2484
2485 static struct constant_descriptor *
2486 record_constant_rtx (mode, x)
2487      enum machine_mode mode;
2488      rtx x;
2489 {
2490   struct constant_descriptor *ptr;
2491   char *label;
2492   struct rtx_const value;
2493
2494   decode_rtx_const (mode, x, &value);
2495
2496   obstack_grow (current_obstack, &ptr, sizeof ptr);
2497   obstack_grow (current_obstack, &label, sizeof label);
2498
2499   /* Record constant contents.  */
2500   obstack_grow (current_obstack, &value, sizeof value);
2501
2502   return (struct constant_descriptor *) obstack_finish (current_obstack);
2503 }
2504 \f
2505 /* Given a constant rtx X, make (or find) a memory constant for its value
2506    and return a MEM rtx to refer to it in memory.  */
2507
2508 rtx
2509 force_const_mem (mode, x)
2510      enum machine_mode mode;
2511      rtx x;
2512 {
2513   register int hash;
2514   register struct constant_descriptor *desc;
2515   char label[256];
2516   char *found = 0;
2517   rtx def;
2518
2519   /* If we want this CONST_DOUBLE in the same mode as it is in memory
2520      (this will always be true for floating CONST_DOUBLEs that have been
2521      placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
2522      use the previous copy.  Otherwise, make a new one.  Note that in
2523      the unlikely event that this same CONST_DOUBLE is used in two different
2524      modes in an alternating fashion, we will allocate a lot of different
2525      memory locations, but this should be extremely rare.  */
2526
2527   /* Don't use CONST_DOUBLE_MEM in a nested function.
2528      Nested functions have their own constant pools,
2529      so they can't share the same values in CONST_DOUBLE_MEM
2530      with the containing function.  */
2531   if (outer_function_chain == 0)
2532     if (GET_CODE (x) == CONST_DOUBLE
2533         && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
2534         && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
2535       return CONST_DOUBLE_MEM (x);
2536
2537   /* Compute hash code of X.  Search the descriptors for that hash code
2538      to see if any of them describes X.  If yes, the descriptor records
2539      the label number already assigned.  */
2540
2541   hash = const_hash_rtx (mode, x);
2542
2543   for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
2544     if (compare_constant_rtx (mode, x, desc))
2545       {
2546         found = desc->label;
2547         break;
2548       }
2549
2550   if (found == 0)
2551     {
2552       register struct pool_constant *pool;
2553       register struct pool_sym *sym;
2554       int align;
2555
2556       /* No constant equal to X is known to have been output.
2557          Make a constant descriptor to enter X in the hash table.
2558          Assign the label number and record it in the descriptor for
2559          future calls to this function to find.  */
2560
2561       desc = record_constant_rtx (mode, x);
2562       desc->next = const_rtx_hash_table[hash];
2563       const_rtx_hash_table[hash] = desc;
2564
2565       /* Align the location counter as required by EXP's data type.  */
2566       align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
2567       if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2568         align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
2569
2570       pool_offset += align - 1;
2571       pool_offset &= ~ (align - 1);
2572
2573       /* Allocate a pool constant descriptor, fill it in, and chain it in.  */
2574
2575       pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
2576       pool->desc = desc;
2577       pool->constant = x;
2578       pool->mode = mode;
2579       pool->labelno = const_labelno;
2580       pool->align = align;
2581       pool->offset = pool_offset;
2582       pool->next = 0;
2583
2584       if (last_pool == 0)
2585         first_pool = pool;
2586       else
2587         last_pool->next = pool;
2588
2589       last_pool = pool;
2590       pool_offset += GET_MODE_SIZE (mode);
2591
2592       /* Create a string containing the label name, in LABEL.  */
2593       ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2594
2595       ++const_labelno;
2596
2597       desc->label = found
2598         = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
2599
2600       /* Add label to symbol hash table.  */
2601       hash = SYMHASH (found);
2602       sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
2603       sym->label = found;
2604       sym->pool = pool;
2605       sym->next = const_rtx_sym_hash_table[hash];
2606       const_rtx_sym_hash_table[hash] = sym;
2607     }
2608
2609   /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
2610
2611   def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
2612
2613   RTX_UNCHANGING_P (def) = 1;
2614   /* Mark the symbol_ref as belonging to this constants pool.  */
2615   CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
2616   current_function_uses_const_pool = 1;
2617
2618   if (outer_function_chain == 0)
2619     if (GET_CODE (x) == CONST_DOUBLE)
2620       {
2621         if (CONST_DOUBLE_MEM (x) == cc0_rtx)
2622           {
2623             CONST_DOUBLE_CHAIN (x) = const_double_chain;
2624             const_double_chain = x;
2625           }
2626         CONST_DOUBLE_MEM (x) = def;
2627       }
2628
2629   return def;
2630 }
2631 \f
2632 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
2633    the corresponding pool_constant structure.  */
2634
2635 static struct pool_constant *
2636 find_pool_constant (addr)
2637      rtx addr;
2638 {
2639   struct pool_sym *sym;
2640   char *label = XSTR (addr, 0);
2641
2642   for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
2643     if (sym->label == label)
2644       return sym->pool;
2645
2646   abort ();
2647 }
2648
2649 /* Given a constant pool SYMBOL_REF, return the corresponding constant.  */
2650
2651 rtx
2652 get_pool_constant (addr)
2653      rtx addr;
2654 {
2655   return (find_pool_constant (addr))->constant;
2656 }
2657
2658 /* Similar, return the mode.  */
2659
2660 enum machine_mode
2661 get_pool_mode (addr)
2662      rtx addr;
2663 {
2664   return (find_pool_constant (addr))->mode;
2665 }
2666
2667 /* Similar, return the offset in the constant pool.  */
2668
2669 int
2670 get_pool_offset (addr)
2671      rtx addr;
2672 {
2673   return (find_pool_constant (addr))->offset;
2674 }
2675
2676 /* Return the size of the constant pool.  */
2677
2678 int
2679 get_pool_size ()
2680 {
2681   return pool_offset;
2682 }
2683 \f
2684 /* Write all the constants in the constant pool.  */
2685
2686 void
2687 output_constant_pool (fnname, fndecl)
2688      char *fnname;
2689      tree fndecl;
2690 {
2691   struct pool_constant *pool;
2692   rtx x;
2693   union real_extract u;
2694
2695 #ifdef ASM_OUTPUT_POOL_PROLOGUE
2696   ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
2697 #endif
2698
2699   for (pool = first_pool; pool; pool = pool->next)
2700     {
2701       x = pool->constant;
2702
2703       /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
2704          whose CODE_LABEL has been deleted.  This can occur if a jump table
2705          is eliminated by optimization.  If so, write a constant of zero
2706          instead.  Note that this can also happen by turning the
2707          CODE_LABEL into a NOTE.  */
2708       if (((GET_CODE (x) == LABEL_REF
2709             && (INSN_DELETED_P (XEXP (x, 0))
2710                 || GET_CODE (XEXP (x, 0)) == NOTE)))
2711           || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
2712               && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
2713               && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
2714                   || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
2715         x = const0_rtx;
2716
2717       /* First switch to correct section.  */
2718 #ifdef SELECT_RTX_SECTION
2719       SELECT_RTX_SECTION (pool->mode, x);
2720 #else
2721       readonly_data_section ();
2722 #endif
2723
2724 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
2725       ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
2726                                      pool->align, pool->labelno, done);
2727 #endif
2728
2729       if (pool->align > 1)
2730         ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
2731
2732       /* Output the label.  */
2733       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
2734
2735       /* Output the value of the constant itself.  */
2736       switch (GET_MODE_CLASS (pool->mode))
2737         {
2738         case MODE_FLOAT:
2739           if (GET_CODE (x) != CONST_DOUBLE)
2740             abort ();
2741
2742           bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
2743           assemble_real (u.d, pool->mode);
2744           break;
2745
2746         case MODE_INT:
2747         case MODE_PARTIAL_INT:
2748           assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
2749           break;
2750
2751         default:
2752           abort ();
2753         }
2754
2755     done: ;
2756     }
2757
2758   /* Done with this pool.  */
2759   first_pool = last_pool = 0;
2760 }
2761 \f
2762 /* Find all the constants whose addresses are referenced inside of EXP,
2763    and make sure assembler code with a label has been output for each one.
2764    Indicate whether an ADDR_EXPR has been encountered.  */
2765
2766 int
2767 output_addressed_constants (exp)
2768      tree exp;
2769 {
2770   int reloc = 0;
2771
2772   switch (TREE_CODE (exp))
2773     {
2774     case ADDR_EXPR:
2775       {
2776         register tree constant = TREE_OPERAND (exp, 0);
2777
2778         while (TREE_CODE (constant) == COMPONENT_REF)
2779           {
2780             constant = TREE_OPERAND (constant, 0);
2781           }
2782
2783         if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
2784             || TREE_CODE (constant) == CONSTRUCTOR)
2785           /* No need to do anything here
2786              for addresses of variables or functions.  */
2787           output_constant_def (constant);
2788       }
2789       reloc = 1;
2790       break;
2791
2792     case PLUS_EXPR:
2793     case MINUS_EXPR:
2794       reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
2795       reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
2796       break;
2797
2798     case NOP_EXPR:
2799     case CONVERT_EXPR:
2800     case NON_LVALUE_EXPR:
2801       reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
2802       break;
2803
2804     case CONSTRUCTOR:
2805       {
2806         register tree link;
2807         for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2808           if (TREE_VALUE (link) != 0)
2809             reloc |= output_addressed_constants (TREE_VALUE (link));
2810       }
2811       break;
2812
2813     case ERROR_MARK:
2814       break;
2815     }
2816   return reloc;
2817 }
2818 \f
2819 /* Output assembler code for constant EXP to FILE, with no label.
2820    This includes the pseudo-op such as ".int" or ".byte", and a newline.
2821    Assumes output_addressed_constants has been done on EXP already.
2822
2823    Generate exactly SIZE bytes of assembler data, padding at the end
2824    with zeros if necessary.  SIZE must always be specified.
2825
2826    SIZE is important for structure constructors,
2827    since trailing members may have been omitted from the constructor.
2828    It is also important for initialization of arrays from string constants
2829    since the full length of the string constant might not be wanted.
2830    It is also needed for initialization of unions, where the initializer's
2831    type is just one member, and that may not be as long as the union.
2832
2833    There a case in which we would fail to output exactly SIZE bytes:
2834    for a structure constructor that wants to produce more than SIZE bytes.
2835    But such constructors will never be generated for any possible input.  */
2836
2837 void
2838 output_constant (exp, size)
2839      register tree exp;
2840      register int size;
2841 {
2842   register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
2843   rtx x;
2844
2845   if (size == 0)
2846     return;
2847
2848   /* Allow a constructor with no elements for any data type.
2849      This means to fill the space with zeros.  */
2850   if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
2851     {
2852       assemble_zeros (size);
2853       return;
2854     }
2855
2856   /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
2857      That way we get the constant (we hope) inside it.  */
2858   if (TREE_CODE (exp) == NOP_EXPR
2859       && TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)))
2860     exp = TREE_OPERAND (exp, 0);
2861
2862   switch (code)
2863     {
2864     case CHAR_TYPE:
2865     case BOOLEAN_TYPE:
2866     case INTEGER_TYPE:
2867     case ENUMERAL_TYPE:
2868     case POINTER_TYPE:
2869     case REFERENCE_TYPE:
2870       /* ??? What about       (int)((float)(int)&foo + 4)    */
2871       while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
2872              || TREE_CODE (exp) == NON_LVALUE_EXPR)
2873         exp = TREE_OPERAND (exp, 0);
2874
2875       if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
2876                                            EXPAND_INITIALIZER),
2877                               size, 0))
2878         error ("initializer for integer value is too complicated");
2879       size = 0;
2880       break;
2881
2882     case REAL_TYPE:
2883       if (TREE_CODE (exp) != REAL_CST)
2884         error ("initializer for floating value is not a floating constant");
2885
2886       assemble_real (TREE_REAL_CST (exp),
2887                      mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
2888       size = 0;
2889       break;
2890
2891     case COMPLEX_TYPE:
2892       output_constant (TREE_REALPART (exp), size / 2);
2893       output_constant (TREE_IMAGPART (exp), size / 2);
2894       size -= (size / 2) * 2;
2895       break;
2896
2897     case ARRAY_TYPE:
2898       if (TREE_CODE (exp) == CONSTRUCTOR)
2899         {
2900           output_constructor (exp, size);
2901           return;
2902         }
2903       else if (TREE_CODE (exp) == STRING_CST)
2904         {
2905           int excess = 0;
2906
2907           if (size > TREE_STRING_LENGTH (exp))
2908             {
2909               excess = size - TREE_STRING_LENGTH (exp);
2910               size = TREE_STRING_LENGTH (exp);
2911             }
2912
2913           assemble_string (TREE_STRING_POINTER (exp), size);
2914           size = excess;
2915         }
2916       else
2917         abort ();
2918       break;
2919
2920     case RECORD_TYPE:
2921     case UNION_TYPE:
2922       if (TREE_CODE (exp) == CONSTRUCTOR)
2923         output_constructor (exp, size);
2924       else
2925         abort ();
2926       return;
2927     }
2928
2929   if (size > 0)
2930     assemble_zeros (size);
2931 }
2932 \f
2933 /* Subroutine of output_constant, used for CONSTRUCTORs
2934    (aggregate constants).
2935    Generate at least SIZE bytes, padding if necessary.  */
2936
2937 void
2938 output_constructor (exp, size)
2939      tree exp;
2940      int size;
2941 {
2942   register tree link, field = 0;
2943   /* Number of bytes output or skipped so far.
2944      In other words, current position within the constructor.  */
2945   int total_bytes = 0;
2946   /* Non-zero means BYTE contains part of a byte, to be output.  */
2947   int byte_buffer_in_use = 0;
2948   register int byte;
2949
2950   if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
2951     abort ();
2952
2953   if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2954     field = TYPE_FIELDS (TREE_TYPE (exp));
2955
2956   /* As LINK goes through the elements of the constant,
2957      FIELD goes through the structure fields, if the constant is a structure.
2958      if the constant is a union, then we override this,
2959      by getting the field from the TREE_LIST element.
2960      But the constant could also be an array.  Then FIELD is zero.  */
2961   for (link = CONSTRUCTOR_ELTS (exp);
2962        link;
2963        link = TREE_CHAIN (link),
2964        field = field ? TREE_CHAIN (field) : 0)
2965     {
2966       tree val = TREE_VALUE (link);
2967       /* the element in a union constructor specifies the proper field.  */
2968       if (TREE_PURPOSE (link) != 0)
2969         field = TREE_PURPOSE (link);
2970
2971       /* Eliminate the marker that makes a cast not be an lvalue.  */
2972       if (val != 0)
2973         STRIP_NOPS (val);
2974
2975       if (field == 0 || !DECL_BIT_FIELD (field))
2976         {
2977           register int fieldsize;
2978           /* Since this structure is static,
2979              we know the positions are constant.  */
2980           int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
2981                                  / BITS_PER_UNIT)
2982                         : 0);
2983
2984           /* An element that is not a bit-field.
2985              Output any buffered-up bit-fields preceding it.  */
2986           if (byte_buffer_in_use)
2987             {
2988               ASM_OUTPUT_BYTE (asm_out_file, byte);
2989               total_bytes++;
2990               byte_buffer_in_use = 0;
2991             }
2992
2993           /* Advance to offset of this element.
2994              Note no alignment needed in an array, since that is guaranteed
2995              if each element has the proper size.  */
2996           if (field != 0 && bitpos != total_bytes)
2997             {
2998               assemble_zeros (bitpos - total_bytes);
2999               total_bytes = bitpos;
3000             }
3001
3002           /* Determine size this element should occupy.  */
3003           if (field)
3004             {
3005               if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3006                 abort ();
3007               if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3008                 {
3009                   /* This avoids overflow trouble.  */
3010                   tree size_tree = size_binop (CEIL_DIV_EXPR,
3011                                                DECL_SIZE (field),
3012                                                size_int (BITS_PER_UNIT));
3013                   fieldsize = TREE_INT_CST_LOW (size_tree);
3014                 }
3015               else
3016                 {
3017                   fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3018                   fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3019                 }
3020             }
3021           else
3022             fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3023
3024           /* Output the element's initial value.  */
3025           if (val == 0)
3026             assemble_zeros (fieldsize);
3027           else
3028             output_constant (val, fieldsize);
3029
3030           /* Count its size.  */
3031           total_bytes += fieldsize;
3032         }
3033       else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3034         error ("invalid initial value for member `%s'",
3035                IDENTIFIER_POINTER (DECL_NAME (field)));
3036       else
3037         {
3038           /* Element that is a bit-field.  */
3039
3040           int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3041           int end_offset
3042             = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3043
3044           if (val == 0)
3045             val = integer_zero_node;
3046
3047           /* If this field does not start in this (or, next) byte,
3048              skip some bytes.  */
3049           if (next_offset / BITS_PER_UNIT != total_bytes)
3050             {
3051               /* Output remnant of any bit field in previous bytes.  */
3052               if (byte_buffer_in_use)
3053                 {
3054                   ASM_OUTPUT_BYTE (asm_out_file, byte);
3055                   total_bytes++;
3056                   byte_buffer_in_use = 0;
3057                 }
3058
3059               /* If still not at proper byte, advance to there.  */
3060               if (next_offset / BITS_PER_UNIT != total_bytes)
3061                 {
3062                   assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3063                   total_bytes = next_offset / BITS_PER_UNIT;
3064                 }
3065             }
3066
3067           if (! byte_buffer_in_use)
3068             byte = 0;
3069
3070           /* We must split the element into pieces that fall within
3071              separate bytes, and combine each byte with previous or
3072              following bit-fields.  */
3073
3074           /* next_offset is the offset n fbits from the beginning of
3075              the structure to the next bit of this element to be processed.
3076              end_offset is the offset of the first bit past the end of
3077              this element.  */
3078           while (next_offset < end_offset)
3079             {
3080               int this_time;
3081               int shift, value;
3082               int next_byte = next_offset / BITS_PER_UNIT;
3083               int next_bit = next_offset % BITS_PER_UNIT;
3084
3085               /* Advance from byte to byte
3086                  within this element when necessary.  */
3087               while (next_byte != total_bytes)
3088                 {
3089                   ASM_OUTPUT_BYTE (asm_out_file, byte);
3090                   total_bytes++;
3091                   byte = 0;
3092                 }
3093
3094               /* Number of bits we can process at once
3095                  (all part of the same byte).  */
3096               this_time = MIN (end_offset - next_offset,
3097                                BITS_PER_UNIT - next_bit);
3098 #if BYTES_BIG_ENDIAN
3099               /* On big-endian machine, take the most significant bits
3100                  first (of the bits that are significant)
3101                  and put them into bytes from the most significant end.  */
3102               shift = end_offset - next_offset - this_time;
3103               /* Don't try to take a bunch of bits that cross
3104                  the word boundary in the INTEGER_CST.  */
3105               if (shift < HOST_BITS_PER_WIDE_INT
3106                   && shift + this_time > HOST_BITS_PER_WIDE_INT)
3107                 {
3108                   this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3109                   shift = HOST_BITS_PER_WIDE_INT;
3110                 }
3111
3112               /* Now get the bits from the appropriate constant word.  */
3113               if (shift < HOST_BITS_PER_WIDE_INT)
3114                 {
3115                   value = TREE_INT_CST_LOW (val);
3116                 }
3117               else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3118                 {
3119                   value = TREE_INT_CST_HIGH (val);
3120                   shift -= HOST_BITS_PER_WIDE_INT;
3121                 }
3122               else
3123                 abort ();
3124               byte |= (((value >> shift)
3125                         & (((HOST_WIDE_INT) 1 << this_time) - 1))
3126                        << (BITS_PER_UNIT - this_time - next_bit));
3127 #else
3128               /* On little-endian machines,
3129                  take first the least significant bits of the value
3130                  and pack them starting at the least significant
3131                  bits of the bytes.  */
3132               shift = (next_offset
3133                        - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3134               /* Don't try to take a bunch of bits that cross
3135                  the word boundary in the INTEGER_CST.  */
3136               if (shift < HOST_BITS_PER_WIDE_INT
3137                   && shift + this_time > HOST_BITS_PER_WIDE_INT)
3138                 {
3139                   this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3140                   shift = HOST_BITS_PER_WIDE_INT;
3141                 }
3142
3143               /* Now get the bits from the appropriate constant word.  */
3144               if (shift < HOST_BITS_PER_INT)
3145                 value = TREE_INT_CST_LOW (val);
3146               else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3147                 {
3148                   value = TREE_INT_CST_HIGH (val);
3149                   shift -= HOST_BITS_PER_WIDE_INT;
3150                 }
3151               else
3152                 abort ();
3153               byte |= ((value >> shift)
3154                        & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
3155 #endif
3156               next_offset += this_time;
3157               byte_buffer_in_use = 1;
3158             }
3159         }
3160     }
3161   if (byte_buffer_in_use)
3162     {
3163       ASM_OUTPUT_BYTE (asm_out_file, byte);
3164       total_bytes++;
3165     }
3166   if (total_bytes < size)
3167     assemble_zeros (size - total_bytes);
3168 }