OSDN Git Service

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