OSDN Git Service

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