OSDN Git Service

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