OSDN Git Service

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