OSDN Git Service

(assemble_variable): Set last_assemble_variable_decl.
[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   /* Compute and output the alignment of this data.  */
1148
1149   align = DECL_ALIGN (decl);
1150   /* In the case for initialing an array whose length isn't specified,
1151      where we have not yet been able to do the layout,
1152      figure out the proper alignment now.  */
1153   if (dont_output_data && DECL_SIZE (decl) == 0
1154       && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1155     align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1156
1157   /* Some object file formats have a maximum alignment which they support.
1158      In particular, a.out format supports a maximum alignment of 4.  */
1159 #ifndef MAX_OFILE_ALIGNMENT
1160 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1161 #endif
1162   if (align > MAX_OFILE_ALIGNMENT)
1163     {
1164       warning_with_decl (decl,
1165           "alignment of `%s' is greater than maximum object file alignment");
1166       align = MAX_OFILE_ALIGNMENT;
1167     }
1168 #ifdef DATA_ALIGNMENT
1169   /* On some machines, it is good to increase alignment sometimes.  */
1170   align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1171 #endif
1172 #ifdef CONSTANT_ALIGNMENT
1173   if (DECL_INITIAL (decl))
1174     align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1175 #endif
1176
1177   /* Reset the alignment in case we have made it tighter, so we can benefit
1178      from it in get_pointer_alignment.  */
1179   DECL_ALIGN (decl) = align;
1180
1181   if (align > BITS_PER_UNIT)
1182     {
1183       if (output_bytecode)
1184         BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1185       else
1186         ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1187     }
1188
1189   /* Do any machine/system dependent processing of the object.  */
1190 #ifdef ASM_DECLARE_OBJECT_NAME
1191   last_assemble_variable_decl = decl;
1192   ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1193 #else
1194   /* Standard thing is just output label for the object.  */
1195   if (output_bytecode)
1196     BC_OUTPUT_LABEL (asm_out_file, name);
1197   else
1198     ASM_OUTPUT_LABEL (asm_out_file, name);
1199 #endif /* ASM_DECLARE_OBJECT_NAME */
1200
1201   if (!dont_output_data)
1202     {
1203       if (DECL_INITIAL (decl))
1204         /* Output the actual data.  */
1205         output_constant (DECL_INITIAL (decl),
1206                          int_size_in_bytes (TREE_TYPE (decl)));
1207       else
1208         /* Leave space for it.  */
1209         assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1210     }
1211
1212  finish:
1213 #ifdef XCOFF_DEBUGGING_INFO
1214   /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1215      declaration.  When something like ".stabx  "aa:S-2",aa,133,0" is emitted 
1216      and `aa' hasn't been output yet, the assembler generates a stab entry with
1217      a value of zero, in addition to creating an unnecessary external entry
1218      for `aa'.  Hence, we must postpone dbxout_symbol to here at the end.  */
1219
1220   /* File-scope global variables are output here.  */
1221   if (write_symbols == XCOFF_DEBUG && top_level)
1222     {
1223       saved_in_section = in_section;
1224
1225       dbxout_symbol (decl, 0);
1226
1227       if (in_section != saved_in_section)
1228         {
1229           /* Switch to the proper section for this data.  */
1230 #ifdef SELECT_SECTION
1231           SELECT_SECTION (decl, reloc);
1232 #else
1233           if (TREE_READONLY (decl)
1234               && ! TREE_THIS_VOLATILE (decl)
1235               && ! (flag_pic && reloc))
1236             readonly_data_section ();
1237           else
1238             data_section ();
1239 #endif
1240         }
1241     }
1242 #else
1243   /* There must be a statement after a label.  */
1244   ;
1245 #endif
1246 }
1247
1248 /* Return 1 if type TYPE contains any pointers.  */
1249
1250 static int
1251 contains_pointers_p (type)
1252      tree type;
1253 {
1254   switch (TREE_CODE (type))
1255     {
1256     case POINTER_TYPE:
1257     case REFERENCE_TYPE:
1258       /* I'm not sure whether OFFSET_TYPE needs this treatment,
1259          so I'll play safe and return 1.  */
1260     case OFFSET_TYPE:
1261       return 1;
1262
1263     case RECORD_TYPE:
1264     case UNION_TYPE:
1265     case QUAL_UNION_TYPE:
1266       {
1267         tree fields;
1268         /* For a type that has fields, see if the fields have pointers.  */
1269         for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1270           if (contains_pointers_p (TREE_TYPE (fields)))
1271             return 1;
1272         return 0;
1273       }
1274
1275     case ARRAY_TYPE:
1276       /* An array type contains pointers if its element type does.  */
1277       return contains_pointers_p (TREE_TYPE (type));
1278
1279     default:
1280       return 0;
1281     }
1282 }
1283
1284 /* Output text storage for constructor CONSTR.  Returns rtx of
1285    storage. */
1286
1287 rtx
1288 bc_output_constructor (constr)
1289   tree constr;
1290 {
1291   int i;
1292
1293   /* Must always be a literal; non-literal constructors are handled
1294      differently. */
1295
1296   if (!TREE_CONSTANT (constr))
1297     abort ();
1298
1299   /* Always const */
1300   text_section ();
1301
1302   /* Align */
1303   for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1304   if (i > 0)
1305     BC_OUTPUT_ALIGN (asm_out_file, i);
1306
1307   /* Output data */
1308   output_constant (constr, int_size_in_bytes (TREE_TYPE (constr)));
1309 }
1310
1311
1312 /* Create storage for constructor CONSTR. */
1313
1314 void
1315 bc_output_data_constructor (constr)
1316     tree constr;
1317 {
1318   int i;
1319
1320   /* Put in data section */
1321   data_section ();
1322
1323   /* Align */
1324   for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1325   if (i > 0)
1326     BC_OUTPUT_ALIGN (asm_out_file, i);
1327
1328   /* The constructor is filled in at runtime. */
1329   BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1330 }
1331
1332
1333 /* Output something to declare an external symbol to the assembler.
1334    (Most assemblers don't need this, so we normally output nothing.)
1335    Do nothing if DECL is not external.  */
1336
1337 void
1338 assemble_external (decl)
1339      tree decl;
1340 {
1341   if (output_bytecode)
1342     return;
1343
1344 #ifdef ASM_OUTPUT_EXTERNAL
1345   if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1346       && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1347     {
1348       rtx rtl = DECL_RTL (decl);
1349
1350       if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1351           && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1352         {
1353           /* Some systems do require some output.  */
1354           SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1355           ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1356         }
1357     }
1358 #endif
1359 }
1360
1361 /* Similar, for calling a library function FUN.  */
1362
1363 void
1364 assemble_external_libcall (fun)
1365      rtx fun;
1366 {
1367 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1368   if (!output_bytecode)
1369     {
1370       /* Declare library function name external when first used, if nec.  */
1371       if (! SYMBOL_REF_USED (fun))
1372         {
1373           SYMBOL_REF_USED (fun) = 1;
1374           ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1375         }
1376     }
1377 #endif
1378 }
1379
1380 /* Declare the label NAME global.  */
1381
1382 void
1383 assemble_global (name)
1384      char *name;
1385 {
1386   ASM_GLOBALIZE_LABEL (asm_out_file, name);
1387 }
1388
1389 /* Assemble a label named NAME.  */
1390
1391 void
1392 assemble_label (name)
1393      char *name;
1394 {
1395   if (output_bytecode)
1396     BC_OUTPUT_LABEL (asm_out_file, name);
1397   else
1398     ASM_OUTPUT_LABEL (asm_out_file, name);
1399 }
1400
1401 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1402    If NAME starts with a *, the rest of NAME is output verbatim.
1403    Otherwise NAME is transformed in an implementation-defined way
1404    (usually by the addition of an underscore).
1405    Many macros in the tm file are defined to call this function.  */
1406
1407 void
1408 assemble_name (file, name)
1409      FILE *file;
1410      char *name;
1411 {
1412   if (name[0] == '*')
1413     {
1414       if (output_bytecode)
1415         bc_emit_labelref (name);
1416       else
1417         fputs (&name[1], file);
1418     }
1419   else
1420     {
1421       if (output_bytecode)
1422         BC_OUTPUT_LABELREF (file, name);
1423       else
1424         ASM_OUTPUT_LABELREF (file, name);
1425     }
1426 }
1427
1428 /* Allocate SIZE bytes writable static space with a gensym name
1429    and return an RTX to refer to its address.  */
1430
1431 rtx
1432 assemble_static_space (size)
1433      int size;
1434 {
1435   char name[12];
1436   char *namestring;
1437   rtx x;
1438   /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1439      so that each uninitialized object starts on such a boundary.  */
1440   int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1441                  / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1442                  * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1443
1444 #if 0
1445   if (flag_shared_data)
1446     data_section ();
1447 #endif
1448
1449   ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1450   ++const_labelno;
1451
1452   namestring = (char *) obstack_alloc (saveable_obstack,
1453                                        strlen (name) + 2);
1454   strcpy (namestring, name);
1455
1456   if (output_bytecode)
1457     x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1458   else
1459     x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1460
1461   if (output_bytecode)
1462     {
1463       BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1464     }
1465   else
1466     {
1467 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1468       ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1469 #else
1470       ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1471 #endif
1472     }
1473   return x;
1474 }
1475
1476 /* Assemble the static constant template for function entry trampolines.
1477    This is done at most once per compilation.
1478    Returns an RTX for the address of the template.  */
1479
1480 rtx
1481 assemble_trampoline_template ()
1482 {
1483   char label[256];
1484   char *name;
1485   int align;
1486
1487   /* Shouldn't get here */
1488   if (output_bytecode)
1489     abort ();
1490
1491   /* By default, put trampoline templates in read-only data section.  */
1492
1493 #ifdef TRAMPOLINE_SECTION
1494   TRAMPOLINE_SECTION ();
1495 #else
1496   readonly_data_section ();
1497 #endif
1498
1499   /* Write the assembler code to define one.  */
1500   align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1501   if (align > 0)
1502     ASM_OUTPUT_ALIGN (asm_out_file, align);
1503
1504   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1505   TRAMPOLINE_TEMPLATE (asm_out_file);
1506
1507   /* Record the rtl to refer to it.  */
1508   ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1509   name
1510     = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1511   return gen_rtx (SYMBOL_REF, Pmode, name);
1512 }
1513 \f
1514 /* Assemble the integer constant X into an object of SIZE bytes.
1515    X must be either a CONST_INT or CONST_DOUBLE.
1516
1517    Return 1 if we were able to output the constant, otherwise 0.  If FORCE is
1518    non-zero, abort if we can't output the constant.  */
1519
1520 int
1521 assemble_integer (x, size, force)
1522      rtx x;
1523      int size;
1524      int force;
1525 {
1526   /* First try to use the standard 1, 2, 4, 8, and 16 byte
1527      ASM_OUTPUT... macros. */
1528
1529   switch (size)
1530     {
1531 #ifdef ASM_OUTPUT_CHAR
1532     case 1:
1533       ASM_OUTPUT_CHAR (asm_out_file, x);
1534       return 1;
1535 #endif
1536
1537 #ifdef ASM_OUTPUT_SHORT
1538     case 2:
1539       ASM_OUTPUT_SHORT (asm_out_file, x);
1540       return 1;
1541 #endif
1542
1543 #ifdef ASM_OUTPUT_INT
1544     case 4:
1545       ASM_OUTPUT_INT (asm_out_file, x);
1546       return 1;
1547 #endif
1548
1549 #ifdef ASM_OUTPUT_DOUBLE_INT
1550     case 8:
1551       ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1552       return 1;
1553 #endif
1554
1555 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1556     case 16:
1557       ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1558       return 1;
1559 #endif
1560     }
1561
1562   /* If we couldn't do it that way, there are two other possibilities: First,
1563      if the machine can output an explicit byte and this is a 1 byte constant,
1564      we can use ASM_OUTPUT_BYTE.  */
1565
1566 #ifdef ASM_OUTPUT_BYTE
1567   if (size == 1 && GET_CODE (x) == CONST_INT)
1568     {
1569       ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1570       return 1;
1571     }
1572 #endif
1573
1574   /* Finally, if SIZE is larger than a single word, try to output the constant
1575      one word at a time.  */
1576
1577   if (size > UNITS_PER_WORD)
1578     {
1579       int i;
1580       enum machine_mode mode
1581         = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1582       rtx word;
1583
1584       for (i = 0; i < size / UNITS_PER_WORD; i++)
1585         {
1586           word = operand_subword (x, i, 0, mode);
1587
1588           if (word == 0)
1589             break;
1590
1591           if (! assemble_integer (word, UNITS_PER_WORD, 0))
1592             break;
1593         }
1594
1595       if (i == size / UNITS_PER_WORD)
1596         return 1;
1597       /* If we output at least one word and then could not finish,
1598          there is no valid way to continue.  */
1599       if (i > 0)
1600         abort ();
1601     }
1602
1603   if (force)
1604     abort ();
1605
1606   return 0;
1607 }
1608 \f
1609 /* Assemble the floating-point constant D into an object of size MODE.  */
1610
1611 void
1612 assemble_real (d, mode)
1613      REAL_VALUE_TYPE d;
1614      enum machine_mode mode;
1615 {
1616   jmp_buf output_constant_handler;
1617
1618   if (setjmp (output_constant_handler))
1619     {
1620       error ("floating point trap outputting a constant");
1621 #ifdef REAL_IS_NOT_DOUBLE
1622       bzero (&d, sizeof d);
1623       d = dconst0;
1624 #else
1625       d = 0;
1626 #endif
1627     }
1628
1629   set_float_handler (output_constant_handler);
1630
1631   switch (mode)
1632     {
1633 #ifdef ASM_OUTPUT_BYTE_FLOAT
1634     case QFmode:
1635       ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1636       break;
1637 #endif
1638 #ifdef ASM_OUTPUT_SHORT_FLOAT
1639     case HFmode:
1640       ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1641       break;
1642 #endif
1643 #ifdef ASM_OUTPUT_FLOAT
1644     case SFmode:
1645       ASM_OUTPUT_FLOAT (asm_out_file, d);
1646       break;
1647 #endif
1648
1649 #ifdef ASM_OUTPUT_DOUBLE
1650     case DFmode:
1651       ASM_OUTPUT_DOUBLE (asm_out_file, d);
1652       break;
1653 #endif
1654
1655 #ifdef ASM_OUTPUT_LONG_DOUBLE
1656     case XFmode:
1657     case TFmode:
1658       ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1659       break;
1660 #endif
1661
1662     default:
1663       abort ();
1664     }
1665
1666   set_float_handler (NULL_PTR);
1667 }
1668 \f
1669 /* Here we combine duplicate floating constants to make
1670    CONST_DOUBLE rtx's, and force those out to memory when necessary.  */
1671
1672 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1673    They are chained through the CONST_DOUBLE_CHAIN.
1674    A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1675    In that case, CONST_DOUBLE_MEM is either a MEM,
1676    or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1677
1678    (CONST_DOUBLE_MEM is used only for top-level functions.
1679    See force_const_mem for explanation.)  */
1680
1681 static rtx const_double_chain;
1682
1683 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1684    For an integer, I0 is the low-order word and I1 is the high-order word.
1685    For a real number, I0 is the word with the low address
1686    and I1 is the word with the high address.  */
1687
1688 rtx
1689 immed_double_const (i0, i1, mode)
1690      HOST_WIDE_INT i0, i1;
1691      enum machine_mode mode;
1692 {
1693   register rtx r;
1694   int in_current_obstack;
1695
1696   if (GET_MODE_CLASS (mode) == MODE_INT
1697       || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1698     {
1699       /* We clear out all bits that don't belong in MODE, unless they and our
1700          sign bit are all one.  So we get either a reasonable negative value
1701          or a reasonable unsigned value for this mode.  */
1702       int width = GET_MODE_BITSIZE (mode);
1703       if (width < HOST_BITS_PER_WIDE_INT
1704           && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1705               != ((HOST_WIDE_INT) (-1) << (width - 1))))
1706         i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1707       else if (width == HOST_BITS_PER_WIDE_INT
1708                && ! (i1 == ~0 && i0 < 0))
1709         i1 = 0;
1710       else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1711         /* We cannot represent this value as a constant.  */
1712         abort ();
1713
1714       /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1715
1716          ??? Strictly speaking, this is wrong if we create a CONST_INT
1717          for a large unsigned constant with the size of MODE being
1718          HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1719          wider mode.  In that case we will mis-interpret it as a negative
1720          number.
1721
1722          Unfortunately, the only alternative is to make a CONST_DOUBLE
1723          for any constant in any mode if it is an unsigned constant larger
1724          than the maximum signed integer in an int on the host.  However,
1725          doing this will break everyone that always expects to see a CONST_INT
1726          for SImode and smaller.
1727
1728          We have always been making CONST_INTs in this case, so nothing new
1729          is being broken.  */
1730
1731       if (width <= HOST_BITS_PER_WIDE_INT)
1732         i1 = (i0 < 0) ? ~0 : 0;
1733
1734       /* If this integer fits in one word, return a CONST_INT.  */
1735       if ((i1 == 0 && i0 >= 0)
1736           || (i1 == ~0 && i0 < 0))
1737         return GEN_INT (i0);
1738
1739       /* We use VOIDmode for integers.  */
1740       mode = VOIDmode;
1741     }
1742
1743   /* Search the chain for an existing CONST_DOUBLE with the right value.
1744      If one is found, return it.  */
1745
1746   for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1747     if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1748         && GET_MODE (r) == mode)
1749       return r;
1750
1751   /* No; make a new one and add it to the chain.
1752
1753      We may be called by an optimizer which may be discarding any memory
1754      allocated during its processing (such as combine and loop).  However,
1755      we will be leaving this constant on the chain, so we cannot tolerate
1756      freed memory.  So switch to saveable_obstack for this allocation
1757      and then switch back if we were in current_obstack.  */
1758
1759   push_obstacks_nochange ();
1760   rtl_in_saveable_obstack ();
1761   r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1762   pop_obstacks ();
1763
1764   /* Don't touch const_double_chain in nested function; see force_const_mem.
1765      Also, don't touch it if not inside any function.  */
1766   if (outer_function_chain == 0 && current_function_decl != 0)
1767     {
1768       CONST_DOUBLE_CHAIN (r) = const_double_chain;
1769       const_double_chain = r;
1770     }
1771
1772   /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1773      Actual use of mem-slot is only through force_const_mem.  */
1774
1775   CONST_DOUBLE_MEM (r) = const0_rtx;
1776
1777   return r;
1778 }
1779
1780 /* Return a CONST_DOUBLE for a specified `double' value
1781    and machine mode.  */
1782
1783 rtx
1784 immed_real_const_1 (d, mode)
1785      REAL_VALUE_TYPE d;
1786      enum machine_mode mode;
1787 {
1788   union real_extract u;
1789   register rtx r;
1790   int in_current_obstack;
1791
1792   /* Get the desired `double' value as a sequence of ints
1793      since that is how they are stored in a CONST_DOUBLE.  */
1794
1795   u.d = d;
1796
1797   /* Detect special cases.  */
1798
1799   /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero.  */
1800   if (!bcmp (&dconst0, &d, sizeof d))
1801     return CONST0_RTX (mode);
1802   /* Check for NaN first, because some ports (specifically the i386) do not
1803      emit correct ieee-fp code by default, and thus will generate a core
1804      dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1805      does a floating point comparison.  */
1806   else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1807     return CONST1_RTX (mode);
1808
1809   if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1810     return immed_double_const (u.i[0], u.i[1], mode);
1811
1812   /* The rest of this function handles the case where
1813      a float value requires more than 2 ints of space.
1814      It will be deleted as dead code on machines that don't need it.  */
1815
1816   /* Search the chain for an existing CONST_DOUBLE with the right value.
1817      If one is found, return it.  */
1818
1819   for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1820     if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
1821         && GET_MODE (r) == mode)
1822       return r;
1823
1824   /* No; make a new one and add it to the chain.
1825
1826      We may be called by an optimizer which may be discarding any memory
1827      allocated during its processing (such as combine and loop).  However,
1828      we will be leaving this constant on the chain, so we cannot tolerate
1829      freed memory.  So switch to saveable_obstack for this allocation
1830      and then switch back if we were in current_obstack.  */
1831
1832   push_obstacks_nochange ();
1833   rtl_in_saveable_obstack ();
1834   r = rtx_alloc (CONST_DOUBLE);
1835   PUT_MODE (r, mode);
1836   bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
1837   pop_obstacks ();
1838
1839   /* Don't touch const_double_chain in nested function; see force_const_mem.
1840      Also, don't touch it if not inside any function.  */
1841   if (outer_function_chain == 0 && current_function_decl != 0)
1842     {
1843       CONST_DOUBLE_CHAIN (r) = const_double_chain;
1844       const_double_chain = r;
1845     }
1846
1847   /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1848      chain, but has not been allocated memory.  Actual use of CONST_DOUBLE_MEM
1849      is only through force_const_mem.  */
1850
1851   CONST_DOUBLE_MEM (r) = const0_rtx;
1852
1853   return r;
1854 }
1855
1856 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1857    which must be a REAL_CST tree node.  */
1858
1859 rtx
1860 immed_real_const (exp)
1861      tree exp;
1862 {
1863   return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1864 }
1865
1866 /* At the end of a function, forget the memory-constants
1867    previously made for CONST_DOUBLEs.  Mark them as not on real_constant_chain.
1868    Also clear out real_constant_chain and clear out all the chain-pointers.  */
1869
1870 void
1871 clear_const_double_mem ()
1872 {
1873   register rtx r, next;
1874
1875   /* Don't touch CONST_DOUBLE_MEM for nested functions.
1876      See force_const_mem for explanation.  */
1877   if (outer_function_chain != 0)
1878     return;
1879
1880   for (r = const_double_chain; r; r = next)
1881     {
1882       next = CONST_DOUBLE_CHAIN (r);
1883       CONST_DOUBLE_CHAIN (r) = 0;
1884       CONST_DOUBLE_MEM (r) = cc0_rtx;
1885     }
1886   const_double_chain = 0;
1887 }
1888 \f
1889 /* Given an expression EXP with a constant value,
1890    reduce it to the sum of an assembler symbol and an integer.
1891    Store them both in the structure *VALUE.
1892    Abort if EXP does not reduce.  */
1893
1894 struct addr_const
1895 {
1896   rtx base;
1897   HOST_WIDE_INT offset;
1898 };
1899
1900 static void
1901 decode_addr_const (exp, value)
1902      tree exp;
1903      struct addr_const *value;
1904 {
1905   register tree target = TREE_OPERAND (exp, 0);
1906   register int offset = 0;
1907   register rtx x;
1908
1909   while (1)
1910     {
1911       if (TREE_CODE (target) == COMPONENT_REF
1912           && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
1913               == INTEGER_CST))
1914         {
1915           offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
1916           target = TREE_OPERAND (target, 0);
1917         }
1918       else if (TREE_CODE (target) == ARRAY_REF)
1919         {
1920           if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
1921               || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
1922             abort ();
1923           offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
1924                       * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
1925                      / BITS_PER_UNIT);
1926           target = TREE_OPERAND (target, 0);
1927         }
1928       else
1929         break;
1930     }
1931
1932   switch (TREE_CODE (target))
1933     {
1934     case VAR_DECL:
1935     case FUNCTION_DECL:
1936       x = DECL_RTL (target);
1937       break;
1938
1939     case LABEL_DECL:
1940       if (output_bytecode)
1941         /* FIXME: this may not be correct, check it */
1942         x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
1943       else
1944         x = gen_rtx (MEM, FUNCTION_MODE,
1945                      gen_rtx (LABEL_REF, VOIDmode,
1946                               label_rtx (TREE_OPERAND (exp, 0))));
1947       break;
1948
1949     case REAL_CST:
1950     case STRING_CST:
1951     case COMPLEX_CST:
1952     case CONSTRUCTOR:
1953       x = TREE_CST_RTL (target);
1954       break;
1955
1956     default:
1957       abort ();
1958     }
1959
1960   if (!output_bytecode)
1961     {
1962       if (GET_CODE (x) != MEM)
1963         abort ();
1964       x = XEXP (x, 0);
1965     }
1966
1967   value->base = x;
1968   value->offset = offset;
1969 }
1970 \f
1971 /* Uniquize all constants that appear in memory.
1972    Each constant in memory thus far output is recorded
1973    in `const_hash_table' with a `struct constant_descriptor'
1974    that contains a polish representation of the value of
1975    the constant.
1976
1977    We cannot store the trees in the hash table
1978    because the trees may be temporary.  */
1979
1980 struct constant_descriptor
1981 {
1982   struct constant_descriptor *next;
1983   char *label;
1984   char contents[1];
1985 };
1986
1987 #define HASHBITS 30
1988 #define MAX_HASH_TABLE 1009
1989 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
1990
1991 /* Compute a hash code for a constant expression.  */
1992
1993 int
1994 const_hash (exp)
1995      tree exp;
1996 {
1997   register char *p;
1998   register int len, hi, i;
1999   register enum tree_code code = TREE_CODE (exp);
2000
2001   if (code == INTEGER_CST)
2002     {
2003       p = (char *) &TREE_INT_CST_LOW (exp);
2004       len = 2 * sizeof TREE_INT_CST_LOW (exp);
2005     }
2006   else if (code == REAL_CST)
2007     {
2008       p = (char *) &TREE_REAL_CST (exp);
2009       len = sizeof TREE_REAL_CST (exp);
2010     }
2011   else if (code == STRING_CST)
2012     p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2013   else if (code == COMPLEX_CST)
2014     return const_hash (TREE_REALPART (exp)) * 5
2015       + const_hash (TREE_IMAGPART (exp));
2016   else if (code == CONSTRUCTOR)
2017     {
2018       register tree link;
2019
2020       /* For record type, include the type in the hashing.
2021          We do not do so for array types
2022          because (1) the sizes of the elements are sufficient
2023          and (2) distinct array types can have the same constructor.
2024          Instead, we include the array size because the constructor could
2025          be shorter.  */
2026       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2027         hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2028           % MAX_HASH_TABLE;
2029       else
2030         hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2031                & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2032
2033       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2034         if (TREE_VALUE (link))
2035           hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2036
2037       return hi;
2038     }
2039   else if (code == ADDR_EXPR)
2040     {
2041       struct addr_const value;
2042       decode_addr_const (exp, &value);
2043       if (GET_CODE (value.base) == SYMBOL_REF)
2044         {
2045           /* Don't hash the address of the SYMBOL_REF;
2046              only use the offset and the symbol name.  */
2047           hi = value.offset;
2048           p = XSTR (value.base, 0);
2049           for (i = 0; p[i] != 0; i++)
2050             hi = ((hi * 613) + (unsigned)(p[i]));
2051         }
2052       else if (GET_CODE (value.base) == LABEL_REF)
2053         hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2054
2055       hi &= (1 << HASHBITS) - 1;
2056       hi %= MAX_HASH_TABLE;
2057       return hi;
2058     }
2059   else if (code == PLUS_EXPR || code == MINUS_EXPR)
2060     return const_hash (TREE_OPERAND (exp, 0)) * 9
2061       +  const_hash (TREE_OPERAND (exp, 1));
2062   else if (code == NOP_EXPR || code == CONVERT_EXPR)
2063     return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2064
2065   /* Compute hashing function */
2066   hi = len;
2067   for (i = 0; i < len; i++)
2068     hi = ((hi * 613) + (unsigned)(p[i]));
2069
2070   hi &= (1 << HASHBITS) - 1;
2071   hi %= MAX_HASH_TABLE;
2072   return hi;
2073 }
2074 \f
2075 /* Compare a constant expression EXP with a constant-descriptor DESC.
2076    Return 1 if DESC describes a constant with the same value as EXP.  */
2077
2078 static int
2079 compare_constant (exp, desc)
2080      tree exp;
2081      struct constant_descriptor *desc;
2082 {
2083   return 0 != compare_constant_1 (exp, desc->contents);
2084 }
2085
2086 /* Compare constant expression EXP with a substring P of a constant descriptor.
2087    If they match, return a pointer to the end of the substring matched.
2088    If they do not match, return 0.
2089
2090    Since descriptors are written in polish prefix notation,
2091    this function can be used recursively to test one operand of EXP
2092    against a subdescriptor, and if it succeeds it returns the
2093    address of the subdescriptor for the next operand.  */
2094
2095 static char *
2096 compare_constant_1 (exp, p)
2097      tree exp;
2098      char *p;
2099 {
2100   register char *strp;
2101   register int len;
2102   register enum tree_code code = TREE_CODE (exp);
2103
2104   if (code != (enum tree_code) *p++)
2105     return 0;
2106
2107   if (code == INTEGER_CST)
2108     {
2109       /* Integer constants are the same only if the same width of type.  */
2110       if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2111         return 0;
2112       strp = (char *) &TREE_INT_CST_LOW (exp);
2113       len = 2 * sizeof TREE_INT_CST_LOW (exp);
2114     }
2115   else if (code == REAL_CST)
2116     {
2117       /* Real constants are the same only if the same width of type.  */
2118       if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2119         return 0;
2120       strp = (char *) &TREE_REAL_CST (exp);
2121       len = sizeof TREE_REAL_CST (exp);
2122     }
2123   else if (code == STRING_CST)
2124     {
2125       if (flag_writable_strings)
2126         return 0;
2127       strp = TREE_STRING_POINTER (exp);
2128       len = TREE_STRING_LENGTH (exp);
2129       if (bcmp (&TREE_STRING_LENGTH (exp), p,
2130                 sizeof TREE_STRING_LENGTH (exp)))
2131         return 0;
2132       p += sizeof TREE_STRING_LENGTH (exp);
2133     }
2134   else if (code == COMPLEX_CST)
2135     {
2136       p = compare_constant_1 (TREE_REALPART (exp), p);
2137       if (p == 0) return 0;
2138       p = compare_constant_1 (TREE_IMAGPART (exp), p);
2139       return p;
2140     }
2141   else if (code == CONSTRUCTOR)
2142     {
2143       register tree link;
2144       int length = list_length (CONSTRUCTOR_ELTS (exp));
2145       tree type;
2146
2147       if (bcmp (&length, p, sizeof length))
2148         return 0;
2149       p += sizeof length;
2150
2151       /* For record constructors, insist that the types match.
2152          For arrays, just verify both constructors are for arrays.  */
2153       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2154         type = TREE_TYPE (exp);
2155       else
2156         type = 0;
2157       if (bcmp (&type, p, sizeof type))
2158         return 0;
2159       p += sizeof type;
2160
2161       /* For arrays, insist that the size in bytes match.  */
2162       if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2163         {
2164           int size = int_size_in_bytes (TREE_TYPE (exp));
2165           if (bcmp (&size, p, sizeof size))
2166             return 0;
2167           p += sizeof size;
2168         }
2169
2170       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2171         {
2172           if (TREE_VALUE (link))
2173             {
2174               if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2175                 return 0;
2176             }
2177           else
2178             {
2179               tree zero = 0;
2180
2181               if (bcmp (&zero, p, sizeof zero))
2182                 return 0;
2183               p += sizeof zero;
2184             }
2185         }
2186
2187       return p;
2188     }
2189   else if (code == ADDR_EXPR)
2190     {
2191       struct addr_const value;
2192       decode_addr_const (exp, &value);
2193       strp = (char *) &value.offset;
2194       len = sizeof value.offset;
2195       /* Compare the offset.  */
2196       while (--len >= 0)
2197         if (*p++ != *strp++)
2198           return 0;
2199       /* Compare symbol name.  */
2200       strp = XSTR (value.base, 0);
2201       len = strlen (strp) + 1;
2202     }
2203   else if (code == PLUS_EXPR || code == MINUS_EXPR)
2204     {
2205       p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2206       if (p == 0) return 0;
2207       p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2208       return p;
2209     }
2210   else if (code == NOP_EXPR || code == CONVERT_EXPR)
2211     {
2212       p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2213       return p;
2214     }
2215
2216   /* Compare constant contents.  */
2217   while (--len >= 0)
2218     if (*p++ != *strp++)
2219       return 0;
2220
2221   return p;
2222 }
2223 \f
2224 /* Construct a constant descriptor for the expression EXP.
2225    It is up to the caller to enter the descriptor in the hash table.  */
2226
2227 static struct constant_descriptor *
2228 record_constant (exp)
2229      tree exp;
2230 {
2231   struct constant_descriptor *next = 0;
2232   char *label = 0;
2233
2234   /* Make a struct constant_descriptor.  The first two pointers will
2235      be filled in later.  Here we just leave space for them.  */
2236
2237   obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2238   obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2239   record_constant_1 (exp);
2240   return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2241 }
2242
2243 /* Add a description of constant expression EXP
2244    to the object growing in `permanent_obstack'.
2245    No need to return its address; the caller will get that
2246    from the obstack when the object is complete.  */
2247
2248 static void
2249 record_constant_1 (exp)
2250      tree exp;
2251 {
2252   register char *strp;
2253   register int len;
2254   register enum tree_code code = TREE_CODE (exp);
2255
2256   obstack_1grow (&permanent_obstack, (unsigned int) code);
2257
2258   if (code == INTEGER_CST)
2259     {
2260       obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2261       strp = (char *) &TREE_INT_CST_LOW (exp);
2262       len = 2 * sizeof TREE_INT_CST_LOW (exp);
2263     }
2264   else if (code == REAL_CST)
2265     {
2266       obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2267       strp = (char *) &TREE_REAL_CST (exp);
2268       len = sizeof TREE_REAL_CST (exp);
2269     }
2270   else if (code == STRING_CST)
2271     {
2272       if (flag_writable_strings)
2273         return;
2274       strp = TREE_STRING_POINTER (exp);
2275       len = TREE_STRING_LENGTH (exp);
2276       obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2277                     sizeof TREE_STRING_LENGTH (exp));
2278     }
2279   else if (code == COMPLEX_CST)
2280     {
2281       record_constant_1 (TREE_REALPART (exp));
2282       record_constant_1 (TREE_IMAGPART (exp));
2283       return;
2284     }
2285   else if (code == CONSTRUCTOR)
2286     {
2287       register tree link;
2288       int length = list_length (CONSTRUCTOR_ELTS (exp));
2289       tree type;
2290
2291       obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2292
2293       /* For record constructors, insist that the types match.
2294          For arrays, just verify both constructors are for arrays.  */
2295       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2296         type = TREE_TYPE (exp);
2297       else
2298         type = 0;
2299       obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2300
2301       /* For arrays, insist that the size in bytes match.  */
2302       if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2303         {
2304           int size = int_size_in_bytes (TREE_TYPE (exp));
2305           obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2306         }
2307
2308       for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2309         {
2310           if (TREE_VALUE (link))
2311             record_constant_1 (TREE_VALUE (link));
2312           else
2313             {
2314               tree zero = 0;
2315
2316               obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
2317             }
2318         }
2319
2320       return;
2321     }
2322   else if (code == ADDR_EXPR)
2323     {
2324       struct addr_const value;
2325       decode_addr_const (exp, &value);
2326       /* Record the offset.  */
2327       obstack_grow (&permanent_obstack,
2328                     (char *) &value.offset, sizeof value.offset);
2329       /* Record the symbol name.  */
2330       obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2331                     strlen (XSTR (value.base, 0)) + 1);
2332       return;
2333     }
2334   else if (code == PLUS_EXPR || code == MINUS_EXPR)
2335     {
2336       record_constant_1 (TREE_OPERAND (exp, 0));
2337       record_constant_1 (TREE_OPERAND (exp, 1));
2338       return;
2339     }
2340   else if (code == NOP_EXPR || code == CONVERT_EXPR)
2341     {
2342       record_constant_1 (TREE_OPERAND (exp, 0));
2343       return;
2344     }
2345
2346   /* Record constant contents.  */
2347   obstack_grow (&permanent_obstack, strp, len);
2348 }
2349 \f
2350 /* Record a list of constant expressions that were passed to
2351    output_constant_def but that could not be output right away.  */
2352
2353 struct deferred_constant
2354 {
2355   struct deferred_constant *next;
2356   tree exp;
2357   int reloc;
2358   int labelno;
2359 };
2360
2361 static struct deferred_constant *deferred_constants;
2362
2363 /* Nonzero means defer output of addressed subconstants
2364    (i.e., those for which output_constant_def is called.)  */
2365 static int defer_addressed_constants_flag;
2366
2367 /* Start deferring output of subconstants.  */
2368
2369 void
2370 defer_addressed_constants ()
2371 {
2372   defer_addressed_constants_flag++;
2373 }
2374
2375 /* Stop deferring output of subconstants,
2376    and output now all those that have been deferred.  */
2377
2378 void
2379 output_deferred_addressed_constants ()
2380 {
2381   struct deferred_constant *p, *next;
2382
2383   defer_addressed_constants_flag--;
2384
2385   if (defer_addressed_constants_flag > 0)
2386     return;
2387
2388   for (p = deferred_constants; p; p = next)
2389     {
2390       output_constant_def_contents (p->exp, p->reloc, p->labelno);
2391       next = p->next;
2392       free (p);
2393     }
2394
2395   deferred_constants = 0;
2396 }
2397
2398 /* Make a copy of the whole tree structure for a constant.
2399    This handles the same types of nodes that compare_constant
2400    and record_constant handle.  */
2401
2402 static tree
2403 copy_constant (exp)
2404      tree exp;
2405 {
2406   switch (TREE_CODE (exp))
2407     {
2408     case INTEGER_CST:
2409     case REAL_CST:
2410     case STRING_CST:
2411     case ADDR_EXPR:
2412       /* For ADDR_EXPR, we do not want to copy the decl
2413          whose address is requested.  */
2414       return copy_node (exp);
2415
2416     case COMPLEX_CST:
2417       return build_complex (copy_constant (TREE_REALPART (exp)),
2418                             copy_constant (TREE_IMAGPART (exp)));
2419
2420     case PLUS_EXPR:
2421     case MINUS_EXPR:
2422       return build (TREE_CODE (exp), TREE_TYPE (exp),
2423                     copy_constant (TREE_OPERAND (exp, 0)),
2424                     copy_constant (TREE_OPERAND (exp, 1)));
2425
2426     case NOP_EXPR:
2427     case CONVERT_EXPR:
2428       return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2429                      copy_constant (TREE_OPERAND (exp, 0)));
2430
2431     case CONSTRUCTOR:
2432       {
2433         tree copy = copy_node (exp);
2434         tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2435         tree tail;
2436
2437         CONSTRUCTOR_ELTS (exp) = list;
2438         for (tail = list; tail; tail = TREE_CHAIN (tail))
2439           TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2440
2441         return copy;
2442       }
2443
2444     default:
2445       abort ();
2446     }
2447 }
2448 \f
2449 /* Return an rtx representing a reference to constant data in memory
2450    for the constant expression EXP.
2451
2452    If assembler code for such a constant has already been output,
2453    return an rtx to refer to it.
2454    Otherwise, output such a constant in memory (or defer it for later)
2455    and generate an rtx for it.
2456
2457    The TREE_CST_RTL of EXP is set up to point to that rtx.
2458    The const_hash_table records which constants already have label strings.  */
2459
2460 rtx
2461 output_constant_def (exp)
2462      tree exp;
2463 {
2464   register int hash;
2465   register struct constant_descriptor *desc;
2466   char label[256];
2467   char *found = 0;
2468   int reloc;
2469   register rtx def;
2470
2471   if (TREE_CODE (exp) == INTEGER_CST)
2472     abort ();                   /* No TREE_CST_RTL slot in these.  */
2473
2474   if (TREE_CST_RTL (exp))
2475     return TREE_CST_RTL (exp);
2476
2477   /* Make sure any other constants whose addresses appear in EXP
2478      are assigned label numbers.  */
2479
2480   reloc = output_addressed_constants (exp);
2481
2482   /* Compute hash code of EXP.  Search the descriptors for that hash code
2483      to see if any of them describes EXP.  If yes, the descriptor records
2484      the label number already assigned.  */
2485
2486   if (!output_bytecode)
2487     {
2488       hash = const_hash (exp) % MAX_HASH_TABLE;
2489       
2490       for (desc = const_hash_table[hash]; desc; desc = desc->next)
2491         if (compare_constant (exp, desc))
2492           {
2493             found = desc->label;
2494             break;
2495           }
2496       
2497       if (found == 0)
2498         {
2499           /* No constant equal to EXP is known to have been output.
2500              Make a constant descriptor to enter EXP in the hash table.
2501              Assign the label number and record it in the descriptor for
2502              future calls to this function to find.  */
2503           
2504           /* Create a string containing the label name, in LABEL.  */
2505           ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2506           
2507           desc = record_constant (exp);
2508           desc->next = const_hash_table[hash];
2509           desc->label
2510             = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2511           const_hash_table[hash] = desc;
2512         }
2513       else
2514         {
2515           /* Create a string containing the label name, in LABEL.  */
2516           ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2517         }
2518     }
2519   
2520   /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
2521
2522   push_obstacks_nochange ();
2523   if (TREE_PERMANENT (exp))
2524     end_temporary_allocation ();
2525
2526   if (!output_bytecode)
2527     {
2528       def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2529       
2530       TREE_CST_RTL (exp)
2531         = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2532       RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2533       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
2534           || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2535         MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2536     }
2537   pop_obstacks ();
2538
2539   /* Optionally set flags or add text to the name to record information
2540      such as that it is a function name.  If the name is changed, the macro
2541      ASM_OUTPUT_LABELREF will have to know how to strip this information.
2542      And if it finds a * at the beginning after doing so, it must handle
2543      that too.  */
2544 #ifdef ENCODE_SECTION_INFO
2545   ENCODE_SECTION_INFO (exp);
2546 #endif
2547
2548   /* If this is the first time we've seen this particular constant,
2549      output it (or defer its output for later).  */
2550   if (found == 0)
2551     {
2552       if (defer_addressed_constants_flag)
2553         {
2554           struct deferred_constant *p;
2555           p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2556
2557           push_obstacks_nochange ();
2558           suspend_momentary ();
2559           p->exp = copy_constant (exp);
2560           pop_obstacks ();
2561           p->reloc = reloc;
2562           p->labelno = const_labelno++;
2563           p->next = deferred_constants;
2564           deferred_constants = p;
2565         }
2566       else
2567         output_constant_def_contents (exp, reloc, const_labelno++);
2568     }
2569
2570   return TREE_CST_RTL (exp);
2571 }
2572
2573 /* Now output assembler code to define the label for EXP,
2574    and follow it with the data of EXP.  */
2575
2576 static void
2577 output_constant_def_contents (exp, reloc, labelno)
2578      tree exp;
2579      int reloc;
2580      int labelno;
2581 {
2582   int align;
2583
2584   /* First switch to text section, except for writable strings.  */
2585 #ifdef SELECT_SECTION
2586   SELECT_SECTION (exp, reloc);
2587 #else
2588   if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2589       || (flag_pic && reloc))
2590     data_section ();
2591   else
2592     readonly_data_section ();
2593 #endif
2594
2595   /* Align the location counter as required by EXP's data type.  */
2596   align = TYPE_ALIGN (TREE_TYPE (exp));
2597 #ifdef CONSTANT_ALIGNMENT
2598   align = CONSTANT_ALIGNMENT (exp, align);
2599 #endif
2600
2601   if (align > BITS_PER_UNIT)
2602     {
2603       if (!output_bytecode)
2604         {
2605           ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2606         }
2607       else
2608         {
2609           BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2610         }
2611     }
2612
2613   /* Output the label itself.  */
2614   ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2615
2616   /* Output the value of EXP.  */
2617   output_constant (exp,
2618                    (TREE_CODE (exp) == STRING_CST
2619                     ? TREE_STRING_LENGTH (exp)
2620                     : int_size_in_bytes (TREE_TYPE (exp))));
2621
2622 }
2623 \f
2624 /* Similar hash facility for making memory-constants
2625    from constant rtl-expressions.  It is used on RISC machines
2626    where immediate integer arguments and constant addresses are restricted
2627    so that such constants must be stored in memory.
2628
2629    This pool of constants is reinitialized for each function
2630    so each function gets its own constants-pool that comes right before it.
2631
2632    All structures allocated here are discarded when functions are saved for
2633    inlining, so they do not need to be allocated permanently.  */
2634
2635 #define MAX_RTX_HASH_TABLE 61
2636 static struct constant_descriptor **const_rtx_hash_table;
2637
2638 /* Structure to represent sufficient information about a constant so that
2639    it can be output when the constant pool is output, so that function
2640    integration can be done, and to simplify handling on machines that reference
2641    constant pool as base+displacement.  */
2642
2643 struct pool_constant
2644 {
2645   struct constant_descriptor *desc;
2646   struct pool_constant *next;
2647   enum machine_mode mode;
2648   rtx constant;
2649   int labelno;
2650   int align;
2651   int offset;
2652 };
2653
2654 /* Pointers to first and last constant in pool.  */
2655
2656 static struct pool_constant *first_pool, *last_pool;
2657
2658 /* Current offset in constant pool (does not include any machine-specific
2659    header.  */
2660
2661 static int pool_offset;
2662
2663 /* Structure used to maintain hash table mapping symbols used to their
2664    corresponding constants.  */
2665
2666 struct pool_sym
2667 {
2668   char *label;
2669   struct pool_constant *pool;
2670   struct pool_sym *next;
2671 };
2672
2673 static struct pool_sym **const_rtx_sym_hash_table;
2674
2675 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2676    The argument is XSTR (... , 0)  */
2677
2678 #define SYMHASH(LABEL)  \
2679   ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1))  % MAX_RTX_HASH_TABLE)
2680 \f
2681 /* Initialize constant pool hashing for next function.  */
2682
2683 void
2684 init_const_rtx_hash_table ()
2685 {
2686   const_rtx_hash_table
2687     = ((struct constant_descriptor **)
2688        oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2689   const_rtx_sym_hash_table
2690     = ((struct pool_sym **)
2691        oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2692   bzero (const_rtx_hash_table,
2693          MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2694   bzero (const_rtx_sym_hash_table,
2695          MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2696
2697   first_pool = last_pool = 0;
2698   pool_offset = 0;
2699 }
2700
2701 /* Save and restore it for a nested function.  */
2702
2703 void
2704 save_varasm_status (p)
2705      struct function *p;
2706 {
2707   p->const_rtx_hash_table = const_rtx_hash_table;
2708   p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2709   p->first_pool = first_pool;
2710   p->last_pool = last_pool;
2711   p->pool_offset = pool_offset;
2712 }
2713
2714 void
2715 restore_varasm_status (p)
2716      struct function *p;
2717 {
2718   const_rtx_hash_table = p->const_rtx_hash_table;
2719   const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2720   first_pool = p->first_pool;
2721   last_pool = p->last_pool;
2722   pool_offset = p->pool_offset;
2723 }
2724 \f
2725 enum kind { RTX_DOUBLE, RTX_INT };
2726
2727 struct rtx_const
2728 {
2729 #ifdef ONLY_INT_FIELDS
2730   unsigned int kind : 16;
2731   unsigned int mode : 16;
2732 #else
2733   enum kind kind : 16;
2734   enum machine_mode mode : 16;
2735 #endif
2736   union {
2737     union real_extract du;
2738     struct addr_const addr;
2739   } un;
2740 };
2741
2742 /* Express an rtx for a constant integer (perhaps symbolic)
2743    as the sum of a symbol or label plus an explicit integer.
2744    They are stored into VALUE.  */
2745
2746 static void
2747 decode_rtx_const (mode, x, value)
2748      enum machine_mode mode;
2749      rtx x;
2750      struct rtx_const *value;
2751 {
2752   /* Clear the whole structure, including any gaps.  */
2753
2754   {
2755     int *p = (int *) value;
2756     int *end = (int *) (value + 1);
2757     while (p < end)
2758       *p++ = 0;
2759   }
2760
2761   value->kind = RTX_INT;        /* Most usual kind. */
2762   value->mode = mode;
2763
2764   switch (GET_CODE (x))
2765     {
2766     case CONST_DOUBLE:
2767       value->kind = RTX_DOUBLE;
2768       if (GET_MODE (x) != VOIDmode)
2769         value->mode = GET_MODE (x);
2770       bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
2771       break;
2772
2773     case CONST_INT:
2774       value->un.addr.offset = INTVAL (x);
2775       break;
2776
2777     case SYMBOL_REF:
2778     case LABEL_REF:
2779     case PC:
2780       value->un.addr.base = x;
2781       break;
2782
2783     case CONST:
2784       x = XEXP (x, 0);
2785       if (GET_CODE (x) == PLUS)
2786         {
2787           value->un.addr.base = XEXP (x, 0);
2788           if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2789             abort ();
2790           value->un.addr.offset = INTVAL (XEXP (x, 1));
2791         }
2792       else if (GET_CODE (x) == MINUS)
2793         {
2794           value->un.addr.base = XEXP (x, 0);
2795           if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2796             abort ();
2797           value->un.addr.offset = - INTVAL (XEXP (x, 1));
2798         }
2799       else
2800         abort ();
2801       break;
2802
2803     default:
2804       abort ();
2805     }
2806
2807   if (value->kind == RTX_INT && value->un.addr.base != 0)
2808     switch (GET_CODE (value->un.addr.base))
2809       {
2810       case SYMBOL_REF:
2811       case LABEL_REF:
2812         /* Use the string's address, not the SYMBOL_REF's address,
2813            for the sake of addresses of library routines.
2814            For a LABEL_REF, compare labels.  */
2815         value->un.addr.base = XEXP (value->un.addr.base, 0);
2816       }
2817 }
2818
2819 /* Given a MINUS expression, simplify it if both sides
2820    include the same symbol.  */
2821
2822 rtx
2823 simplify_subtraction (x)
2824      rtx x;
2825 {
2826   struct rtx_const val0, val1;
2827
2828   decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2829   decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2830
2831   if (val0.un.addr.base == val1.un.addr.base)
2832     return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2833   return x;
2834 }
2835
2836 /* Compute a hash code for a constant RTL expression.  */
2837
2838 int
2839 const_hash_rtx (mode, x)
2840      enum machine_mode mode;
2841      rtx x;
2842 {
2843   register int hi, i;
2844
2845   struct rtx_const value;
2846   decode_rtx_const (mode, x, &value);
2847
2848   /* Compute hashing function */
2849   hi = 0;
2850   for (i = 0; i < sizeof value / sizeof (int); i++)
2851     hi += ((int *) &value)[i];
2852
2853   hi &= (1 << HASHBITS) - 1;
2854   hi %= MAX_RTX_HASH_TABLE;
2855   return hi;
2856 }
2857
2858 /* Compare a constant rtl object X with a constant-descriptor DESC.
2859    Return 1 if DESC describes a constant with the same value as X.  */
2860
2861 static int
2862 compare_constant_rtx (mode, x, desc)
2863      enum machine_mode mode;
2864      rtx x;
2865      struct constant_descriptor *desc;
2866 {
2867   register int *p = (int *) desc->contents;
2868   register int *strp;
2869   register int len;
2870   struct rtx_const value;
2871
2872   decode_rtx_const (mode, x, &value);
2873   strp = (int *) &value;
2874   len = sizeof value / sizeof (int);
2875
2876   /* Compare constant contents.  */
2877   while (--len >= 0)
2878     if (*p++ != *strp++)
2879       return 0;
2880
2881   return 1;
2882 }
2883
2884 /* Construct a constant descriptor for the rtl-expression X.
2885    It is up to the caller to enter the descriptor in the hash table.  */
2886
2887 static struct constant_descriptor *
2888 record_constant_rtx (mode, x)
2889      enum machine_mode mode;
2890      rtx x;
2891 {
2892   struct constant_descriptor *ptr;
2893   char *label;
2894   struct rtx_const value;
2895
2896   decode_rtx_const (mode, x, &value);
2897
2898   obstack_grow (current_obstack, &ptr, sizeof ptr);
2899   obstack_grow (current_obstack, &label, sizeof label);
2900
2901   /* Record constant contents.  */
2902   obstack_grow (current_obstack, &value, sizeof value);
2903
2904   return (struct constant_descriptor *) obstack_finish (current_obstack);
2905 }
2906 \f
2907 /* Given a constant rtx X, make (or find) a memory constant for its value
2908    and return a MEM rtx to refer to it in memory.  */
2909
2910 rtx
2911 force_const_mem (mode, x)
2912      enum machine_mode mode;
2913      rtx x;
2914 {
2915   register int hash;
2916   register struct constant_descriptor *desc;
2917   char label[256];
2918   char *found = 0;
2919   rtx def;
2920
2921   /* If we want this CONST_DOUBLE in the same mode as it is in memory
2922      (this will always be true for floating CONST_DOUBLEs that have been
2923      placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
2924      use the previous copy.  Otherwise, make a new one.  Note that in
2925      the unlikely event that this same CONST_DOUBLE is used in two different
2926      modes in an alternating fashion, we will allocate a lot of different
2927      memory locations, but this should be extremely rare.  */
2928
2929   /* Don't use CONST_DOUBLE_MEM in a nested function.
2930      Nested functions have their own constant pools,
2931      so they can't share the same values in CONST_DOUBLE_MEM
2932      with the containing function.  */
2933   if (outer_function_chain == 0)
2934     if (GET_CODE (x) == CONST_DOUBLE
2935         && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
2936         && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
2937       return CONST_DOUBLE_MEM (x);
2938
2939   /* Compute hash code of X.  Search the descriptors for that hash code
2940      to see if any of them describes X.  If yes, the descriptor records
2941      the label number already assigned.  */
2942
2943   hash = const_hash_rtx (mode, x);
2944
2945   for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
2946     if (compare_constant_rtx (mode, x, desc))
2947       {
2948         found = desc->label;
2949         break;
2950       }
2951
2952   if (found == 0)
2953     {
2954       register struct pool_constant *pool;
2955       register struct pool_sym *sym;
2956       int align;
2957
2958       /* No constant equal to X is known to have been output.
2959          Make a constant descriptor to enter X in the hash table.
2960          Assign the label number and record it in the descriptor for
2961          future calls to this function to find.  */
2962
2963       desc = record_constant_rtx (mode, x);
2964       desc->next = const_rtx_hash_table[hash];
2965       const_rtx_hash_table[hash] = desc;
2966
2967       /* Align the location counter as required by EXP's data type.  */
2968       align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
2969       if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2970         align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
2971
2972       pool_offset += align - 1;
2973       pool_offset &= ~ (align - 1);
2974
2975       /* Allocate a pool constant descriptor, fill it in, and chain it in.  */
2976
2977       pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
2978       pool->desc = desc;
2979       pool->constant = x;
2980       pool->mode = mode;
2981       pool->labelno = const_labelno;
2982       pool->align = align;
2983       pool->offset = pool_offset;
2984       pool->next = 0;
2985
2986       if (last_pool == 0)
2987         first_pool = pool;
2988       else
2989         last_pool->next = pool;
2990
2991       last_pool = pool;
2992       pool_offset += GET_MODE_SIZE (mode);
2993
2994       /* Create a string containing the label name, in LABEL.  */
2995       ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2996
2997       ++const_labelno;
2998
2999       desc->label = found
3000         = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3001
3002       /* Add label to symbol hash table.  */
3003       hash = SYMHASH (found);
3004       sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
3005       sym->label = found;
3006       sym->pool = pool;
3007       sym->next = const_rtx_sym_hash_table[hash];
3008       const_rtx_sym_hash_table[hash] = sym;
3009     }
3010
3011   /* We have a symbol name; construct the SYMBOL_REF and the MEM.  */
3012
3013   def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3014
3015   RTX_UNCHANGING_P (def) = 1;
3016   /* Mark the symbol_ref as belonging to this constants pool.  */
3017   CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3018   current_function_uses_const_pool = 1;
3019
3020   if (outer_function_chain == 0)
3021     if (GET_CODE (x) == CONST_DOUBLE)
3022       {
3023         if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3024           {
3025             CONST_DOUBLE_CHAIN (x) = const_double_chain;
3026             const_double_chain = x;
3027           }
3028         CONST_DOUBLE_MEM (x) = def;
3029       }
3030
3031   return def;
3032 }
3033 \f
3034 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3035    the corresponding pool_constant structure.  */
3036
3037 static struct pool_constant *
3038 find_pool_constant (addr)
3039      rtx addr;
3040 {
3041   struct pool_sym *sym;
3042   char *label = XSTR (addr, 0);
3043
3044   for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3045     if (sym->label == label)
3046       return sym->pool;
3047
3048   abort ();
3049 }
3050
3051 /* Given a constant pool SYMBOL_REF, return the corresponding constant.  */
3052
3053 rtx
3054 get_pool_constant (addr)
3055      rtx addr;
3056 {
3057   return (find_pool_constant (addr))->constant;
3058 }
3059
3060 /* Similar, return the mode.  */
3061
3062 enum machine_mode
3063 get_pool_mode (addr)
3064      rtx addr;
3065 {
3066   return (find_pool_constant (addr))->mode;
3067 }
3068
3069 /* Similar, return the offset in the constant pool.  */
3070
3071 int
3072 get_pool_offset (addr)
3073      rtx addr;
3074 {
3075   return (find_pool_constant (addr))->offset;
3076 }
3077
3078 /* Return the size of the constant pool.  */
3079
3080 int
3081 get_pool_size ()
3082 {
3083   return pool_offset;
3084 }
3085 \f
3086 /* Write all the constants in the constant pool.  */
3087
3088 void
3089 output_constant_pool (fnname, fndecl)
3090      char *fnname;
3091      tree fndecl;
3092 {
3093   struct pool_constant *pool;
3094   rtx x;
3095   union real_extract u;
3096
3097 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3098   ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3099 #endif
3100
3101   for (pool = first_pool; pool; pool = pool->next)
3102     {
3103       x = pool->constant;
3104
3105       /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3106          whose CODE_LABEL has been deleted.  This can occur if a jump table
3107          is eliminated by optimization.  If so, write a constant of zero
3108          instead.  Note that this can also happen by turning the
3109          CODE_LABEL into a NOTE.  */
3110       if (((GET_CODE (x) == LABEL_REF
3111             && (INSN_DELETED_P (XEXP (x, 0))
3112                 || GET_CODE (XEXP (x, 0)) == NOTE)))
3113           || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3114               && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3115               && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3116                   || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3117         x = const0_rtx;
3118
3119       /* First switch to correct section.  */
3120 #ifdef SELECT_RTX_SECTION
3121       SELECT_RTX_SECTION (pool->mode, x);
3122 #else
3123       readonly_data_section ();
3124 #endif
3125
3126 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3127       ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3128                                      pool->align, pool->labelno, done);
3129 #endif
3130
3131       if (pool->align > 1)
3132         ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3133
3134       /* Output the label.  */
3135       ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3136
3137       /* Output the value of the constant itself.  */
3138       switch (GET_MODE_CLASS (pool->mode))
3139         {
3140         case MODE_FLOAT:
3141           if (GET_CODE (x) != CONST_DOUBLE)
3142             abort ();
3143
3144           bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
3145           assemble_real (u.d, pool->mode);
3146           break;
3147
3148         case MODE_INT:
3149         case MODE_PARTIAL_INT:
3150           assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3151           break;
3152
3153         default:
3154           abort ();
3155         }
3156
3157     done: ;
3158     }
3159
3160   /* Done with this pool.  */
3161   first_pool = last_pool = 0;
3162 }
3163 \f
3164 /* Find all the constants whose addresses are referenced inside of EXP,
3165    and make sure assembler code with a label has been output for each one.
3166    Indicate whether an ADDR_EXPR has been encountered.  */
3167
3168 int
3169 output_addressed_constants (exp)
3170      tree exp;
3171 {
3172   int reloc = 0;
3173
3174   switch (TREE_CODE (exp))
3175     {
3176     case ADDR_EXPR:
3177       {
3178         register tree constant = TREE_OPERAND (exp, 0);
3179
3180         while (TREE_CODE (constant) == COMPONENT_REF)
3181           {
3182             constant = TREE_OPERAND (constant, 0);
3183           }
3184
3185         if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3186             || TREE_CODE (constant) == CONSTRUCTOR)
3187           /* No need to do anything here
3188              for addresses of variables or functions.  */
3189           output_constant_def (constant);
3190       }
3191       reloc = 1;
3192       break;
3193
3194     case PLUS_EXPR:
3195     case MINUS_EXPR:
3196       reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3197       reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3198       break;
3199
3200     case NOP_EXPR:
3201     case CONVERT_EXPR:
3202     case NON_LVALUE_EXPR:
3203       reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3204       break;
3205
3206     case CONSTRUCTOR:
3207       {
3208         register tree link;
3209         for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3210           if (TREE_VALUE (link) != 0)
3211             reloc |= output_addressed_constants (TREE_VALUE (link));
3212       }
3213       break;
3214
3215     case ERROR_MARK:
3216       break;
3217     }
3218   return reloc;
3219 }
3220
3221
3222 /* Output assembler for byte constant */
3223 void
3224 output_byte_asm (byte)
3225   int byte;
3226 {
3227   if (output_bytecode)
3228     bc_emit_const ((char *) &byte, sizeof (char));
3229 #ifdef ASM_OUTPUT_BYTE
3230   else
3231     {
3232       ASM_OUTPUT_BYTE (asm_out_file, byte);
3233     }
3234 #endif
3235 }
3236 \f
3237 /* Output assembler code for constant EXP to FILE, with no label.
3238    This includes the pseudo-op such as ".int" or ".byte", and a newline.
3239    Assumes output_addressed_constants has been done on EXP already.
3240
3241    Generate exactly SIZE bytes of assembler data, padding at the end
3242    with zeros if necessary.  SIZE must always be specified.
3243
3244    SIZE is important for structure constructors,
3245    since trailing members may have been omitted from the constructor.
3246    It is also important for initialization of arrays from string constants
3247    since the full length of the string constant might not be wanted.
3248    It is also needed for initialization of unions, where the initializer's
3249    type is just one member, and that may not be as long as the union.
3250
3251    There a case in which we would fail to output exactly SIZE bytes:
3252    for a structure constructor that wants to produce more than SIZE bytes.
3253    But such constructors will never be generated for any possible input.  */
3254
3255 void
3256 output_constant (exp, size)
3257      register tree exp;
3258      register int size;
3259 {
3260   register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3261   rtx x;
3262
3263   if (size == 0)
3264     return;
3265
3266   /* Allow a constructor with no elements for any data type.
3267      This means to fill the space with zeros.  */
3268   if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3269     {
3270       if (output_bytecode)
3271         bc_emit_const_skip (size);
3272       else
3273         assemble_zeros (size);
3274       return;
3275     }
3276
3277   /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
3278      That way we get the constant (we hope) inside it.  */
3279   if (TREE_CODE (exp) == NOP_EXPR
3280       && TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)))
3281     exp = TREE_OPERAND (exp, 0);
3282
3283   switch (code)
3284     {
3285     case CHAR_TYPE:
3286     case BOOLEAN_TYPE:
3287     case INTEGER_TYPE:
3288     case ENUMERAL_TYPE:
3289     case POINTER_TYPE:
3290     case REFERENCE_TYPE:
3291       /* ??? What about       (int)((float)(int)&foo + 4)    */
3292       while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3293              || TREE_CODE (exp) == NON_LVALUE_EXPR)
3294         exp = TREE_OPERAND (exp, 0);
3295
3296       if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3297                                            EXPAND_INITIALIZER),
3298                               size, 0))
3299         error ("initializer for integer value is too complicated");
3300       size = 0;
3301       break;
3302
3303     case REAL_TYPE:
3304       if (TREE_CODE (exp) != REAL_CST)
3305         error ("initializer for floating value is not a floating constant");
3306
3307       assemble_real (TREE_REAL_CST (exp),
3308                      mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3309       size = 0;
3310       break;
3311
3312     case COMPLEX_TYPE:
3313       output_constant (TREE_REALPART (exp), size / 2);
3314       output_constant (TREE_IMAGPART (exp), size / 2);
3315       size -= (size / 2) * 2;
3316       break;
3317
3318     case ARRAY_TYPE:
3319       if (TREE_CODE (exp) == CONSTRUCTOR)
3320         {
3321           output_constructor (exp, size);
3322           return;
3323         }
3324       else if (TREE_CODE (exp) == STRING_CST)
3325         {
3326           int excess = 0;
3327
3328           if (size > TREE_STRING_LENGTH (exp))
3329             {
3330               excess = size - TREE_STRING_LENGTH (exp);
3331               size = TREE_STRING_LENGTH (exp);
3332             }
3333
3334           assemble_string (TREE_STRING_POINTER (exp), size);
3335           size = excess;
3336         }
3337       else
3338         abort ();
3339       break;
3340
3341     case RECORD_TYPE:
3342     case UNION_TYPE:
3343       if (TREE_CODE (exp) == CONSTRUCTOR)
3344         output_constructor (exp, size);
3345       else
3346         abort ();
3347       return;
3348     }
3349
3350   if (size > 0)
3351     assemble_zeros (size);
3352 }
3353
3354
3355 /* Bytecode specific code to output assembler for integer. */
3356 static void
3357 bc_assemble_integer (exp, size)
3358     tree exp;
3359     int size;
3360 {
3361   tree const_part;
3362   tree addr_part;
3363   tree tmp;
3364
3365   /* FIXME: is this fold() business going to be as good as the
3366      expand_expr() using EXPAND_SUM above in the RTL case?  I
3367      hate RMS.
3368      FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3369   
3370   exp = fold (exp);
3371   
3372   while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3373     exp = TREE_OPERAND (exp, 0);
3374   if (TREE_CODE (exp) == INTEGER_CST)
3375     {
3376       const_part = exp;
3377       addr_part = 0;
3378     }
3379   else if (TREE_CODE (exp) == PLUS_EXPR)
3380     {
3381       const_part = TREE_OPERAND (exp, 0);
3382       while (TREE_CODE (const_part) == NOP_EXPR
3383              || TREE_CODE (const_part) == CONVERT_EXPR)
3384         const_part = TREE_OPERAND (const_part, 0);
3385       addr_part = TREE_OPERAND (exp, 1);
3386       while (TREE_CODE (addr_part) == NOP_EXPR
3387              || TREE_CODE (addr_part) == CONVERT_EXPR)
3388         addr_part = TREE_OPERAND (addr_part, 0);
3389       if (TREE_CODE (const_part) != INTEGER_CST)
3390         tmp = const_part, const_part = addr_part, addr_part = tmp;
3391       if (TREE_CODE (const_part) != INTEGER_CST
3392           || TREE_CODE (addr_part) != ADDR_EXPR)
3393         abort ();               /* FIXME: we really haven't considered
3394                                    all the possible cases here.  */
3395     }
3396   else if (TREE_CODE (exp) == ADDR_EXPR)
3397     {
3398       const_part = integer_zero_node;
3399       addr_part = exp;
3400     }
3401   else
3402     abort ();           /* FIXME: ditto previous.  */
3403   
3404   if (addr_part == 0)
3405     {
3406       if (size == 1)
3407         {
3408           char c = TREE_INT_CST_LOW (const_part);
3409           bc_emit (&c, 1);
3410           size -= 1;
3411         }
3412       else if (size == 2)
3413         {
3414           short s = TREE_INT_CST_LOW (const_part);
3415           bc_emit ((char *) &s, 2);
3416           size -= 2;
3417         }
3418       else if (size == 4)
3419         {
3420           int i = TREE_INT_CST_LOW (const_part);
3421           bc_emit ((char *) &i, 4);
3422           size -= 4;
3423         }
3424       else if (size == 8)
3425         {
3426 #if WORDS_BIG_ENDIAN
3427           int i = TREE_INT_CST_HIGH (const_part);
3428           bc_emit ((char *) &i, 4);
3429           i = TREE_INT_CST_LOW (const_part);
3430           bc_emit ((char *) &i, 4);
3431 #else
3432           int i = TREE_INT_CST_LOW (const_part);
3433           bc_emit ((char *) &i, 4);
3434           i = TREE_INT_CST_HIGH (const_part);
3435           bc_emit ((char *) &i, 4);
3436 #endif
3437           size -= 8;
3438         }
3439     }
3440   else
3441     if (size == 4
3442         && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3443       bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3444                         TREE_INT_CST_LOW (const_part));
3445     else
3446       abort ();         /* FIXME: there may be more cases.  */
3447 }
3448 \f
3449 /* Subroutine of output_constant, used for CONSTRUCTORs
3450    (aggregate constants).
3451    Generate at least SIZE bytes, padding if necessary.  */
3452
3453 void
3454 output_constructor (exp, size)
3455      tree exp;
3456      int size;
3457 {
3458   register tree link, field = 0;
3459   HOST_WIDE_INT min_index = 0;
3460   /* Number of bytes output or skipped so far.
3461      In other words, current position within the constructor.  */
3462   int total_bytes = 0;
3463   /* Non-zero means BYTE contains part of a byte, to be output.  */
3464   int byte_buffer_in_use = 0;
3465   register int byte;
3466
3467   if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3468     abort ();
3469
3470   if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3471     field = TYPE_FIELDS (TREE_TYPE (exp));
3472
3473   if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3474       && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3475     min_index
3476       = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3477
3478   /* As LINK goes through the elements of the constant,
3479      FIELD goes through the structure fields, if the constant is a structure.
3480      if the constant is a union, then we override this,
3481      by getting the field from the TREE_LIST element.
3482      But the constant could also be an array.  Then FIELD is zero.  */
3483   for (link = CONSTRUCTOR_ELTS (exp);
3484        link;
3485        link = TREE_CHAIN (link),
3486        field = field ? TREE_CHAIN (field) : 0)
3487     {
3488       tree val = TREE_VALUE (link);
3489       tree index = 0;
3490
3491       /* the element in a union constructor specifies the proper field.  */
3492
3493       if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3494           || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3495         {
3496           /* if available, use the type given by link */
3497           if (TREE_PURPOSE (link) != 0)
3498             field = TREE_PURPOSE (link);
3499         }
3500
3501       if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3502         index = TREE_PURPOSE (link);
3503
3504       /* Eliminate the marker that makes a cast not be an lvalue.  */
3505       if (val != 0)
3506         STRIP_NOPS (val);
3507
3508       if (field == 0 || !DECL_BIT_FIELD (field))
3509         {
3510           /* An element that is not a bit-field.  */
3511
3512           register int fieldsize;
3513           /* Since this structure is static,
3514              we know the positions are constant.  */
3515           int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3516                                  / BITS_PER_UNIT)
3517                         : 0);
3518           if (index != 0)
3519             bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3520                       / BITS_PER_UNIT
3521                       * (TREE_INT_CST_LOW (index) - min_index));
3522
3523           /* Output any buffered-up bit-fields preceding this element.  */
3524           if (byte_buffer_in_use)
3525             {
3526               ASM_OUTPUT_BYTE (asm_out_file, byte);
3527               total_bytes++;
3528               byte_buffer_in_use = 0;
3529             }
3530
3531           /* Advance to offset of this element.
3532              Note no alignment needed in an array, since that is guaranteed
3533              if each element has the proper size.  */
3534           if ((field != 0 || index != 0) && bitpos != total_bytes)
3535             {
3536               if (!output_bytecode)
3537                 assemble_zeros (bitpos - total_bytes);
3538               else
3539                 bc_emit_const_skip (bitpos - total_bytes);
3540               total_bytes = bitpos;
3541             }
3542
3543           /* Determine size this element should occupy.  */
3544           if (field)
3545             {
3546               if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3547                 abort ();
3548               if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3549                 {
3550                   /* This avoids overflow trouble.  */
3551                   tree size_tree = size_binop (CEIL_DIV_EXPR,
3552                                                DECL_SIZE (field),
3553                                                size_int (BITS_PER_UNIT));
3554                   fieldsize = TREE_INT_CST_LOW (size_tree);
3555                 }
3556               else
3557                 {
3558                   fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3559                   fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3560                 }
3561             }
3562           else
3563             fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3564
3565           /* Output the element's initial value.  */
3566           if (val == 0)
3567             assemble_zeros (fieldsize);
3568           else
3569             output_constant (val, fieldsize);
3570
3571           /* Count its size.  */
3572           total_bytes += fieldsize;
3573         }
3574       else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3575         error ("invalid initial value for member `%s'",
3576                IDENTIFIER_POINTER (DECL_NAME (field)));
3577       else
3578         {
3579           /* Element that is a bit-field.  */
3580
3581           int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3582           int end_offset
3583             = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3584
3585           if (val == 0)
3586             val = integer_zero_node;
3587
3588           /* If this field does not start in this (or, next) byte,
3589              skip some bytes.  */
3590           if (next_offset / BITS_PER_UNIT != total_bytes)
3591             {
3592               /* Output remnant of any bit field in previous bytes.  */
3593               if (byte_buffer_in_use)
3594                 {
3595                   ASM_OUTPUT_BYTE (asm_out_file, byte);
3596                   total_bytes++;
3597                   byte_buffer_in_use = 0;
3598                 }
3599
3600               /* If still not at proper byte, advance to there.  */
3601               if (next_offset / BITS_PER_UNIT != total_bytes)
3602                 {
3603                   assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3604                   total_bytes = next_offset / BITS_PER_UNIT;
3605                 }
3606             }
3607
3608           if (! byte_buffer_in_use)
3609             byte = 0;
3610
3611           /* We must split the element into pieces that fall within
3612              separate bytes, and combine each byte with previous or
3613              following bit-fields.  */
3614
3615           /* next_offset is the offset n fbits from the beginning of
3616              the structure to the next bit of this element to be processed.
3617              end_offset is the offset of the first bit past the end of
3618              this element.  */
3619           while (next_offset < end_offset)
3620             {
3621               int this_time;
3622               int shift, value;
3623               int next_byte = next_offset / BITS_PER_UNIT;
3624               int next_bit = next_offset % BITS_PER_UNIT;
3625
3626               /* Advance from byte to byte
3627                  within this element when necessary.  */
3628               while (next_byte != total_bytes)
3629                 {
3630                   ASM_OUTPUT_BYTE (asm_out_file, byte);
3631                   total_bytes++;
3632                   byte = 0;
3633                 }
3634
3635               /* Number of bits we can process at once
3636                  (all part of the same byte).  */
3637               this_time = MIN (end_offset - next_offset,
3638                                BITS_PER_UNIT - next_bit);
3639 #if BYTES_BIG_ENDIAN
3640               /* On big-endian machine, take the most significant bits
3641                  first (of the bits that are significant)
3642                  and put them into bytes from the most significant end.  */
3643               shift = end_offset - next_offset - this_time;
3644               /* Don't try to take a bunch of bits that cross
3645                  the word boundary in the INTEGER_CST.  */
3646               if (shift < HOST_BITS_PER_WIDE_INT
3647                   && shift + this_time > HOST_BITS_PER_WIDE_INT)
3648                 {
3649                   this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3650                   shift = HOST_BITS_PER_WIDE_INT;
3651                 }
3652
3653               /* Now get the bits from the appropriate constant word.  */
3654               if (shift < HOST_BITS_PER_WIDE_INT)
3655                 {
3656                   value = TREE_INT_CST_LOW (val);
3657                 }
3658               else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3659                 {
3660                   value = TREE_INT_CST_HIGH (val);
3661                   shift -= HOST_BITS_PER_WIDE_INT;
3662                 }
3663               else
3664                 abort ();
3665               byte |= (((value >> shift)
3666                         & (((HOST_WIDE_INT) 1 << this_time) - 1))
3667                        << (BITS_PER_UNIT - this_time - next_bit));
3668 #else
3669               /* On little-endian machines,
3670                  take first the least significant bits of the value
3671                  and pack them starting at the least significant
3672                  bits of the bytes.  */
3673               shift = (next_offset
3674                        - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3675               /* Don't try to take a bunch of bits that cross
3676                  the word boundary in the INTEGER_CST.  */
3677               if (shift < HOST_BITS_PER_WIDE_INT
3678                   && shift + this_time > HOST_BITS_PER_WIDE_INT)
3679                 {
3680                   this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3681                   shift = HOST_BITS_PER_WIDE_INT;
3682                 }
3683
3684               /* Now get the bits from the appropriate constant word.  */
3685               if (shift < HOST_BITS_PER_INT)
3686                 value = TREE_INT_CST_LOW (val);
3687               else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3688                 {
3689                   value = TREE_INT_CST_HIGH (val);
3690                   shift -= HOST_BITS_PER_WIDE_INT;
3691                 }
3692               else
3693                 abort ();
3694               byte |= ((value >> shift)
3695                        & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
3696 #endif
3697               next_offset += this_time;
3698               byte_buffer_in_use = 1;
3699             }
3700         }
3701     }
3702   if (byte_buffer_in_use)
3703     {
3704       ASM_OUTPUT_BYTE (asm_out_file, byte);
3705       total_bytes++;
3706     }
3707   if (total_bytes < size)
3708     assemble_zeros (size - total_bytes);
3709 }
3710
3711
3712 #ifdef HANDLE_SYSV_PRAGMA
3713
3714 /* Support #pragma weak by default if WEAK_ASM_OP is defined.  */
3715 #if defined (HANDLE_PRAGMA_WEAK) || (defined (WEAK_ASM_OP) && defined (SET_ASM_OP))
3716
3717 /* See c-pragma.c for an identical definition.  */
3718 enum pragma_state
3719 {
3720   ps_start,
3721   ps_done,
3722   ps_bad,
3723   ps_weak,
3724   ps_name,
3725   ps_equals,
3726   ps_value,
3727   ps_pack,
3728   ps_left,
3729   ps_align,
3730   ps_right
3731 };
3732
3733 /* Output asm to handle ``#pragma weak'' */
3734 void
3735 handle_pragma_weak (what, asm_out_file, name, value)
3736      enum pragma_state what;
3737      FILE *asm_out_file;
3738      char *name, *value;
3739 {
3740   if (what == ps_name || what == ps_value)
3741     {
3742       fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
3743
3744       if (output_bytecode)
3745         BC_OUTPUT_LABELREF (asm_out_file, name);
3746       else
3747         ASM_OUTPUT_LABELREF (asm_out_file, name);
3748
3749       fputc ('\n', asm_out_file);
3750       if (what == ps_value)
3751         {
3752           fprintf (asm_out_file, "\t%s\t", SET_ASM_OP);
3753           if (output_bytecode)
3754             BC_OUTPUT_LABELREF (asm_out_file, name);
3755           else
3756             ASM_OUTPUT_LABELREF (asm_out_file, name);
3757
3758           fputc (',', asm_out_file);
3759           if (output_bytecode)
3760             BC_OUTPUT_LABELREF (asm_out_file, value);
3761           else
3762             ASM_OUTPUT_LABELREF (asm_out_file, value);
3763
3764           fputc ('\n', asm_out_file);
3765         }
3766     }
3767   else if (! (what == ps_done || what == ps_start))
3768     warning ("malformed `#pragma weak'");
3769 }
3770
3771 #endif /* HANDLE_PRAGMA_WEAK or (WEAK_ASM_OP and SET_ASM_OP) */
3772
3773 #endif /* HANDLE_SYSV_PRAGMA */