OSDN Git Service

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