OSDN Git Service

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