OSDN Git Service

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