1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92-6, 1997 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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)
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.
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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file handles generation of all the assembler code
23 *except* the instructions of a function.
24 This includes declarations of variables and their initial values.
26 We also output the assembler code for constants stored in memory
27 and are responsible for combining constants with the same value. */
31 /* #include <stab.h> */
40 #include "hard-reg-set.h"
49 #ifdef XCOFF_DEBUGGING_INFO
56 #define ASM_STABS_OP ".stabs"
59 /* This macro gets just the user-specified name
60 out of the string in a SYMBOL_REF. On most machines,
61 we discard the * if any and that's all. */
62 #ifndef STRIP_NAME_ENCODING
63 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
64 (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
67 /* File in which assembler code is being written. */
69 extern FILE *asm_out_file;
71 /* The (assembler) name of the first globally-visible object output. */
72 char *first_global_object_name;
74 extern struct obstack *current_obstack;
75 extern struct obstack *saveable_obstack;
76 extern struct obstack *rtl_obstack;
77 extern struct obstack permanent_obstack;
78 #define obstack_chunk_alloc xmalloc
80 /* Number for making the label on the next
81 constant that is stored in memory. */
85 /* Number for making the label on the next
86 static variable internal to a function. */
90 /* Carry information from ASM_DECLARE_OBJECT_NAME
91 to ASM_FINISH_DECLARE_OBJECT. */
93 int size_directive_output;
95 /* The last decl for which assemble_variable was called,
96 if it did ASM_DECLARE_OBJECT_NAME.
97 If the last call to assemble_variable didn't do that,
100 tree last_assemble_variable_decl;
103 #ifdef HANDLE_PRAGMA_WEAK
104 /* Any weak symbol declarations waiting to be emitted. */
108 struct weak_syms *next;
113 static struct weak_syms *weak_decls;
116 /* Nonzero if at least one function definition has been seen. */
118 static int function_defined;
121 struct constant_descriptor;
123 struct pool_constant;
125 static void bc_make_decl_rtl PROTO((tree, char *, int));
126 static char *strip_reg_name PROTO((char *));
127 static void bc_output_ascii PROTO((FILE *, char *, int));
128 static int contains_pointers_p PROTO((tree));
129 static void decode_addr_const PROTO((tree, struct addr_const *));
130 static int const_hash PROTO((tree));
131 static int compare_constant PROTO((tree,
132 struct constant_descriptor *));
133 static char *compare_constant_1 PROTO((tree, char *));
134 static struct constant_descriptor *record_constant PROTO((tree));
135 static void record_constant_1 PROTO((tree));
136 static tree copy_constant PROTO((tree));
137 static void output_constant_def_contents PROTO((tree, int, int));
138 static void decode_rtx_const PROTO((enum machine_mode, rtx,
139 struct rtx_const *));
140 static int const_hash_rtx PROTO((enum machine_mode, rtx));
141 static int compare_constant_rtx PROTO((enum machine_mode, rtx,
142 struct constant_descriptor *));
143 static struct constant_descriptor *record_constant_rtx PROTO((enum machine_mode,
145 static struct pool_constant *find_pool_constant PROTO((rtx));
146 static void mark_constant_pool PROTO((void));
147 static void mark_constants PROTO((rtx));
148 static int output_addressed_constants PROTO((tree));
149 static void output_after_function_constants PROTO((void));
150 static void bc_assemble_integer PROTO((tree, int));
151 static void output_constructor PROTO((tree, int));
153 static enum in_section { no_section, in_text, in_data, in_named
154 #ifdef BSS_SECTION_ASM_OP
157 #ifdef EXTRA_SECTIONS
160 } in_section = no_section;
162 /* Return a non-zero value if DECL has a section attribute. */
163 #define IN_NAMED_SECTION(DECL) \
164 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
165 && DECL_SECTION_NAME (DECL) != NULL_TREE)
167 /* Text of section name when in_section == in_named. */
168 static char *in_named_name;
170 /* Define functions like text_section for any extra sections. */
171 #ifdef EXTRA_SECTION_FUNCTIONS
172 EXTRA_SECTION_FUNCTIONS
175 /* Tell assembler to switch to text section. */
180 if (in_section != in_text)
185 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
187 in_section = in_text;
191 /* Tell assembler to switch to data section. */
196 if (in_section != in_data)
202 if (flag_shared_data)
204 #ifdef SHARED_SECTION_ASM_OP
205 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
207 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
211 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
214 in_section = in_data;
218 /* Tell assembler to switch to read-only data section. This is normally
222 readonly_data_section ()
224 #ifdef READONLY_DATA_SECTION
225 READONLY_DATA_SECTION (); /* Note this can call data_section. */
231 /* Determine if we're in the text section. */
236 return in_section == in_text;
239 /* Determine if we're in the data section. */
244 return in_section == in_data;
247 /* Tell assembler to change to section NAME for DECL.
248 If DECL is NULL, just switch to section NAME.
249 If NAME is NULL, get the name from DECL. */
252 named_section (decl, name)
256 if (decl != NULL_TREE
257 && TREE_CODE_CLASS (TREE_CODE (decl)) != 'd')
260 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
262 if (in_section != in_named || strcmp (name, in_named_name))
264 in_named_name = obstack_alloc (&permanent_obstack, strlen (name) + 1);
265 strcpy (in_named_name, name);
266 in_section = in_named;
268 #ifdef ASM_OUTPUT_SECTION_NAME
269 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name);
271 /* Section attributes are not supported if this macro isn't provided -
272 some host formats don't support them at all. The front-end should
273 already have flagged this as an error. */
279 #ifdef BSS_SECTION_ASM_OP
281 /* Tell the assembler to switch to the bss section. */
286 if (in_section != in_bss)
292 #ifdef SHARED_BSS_SECTION_ASM_OP
293 if (flag_shared_data)
294 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
297 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
304 #ifdef ASM_OUTPUT_BSS
306 /* Utility function for ASM_OUTPUT_BSS for targets to use if
307 they don't support alignments in .bss.
308 ??? It is believed that this function will work in most cases so such
309 support is localized here. */
312 asm_output_bss (file, decl, name, size, rounded)
318 ASM_GLOBALIZE_LABEL (file, name);
320 #ifdef ASM_DECLARE_OBJECT_NAME
321 last_assemble_variable_decl = decl;
322 ASM_DECLARE_OBJECT_NAME (file, name, decl);
324 /* Standard thing is just output label for the object. */
325 ASM_OUTPUT_LABEL (file, name);
326 #endif /* ASM_DECLARE_OBJECT_NAME */
327 ASM_OUTPUT_SKIP (file, rounded);
332 #ifdef ASM_OUTPUT_ALIGNED_BSS
334 /* Utility function for targets to use in implementing
335 ASM_OUTPUT_ALIGNED_BSS.
336 ??? It is believed that this function will work in most cases so such
337 support is localized here. */
340 asm_output_aligned_bss (file, decl, name, size, align)
346 ASM_GLOBALIZE_LABEL (file, name);
348 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
349 #ifdef ASM_DECLARE_OBJECT_NAME
350 last_assemble_variable_decl = decl;
351 ASM_DECLARE_OBJECT_NAME (file, name, decl);
353 /* Standard thing is just output label for the object. */
354 ASM_OUTPUT_LABEL (file, name);
355 #endif /* ASM_DECLARE_OBJECT_NAME */
356 ASM_OUTPUT_SKIP (file, size ? size : 1);
361 #endif /* BSS_SECTION_ASM_OP */
363 /* Switch to the section for function DECL.
365 If DECL is NULL_TREE, switch to the text section.
366 ??? It's not clear that we will ever be passed NULL_TREE, but it's
367 safer to handle it. */
370 function_section (decl)
373 if (decl != NULL_TREE
374 && DECL_SECTION_NAME (decl) != NULL_TREE)
375 named_section (decl, (char *) 0);
380 /* Switch to section for variable DECL.
382 RELOC is the `reloc' argument to SELECT_SECTION. */
385 variable_section (decl, reloc)
389 if (IN_NAMED_SECTION (decl))
390 named_section (decl, NULL);
393 /* C++ can have const variables that get initialized from constructors,
394 and thus can not be in a readonly section. We prevent this by
395 verifying that the initial value is constant for objects put in a
398 error_mark_node is used by the C front end to indicate that the
399 initializer has not been seen yet. In this case, we assume that
400 the initializer must be constant.
402 C++ uses error_mark_node for variables that have complicated
403 initializers, but these variables go in BSS so we won't be called
406 #ifdef SELECT_SECTION
407 SELECT_SECTION (decl, reloc);
409 if (TREE_READONLY (decl)
410 && ! TREE_THIS_VOLATILE (decl)
411 && DECL_INITIAL (decl)
412 && (DECL_INITIAL (decl) == error_mark_node
413 || TREE_CONSTANT (DECL_INITIAL (decl)))
414 && ! (flag_pic && reloc))
415 readonly_data_section ();
422 /* Tell assembler to switch to the section for the exception handling
428 #ifdef ASM_OUTPUT_SECTION_NAME
429 named_section (NULL_TREE, ".gcc_except_table");
434 #if defined (EXCEPTION_SECTION)
435 EXCEPTION_SECTION ();
437 readonly_data_section ();
442 /* Create the rtl to represent a function, for a function definition.
443 DECL is a FUNCTION_DECL node which describes which function.
444 The rtl is stored into DECL. */
447 make_function_rtl (decl)
450 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
454 if (DECL_RTL (decl) == 0)
455 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
457 /* Record that at least one function has been defined. */
458 function_defined = 1;
462 /* Rename a nested function to avoid conflicts. */
463 if (decl_function_context (decl) != 0
464 && DECL_INITIAL (decl) != 0
465 && DECL_RTL (decl) == 0)
469 name = IDENTIFIER_POINTER (DECL_NAME (decl));
470 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
471 name = obstack_copy0 (saveable_obstack, label, strlen (label));
475 if (DECL_RTL (decl) == 0)
478 = gen_rtx (MEM, DECL_MODE (decl),
479 gen_rtx (SYMBOL_REF, Pmode, name));
481 /* Optionally set flags or add text to the name to record information
482 such as that it is a function name. If the name is changed, the macro
483 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
484 #ifdef ENCODE_SECTION_INFO
485 ENCODE_SECTION_INFO (decl);
489 /* Record at least one function has been defined. */
490 function_defined = 1;
493 /* Create the DECL_RTL for a declaration for a static or external
494 variable or static or external function.
495 ASMSPEC, if not 0, is the string which the user specified
496 as the assembler symbol name.
497 TOP_LEVEL is nonzero if this is a file-scope variable.
498 This is never called for PARM_DECLs. */
501 bc_make_decl_rtl (decl, asmspec, top_level)
506 register char *name = TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl));
508 if (DECL_RTL (decl) == 0)
510 /* Print an error message for register variables. */
511 if (DECL_REGISTER (decl))
512 error ("global register variables not supported in the interpreter");
514 /* Handle ordinary static variables and functions. */
515 if (DECL_RTL (decl) == 0)
517 /* Can't use just the variable's own name for a variable
518 whose scope is less than the whole file.
519 Concatenate a distinguishing number. */
520 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
524 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
525 name = obstack_copy0 (saveable_obstack, label, strlen (label));
529 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
534 /* Given NAME, a putative register name, discard any customary prefixes. */
537 strip_reg_name (name)
540 #ifdef REGISTER_PREFIX
541 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
542 name += strlen (REGISTER_PREFIX);
544 if (name[0] == '%' || name[0] == '#')
549 /* Decode an `asm' spec for a declaration as a register name.
550 Return the register number, or -1 if nothing specified,
551 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
552 or -3 if ASMSPEC is `cc' and is not recognized,
553 or -4 if ASMSPEC is `memory' and is not recognized.
554 Accept an exact spelling or a decimal number.
555 Prefixes such as % are optional. */
558 decode_reg_name (asmspec)
565 /* Get rid of confusing prefixes. */
566 asmspec = strip_reg_name (asmspec);
568 /* Allow a decimal number as a "register name". */
569 for (i = strlen (asmspec) - 1; i >= 0; i--)
570 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
572 if (asmspec[0] != 0 && i < 0)
575 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
581 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
583 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
586 #ifdef ADDITIONAL_REGISTER_NAMES
588 static struct { char *name; int number; } table[]
589 = ADDITIONAL_REGISTER_NAMES;
591 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
592 if (! strcmp (asmspec, table[i].name))
593 return table[i].number;
595 #endif /* ADDITIONAL_REGISTER_NAMES */
597 if (!strcmp (asmspec, "memory"))
600 if (!strcmp (asmspec, "cc"))
609 /* Create the DECL_RTL for a declaration for a static or external variable
610 or static or external function.
611 ASMSPEC, if not 0, is the string which the user specified
612 as the assembler symbol name.
613 TOP_LEVEL is nonzero if this is a file-scope variable.
615 This is never called for PARM_DECL nodes. */
618 make_decl_rtl (decl, asmspec, top_level)
623 register char *name = 0;
628 bc_make_decl_rtl (decl, asmspec, top_level);
632 reg_number = decode_reg_name (asmspec);
634 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
635 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
637 if (reg_number == -2)
639 /* ASMSPEC is given, and not the name of a register. */
640 name = (char *) obstack_alloc (saveable_obstack,
641 strlen (asmspec) + 2);
643 strcpy (&name[1], asmspec);
646 /* For a duplicate declaration, we can be called twice on the
647 same DECL node. Don't discard the RTL already made. */
648 if (DECL_RTL (decl) == 0)
652 /* First detect errors in declaring global registers. */
653 if (TREE_CODE (decl) != FUNCTION_DECL
654 && DECL_REGISTER (decl) && reg_number == -1)
655 error_with_decl (decl,
656 "register name not specified for `%s'");
657 else if (TREE_CODE (decl) != FUNCTION_DECL
658 && DECL_REGISTER (decl) && reg_number < 0)
659 error_with_decl (decl,
660 "invalid register name for `%s'");
661 else if ((reg_number >= 0 || reg_number == -3)
662 && (TREE_CODE (decl) == FUNCTION_DECL
663 && ! DECL_REGISTER (decl)))
664 error_with_decl (decl,
665 "register name given for non-register variable `%s'");
666 else if (TREE_CODE (decl) != FUNCTION_DECL
667 && DECL_REGISTER (decl)
668 && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
669 error_with_decl (decl,
670 "data type of `%s' isn't suitable for a register");
671 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)
672 && ! HARD_REGNO_MODE_OK (reg_number,
673 TYPE_MODE (TREE_TYPE (decl))))
674 error_with_decl (decl,
675 "register number for `%s' isn't suitable for data type");
676 /* Now handle properly declared static register variables. */
677 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
681 if (DECL_INITIAL (decl) != 0 && top_level)
683 DECL_INITIAL (decl) = 0;
684 error ("global register variable has initial value");
686 if (fixed_regs[reg_number] == 0
687 && function_defined && top_level)
688 error ("global register variable follows a function definition");
689 if (TREE_THIS_VOLATILE (decl))
690 warning ("volatile register variables don't work as you might wish");
692 /* If the user specified one of the eliminables registers here,
693 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
694 confused with that register and be eliminated. Although this
695 usage is somewhat suspect, we nevertheless use the following
696 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
699 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
700 REGNO (DECL_RTL (decl)) = reg_number;
701 REG_USERVAR_P (DECL_RTL (decl)) = 1;
705 /* Make this register global, so not usable for anything
707 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
709 globalize_reg (reg_number + --nregs);
712 /* Specifying a section attribute on a variable forces it into a
713 non-.bss section, and thus it cannot be common. */
714 else if (TREE_CODE (decl) == VAR_DECL
715 && DECL_SECTION_NAME (decl) != NULL_TREE
716 && DECL_INITIAL (decl) == NULL_TREE
717 && DECL_COMMON (decl))
718 DECL_COMMON (decl) = 0;
720 /* Now handle ordinary static variables and functions (in memory).
721 Also handle vars declared register invalidly. */
722 if (DECL_RTL (decl) == 0)
724 /* Can't use just the variable's own name for a variable
725 whose scope is less than the whole file.
726 Concatenate a distinguishing number. */
727 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
731 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
732 name = obstack_copy0 (saveable_obstack, label, strlen (label));
739 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
740 gen_rtx (SYMBOL_REF, Pmode, name));
742 /* If this variable is to be treated as volatile, show its
743 tree node has side effects. If it has side effects, either
744 because of this test or from TREE_THIS_VOLATILE also
745 being set, show the MEM is volatile. */
746 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
747 && TREE_PUBLIC (decl))
748 TREE_SIDE_EFFECTS (decl) = 1;
749 if (TREE_SIDE_EFFECTS (decl))
750 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
752 if (TREE_READONLY (decl))
753 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
754 MEM_IN_STRUCT_P (DECL_RTL (decl))
755 = AGGREGATE_TYPE_P (TREE_TYPE (decl));
757 /* Optionally set flags or add text to the name to record information
758 such as that it is a function name.
759 If the name is changed, the macro ASM_OUTPUT_LABELREF
760 will have to know how to strip this information. */
761 #ifdef ENCODE_SECTION_INFO
762 ENCODE_SECTION_INFO (decl);
766 /* If the old RTL had the wrong mode, fix the mode. */
767 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
769 rtx rtl = DECL_RTL (decl);
770 PUT_MODE (rtl, DECL_MODE (decl));
774 /* Make the rtl for variable VAR be volatile.
775 Use this only for static variables. */
778 make_var_volatile (var)
781 if (GET_CODE (DECL_RTL (var)) != MEM)
784 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
787 /* Output alignment directive to align for constant expression EXP. */
790 assemble_constant_align (exp)
795 /* Align the location counter as required by EXP's data type. */
796 align = TYPE_ALIGN (TREE_TYPE (exp));
797 #ifdef CONSTANT_ALIGNMENT
798 align = CONSTANT_ALIGNMENT (exp, align);
801 if (align > BITS_PER_UNIT)
802 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
805 /* Output a string of literal assembler code
806 for an `asm' keyword used between functions. */
809 assemble_asm (string)
814 error ("asm statements not allowed in interpreter");
820 if (TREE_CODE (string) == ADDR_EXPR)
821 string = TREE_OPERAND (string, 0);
823 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
826 #if 0 /* This should no longer be needed, because
827 flag_gnu_linker should be 0 on these systems,
828 which should prevent any output
829 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
830 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
831 #ifndef ASM_OUTPUT_CONSTRUCTOR
832 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
834 #ifndef ASM_OUTPUT_DESTRUCTOR
835 #define ASM_OUTPUT_DESTRUCTOR(file, name)
840 /* Record an element in the table of global destructors.
841 How this is done depends on what sort of assembler and linker
844 NAME should be the name of a global function to be called
845 at exit time. This name is output using assemble_name. */
848 assemble_destructor (name)
851 #ifdef ASM_OUTPUT_DESTRUCTOR
852 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
856 /* Now tell GNU LD that this is part of the static destructor set. */
857 /* This code works for any machine provided you use GNU as/ld. */
858 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
859 assemble_name (asm_out_file, name);
860 fputc ('\n', asm_out_file);
865 /* Likewise for global constructors. */
868 assemble_constructor (name)
871 #ifdef ASM_OUTPUT_CONSTRUCTOR
872 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
876 /* Now tell GNU LD that this is part of the static constructor set. */
877 /* This code works for any machine provided you use GNU as/ld. */
878 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
879 assemble_name (asm_out_file, name);
880 fputc ('\n', asm_out_file);
885 /* Likewise for entries we want to record for garbage collection.
886 Garbage collection is still under development. */
889 assemble_gc_entry (name)
892 #ifdef ASM_OUTPUT_GC_ENTRY
893 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
897 /* Now tell GNU LD that this is part of the static constructor set. */
898 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
899 assemble_name (asm_out_file, name);
900 fputc ('\n', asm_out_file);
905 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
906 a non-zero value if the constant pool should be output before the
907 start of the function, or a zero value if the pool should output
908 after the end of the function. The default is to put it before the
911 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
912 #define CONSTANT_POOL_BEFORE_FUNCTION 1
915 /* Output assembler code for the constant pool of a function and associated
916 with defining the name of the function. DECL describes the function.
917 NAME is the function's name. For the constant pool, we use the current
918 constant pool data. */
921 assemble_start_function (decl, fnname)
927 /* The following code does not need preprocessing in the assembler. */
931 if (CONSTANT_POOL_BEFORE_FUNCTION)
932 output_constant_pool (fnname, decl);
934 #ifdef ASM_OUTPUT_SECTION_NAME
935 /* If the function is to be put in its own section and it's not in a section
936 already, indicate so. */
937 if (flag_function_sections
938 && DECL_SECTION_NAME (decl) == NULL_TREE)
940 #ifdef UNIQUE_SECTION
941 DECL_SECTION_NAME(decl) = UNIQUE_SECTION (decl);
943 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
944 /* Strip off any encoding in name. */
945 STRIP_NAME_ENCODING (name, name);
946 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
951 function_section (decl);
953 /* Tell assembler to move to target machine's alignment for functions. */
954 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
958 BC_OUTPUT_ALIGN (asm_out_file, align);
960 ASM_OUTPUT_ALIGN (asm_out_file, align);
963 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
964 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
967 #ifdef SDB_DEBUGGING_INFO
968 /* Output SDB definition of the function. */
969 if (write_symbols == SDB_DEBUG)
970 sdbout_mark_begin_function ();
973 #ifdef DBX_DEBUGGING_INFO
974 /* Output DBX definition of the function. */
975 if (write_symbols == DBX_DEBUG)
976 dbxout_begin_function (decl);
979 /* Make function name accessible from other files, if appropriate. */
981 if (TREE_PUBLIC (decl))
983 if (!first_global_object_name && ! DECL_WEAK (decl)
984 && ! DECL_ONE_ONLY (decl))
988 STRIP_NAME_ENCODING (p, fnname);
989 first_global_object_name = permalloc (strlen (p) + 1);
990 strcpy (first_global_object_name, p);
993 #ifdef ASM_WEAKEN_LABEL
994 if (DECL_WEAK (decl))
995 ASM_WEAKEN_LABEL (asm_out_file, fnname);
999 BC_GLOBALIZE_LABEL (asm_out_file, fnname);
1001 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
1004 /* Do any machine/system dependent processing of the function name */
1005 if (output_bytecode)
1006 BC_OUTPUT_LABEL (asm_out_file, fnname);
1009 #ifdef ASM_DECLARE_FUNCTION_NAME
1010 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1012 /* Standard thing is just output label for the function. */
1013 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1014 #endif /* ASM_DECLARE_FUNCTION_NAME */
1018 /* Output assembler code associated with defining the size of the
1019 function. DECL describes the function. NAME is the function's name. */
1022 assemble_end_function (decl, fnname)
1026 #ifdef ASM_DECLARE_FUNCTION_SIZE
1027 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1029 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1030 output_constant_pool (fnname, decl);
1032 /* Output any constants which should appear after the function. */
1033 output_after_function_constants ();
1036 /* Assemble code to leave SIZE bytes of zeros. */
1039 assemble_zeros (size)
1042 if (output_bytecode)
1044 bc_emit_const_skip (size);
1048 #ifdef ASM_NO_SKIP_IN_TEXT
1049 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1050 so we must output 0s explicitly in the text section. */
1051 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1055 for (i = 0; i < size - 20; i += 20)
1058 fprintf (asm_out_file,
1059 "%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);
1061 fprintf (asm_out_file,
1062 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1068 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
1070 fprintf (asm_out_file, "\tbyte 0");
1073 for (; i < size; i++)
1074 fprintf (asm_out_file, ",0");
1075 fprintf (asm_out_file, "\n");
1082 if (output_bytecode)
1083 BC_OUTPUT_SKIP (asm_out_file, size);
1085 ASM_OUTPUT_SKIP (asm_out_file, size);
1089 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1092 assemble_align (align)
1095 if (align > BITS_PER_UNIT)
1096 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1099 /* Assemble a string constant with the specified C string as contents. */
1102 assemble_string (p, size)
1110 if (output_bytecode)
1116 /* If the string is very long, split it up. */
1120 int thissize = size - pos;
1121 if (thissize > maximum)
1124 if (output_bytecode)
1125 bc_output_ascii (asm_out_file, p, thissize);
1128 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1137 bc_output_ascii (file, p, size)
1142 BC_OUTPUT_ASCII (file, p, size);
1145 /* Assemble everything that is needed for a variable or function declaration.
1146 Not used for automatic variables, and not used for function definitions.
1147 Should not be called for variables of incomplete structure type.
1149 TOP_LEVEL is nonzero if this variable has file scope.
1150 AT_END is nonzero if this is the special handling, at end of compilation,
1151 to define things that have had only tentative definitions.
1152 DONT_OUTPUT_DATA if nonzero means don't actually output the
1153 initial value (that will be done by the caller). */
1156 assemble_variable (decl, top_level, at_end, dont_output_data)
1160 int dont_output_data;
1162 register char *name;
1166 enum in_section saved_in_section;
1168 last_assemble_variable_decl = 0;
1170 if (output_bytecode)
1173 if (GET_CODE (DECL_RTL (decl)) == REG)
1175 /* Do output symbol info for global register variables, but do nothing
1178 if (TREE_ASM_WRITTEN (decl))
1180 TREE_ASM_WRITTEN (decl) = 1;
1182 if (!output_bytecode)
1184 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1185 /* File-scope global variables are output here. */
1186 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1188 dbxout_symbol (decl, 0);
1190 #ifdef SDB_DEBUGGING_INFO
1191 if (write_symbols == SDB_DEBUG && top_level
1192 /* Leave initialized global vars for end of compilation;
1193 see comment in compile_file. */
1194 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1195 sdbout_symbol (decl, 0);
1199 /* Don't output any DWARF debugging information for variables here.
1200 In the case of local variables, the information for them is output
1201 when we do our recursive traversal of the tree representation for
1202 the entire containing function. In the case of file-scope variables,
1203 we output information for all of them at the very end of compilation
1204 while we are doing our final traversal of the chain of file-scope
1210 /* Normally no need to say anything here for external references,
1211 since assemble_external is called by the language-specific code
1212 when a declaration is first seen. */
1214 if (DECL_EXTERNAL (decl))
1217 /* Output no assembler code for a function declaration.
1218 Only definitions of functions output anything. */
1220 if (TREE_CODE (decl) == FUNCTION_DECL)
1223 /* If type was incomplete when the variable was declared,
1224 see if it is complete now. */
1226 if (DECL_SIZE (decl) == 0)
1227 layout_decl (decl, 0);
1229 /* Still incomplete => don't allocate it; treat the tentative defn
1230 (which is what it must have been) as an `extern' reference. */
1232 if (!dont_output_data && DECL_SIZE (decl) == 0)
1234 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1235 DECL_SOURCE_LINE (decl),
1236 "storage size of `%s' isn't known",
1237 IDENTIFIER_POINTER (DECL_NAME (decl)));
1238 TREE_ASM_WRITTEN (decl) = 1;
1242 /* The first declaration of a variable that comes through this function
1243 decides whether it is global (in C, has external linkage)
1244 or local (in C, has internal linkage). So do nothing more
1245 if this function has already run. */
1247 if (TREE_ASM_WRITTEN (decl))
1250 TREE_ASM_WRITTEN (decl) = 1;
1254 if (! dont_output_data)
1256 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1259 /* This is better than explicit arithmetic, since it avoids overflow. */
1260 size_tree = size_binop (CEIL_DIV_EXPR,
1261 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1263 if (TREE_INT_CST_HIGH (size_tree) != 0)
1265 error_with_decl (decl, "size of variable `%s' is too large");
1270 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1272 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1273 && ! first_global_object_name
1274 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1275 || DECL_INITIAL (decl) == error_mark_node))
1276 && ! DECL_WEAK (decl)
1277 && ! DECL_ONE_ONLY (decl))
1281 STRIP_NAME_ENCODING (p, name);
1282 first_global_object_name = permalloc (strlen (p) + 1);
1283 strcpy (first_global_object_name, p);
1286 /* Handle uninitialized definitions. */
1288 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1289 /* If the target can't output uninitialized but not common global data
1290 in .bss, then we have to use .data. */
1291 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
1292 && DECL_COMMON (decl)
1294 && ! dont_output_data)
1296 int size = TREE_INT_CST_LOW (size_tree);
1299 /* Don't allocate zero bytes of common,
1300 since that means "undefined external" in the linker. */
1301 if (size == 0) rounded = 1;
1302 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1303 so that each uninitialized object starts on such a boundary. */
1304 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1305 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1306 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1308 #ifdef DBX_DEBUGGING_INFO
1309 /* File-scope global variables are output here. */
1310 if (write_symbols == DBX_DEBUG && top_level)
1311 dbxout_symbol (decl, 0);
1313 #ifdef SDB_DEBUGGING_INFO
1314 if (write_symbols == SDB_DEBUG && top_level
1315 /* Leave initialized global vars for end of compilation;
1316 see comment in compile_file. */
1317 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1318 sdbout_symbol (decl, 0);
1321 /* Don't output any DWARF debugging information for variables here.
1322 In the case of local variables, the information for them is output
1323 when we do our recursive traversal of the tree representation for
1324 the entire containing function. In the case of file-scope variables,
1325 we output information for all of them at the very end of compilation
1326 while we are doing our final traversal of the chain of file-scope
1329 #if 0 /* ??? We should either delete this or add a comment describing what
1330 it was intended to do and why we shouldn't delete it. */
1331 if (flag_shared_data)
1335 if (TREE_PUBLIC (decl)
1336 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1337 && DECL_COMMON (decl)
1341 #ifdef ASM_OUTPUT_SHARED_COMMON
1342 if (flag_shared_data)
1343 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1346 if (output_bytecode)
1348 BC_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1352 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1353 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1356 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1360 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1361 else if (TREE_PUBLIC (decl))
1363 #ifdef ASM_OUTPUT_SHARED_BSS
1364 if (flag_shared_data)
1365 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1368 if (output_bytecode)
1370 BC_OUTPUT_BSS (asm_out_file, name, size, rounded);
1374 #ifdef ASM_OUTPUT_ALIGNED_BSS
1375 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size,
1378 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1382 #endif /* ASM_OUTPUT_BSS || ASM_OUTPUT_ALIGNED_BSS */
1385 #ifdef ASM_OUTPUT_SHARED_LOCAL
1386 if (flag_shared_data)
1387 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1390 if (output_bytecode)
1392 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1396 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1397 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1400 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1407 /* Handle initialized definitions.
1408 Also handle uninitialized global definitions if -fno-common and the
1409 target doesn't support ASM_OUTPUT_BSS. */
1411 /* First make the assembler name(s) global if appropriate. */
1412 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1414 #ifdef ASM_WEAKEN_LABEL
1415 if (DECL_WEAK (decl))
1416 ASM_WEAKEN_LABEL (asm_out_file, name);
1419 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1422 for (d = equivalents; d; d = TREE_CHAIN (d))
1424 tree e = TREE_VALUE (d);
1425 if (TREE_PUBLIC (e) && DECL_NAME (e))
1426 ASM_GLOBALIZE_LABEL (asm_out_file,
1427 XSTR (XEXP (DECL_RTL (e), 0), 0));
1431 /* Output any data that we will need to use the address of. */
1432 if (DECL_INITIAL (decl) == error_mark_node)
1433 reloc = contains_pointers_p (TREE_TYPE (decl));
1434 else if (DECL_INITIAL (decl))
1435 reloc = output_addressed_constants (DECL_INITIAL (decl));
1437 /* Switch to the appropriate section. */
1438 variable_section (decl, reloc);
1440 /* dbxout.c needs to know this. */
1441 if (in_text_section ())
1442 DECL_IN_TEXT_SECTION (decl) = 1;
1444 /* Record current section so we can restore it if dbxout.c clobbers it. */
1445 saved_in_section = in_section;
1447 /* Output the dbx info now that we have chosen the section. */
1449 #ifdef DBX_DEBUGGING_INFO
1450 /* File-scope global variables are output here. */
1451 if (write_symbols == DBX_DEBUG && top_level)
1452 dbxout_symbol (decl, 0);
1454 #ifdef SDB_DEBUGGING_INFO
1455 if (write_symbols == SDB_DEBUG && top_level
1456 /* Leave initialized global vars for end of compilation;
1457 see comment in compile_file. */
1458 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1459 sdbout_symbol (decl, 0);
1462 /* Don't output any DWARF debugging information for variables here.
1463 In the case of local variables, the information for them is output
1464 when we do our recursive traversal of the tree representation for
1465 the entire containing function. In the case of file-scope variables,
1466 we output information for all of them at the very end of compilation
1467 while we are doing our final traversal of the chain of file-scope
1470 /* If the debugging output changed sections, reselect the section
1471 that's supposed to be selected. */
1472 if (in_section != saved_in_section)
1473 variable_section (decl, reloc);
1475 /* Compute and output the alignment of this data. */
1477 align = DECL_ALIGN (decl);
1478 /* In the case for initialing an array whose length isn't specified,
1479 where we have not yet been able to do the layout,
1480 figure out the proper alignment now. */
1481 if (dont_output_data && DECL_SIZE (decl) == 0
1482 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1483 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1485 /* Some object file formats have a maximum alignment which they support.
1486 In particular, a.out format supports a maximum alignment of 4. */
1487 #ifndef MAX_OFILE_ALIGNMENT
1488 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1490 if (align > MAX_OFILE_ALIGNMENT)
1492 warning_with_decl (decl,
1493 "alignment of `%s' is greater than maximum object file alignment");
1494 align = MAX_OFILE_ALIGNMENT;
1496 #ifdef DATA_ALIGNMENT
1497 /* On some machines, it is good to increase alignment sometimes. */
1498 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1500 #ifdef CONSTANT_ALIGNMENT
1501 if (DECL_INITIAL (decl))
1502 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1505 /* Reset the alignment in case we have made it tighter, so we can benefit
1506 from it in get_pointer_alignment. */
1507 DECL_ALIGN (decl) = align;
1509 if (align > BITS_PER_UNIT)
1511 if (output_bytecode)
1512 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1514 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1517 /* Do any machine/system dependent processing of the object. */
1518 if (output_bytecode)
1519 BC_OUTPUT_LABEL (asm_out_file, name);
1522 #ifdef ASM_DECLARE_OBJECT_NAME
1523 last_assemble_variable_decl = decl;
1524 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1526 /* Standard thing is just output label for the object. */
1527 ASM_OUTPUT_LABEL (asm_out_file, name);
1528 #endif /* ASM_DECLARE_OBJECT_NAME */
1531 if (!dont_output_data)
1533 if (DECL_INITIAL (decl))
1534 /* Output the actual data. */
1535 output_constant (DECL_INITIAL (decl), TREE_INT_CST_LOW (size_tree));
1537 /* Leave space for it. */
1538 assemble_zeros (TREE_INT_CST_LOW (size_tree));
1542 #ifdef XCOFF_DEBUGGING_INFO
1543 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1544 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1545 and `aa' hasn't been output yet, the assembler generates a stab entry with
1546 a value of zero, in addition to creating an unnecessary external entry
1547 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1549 /* File-scope global variables are output here. */
1550 if (write_symbols == XCOFF_DEBUG && top_level)
1552 saved_in_section = in_section;
1554 dbxout_symbol (decl, 0);
1556 if (in_section != saved_in_section)
1557 variable_section (decl, reloc);
1560 /* There must be a statement after a label. */
1565 /* Return 1 if type TYPE contains any pointers. */
1568 contains_pointers_p (type)
1571 switch (TREE_CODE (type))
1574 case REFERENCE_TYPE:
1575 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1576 so I'll play safe and return 1. */
1582 case QUAL_UNION_TYPE:
1585 /* For a type that has fields, see if the fields have pointers. */
1586 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1587 if (TREE_CODE (fields) == FIELD_DECL
1588 && contains_pointers_p (TREE_TYPE (fields)))
1594 /* An array type contains pointers if its element type does. */
1595 return contains_pointers_p (TREE_TYPE (type));
1602 /* Output text storage for constructor CONSTR. */
1605 bc_output_constructor (constr, size)
1611 /* Must always be a literal; non-literal constructors are handled
1614 if (!TREE_CONSTANT (constr))
1621 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++)
1625 BC_OUTPUT_ALIGN (asm_out_file, i);
1628 output_constant (constr, size);
1631 /* Create storage for constructor CONSTR. */
1634 bc_output_data_constructor (constr)
1639 /* Put in data section */
1643 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1645 BC_OUTPUT_ALIGN (asm_out_file, i);
1647 /* The constructor is filled in at runtime. */
1648 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1651 /* Output something to declare an external symbol to the assembler.
1652 (Most assemblers don't need this, so we normally output nothing.)
1653 Do nothing if DECL is not external. */
1656 assemble_external (decl)
1659 if (output_bytecode)
1662 #ifdef ASM_OUTPUT_EXTERNAL
1663 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1664 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1666 rtx rtl = DECL_RTL (decl);
1668 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1669 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1671 /* Some systems do require some output. */
1672 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1673 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1679 /* Similar, for calling a library function FUN. */
1682 assemble_external_libcall (fun)
1685 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1686 if (!output_bytecode)
1688 /* Declare library function name external when first used, if nec. */
1689 if (! SYMBOL_REF_USED (fun))
1691 SYMBOL_REF_USED (fun) = 1;
1692 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1698 /* Declare the label NAME global. */
1701 assemble_global (name)
1704 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1707 /* Assemble a label named NAME. */
1710 assemble_label (name)
1713 if (output_bytecode)
1714 BC_OUTPUT_LABEL (asm_out_file, name);
1716 ASM_OUTPUT_LABEL (asm_out_file, name);
1719 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1720 If NAME starts with a *, the rest of NAME is output verbatim.
1721 Otherwise NAME is transformed in an implementation-defined way
1722 (usually by the addition of an underscore).
1723 Many macros in the tm file are defined to call this function. */
1726 assemble_name (file, name)
1733 STRIP_NAME_ENCODING (real_name, name);
1735 id = maybe_get_identifier (real_name);
1737 TREE_SYMBOL_REFERENCED (id) = 1;
1741 if (output_bytecode)
1742 bc_emit_labelref (name, 0);
1744 fputs (&name[1], file);
1748 if (output_bytecode)
1749 BC_OUTPUT_LABELREF (file, name);
1751 ASM_OUTPUT_LABELREF (file, name);
1755 /* Allocate SIZE bytes writable static space with a gensym name
1756 and return an RTX to refer to its address. */
1759 assemble_static_space (size)
1765 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1766 so that each uninitialized object starts on such a boundary. */
1767 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1768 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1769 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1772 if (flag_shared_data)
1776 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1779 namestring = (char *) obstack_alloc (saveable_obstack,
1781 strcpy (namestring, name);
1783 if (output_bytecode)
1784 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1786 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1788 if (output_bytecode)
1790 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1794 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1795 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1797 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1803 /* Assemble the static constant template for function entry trampolines.
1804 This is done at most once per compilation.
1805 Returns an RTX for the address of the template. */
1807 #ifdef TRAMPOLINE_TEMPLATE
1809 assemble_trampoline_template ()
1815 /* Shouldn't get here */
1816 if (output_bytecode)
1819 /* By default, put trampoline templates in read-only data section. */
1821 #ifdef TRAMPOLINE_SECTION
1822 TRAMPOLINE_SECTION ();
1824 readonly_data_section ();
1827 /* Write the assembler code to define one. */
1828 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1830 ASM_OUTPUT_ALIGN (asm_out_file, align);
1832 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1833 TRAMPOLINE_TEMPLATE (asm_out_file);
1835 /* Record the rtl to refer to it. */
1836 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1838 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1839 return gen_rtx (SYMBOL_REF, Pmode, name);
1843 /* Assemble the integer constant X into an object of SIZE bytes.
1844 X must be either a CONST_INT or CONST_DOUBLE.
1846 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1847 non-zero, abort if we can't output the constant. */
1850 assemble_integer (x, size, force)
1855 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1856 ASM_OUTPUT... macros. */
1860 #ifdef ASM_OUTPUT_CHAR
1862 ASM_OUTPUT_CHAR (asm_out_file, x);
1866 #ifdef ASM_OUTPUT_SHORT
1868 ASM_OUTPUT_SHORT (asm_out_file, x);
1872 #ifdef ASM_OUTPUT_INT
1874 ASM_OUTPUT_INT (asm_out_file, x);
1878 #ifdef ASM_OUTPUT_DOUBLE_INT
1880 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1884 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1886 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1891 /* If we couldn't do it that way, there are two other possibilities: First,
1892 if the machine can output an explicit byte and this is a 1 byte constant,
1893 we can use ASM_OUTPUT_BYTE. */
1895 #ifdef ASM_OUTPUT_BYTE
1896 if (size == 1 && GET_CODE (x) == CONST_INT)
1898 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1903 /* Finally, if SIZE is larger than a single word, try to output the constant
1904 one word at a time. */
1906 if (size > UNITS_PER_WORD)
1909 enum machine_mode mode
1910 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1913 for (i = 0; i < size / UNITS_PER_WORD; i++)
1915 word = operand_subword (x, i, 0, mode);
1920 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1924 if (i == size / UNITS_PER_WORD)
1926 /* If we output at least one word and then could not finish,
1927 there is no valid way to continue. */
1938 /* Assemble the floating-point constant D into an object of size MODE. */
1941 assemble_real (d, mode)
1943 enum machine_mode mode;
1945 jmp_buf output_constant_handler;
1947 if (setjmp (output_constant_handler))
1949 error ("floating point trap outputting a constant");
1950 #ifdef REAL_IS_NOT_DOUBLE
1951 bzero ((char *) &d, sizeof d);
1958 set_float_handler (output_constant_handler);
1962 #ifdef ASM_OUTPUT_BYTE_FLOAT
1964 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1967 #ifdef ASM_OUTPUT_SHORT_FLOAT
1969 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1972 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1974 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1977 #ifdef ASM_OUTPUT_FLOAT
1979 ASM_OUTPUT_FLOAT (asm_out_file, d);
1983 #ifdef ASM_OUTPUT_DOUBLE
1985 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1989 #ifdef ASM_OUTPUT_LONG_DOUBLE
1992 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
2000 set_float_handler (NULL_PTR);
2003 /* Here we combine duplicate floating constants to make
2004 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
2006 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
2007 They are chained through the CONST_DOUBLE_CHAIN.
2008 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
2009 In that case, CONST_DOUBLE_MEM is either a MEM,
2010 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
2012 (CONST_DOUBLE_MEM is used only for top-level functions.
2013 See force_const_mem for explanation.) */
2015 static rtx const_double_chain;
2017 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2018 For an integer, I0 is the low-order word and I1 is the high-order word.
2019 For a real number, I0 is the word with the low address
2020 and I1 is the word with the high address. */
2023 immed_double_const (i0, i1, mode)
2024 HOST_WIDE_INT i0, i1;
2025 enum machine_mode mode;
2028 int in_current_obstack;
2030 if (GET_MODE_CLASS (mode) == MODE_INT
2031 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
2033 /* We clear out all bits that don't belong in MODE, unless they and our
2034 sign bit are all one. So we get either a reasonable negative value
2035 or a reasonable unsigned value for this mode. */
2036 int width = GET_MODE_BITSIZE (mode);
2037 if (width < HOST_BITS_PER_WIDE_INT
2038 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
2039 != ((HOST_WIDE_INT) (-1) << (width - 1))))
2040 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
2041 else if (width == HOST_BITS_PER_WIDE_INT
2042 && ! (i1 == ~0 && i0 < 0))
2044 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2045 /* We cannot represent this value as a constant. */
2048 /* If this would be an entire word for the target, but is not for
2049 the host, then sign-extend on the host so that the number will look
2050 the same way on the host that it would on the target.
2052 For example, when building a 64 bit alpha hosted 32 bit sparc
2053 targeted compiler, then we want the 32 bit unsigned value -1 to be
2054 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2055 The later confuses the sparc backend. */
2057 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
2058 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2059 i0 |= ((HOST_WIDE_INT) (-1) << width);
2061 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2063 ??? Strictly speaking, this is wrong if we create a CONST_INT
2064 for a large unsigned constant with the size of MODE being
2065 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2066 wider mode. In that case we will mis-interpret it as a negative
2069 Unfortunately, the only alternative is to make a CONST_DOUBLE
2070 for any constant in any mode if it is an unsigned constant larger
2071 than the maximum signed integer in an int on the host. However,
2072 doing this will break everyone that always expects to see a CONST_INT
2073 for SImode and smaller.
2075 We have always been making CONST_INTs in this case, so nothing new
2078 if (width <= HOST_BITS_PER_WIDE_INT)
2079 i1 = (i0 < 0) ? ~0 : 0;
2081 /* If this integer fits in one word, return a CONST_INT. */
2082 if ((i1 == 0 && i0 >= 0)
2083 || (i1 == ~0 && i0 < 0))
2084 return GEN_INT (i0);
2086 /* We use VOIDmode for integers. */
2090 /* Search the chain for an existing CONST_DOUBLE with the right value.
2091 If one is found, return it. */
2093 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2094 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2095 && GET_MODE (r) == mode)
2098 /* No; make a new one and add it to the chain.
2100 We may be called by an optimizer which may be discarding any memory
2101 allocated during its processing (such as combine and loop). However,
2102 we will be leaving this constant on the chain, so we cannot tolerate
2103 freed memory. So switch to saveable_obstack for this allocation
2104 and then switch back if we were in current_obstack. */
2106 push_obstacks_nochange ();
2107 rtl_in_saveable_obstack ();
2108 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
2111 /* Don't touch const_double_chain in nested function; see force_const_mem.
2112 Also, don't touch it if not inside any function. */
2113 if (outer_function_chain == 0 && current_function_decl != 0)
2115 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2116 const_double_chain = r;
2119 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
2120 Actual use of mem-slot is only through force_const_mem. */
2122 CONST_DOUBLE_MEM (r) = const0_rtx;
2127 /* Return a CONST_DOUBLE for a specified `double' value
2128 and machine mode. */
2131 immed_real_const_1 (d, mode)
2133 enum machine_mode mode;
2135 union real_extract u;
2137 int in_current_obstack;
2139 /* Get the desired `double' value as a sequence of ints
2140 since that is how they are stored in a CONST_DOUBLE. */
2144 /* Detect special cases. */
2146 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
2147 if (!bcmp ((char *) &dconst0, (char *) &d, sizeof d))
2148 return CONST0_RTX (mode);
2149 /* Check for NaN first, because some ports (specifically the i386) do not
2150 emit correct ieee-fp code by default, and thus will generate a core
2151 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2152 does a floating point comparison. */
2153 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2154 return CONST1_RTX (mode);
2156 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2157 return immed_double_const (u.i[0], u.i[1], mode);
2159 /* The rest of this function handles the case where
2160 a float value requires more than 2 ints of space.
2161 It will be deleted as dead code on machines that don't need it. */
2163 /* Search the chain for an existing CONST_DOUBLE with the right value.
2164 If one is found, return it. */
2166 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2167 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2168 && GET_MODE (r) == mode)
2171 /* No; make a new one and add it to the chain.
2173 We may be called by an optimizer which may be discarding any memory
2174 allocated during its processing (such as combine and loop). However,
2175 we will be leaving this constant on the chain, so we cannot tolerate
2176 freed memory. So switch to saveable_obstack for this allocation
2177 and then switch back if we were in current_obstack. */
2179 push_obstacks_nochange ();
2180 rtl_in_saveable_obstack ();
2181 r = rtx_alloc (CONST_DOUBLE);
2183 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
2186 /* Don't touch const_double_chain in nested function; see force_const_mem.
2187 Also, don't touch it if not inside any function. */
2188 if (outer_function_chain == 0 && current_function_decl != 0)
2190 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2191 const_double_chain = r;
2194 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2195 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2196 is only through force_const_mem. */
2198 CONST_DOUBLE_MEM (r) = const0_rtx;
2203 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2204 which must be a REAL_CST tree node. */
2207 immed_real_const (exp)
2210 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2213 /* At the end of a function, forget the memory-constants
2214 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2215 Also clear out real_constant_chain and clear out all the chain-pointers. */
2218 clear_const_double_mem ()
2220 register rtx r, next;
2222 /* Don't touch CONST_DOUBLE_MEM for nested functions.
2223 See force_const_mem for explanation. */
2224 if (outer_function_chain != 0)
2227 for (r = const_double_chain; r; r = next)
2229 next = CONST_DOUBLE_CHAIN (r);
2230 CONST_DOUBLE_CHAIN (r) = 0;
2231 CONST_DOUBLE_MEM (r) = cc0_rtx;
2233 const_double_chain = 0;
2236 /* Given an expression EXP with a constant value,
2237 reduce it to the sum of an assembler symbol and an integer.
2238 Store them both in the structure *VALUE.
2239 Abort if EXP does not reduce. */
2244 HOST_WIDE_INT offset;
2248 decode_addr_const (exp, value)
2250 struct addr_const *value;
2252 register tree target = TREE_OPERAND (exp, 0);
2253 register int offset = 0;
2258 if (TREE_CODE (target) == COMPONENT_REF
2259 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2262 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2263 target = TREE_OPERAND (target, 0);
2265 else if (TREE_CODE (target) == ARRAY_REF)
2267 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2268 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2270 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2271 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2273 target = TREE_OPERAND (target, 0);
2279 switch (TREE_CODE (target))
2283 x = DECL_RTL (target);
2287 if (output_bytecode)
2288 /* FIXME: this may not be correct, check it */
2289 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
2291 x = gen_rtx (MEM, FUNCTION_MODE,
2292 gen_rtx (LABEL_REF, VOIDmode,
2293 label_rtx (TREE_OPERAND (exp, 0))));
2301 x = TREE_CST_RTL (target);
2308 if (!output_bytecode)
2310 if (GET_CODE (x) != MEM)
2316 value->offset = offset;
2319 /* Uniquize all constants that appear in memory.
2320 Each constant in memory thus far output is recorded
2321 in `const_hash_table' with a `struct constant_descriptor'
2322 that contains a polish representation of the value of
2325 We cannot store the trees in the hash table
2326 because the trees may be temporary. */
2328 struct constant_descriptor
2330 struct constant_descriptor *next;
2336 #define MAX_HASH_TABLE 1009
2337 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2339 /* Compute a hash code for a constant expression. */
2346 register int len, hi, i;
2347 register enum tree_code code = TREE_CODE (exp);
2349 /* Either set P and LEN to the address and len of something to hash and
2350 exit the switch or return a value. */
2355 p = (char *) &TREE_INT_CST_LOW (exp);
2356 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2360 p = (char *) &TREE_REAL_CST (exp);
2361 len = sizeof TREE_REAL_CST (exp);
2365 p = TREE_STRING_POINTER (exp);
2366 len = TREE_STRING_LENGTH (exp);
2370 return (const_hash (TREE_REALPART (exp)) * 5
2371 + const_hash (TREE_IMAGPART (exp)));
2374 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2376 len = int_size_in_bytes (TREE_TYPE (exp));
2377 p = (char *) alloca (len);
2378 get_set_constructor_bytes (exp, (unsigned char *) p, len);
2385 /* For record type, include the type in the hashing.
2386 We do not do so for array types
2387 because (1) the sizes of the elements are sufficient
2388 and (2) distinct array types can have the same constructor.
2389 Instead, we include the array size because the constructor could
2391 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2392 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2395 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2396 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2398 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2399 if (TREE_VALUE (link))
2401 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2408 struct addr_const value;
2410 decode_addr_const (exp, &value);
2411 if (GET_CODE (value.base) == SYMBOL_REF)
2413 /* Don't hash the address of the SYMBOL_REF;
2414 only use the offset and the symbol name. */
2416 p = XSTR (value.base, 0);
2417 for (i = 0; p[i] != 0; i++)
2418 hi = ((hi * 613) + (unsigned) (p[i]));
2420 else if (GET_CODE (value.base) == LABEL_REF)
2421 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2423 hi &= (1 << HASHBITS) - 1;
2424 hi %= MAX_HASH_TABLE;
2430 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2431 + const_hash (TREE_OPERAND (exp, 1)));
2435 case NON_LVALUE_EXPR:
2436 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2439 /* Compute hashing function */
2441 for (i = 0; i < len; i++)
2442 hi = ((hi * 613) + (unsigned) (p[i]));
2444 hi &= (1 << HASHBITS) - 1;
2445 hi %= MAX_HASH_TABLE;
2449 /* Compare a constant expression EXP with a constant-descriptor DESC.
2450 Return 1 if DESC describes a constant with the same value as EXP. */
2453 compare_constant (exp, desc)
2455 struct constant_descriptor *desc;
2457 return 0 != compare_constant_1 (exp, desc->contents);
2460 /* Compare constant expression EXP with a substring P of a constant descriptor.
2461 If they match, return a pointer to the end of the substring matched.
2462 If they do not match, return 0.
2464 Since descriptors are written in polish prefix notation,
2465 this function can be used recursively to test one operand of EXP
2466 against a subdescriptor, and if it succeeds it returns the
2467 address of the subdescriptor for the next operand. */
2470 compare_constant_1 (exp, p)
2474 register char *strp;
2476 register enum tree_code code = TREE_CODE (exp);
2478 if (code != (enum tree_code) *p++)
2481 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2482 switch, or return the result of the comparison. */
2487 /* Integer constants are the same only if the same width of type. */
2488 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2491 strp = (char *) &TREE_INT_CST_LOW (exp);
2492 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2496 /* Real constants are the same only if the same width of type. */
2497 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2500 strp = (char *) &TREE_REAL_CST (exp);
2501 len = sizeof TREE_REAL_CST (exp);
2505 if (flag_writable_strings)
2508 strp = TREE_STRING_POINTER (exp);
2509 len = TREE_STRING_LENGTH (exp);
2510 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2511 sizeof TREE_STRING_LENGTH (exp)))
2514 p += sizeof TREE_STRING_LENGTH (exp);
2518 p = compare_constant_1 (TREE_REALPART (exp), p);
2522 return compare_constant_1 (TREE_IMAGPART (exp), p);
2525 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2527 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2529 strp = (char *) alloca (len);
2530 get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2531 if (bcmp ((char *) &xlen, p, sizeof xlen))
2540 int length = list_length (CONSTRUCTOR_ELTS (exp));
2543 if (bcmp ((char *) &length, p, sizeof length))
2548 /* For record constructors, insist that the types match.
2549 For arrays, just verify both constructors are for arrays. */
2550 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2551 type = TREE_TYPE (exp);
2555 if (bcmp ((char *) &type, p, sizeof type))
2560 /* For arrays, insist that the size in bytes match. */
2561 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2563 int size = int_size_in_bytes (TREE_TYPE (exp));
2564 if (bcmp ((char *) &size, p, sizeof size))
2570 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2572 if (TREE_VALUE (link))
2574 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2581 if (bcmp ((char *) &zero, p, sizeof zero))
2593 struct addr_const value;
2595 decode_addr_const (exp, &value);
2596 strp = (char *) &value.offset;
2597 len = sizeof value.offset;
2598 /* Compare the offset. */
2600 if (*p++ != *strp++)
2603 /* Compare symbol name. */
2604 strp = XSTR (value.base, 0);
2605 len = strlen (strp) + 1;
2611 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2615 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2619 case NON_LVALUE_EXPR:
2620 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2623 /* Compare constant contents. */
2625 if (*p++ != *strp++)
2631 /* Construct a constant descriptor for the expression EXP.
2632 It is up to the caller to enter the descriptor in the hash table. */
2634 static struct constant_descriptor *
2635 record_constant (exp)
2638 struct constant_descriptor *next = 0;
2641 /* Make a struct constant_descriptor. The first two pointers will
2642 be filled in later. Here we just leave space for them. */
2644 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2645 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2646 record_constant_1 (exp);
2647 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2650 /* Add a description of constant expression EXP
2651 to the object growing in `permanent_obstack'.
2652 No need to return its address; the caller will get that
2653 from the obstack when the object is complete. */
2656 record_constant_1 (exp)
2659 register char *strp;
2661 register enum tree_code code = TREE_CODE (exp);
2663 obstack_1grow (&permanent_obstack, (unsigned int) code);
2668 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2669 strp = (char *) &TREE_INT_CST_LOW (exp);
2670 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2674 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2675 strp = (char *) &TREE_REAL_CST (exp);
2676 len = sizeof TREE_REAL_CST (exp);
2680 if (flag_writable_strings)
2683 strp = TREE_STRING_POINTER (exp);
2684 len = TREE_STRING_LENGTH (exp);
2685 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2686 sizeof TREE_STRING_LENGTH (exp));
2690 record_constant_1 (TREE_REALPART (exp));
2691 record_constant_1 (TREE_IMAGPART (exp));
2695 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2697 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2698 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2699 obstack_blank (&permanent_obstack, nbytes);
2700 get_set_constructor_bytes
2701 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2708 int length = list_length (CONSTRUCTOR_ELTS (exp));
2711 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2713 /* For record constructors, insist that the types match.
2714 For arrays, just verify both constructors are for arrays. */
2715 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2716 type = TREE_TYPE (exp);
2719 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2721 /* For arrays, insist that the size in bytes match. */
2722 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2724 int size = int_size_in_bytes (TREE_TYPE (exp));
2725 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2728 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2730 if (TREE_VALUE (link))
2731 record_constant_1 (TREE_VALUE (link));
2736 obstack_grow (&permanent_obstack,
2737 (char *) &zero, sizeof zero);
2745 struct addr_const value;
2747 decode_addr_const (exp, &value);
2748 /* Record the offset. */
2749 obstack_grow (&permanent_obstack,
2750 (char *) &value.offset, sizeof value.offset);
2751 /* Record the symbol name. */
2752 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2753 strlen (XSTR (value.base, 0)) + 1);
2759 record_constant_1 (TREE_OPERAND (exp, 0));
2760 record_constant_1 (TREE_OPERAND (exp, 1));
2765 case NON_LVALUE_EXPR:
2766 record_constant_1 (TREE_OPERAND (exp, 0));
2773 /* Record constant contents. */
2774 obstack_grow (&permanent_obstack, strp, len);
2777 /* Record a list of constant expressions that were passed to
2778 output_constant_def but that could not be output right away. */
2780 struct deferred_constant
2782 struct deferred_constant *next;
2788 static struct deferred_constant *deferred_constants;
2790 /* Another list of constants which should be output after the
2792 static struct deferred_constant *after_function_constants;
2794 /* Nonzero means defer output of addressed subconstants
2795 (i.e., those for which output_constant_def is called.) */
2796 static int defer_addressed_constants_flag;
2798 /* Start deferring output of subconstants. */
2801 defer_addressed_constants ()
2803 defer_addressed_constants_flag++;
2806 /* Stop deferring output of subconstants,
2807 and output now all those that have been deferred. */
2810 output_deferred_addressed_constants ()
2812 struct deferred_constant *p, *next;
2814 defer_addressed_constants_flag--;
2816 if (defer_addressed_constants_flag > 0)
2819 for (p = deferred_constants; p; p = next)
2821 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2826 deferred_constants = 0;
2829 /* Output any constants which should appear after a function. */
2832 output_after_function_constants ()
2834 struct deferred_constant *p, *next;
2836 for (p = after_function_constants; p; p = next)
2838 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2843 after_function_constants = 0;
2846 /* Make a copy of the whole tree structure for a constant.
2847 This handles the same types of nodes that compare_constant
2848 and record_constant handle. */
2854 switch (TREE_CODE (exp))
2857 /* For ADDR_EXPR, we do not want to copy the decl whose address
2858 is requested. We do want to copy constants though. */
2859 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2860 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2861 copy_constant (TREE_OPERAND (exp, 0)));
2863 return copy_node (exp);
2868 return copy_node (exp);
2871 return build_complex (TREE_TYPE (exp),
2872 copy_constant (TREE_REALPART (exp)),
2873 copy_constant (TREE_IMAGPART (exp)));
2877 return build (TREE_CODE (exp), TREE_TYPE (exp),
2878 copy_constant (TREE_OPERAND (exp, 0)),
2879 copy_constant (TREE_OPERAND (exp, 1)));
2883 case NON_LVALUE_EXPR:
2884 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2885 copy_constant (TREE_OPERAND (exp, 0)));
2889 tree copy = copy_node (exp);
2890 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2893 CONSTRUCTOR_ELTS (copy) = list;
2894 for (tail = list; tail; tail = TREE_CHAIN (tail))
2895 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2896 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2897 for (tail = list; tail; tail = TREE_CHAIN (tail))
2898 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2908 /* Return an rtx representing a reference to constant data in memory
2909 for the constant expression EXP.
2911 If assembler code for such a constant has already been output,
2912 return an rtx to refer to it.
2913 Otherwise, output such a constant in memory (or defer it for later)
2914 and generate an rtx for it.
2916 The TREE_CST_RTL of EXP is set up to point to that rtx.
2917 The const_hash_table records which constants already have label strings. */
2920 output_constant_def (exp)
2924 register struct constant_descriptor *desc;
2930 if (TREE_CST_RTL (exp))
2931 return TREE_CST_RTL (exp);
2933 /* Make sure any other constants whose addresses appear in EXP
2934 are assigned label numbers. */
2936 reloc = output_addressed_constants (exp);
2938 /* Compute hash code of EXP. Search the descriptors for that hash code
2939 to see if any of them describes EXP. If yes, the descriptor records
2940 the label number already assigned. */
2942 hash = const_hash (exp) % MAX_HASH_TABLE;
2944 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2945 if (compare_constant (exp, desc))
2947 found = desc->label;
2953 /* No constant equal to EXP is known to have been output.
2954 Make a constant descriptor to enter EXP in the hash table.
2955 Assign the label number and record it in the descriptor for
2956 future calls to this function to find. */
2958 /* Create a string containing the label name, in LABEL. */
2959 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2961 desc = record_constant (exp);
2962 desc->next = const_hash_table[hash];
2964 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2965 const_hash_table[hash] = desc;
2969 /* Create a string containing the label name, in LABEL. */
2970 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2973 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2975 push_obstacks_nochange ();
2976 if (TREE_PERMANENT (exp))
2977 end_temporary_allocation ();
2979 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2982 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2983 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2984 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2985 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2989 /* Optionally set flags or add text to the name to record information
2990 such as that it is a function name. If the name is changed, the macro
2991 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2992 #ifdef ENCODE_SECTION_INFO
2993 ENCODE_SECTION_INFO (exp);
2996 /* If this is the first time we've seen this particular constant,
2997 output it (or defer its output for later). */
3000 int after_function = 0;
3002 #ifdef CONSTANT_AFTER_FUNCTION_P
3003 if (current_function_decl != 0
3004 && CONSTANT_AFTER_FUNCTION_P (exp))
3008 if (defer_addressed_constants_flag || after_function)
3010 struct deferred_constant *p;
3011 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
3013 push_obstacks_nochange ();
3014 suspend_momentary ();
3015 p->exp = copy_constant (exp);
3018 p->labelno = const_labelno++;
3021 p->next = after_function_constants;
3022 after_function_constants = p;
3026 p->next = deferred_constants;
3027 deferred_constants = p;
3031 output_constant_def_contents (exp, reloc, const_labelno++);
3034 return TREE_CST_RTL (exp);
3037 /* Now output assembler code to define the label for EXP,
3038 and follow it with the data of EXP. */
3041 output_constant_def_contents (exp, reloc, labelno)
3048 if (IN_NAMED_SECTION (exp))
3049 named_section (exp, NULL);
3052 /* First switch to text section, except for writable strings. */
3053 #ifdef SELECT_SECTION
3054 SELECT_SECTION (exp, reloc);
3056 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3057 || (flag_pic && reloc))
3060 readonly_data_section ();
3064 /* Align the location counter as required by EXP's data type. */
3065 align = TYPE_ALIGN (TREE_TYPE (exp));
3066 #ifdef CONSTANT_ALIGNMENT
3067 align = CONSTANT_ALIGNMENT (exp, align);
3070 if (align > BITS_PER_UNIT)
3072 if (!output_bytecode)
3074 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3078 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3082 /* Output the label itself. */
3083 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3085 /* Output the value of EXP. */
3086 output_constant (exp,
3087 (TREE_CODE (exp) == STRING_CST
3088 ? TREE_STRING_LENGTH (exp)
3089 : int_size_in_bytes (TREE_TYPE (exp))));
3093 /* Similar hash facility for making memory-constants
3094 from constant rtl-expressions. It is used on RISC machines
3095 where immediate integer arguments and constant addresses are restricted
3096 so that such constants must be stored in memory.
3098 This pool of constants is reinitialized for each function
3099 so each function gets its own constants-pool that comes right before it.
3101 All structures allocated here are discarded when functions are saved for
3102 inlining, so they do not need to be allocated permanently. */
3104 #define MAX_RTX_HASH_TABLE 61
3105 static struct constant_descriptor **const_rtx_hash_table;
3107 /* Structure to represent sufficient information about a constant so that
3108 it can be output when the constant pool is output, so that function
3109 integration can be done, and to simplify handling on machines that reference
3110 constant pool as base+displacement. */
3112 struct pool_constant
3114 struct constant_descriptor *desc;
3115 struct pool_constant *next;
3116 enum machine_mode mode;
3124 /* Pointers to first and last constant in pool. */
3126 static struct pool_constant *first_pool, *last_pool;
3128 /* Current offset in constant pool (does not include any machine-specific
3131 static int pool_offset;
3133 /* Structure used to maintain hash table mapping symbols used to their
3134 corresponding constants. */
3139 struct pool_constant *pool;
3140 struct pool_sym *next;
3143 static struct pool_sym **const_rtx_sym_hash_table;
3145 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3146 The argument is XSTR (... , 0) */
3148 #define SYMHASH(LABEL) \
3149 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3151 /* Initialize constant pool hashing for next function. */
3154 init_const_rtx_hash_table ()
3156 const_rtx_hash_table
3157 = ((struct constant_descriptor **)
3158 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
3159 const_rtx_sym_hash_table
3160 = ((struct pool_sym **)
3161 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
3162 bzero ((char *) const_rtx_hash_table,
3163 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
3164 bzero ((char *) const_rtx_sym_hash_table,
3165 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
3167 first_pool = last_pool = 0;
3171 /* Save and restore status for a nested function. */
3174 save_varasm_status (p)
3177 p->const_rtx_hash_table = const_rtx_hash_table;
3178 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
3179 p->first_pool = first_pool;
3180 p->last_pool = last_pool;
3181 p->pool_offset = pool_offset;
3185 restore_varasm_status (p)
3188 const_rtx_hash_table = p->const_rtx_hash_table;
3189 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
3190 first_pool = p->first_pool;
3191 last_pool = p->last_pool;
3192 pool_offset = p->pool_offset;
3195 enum kind { RTX_DOUBLE, RTX_INT };
3199 #ifdef ONLY_INT_FIELDS
3200 unsigned int kind : 16;
3201 unsigned int mode : 16;
3203 enum kind kind : 16;
3204 enum machine_mode mode : 16;
3207 union real_extract du;
3208 struct addr_const addr;
3209 struct {HOST_WIDE_INT high, low;} di;
3213 /* Express an rtx for a constant integer (perhaps symbolic)
3214 as the sum of a symbol or label plus an explicit integer.
3215 They are stored into VALUE. */
3218 decode_rtx_const (mode, x, value)
3219 enum machine_mode mode;
3221 struct rtx_const *value;
3223 /* Clear the whole structure, including any gaps. */
3226 int *p = (int *) value;
3227 int *end = (int *) (value + 1);
3232 value->kind = RTX_INT; /* Most usual kind. */
3235 switch (GET_CODE (x))
3238 value->kind = RTX_DOUBLE;
3239 if (GET_MODE (x) != VOIDmode)
3241 value->mode = GET_MODE (x);
3242 bcopy ((char *) &CONST_DOUBLE_LOW (x),
3243 (char *) &value->un.du, sizeof value->un.du);
3247 value->un.di.low = CONST_DOUBLE_LOW (x);
3248 value->un.di.high = CONST_DOUBLE_HIGH (x);
3253 value->un.addr.offset = INTVAL (x);
3259 value->un.addr.base = x;
3264 if (GET_CODE (x) == PLUS)
3266 value->un.addr.base = XEXP (x, 0);
3267 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3269 value->un.addr.offset = INTVAL (XEXP (x, 1));
3271 else if (GET_CODE (x) == MINUS)
3273 value->un.addr.base = XEXP (x, 0);
3274 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3276 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3286 if (value->kind == RTX_INT && value->un.addr.base != 0)
3287 switch (GET_CODE (value->un.addr.base))
3291 /* Use the string's address, not the SYMBOL_REF's address,
3292 for the sake of addresses of library routines.
3293 For a LABEL_REF, compare labels. */
3294 value->un.addr.base = XEXP (value->un.addr.base, 0);
3298 /* Given a MINUS expression, simplify it if both sides
3299 include the same symbol. */
3302 simplify_subtraction (x)
3305 struct rtx_const val0, val1;
3307 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3308 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3310 if (val0.un.addr.base == val1.un.addr.base)
3311 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3315 /* Compute a hash code for a constant RTL expression. */
3318 const_hash_rtx (mode, x)
3319 enum machine_mode mode;
3324 struct rtx_const value;
3325 decode_rtx_const (mode, x, &value);
3327 /* Compute hashing function */
3329 for (i = 0; i < sizeof value / sizeof (int); i++)
3330 hi += ((int *) &value)[i];
3332 hi &= (1 << HASHBITS) - 1;
3333 hi %= MAX_RTX_HASH_TABLE;
3337 /* Compare a constant rtl object X with a constant-descriptor DESC.
3338 Return 1 if DESC describes a constant with the same value as X. */
3341 compare_constant_rtx (mode, x, desc)
3342 enum machine_mode mode;
3344 struct constant_descriptor *desc;
3346 register int *p = (int *) desc->contents;
3349 struct rtx_const value;
3351 decode_rtx_const (mode, x, &value);
3352 strp = (int *) &value;
3353 len = sizeof value / sizeof (int);
3355 /* Compare constant contents. */
3357 if (*p++ != *strp++)
3363 /* Construct a constant descriptor for the rtl-expression X.
3364 It is up to the caller to enter the descriptor in the hash table. */
3366 static struct constant_descriptor *
3367 record_constant_rtx (mode, x)
3368 enum machine_mode mode;
3371 struct constant_descriptor *ptr;
3373 struct rtx_const value;
3375 decode_rtx_const (mode, x, &value);
3377 /* Put these things in the saveable obstack so we can ensure it won't
3378 be freed if we are called from combine or some other phase that discards
3379 memory allocated from function_obstack (current_obstack). */
3380 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3381 obstack_grow (saveable_obstack, &label, sizeof label);
3383 /* Record constant contents. */
3384 obstack_grow (saveable_obstack, &value, sizeof value);
3386 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3389 /* Given a constant rtx X, make (or find) a memory constant for its value
3390 and return a MEM rtx to refer to it in memory. */
3393 force_const_mem (mode, x)
3394 enum machine_mode mode;
3398 register struct constant_descriptor *desc;
3403 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3404 (this will always be true for floating CONST_DOUBLEs that have been
3405 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3406 use the previous copy. Otherwise, make a new one. Note that in
3407 the unlikely event that this same CONST_DOUBLE is used in two different
3408 modes in an alternating fashion, we will allocate a lot of different
3409 memory locations, but this should be extremely rare. */
3411 /* Don't use CONST_DOUBLE_MEM in a nested function.
3412 Nested functions have their own constant pools,
3413 so they can't share the same values in CONST_DOUBLE_MEM
3414 with the containing function. */
3415 if (outer_function_chain == 0)
3416 if (GET_CODE (x) == CONST_DOUBLE
3417 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3418 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3419 return CONST_DOUBLE_MEM (x);
3421 /* Compute hash code of X. Search the descriptors for that hash code
3422 to see if any of them describes X. If yes, the descriptor records
3423 the label number already assigned. */
3425 hash = const_hash_rtx (mode, x);
3427 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3428 if (compare_constant_rtx (mode, x, desc))
3430 found = desc->label;
3436 register struct pool_constant *pool;
3437 register struct pool_sym *sym;
3440 /* No constant equal to X is known to have been output.
3441 Make a constant descriptor to enter X in the hash table.
3442 Assign the label number and record it in the descriptor for
3443 future calls to this function to find. */
3445 desc = record_constant_rtx (mode, x);
3446 desc->next = const_rtx_hash_table[hash];
3447 const_rtx_hash_table[hash] = desc;
3449 /* Align the location counter as required by EXP's data type. */
3450 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3451 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3452 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3454 pool_offset += align - 1;
3455 pool_offset &= ~ (align - 1);
3457 /* If RTL is not being placed into the saveable obstack, make a
3458 copy of X that is in the saveable obstack in case we are
3459 being called from combine or some other phase that discards
3460 memory it allocates. We used to only do this if it is a
3461 CONST; however, reload can allocate a CONST_INT when
3462 eliminating registers. */
3463 if (rtl_obstack != saveable_obstack
3464 && (GET_CODE (x) == CONST || GET_CODE (x) == CONST_INT))
3466 push_obstacks_nochange ();
3467 rtl_in_saveable_obstack ();
3469 if (GET_CODE (x) == CONST)
3470 x = gen_rtx (CONST, GET_MODE (x),
3471 gen_rtx (PLUS, GET_MODE (x),
3472 XEXP (XEXP (x, 0), 0),
3473 XEXP (XEXP (x, 0), 1)));
3475 x = GEN_INT (INTVAL (x));
3480 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3482 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3486 pool->labelno = const_labelno;
3487 pool->align = align;
3488 pool->offset = pool_offset;
3495 last_pool->next = pool;
3498 pool_offset += GET_MODE_SIZE (mode);
3500 /* Create a string containing the label name, in LABEL. */
3501 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3506 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3508 /* Add label to symbol hash table. */
3509 hash = SYMHASH (found);
3510 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3513 sym->next = const_rtx_sym_hash_table[hash];
3514 const_rtx_sym_hash_table[hash] = sym;
3517 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3519 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3521 RTX_UNCHANGING_P (def) = 1;
3522 /* Mark the symbol_ref as belonging to this constants pool. */
3523 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3524 current_function_uses_const_pool = 1;
3526 if (outer_function_chain == 0)
3527 if (GET_CODE (x) == CONST_DOUBLE)
3529 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3531 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3532 const_double_chain = x;
3534 CONST_DOUBLE_MEM (x) = def;
3540 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3541 the corresponding pool_constant structure. */
3543 static struct pool_constant *
3544 find_pool_constant (addr)
3547 struct pool_sym *sym;
3548 char *label = XSTR (addr, 0);
3550 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3551 if (sym->label == label)
3557 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3560 get_pool_constant (addr)
3563 return (find_pool_constant (addr))->constant;
3566 /* Similar, return the mode. */
3569 get_pool_mode (addr)
3572 return (find_pool_constant (addr))->mode;
3575 /* Similar, return the offset in the constant pool. */
3578 get_pool_offset (addr)
3581 return (find_pool_constant (addr))->offset;
3584 /* Return the size of the constant pool. */
3592 /* Write all the constants in the constant pool. */
3595 output_constant_pool (fnname, fndecl)
3599 struct pool_constant *pool;
3601 union real_extract u;
3603 /* It is possible for gcc to call force_const_mem and then to later
3604 discard the instructions which refer to the constant. In such a
3605 case we do not need to output the constant. */
3606 if (optimize >= 0 && flag_expensive_optimizations)
3607 mark_constant_pool ();
3609 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3610 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3613 for (pool = first_pool; pool; pool = pool->next)
3620 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3621 whose CODE_LABEL has been deleted. This can occur if a jump table
3622 is eliminated by optimization. If so, write a constant of zero
3623 instead. Note that this can also happen by turning the
3624 CODE_LABEL into a NOTE. */
3625 if (((GET_CODE (x) == LABEL_REF
3626 && (INSN_DELETED_P (XEXP (x, 0))
3627 || GET_CODE (XEXP (x, 0)) == NOTE)))
3628 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3629 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3630 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3631 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3634 /* First switch to correct section. */
3635 #ifdef SELECT_RTX_SECTION
3636 SELECT_RTX_SECTION (pool->mode, x);
3638 readonly_data_section ();
3641 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3642 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3643 pool->align, pool->labelno, done);
3646 if (pool->align > 1)
3647 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3649 /* Output the label. */
3650 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3652 /* Output the value of the constant itself. */
3653 switch (GET_MODE_CLASS (pool->mode))
3656 if (GET_CODE (x) != CONST_DOUBLE)
3659 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3660 assemble_real (u.d, pool->mode);
3664 case MODE_PARTIAL_INT:
3665 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3675 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3676 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3679 /* Done with this pool. */
3680 first_pool = last_pool = 0;
3683 /* Look through the instructions for this function, and mark all the
3684 entries in the constant pool which are actually being used. */
3687 mark_constant_pool ()
3690 struct pool_constant *pool;
3692 if (first_pool == 0)
3695 for (pool = first_pool; pool; pool = pool->next)
3698 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3699 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3700 mark_constants (PATTERN (insn));
3702 for (insn = current_function_epilogue_delay_list;
3704 insn = XEXP (insn, 1))
3705 if (GET_RTX_CLASS (GET_CODE (insn)) == 'i')
3706 mark_constants (PATTERN (insn));
3714 register char *format_ptr;
3719 if (GET_CODE (x) == SYMBOL_REF)
3721 if (CONSTANT_POOL_ADDRESS_P (x))
3722 find_pool_constant (x)->mark = 1;
3726 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3727 insns, not any notes that may be attached. We don't want to mark
3728 a constant just because it happens to appear in a REG_EQUIV note. */
3729 if (GET_RTX_CLASS (GET_CODE (x)) == 'i')
3731 mark_constants (PATTERN (x));
3735 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3737 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3739 switch (*format_ptr++)
3742 mark_constants (XEXP (x, i));
3746 if (XVEC (x, i) != 0)
3750 for (j = 0; j < XVECLEN (x, i); j++)
3751 mark_constants (XVECEXP (x, i, j));
3770 /* Find all the constants whose addresses are referenced inside of EXP,
3771 and make sure assembler code with a label has been output for each one.
3772 Indicate whether an ADDR_EXPR has been encountered. */
3775 output_addressed_constants (exp)
3780 switch (TREE_CODE (exp))
3784 register tree constant = TREE_OPERAND (exp, 0);
3786 while (TREE_CODE (constant) == COMPONENT_REF)
3788 constant = TREE_OPERAND (constant, 0);
3791 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3792 || TREE_CODE (constant) == CONSTRUCTOR)
3793 /* No need to do anything here
3794 for addresses of variables or functions. */
3795 output_constant_def (constant);
3802 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3803 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3808 case NON_LVALUE_EXPR:
3809 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3815 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3816 if (TREE_VALUE (link) != 0)
3817 reloc |= output_addressed_constants (TREE_VALUE (link));
3827 /* Output assembler code for constant EXP to FILE, with no label.
3828 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3829 Assumes output_addressed_constants has been done on EXP already.
3831 Generate exactly SIZE bytes of assembler data, padding at the end
3832 with zeros if necessary. SIZE must always be specified.
3834 SIZE is important for structure constructors,
3835 since trailing members may have been omitted from the constructor.
3836 It is also important for initialization of arrays from string constants
3837 since the full length of the string constant might not be wanted.
3838 It is also needed for initialization of unions, where the initializer's
3839 type is just one member, and that may not be as long as the union.
3841 There a case in which we would fail to output exactly SIZE bytes:
3842 for a structure constructor that wants to produce more than SIZE bytes.
3843 But such constructors will never be generated for any possible input. */
3846 output_constant (exp, size)
3850 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3856 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3857 That way we get the constant (we hope) inside it. Also, strip off any
3858 NOP_EXPR that converts between two record, union, array, or set types. */
3859 while ((TREE_CODE (exp) == NOP_EXPR
3860 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3861 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
3862 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3863 exp = TREE_OPERAND (exp, 0);
3865 /* Allow a constructor with no elements for any data type.
3866 This means to fill the space with zeros. */
3867 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3869 if (output_bytecode)
3870 bc_emit_const_skip (size);
3872 assemble_zeros (size);
3883 case REFERENCE_TYPE:
3884 /* ??? What about (int)((float)(int)&foo + 4) */
3885 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3886 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3887 exp = TREE_OPERAND (exp, 0);
3889 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3890 EXPAND_INITIALIZER),
3892 error ("initializer for integer value is too complicated");
3897 if (TREE_CODE (exp) != REAL_CST)
3898 error ("initializer for floating value is not a floating constant");
3900 assemble_real (TREE_REAL_CST (exp),
3901 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3906 output_constant (TREE_REALPART (exp), size / 2);
3907 output_constant (TREE_IMAGPART (exp), size / 2);
3908 size -= (size / 2) * 2;
3912 if (TREE_CODE (exp) == CONSTRUCTOR)
3914 output_constructor (exp, size);
3917 else if (TREE_CODE (exp) == STRING_CST)
3921 if (size > TREE_STRING_LENGTH (exp))
3923 excess = size - TREE_STRING_LENGTH (exp);
3924 size = TREE_STRING_LENGTH (exp);
3927 assemble_string (TREE_STRING_POINTER (exp), size);
3936 if (TREE_CODE (exp) == CONSTRUCTOR)
3937 output_constructor (exp, size);
3943 if (TREE_CODE (exp) == INTEGER_CST)
3944 assemble_integer (expand_expr (exp, NULL_RTX,
3945 VOIDmode, EXPAND_INITIALIZER),
3947 else if (TREE_CODE (exp) == CONSTRUCTOR)
3949 unsigned char *buffer = (unsigned char *) alloca (size);
3950 if (get_set_constructor_bytes (exp, buffer, size))
3952 assemble_string ((char *) buffer, size);
3955 error ("unknown set constructor type");
3960 assemble_zeros (size);
3963 /* Bytecode specific code to output assembler for integer. */
3966 bc_assemble_integer (exp, size)
3974 /* FIXME: is this fold() business going to be as good as the
3975 expand_expr() using EXPAND_SUM above in the RTL case? I
3977 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3981 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3982 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3983 exp = TREE_OPERAND (exp, 0);
3984 if (TREE_CODE (exp) == INTEGER_CST)
3989 else if (TREE_CODE (exp) == PLUS_EXPR)
3991 const_part = TREE_OPERAND (exp, 0);
3992 while (TREE_CODE (const_part) == NOP_EXPR
3993 || TREE_CODE (const_part) == CONVERT_EXPR
3994 || TREE_CODE (const_part) == NON_LVALUE_EXPR)
3995 const_part = TREE_OPERAND (const_part, 0);
3996 addr_part = TREE_OPERAND (exp, 1);
3997 while (TREE_CODE (addr_part) == NOP_EXPR
3998 || TREE_CODE (addr_part) == CONVERT_EXPR
3999 || TREE_CODE (addr_part) == NON_LVALUE_EXPR)
4000 addr_part = TREE_OPERAND (addr_part, 0);
4001 if (TREE_CODE (const_part) != INTEGER_CST)
4002 tmp = const_part, const_part = addr_part, addr_part = tmp;
4003 if (TREE_CODE (const_part) != INTEGER_CST
4004 || TREE_CODE (addr_part) != ADDR_EXPR)
4005 abort (); /* FIXME: we really haven't considered
4006 all the possible cases here. */
4008 else if (TREE_CODE (exp) == ADDR_EXPR)
4010 const_part = integer_zero_node;
4014 abort (); /* FIXME: ditto previous. */
4020 char c = TREE_INT_CST_LOW (const_part);
4026 short s = TREE_INT_CST_LOW (const_part);
4027 bc_emit ((char *) &s, 2);
4032 int i = TREE_INT_CST_LOW (const_part);
4033 bc_emit ((char *) &i, 4);
4038 if (WORDS_BIG_ENDIAN)
4040 int i = TREE_INT_CST_HIGH (const_part);
4041 bc_emit ((char *) &i, 4);
4042 i = TREE_INT_CST_LOW (const_part);
4043 bc_emit ((char *) &i, 4);
4047 int i = TREE_INT_CST_LOW (const_part);
4048 bc_emit ((char *) &i, 4);
4049 i = TREE_INT_CST_HIGH (const_part);
4050 bc_emit ((char *) &i, 4);
4057 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
4058 bc_emit_labelref (IDENTIFIER_POINTER
4059 (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0))),
4060 TREE_INT_CST_LOW (const_part));
4062 abort (); /* FIXME: there may be more cases. */
4065 /* Subroutine of output_constant, used for CONSTRUCTORs
4066 (aggregate constants).
4067 Generate at least SIZE bytes, padding if necessary. */
4070 output_constructor (exp, size)
4074 register tree link, field = 0;
4075 HOST_WIDE_INT min_index = 0;
4076 /* Number of bytes output or skipped so far.
4077 In other words, current position within the constructor. */
4078 int total_bytes = 0;
4079 /* Non-zero means BYTE contains part of a byte, to be output. */
4080 int byte_buffer_in_use = 0;
4083 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4086 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
4087 field = TYPE_FIELDS (TREE_TYPE (exp));
4089 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
4090 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
4092 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
4094 /* As LINK goes through the elements of the constant,
4095 FIELD goes through the structure fields, if the constant is a structure.
4096 if the constant is a union, then we override this,
4097 by getting the field from the TREE_LIST element.
4098 But the constant could also be an array. Then FIELD is zero. */
4099 for (link = CONSTRUCTOR_ELTS (exp);
4101 link = TREE_CHAIN (link),
4102 field = field ? TREE_CHAIN (field) : 0)
4104 tree val = TREE_VALUE (link);
4107 /* the element in a union constructor specifies the proper field. */
4109 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
4110 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
4112 /* if available, use the type given by link */
4113 if (TREE_PURPOSE (link) != 0)
4114 field = TREE_PURPOSE (link);
4117 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
4118 index = TREE_PURPOSE (link);
4120 /* Eliminate the marker that makes a cast not be an lvalue. */
4124 if (index && TREE_CODE (index) == RANGE_EXPR)
4126 register int fieldsize
4127 = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4128 HOST_WIDE_INT lo_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 0));
4129 HOST_WIDE_INT hi_index = TREE_INT_CST_LOW (TREE_OPERAND (index, 1));
4130 HOST_WIDE_INT index;
4131 for (index = lo_index; index <= hi_index; index++)
4133 /* Output the element's initial value. */
4135 assemble_zeros (fieldsize);
4137 output_constant (val, fieldsize);
4139 /* Count its size. */
4140 total_bytes += fieldsize;
4143 else if (field == 0 || !DECL_BIT_FIELD (field))
4145 /* An element that is not a bit-field. */
4147 register int fieldsize;
4148 /* Since this structure is static,
4149 we know the positions are constant. */
4150 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
4154 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
4156 * (TREE_INT_CST_LOW (index) - min_index));
4158 /* Output any buffered-up bit-fields preceding this element. */
4159 if (byte_buffer_in_use)
4161 ASM_OUTPUT_BYTE (asm_out_file, byte);
4163 byte_buffer_in_use = 0;
4166 /* Advance to offset of this element.
4167 Note no alignment needed in an array, since that is guaranteed
4168 if each element has the proper size. */
4169 if ((field != 0 || index != 0) && bitpos != total_bytes)
4171 if (!output_bytecode)
4172 assemble_zeros (bitpos - total_bytes);
4174 bc_emit_const_skip (bitpos - total_bytes);
4175 total_bytes = bitpos;
4178 /* Determine size this element should occupy. */
4181 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
4183 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
4185 /* This avoids overflow trouble. */
4186 tree size_tree = size_binop (CEIL_DIV_EXPR,
4188 size_int (BITS_PER_UNIT));
4189 fieldsize = TREE_INT_CST_LOW (size_tree);
4193 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
4194 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
4198 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
4200 /* Output the element's initial value. */
4202 assemble_zeros (fieldsize);
4204 output_constant (val, fieldsize);
4206 /* Count its size. */
4207 total_bytes += fieldsize;
4209 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4210 error ("invalid initial value for member `%s'",
4211 IDENTIFIER_POINTER (DECL_NAME (field)));
4214 /* Element that is a bit-field. */
4216 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
4218 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
4221 val = integer_zero_node;
4223 /* If this field does not start in this (or, next) byte,
4225 if (next_offset / BITS_PER_UNIT != total_bytes)
4227 /* Output remnant of any bit field in previous bytes. */
4228 if (byte_buffer_in_use)
4230 ASM_OUTPUT_BYTE (asm_out_file, byte);
4232 byte_buffer_in_use = 0;
4235 /* If still not at proper byte, advance to there. */
4236 if (next_offset / BITS_PER_UNIT != total_bytes)
4238 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4239 total_bytes = next_offset / BITS_PER_UNIT;
4243 if (! byte_buffer_in_use)
4246 /* We must split the element into pieces that fall within
4247 separate bytes, and combine each byte with previous or
4248 following bit-fields. */
4250 /* next_offset is the offset n fbits from the beginning of
4251 the structure to the next bit of this element to be processed.
4252 end_offset is the offset of the first bit past the end of
4254 while (next_offset < end_offset)
4258 HOST_WIDE_INT value;
4259 int next_byte = next_offset / BITS_PER_UNIT;
4260 int next_bit = next_offset % BITS_PER_UNIT;
4262 /* Advance from byte to byte
4263 within this element when necessary. */
4264 while (next_byte != total_bytes)
4266 ASM_OUTPUT_BYTE (asm_out_file, byte);
4271 /* Number of bits we can process at once
4272 (all part of the same byte). */
4273 this_time = MIN (end_offset - next_offset,
4274 BITS_PER_UNIT - next_bit);
4275 if (BYTES_BIG_ENDIAN)
4277 /* On big-endian machine, take the most significant bits
4278 first (of the bits that are significant)
4279 and put them into bytes from the most significant end. */
4280 shift = end_offset - next_offset - this_time;
4281 /* Don't try to take a bunch of bits that cross
4282 the word boundary in the INTEGER_CST. */
4283 if (shift < HOST_BITS_PER_WIDE_INT
4284 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4286 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4287 shift = HOST_BITS_PER_WIDE_INT;
4290 /* Now get the bits from the appropriate constant word. */
4291 if (shift < HOST_BITS_PER_WIDE_INT)
4293 value = TREE_INT_CST_LOW (val);
4295 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4297 value = TREE_INT_CST_HIGH (val);
4298 shift -= HOST_BITS_PER_WIDE_INT;
4302 byte |= (((value >> shift)
4303 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4304 << (BITS_PER_UNIT - this_time - next_bit));
4308 /* On little-endian machines,
4309 take first the least significant bits of the value
4310 and pack them starting at the least significant
4311 bits of the bytes. */
4312 shift = (next_offset
4313 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
4314 /* Don't try to take a bunch of bits that cross
4315 the word boundary in the INTEGER_CST. */
4316 if (shift < HOST_BITS_PER_WIDE_INT
4317 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4319 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4320 shift = HOST_BITS_PER_WIDE_INT;
4323 /* Now get the bits from the appropriate constant word. */
4324 if (shift < HOST_BITS_PER_INT)
4325 value = TREE_INT_CST_LOW (val);
4326 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4328 value = TREE_INT_CST_HIGH (val);
4329 shift -= HOST_BITS_PER_WIDE_INT;
4333 byte |= (((value >> shift)
4334 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4337 next_offset += this_time;
4338 byte_buffer_in_use = 1;
4342 if (byte_buffer_in_use)
4344 ASM_OUTPUT_BYTE (asm_out_file, byte);
4347 if (total_bytes < size)
4348 assemble_zeros (size - total_bytes);
4351 /* Output asm to handle ``#pragma weak'' */
4354 handle_pragma_weak (what, name, value)
4355 enum pragma_state what;
4358 #ifdef HANDLE_PRAGMA_WEAK
4359 if (what == ps_name || what == ps_value)
4361 struct weak_syms *weak =
4362 (struct weak_syms *)permalloc (sizeof (struct weak_syms));
4363 weak->next = weak_decls;
4364 weak->name = permalloc (strlen (name) + 1);
4365 strcpy (weak->name, name);
4367 if (what != ps_value)
4368 weak->value = NULL_PTR;
4372 weak->value = permalloc (strlen (value) + 1);
4373 strcpy (weak->value, value);
4378 else if (! (what == ps_done || what == ps_start))
4379 warning ("malformed `#pragma weak'");
4380 #endif /* HANDLE_PRAGMA_WEAK */
4383 /* Declare DECL to be a weak symbol. */
4389 if (! TREE_PUBLIC (decl))
4390 error_with_decl (decl, "weak declaration of `%s' must be public");
4391 else if (TREE_ASM_WRITTEN (decl))
4392 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4393 else if (SUPPORTS_WEAK)
4394 DECL_WEAK (decl) = 1;
4397 /* Emit any pending weak declarations. */
4402 #ifdef HANDLE_PRAGMA_WEAK
4403 if (HANDLE_PRAGMA_WEAK)
4405 struct weak_syms *t;
4406 for (t = weak_decls; t; t = t->next)
4408 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4410 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4417 assemble_alias (decl, target)
4422 make_decl_rtl (decl, (char *) 0, 1);
4423 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4425 #ifdef ASM_OUTPUT_DEF
4426 /* Make name accessible from other files, if appropriate. */
4428 if (TREE_PUBLIC (decl))
4430 #ifdef ASM_WEAKEN_LABEL
4431 if (DECL_WEAK (decl))
4432 ASM_WEAKEN_LABEL (asm_out_file, name);
4435 if (output_bytecode)
4436 BC_GLOBALIZE_LABEL (asm_out_file, name);
4438 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4441 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4442 TREE_ASM_WRITTEN (decl) = 1;
4444 #ifdef ASM_OUTPUT_WEAK_ALIAS
4445 if (! DECL_WEAK (decl))
4446 warning ("only weak aliases are supported in this configuration");
4448 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4449 TREE_ASM_WRITTEN (decl) = 1;
4451 warning ("alias definitions not supported in this configuration; ignored");
4456 /* This determines whether or not we support link-once semantics. */
4457 #ifndef SUPPORTS_ONE_ONLY
4458 #ifdef MAKE_DECL_ONE_ONLY
4459 #define SUPPORTS_ONE_ONLY 1
4461 #define SUPPORTS_ONE_ONLY 0
4465 /* Returns 1 if the target configuration supports defining public symbols
4466 so that one of them will be chosen at link time instead of generating a
4467 multiply-defined symbol error, whether through the use of weak symbols or
4468 a target-specific mechanism for having duplicates discarded. */
4471 supports_one_only ()
4473 if (SUPPORTS_ONE_ONLY)
4475 return SUPPORTS_WEAK;
4478 /* Set up DECL as a public symbol that can be defined in multiple
4479 translation units without generating a linker error. */
4482 make_decl_one_only (decl)
4485 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4488 TREE_PUBLIC (decl) = 1;
4490 if (TREE_CODE (decl) == VAR_DECL
4491 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4492 DECL_COMMON (decl) = 1;
4493 else if (SUPPORTS_ONE_ONLY)
4495 #ifdef MAKE_DECL_ONE_ONLY
4496 MAKE_DECL_ONE_ONLY (decl);
4498 DECL_ONE_ONLY (decl) = 1;
4500 else if (SUPPORTS_WEAK)
4501 DECL_WEAK (decl) = 1;