OSDN Git Service

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