OSDN Git Service

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