1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This file handles generation of all the assembler code
22 *except* the instructions of a function.
23 This includes declarations of variables and their initial values.
25 We also output the assembler code for constants stored in memory
26 and are responsible for combining constants with the same value. */
30 /* #include <stab.h> */
38 #include "hard-reg-set.h"
47 #ifdef XCOFF_DEBUGGING_INFO
54 #define ASM_STABS_OP ".stabs"
57 /* This macro gets just the user-specified name
58 out of the string in a SYMBOL_REF. On most machines,
59 we discard the * if any and that's all. */
60 #ifndef STRIP_NAME_ENCODING
61 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
62 (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
65 /* File in which assembler code is being written. */
67 extern FILE *asm_out_file;
69 /* The (assembler) name of the first globally-visible object output. */
70 char *first_global_object_name;
72 extern struct obstack *current_obstack;
73 extern struct obstack *saveable_obstack;
74 extern struct obstack *rtl_obstack;
75 extern struct obstack permanent_obstack;
76 #define obstack_chunk_alloc xmalloc
78 /* Number for making the label on the next
79 constant that is stored in memory. */
83 /* Number for making the label on the next
84 static variable internal to a function. */
88 /* Carry information from ASM_DECLARE_OBJECT_NAME
89 to ASM_FINISH_DECLARE_OBJECT. */
91 int size_directive_output;
93 /* The last decl for which assemble_variable was called,
94 if it did ASM_DECLARE_OBJECT_NAME.
95 If the last call to assemble_variable didn't do that,
98 tree last_assemble_variable_decl;
101 #ifdef HANDLE_PRAGMA_WEAK
102 /* Any weak symbol declarations waiting to be emitted. */
106 struct weak_syms *next;
111 static struct weak_syms *weak_decls;
114 /* Nonzero if at least one function definition has been seen. */
116 static int function_defined;
119 struct constant_descriptor;
121 struct pool_constant;
123 static void bc_make_decl_rtl PROTO((tree, char *, int));
124 static char *strip_reg_name PROTO((char *));
125 static void bc_output_ascii PROTO((FILE *, char *, int));
126 static int contains_pointers_p PROTO((tree));
127 static void decode_addr_const PROTO((tree, struct addr_const *));
128 static int const_hash PROTO((tree));
129 static int compare_constant PROTO((tree,
130 struct constant_descriptor *));
131 static char *compare_constant_1 PROTO((tree, char *));
132 static struct constant_descriptor *record_constant PROTO((tree));
133 static void record_constant_1 PROTO((tree));
134 static tree copy_constant PROTO((tree));
135 static void output_constant_def_contents PROTO((tree, int, int));
136 static void decode_rtx_const PROTO((enum machine_mode, rtx,
137 struct rtx_const *));
138 static int const_hash_rtx PROTO((enum machine_mode, rtx));
139 static int compare_constant_rtx PROTO((enum machine_mode, rtx,
140 struct constant_descriptor *));
141 static struct constant_descriptor *record_constant_rtx PROTO((enum machine_mode,
143 static struct pool_constant *find_pool_constant PROTO((rtx));
144 static int output_addressed_constants PROTO((tree));
145 static void bc_assemble_integer PROTO((tree, int));
146 static void output_constructor PROTO((tree, int));
148 #ifdef EXTRA_SECTIONS
149 static enum in_section {no_section, in_text, in_data, in_named, EXTRA_SECTIONS} in_section
152 static enum in_section {no_section, in_text, in_data, in_named} in_section
156 /* Return a non-zero value if DECL has a section attribute. */
157 #define IN_NAMED_SECTION(DECL) \
158 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
159 && DECL_SECTION_NAME (DECL) != NULL_TREE)
161 /* Text of section name when in_section == in_named. */
162 static char *in_named_name;
164 /* Define functions like text_section for any extra sections. */
165 #ifdef EXTRA_SECTION_FUNCTIONS
166 EXTRA_SECTION_FUNCTIONS
169 /* Tell assembler to switch to text section. */
174 if (in_section != in_text)
179 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
181 in_section = in_text;
185 /* Tell assembler to switch to data section. */
190 if (in_section != in_data)
196 if (flag_shared_data)
198 #ifdef SHARED_SECTION_ASM_OP
199 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
201 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
205 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
208 in_section = in_data;
212 /* Tell assembler to switch to read-only data section. This is normally
216 readonly_data_section ()
218 #ifdef READONLY_DATA_SECTION
219 READONLY_DATA_SECTION (); /* Note this can call data_section. */
225 /* Determine if we're in the text section. */
230 return in_section == in_text;
233 /* Tell assembler to change to section NAME for DECL.
234 If DECL is NULL, just switch to section NAME.
235 If NAME is NULL, get the name from DECL. */
238 named_section (decl, name)
242 if (decl != NULL_TREE
243 && (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL))
246 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
248 if (in_section != in_named || strcmp (name, in_named_name))
250 in_named_name = name;
251 in_section = in_named;
253 #ifdef ASM_OUTPUT_SECTION_NAME
254 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name);
256 /* Section attributes are not supported if this macro isn't provided -
257 some host formats don't support them at all. The front-end should
258 already have flagged this as an error. */
264 /* Switch to the section for function DECL.
266 If DECL is NULL_TREE, switch to the text section.
267 ??? It's not clear that we will ever be passed NULL_TREE, but it's
268 safer to handle it. */
271 function_section (decl)
274 if (decl != NULL_TREE
275 && DECL_SECTION_NAME (decl) != NULL_TREE)
276 named_section (decl, (char *) 0);
281 /* Create the rtl to represent a function, for a function definition.
282 DECL is a FUNCTION_DECL node which describes which function.
283 The rtl is stored into DECL. */
286 make_function_rtl (decl)
289 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
293 if (DECL_RTL (decl) == 0)
294 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
296 /* Record that at least one function has been defined. */
297 function_defined = 1;
301 /* Rename a nested function to avoid conflicts. */
302 if (decl_function_context (decl) != 0
303 && DECL_INITIAL (decl) != 0
304 && DECL_RTL (decl) == 0)
308 name = IDENTIFIER_POINTER (DECL_NAME (decl));
309 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
310 name = obstack_copy0 (saveable_obstack, label, strlen (label));
314 if (DECL_RTL (decl) == 0)
317 = gen_rtx (MEM, DECL_MODE (decl),
318 gen_rtx (SYMBOL_REF, Pmode, name));
320 /* Optionally set flags or add text to the name to record information
321 such as that it is a function name. If the name is changed, the macro
322 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
323 #ifdef ENCODE_SECTION_INFO
324 ENCODE_SECTION_INFO (decl);
328 /* Record at least one function has been defined. */
329 function_defined = 1;
332 /* Create the DECL_RTL for a declaration for a static or external
333 variable or static or external function.
334 ASMSPEC, if not 0, is the string which the user specified
335 as the assembler symbol name.
336 TOP_LEVEL is nonzero if this is a file-scope variable.
337 This is never called for PARM_DECLs. */
340 bc_make_decl_rtl (decl, asmspec, top_level)
345 register char *name = TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl));
347 if (DECL_RTL (decl) == 0)
349 /* Print an error message for register variables. */
350 if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
351 error ("function declared `register'");
352 else if (DECL_REGISTER (decl))
353 error ("global register variables not supported in the interpreter");
355 /* Handle ordinary static variables and functions. */
356 if (DECL_RTL (decl) == 0)
358 /* Can't use just the variable's own name for a variable
359 whose scope is less than the whole file.
360 Concatenate a distinguishing number. */
361 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
365 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
366 name = obstack_copy0 (saveable_obstack, label, strlen (label));
370 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
375 /* Given NAME, a putative register name, discard any customary prefixes. */
378 strip_reg_name (name)
381 #ifdef REGISTER_PREFIX
382 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
383 name += strlen (REGISTER_PREFIX);
385 if (name[0] == '%' || name[0] == '#')
390 /* Decode an `asm' spec for a declaration as a register name.
391 Return the register number, or -1 if nothing specified,
392 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
393 or -3 if ASMSPEC is `cc' and is not recognized,
394 or -4 if ASMSPEC is `memory' and is not recognized.
395 Accept an exact spelling or a decimal number.
396 Prefixes such as % are optional. */
399 decode_reg_name (asmspec)
406 /* Get rid of confusing prefixes. */
407 asmspec = strip_reg_name (asmspec);
409 /* Allow a decimal number as a "register name". */
410 for (i = strlen (asmspec) - 1; i >= 0; i--)
411 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
413 if (asmspec[0] != 0 && i < 0)
416 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
422 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
424 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
427 #ifdef ADDITIONAL_REGISTER_NAMES
429 static struct { char *name; int number; } table[]
430 = ADDITIONAL_REGISTER_NAMES;
432 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
433 if (! strcmp (asmspec, table[i].name))
434 return table[i].number;
436 #endif /* ADDITIONAL_REGISTER_NAMES */
438 if (!strcmp (asmspec, "memory"))
441 if (!strcmp (asmspec, "cc"))
450 /* Create the DECL_RTL for a declaration for a static or external variable
451 or static or external function.
452 ASMSPEC, if not 0, is the string which the user specified
453 as the assembler symbol name.
454 TOP_LEVEL is nonzero if this is a file-scope variable.
456 This is never called for PARM_DECL nodes. */
459 make_decl_rtl (decl, asmspec, top_level)
464 register char *name = 0;
469 bc_make_decl_rtl (decl, asmspec, top_level);
473 reg_number = decode_reg_name (asmspec);
475 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
476 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
478 if (reg_number == -2)
480 /* ASMSPEC is given, and not the name of a register. */
481 name = (char *) obstack_alloc (saveable_obstack,
482 strlen (asmspec) + 2);
484 strcpy (&name[1], asmspec);
487 /* For a duplicate declaration, we can be called twice on the
488 same DECL node. Don't discard the RTL already made. */
489 if (DECL_RTL (decl) == 0)
493 /* First detect errors in declaring global registers. */
494 if (DECL_REGISTER (decl) && reg_number == -1)
495 error_with_decl (decl,
496 "register name not specified for `%s'");
497 else if (DECL_REGISTER (decl) && reg_number < 0)
498 error_with_decl (decl,
499 "invalid register name for `%s'");
500 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
501 error_with_decl (decl,
502 "register name given for non-register variable `%s'");
503 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
504 error ("function declared `register'");
505 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
506 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
507 else if (DECL_REGISTER (decl)
508 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
509 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
510 /* Now handle properly declared static register variables. */
511 else if (DECL_REGISTER (decl))
514 #if 0 /* yylex should print the warning for this */
516 pedwarn ("ANSI C forbids global register variables");
518 if (DECL_INITIAL (decl) != 0 && top_level)
520 DECL_INITIAL (decl) = 0;
521 error ("global register variable has initial value");
523 if (fixed_regs[reg_number] == 0
524 && function_defined && top_level)
525 error ("global register variable follows a function definition");
526 if (TREE_THIS_VOLATILE (decl))
527 warning ("volatile register variables don't work as you might wish");
529 /* If the user specified one of the eliminables registers here,
530 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
531 confused with that register and be eliminated. Although this
532 usage is somewhat suspect, we nevertheless use the following
533 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
536 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
537 REGNO (DECL_RTL (decl)) = reg_number;
538 REG_USERVAR_P (DECL_RTL (decl)) = 1;
542 /* Make this register global, so not usable for anything
544 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
546 globalize_reg (reg_number + --nregs);
549 /* Specifying a section attribute on an uninitialized variable does not
550 (and cannot) cause it to be put in the given section. The linker
551 can only put initialized objects in specific sections, everything
552 else goes in bss for the linker to sort out later (otherwise the
553 linker would give a duplicate definition error for each compilation
554 unit that behaved thusly). So warn the user. */
555 else if (TREE_CODE (decl) == VAR_DECL
556 && DECL_SECTION_NAME (decl) != NULL_TREE
557 && DECL_INITIAL (decl) == NULL_TREE
558 && DECL_COMMON (decl)
561 warning_with_decl (decl,
562 "section attribute ignored for uninitialized variable `%s'");
563 /* Remove the section name so subsequent declarations won't see it.
564 We are ignoring it, remember. */
565 DECL_SECTION_NAME (decl) = NULL_TREE;
568 /* Now handle ordinary static variables and functions (in memory).
569 Also handle vars declared register invalidly. */
570 if (DECL_RTL (decl) == 0)
572 /* Can't use just the variable's own name for a variable
573 whose scope is less than the whole file.
574 Concatenate a distinguishing number. */
575 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
579 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
580 name = obstack_copy0 (saveable_obstack, label, strlen (label));
587 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
588 gen_rtx (SYMBOL_REF, Pmode, name));
590 /* If this variable is to be treated as volatile, show its
591 tree node has side effects. If it has side effects, either
592 because of this test or from TREE_THIS_VOLATILE also
593 being set, show the MEM is volatile. */
594 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
595 && TREE_PUBLIC (decl))
596 TREE_SIDE_EFFECTS (decl) = 1;
597 if (TREE_SIDE_EFFECTS (decl))
598 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
600 if (TREE_READONLY (decl))
601 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
602 MEM_IN_STRUCT_P (DECL_RTL (decl))
603 = AGGREGATE_TYPE_P (TREE_TYPE (decl));
605 /* Optionally set flags or add text to the name to record information
606 such as that it is a function name.
607 If the name is changed, the macro ASM_OUTPUT_LABELREF
608 will have to know how to strip this information. */
609 #ifdef ENCODE_SECTION_INFO
610 ENCODE_SECTION_INFO (decl);
614 /* If the old RTL had the wrong mode, fix the mode. */
615 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
617 rtx rtl = DECL_RTL (decl);
618 PUT_MODE (rtl, DECL_MODE (decl));
622 /* Make the rtl for variable VAR be volatile.
623 Use this only for static variables. */
626 make_var_volatile (var)
629 if (GET_CODE (DECL_RTL (var)) != MEM)
632 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
635 /* Output alignment directive to align for constant expression EXP. */
638 assemble_constant_align (exp)
643 /* Align the location counter as required by EXP's data type. */
644 align = TYPE_ALIGN (TREE_TYPE (exp));
645 #ifdef CONSTANT_ALIGNMENT
646 align = CONSTANT_ALIGNMENT (exp, align);
649 if (align > BITS_PER_UNIT)
650 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
653 /* Output a string of literal assembler code
654 for an `asm' keyword used between functions. */
657 assemble_asm (string)
662 error ("asm statements not allowed in interpreter");
668 if (TREE_CODE (string) == ADDR_EXPR)
669 string = TREE_OPERAND (string, 0);
671 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
674 #if 0 /* This should no longer be needed, because
675 flag_gnu_linker should be 0 on these systems,
676 which should prevent any output
677 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
678 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
679 #ifndef ASM_OUTPUT_CONSTRUCTOR
680 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
682 #ifndef ASM_OUTPUT_DESTRUCTOR
683 #define ASM_OUTPUT_DESTRUCTOR(file, name)
688 /* Record an element in the table of global destructors.
689 How this is done depends on what sort of assembler and linker
692 NAME should be the name of a global function to be called
693 at exit time. This name is output using assemble_name. */
696 assemble_destructor (name)
699 #ifdef ASM_OUTPUT_DESTRUCTOR
700 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
704 /* Now tell GNU LD that this is part of the static destructor set. */
705 /* This code works for any machine provided you use GNU as/ld. */
706 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
707 assemble_name (asm_out_file, name);
708 fputc ('\n', asm_out_file);
713 /* Likewise for global constructors. */
716 assemble_constructor (name)
719 #ifdef ASM_OUTPUT_CONSTRUCTOR
720 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
724 /* Now tell GNU LD that this is part of the static constructor set. */
725 /* This code works for any machine provided you use GNU as/ld. */
726 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
727 assemble_name (asm_out_file, name);
728 fputc ('\n', asm_out_file);
733 /* Likewise for entries we want to record for garbage collection.
734 Garbage collection is still under development. */
737 assemble_gc_entry (name)
740 #ifdef ASM_OUTPUT_GC_ENTRY
741 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
745 /* Now tell GNU LD that this is part of the static constructor set. */
746 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
747 assemble_name (asm_out_file, name);
748 fputc ('\n', asm_out_file);
753 /* Output assembler code for the constant pool of a function and associated
754 with defining the name of the function. DECL describes the function.
755 NAME is the function's name. For the constant pool, we use the current
756 constant pool data. */
759 assemble_start_function (decl, fnname)
765 /* The following code does not need preprocessing in the assembler. */
769 output_constant_pool (fnname, decl);
771 function_section (decl);
773 /* Tell assembler to move to target machine's alignment for functions. */
774 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
778 BC_OUTPUT_ALIGN (asm_out_file, align);
780 ASM_OUTPUT_ALIGN (asm_out_file, align);
783 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
784 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
787 #ifdef SDB_DEBUGGING_INFO
788 /* Output SDB definition of the function. */
789 if (write_symbols == SDB_DEBUG)
790 sdbout_mark_begin_function ();
793 #ifdef DBX_DEBUGGING_INFO
794 /* Output DBX definition of the function. */
795 if (write_symbols == DBX_DEBUG)
796 dbxout_begin_function (decl);
799 /* Make function name accessible from other files, if appropriate. */
801 if (TREE_PUBLIC (decl))
803 if (!first_global_object_name)
804 STRIP_NAME_ENCODING (first_global_object_name, fnname);
806 BC_GLOBALIZE_LABEL (asm_out_file, fnname);
808 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
811 /* Do any machine/system dependent processing of the function name */
812 #ifdef ASM_DECLARE_FUNCTION_NAME
813 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
815 /* Standard thing is just output label for the function. */
817 BC_OUTPUT_LABEL (asm_out_file, fnname);
819 ASM_OUTPUT_LABEL (asm_out_file, fnname);
820 #endif /* ASM_DECLARE_FUNCTION_NAME */
823 /* Output assembler code associated with defining the size of the
824 function. DECL describes the function. NAME is the function's name. */
827 assemble_end_function (decl, fnname)
831 #ifdef ASM_DECLARE_FUNCTION_SIZE
832 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
836 /* Assemble code to leave SIZE bytes of zeros. */
839 assemble_zeros (size)
844 bc_emit_const_skip (size);
848 #ifdef ASM_NO_SKIP_IN_TEXT
849 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
850 so we must output 0s explicitly in the text section. */
851 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
855 for (i = 0; i < size - 20; i += 20)
858 fprintf (asm_out_file,
859 "%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);
861 fprintf (asm_out_file,
862 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
868 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
870 fprintf (asm_out_file, "\tbyte 0");
873 for (; i < size; i++)
874 fprintf (asm_out_file, ",0");
875 fprintf (asm_out_file, "\n");
883 BC_OUTPUT_SKIP (asm_out_file, size);
885 ASM_OUTPUT_SKIP (asm_out_file, size);
889 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
892 assemble_align (align)
895 if (align > BITS_PER_UNIT)
896 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
899 /* Assemble a string constant with the specified C string as contents. */
902 assemble_string (p, size)
916 /* If the string is very long, split it up. */
920 int thissize = size - pos;
921 if (thissize > maximum)
925 bc_output_ascii (asm_out_file, p, thissize);
928 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
937 bc_output_ascii (file, p, size)
942 BC_OUTPUT_ASCII (file, p, size);
945 /* Assemble everything that is needed for a variable or function declaration.
946 Not used for automatic variables, and not used for function definitions.
947 Should not be called for variables of incomplete structure type.
949 TOP_LEVEL is nonzero if this variable has file scope.
950 AT_END is nonzero if this is the special handling, at end of compilation,
951 to define things that have had only tentative definitions.
952 DONT_OUTPUT_DATA if nonzero means don't actually output the
953 initial value (that will be done by the caller). */
956 assemble_variable (decl, top_level, at_end, dont_output_data)
960 int dont_output_data;
966 enum in_section saved_in_section;
968 last_assemble_variable_decl = 0;
973 if (GET_CODE (DECL_RTL (decl)) == REG)
975 /* Do output symbol info for global register variables, but do nothing
978 if (TREE_ASM_WRITTEN (decl))
980 TREE_ASM_WRITTEN (decl) = 1;
982 if (!output_bytecode)
984 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
985 /* File-scope global variables are output here. */
986 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
988 dbxout_symbol (decl, 0);
990 #ifdef SDB_DEBUGGING_INFO
991 if (write_symbols == SDB_DEBUG && top_level
992 /* Leave initialized global vars for end of compilation;
993 see comment in compile_file. */
994 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
995 sdbout_symbol (decl, 0);
999 /* Don't output any DWARF debugging information for variables here.
1000 In the case of local variables, the information for them is output
1001 when we do our recursive traversal of the tree representation for
1002 the entire containing function. In the case of file-scope variables,
1003 we output information for all of them at the very end of compilation
1004 while we are doing our final traversal of the chain of file-scope
1010 /* Normally no need to say anything here for external references,
1011 since assemble_external is called by the langauge-specific code
1012 when a declaration is first seen. */
1014 if (DECL_EXTERNAL (decl))
1017 /* Output no assembler code for a function declaration.
1018 Only definitions of functions output anything. */
1020 if (TREE_CODE (decl) == FUNCTION_DECL)
1023 /* If type was incomplete when the variable was declared,
1024 see if it is complete now. */
1026 if (DECL_SIZE (decl) == 0)
1027 layout_decl (decl, 0);
1029 /* Still incomplete => don't allocate it; treat the tentative defn
1030 (which is what it must have been) as an `extern' reference. */
1032 if (!dont_output_data && DECL_SIZE (decl) == 0)
1034 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1035 DECL_SOURCE_LINE (decl),
1036 "storage size of `%s' isn't known",
1037 IDENTIFIER_POINTER (DECL_NAME (decl)));
1038 TREE_ASM_WRITTEN (decl) = 1;
1042 /* The first declaration of a variable that comes through this function
1043 decides whether it is global (in C, has external linkage)
1044 or local (in C, has internal linkage). So do nothing more
1045 if this function has already run. */
1047 if (TREE_ASM_WRITTEN (decl))
1050 TREE_ASM_WRITTEN (decl) = 1;
1054 if (! dont_output_data)
1056 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1059 /* This is better than explicit arithmetic, since it avoids overflow. */
1060 size_tree = size_binop (CEIL_DIV_EXPR,
1061 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1063 if (TREE_INT_CST_HIGH (size_tree) != 0)
1065 error_with_decl (decl, "size of variable `%s' is too large");
1070 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1072 /* Handle uninitialized definitions. */
1074 /* ANSI specifies that a tentative definition which is not merged with
1075 a non-tentative definition behaves exactly like a definition with an
1076 initializer equal to zero. (Section 3.7.2)
1077 -fno-common gives strict ANSI behavior. Usually you don't want it.
1078 This matters only for variables with external linkage. */
1079 if ((! flag_no_common || ! TREE_PUBLIC (decl))
1080 && DECL_COMMON (decl)
1081 && ! dont_output_data
1082 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
1084 int size = TREE_INT_CST_LOW (size_tree);
1087 if (TREE_INT_CST_HIGH (size_tree) != 0)
1088 error_with_decl (decl, "size of variable `%s' is too large");
1089 /* Don't allocate zero bytes of common,
1090 since that means "undefined external" in the linker. */
1091 if (size == 0) rounded = 1;
1092 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1093 so that each uninitialized object starts on such a boundary. */
1094 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1095 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1096 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1098 #ifdef DBX_DEBUGGING_INFO
1099 /* File-scope global variables are output here. */
1100 if (write_symbols == DBX_DEBUG && top_level)
1101 dbxout_symbol (decl, 0);
1103 #ifdef SDB_DEBUGGING_INFO
1104 if (write_symbols == SDB_DEBUG && top_level
1105 /* Leave initialized global vars for end of compilation;
1106 see comment in compile_file. */
1107 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1108 sdbout_symbol (decl, 0);
1111 /* Don't output any DWARF debugging information for variables here.
1112 In the case of local variables, the information for them is output
1113 when we do our recursive traversal of the tree representation for
1114 the entire containing function. In the case of file-scope variables,
1115 we output information for all of them at the very end of compilation
1116 while we are doing our final traversal of the chain of file-scope
1120 if (flag_shared_data)
1123 if (TREE_PUBLIC (decl))
1125 #ifdef ASM_OUTPUT_SHARED_COMMON
1126 if (flag_shared_data)
1127 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1130 if (output_bytecode)
1132 BC_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1136 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1137 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1140 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1146 #ifdef ASM_OUTPUT_SHARED_LOCAL
1147 if (flag_shared_data)
1148 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1151 if (output_bytecode)
1153 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1157 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1158 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1161 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1168 /* Handle initialized definitions. */
1170 /* First make the assembler name(s) global if appropriate. */
1171 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1173 if (!first_global_object_name)
1174 STRIP_NAME_ENCODING(first_global_object_name, name);
1175 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1178 for (d = equivalents; d; d = TREE_CHAIN (d))
1180 tree e = TREE_VALUE (d);
1181 if (TREE_PUBLIC (e) && DECL_NAME (e))
1182 ASM_GLOBALIZE_LABEL (asm_out_file,
1183 XSTR (XEXP (DECL_RTL (e), 0), 0));
1187 /* Output any data that we will need to use the address of. */
1188 if (DECL_INITIAL (decl) == error_mark_node)
1189 reloc = contains_pointers_p (TREE_TYPE (decl));
1190 else if (DECL_INITIAL (decl))
1191 reloc = output_addressed_constants (DECL_INITIAL (decl));
1193 /* Switch to the proper section for this data. */
1194 if (IN_NAMED_SECTION (decl))
1195 named_section (decl, NULL);
1198 /* C++ can have const variables that get initialized from constructors,
1199 and thus can not be in a readonly section. We prevent this by
1200 verifying that the initial value is constant for objects put in a
1203 error_mark_node is used by the C front end to indicate that the
1204 initializer has not been seen yet. In this case, we assume that
1205 the initializer must be constant. */
1206 #ifdef SELECT_SECTION
1207 SELECT_SECTION (decl, reloc);
1209 if (TREE_READONLY (decl)
1210 && ! TREE_THIS_VOLATILE (decl)
1211 && DECL_INITIAL (decl)
1212 && (DECL_INITIAL (decl) == error_mark_node
1213 || TREE_CONSTANT (DECL_INITIAL (decl)))
1214 && ! (flag_pic && reloc))
1215 readonly_data_section ();
1221 /* dbxout.c needs to know this. */
1222 if (in_text_section ())
1223 DECL_IN_TEXT_SECTION (decl) = 1;
1225 /* Record current section so we can restore it if dbxout.c clobbers it. */
1226 saved_in_section = in_section;
1228 /* Output the dbx info now that we have chosen the section. */
1230 #ifdef DBX_DEBUGGING_INFO
1231 /* File-scope global variables are output here. */
1232 if (write_symbols == DBX_DEBUG && top_level)
1233 dbxout_symbol (decl, 0);
1235 #ifdef SDB_DEBUGGING_INFO
1236 if (write_symbols == SDB_DEBUG && top_level
1237 /* Leave initialized global vars for end of compilation;
1238 see comment in compile_file. */
1239 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1240 sdbout_symbol (decl, 0);
1243 /* Don't output any DWARF debugging information for variables here.
1244 In the case of local variables, the information for them is output
1245 when we do our recursive traversal of the tree representation for
1246 the entire containing function. In the case of file-scope variables,
1247 we output information for all of them at the very end of compilation
1248 while we are doing our final traversal of the chain of file-scope
1251 /* If the debugging output changed sections, reselect the section
1252 that's supposed to be selected. */
1253 if (in_section != saved_in_section)
1255 /* Switch to the proper section for this data. */
1256 #ifdef SELECT_SECTION
1257 SELECT_SECTION (decl, reloc);
1259 if (TREE_READONLY (decl)
1260 && ! TREE_THIS_VOLATILE (decl)
1261 && DECL_INITIAL (decl)
1262 && (DECL_INITIAL (decl) == error_mark_node
1263 || TREE_CONSTANT (DECL_INITIAL (decl)))
1264 && ! (flag_pic && reloc))
1265 readonly_data_section ();
1271 /* Compute and output the alignment of this data. */
1273 align = DECL_ALIGN (decl);
1274 /* In the case for initialing an array whose length isn't specified,
1275 where we have not yet been able to do the layout,
1276 figure out the proper alignment now. */
1277 if (dont_output_data && DECL_SIZE (decl) == 0
1278 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1279 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1281 /* Some object file formats have a maximum alignment which they support.
1282 In particular, a.out format supports a maximum alignment of 4. */
1283 #ifndef MAX_OFILE_ALIGNMENT
1284 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1286 if (align > MAX_OFILE_ALIGNMENT)
1288 warning_with_decl (decl,
1289 "alignment of `%s' is greater than maximum object file alignment");
1290 align = MAX_OFILE_ALIGNMENT;
1292 #ifdef DATA_ALIGNMENT
1293 /* On some machines, it is good to increase alignment sometimes. */
1294 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1296 #ifdef CONSTANT_ALIGNMENT
1297 if (DECL_INITIAL (decl))
1298 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1301 /* Reset the alignment in case we have made it tighter, so we can benefit
1302 from it in get_pointer_alignment. */
1303 DECL_ALIGN (decl) = align;
1305 if (align > BITS_PER_UNIT)
1307 if (output_bytecode)
1308 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1310 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1313 /* Do any machine/system dependent processing of the object. */
1314 #ifdef ASM_DECLARE_OBJECT_NAME
1315 last_assemble_variable_decl = decl;
1316 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1318 /* Standard thing is just output label for the object. */
1319 if (output_bytecode)
1320 BC_OUTPUT_LABEL (asm_out_file, name);
1322 ASM_OUTPUT_LABEL (asm_out_file, name);
1323 #endif /* ASM_DECLARE_OBJECT_NAME */
1325 if (!dont_output_data)
1327 if (DECL_INITIAL (decl))
1328 /* Output the actual data. */
1329 output_constant (DECL_INITIAL (decl), TREE_INT_CST_LOW (size_tree));
1331 /* Leave space for it. */
1332 assemble_zeros (TREE_INT_CST_LOW (size_tree));
1336 #ifdef XCOFF_DEBUGGING_INFO
1337 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1338 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1339 and `aa' hasn't been output yet, the assembler generates a stab entry with
1340 a value of zero, in addition to creating an unnecessary external entry
1341 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1343 /* File-scope global variables are output here. */
1344 if (write_symbols == XCOFF_DEBUG && top_level)
1346 saved_in_section = in_section;
1348 dbxout_symbol (decl, 0);
1350 if (in_section != saved_in_section)
1352 /* Switch to the proper section for this data. */
1353 #ifdef SELECT_SECTION
1354 SELECT_SECTION (decl, reloc);
1356 if (TREE_READONLY (decl)
1357 && ! TREE_THIS_VOLATILE (decl)
1358 && DECL_INITIAL (decl)
1359 && (DECL_INITIAL (decl) == error_mark_node
1360 || TREE_CONSTANT (DECL_INITIAL (decl)))
1361 && ! (flag_pic && reloc))
1362 readonly_data_section ();
1369 /* There must be a statement after a label. */
1374 /* Return 1 if type TYPE contains any pointers. */
1377 contains_pointers_p (type)
1380 switch (TREE_CODE (type))
1383 case REFERENCE_TYPE:
1384 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1385 so I'll play safe and return 1. */
1391 case QUAL_UNION_TYPE:
1394 /* For a type that has fields, see if the fields have pointers. */
1395 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1396 if (TREE_CODE (fields) == FIELD_DECL
1397 && contains_pointers_p (TREE_TYPE (fields)))
1403 /* An array type contains pointers if its element type does. */
1404 return contains_pointers_p (TREE_TYPE (type));
1411 /* Output text storage for constructor CONSTR. */
1414 bc_output_constructor (constr, size)
1420 /* Must always be a literal; non-literal constructors are handled
1423 if (!TREE_CONSTANT (constr))
1430 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++)
1434 BC_OUTPUT_ALIGN (asm_out_file, i);
1437 output_constant (constr, size);
1440 /* Create storage for constructor CONSTR. */
1443 bc_output_data_constructor (constr)
1448 /* Put in data section */
1452 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1454 BC_OUTPUT_ALIGN (asm_out_file, i);
1456 /* The constructor is filled in at runtime. */
1457 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1460 /* Output something to declare an external symbol to the assembler.
1461 (Most assemblers don't need this, so we normally output nothing.)
1462 Do nothing if DECL is not external. */
1465 assemble_external (decl)
1468 if (output_bytecode)
1471 #ifdef ASM_OUTPUT_EXTERNAL
1472 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1473 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1475 rtx rtl = DECL_RTL (decl);
1477 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1478 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1480 /* Some systems do require some output. */
1481 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1482 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1488 /* Similar, for calling a library function FUN. */
1491 assemble_external_libcall (fun)
1494 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1495 if (!output_bytecode)
1497 /* Declare library function name external when first used, if nec. */
1498 if (! SYMBOL_REF_USED (fun))
1500 SYMBOL_REF_USED (fun) = 1;
1501 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1507 /* Declare the label NAME global. */
1510 assemble_global (name)
1513 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1516 /* Assemble a label named NAME. */
1519 assemble_label (name)
1522 if (output_bytecode)
1523 BC_OUTPUT_LABEL (asm_out_file, name);
1525 ASM_OUTPUT_LABEL (asm_out_file, name);
1528 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1529 If NAME starts with a *, the rest of NAME is output verbatim.
1530 Otherwise NAME is transformed in an implementation-defined way
1531 (usually by the addition of an underscore).
1532 Many macros in the tm file are defined to call this function. */
1535 assemble_name (file, name)
1541 STRIP_NAME_ENCODING (real_name, name);
1542 TREE_SYMBOL_REFERENCED (get_identifier (real_name)) = 1;
1546 if (output_bytecode)
1547 bc_emit_labelref (name);
1549 fputs (&name[1], file);
1553 if (output_bytecode)
1554 BC_OUTPUT_LABELREF (file, name);
1556 ASM_OUTPUT_LABELREF (file, name);
1560 /* Allocate SIZE bytes writable static space with a gensym name
1561 and return an RTX to refer to its address. */
1564 assemble_static_space (size)
1570 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1571 so that each uninitialized object starts on such a boundary. */
1572 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1573 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1574 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1577 if (flag_shared_data)
1581 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1584 namestring = (char *) obstack_alloc (saveable_obstack,
1586 strcpy (namestring, name);
1588 if (output_bytecode)
1589 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1591 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1593 if (output_bytecode)
1595 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1599 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1600 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1602 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1608 /* Assemble the static constant template for function entry trampolines.
1609 This is done at most once per compilation.
1610 Returns an RTX for the address of the template. */
1613 assemble_trampoline_template ()
1619 /* Shouldn't get here */
1620 if (output_bytecode)
1623 /* By default, put trampoline templates in read-only data section. */
1625 #ifdef TRAMPOLINE_SECTION
1626 TRAMPOLINE_SECTION ();
1628 readonly_data_section ();
1631 /* Write the assembler code to define one. */
1632 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1634 ASM_OUTPUT_ALIGN (asm_out_file, align);
1636 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1637 TRAMPOLINE_TEMPLATE (asm_out_file);
1639 /* Record the rtl to refer to it. */
1640 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1642 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1643 return gen_rtx (SYMBOL_REF, Pmode, name);
1646 /* Assemble the integer constant X into an object of SIZE bytes.
1647 X must be either a CONST_INT or CONST_DOUBLE.
1649 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1650 non-zero, abort if we can't output the constant. */
1653 assemble_integer (x, size, force)
1658 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1659 ASM_OUTPUT... macros. */
1663 #ifdef ASM_OUTPUT_CHAR
1665 ASM_OUTPUT_CHAR (asm_out_file, x);
1669 #ifdef ASM_OUTPUT_SHORT
1671 ASM_OUTPUT_SHORT (asm_out_file, x);
1675 #ifdef ASM_OUTPUT_INT
1677 ASM_OUTPUT_INT (asm_out_file, x);
1681 #ifdef ASM_OUTPUT_DOUBLE_INT
1683 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1687 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1689 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1694 /* If we couldn't do it that way, there are two other possibilities: First,
1695 if the machine can output an explicit byte and this is a 1 byte constant,
1696 we can use ASM_OUTPUT_BYTE. */
1698 #ifdef ASM_OUTPUT_BYTE
1699 if (size == 1 && GET_CODE (x) == CONST_INT)
1701 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1706 /* Finally, if SIZE is larger than a single word, try to output the constant
1707 one word at a time. */
1709 if (size > UNITS_PER_WORD)
1712 enum machine_mode mode
1713 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1716 for (i = 0; i < size / UNITS_PER_WORD; i++)
1718 word = operand_subword (x, i, 0, mode);
1723 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1727 if (i == size / UNITS_PER_WORD)
1729 /* If we output at least one word and then could not finish,
1730 there is no valid way to continue. */
1741 /* Assemble the floating-point constant D into an object of size MODE. */
1744 assemble_real (d, mode)
1746 enum machine_mode mode;
1748 jmp_buf output_constant_handler;
1750 if (setjmp (output_constant_handler))
1752 error ("floating point trap outputting a constant");
1753 #ifdef REAL_IS_NOT_DOUBLE
1754 bzero ((char *) &d, sizeof d);
1761 set_float_handler (output_constant_handler);
1765 #ifdef ASM_OUTPUT_BYTE_FLOAT
1767 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1770 #ifdef ASM_OUTPUT_SHORT_FLOAT
1772 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1775 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1777 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1780 #ifdef ASM_OUTPUT_FLOAT
1782 ASM_OUTPUT_FLOAT (asm_out_file, d);
1786 #ifdef ASM_OUTPUT_DOUBLE
1788 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1792 #ifdef ASM_OUTPUT_LONG_DOUBLE
1795 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1803 set_float_handler (NULL_PTR);
1806 /* Here we combine duplicate floating constants to make
1807 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1809 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1810 They are chained through the CONST_DOUBLE_CHAIN.
1811 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1812 In that case, CONST_DOUBLE_MEM is either a MEM,
1813 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1815 (CONST_DOUBLE_MEM is used only for top-level functions.
1816 See force_const_mem for explanation.) */
1818 static rtx const_double_chain;
1820 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1821 For an integer, I0 is the low-order word and I1 is the high-order word.
1822 For a real number, I0 is the word with the low address
1823 and I1 is the word with the high address. */
1826 immed_double_const (i0, i1, mode)
1827 HOST_WIDE_INT i0, i1;
1828 enum machine_mode mode;
1831 int in_current_obstack;
1833 if (GET_MODE_CLASS (mode) == MODE_INT
1834 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1836 /* We clear out all bits that don't belong in MODE, unless they and our
1837 sign bit are all one. So we get either a reasonable negative value
1838 or a reasonable unsigned value for this mode. */
1839 int width = GET_MODE_BITSIZE (mode);
1840 if (width < HOST_BITS_PER_WIDE_INT
1841 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1842 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1843 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1844 else if (width == HOST_BITS_PER_WIDE_INT
1845 && ! (i1 == ~0 && i0 < 0))
1847 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1848 /* We cannot represent this value as a constant. */
1851 /* If this would be an entire word for the target, but is not for
1852 the host, then sign-extend on the host so that the number will look
1853 the same way on the host that it would on the target.
1855 For example, when building a 64 bit alpha hosted 32 bit sparc
1856 targeted compiler, then we want the 32 bit unsigned value -1 to be
1857 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1858 The later confuses the sparc backend. */
1860 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1861 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1862 i0 |= ((HOST_WIDE_INT) (-1) << width);
1864 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1866 ??? Strictly speaking, this is wrong if we create a CONST_INT
1867 for a large unsigned constant with the size of MODE being
1868 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1869 wider mode. In that case we will mis-interpret it as a negative
1872 Unfortunately, the only alternative is to make a CONST_DOUBLE
1873 for any constant in any mode if it is an unsigned constant larger
1874 than the maximum signed integer in an int on the host. However,
1875 doing this will break everyone that always expects to see a CONST_INT
1876 for SImode and smaller.
1878 We have always been making CONST_INTs in this case, so nothing new
1881 if (width <= HOST_BITS_PER_WIDE_INT)
1882 i1 = (i0 < 0) ? ~0 : 0;
1884 /* If this integer fits in one word, return a CONST_INT. */
1885 if ((i1 == 0 && i0 >= 0)
1886 || (i1 == ~0 && i0 < 0))
1887 return GEN_INT (i0);
1889 /* We use VOIDmode for integers. */
1893 /* Search the chain for an existing CONST_DOUBLE with the right value.
1894 If one is found, return it. */
1896 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1897 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1898 && GET_MODE (r) == mode)
1901 /* No; make a new one and add it to the chain.
1903 We may be called by an optimizer which may be discarding any memory
1904 allocated during its processing (such as combine and loop). However,
1905 we will be leaving this constant on the chain, so we cannot tolerate
1906 freed memory. So switch to saveable_obstack for this allocation
1907 and then switch back if we were in current_obstack. */
1909 push_obstacks_nochange ();
1910 rtl_in_saveable_obstack ();
1911 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1914 /* Don't touch const_double_chain in nested function; see force_const_mem.
1915 Also, don't touch it if not inside any function. */
1916 if (outer_function_chain == 0 && current_function_decl != 0)
1918 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1919 const_double_chain = r;
1922 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1923 Actual use of mem-slot is only through force_const_mem. */
1925 CONST_DOUBLE_MEM (r) = const0_rtx;
1930 /* Return a CONST_DOUBLE for a specified `double' value
1931 and machine mode. */
1934 immed_real_const_1 (d, mode)
1936 enum machine_mode mode;
1938 union real_extract u;
1940 int in_current_obstack;
1942 /* Get the desired `double' value as a sequence of ints
1943 since that is how they are stored in a CONST_DOUBLE. */
1947 /* Detect special cases. */
1949 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1950 if (!bcmp ((char *) &dconst0, (char *) &d, sizeof d))
1951 return CONST0_RTX (mode);
1952 /* Check for NaN first, because some ports (specifically the i386) do not
1953 emit correct ieee-fp code by default, and thus will generate a core
1954 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1955 does a floating point comparison. */
1956 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1957 return CONST1_RTX (mode);
1959 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1960 return immed_double_const (u.i[0], u.i[1], mode);
1962 /* The rest of this function handles the case where
1963 a float value requires more than 2 ints of space.
1964 It will be deleted as dead code on machines that don't need it. */
1966 /* Search the chain for an existing CONST_DOUBLE with the right value.
1967 If one is found, return it. */
1969 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1970 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
1971 && GET_MODE (r) == mode)
1974 /* No; make a new one and add it to the chain.
1976 We may be called by an optimizer which may be discarding any memory
1977 allocated during its processing (such as combine and loop). However,
1978 we will be leaving this constant on the chain, so we cannot tolerate
1979 freed memory. So switch to saveable_obstack for this allocation
1980 and then switch back if we were in current_obstack. */
1982 push_obstacks_nochange ();
1983 rtl_in_saveable_obstack ();
1984 r = rtx_alloc (CONST_DOUBLE);
1986 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
1989 /* Don't touch const_double_chain in nested function; see force_const_mem.
1990 Also, don't touch it if not inside any function. */
1991 if (outer_function_chain == 0 && current_function_decl != 0)
1993 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1994 const_double_chain = r;
1997 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1998 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1999 is only through force_const_mem. */
2001 CONST_DOUBLE_MEM (r) = const0_rtx;
2006 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2007 which must be a REAL_CST tree node. */
2010 immed_real_const (exp)
2013 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2016 /* At the end of a function, forget the memory-constants
2017 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2018 Also clear out real_constant_chain and clear out all the chain-pointers. */
2021 clear_const_double_mem ()
2023 register rtx r, next;
2025 /* Don't touch CONST_DOUBLE_MEM for nested functions.
2026 See force_const_mem for explanation. */
2027 if (outer_function_chain != 0)
2030 for (r = const_double_chain; r; r = next)
2032 next = CONST_DOUBLE_CHAIN (r);
2033 CONST_DOUBLE_CHAIN (r) = 0;
2034 CONST_DOUBLE_MEM (r) = cc0_rtx;
2036 const_double_chain = 0;
2039 /* Given an expression EXP with a constant value,
2040 reduce it to the sum of an assembler symbol and an integer.
2041 Store them both in the structure *VALUE.
2042 Abort if EXP does not reduce. */
2047 HOST_WIDE_INT offset;
2051 decode_addr_const (exp, value)
2053 struct addr_const *value;
2055 register tree target = TREE_OPERAND (exp, 0);
2056 register int offset = 0;
2061 if (TREE_CODE (target) == COMPONENT_REF
2062 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2065 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2066 target = TREE_OPERAND (target, 0);
2068 else if (TREE_CODE (target) == ARRAY_REF)
2070 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2071 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2073 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2074 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2076 target = TREE_OPERAND (target, 0);
2082 switch (TREE_CODE (target))
2086 x = DECL_RTL (target);
2090 if (output_bytecode)
2091 /* FIXME: this may not be correct, check it */
2092 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
2094 x = gen_rtx (MEM, FUNCTION_MODE,
2095 gen_rtx (LABEL_REF, VOIDmode,
2096 label_rtx (TREE_OPERAND (exp, 0))));
2103 x = TREE_CST_RTL (target);
2110 if (!output_bytecode)
2112 if (GET_CODE (x) != MEM)
2118 value->offset = offset;
2121 /* Uniquize all constants that appear in memory.
2122 Each constant in memory thus far output is recorded
2123 in `const_hash_table' with a `struct constant_descriptor'
2124 that contains a polish representation of the value of
2127 We cannot store the trees in the hash table
2128 because the trees may be temporary. */
2130 struct constant_descriptor
2132 struct constant_descriptor *next;
2138 #define MAX_HASH_TABLE 1009
2139 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2141 /* Compute a hash code for a constant expression. */
2148 register int len, hi, i;
2149 register enum tree_code code = TREE_CODE (exp);
2151 if (code == INTEGER_CST)
2153 p = (char *) &TREE_INT_CST_LOW (exp);
2154 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2156 else if (code == REAL_CST)
2158 p = (char *) &TREE_REAL_CST (exp);
2159 len = sizeof TREE_REAL_CST (exp);
2161 else if (code == STRING_CST)
2162 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2163 else if (code == COMPLEX_CST)
2164 return const_hash (TREE_REALPART (exp)) * 5
2165 + const_hash (TREE_IMAGPART (exp));
2166 else if (code == CONSTRUCTOR && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2168 len = int_size_in_bytes (TREE_TYPE (exp));
2169 p = (char*) alloca (len);
2170 get_set_constructor_bytes (exp, (unsigned char *) p, len);
2172 else if (code == CONSTRUCTOR)
2176 /* For record type, include the type in the hashing.
2177 We do not do so for array types
2178 because (1) the sizes of the elements are sufficient
2179 and (2) distinct array types can have the same constructor.
2180 Instead, we include the array size because the constructor could
2182 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2183 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2186 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2187 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2189 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2190 if (TREE_VALUE (link))
2191 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2195 else if (code == ADDR_EXPR)
2197 struct addr_const value;
2198 decode_addr_const (exp, &value);
2199 if (GET_CODE (value.base) == SYMBOL_REF)
2201 /* Don't hash the address of the SYMBOL_REF;
2202 only use the offset and the symbol name. */
2204 p = XSTR (value.base, 0);
2205 for (i = 0; p[i] != 0; i++)
2206 hi = ((hi * 613) + (unsigned)(p[i]));
2208 else if (GET_CODE (value.base) == LABEL_REF)
2209 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2211 hi &= (1 << HASHBITS) - 1;
2212 hi %= MAX_HASH_TABLE;
2215 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2216 return const_hash (TREE_OPERAND (exp, 0)) * 9
2217 + const_hash (TREE_OPERAND (exp, 1));
2218 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2219 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2221 /* Compute hashing function */
2223 for (i = 0; i < len; i++)
2224 hi = ((hi * 613) + (unsigned)(p[i]));
2226 hi &= (1 << HASHBITS) - 1;
2227 hi %= MAX_HASH_TABLE;
2231 /* Compare a constant expression EXP with a constant-descriptor DESC.
2232 Return 1 if DESC describes a constant with the same value as EXP. */
2235 compare_constant (exp, desc)
2237 struct constant_descriptor *desc;
2239 return 0 != compare_constant_1 (exp, desc->contents);
2242 /* Compare constant expression EXP with a substring P of a constant descriptor.
2243 If they match, return a pointer to the end of the substring matched.
2244 If they do not match, return 0.
2246 Since descriptors are written in polish prefix notation,
2247 this function can be used recursively to test one operand of EXP
2248 against a subdescriptor, and if it succeeds it returns the
2249 address of the subdescriptor for the next operand. */
2252 compare_constant_1 (exp, p)
2256 register char *strp;
2258 register enum tree_code code = TREE_CODE (exp);
2260 if (code != (enum tree_code) *p++)
2263 if (code == INTEGER_CST)
2265 /* Integer constants are the same only if the same width of type. */
2266 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2268 strp = (char *) &TREE_INT_CST_LOW (exp);
2269 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2271 else if (code == REAL_CST)
2273 /* Real constants are the same only if the same width of type. */
2274 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2276 strp = (char *) &TREE_REAL_CST (exp);
2277 len = sizeof TREE_REAL_CST (exp);
2279 else if (code == STRING_CST)
2281 if (flag_writable_strings)
2283 strp = TREE_STRING_POINTER (exp);
2284 len = TREE_STRING_LENGTH (exp);
2285 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2286 sizeof TREE_STRING_LENGTH (exp)))
2288 p += sizeof TREE_STRING_LENGTH (exp);
2290 else if (code == COMPLEX_CST)
2292 p = compare_constant_1 (TREE_REALPART (exp), p);
2293 if (p == 0) return 0;
2294 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2297 else if (code == CONSTRUCTOR && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2299 len = int_size_in_bytes (TREE_TYPE (exp));
2300 strp = (char*) alloca (len);
2301 get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2303 else if (code == CONSTRUCTOR)
2306 int length = list_length (CONSTRUCTOR_ELTS (exp));
2309 if (bcmp ((char *) &length, p, sizeof length))
2313 /* For record constructors, insist that the types match.
2314 For arrays, just verify both constructors are for arrays. */
2315 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2316 type = TREE_TYPE (exp);
2319 if (bcmp ((char *) &type, p, sizeof type))
2323 /* For arrays, insist that the size in bytes match. */
2324 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2326 int size = int_size_in_bytes (TREE_TYPE (exp));
2327 if (bcmp ((char *) &size, p, sizeof size))
2332 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2334 if (TREE_VALUE (link))
2336 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2343 if (bcmp ((char *) &zero, p, sizeof zero))
2351 else if (code == ADDR_EXPR)
2353 struct addr_const value;
2354 decode_addr_const (exp, &value);
2355 strp = (char *) &value.offset;
2356 len = sizeof value.offset;
2357 /* Compare the offset. */
2359 if (*p++ != *strp++)
2361 /* Compare symbol name. */
2362 strp = XSTR (value.base, 0);
2363 len = strlen (strp) + 1;
2365 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2367 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2368 if (p == 0) return 0;
2369 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2372 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2374 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2378 /* Compare constant contents. */
2380 if (*p++ != *strp++)
2386 /* Construct a constant descriptor for the expression EXP.
2387 It is up to the caller to enter the descriptor in the hash table. */
2389 static struct constant_descriptor *
2390 record_constant (exp)
2393 struct constant_descriptor *next = 0;
2396 /* Make a struct constant_descriptor. The first two pointers will
2397 be filled in later. Here we just leave space for them. */
2399 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2400 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2401 record_constant_1 (exp);
2402 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2405 /* Add a description of constant expression EXP
2406 to the object growing in `permanent_obstack'.
2407 No need to return its address; the caller will get that
2408 from the obstack when the object is complete. */
2411 record_constant_1 (exp)
2414 register char *strp;
2416 register enum tree_code code = TREE_CODE (exp);
2418 obstack_1grow (&permanent_obstack, (unsigned int) code);
2423 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2424 strp = (char *) &TREE_INT_CST_LOW (exp);
2425 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2429 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2430 strp = (char *) &TREE_REAL_CST (exp);
2431 len = sizeof TREE_REAL_CST (exp);
2435 if (flag_writable_strings)
2438 strp = TREE_STRING_POINTER (exp);
2439 len = TREE_STRING_LENGTH (exp);
2440 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2441 sizeof TREE_STRING_LENGTH (exp));
2445 record_constant_1 (TREE_REALPART (exp));
2446 record_constant_1 (TREE_IMAGPART (exp));
2450 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2452 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2453 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2454 obstack_blank (&permanent_obstack, nbytes);
2455 get_set_constructor_bytes
2456 (exp, (unsigned char *) permanent_obstack.next_free, nbytes);
2462 int length = list_length (CONSTRUCTOR_ELTS (exp));
2465 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2467 /* For record constructors, insist that the types match.
2468 For arrays, just verify both constructors are for arrays. */
2469 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2470 type = TREE_TYPE (exp);
2473 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2475 /* For arrays, insist that the size in bytes match. */
2476 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2478 int size = int_size_in_bytes (TREE_TYPE (exp));
2479 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2482 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2484 if (TREE_VALUE (link))
2485 record_constant_1 (TREE_VALUE (link));
2490 obstack_grow (&permanent_obstack,
2491 (char *) &zero, sizeof zero);
2499 struct addr_const value;
2501 decode_addr_const (exp, &value);
2502 /* Record the offset. */
2503 obstack_grow (&permanent_obstack,
2504 (char *) &value.offset, sizeof value.offset);
2505 /* Record the symbol name. */
2506 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2507 strlen (XSTR (value.base, 0)) + 1);
2513 record_constant_1 (TREE_OPERAND (exp, 0));
2514 record_constant_1 (TREE_OPERAND (exp, 1));
2519 case NON_LVALUE_EXPR:
2520 record_constant_1 (TREE_OPERAND (exp, 0));
2527 /* Record constant contents. */
2528 obstack_grow (&permanent_obstack, strp, len);
2531 /* Record a list of constant expressions that were passed to
2532 output_constant_def but that could not be output right away. */
2534 struct deferred_constant
2536 struct deferred_constant *next;
2542 static struct deferred_constant *deferred_constants;
2544 /* Nonzero means defer output of addressed subconstants
2545 (i.e., those for which output_constant_def is called.) */
2546 static int defer_addressed_constants_flag;
2548 /* Start deferring output of subconstants. */
2551 defer_addressed_constants ()
2553 defer_addressed_constants_flag++;
2556 /* Stop deferring output of subconstants,
2557 and output now all those that have been deferred. */
2560 output_deferred_addressed_constants ()
2562 struct deferred_constant *p, *next;
2564 defer_addressed_constants_flag--;
2566 if (defer_addressed_constants_flag > 0)
2569 for (p = deferred_constants; p; p = next)
2571 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2576 deferred_constants = 0;
2579 /* Make a copy of the whole tree structure for a constant.
2580 This handles the same types of nodes that compare_constant
2581 and record_constant handle. */
2587 switch (TREE_CODE (exp))
2590 /* For ADDR_EXPR, we do not want to copy the decl whose address
2591 is requested. We do want to copy constants though. */
2592 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2593 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2594 copy_constant (TREE_OPERAND (exp, 0)));
2596 return copy_node (exp);
2601 return copy_node (exp);
2604 return build_complex (copy_constant (TREE_REALPART (exp)),
2605 copy_constant (TREE_IMAGPART (exp)));
2609 return build (TREE_CODE (exp), TREE_TYPE (exp),
2610 copy_constant (TREE_OPERAND (exp, 0)),
2611 copy_constant (TREE_OPERAND (exp, 1)));
2615 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2616 copy_constant (TREE_OPERAND (exp, 0)));
2620 tree copy = copy_node (exp);
2621 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2624 CONSTRUCTOR_ELTS (copy) = list;
2625 for (tail = list; tail; tail = TREE_CHAIN (tail))
2626 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2627 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2628 for (tail = list; tail; tail = TREE_CHAIN (tail))
2629 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2639 /* Return an rtx representing a reference to constant data in memory
2640 for the constant expression EXP.
2642 If assembler code for such a constant has already been output,
2643 return an rtx to refer to it.
2644 Otherwise, output such a constant in memory (or defer it for later)
2645 and generate an rtx for it.
2647 The TREE_CST_RTL of EXP is set up to point to that rtx.
2648 The const_hash_table records which constants already have label strings. */
2651 output_constant_def (exp)
2655 register struct constant_descriptor *desc;
2661 if (TREE_CODE (exp) == INTEGER_CST)
2662 abort (); /* No TREE_CST_RTL slot in these. */
2664 if (TREE_CST_RTL (exp))
2665 return TREE_CST_RTL (exp);
2667 /* Make sure any other constants whose addresses appear in EXP
2668 are assigned label numbers. */
2670 reloc = output_addressed_constants (exp);
2672 /* Compute hash code of EXP. Search the descriptors for that hash code
2673 to see if any of them describes EXP. If yes, the descriptor records
2674 the label number already assigned. */
2676 hash = const_hash (exp) % MAX_HASH_TABLE;
2678 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2679 if (compare_constant (exp, desc))
2681 found = desc->label;
2687 /* No constant equal to EXP is known to have been output.
2688 Make a constant descriptor to enter EXP in the hash table.
2689 Assign the label number and record it in the descriptor for
2690 future calls to this function to find. */
2692 /* Create a string containing the label name, in LABEL. */
2693 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2695 desc = record_constant (exp);
2696 desc->next = const_hash_table[hash];
2698 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2699 const_hash_table[hash] = desc;
2703 /* Create a string containing the label name, in LABEL. */
2704 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2707 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2709 push_obstacks_nochange ();
2710 if (TREE_PERMANENT (exp))
2711 end_temporary_allocation ();
2713 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2716 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2717 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2718 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2719 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2723 /* Optionally set flags or add text to the name to record information
2724 such as that it is a function name. If the name is changed, the macro
2725 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2726 #ifdef ENCODE_SECTION_INFO
2727 ENCODE_SECTION_INFO (exp);
2730 /* If this is the first time we've seen this particular constant,
2731 output it (or defer its output for later). */
2734 if (defer_addressed_constants_flag)
2736 struct deferred_constant *p;
2737 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2739 push_obstacks_nochange ();
2740 suspend_momentary ();
2741 p->exp = copy_constant (exp);
2744 p->labelno = const_labelno++;
2745 p->next = deferred_constants;
2746 deferred_constants = p;
2749 output_constant_def_contents (exp, reloc, const_labelno++);
2752 return TREE_CST_RTL (exp);
2755 /* Now output assembler code to define the label for EXP,
2756 and follow it with the data of EXP. */
2759 output_constant_def_contents (exp, reloc, labelno)
2766 if (IN_NAMED_SECTION (exp))
2767 named_section (exp, NULL);
2770 /* First switch to text section, except for writable strings. */
2771 #ifdef SELECT_SECTION
2772 SELECT_SECTION (exp, reloc);
2774 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2775 || (flag_pic && reloc))
2778 readonly_data_section ();
2782 /* Align the location counter as required by EXP's data type. */
2783 align = TYPE_ALIGN (TREE_TYPE (exp));
2784 #ifdef CONSTANT_ALIGNMENT
2785 align = CONSTANT_ALIGNMENT (exp, align);
2788 if (align > BITS_PER_UNIT)
2790 if (!output_bytecode)
2792 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2796 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2800 /* Output the label itself. */
2801 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2803 /* Output the value of EXP. */
2804 output_constant (exp,
2805 (TREE_CODE (exp) == STRING_CST
2806 ? TREE_STRING_LENGTH (exp)
2807 : int_size_in_bytes (TREE_TYPE (exp))));
2811 /* Similar hash facility for making memory-constants
2812 from constant rtl-expressions. It is used on RISC machines
2813 where immediate integer arguments and constant addresses are restricted
2814 so that such constants must be stored in memory.
2816 This pool of constants is reinitialized for each function
2817 so each function gets its own constants-pool that comes right before it.
2819 All structures allocated here are discarded when functions are saved for
2820 inlining, so they do not need to be allocated permanently. */
2822 #define MAX_RTX_HASH_TABLE 61
2823 static struct constant_descriptor **const_rtx_hash_table;
2825 /* Structure to represent sufficient information about a constant so that
2826 it can be output when the constant pool is output, so that function
2827 integration can be done, and to simplify handling on machines that reference
2828 constant pool as base+displacement. */
2830 struct pool_constant
2832 struct constant_descriptor *desc;
2833 struct pool_constant *next;
2834 enum machine_mode mode;
2841 /* Pointers to first and last constant in pool. */
2843 static struct pool_constant *first_pool, *last_pool;
2845 /* Current offset in constant pool (does not include any machine-specific
2848 static int pool_offset;
2850 /* Structure used to maintain hash table mapping symbols used to their
2851 corresponding constants. */
2856 struct pool_constant *pool;
2857 struct pool_sym *next;
2860 static struct pool_sym **const_rtx_sym_hash_table;
2862 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2863 The argument is XSTR (... , 0) */
2865 #define SYMHASH(LABEL) \
2866 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2868 /* Initialize constant pool hashing for next function. */
2871 init_const_rtx_hash_table ()
2873 const_rtx_hash_table
2874 = ((struct constant_descriptor **)
2875 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2876 const_rtx_sym_hash_table
2877 = ((struct pool_sym **)
2878 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2879 bzero ((char *) const_rtx_hash_table,
2880 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2881 bzero ((char *) const_rtx_sym_hash_table,
2882 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2884 first_pool = last_pool = 0;
2888 /* Save and restore status for a nested function. */
2891 save_varasm_status (p)
2894 p->const_rtx_hash_table = const_rtx_hash_table;
2895 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2896 p->first_pool = first_pool;
2897 p->last_pool = last_pool;
2898 p->pool_offset = pool_offset;
2902 restore_varasm_status (p)
2905 const_rtx_hash_table = p->const_rtx_hash_table;
2906 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2907 first_pool = p->first_pool;
2908 last_pool = p->last_pool;
2909 pool_offset = p->pool_offset;
2912 enum kind { RTX_DOUBLE, RTX_INT };
2916 #ifdef ONLY_INT_FIELDS
2917 unsigned int kind : 16;
2918 unsigned int mode : 16;
2920 enum kind kind : 16;
2921 enum machine_mode mode : 16;
2924 union real_extract du;
2925 struct addr_const addr;
2929 /* Express an rtx for a constant integer (perhaps symbolic)
2930 as the sum of a symbol or label plus an explicit integer.
2931 They are stored into VALUE. */
2934 decode_rtx_const (mode, x, value)
2935 enum machine_mode mode;
2937 struct rtx_const *value;
2939 /* Clear the whole structure, including any gaps. */
2942 int *p = (int *) value;
2943 int *end = (int *) (value + 1);
2948 value->kind = RTX_INT; /* Most usual kind. */
2951 switch (GET_CODE (x))
2954 value->kind = RTX_DOUBLE;
2955 if (GET_MODE (x) != VOIDmode)
2956 value->mode = GET_MODE (x);
2957 bcopy ((char *) &CONST_DOUBLE_LOW (x),
2958 (char *) &value->un.du, sizeof value->un.du);
2962 value->un.addr.offset = INTVAL (x);
2968 value->un.addr.base = x;
2973 if (GET_CODE (x) == PLUS)
2975 value->un.addr.base = XEXP (x, 0);
2976 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2978 value->un.addr.offset = INTVAL (XEXP (x, 1));
2980 else if (GET_CODE (x) == MINUS)
2982 value->un.addr.base = XEXP (x, 0);
2983 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2985 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2995 if (value->kind == RTX_INT && value->un.addr.base != 0)
2996 switch (GET_CODE (value->un.addr.base))
3000 /* Use the string's address, not the SYMBOL_REF's address,
3001 for the sake of addresses of library routines.
3002 For a LABEL_REF, compare labels. */
3003 value->un.addr.base = XEXP (value->un.addr.base, 0);
3007 /* Given a MINUS expression, simplify it if both sides
3008 include the same symbol. */
3011 simplify_subtraction (x)
3014 struct rtx_const val0, val1;
3016 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3017 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3019 if (val0.un.addr.base == val1.un.addr.base)
3020 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3024 /* Compute a hash code for a constant RTL expression. */
3027 const_hash_rtx (mode, x)
3028 enum machine_mode mode;
3033 struct rtx_const value;
3034 decode_rtx_const (mode, x, &value);
3036 /* Compute hashing function */
3038 for (i = 0; i < sizeof value / sizeof (int); i++)
3039 hi += ((int *) &value)[i];
3041 hi &= (1 << HASHBITS) - 1;
3042 hi %= MAX_RTX_HASH_TABLE;
3046 /* Compare a constant rtl object X with a constant-descriptor DESC.
3047 Return 1 if DESC describes a constant with the same value as X. */
3050 compare_constant_rtx (mode, x, desc)
3051 enum machine_mode mode;
3053 struct constant_descriptor *desc;
3055 register int *p = (int *) desc->contents;
3058 struct rtx_const value;
3060 decode_rtx_const (mode, x, &value);
3061 strp = (int *) &value;
3062 len = sizeof value / sizeof (int);
3064 /* Compare constant contents. */
3066 if (*p++ != *strp++)
3072 /* Construct a constant descriptor for the rtl-expression X.
3073 It is up to the caller to enter the descriptor in the hash table. */
3075 static struct constant_descriptor *
3076 record_constant_rtx (mode, x)
3077 enum machine_mode mode;
3080 struct constant_descriptor *ptr;
3082 struct rtx_const value;
3084 decode_rtx_const (mode, x, &value);
3086 /* Put these things in the saveable obstack so we can ensure it won't
3087 be freed if we are called from combine or some other phase that discards
3088 memory allocated from function_obstack (current_obstack). */
3089 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3090 obstack_grow (saveable_obstack, &label, sizeof label);
3092 /* Record constant contents. */
3093 obstack_grow (saveable_obstack, &value, sizeof value);
3095 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3098 /* Given a constant rtx X, make (or find) a memory constant for its value
3099 and return a MEM rtx to refer to it in memory. */
3102 force_const_mem (mode, x)
3103 enum machine_mode mode;
3107 register struct constant_descriptor *desc;
3112 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3113 (this will always be true for floating CONST_DOUBLEs that have been
3114 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3115 use the previous copy. Otherwise, make a new one. Note that in
3116 the unlikely event that this same CONST_DOUBLE is used in two different
3117 modes in an alternating fashion, we will allocate a lot of different
3118 memory locations, but this should be extremely rare. */
3120 /* Don't use CONST_DOUBLE_MEM in a nested function.
3121 Nested functions have their own constant pools,
3122 so they can't share the same values in CONST_DOUBLE_MEM
3123 with the containing function. */
3124 if (outer_function_chain == 0)
3125 if (GET_CODE (x) == CONST_DOUBLE
3126 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3127 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3128 return CONST_DOUBLE_MEM (x);
3130 /* Compute hash code of X. Search the descriptors for that hash code
3131 to see if any of them describes X. If yes, the descriptor records
3132 the label number already assigned. */
3134 hash = const_hash_rtx (mode, x);
3136 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3137 if (compare_constant_rtx (mode, x, desc))
3139 found = desc->label;
3145 register struct pool_constant *pool;
3146 register struct pool_sym *sym;
3149 /* No constant equal to X is known to have been output.
3150 Make a constant descriptor to enter X in the hash table.
3151 Assign the label number and record it in the descriptor for
3152 future calls to this function to find. */
3154 desc = record_constant_rtx (mode, x);
3155 desc->next = const_rtx_hash_table[hash];
3156 const_rtx_hash_table[hash] = desc;
3158 /* Align the location counter as required by EXP's data type. */
3159 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3160 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3161 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3163 pool_offset += align - 1;
3164 pool_offset &= ~ (align - 1);
3166 /* If RTL is not being placed into the saveable obstack, make a
3167 copy of X that is in the saveable obstack in case we are being
3168 called from combine or some other phase that discards memory
3169 it allocates. We need only do this if it is a CONST, since
3170 no other RTX should be allocated in this situation. */
3171 if (rtl_obstack != saveable_obstack
3172 && GET_CODE (x) == CONST)
3174 push_obstacks_nochange ();
3175 rtl_in_saveable_obstack ();
3177 x = gen_rtx (CONST, GET_MODE (x),
3178 gen_rtx (PLUS, GET_MODE (x),
3179 XEXP (XEXP (x, 0), 0), XEXP (XEXP (x, 0), 1)));
3183 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3185 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3189 pool->labelno = const_labelno;
3190 pool->align = align;
3191 pool->offset = pool_offset;
3197 last_pool->next = pool;
3200 pool_offset += GET_MODE_SIZE (mode);
3202 /* Create a string containing the label name, in LABEL. */
3203 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3208 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3210 /* Add label to symbol hash table. */
3211 hash = SYMHASH (found);
3212 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3215 sym->next = const_rtx_sym_hash_table[hash];
3216 const_rtx_sym_hash_table[hash] = sym;
3219 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3221 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3223 RTX_UNCHANGING_P (def) = 1;
3224 /* Mark the symbol_ref as belonging to this constants pool. */
3225 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3226 current_function_uses_const_pool = 1;
3228 if (outer_function_chain == 0)
3229 if (GET_CODE (x) == CONST_DOUBLE)
3231 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3233 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3234 const_double_chain = x;
3236 CONST_DOUBLE_MEM (x) = def;
3242 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3243 the corresponding pool_constant structure. */
3245 static struct pool_constant *
3246 find_pool_constant (addr)
3249 struct pool_sym *sym;
3250 char *label = XSTR (addr, 0);
3252 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3253 if (sym->label == label)
3259 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3262 get_pool_constant (addr)
3265 return (find_pool_constant (addr))->constant;
3268 /* Similar, return the mode. */
3271 get_pool_mode (addr)
3274 return (find_pool_constant (addr))->mode;
3277 /* Similar, return the offset in the constant pool. */
3280 get_pool_offset (addr)
3283 return (find_pool_constant (addr))->offset;
3286 /* Return the size of the constant pool. */
3294 /* Write all the constants in the constant pool. */
3297 output_constant_pool (fnname, fndecl)
3301 struct pool_constant *pool;
3303 union real_extract u;
3305 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3306 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3309 for (pool = first_pool; pool; pool = pool->next)
3313 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3314 whose CODE_LABEL has been deleted. This can occur if a jump table
3315 is eliminated by optimization. If so, write a constant of zero
3316 instead. Note that this can also happen by turning the
3317 CODE_LABEL into a NOTE. */
3318 if (((GET_CODE (x) == LABEL_REF
3319 && (INSN_DELETED_P (XEXP (x, 0))
3320 || GET_CODE (XEXP (x, 0)) == NOTE)))
3321 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3322 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3323 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3324 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3327 /* First switch to correct section. */
3328 #ifdef SELECT_RTX_SECTION
3329 SELECT_RTX_SECTION (pool->mode, x);
3331 readonly_data_section ();
3334 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3335 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3336 pool->align, pool->labelno, done);
3339 if (pool->align > 1)
3340 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3342 /* Output the label. */
3343 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3345 /* Output the value of the constant itself. */
3346 switch (GET_MODE_CLASS (pool->mode))
3349 if (GET_CODE (x) != CONST_DOUBLE)
3352 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3353 assemble_real (u.d, pool->mode);
3357 case MODE_PARTIAL_INT:
3358 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3368 /* Done with this pool. */
3369 first_pool = last_pool = 0;
3372 /* Find all the constants whose addresses are referenced inside of EXP,
3373 and make sure assembler code with a label has been output for each one.
3374 Indicate whether an ADDR_EXPR has been encountered. */
3377 output_addressed_constants (exp)
3382 switch (TREE_CODE (exp))
3386 register tree constant = TREE_OPERAND (exp, 0);
3388 while (TREE_CODE (constant) == COMPONENT_REF)
3390 constant = TREE_OPERAND (constant, 0);
3393 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3394 || TREE_CODE (constant) == CONSTRUCTOR)
3395 /* No need to do anything here
3396 for addresses of variables or functions. */
3397 output_constant_def (constant);
3404 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3405 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3410 case NON_LVALUE_EXPR:
3411 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3417 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3418 if (TREE_VALUE (link) != 0)
3419 reloc |= output_addressed_constants (TREE_VALUE (link));
3429 /* Output assembler code for constant EXP to FILE, with no label.
3430 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3431 Assumes output_addressed_constants has been done on EXP already.
3433 Generate exactly SIZE bytes of assembler data, padding at the end
3434 with zeros if necessary. SIZE must always be specified.
3436 SIZE is important for structure constructors,
3437 since trailing members may have been omitted from the constructor.
3438 It is also important for initialization of arrays from string constants
3439 since the full length of the string constant might not be wanted.
3440 It is also needed for initialization of unions, where the initializer's
3441 type is just one member, and that may not be as long as the union.
3443 There a case in which we would fail to output exactly SIZE bytes:
3444 for a structure constructor that wants to produce more than SIZE bytes.
3445 But such constructors will never be generated for any possible input. */
3448 output_constant (exp, size)
3452 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3458 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3459 That way we get the constant (we hope) inside it. Also, strip off any
3460 NOP_EXPR that converts between two record, union, array, or set types. */
3461 while ((TREE_CODE (exp) == NOP_EXPR
3462 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3463 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
3464 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3465 exp = TREE_OPERAND (exp, 0);
3467 /* Allow a constructor with no elements for any data type.
3468 This means to fill the space with zeros. */
3469 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3471 if (output_bytecode)
3472 bc_emit_const_skip (size);
3474 assemble_zeros (size);
3485 case REFERENCE_TYPE:
3486 /* ??? What about (int)((float)(int)&foo + 4) */
3487 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3488 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3489 exp = TREE_OPERAND (exp, 0);
3491 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3492 EXPAND_INITIALIZER),
3494 error ("initializer for integer value is too complicated");
3499 if (TREE_CODE (exp) != REAL_CST)
3500 error ("initializer for floating value is not a floating constant");
3502 assemble_real (TREE_REAL_CST (exp),
3503 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3508 output_constant (TREE_REALPART (exp), size / 2);
3509 output_constant (TREE_IMAGPART (exp), size / 2);
3510 size -= (size / 2) * 2;
3514 if (TREE_CODE (exp) == CONSTRUCTOR)
3516 output_constructor (exp, size);
3519 else if (TREE_CODE (exp) == STRING_CST)
3523 if (size > TREE_STRING_LENGTH (exp))
3525 excess = size - TREE_STRING_LENGTH (exp);
3526 size = TREE_STRING_LENGTH (exp);
3529 assemble_string (TREE_STRING_POINTER (exp), size);
3538 if (TREE_CODE (exp) == CONSTRUCTOR)
3539 output_constructor (exp, size);
3545 if (TREE_CODE (exp) == INTEGER_CST)
3546 assemble_integer (expand_expr (exp, NULL_RTX,
3547 VOIDmode, EXPAND_INITIALIZER),
3549 else if (TREE_CODE (exp) == CONSTRUCTOR)
3551 unsigned char *buffer = (unsigned char *) alloca (size);
3552 if (get_set_constructor_bytes (exp, buffer, size))
3554 assemble_string ((char *) buffer, size);
3557 error ("unknown set constructor type");
3562 assemble_zeros (size);
3565 /* Bytecode specific code to output assembler for integer. */
3568 bc_assemble_integer (exp, size)
3576 /* FIXME: is this fold() business going to be as good as the
3577 expand_expr() using EXPAND_SUM above in the RTL case? I
3579 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3583 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3584 exp = TREE_OPERAND (exp, 0);
3585 if (TREE_CODE (exp) == INTEGER_CST)
3590 else if (TREE_CODE (exp) == PLUS_EXPR)
3592 const_part = TREE_OPERAND (exp, 0);
3593 while (TREE_CODE (const_part) == NOP_EXPR
3594 || TREE_CODE (const_part) == CONVERT_EXPR)
3595 const_part = TREE_OPERAND (const_part, 0);
3596 addr_part = TREE_OPERAND (exp, 1);
3597 while (TREE_CODE (addr_part) == NOP_EXPR
3598 || TREE_CODE (addr_part) == CONVERT_EXPR)
3599 addr_part = TREE_OPERAND (addr_part, 0);
3600 if (TREE_CODE (const_part) != INTEGER_CST)
3601 tmp = const_part, const_part = addr_part, addr_part = tmp;
3602 if (TREE_CODE (const_part) != INTEGER_CST
3603 || TREE_CODE (addr_part) != ADDR_EXPR)
3604 abort (); /* FIXME: we really haven't considered
3605 all the possible cases here. */
3607 else if (TREE_CODE (exp) == ADDR_EXPR)
3609 const_part = integer_zero_node;
3613 abort (); /* FIXME: ditto previous. */
3619 char c = TREE_INT_CST_LOW (const_part);
3625 short s = TREE_INT_CST_LOW (const_part);
3626 bc_emit ((char *) &s, 2);
3631 int i = TREE_INT_CST_LOW (const_part);
3632 bc_emit ((char *) &i, 4);
3637 if (WORDS_BIG_ENDIAN)
3639 int i = TREE_INT_CST_HIGH (const_part);
3640 bc_emit ((char *) &i, 4);
3641 i = TREE_INT_CST_LOW (const_part);
3642 bc_emit ((char *) &i, 4);
3646 int i = TREE_INT_CST_LOW (const_part);
3647 bc_emit ((char *) &i, 4);
3648 i = TREE_INT_CST_HIGH (const_part);
3649 bc_emit ((char *) &i, 4);
3656 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3657 bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3658 TREE_INT_CST_LOW (const_part));
3660 abort (); /* FIXME: there may be more cases. */
3663 /* Subroutine of output_constant, used for CONSTRUCTORs
3664 (aggregate constants).
3665 Generate at least SIZE bytes, padding if necessary. */
3668 output_constructor (exp, size)
3672 register tree link, field = 0;
3673 HOST_WIDE_INT min_index = 0;
3674 /* Number of bytes output or skipped so far.
3675 In other words, current position within the constructor. */
3676 int total_bytes = 0;
3677 /* Non-zero means BYTE contains part of a byte, to be output. */
3678 int byte_buffer_in_use = 0;
3681 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3684 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3685 field = TYPE_FIELDS (TREE_TYPE (exp));
3687 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3688 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3690 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3692 /* As LINK goes through the elements of the constant,
3693 FIELD goes through the structure fields, if the constant is a structure.
3694 if the constant is a union, then we override this,
3695 by getting the field from the TREE_LIST element.
3696 But the constant could also be an array. Then FIELD is zero. */
3697 for (link = CONSTRUCTOR_ELTS (exp);
3699 link = TREE_CHAIN (link),
3700 field = field ? TREE_CHAIN (field) : 0)
3702 tree val = TREE_VALUE (link);
3705 /* the element in a union constructor specifies the proper field. */
3707 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3708 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3710 /* if available, use the type given by link */
3711 if (TREE_PURPOSE (link) != 0)
3712 field = TREE_PURPOSE (link);
3715 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3716 index = TREE_PURPOSE (link);
3718 /* Eliminate the marker that makes a cast not be an lvalue. */
3722 if (field == 0 || !DECL_BIT_FIELD (field))
3724 /* An element that is not a bit-field. */
3726 register int fieldsize;
3727 /* Since this structure is static,
3728 we know the positions are constant. */
3729 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3733 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3735 * (TREE_INT_CST_LOW (index) - min_index));
3737 /* Output any buffered-up bit-fields preceding this element. */
3738 if (byte_buffer_in_use)
3740 ASM_OUTPUT_BYTE (asm_out_file, byte);
3742 byte_buffer_in_use = 0;
3745 /* Advance to offset of this element.
3746 Note no alignment needed in an array, since that is guaranteed
3747 if each element has the proper size. */
3748 if ((field != 0 || index != 0) && bitpos != total_bytes)
3750 if (!output_bytecode)
3751 assemble_zeros (bitpos - total_bytes);
3753 bc_emit_const_skip (bitpos - total_bytes);
3754 total_bytes = bitpos;
3757 /* Determine size this element should occupy. */
3760 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3762 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3764 /* This avoids overflow trouble. */
3765 tree size_tree = size_binop (CEIL_DIV_EXPR,
3767 size_int (BITS_PER_UNIT));
3768 fieldsize = TREE_INT_CST_LOW (size_tree);
3772 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3773 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3777 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3779 /* Output the element's initial value. */
3781 assemble_zeros (fieldsize);
3783 output_constant (val, fieldsize);
3785 /* Count its size. */
3786 total_bytes += fieldsize;
3788 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3789 error ("invalid initial value for member `%s'",
3790 IDENTIFIER_POINTER (DECL_NAME (field)));
3793 /* Element that is a bit-field. */
3795 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3797 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3800 val = integer_zero_node;
3802 /* If this field does not start in this (or, next) byte,
3804 if (next_offset / BITS_PER_UNIT != total_bytes)
3806 /* Output remnant of any bit field in previous bytes. */
3807 if (byte_buffer_in_use)
3809 ASM_OUTPUT_BYTE (asm_out_file, byte);
3811 byte_buffer_in_use = 0;
3814 /* If still not at proper byte, advance to there. */
3815 if (next_offset / BITS_PER_UNIT != total_bytes)
3817 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3818 total_bytes = next_offset / BITS_PER_UNIT;
3822 if (! byte_buffer_in_use)
3825 /* We must split the element into pieces that fall within
3826 separate bytes, and combine each byte with previous or
3827 following bit-fields. */
3829 /* next_offset is the offset n fbits from the beginning of
3830 the structure to the next bit of this element to be processed.
3831 end_offset is the offset of the first bit past the end of
3833 while (next_offset < end_offset)
3837 HOST_WIDE_INT value;
3838 int next_byte = next_offset / BITS_PER_UNIT;
3839 int next_bit = next_offset % BITS_PER_UNIT;
3841 /* Advance from byte to byte
3842 within this element when necessary. */
3843 while (next_byte != total_bytes)
3845 ASM_OUTPUT_BYTE (asm_out_file, byte);
3850 /* Number of bits we can process at once
3851 (all part of the same byte). */
3852 this_time = MIN (end_offset - next_offset,
3853 BITS_PER_UNIT - next_bit);
3854 if (BYTES_BIG_ENDIAN)
3856 /* On big-endian machine, take the most significant bits
3857 first (of the bits that are significant)
3858 and put them into bytes from the most significant end. */
3859 shift = end_offset - next_offset - this_time;
3860 /* Don't try to take a bunch of bits that cross
3861 the word boundary in the INTEGER_CST. */
3862 if (shift < HOST_BITS_PER_WIDE_INT
3863 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3865 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3866 shift = HOST_BITS_PER_WIDE_INT;
3869 /* Now get the bits from the appropriate constant word. */
3870 if (shift < HOST_BITS_PER_WIDE_INT)
3872 value = TREE_INT_CST_LOW (val);
3874 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3876 value = TREE_INT_CST_HIGH (val);
3877 shift -= HOST_BITS_PER_WIDE_INT;
3881 byte |= (((value >> shift)
3882 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3883 << (BITS_PER_UNIT - this_time - next_bit));
3887 /* On little-endian machines,
3888 take first the least significant bits of the value
3889 and pack them starting at the least significant
3890 bits of the bytes. */
3891 shift = (next_offset
3892 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3893 /* Don't try to take a bunch of bits that cross
3894 the word boundary in the INTEGER_CST. */
3895 if (shift < HOST_BITS_PER_WIDE_INT
3896 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3898 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3899 shift = HOST_BITS_PER_WIDE_INT;
3902 /* Now get the bits from the appropriate constant word. */
3903 if (shift < HOST_BITS_PER_INT)
3904 value = TREE_INT_CST_LOW (val);
3905 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3907 value = TREE_INT_CST_HIGH (val);
3908 shift -= HOST_BITS_PER_WIDE_INT;
3912 byte |= (((value >> shift)
3913 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3916 next_offset += this_time;
3917 byte_buffer_in_use = 1;
3921 if (byte_buffer_in_use)
3923 ASM_OUTPUT_BYTE (asm_out_file, byte);
3926 if (total_bytes < size)
3927 assemble_zeros (size - total_bytes);
3930 /* Output asm to handle ``#pragma weak'' */
3932 handle_pragma_weak (what, name, value)
3933 enum pragma_state what;
3936 #ifdef HANDLE_PRAGMA_WEAK
3937 if (what == ps_name || what == ps_value)
3939 struct weak_syms *weak =
3940 (struct weak_syms *)permalloc (sizeof (struct weak_syms));
3941 weak->next = weak_decls;
3942 weak->name = permalloc (strlen (name) + 1);
3943 strcpy (weak->name, name);
3945 if (what != ps_value)
3946 weak->value = NULL_PTR;
3950 weak->value = permalloc (strlen (value) + 1);
3951 strcpy (weak->value, value);
3956 else if (! (what == ps_done || what == ps_start))
3957 warning ("malformed `#pragma weak'");
3958 #endif /* HANDLE_PRAGMA_WEAK */
3961 /* Declare DECL to be a weak symbol. */
3967 #ifdef HANDLE_PRAGMA_WEAK
3968 if (! TREE_PUBLIC (decl))
3969 error_with_decl (decl, "weak declaration of `%s' must be public");
3971 handle_pragma_weak (ps_name,
3972 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
3977 /* Emit any pending weak declarations. */
3982 #ifdef HANDLE_PRAGMA_WEAK
3983 if (HANDLE_PRAGMA_WEAK)
3985 struct weak_syms *t;
3986 for (t = weak_decls; t; t = t->next)
3988 fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
3990 if (output_bytecode)
3991 BC_OUTPUT_LABELREF (asm_out_file, t->name);
3993 ASM_OUTPUT_LABELREF (asm_out_file, t->name);
3995 fputc ('\n', asm_out_file);
3997 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4004 assemble_alias (decl, target)
4007 #ifdef ASM_OUTPUT_DEF
4010 make_decl_rtl (decl, (char*)0, 1);
4011 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4013 /* Make name accessible from other files, if appropriate. */
4015 if (TREE_PUBLIC (decl))
4017 if (output_bytecode)
4018 BC_GLOBALIZE_LABEL (asm_out_file, name);
4020 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4023 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4025 warning ("alias definitions not supported in this configuration");