OSDN Git Service

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