OSDN Git Service

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