1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993 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> */
37 #include "hard-reg-set.h"
45 #ifdef XCOFF_DEBUGGING_INFO
52 #define ASM_STABS_OP ".stabs"
55 /* This macro gets just the user-specified name
56 out of the string in a SYMBOL_REF. On most machines,
57 we discard the * if any and that's all. */
58 #ifndef STRIP_NAME_ENCODING
59 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
60 (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
63 /* File in which assembler code is being written. */
65 extern FILE *asm_out_file;
67 /* The (assembler) name of the first globally-visible object output. */
68 char *first_global_object_name;
70 extern struct obstack *current_obstack;
71 extern struct obstack *saveable_obstack;
72 extern struct obstack permanent_obstack;
73 #define obstack_chunk_alloc xmalloc
75 /* Number for making the label on the next
76 constant that is stored in memory. */
80 /* Number for making the label on the next
81 static variable internal to a function. */
85 /* Carry information from ASM_DECLARE_OBJECT_NAME
86 to ASM_FINISH_DECLARE_OBJECT. */
88 int size_directive_output;
90 /* Nonzero if at least one function definition has been seen. */
91 static int function_defined;
93 extern FILE *asm_out_file;
95 static char *compare_constant_1 ();
96 static void record_constant_1 ();
97 static void output_constant_def_contents ();
98 static int contains_pointers_p ();
99 static void bc_output_ascii ();
101 void output_constant_pool ();
102 void assemble_name ();
103 int output_addressed_constants ();
104 void output_constant ();
105 void output_constructor ();
106 void output_byte_asm ();
107 void text_section ();
108 void readonly_data_section ();
109 void data_section ();
110 static void bc_assemble_integer ();
112 #ifdef EXTRA_SECTIONS
113 static enum in_section {no_section, in_text, in_data, EXTRA_SECTIONS} in_section
116 static enum in_section {no_section, in_text, in_data} in_section
120 /* Define functions like text_section for any extra sections. */
121 #ifdef EXTRA_SECTION_FUNCTIONS
122 EXTRA_SECTION_FUNCTIONS
125 /* Tell assembler to switch to text section. */
130 if (in_section != in_text)
135 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
137 in_section = in_text;
141 /* Tell assembler to switch to data section. */
146 if (in_section != in_data)
152 if (flag_shared_data)
154 #ifdef SHARED_SECTION_ASM_OP
155 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
157 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
161 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
164 in_section = in_data;
168 /* Tell assembler to switch to read-only data section. This is normally
172 readonly_data_section ()
174 #ifdef READONLY_DATA_SECTION
175 READONLY_DATA_SECTION (); /* Note this can call data_section. */
181 /* Determine if we're in the text section. */
186 return in_section == in_text;
189 /* Create the rtl to represent a function, for a function definition.
190 DECL is a FUNCTION_DECL node which describes which function.
191 The rtl is stored into DECL. */
194 make_function_rtl (decl)
197 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
201 if (DECL_RTL (decl) == 0)
202 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
204 /* Record that at least one function has been defined. */
205 function_defined = 1;
209 /* Rename a nested function to avoid conflicts. */
210 if (decl_function_context (decl) != 0
211 && DECL_INITIAL (decl) != 0
212 && DECL_RTL (decl) == 0)
216 name = IDENTIFIER_POINTER (DECL_NAME (decl));
217 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
218 name = obstack_copy0 (saveable_obstack, label, strlen (label));
222 if (DECL_RTL (decl) == 0)
225 = gen_rtx (MEM, DECL_MODE (decl),
226 gen_rtx (SYMBOL_REF, Pmode, name));
228 /* Optionally set flags or add text to the name to record information
229 such as that it is a function name. If the name is changed, the macro
230 ASM_OUTPUT_LABELREF will have to know how to strip this information.
231 And if it finds a * at the beginning after doing so, it must handle
233 #ifdef ENCODE_SECTION_INFO
234 ENCODE_SECTION_INFO (decl);
238 /* Record at least one function has been defined. */
239 function_defined = 1;
242 /* Create the DECL_RTL for a declaration for a static or external
243 variable or static or external function.
244 ASMSPEC, if not 0, is the string which the user specified
245 as the assembler symbol name.
246 TOP_LEVEL is nonzero if this is a file-scope variable.
247 This is never called for PARM_DECLs. */
249 bc_make_decl_rtl (decl, asmspec, top_level)
254 register char *name = TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl));
256 if (DECL_RTL (decl) == 0)
258 /* Print an error message for register variables. */
259 if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
260 error ("function declared `register'");
261 else if (DECL_REGISTER (decl))
262 error ("global register variables not supported in the interpreter");
264 /* Handle ordinary static variables and functions. */
265 if (DECL_RTL (decl) == 0)
267 /* Can't use just the variable's own name for a variable
268 whose scope is less than the whole file.
269 Concatenate a distinguishing number. */
270 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
274 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
275 name = obstack_copy0 (saveable_obstack, label, strlen (label));
279 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
284 /* Given NAME, a putative register name, discard any customary prefixes. */
287 strip_reg_name (name)
290 #ifdef REGISTER_PREFIX
291 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
292 name += strlen (REGISTER_PREFIX);
294 if (name[0] == '%' || name[0] == '#')
299 /* Decode an `asm' spec for a declaration as a register name.
300 Return the register number, or -1 if nothing specified,
301 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
302 or -3 if ASMSPEC is `cc' and is not recognized,
303 or -4 if ASMSPEC is `memory' and is not recognized.
304 Accept an exact spelling or a decimal number.
305 Prefixes such as % are optional. */
308 decode_reg_name (asmspec)
315 /* Get rid of confusing prefixes. */
316 asmspec = strip_reg_name (asmspec);
318 /* Allow a decimal number as a "register name". */
319 for (i = strlen (asmspec) - 1; i >= 0; i--)
320 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
322 if (asmspec[0] != 0 && i < 0)
325 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
331 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
333 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
336 #ifdef ADDITIONAL_REGISTER_NAMES
338 static struct { char *name; int number; } table[]
339 = ADDITIONAL_REGISTER_NAMES;
341 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
342 if (! strcmp (asmspec, table[i].name))
343 return table[i].number;
345 #endif /* ADDITIONAL_REGISTER_NAMES */
347 if (!strcmp (asmspec, "memory"))
350 if (!strcmp (asmspec, "cc"))
359 /* Create the DECL_RTL for a declaration for a static or external variable
360 or static or external function.
361 ASMSPEC, if not 0, is the string which the user specified
362 as the assembler symbol name.
363 TOP_LEVEL is nonzero if this is a file-scope variable.
365 This is never called for PARM_DECL nodes. */
368 make_decl_rtl (decl, asmspec, top_level)
378 bc_make_decl_rtl (decl, asmspec, top_level);
382 reg_number = decode_reg_name (asmspec);
384 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
385 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
387 if (reg_number == -2)
389 /* ASMSPEC is given, and not the name of a register. */
390 name = (char *) obstack_alloc (saveable_obstack,
391 strlen (asmspec) + 2);
393 strcpy (&name[1], asmspec);
396 /* For a duplicate declaration, we can be called twice on the
397 same DECL node. Don't discard the RTL already made. */
398 if (DECL_RTL (decl) == 0)
402 /* First detect errors in declaring global registers. */
403 if (DECL_REGISTER (decl) && reg_number == -1)
404 error_with_decl (decl,
405 "register name not specified for `%s'");
406 else if (DECL_REGISTER (decl) && reg_number < 0)
407 error_with_decl (decl,
408 "invalid register name for `%s'");
409 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
410 error_with_decl (decl,
411 "register name given for non-register variable `%s'");
412 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
413 error ("function declared `register'");
414 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
415 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
416 else if (DECL_REGISTER (decl)
417 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
418 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
419 /* Now handle properly declared static register variables. */
420 else if (DECL_REGISTER (decl))
423 #if 0 /* yylex should print the warning for this */
425 pedwarn ("ANSI C forbids global register variables");
427 if (DECL_INITIAL (decl) != 0 && top_level)
429 DECL_INITIAL (decl) = 0;
430 error ("global register variable has initial value");
432 if (fixed_regs[reg_number] == 0
433 && function_defined && top_level)
434 error ("global register variable follows a function definition");
435 if (TREE_THIS_VOLATILE (decl))
436 warning ("volatile register variables don't work as you might wish");
438 /* If the user specified one of the eliminables registers here,
439 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
440 confused with that register and be eliminated. Although this
441 usage is somewhat suspect, we nevertheless use the following
442 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
445 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
446 REGNO (DECL_RTL (decl)) = reg_number;
447 REG_USERVAR_P (DECL_RTL (decl)) = 1;
451 /* Make this register fixed, so not usable for anything else. */
452 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
454 global_regs[reg_number + --nregs] = 1;
459 /* Now handle ordinary static variables and functions (in memory).
460 Also handle vars declared register invalidly. */
461 if (DECL_RTL (decl) == 0)
463 /* Can't use just the variable's own name for a variable
464 whose scope is less than the whole file.
465 Concatenate a distinguishing number. */
466 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
470 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
471 name = obstack_copy0 (saveable_obstack, label, strlen (label));
475 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
476 gen_rtx (SYMBOL_REF, Pmode, name));
478 /* If this variable is to be treated as volatile, show its
479 tree node has side effects. If it has side effects, either
480 because of this test or from TREE_THIS_VOLATILE also
481 being set, show the MEM is volatile. */
482 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
483 && TREE_PUBLIC (decl))
484 TREE_SIDE_EFFECTS (decl) = 1;
485 if (TREE_SIDE_EFFECTS (decl))
486 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
488 if (TREE_READONLY (decl))
489 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
490 MEM_IN_STRUCT_P (DECL_RTL (decl))
491 = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
492 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
493 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
494 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE);
496 /* Optionally set flags or add text to the name to record information
497 such as that it is a function name.
498 If the name is changed, the macro ASM_OUTPUT_LABELREF
499 will have to know how to strip this information.
500 And if it finds a * at the beginning after doing so,
501 it must handle that too. */
502 #ifdef ENCODE_SECTION_INFO
503 ENCODE_SECTION_INFO (decl);
507 /* If the old RTL had the wrong mode, fix the mode. */
508 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
510 rtx rtl = DECL_RTL (decl);
511 PUT_MODE (rtl, DECL_MODE (decl));
515 /* Make the rtl for variable VAR be volatile.
516 Use this only for static variables. */
519 make_var_volatile (var)
522 if (GET_CODE (DECL_RTL (var)) != MEM)
525 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
528 /* Output alignment directive to align for constant expression EXP. */
531 assemble_constant_align (exp)
536 /* Align the location counter as required by EXP's data type. */
537 align = TYPE_ALIGN (TREE_TYPE (exp));
538 #ifdef CONSTANT_ALIGNMENT
539 align = CONSTANT_ALIGNMENT (exp, align);
542 if (align > BITS_PER_UNIT)
543 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
546 /* Output a string of literal assembler code
547 for an `asm' keyword used between functions. */
550 assemble_asm (string)
555 error ("asm statements not allowed in interpreter");
561 if (TREE_CODE (string) == ADDR_EXPR)
562 string = TREE_OPERAND (string, 0);
564 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
567 #if 0 /* This should no longer be needed, because
568 flag_gnu_linker should be 0 on these systems,
569 which should prevent any output
570 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
571 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
572 #ifndef ASM_OUTPUT_CONSTRUCTOR
573 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
575 #ifndef ASM_OUTPUT_DESTRUCTOR
576 #define ASM_OUTPUT_DESTRUCTOR(file, name)
581 /* Record an element in the table of global destructors.
582 How this is done depends on what sort of assembler and linker
585 NAME should be the name of a global function to be called
586 at exit time. This name is output using assemble_name. */
589 assemble_destructor (name)
592 #ifdef ASM_OUTPUT_DESTRUCTOR
593 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
597 /* Now tell GNU LD that this is part of the static destructor set. */
598 /* This code works for any machine provided you use GNU as/ld. */
599 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
600 assemble_name (asm_out_file, name);
601 fputc ('\n', asm_out_file);
606 /* Likewise for global constructors. */
609 assemble_constructor (name)
612 #ifdef ASM_OUTPUT_CONSTRUCTOR
613 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
617 /* Now tell GNU LD that this is part of the static constructor set. */
618 /* This code works for any machine provided you use GNU as/ld. */
619 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
620 assemble_name (asm_out_file, name);
621 fputc ('\n', asm_out_file);
626 /* Likewise for entries we want to record for garbage collection.
627 Garbage collection is still under development. */
630 assemble_gc_entry (name)
633 #ifdef ASM_OUTPUT_GC_ENTRY
634 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
638 /* Now tell GNU LD that this is part of the static constructor set. */
639 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
640 assemble_name (asm_out_file, name);
641 fputc ('\n', asm_out_file);
646 /* Output assembler code for the constant pool of a function and associated
647 with defining the name of the function. DECL describes the function.
648 NAME is the function's name. For the constant pool, we use the current
649 constant pool data. */
652 assemble_start_function (decl, fnname)
658 /* The following code does not need preprocessing in the assembler. */
662 output_constant_pool (fnname, decl);
667 /* Tell assembler to move to target machine's alignment for functions. */
668 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
672 BC_OUTPUT_ALIGN (asm_out_file, align);
674 ASM_OUTPUT_ALIGN (asm_out_file, align);
677 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
678 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
681 #ifdef SDB_DEBUGGING_INFO
682 /* Output SDB definition of the function. */
683 if (write_symbols == SDB_DEBUG)
684 sdbout_mark_begin_function ();
687 #ifdef DBX_DEBUGGING_INFO
688 /* Output DBX definition of the function. */
689 if (write_symbols == DBX_DEBUG)
690 dbxout_begin_function (decl);
693 /* Make function name accessible from other files, if appropriate. */
695 if (TREE_PUBLIC (decl))
697 if (!first_global_object_name)
698 STRIP_NAME_ENCODING (first_global_object_name, fnname);
700 BC_GLOBALIZE_LABEL (asm_out_file, fnname);
702 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
705 /* Do any machine/system dependent processing of the function name */
706 #ifdef ASM_DECLARE_FUNCTION_NAME
707 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
709 /* Standard thing is just output label for the function. */
711 BC_OUTPUT_LABEL (asm_out_file, fnname);
713 ASM_OUTPUT_LABEL (asm_out_file, fnname);
714 #endif /* ASM_DECLARE_FUNCTION_NAME */
717 /* Output assembler code associated with defining the size of the
718 function. DECL describes the function. NAME is the function's name. */
721 assemble_end_function (decl, fnname)
725 #ifdef ASM_DECLARE_FUNCTION_SIZE
726 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
730 /* Assemble code to leave SIZE bytes of zeros. */
733 assemble_zeros (size)
738 bc_emit_const_skip (size);
742 #ifdef ASM_NO_SKIP_IN_TEXT
743 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
744 so we must output 0s explicitly in the text section. */
745 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
749 for (i = 0; i < size - 20; i += 20)
752 fprintf (asm_out_file,
753 "%s 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ASM_BYTE_OP);
755 fprintf (asm_out_file,
756 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
762 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
764 fprintf (asm_out_file, "\tbyte 0");
767 for (; i < size; i++)
768 fprintf (asm_out_file, ",0");
769 fprintf (asm_out_file, "\n");
777 BC_OUTPUT_SKIP (asm_out_file, size);
779 ASM_OUTPUT_SKIP (asm_out_file, size);
783 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
786 assemble_align (align)
789 if (align > BITS_PER_UNIT)
790 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
793 /* Assemble a string constant with the specified C string as contents. */
796 assemble_string (p, size)
810 /* If the string is very long, split it up. */
814 int thissize = size - pos;
815 if (thissize > maximum)
819 bc_output_ascii (asm_out_file, p, thissize);
822 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
831 bc_output_ascii (file, p, size)
836 BC_OUTPUT_ASCII (file, p, size);
839 /* Assemble everything that is needed for a variable or function declaration.
840 Not used for automatic variables, and not used for function definitions.
841 Should not be called for variables of incomplete structure type.
843 TOP_LEVEL is nonzero if this variable has file scope.
844 AT_END is nonzero if this is the special handling, at end of compilation,
845 to define things that have had only tentative definitions.
846 DONT_OUTPUT_DATA if nonzero means don't actually output the
847 initial value (that will be done by the caller). */
850 assemble_variable (decl, top_level, at_end, dont_output_data)
859 enum in_section saved_in_section;
864 if (GET_CODE (DECL_RTL (decl)) == REG)
866 /* Do output symbol info for global register variables, but do nothing
869 if (TREE_ASM_WRITTEN (decl))
871 TREE_ASM_WRITTEN (decl) = 1;
873 if (!output_bytecode)
875 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
876 /* File-scope global variables are output here. */
877 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
879 dbxout_symbol (decl, 0);
881 #ifdef SDB_DEBUGGING_INFO
882 if (write_symbols == SDB_DEBUG && top_level
883 /* Leave initialized global vars for end of compilation;
884 see comment in compile_file. */
885 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
886 sdbout_symbol (decl, 0);
890 /* Don't output any DWARF debugging information for variables here.
891 In the case of local variables, the information for them is output
892 when we do our recursive traversal of the tree representation for
893 the entire containing function. In the case of file-scope variables,
894 we output information for all of them at the very end of compilation
895 while we are doing our final traversal of the chain of file-scope
901 /* Normally no need to say anything here for external references,
902 since assemble_external is called by the langauge-specific code
903 when a declaration is first seen. */
905 if (DECL_EXTERNAL (decl))
908 /* Output no assembler code for a function declaration.
909 Only definitions of functions output anything. */
911 if (TREE_CODE (decl) == FUNCTION_DECL)
914 /* If type was incomplete when the variable was declared,
915 see if it is complete now. */
917 if (DECL_SIZE (decl) == 0)
918 layout_decl (decl, 0);
920 /* Still incomplete => don't allocate it; treat the tentative defn
921 (which is what it must have been) as an `extern' reference. */
923 if (!dont_output_data && DECL_SIZE (decl) == 0)
925 error_with_file_and_line (DECL_SOURCE_FILE (decl),
926 DECL_SOURCE_LINE (decl),
927 "storage size of `%s' isn't known",
928 IDENTIFIER_POINTER (DECL_NAME (decl)));
932 /* The first declaration of a variable that comes through this function
933 decides whether it is global (in C, has external linkage)
934 or local (in C, has internal linkage). So do nothing more
935 if this function has already run. */
937 if (TREE_ASM_WRITTEN (decl))
940 TREE_ASM_WRITTEN (decl) = 1;
942 /* If storage size is erroneously variable, just continue.
943 Error message was already made. */
945 if (DECL_SIZE (decl))
947 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
952 /* This is better than explicit arithmetic, since it avoids overflow. */
953 size_tree = size_binop (CEIL_DIV_EXPR,
954 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
956 if (TREE_INT_CST_HIGH (size_tree) != 0)
958 error_with_decl (decl, "size of variable `%s' is too large");
963 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
965 /* Handle uninitialized definitions. */
967 /* ANSI specifies that a tentative definition which is not merged with
968 a non-tentative definition behaves exactly like a definition with an
969 initializer equal to zero. (Section 3.7.2)
970 -fno-common gives strict ANSI behavior. Usually you don't want it.
971 This matters only for variables with external linkage. */
972 if ((! flag_no_common || ! TREE_PUBLIC (decl))
973 && ! dont_output_data
974 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
976 int size = TREE_INT_CST_LOW (size_tree);
979 if (TREE_INT_CST_HIGH (size_tree) != 0)
980 error_with_decl (decl, "size of variable `%s' is too large");
981 /* Don't allocate zero bytes of common,
982 since that means "undefined external" in the linker. */
983 if (size == 0) rounded = 1;
984 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
985 so that each uninitialized object starts on such a boundary. */
986 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
987 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
988 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
990 #ifdef DBX_DEBUGGING_INFO
991 /* File-scope global variables are output here. */
992 if (write_symbols == DBX_DEBUG && top_level)
993 dbxout_symbol (decl, 0);
995 #ifdef SDB_DEBUGGING_INFO
996 if (write_symbols == SDB_DEBUG && top_level
997 /* Leave initialized global vars for end of compilation;
998 see comment in compile_file. */
999 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1000 sdbout_symbol (decl, 0);
1003 /* Don't output any DWARF debugging information for variables here.
1004 In the case of local variables, the information for them is output
1005 when we do our recursive traversal of the tree representation for
1006 the entire containing function. In the case of file-scope variables,
1007 we output information for all of them at the very end of compilation
1008 while we are doing our final traversal of the chain of file-scope
1012 if (flag_shared_data)
1015 if (TREE_PUBLIC (decl))
1017 #ifdef ASM_OUTPUT_SHARED_COMMON
1018 if (flag_shared_data)
1019 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1022 if (output_bytecode)
1024 BC_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1028 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1029 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1032 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1038 #ifdef ASM_OUTPUT_SHARED_LOCAL
1039 if (flag_shared_data)
1040 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1043 if (output_bytecode)
1045 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1049 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1050 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1053 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1060 /* Handle initialized definitions. */
1062 /* First make the assembler name(s) global if appropriate. */
1063 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1065 if (!first_global_object_name)
1066 STRIP_NAME_ENCODING(first_global_object_name, name);
1067 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1070 for (d = equivalents; d; d = TREE_CHAIN (d))
1072 tree e = TREE_VALUE (d);
1073 if (TREE_PUBLIC (e) && DECL_NAME (e))
1074 ASM_GLOBALIZE_LABEL (asm_out_file,
1075 XSTR (XEXP (DECL_RTL (e), 0), 0));
1079 /* Output any data that we will need to use the address of. */
1080 if (DECL_INITIAL (decl) == error_mark_node)
1081 reloc = contains_pointers_p (TREE_TYPE (decl));
1082 else if (DECL_INITIAL (decl))
1083 reloc = output_addressed_constants (DECL_INITIAL (decl));
1085 /* Switch to the proper section for this data. */
1086 #ifdef SELECT_SECTION
1087 SELECT_SECTION (decl, reloc);
1089 if (TREE_READONLY (decl)
1090 && ! TREE_THIS_VOLATILE (decl)
1091 && ! (flag_pic && reloc))
1092 readonly_data_section ();
1097 /* Record current section so we can restore it if dbxout.c clobbers it. */
1098 saved_in_section = in_section;
1100 /* Output the dbx info now that we have chosen the section. */
1102 #ifdef DBX_DEBUGGING_INFO
1103 /* File-scope global variables are output here. */
1104 if (write_symbols == DBX_DEBUG && top_level)
1105 dbxout_symbol (decl, 0);
1107 #ifdef SDB_DEBUGGING_INFO
1108 if (write_symbols == SDB_DEBUG && top_level
1109 /* Leave initialized global vars for end of compilation;
1110 see comment in compile_file. */
1111 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1112 sdbout_symbol (decl, 0);
1115 /* Don't output any DWARF debugging information for variables here.
1116 In the case of local variables, the information for them is output
1117 when we do our recursive traversal of the tree representation for
1118 the entire containing function. In the case of file-scope variables,
1119 we output information for all of them at the very end of compilation
1120 while we are doing our final traversal of the chain of file-scope
1123 if (in_section != saved_in_section)
1125 /* Switch to the proper section for this data. */
1126 #ifdef SELECT_SECTION
1127 SELECT_SECTION (decl, reloc);
1129 if (TREE_READONLY (decl)
1130 && ! TREE_THIS_VOLATILE (decl)
1131 && ! (flag_pic && reloc))
1132 readonly_data_section ();
1138 /* Compute and output the alignment of this data. */
1140 align = DECL_ALIGN (decl);
1141 /* In the case for initialing an array whose length isn't specified,
1142 where we have not yet been able to do the layout,
1143 figure out the proper alignment now. */
1144 if (dont_output_data && DECL_SIZE (decl) == 0
1145 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1146 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1148 /* Some object file formats have a maximum alignment which they support.
1149 In particular, a.out format supports a maximum alignment of 4. */
1150 #ifndef MAX_OFILE_ALIGNMENT
1151 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1153 if (align > MAX_OFILE_ALIGNMENT)
1155 warning_with_decl (decl,
1156 "alignment of `%s' is greater than maximum object file alignment");
1157 align = MAX_OFILE_ALIGNMENT;
1159 #ifdef DATA_ALIGNMENT
1160 /* On some machines, it is good to increase alignment sometimes. */
1161 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1163 #ifdef CONSTANT_ALIGNMENT
1164 if (DECL_INITIAL (decl))
1165 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1168 /* Reset the alignment in case we have made it tighter, so we can benefit
1169 from it in get_pointer_alignment. */
1170 DECL_ALIGN (decl) = align;
1172 if (align > BITS_PER_UNIT)
1174 if (output_bytecode)
1175 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1177 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1180 /* Do any machine/system dependent processing of the object. */
1181 #ifdef ASM_DECLARE_OBJECT_NAME
1182 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1184 /* Standard thing is just output label for the object. */
1185 if (output_bytecode)
1186 BC_OUTPUT_LABEL (asm_out_file, name);
1188 ASM_OUTPUT_LABEL (asm_out_file, name);
1189 #endif /* ASM_DECLARE_OBJECT_NAME */
1191 if (!dont_output_data)
1193 if (DECL_INITIAL (decl))
1194 /* Output the actual data. */
1195 output_constant (DECL_INITIAL (decl),
1196 int_size_in_bytes (TREE_TYPE (decl)));
1198 /* Leave space for it. */
1199 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1203 #ifdef XCOFF_DEBUGGING_INFO
1204 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1205 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1206 and `aa' hasn't been output yet, the assembler generates a stab entry with
1207 a value of zero, in addition to creating an unnecessary external entry
1208 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1210 /* File-scope global variables are output here. */
1211 if (write_symbols == XCOFF_DEBUG && top_level)
1213 saved_in_section = in_section;
1215 dbxout_symbol (decl, 0);
1217 if (in_section != saved_in_section)
1219 /* Switch to the proper section for this data. */
1220 #ifdef SELECT_SECTION
1221 SELECT_SECTION (decl, reloc);
1223 if (TREE_READONLY (decl)
1224 && ! TREE_THIS_VOLATILE (decl)
1225 && ! (flag_pic && reloc))
1226 readonly_data_section ();
1233 /* There must be a statement after a label. */
1238 /* Return 1 if type TYPE contains any pointers. */
1241 contains_pointers_p (type)
1244 switch (TREE_CODE (type))
1247 case REFERENCE_TYPE:
1248 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1249 so I'll play safe and return 1. */
1255 case QUAL_UNION_TYPE:
1258 /* For a type that has fields, see if the fields have pointers. */
1259 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1260 if (contains_pointers_p (TREE_TYPE (fields)))
1266 /* An array type contains pointers if its element type does. */
1267 return contains_pointers_p (TREE_TYPE (type));
1274 /* Output text storage for constructor CONSTR. Returns rtx of
1278 bc_output_constructor (constr)
1283 /* Must always be a literal; non-literal constructors are handled
1286 if (!TREE_CONSTANT (constr))
1293 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1295 BC_OUTPUT_ALIGN (asm_out_file, i);
1298 output_constant (constr, int_size_in_bytes (TREE_TYPE (constr)));
1302 /* Create storage for constructor CONSTR. */
1305 bc_output_data_constructor (constr)
1310 /* Put in data section */
1314 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1316 BC_OUTPUT_ALIGN (asm_out_file, i);
1318 /* The constructor is filled in at runtime. */
1319 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1323 /* Output something to declare an external symbol to the assembler.
1324 (Most assemblers don't need this, so we normally output nothing.)
1325 Do nothing if DECL is not external. */
1328 assemble_external (decl)
1331 if (output_bytecode)
1334 #ifdef ASM_OUTPUT_EXTERNAL
1335 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1336 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1338 rtx rtl = DECL_RTL (decl);
1340 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1341 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1343 /* Some systems do require some output. */
1344 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1345 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1351 /* Similar, for calling a library function FUN. */
1354 assemble_external_libcall (fun)
1357 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1358 if (!output_bytecode)
1360 /* Declare library function name external when first used, if nec. */
1361 if (! SYMBOL_REF_USED (fun))
1363 SYMBOL_REF_USED (fun) = 1;
1364 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1370 /* Declare the label NAME global. */
1373 assemble_global (name)
1376 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1379 /* Assemble a label named NAME. */
1382 assemble_label (name)
1385 if (output_bytecode)
1386 BC_OUTPUT_LABEL (asm_out_file, name);
1388 ASM_OUTPUT_LABEL (asm_out_file, name);
1391 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1392 If NAME starts with a *, the rest of NAME is output verbatim.
1393 Otherwise NAME is transformed in an implementation-defined way
1394 (usually by the addition of an underscore).
1395 Many macros in the tm file are defined to call this function. */
1398 assemble_name (file, name)
1404 if (output_bytecode)
1405 bc_emit_labelref (name);
1407 fputs (&name[1], file);
1411 if (output_bytecode)
1412 BC_OUTPUT_LABELREF (file, name);
1414 ASM_OUTPUT_LABELREF (file, name);
1418 /* Allocate SIZE bytes writable static space with a gensym name
1419 and return an RTX to refer to its address. */
1422 assemble_static_space (size)
1428 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1429 so that each uninitialized object starts on such a boundary. */
1430 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1431 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1432 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1435 if (flag_shared_data)
1439 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1442 namestring = (char *) obstack_alloc (saveable_obstack,
1444 strcpy (namestring, name);
1446 if (output_bytecode)
1447 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1449 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1451 if (output_bytecode)
1453 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1457 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1458 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1460 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1466 /* Assemble the static constant template for function entry trampolines.
1467 This is done at most once per compilation.
1468 Returns an RTX for the address of the template. */
1471 assemble_trampoline_template ()
1477 /* Shouldn't get here */
1478 if (output_bytecode)
1481 /* By default, put trampoline templates in read-only data section. */
1483 #ifdef TRAMPOLINE_SECTION
1484 TRAMPOLINE_SECTION ();
1486 readonly_data_section ();
1489 /* Write the assembler code to define one. */
1490 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1492 ASM_OUTPUT_ALIGN (asm_out_file, align);
1494 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1495 TRAMPOLINE_TEMPLATE (asm_out_file);
1497 /* Record the rtl to refer to it. */
1498 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1500 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1501 return gen_rtx (SYMBOL_REF, Pmode, name);
1504 /* Assemble the integer constant X into an object of SIZE bytes.
1505 X must be either a CONST_INT or CONST_DOUBLE.
1507 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1508 non-zero, abort if we can't output the constant. */
1511 assemble_integer (x, size, force)
1516 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1517 ASM_OUTPUT... macros. */
1521 #ifdef ASM_OUTPUT_CHAR
1523 ASM_OUTPUT_CHAR (asm_out_file, x);
1527 #ifdef ASM_OUTPUT_SHORT
1529 ASM_OUTPUT_SHORT (asm_out_file, x);
1533 #ifdef ASM_OUTPUT_INT
1535 ASM_OUTPUT_INT (asm_out_file, x);
1539 #ifdef ASM_OUTPUT_DOUBLE_INT
1541 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1545 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1547 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1552 /* If we couldn't do it that way, there are two other possibilities: First,
1553 if the machine can output an explicit byte and this is a 1 byte constant,
1554 we can use ASM_OUTPUT_BYTE. */
1556 #ifdef ASM_OUTPUT_BYTE
1557 if (size == 1 && GET_CODE (x) == CONST_INT)
1559 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1564 /* Finally, if SIZE is larger than a single word, try to output the constant
1565 one word at a time. */
1567 if (size > UNITS_PER_WORD)
1570 enum machine_mode mode
1571 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1574 for (i = 0; i < size / UNITS_PER_WORD; i++)
1576 word = operand_subword (x, i, 0, mode);
1581 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1585 if (i == size / UNITS_PER_WORD)
1587 /* If we output at least one word and then could not finish,
1588 there is no valid way to continue. */
1599 /* Assemble the floating-point constant D into an object of size MODE. */
1602 assemble_real (d, mode)
1604 enum machine_mode mode;
1606 jmp_buf output_constant_handler;
1608 if (setjmp (output_constant_handler))
1610 error ("floating point trap outputting a constant");
1611 #ifdef REAL_IS_NOT_DOUBLE
1612 bzero (&d, sizeof d);
1619 set_float_handler (output_constant_handler);
1623 #ifdef ASM_OUTPUT_BYTE_FLOAT
1625 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1628 #ifdef ASM_OUTPUT_SHORT_FLOAT
1630 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1633 #ifdef ASM_OUTPUT_FLOAT
1635 ASM_OUTPUT_FLOAT (asm_out_file, d);
1639 #ifdef ASM_OUTPUT_DOUBLE
1641 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1645 #ifdef ASM_OUTPUT_LONG_DOUBLE
1648 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1656 set_float_handler (NULL_PTR);
1659 /* Here we combine duplicate floating constants to make
1660 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1662 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1663 They are chained through the CONST_DOUBLE_CHAIN.
1664 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1665 In that case, CONST_DOUBLE_MEM is either a MEM,
1666 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1668 (CONST_DOUBLE_MEM is used only for top-level functions.
1669 See force_const_mem for explanation.) */
1671 static rtx const_double_chain;
1673 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1674 For an integer, I0 is the low-order word and I1 is the high-order word.
1675 For a real number, I0 is the word with the low address
1676 and I1 is the word with the high address. */
1679 immed_double_const (i0, i1, mode)
1680 HOST_WIDE_INT i0, i1;
1681 enum machine_mode mode;
1684 int in_current_obstack;
1686 if (GET_MODE_CLASS (mode) == MODE_INT
1687 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1689 /* We clear out all bits that don't belong in MODE, unless they and our
1690 sign bit are all one. So we get either a reasonable negative value
1691 or a reasonable unsigned value for this mode. */
1692 int width = GET_MODE_BITSIZE (mode);
1693 if (width < HOST_BITS_PER_WIDE_INT
1694 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1695 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1696 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1697 else if (width == HOST_BITS_PER_WIDE_INT
1698 && ! (i1 == ~0 && i0 < 0))
1700 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1701 /* We cannot represent this value as a constant. */
1704 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1706 ??? Strictly speaking, this is wrong if we create a CONST_INT
1707 for a large unsigned constant with the size of MODE being
1708 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1709 wider mode. In that case we will mis-interpret it as a negative
1712 Unfortunately, the only alternative is to make a CONST_DOUBLE
1713 for any constant in any mode if it is an unsigned constant larger
1714 than the maximum signed integer in an int on the host. However,
1715 doing this will break everyone that always expects to see a CONST_INT
1716 for SImode and smaller.
1718 We have always been making CONST_INTs in this case, so nothing new
1721 if (width <= HOST_BITS_PER_WIDE_INT)
1722 i1 = (i0 < 0) ? ~0 : 0;
1724 /* If this integer fits in one word, return a CONST_INT. */
1725 if ((i1 == 0 && i0 >= 0)
1726 || (i1 == ~0 && i0 < 0))
1727 return GEN_INT (i0);
1729 /* We use VOIDmode for integers. */
1733 /* Search the chain for an existing CONST_DOUBLE with the right value.
1734 If one is found, return it. */
1736 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1737 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1738 && GET_MODE (r) == mode)
1741 /* No; make a new one and add it to the chain.
1743 We may be called by an optimizer which may be discarding any memory
1744 allocated during its processing (such as combine and loop). However,
1745 we will be leaving this constant on the chain, so we cannot tolerate
1746 freed memory. So switch to saveable_obstack for this allocation
1747 and then switch back if we were in current_obstack. */
1749 push_obstacks_nochange ();
1750 rtl_in_saveable_obstack ();
1751 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1754 /* Don't touch const_double_chain in nested function; see force_const_mem.
1755 Also, don't touch it if not inside any function. */
1756 if (outer_function_chain == 0 && current_function_decl != 0)
1758 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1759 const_double_chain = r;
1762 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1763 Actual use of mem-slot is only through force_const_mem. */
1765 CONST_DOUBLE_MEM (r) = const0_rtx;
1770 /* Return a CONST_DOUBLE for a specified `double' value
1771 and machine mode. */
1774 immed_real_const_1 (d, mode)
1776 enum machine_mode mode;
1778 union real_extract u;
1780 int in_current_obstack;
1782 /* Get the desired `double' value as a sequence of ints
1783 since that is how they are stored in a CONST_DOUBLE. */
1787 /* Detect special cases. */
1789 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1790 if (!bcmp (&dconst0, &d, sizeof d))
1791 return CONST0_RTX (mode);
1792 /* Check for NaN first, because some ports (specifically the i386) do not
1793 emit correct ieee-fp code by default, and thus will generate a core
1794 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1795 does a floating point comparison. */
1796 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1797 return CONST1_RTX (mode);
1799 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1800 return immed_double_const (u.i[0], u.i[1], mode);
1802 /* The rest of this function handles the case where
1803 a float value requires more than 2 ints of space.
1804 It will be deleted as dead code on machines that don't need it. */
1806 /* Search the chain for an existing CONST_DOUBLE with the right value.
1807 If one is found, return it. */
1809 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1810 if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
1811 && GET_MODE (r) == mode)
1814 /* No; make a new one and add it to the chain.
1816 We may be called by an optimizer which may be discarding any memory
1817 allocated during its processing (such as combine and loop). However,
1818 we will be leaving this constant on the chain, so we cannot tolerate
1819 freed memory. So switch to saveable_obstack for this allocation
1820 and then switch back if we were in current_obstack. */
1822 push_obstacks_nochange ();
1823 rtl_in_saveable_obstack ();
1824 r = rtx_alloc (CONST_DOUBLE);
1826 bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
1829 /* Don't touch const_double_chain in nested function; see force_const_mem.
1830 Also, don't touch it if not inside any function. */
1831 if (outer_function_chain == 0 && current_function_decl != 0)
1833 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1834 const_double_chain = r;
1837 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1838 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1839 is only through force_const_mem. */
1841 CONST_DOUBLE_MEM (r) = const0_rtx;
1846 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1847 which must be a REAL_CST tree node. */
1850 immed_real_const (exp)
1853 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1856 /* At the end of a function, forget the memory-constants
1857 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1858 Also clear out real_constant_chain and clear out all the chain-pointers. */
1861 clear_const_double_mem ()
1863 register rtx r, next;
1865 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1866 See force_const_mem for explanation. */
1867 if (outer_function_chain != 0)
1870 for (r = const_double_chain; r; r = next)
1872 next = CONST_DOUBLE_CHAIN (r);
1873 CONST_DOUBLE_CHAIN (r) = 0;
1874 CONST_DOUBLE_MEM (r) = cc0_rtx;
1876 const_double_chain = 0;
1879 /* Given an expression EXP with a constant value,
1880 reduce it to the sum of an assembler symbol and an integer.
1881 Store them both in the structure *VALUE.
1882 Abort if EXP does not reduce. */
1887 HOST_WIDE_INT offset;
1891 decode_addr_const (exp, value)
1893 struct addr_const *value;
1895 register tree target = TREE_OPERAND (exp, 0);
1896 register int offset = 0;
1901 if (TREE_CODE (target) == COMPONENT_REF
1902 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
1905 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
1906 target = TREE_OPERAND (target, 0);
1908 else if (TREE_CODE (target) == ARRAY_REF)
1910 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
1911 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
1913 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
1914 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
1916 target = TREE_OPERAND (target, 0);
1922 switch (TREE_CODE (target))
1926 x = DECL_RTL (target);
1930 if (output_bytecode)
1931 /* FIXME: this may not be correct, check it */
1932 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
1934 x = gen_rtx (MEM, FUNCTION_MODE,
1935 gen_rtx (LABEL_REF, VOIDmode,
1936 label_rtx (TREE_OPERAND (exp, 0))));
1943 x = TREE_CST_RTL (target);
1950 if (!output_bytecode)
1952 if (GET_CODE (x) != MEM)
1958 value->offset = offset;
1961 /* Uniquize all constants that appear in memory.
1962 Each constant in memory thus far output is recorded
1963 in `const_hash_table' with a `struct constant_descriptor'
1964 that contains a polish representation of the value of
1967 We cannot store the trees in the hash table
1968 because the trees may be temporary. */
1970 struct constant_descriptor
1972 struct constant_descriptor *next;
1978 #define MAX_HASH_TABLE 1009
1979 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
1981 /* Compute a hash code for a constant expression. */
1988 register int len, hi, i;
1989 register enum tree_code code = TREE_CODE (exp);
1991 if (code == INTEGER_CST)
1993 p = (char *) &TREE_INT_CST_LOW (exp);
1994 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1996 else if (code == REAL_CST)
1998 p = (char *) &TREE_REAL_CST (exp);
1999 len = sizeof TREE_REAL_CST (exp);
2001 else if (code == STRING_CST)
2002 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2003 else if (code == COMPLEX_CST)
2004 return const_hash (TREE_REALPART (exp)) * 5
2005 + const_hash (TREE_IMAGPART (exp));
2006 else if (code == CONSTRUCTOR)
2010 /* For record type, include the type in the hashing.
2011 We do not do so for array types
2012 because (1) the sizes of the elements are sufficient
2013 and (2) distinct array types can have the same constructor.
2014 Instead, we include the array size because the constructor could
2016 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2017 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2020 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2021 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2023 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2024 if (TREE_VALUE (link))
2025 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2029 else if (code == ADDR_EXPR)
2031 struct addr_const value;
2032 decode_addr_const (exp, &value);
2033 if (GET_CODE (value.base) == SYMBOL_REF)
2035 /* Don't hash the address of the SYMBOL_REF;
2036 only use the offset and the symbol name. */
2038 p = XSTR (value.base, 0);
2039 for (i = 0; p[i] != 0; i++)
2040 hi = ((hi * 613) + (unsigned)(p[i]));
2042 else if (GET_CODE (value.base) == LABEL_REF)
2043 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2045 hi &= (1 << HASHBITS) - 1;
2046 hi %= MAX_HASH_TABLE;
2049 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2050 return const_hash (TREE_OPERAND (exp, 0)) * 9
2051 + const_hash (TREE_OPERAND (exp, 1));
2052 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2053 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2055 /* Compute hashing function */
2057 for (i = 0; i < len; i++)
2058 hi = ((hi * 613) + (unsigned)(p[i]));
2060 hi &= (1 << HASHBITS) - 1;
2061 hi %= MAX_HASH_TABLE;
2065 /* Compare a constant expression EXP with a constant-descriptor DESC.
2066 Return 1 if DESC describes a constant with the same value as EXP. */
2069 compare_constant (exp, desc)
2071 struct constant_descriptor *desc;
2073 return 0 != compare_constant_1 (exp, desc->contents);
2076 /* Compare constant expression EXP with a substring P of a constant descriptor.
2077 If they match, return a pointer to the end of the substring matched.
2078 If they do not match, return 0.
2080 Since descriptors are written in polish prefix notation,
2081 this function can be used recursively to test one operand of EXP
2082 against a subdescriptor, and if it succeeds it returns the
2083 address of the subdescriptor for the next operand. */
2086 compare_constant_1 (exp, p)
2090 register char *strp;
2092 register enum tree_code code = TREE_CODE (exp);
2094 if (code != (enum tree_code) *p++)
2097 if (code == INTEGER_CST)
2099 /* Integer constants are the same only if the same width of type. */
2100 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2102 strp = (char *) &TREE_INT_CST_LOW (exp);
2103 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2105 else if (code == REAL_CST)
2107 /* Real constants are the same only if the same width of type. */
2108 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2110 strp = (char *) &TREE_REAL_CST (exp);
2111 len = sizeof TREE_REAL_CST (exp);
2113 else if (code == STRING_CST)
2115 if (flag_writable_strings)
2117 strp = TREE_STRING_POINTER (exp);
2118 len = TREE_STRING_LENGTH (exp);
2119 if (bcmp (&TREE_STRING_LENGTH (exp), p,
2120 sizeof TREE_STRING_LENGTH (exp)))
2122 p += sizeof TREE_STRING_LENGTH (exp);
2124 else if (code == COMPLEX_CST)
2126 p = compare_constant_1 (TREE_REALPART (exp), p);
2127 if (p == 0) return 0;
2128 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2131 else if (code == CONSTRUCTOR)
2134 int length = list_length (CONSTRUCTOR_ELTS (exp));
2137 if (bcmp (&length, p, sizeof length))
2141 /* For record constructors, insist that the types match.
2142 For arrays, just verify both constructors are for arrays. */
2143 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2144 type = TREE_TYPE (exp);
2147 if (bcmp (&type, p, sizeof type))
2151 /* For arrays, insist that the size in bytes match. */
2152 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2154 int size = int_size_in_bytes (TREE_TYPE (exp));
2155 if (bcmp (&size, p, sizeof size))
2160 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2162 if (TREE_VALUE (link))
2164 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2171 if (bcmp (&zero, p, sizeof zero))
2179 else if (code == ADDR_EXPR)
2181 struct addr_const value;
2182 decode_addr_const (exp, &value);
2183 strp = (char *) &value.offset;
2184 len = sizeof value.offset;
2185 /* Compare the offset. */
2187 if (*p++ != *strp++)
2189 /* Compare symbol name. */
2190 strp = XSTR (value.base, 0);
2191 len = strlen (strp) + 1;
2193 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2195 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2196 if (p == 0) return 0;
2197 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2200 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2202 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2206 /* Compare constant contents. */
2208 if (*p++ != *strp++)
2214 /* Construct a constant descriptor for the expression EXP.
2215 It is up to the caller to enter the descriptor in the hash table. */
2217 static struct constant_descriptor *
2218 record_constant (exp)
2221 struct constant_descriptor *next = 0;
2224 /* Make a struct constant_descriptor. The first two pointers will
2225 be filled in later. Here we just leave space for them. */
2227 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2228 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2229 record_constant_1 (exp);
2230 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2233 /* Add a description of constant expression EXP
2234 to the object growing in `permanent_obstack'.
2235 No need to return its address; the caller will get that
2236 from the obstack when the object is complete. */
2239 record_constant_1 (exp)
2242 register char *strp;
2244 register enum tree_code code = TREE_CODE (exp);
2246 obstack_1grow (&permanent_obstack, (unsigned int) code);
2248 if (code == INTEGER_CST)
2250 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2251 strp = (char *) &TREE_INT_CST_LOW (exp);
2252 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2254 else if (code == REAL_CST)
2256 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2257 strp = (char *) &TREE_REAL_CST (exp);
2258 len = sizeof TREE_REAL_CST (exp);
2260 else if (code == STRING_CST)
2262 if (flag_writable_strings)
2264 strp = TREE_STRING_POINTER (exp);
2265 len = TREE_STRING_LENGTH (exp);
2266 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2267 sizeof TREE_STRING_LENGTH (exp));
2269 else if (code == COMPLEX_CST)
2271 record_constant_1 (TREE_REALPART (exp));
2272 record_constant_1 (TREE_IMAGPART (exp));
2275 else if (code == CONSTRUCTOR)
2278 int length = list_length (CONSTRUCTOR_ELTS (exp));
2281 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2283 /* For record constructors, insist that the types match.
2284 For arrays, just verify both constructors are for arrays. */
2285 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2286 type = TREE_TYPE (exp);
2289 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2291 /* For arrays, insist that the size in bytes match. */
2292 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2294 int size = int_size_in_bytes (TREE_TYPE (exp));
2295 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2298 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2300 if (TREE_VALUE (link))
2301 record_constant_1 (TREE_VALUE (link));
2306 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
2312 else if (code == ADDR_EXPR)
2314 struct addr_const value;
2315 decode_addr_const (exp, &value);
2316 /* Record the offset. */
2317 obstack_grow (&permanent_obstack,
2318 (char *) &value.offset, sizeof value.offset);
2319 /* Record the symbol name. */
2320 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2321 strlen (XSTR (value.base, 0)) + 1);
2324 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2326 record_constant_1 (TREE_OPERAND (exp, 0));
2327 record_constant_1 (TREE_OPERAND (exp, 1));
2330 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2332 record_constant_1 (TREE_OPERAND (exp, 0));
2336 /* Record constant contents. */
2337 obstack_grow (&permanent_obstack, strp, len);
2340 /* Record a list of constant expressions that were passed to
2341 output_constant_def but that could not be output right away. */
2343 struct deferred_constant
2345 struct deferred_constant *next;
2351 static struct deferred_constant *deferred_constants;
2353 /* Nonzero means defer output of addressed subconstants
2354 (i.e., those for which output_constant_def is called.) */
2355 static int defer_addressed_constants_flag;
2357 /* Start deferring output of subconstants. */
2360 defer_addressed_constants ()
2362 defer_addressed_constants_flag++;
2365 /* Stop deferring output of subconstants,
2366 and output now all those that have been deferred. */
2369 output_deferred_addressed_constants ()
2371 struct deferred_constant *p, *next;
2373 defer_addressed_constants_flag--;
2375 if (defer_addressed_constants_flag > 0)
2378 for (p = deferred_constants; p; p = next)
2380 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2385 deferred_constants = 0;
2388 /* Return an rtx representing a reference to constant data in memory
2389 for the constant expression EXP.
2391 If assembler code for such a constant has already been output,
2392 return an rtx to refer to it.
2393 Otherwise, output such a constant in memory (or defer it for later)
2394 and generate an rtx for it.
2396 The TREE_CST_RTL of EXP is set up to point to that rtx.
2397 The const_hash_table records which constants already have label strings. */
2400 output_constant_def (exp)
2404 register struct constant_descriptor *desc;
2410 if (TREE_CODE (exp) == INTEGER_CST)
2411 abort (); /* No TREE_CST_RTL slot in these. */
2413 if (TREE_CST_RTL (exp))
2414 return TREE_CST_RTL (exp);
2416 /* Make sure any other constants whose addresses appear in EXP
2417 are assigned label numbers. */
2419 reloc = output_addressed_constants (exp);
2421 /* Compute hash code of EXP. Search the descriptors for that hash code
2422 to see if any of them describes EXP. If yes, the descriptor records
2423 the label number already assigned. */
2425 if (!output_bytecode)
2427 hash = const_hash (exp) % MAX_HASH_TABLE;
2429 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2430 if (compare_constant (exp, desc))
2432 found = desc->label;
2438 /* No constant equal to EXP is known to have been output.
2439 Make a constant descriptor to enter EXP in the hash table.
2440 Assign the label number and record it in the descriptor for
2441 future calls to this function to find. */
2443 /* Create a string containing the label name, in LABEL. */
2444 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2446 desc = record_constant (exp);
2447 desc->next = const_hash_table[hash];
2449 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2450 const_hash_table[hash] = desc;
2454 /* Create a string containing the label name, in LABEL. */
2455 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2459 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2461 push_obstacks_nochange ();
2462 if (TREE_PERMANENT (exp))
2463 end_temporary_allocation ();
2465 if (!output_bytecode)
2467 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2470 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2471 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2472 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
2473 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2474 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2478 /* Optionally set flags or add text to the name to record information
2479 such as that it is a function name. If the name is changed, the macro
2480 ASM_OUTPUT_LABELREF will have to know how to strip this information.
2481 And if it finds a * at the beginning after doing so, it must handle
2483 #ifdef ENCODE_SECTION_INFO
2484 ENCODE_SECTION_INFO (exp);
2487 /* If this is the first time we've seen this particular constant,
2488 output it (or defer its output for later). */
2491 if (defer_addressed_constants_flag)
2493 struct deferred_constant *p;
2494 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2496 /* We really should copy trees in depth here,
2497 but since this case is the only one that should happen now,
2498 let's do it later. */
2499 if (TREE_CODE (exp) != STRING_CST)
2502 push_obstacks_nochange ();
2503 suspend_momentary ();
2504 p->exp = copy_node (exp);
2507 p->labelno = const_labelno++;
2508 p->next = deferred_constants;
2509 deferred_constants = p;
2512 output_constant_def_contents (exp, reloc, const_labelno++);
2515 return TREE_CST_RTL (exp);
2518 /* Now output assembler code to define the label for EXP,
2519 and follow it with the data of EXP. */
2522 output_constant_def_contents (exp, reloc, labelno)
2529 /* First switch to text section, except for writable strings. */
2530 #ifdef SELECT_SECTION
2531 SELECT_SECTION (exp, reloc);
2533 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2534 || (flag_pic && reloc))
2537 readonly_data_section ();
2540 /* Align the location counter as required by EXP's data type. */
2541 align = TYPE_ALIGN (TREE_TYPE (exp));
2542 #ifdef CONSTANT_ALIGNMENT
2543 align = CONSTANT_ALIGNMENT (exp, align);
2546 if (align > BITS_PER_UNIT)
2548 if (!output_bytecode)
2550 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2554 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2558 /* Output the label itself. */
2559 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2561 /* Output the value of EXP. */
2562 output_constant (exp,
2563 (TREE_CODE (exp) == STRING_CST
2564 ? TREE_STRING_LENGTH (exp)
2565 : int_size_in_bytes (TREE_TYPE (exp))));
2569 /* Similar hash facility for making memory-constants
2570 from constant rtl-expressions. It is used on RISC machines
2571 where immediate integer arguments and constant addresses are restricted
2572 so that such constants must be stored in memory.
2574 This pool of constants is reinitialized for each function
2575 so each function gets its own constants-pool that comes right before it.
2577 All structures allocated here are discarded when functions are saved for
2578 inlining, so they do not need to be allocated permanently. */
2580 #define MAX_RTX_HASH_TABLE 61
2581 static struct constant_descriptor **const_rtx_hash_table;
2583 /* Structure to represent sufficient information about a constant so that
2584 it can be output when the constant pool is output, so that function
2585 integration can be done, and to simplify handling on machines that reference
2586 constant pool as base+displacement. */
2588 struct pool_constant
2590 struct constant_descriptor *desc;
2591 struct pool_constant *next;
2592 enum machine_mode mode;
2599 /* Pointers to first and last constant in pool. */
2601 static struct pool_constant *first_pool, *last_pool;
2603 /* Current offset in constant pool (does not include any machine-specific
2606 static int pool_offset;
2608 /* Structure used to maintain hash table mapping symbols used to their
2609 corresponding constants. */
2614 struct pool_constant *pool;
2615 struct pool_sym *next;
2618 static struct pool_sym **const_rtx_sym_hash_table;
2620 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2621 The argument is XSTR (... , 0) */
2623 #define SYMHASH(LABEL) \
2624 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2626 /* Initialize constant pool hashing for next function. */
2629 init_const_rtx_hash_table ()
2631 const_rtx_hash_table
2632 = ((struct constant_descriptor **)
2633 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2634 const_rtx_sym_hash_table
2635 = ((struct pool_sym **)
2636 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2637 bzero (const_rtx_hash_table,
2638 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2639 bzero (const_rtx_sym_hash_table,
2640 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2642 first_pool = last_pool = 0;
2646 /* Save and restore it for a nested function. */
2649 save_varasm_status (p)
2652 p->const_rtx_hash_table = const_rtx_hash_table;
2653 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2654 p->first_pool = first_pool;
2655 p->last_pool = last_pool;
2656 p->pool_offset = pool_offset;
2660 restore_varasm_status (p)
2663 const_rtx_hash_table = p->const_rtx_hash_table;
2664 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2665 first_pool = p->first_pool;
2666 last_pool = p->last_pool;
2667 pool_offset = p->pool_offset;
2670 enum kind { RTX_DOUBLE, RTX_INT };
2674 #ifdef ONLY_INT_FIELDS
2675 unsigned int kind : 16;
2676 unsigned int mode : 16;
2678 enum kind kind : 16;
2679 enum machine_mode mode : 16;
2682 union real_extract du;
2683 struct addr_const addr;
2687 /* Express an rtx for a constant integer (perhaps symbolic)
2688 as the sum of a symbol or label plus an explicit integer.
2689 They are stored into VALUE. */
2692 decode_rtx_const (mode, x, value)
2693 enum machine_mode mode;
2695 struct rtx_const *value;
2697 /* Clear the whole structure, including any gaps. */
2700 int *p = (int *) value;
2701 int *end = (int *) (value + 1);
2706 value->kind = RTX_INT; /* Most usual kind. */
2709 switch (GET_CODE (x))
2712 value->kind = RTX_DOUBLE;
2713 if (GET_MODE (x) != VOIDmode)
2714 value->mode = GET_MODE (x);
2715 bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
2719 value->un.addr.offset = INTVAL (x);
2725 value->un.addr.base = x;
2730 if (GET_CODE (x) == PLUS)
2732 value->un.addr.base = XEXP (x, 0);
2733 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2735 value->un.addr.offset = INTVAL (XEXP (x, 1));
2737 else if (GET_CODE (x) == MINUS)
2739 value->un.addr.base = XEXP (x, 0);
2740 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2742 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2752 if (value->kind == RTX_INT && value->un.addr.base != 0)
2753 switch (GET_CODE (value->un.addr.base))
2757 /* Use the string's address, not the SYMBOL_REF's address,
2758 for the sake of addresses of library routines.
2759 For a LABEL_REF, compare labels. */
2760 value->un.addr.base = XEXP (value->un.addr.base, 0);
2764 /* Given a MINUS expression, simplify it if both sides
2765 include the same symbol. */
2768 simplify_subtraction (x)
2771 struct rtx_const val0, val1;
2773 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2774 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2776 if (val0.un.addr.base == val1.un.addr.base)
2777 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2781 /* Compute a hash code for a constant RTL expression. */
2784 const_hash_rtx (mode, x)
2785 enum machine_mode mode;
2790 struct rtx_const value;
2791 decode_rtx_const (mode, x, &value);
2793 /* Compute hashing function */
2795 for (i = 0; i < sizeof value / sizeof (int); i++)
2796 hi += ((int *) &value)[i];
2798 hi &= (1 << HASHBITS) - 1;
2799 hi %= MAX_RTX_HASH_TABLE;
2803 /* Compare a constant rtl object X with a constant-descriptor DESC.
2804 Return 1 if DESC describes a constant with the same value as X. */
2807 compare_constant_rtx (mode, x, desc)
2808 enum machine_mode mode;
2810 struct constant_descriptor *desc;
2812 register int *p = (int *) desc->contents;
2815 struct rtx_const value;
2817 decode_rtx_const (mode, x, &value);
2818 strp = (int *) &value;
2819 len = sizeof value / sizeof (int);
2821 /* Compare constant contents. */
2823 if (*p++ != *strp++)
2829 /* Construct a constant descriptor for the rtl-expression X.
2830 It is up to the caller to enter the descriptor in the hash table. */
2832 static struct constant_descriptor *
2833 record_constant_rtx (mode, x)
2834 enum machine_mode mode;
2837 struct constant_descriptor *ptr;
2839 struct rtx_const value;
2841 decode_rtx_const (mode, x, &value);
2843 obstack_grow (current_obstack, &ptr, sizeof ptr);
2844 obstack_grow (current_obstack, &label, sizeof label);
2846 /* Record constant contents. */
2847 obstack_grow (current_obstack, &value, sizeof value);
2849 return (struct constant_descriptor *) obstack_finish (current_obstack);
2852 /* Given a constant rtx X, make (or find) a memory constant for its value
2853 and return a MEM rtx to refer to it in memory. */
2856 force_const_mem (mode, x)
2857 enum machine_mode mode;
2861 register struct constant_descriptor *desc;
2866 /* If we want this CONST_DOUBLE in the same mode as it is in memory
2867 (this will always be true for floating CONST_DOUBLEs that have been
2868 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
2869 use the previous copy. Otherwise, make a new one. Note that in
2870 the unlikely event that this same CONST_DOUBLE is used in two different
2871 modes in an alternating fashion, we will allocate a lot of different
2872 memory locations, but this should be extremely rare. */
2874 /* Don't use CONST_DOUBLE_MEM in a nested function.
2875 Nested functions have their own constant pools,
2876 so they can't share the same values in CONST_DOUBLE_MEM
2877 with the containing function. */
2878 if (outer_function_chain == 0)
2879 if (GET_CODE (x) == CONST_DOUBLE
2880 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
2881 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
2882 return CONST_DOUBLE_MEM (x);
2884 /* Compute hash code of X. Search the descriptors for that hash code
2885 to see if any of them describes X. If yes, the descriptor records
2886 the label number already assigned. */
2888 hash = const_hash_rtx (mode, x);
2890 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
2891 if (compare_constant_rtx (mode, x, desc))
2893 found = desc->label;
2899 register struct pool_constant *pool;
2900 register struct pool_sym *sym;
2903 /* No constant equal to X is known to have been output.
2904 Make a constant descriptor to enter X in the hash table.
2905 Assign the label number and record it in the descriptor for
2906 future calls to this function to find. */
2908 desc = record_constant_rtx (mode, x);
2909 desc->next = const_rtx_hash_table[hash];
2910 const_rtx_hash_table[hash] = desc;
2912 /* Align the location counter as required by EXP's data type. */
2913 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
2914 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2915 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
2917 pool_offset += align - 1;
2918 pool_offset &= ~ (align - 1);
2920 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
2922 pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
2926 pool->labelno = const_labelno;
2927 pool->align = align;
2928 pool->offset = pool_offset;
2934 last_pool->next = pool;
2937 pool_offset += GET_MODE_SIZE (mode);
2939 /* Create a string containing the label name, in LABEL. */
2940 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2945 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
2947 /* Add label to symbol hash table. */
2948 hash = SYMHASH (found);
2949 sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
2952 sym->next = const_rtx_sym_hash_table[hash];
2953 const_rtx_sym_hash_table[hash] = sym;
2956 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2958 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
2960 RTX_UNCHANGING_P (def) = 1;
2961 /* Mark the symbol_ref as belonging to this constants pool. */
2962 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
2963 current_function_uses_const_pool = 1;
2965 if (outer_function_chain == 0)
2966 if (GET_CODE (x) == CONST_DOUBLE)
2968 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
2970 CONST_DOUBLE_CHAIN (x) = const_double_chain;
2971 const_double_chain = x;
2973 CONST_DOUBLE_MEM (x) = def;
2979 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
2980 the corresponding pool_constant structure. */
2982 static struct pool_constant *
2983 find_pool_constant (addr)
2986 struct pool_sym *sym;
2987 char *label = XSTR (addr, 0);
2989 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
2990 if (sym->label == label)
2996 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
2999 get_pool_constant (addr)
3002 return (find_pool_constant (addr))->constant;
3005 /* Similar, return the mode. */
3008 get_pool_mode (addr)
3011 return (find_pool_constant (addr))->mode;
3014 /* Similar, return the offset in the constant pool. */
3017 get_pool_offset (addr)
3020 return (find_pool_constant (addr))->offset;
3023 /* Return the size of the constant pool. */
3031 /* Write all the constants in the constant pool. */
3034 output_constant_pool (fnname, fndecl)
3038 struct pool_constant *pool;
3040 union real_extract u;
3042 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3043 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3046 for (pool = first_pool; pool; pool = pool->next)
3050 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3051 whose CODE_LABEL has been deleted. This can occur if a jump table
3052 is eliminated by optimization. If so, write a constant of zero
3053 instead. Note that this can also happen by turning the
3054 CODE_LABEL into a NOTE. */
3055 if (((GET_CODE (x) == LABEL_REF
3056 && (INSN_DELETED_P (XEXP (x, 0))
3057 || GET_CODE (XEXP (x, 0)) == NOTE)))
3058 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3059 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3060 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3061 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3064 /* First switch to correct section. */
3065 #ifdef SELECT_RTX_SECTION
3066 SELECT_RTX_SECTION (pool->mode, x);
3068 readonly_data_section ();
3071 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3072 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3073 pool->align, pool->labelno, done);
3076 if (pool->align > 1)
3077 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3079 /* Output the label. */
3080 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3082 /* Output the value of the constant itself. */
3083 switch (GET_MODE_CLASS (pool->mode))
3086 if (GET_CODE (x) != CONST_DOUBLE)
3089 bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
3090 assemble_real (u.d, pool->mode);
3094 case MODE_PARTIAL_INT:
3095 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3105 /* Done with this pool. */
3106 first_pool = last_pool = 0;
3109 /* Find all the constants whose addresses are referenced inside of EXP,
3110 and make sure assembler code with a label has been output for each one.
3111 Indicate whether an ADDR_EXPR has been encountered. */
3114 output_addressed_constants (exp)
3119 switch (TREE_CODE (exp))
3123 register tree constant = TREE_OPERAND (exp, 0);
3125 while (TREE_CODE (constant) == COMPONENT_REF)
3127 constant = TREE_OPERAND (constant, 0);
3130 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3131 || TREE_CODE (constant) == CONSTRUCTOR)
3132 /* No need to do anything here
3133 for addresses of variables or functions. */
3134 output_constant_def (constant);
3141 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3142 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3147 case NON_LVALUE_EXPR:
3148 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3154 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3155 if (TREE_VALUE (link) != 0)
3156 reloc |= output_addressed_constants (TREE_VALUE (link));
3167 /* Output assembler for byte constant */
3169 output_byte_asm (byte)
3172 if (output_bytecode)
3173 bc_emit_const ((char *) &byte, sizeof (char));
3174 #ifdef ASM_OUTPUT_BYTE
3177 ASM_OUTPUT_BYTE (asm_out_file, byte);
3182 /* Output assembler code for constant EXP to FILE, with no label.
3183 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3184 Assumes output_addressed_constants has been done on EXP already.
3186 Generate exactly SIZE bytes of assembler data, padding at the end
3187 with zeros if necessary. SIZE must always be specified.
3189 SIZE is important for structure constructors,
3190 since trailing members may have been omitted from the constructor.
3191 It is also important for initialization of arrays from string constants
3192 since the full length of the string constant might not be wanted.
3193 It is also needed for initialization of unions, where the initializer's
3194 type is just one member, and that may not be as long as the union.
3196 There a case in which we would fail to output exactly SIZE bytes:
3197 for a structure constructor that wants to produce more than SIZE bytes.
3198 But such constructors will never be generated for any possible input. */
3201 output_constant (exp, size)
3205 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3211 /* Allow a constructor with no elements for any data type.
3212 This means to fill the space with zeros. */
3213 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3215 if (output_bytecode)
3216 bc_emit_const_skip (size);
3218 assemble_zeros (size);
3222 /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
3223 That way we get the constant (we hope) inside it. */
3224 if (TREE_CODE (exp) == NOP_EXPR
3225 && TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)))
3226 exp = TREE_OPERAND (exp, 0);
3235 case REFERENCE_TYPE:
3236 /* ??? What about (int)((float)(int)&foo + 4) */
3237 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3238 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3239 exp = TREE_OPERAND (exp, 0);
3241 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3242 EXPAND_INITIALIZER),
3244 error ("initializer for integer value is too complicated");
3249 if (TREE_CODE (exp) != REAL_CST)
3250 error ("initializer for floating value is not a floating constant");
3252 assemble_real (TREE_REAL_CST (exp),
3253 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3258 output_constant (TREE_REALPART (exp), size / 2);
3259 output_constant (TREE_IMAGPART (exp), size / 2);
3260 size -= (size / 2) * 2;
3264 if (TREE_CODE (exp) == CONSTRUCTOR)
3266 output_constructor (exp, size);
3269 else if (TREE_CODE (exp) == STRING_CST)
3273 if (size > TREE_STRING_LENGTH (exp))
3275 excess = size - TREE_STRING_LENGTH (exp);
3276 size = TREE_STRING_LENGTH (exp);
3279 assemble_string (TREE_STRING_POINTER (exp), size);
3288 if (TREE_CODE (exp) == CONSTRUCTOR)
3289 output_constructor (exp, size);
3296 assemble_zeros (size);
3300 /* Bytecode specific code to output assembler for integer. */
3302 bc_assemble_integer (exp, size)
3310 /* FIXME: is this fold() business going to be as good as the
3311 expand_expr() using EXPAND_SUM above in the RTL case? I
3313 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3317 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3318 exp = TREE_OPERAND (exp, 0);
3319 if (TREE_CODE (exp) == INTEGER_CST)
3324 else if (TREE_CODE (exp) == PLUS_EXPR)
3326 const_part = TREE_OPERAND (exp, 0);
3327 while (TREE_CODE (const_part) == NOP_EXPR
3328 || TREE_CODE (const_part) == CONVERT_EXPR)
3329 const_part = TREE_OPERAND (const_part, 0);
3330 addr_part = TREE_OPERAND (exp, 1);
3331 while (TREE_CODE (addr_part) == NOP_EXPR
3332 || TREE_CODE (addr_part) == CONVERT_EXPR)
3333 addr_part = TREE_OPERAND (addr_part, 0);
3334 if (TREE_CODE (const_part) != INTEGER_CST)
3335 tmp = const_part, const_part = addr_part, addr_part = tmp;
3336 if (TREE_CODE (const_part) != INTEGER_CST
3337 || TREE_CODE (addr_part) != ADDR_EXPR)
3338 abort (); /* FIXME: we really haven't considered
3339 all the possible cases here. */
3341 else if (TREE_CODE (exp) == ADDR_EXPR)
3343 const_part = integer_zero_node;
3347 abort (); /* FIXME: ditto previous. */
3353 char c = TREE_INT_CST_LOW (const_part);
3359 short s = TREE_INT_CST_LOW (const_part);
3360 bc_emit ((char *) &s, 2);
3365 int i = TREE_INT_CST_LOW (const_part);
3366 bc_emit ((char *) &i, 4);
3371 #if WORDS_BIG_ENDIAN
3372 int i = TREE_INT_CST_HIGH (const_part);
3373 bc_emit ((char *) &i, 4);
3374 i = TREE_INT_CST_LOW (const_part);
3375 bc_emit ((char *) &i, 4);
3377 int i = TREE_INT_CST_LOW (const_part);
3378 bc_emit ((char *) &i, 4);
3379 i = TREE_INT_CST_HIGH (const_part);
3380 bc_emit ((char *) &i, 4);
3387 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3388 bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3389 TREE_INT_CST_LOW (const_part));
3391 abort (); /* FIXME: there may be more cases. */
3394 /* Subroutine of output_constant, used for CONSTRUCTORs
3395 (aggregate constants).
3396 Generate at least SIZE bytes, padding if necessary. */
3399 output_constructor (exp, size)
3403 register tree link, field = 0;
3404 HOST_WIDE_INT min_index = 0;
3405 /* Number of bytes output or skipped so far.
3406 In other words, current position within the constructor. */
3407 int total_bytes = 0;
3408 /* Non-zero means BYTE contains part of a byte, to be output. */
3409 int byte_buffer_in_use = 0;
3412 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3415 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3416 field = TYPE_FIELDS (TREE_TYPE (exp));
3418 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3420 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3422 /* As LINK goes through the elements of the constant,
3423 FIELD goes through the structure fields, if the constant is a structure.
3424 if the constant is a union, then we override this,
3425 by getting the field from the TREE_LIST element.
3426 But the constant could also be an array. Then FIELD is zero. */
3427 for (link = CONSTRUCTOR_ELTS (exp);
3429 link = TREE_CHAIN (link),
3430 field = field ? TREE_CHAIN (field) : 0)
3432 tree val = TREE_VALUE (link);
3435 /* the element in a union constructor specifies the proper field. */
3437 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3438 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3440 /* if available, use the type given by link */
3441 if (TREE_PURPOSE (link) != 0)
3442 field = TREE_PURPOSE (link);
3445 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3446 index = TREE_PURPOSE (link);
3448 /* Eliminate the marker that makes a cast not be an lvalue. */
3452 if (field == 0 || !DECL_BIT_FIELD (field))
3454 /* An element that is not a bit-field. */
3456 register int fieldsize;
3457 /* Since this structure is static,
3458 we know the positions are constant. */
3459 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3463 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3465 * (TREE_INT_CST_LOW (index) - min_index));
3467 /* Output any buffered-up bit-fields preceding this element. */
3468 if (byte_buffer_in_use)
3470 ASM_OUTPUT_BYTE (asm_out_file, byte);
3472 byte_buffer_in_use = 0;
3475 /* Advance to offset of this element.
3476 Note no alignment needed in an array, since that is guaranteed
3477 if each element has the proper size. */
3478 if ((field != 0 || index != 0) && bitpos != total_bytes)
3480 if (!output_bytecode)
3481 assemble_zeros (bitpos - total_bytes);
3483 bc_emit_const_skip (bitpos - total_bytes);
3484 total_bytes = bitpos;
3487 /* Determine size this element should occupy. */
3490 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3492 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3494 /* This avoids overflow trouble. */
3495 tree size_tree = size_binop (CEIL_DIV_EXPR,
3497 size_int (BITS_PER_UNIT));
3498 fieldsize = TREE_INT_CST_LOW (size_tree);
3502 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3503 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3507 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3509 /* Output the element's initial value. */
3511 assemble_zeros (fieldsize);
3513 output_constant (val, fieldsize);
3515 /* Count its size. */
3516 total_bytes += fieldsize;
3518 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3519 error ("invalid initial value for member `%s'",
3520 IDENTIFIER_POINTER (DECL_NAME (field)));
3523 /* Element that is a bit-field. */
3525 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3527 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3530 val = integer_zero_node;
3532 /* If this field does not start in this (or, next) byte,
3534 if (next_offset / BITS_PER_UNIT != total_bytes)
3536 /* Output remnant of any bit field in previous bytes. */
3537 if (byte_buffer_in_use)
3539 ASM_OUTPUT_BYTE (asm_out_file, byte);
3541 byte_buffer_in_use = 0;
3544 /* If still not at proper byte, advance to there. */
3545 if (next_offset / BITS_PER_UNIT != total_bytes)
3547 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3548 total_bytes = next_offset / BITS_PER_UNIT;
3552 if (! byte_buffer_in_use)
3555 /* We must split the element into pieces that fall within
3556 separate bytes, and combine each byte with previous or
3557 following bit-fields. */
3559 /* next_offset is the offset n fbits from the beginning of
3560 the structure to the next bit of this element to be processed.
3561 end_offset is the offset of the first bit past the end of
3563 while (next_offset < end_offset)
3567 int next_byte = next_offset / BITS_PER_UNIT;
3568 int next_bit = next_offset % BITS_PER_UNIT;
3570 /* Advance from byte to byte
3571 within this element when necessary. */
3572 while (next_byte != total_bytes)
3574 ASM_OUTPUT_BYTE (asm_out_file, byte);
3579 /* Number of bits we can process at once
3580 (all part of the same byte). */
3581 this_time = MIN (end_offset - next_offset,
3582 BITS_PER_UNIT - next_bit);
3583 #if BYTES_BIG_ENDIAN
3584 /* On big-endian machine, take the most significant bits
3585 first (of the bits that are significant)
3586 and put them into bytes from the most significant end. */
3587 shift = end_offset - next_offset - this_time;
3588 /* Don't try to take a bunch of bits that cross
3589 the word boundary in the INTEGER_CST. */
3590 if (shift < HOST_BITS_PER_WIDE_INT
3591 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3593 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3594 shift = HOST_BITS_PER_WIDE_INT;
3597 /* Now get the bits from the appropriate constant word. */
3598 if (shift < HOST_BITS_PER_WIDE_INT)
3600 value = TREE_INT_CST_LOW (val);
3602 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3604 value = TREE_INT_CST_HIGH (val);
3605 shift -= HOST_BITS_PER_WIDE_INT;
3609 byte |= (((value >> shift)
3610 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3611 << (BITS_PER_UNIT - this_time - next_bit));
3613 /* On little-endian machines,
3614 take first the least significant bits of the value
3615 and pack them starting at the least significant
3616 bits of the bytes. */
3617 shift = (next_offset
3618 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3619 /* Don't try to take a bunch of bits that cross
3620 the word boundary in the INTEGER_CST. */
3621 if (shift < HOST_BITS_PER_WIDE_INT
3622 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3624 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3625 shift = HOST_BITS_PER_WIDE_INT;
3628 /* Now get the bits from the appropriate constant word. */
3629 if (shift < HOST_BITS_PER_INT)
3630 value = TREE_INT_CST_LOW (val);
3631 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3633 value = TREE_INT_CST_HIGH (val);
3634 shift -= HOST_BITS_PER_WIDE_INT;
3638 byte |= ((value >> shift)
3639 & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
3641 next_offset += this_time;
3642 byte_buffer_in_use = 1;
3646 if (byte_buffer_in_use)
3648 ASM_OUTPUT_BYTE (asm_out_file, byte);
3651 if (total_bytes < size)
3652 assemble_zeros (size - total_bytes);
3656 #ifdef HANDLE_SYSV_PRAGMA
3658 /* Support #pragma weak by default if WEAK_ASM_OP is defined. */
3659 #if defined (HANDLE_PRAGMA_WEAK) || (defined (WEAK_ASM_OP) && defined (SET_ASM_OP))
3661 /* See c-pragma.c for an identical definition. */
3677 /* Output asm to handle ``#pragma weak'' */
3679 handle_pragma_weak (what, asm_out_file, name, value)
3680 enum pragma_state what;
3684 if (what == ps_name || what == ps_value)
3686 fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
3688 if (output_bytecode)
3689 BC_OUTPUT_LABELREF (asm_out_file, name);
3691 ASM_OUTPUT_LABELREF (asm_out_file, name);
3693 fputc ('\n', asm_out_file);
3694 if (what == ps_value)
3696 fprintf (asm_out_file, "\t%s\t", SET_ASM_OP);
3697 if (output_bytecode)
3698 BC_OUTPUT_LABELREF (asm_out_file, name);
3700 ASM_OUTPUT_LABELREF (asm_out_file, name);
3702 fputc (',', asm_out_file);
3703 if (output_bytecode)
3704 BC_OUTPUT_LABELREF (asm_out_file, value);
3706 ASM_OUTPUT_LABELREF (asm_out_file, value);
3708 fputc ('\n', asm_out_file);
3711 else if (! (what == ps_done || what == ps_start))
3712 warning ("malformed `#pragma weak'");
3715 #endif /* HANDLE_PRAGMA_WEAK or (WEAK_ASM_OP and SET_ASM_OP) */
3717 #endif /* HANDLE_SYSV_PRAGMA */