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 /* Nonzero if at least one function definition has been seen. */
86 static int function_defined;
88 extern FILE *asm_out_file;
90 static char *compare_constant_1 ();
91 static void record_constant_1 ();
92 static void output_constant_def_contents ();
93 static int contains_pointers_p ();
94 static void bc_output_ascii ();
96 void output_constant_pool ();
97 void assemble_name ();
98 int output_addressed_constants ();
99 void output_constant ();
100 void output_constructor ();
101 void output_byte_asm ();
102 void text_section ();
103 void readonly_data_section ();
104 void data_section ();
105 static void bc_assemble_integer ();
107 #ifdef EXTRA_SECTIONS
108 static enum in_section {no_section, in_text, in_data, EXTRA_SECTIONS} in_section
111 static enum in_section {no_section, in_text, in_data} in_section
115 /* Define functions like text_section for any extra sections. */
116 #ifdef EXTRA_SECTION_FUNCTIONS
117 EXTRA_SECTION_FUNCTIONS
120 /* Tell assembler to switch to text section. */
125 if (in_section != in_text)
130 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
132 in_section = in_text;
136 /* Tell assembler to switch to data section. */
141 if (in_section != in_data)
147 if (flag_shared_data)
149 #ifdef SHARED_SECTION_ASM_OP
150 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
152 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
156 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
159 in_section = in_data;
163 /* Tell assembler to switch to read-only data section. This is normally
167 readonly_data_section ()
169 #ifdef READONLY_DATA_SECTION
170 READONLY_DATA_SECTION (); /* Note this can call data_section. */
176 /* Determine if we're in the text section. */
181 return in_section == in_text;
184 /* Create the rtl to represent a function, for a function definition.
185 DECL is a FUNCTION_DECL node which describes which function.
186 The rtl is stored into DECL. */
189 make_function_rtl (decl)
192 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
196 if (DECL_RTL (decl) == 0)
197 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
199 /* Record that at least one function has been defined. */
200 function_defined = 1;
204 /* Rename a nested function to avoid conflicts. */
205 if (decl_function_context (decl) != 0
206 && DECL_INITIAL (decl) != 0
207 && DECL_RTL (decl) == 0)
211 name = IDENTIFIER_POINTER (DECL_NAME (decl));
212 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
213 name = obstack_copy0 (saveable_obstack, label, strlen (label));
217 if (DECL_RTL (decl) == 0)
220 = gen_rtx (MEM, DECL_MODE (decl),
221 gen_rtx (SYMBOL_REF, Pmode, name));
223 /* Optionally set flags or add text to the name to record information
224 such as that it is a function name. If the name is changed, the macro
225 ASM_OUTPUT_LABELREF will have to know how to strip this information.
226 And if it finds a * at the beginning after doing so, it must handle
228 #ifdef ENCODE_SECTION_INFO
229 ENCODE_SECTION_INFO (decl);
233 /* Record at least one function has been defined. */
234 function_defined = 1;
237 /* Create the DECL_RTL for a declaration for a static or external
238 variable or static or external function.
239 ASMSPEC, if not 0, is the string which the user specified
240 as the assembler symbol name.
241 TOP_LEVEL is nonzero if this is a file-scope variable.
242 This is never called for PARM_DECLs. */
244 bc_make_decl_rtl (decl, asmspec, top_level)
249 register char *name = TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl));
251 if (DECL_RTL (decl) == 0)
253 /* Print an error message for register variables. */
254 if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
255 error ("function declared `register'");
256 else if (DECL_REGISTER (decl))
257 error ("global register variables not supported in the interpreter");
259 /* Handle ordinary static variables and functions. */
260 if (DECL_RTL (decl) == 0)
262 /* Can't use just the variable's own name for a variable
263 whose scope is less than the whole file.
264 Concatenate a distinguishing number. */
265 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
269 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
270 name = obstack_copy0 (saveable_obstack, label, strlen (label));
274 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
279 /* Given NAME, a putative register name, discard any customary prefixes. */
282 strip_reg_name (name)
285 #ifdef REGISTER_PREFIX
286 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
287 name += strlen (REGISTER_PREFIX);
289 if (name[0] == '%' || name[0] == '#')
294 /* Decode an `asm' spec for a declaration as a register name.
295 Return the register number, or -1 if nothing specified,
296 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
297 or -3 if ASMSPEC is `cc' and is not recognized,
298 or -4 if ASMSPEC is `memory' and is not recognized.
299 Accept an exact spelling or a decimal number.
300 Prefixes such as % are optional. */
303 decode_reg_name (asmspec)
310 /* Get rid of confusing prefixes. */
311 asmspec = strip_reg_name (asmspec);
313 /* Allow a decimal number as a "register name". */
314 for (i = strlen (asmspec) - 1; i >= 0; i--)
315 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
317 if (asmspec[0] != 0 && i < 0)
320 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
326 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
328 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
331 #ifdef ADDITIONAL_REGISTER_NAMES
333 static struct { char *name; int number; } table[]
334 = ADDITIONAL_REGISTER_NAMES;
336 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
337 if (! strcmp (asmspec, table[i].name))
338 return table[i].number;
340 #endif /* ADDITIONAL_REGISTER_NAMES */
342 if (!strcmp (asmspec, "memory"))
345 if (!strcmp (asmspec, "cc"))
354 /* Create the DECL_RTL for a declaration for a static or external variable
355 or static or external function.
356 ASMSPEC, if not 0, is the string which the user specified
357 as the assembler symbol name.
358 TOP_LEVEL is nonzero if this is a file-scope variable.
360 This is never called for PARM_DECL nodes. */
363 make_decl_rtl (decl, asmspec, top_level)
373 bc_make_decl_rtl (decl, asmspec, top_level);
377 reg_number = decode_reg_name (asmspec);
379 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
380 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
382 if (reg_number == -2)
384 /* ASMSPEC is given, and not the name of a register. */
385 name = (char *) obstack_alloc (saveable_obstack,
386 strlen (asmspec) + 2);
388 strcpy (&name[1], asmspec);
391 /* For a duplicate declaration, we can be called twice on the
392 same DECL node. Don't discard the RTL already made. */
393 if (DECL_RTL (decl) == 0)
397 /* First detect errors in declaring global registers. */
398 if (DECL_REGISTER (decl) && reg_number == -1)
399 error_with_decl (decl,
400 "register name not specified for `%s'");
401 else if (DECL_REGISTER (decl) && reg_number < 0)
402 error_with_decl (decl,
403 "invalid register name for `%s'");
404 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
405 error_with_decl (decl,
406 "register name given for non-register variable `%s'");
407 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
408 error ("function declared `register'");
409 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
410 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
411 else if (DECL_REGISTER (decl)
412 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
413 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
414 /* Now handle properly declared static register variables. */
415 else if (DECL_REGISTER (decl))
418 #if 0 /* yylex should print the warning for this */
420 pedwarn ("ANSI C forbids global register variables");
422 if (DECL_INITIAL (decl) != 0 && top_level)
424 DECL_INITIAL (decl) = 0;
425 error ("global register variable has initial value");
427 if (fixed_regs[reg_number] == 0
428 && function_defined && top_level)
429 error ("global register variable follows a function definition");
430 if (TREE_THIS_VOLATILE (decl))
431 warning ("volatile register variables don't work as you might wish");
433 /* If the user specified one of the eliminables registers here,
434 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
435 confused with that register and be eliminated. Although this
436 usage is somewhat suspect, we nevertheless use the following
437 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
440 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
441 REGNO (DECL_RTL (decl)) = reg_number;
442 REG_USERVAR_P (DECL_RTL (decl)) = 1;
446 /* Make this register fixed, so not usable for anything else. */
447 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
449 global_regs[reg_number + --nregs] = 1;
454 /* Now handle ordinary static variables and functions (in memory).
455 Also handle vars declared register invalidly. */
456 if (DECL_RTL (decl) == 0)
458 /* Can't use just the variable's own name for a variable
459 whose scope is less than the whole file.
460 Concatenate a distinguishing number. */
461 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
465 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
466 name = obstack_copy0 (saveable_obstack, label, strlen (label));
470 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
471 gen_rtx (SYMBOL_REF, Pmode, name));
473 /* If this variable is to be treated as volatile, show its
474 tree node has side effects. If it has side effects, either
475 because of this test or from TREE_THIS_VOLATILE also
476 being set, show the MEM is volatile. */
477 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
478 && TREE_PUBLIC (decl))
479 TREE_SIDE_EFFECTS (decl) = 1;
480 if (TREE_SIDE_EFFECTS (decl))
481 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
483 if (TREE_READONLY (decl))
484 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
485 MEM_IN_STRUCT_P (DECL_RTL (decl))
486 = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
487 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
488 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
489 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE);
491 /* Optionally set flags or add text to the name to record information
492 such as that it is a function name.
493 If the name is changed, the macro ASM_OUTPUT_LABELREF
494 will have to know how to strip this information.
495 And if it finds a * at the beginning after doing so,
496 it must handle that too. */
497 #ifdef ENCODE_SECTION_INFO
498 ENCODE_SECTION_INFO (decl);
502 /* If the old RTL had the wrong mode, fix the mode. */
503 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
505 rtx rtl = DECL_RTL (decl);
506 PUT_MODE (rtl, DECL_MODE (decl));
510 /* Make the rtl for variable VAR be volatile.
511 Use this only for static variables. */
514 make_var_volatile (var)
517 if (GET_CODE (DECL_RTL (var)) != MEM)
520 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
523 /* Output alignment directive to align for constant expression EXP. */
526 assemble_constant_align (exp)
531 /* Align the location counter as required by EXP's data type. */
532 align = TYPE_ALIGN (TREE_TYPE (exp));
533 #ifdef CONSTANT_ALIGNMENT
534 align = CONSTANT_ALIGNMENT (exp, align);
537 if (align > BITS_PER_UNIT)
538 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
541 /* Output a string of literal assembler code
542 for an `asm' keyword used between functions. */
545 assemble_asm (string)
550 error ("asm statements not allowed in interpreter");
556 if (TREE_CODE (string) == ADDR_EXPR)
557 string = TREE_OPERAND (string, 0);
559 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
562 #if 0 /* This should no longer be needed, because
563 flag_gnu_linker should be 0 on these systems,
564 which should prevent any output
565 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
566 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
567 #ifndef ASM_OUTPUT_CONSTRUCTOR
568 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
570 #ifndef ASM_OUTPUT_DESTRUCTOR
571 #define ASM_OUTPUT_DESTRUCTOR(file, name)
576 /* Record an element in the table of global destructors.
577 How this is done depends on what sort of assembler and linker
580 NAME should be the name of a global function to be called
581 at exit time. This name is output using assemble_name. */
584 assemble_destructor (name)
587 #ifdef ASM_OUTPUT_DESTRUCTOR
588 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
592 /* Now tell GNU LD that this is part of the static destructor set. */
593 /* This code works for any machine provided you use GNU as/ld. */
594 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
595 assemble_name (asm_out_file, name);
596 fputc ('\n', asm_out_file);
601 /* Likewise for global constructors. */
604 assemble_constructor (name)
607 #ifdef ASM_OUTPUT_CONSTRUCTOR
608 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
612 /* Now tell GNU LD that this is part of the static constructor set. */
613 /* This code works for any machine provided you use GNU as/ld. */
614 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
615 assemble_name (asm_out_file, name);
616 fputc ('\n', asm_out_file);
621 /* Likewise for entries we want to record for garbage collection.
622 Garbage collection is still under development. */
625 assemble_gc_entry (name)
628 #ifdef ASM_OUTPUT_GC_ENTRY
629 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
633 /* Now tell GNU LD that this is part of the static constructor set. */
634 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
635 assemble_name (asm_out_file, name);
636 fputc ('\n', asm_out_file);
641 /* Output assembler code for the constant pool of a function and associated
642 with defining the name of the function. DECL describes the function.
643 NAME is the function's name. For the constant pool, we use the current
644 constant pool data. */
647 assemble_start_function (decl, fnname)
653 /* The following code does not need preprocessing in the assembler. */
657 output_constant_pool (fnname, decl);
662 /* Tell assembler to move to target machine's alignment for functions. */
663 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
667 BC_OUTPUT_ALIGN (asm_out_file, align);
669 ASM_OUTPUT_ALIGN (asm_out_file, align);
672 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
673 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
676 #ifdef SDB_DEBUGGING_INFO
677 /* Output SDB definition of the function. */
678 if (write_symbols == SDB_DEBUG)
679 sdbout_mark_begin_function ();
682 #ifdef DBX_DEBUGGING_INFO
683 /* Output DBX definition of the function. */
684 if (write_symbols == DBX_DEBUG)
685 dbxout_begin_function (decl);
688 /* Make function name accessible from other files, if appropriate. */
690 if (TREE_PUBLIC (decl))
692 if (!first_global_object_name)
693 STRIP_NAME_ENCODING (first_global_object_name, fnname);
695 BC_GLOBALIZE_LABEL (asm_out_file, fnname);
697 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
700 /* Do any machine/system dependent processing of the function name */
701 #ifdef ASM_DECLARE_FUNCTION_NAME
702 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
704 /* Standard thing is just output label for the function. */
706 BC_OUTPUT_LABEL (asm_out_file, fnname);
708 ASM_OUTPUT_LABEL (asm_out_file, fnname);
709 #endif /* ASM_DECLARE_FUNCTION_NAME */
712 /* Output assembler code associated with defining the size of the
713 function. DECL describes the function. NAME is the function's name. */
716 assemble_end_function (decl, fnname)
720 #ifdef ASM_DECLARE_FUNCTION_SIZE
721 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
725 /* Assemble code to leave SIZE bytes of zeros. */
728 assemble_zeros (size)
733 bc_emit_const_skip (size);
737 #ifdef ASM_NO_SKIP_IN_TEXT
738 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
739 so we must output 0s explicitly in the text section. */
740 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
744 for (i = 0; i < size - 20; i += 20)
747 fprintf (asm_out_file,
748 "%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);
750 fprintf (asm_out_file,
751 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
757 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
759 fprintf (asm_out_file, "\tbyte 0");
762 for (; i < size; i++)
763 fprintf (asm_out_file, ",0");
764 fprintf (asm_out_file, "\n");
772 BC_OUTPUT_SKIP (asm_out_file, size);
774 ASM_OUTPUT_SKIP (asm_out_file, size);
778 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
781 assemble_align (align)
784 if (align > BITS_PER_UNIT)
785 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
788 /* Assemble a string constant with the specified C string as contents. */
791 assemble_string (p, size)
805 /* If the string is very long, split it up. */
809 int thissize = size - pos;
810 if (thissize > maximum)
814 bc_output_ascii (asm_out_file, p, thissize);
817 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
826 bc_output_ascii (file, p, size)
831 BC_OUTPUT_ASCII (file, p, size);
834 /* Assemble everything that is needed for a variable or function declaration.
835 Not used for automatic variables, and not used for function definitions.
836 Should not be called for variables of incomplete structure type.
838 TOP_LEVEL is nonzero if this variable has file scope.
839 AT_END is nonzero if this is the special handling, at end of compilation,
840 to define things that have had only tentative definitions.
841 DONT_OUTPUT_DATA if nonzero means don't actually output the
842 initial value (that will be done by the caller). */
845 assemble_variable (decl, top_level, at_end, dont_output_data)
854 enum in_section saved_in_section;
859 if (GET_CODE (DECL_RTL (decl)) == REG)
861 /* Do output symbol info for global register variables, but do nothing
864 if (TREE_ASM_WRITTEN (decl))
866 TREE_ASM_WRITTEN (decl) = 1;
868 if (!output_bytecode)
870 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
871 /* File-scope global variables are output here. */
872 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
874 dbxout_symbol (decl, 0);
876 #ifdef SDB_DEBUGGING_INFO
877 if (write_symbols == SDB_DEBUG && top_level
878 /* Leave initialized global vars for end of compilation;
879 see comment in compile_file. */
880 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
881 sdbout_symbol (decl, 0);
885 /* Don't output any DWARF debugging information for variables here.
886 In the case of local variables, the information for them is output
887 when we do our recursive traversal of the tree representation for
888 the entire containing function. In the case of file-scope variables,
889 we output information for all of them at the very end of compilation
890 while we are doing our final traversal of the chain of file-scope
896 /* Normally no need to say anything here for external references,
897 since assemble_external is called by the langauge-specific code
898 when a declaration is first seen. */
900 if (DECL_EXTERNAL (decl))
903 /* Output no assembler code for a function declaration.
904 Only definitions of functions output anything. */
906 if (TREE_CODE (decl) == FUNCTION_DECL)
909 /* If type was incomplete when the variable was declared,
910 see if it is complete now. */
912 if (DECL_SIZE (decl) == 0)
913 layout_decl (decl, 0);
915 /* Still incomplete => don't allocate it; treat the tentative defn
916 (which is what it must have been) as an `extern' reference. */
918 if (!dont_output_data && DECL_SIZE (decl) == 0)
920 error_with_file_and_line (DECL_SOURCE_FILE (decl),
921 DECL_SOURCE_LINE (decl),
922 "storage size of `%s' isn't known",
923 IDENTIFIER_POINTER (DECL_NAME (decl)));
927 /* The first declaration of a variable that comes through this function
928 decides whether it is global (in C, has external linkage)
929 or local (in C, has internal linkage). So do nothing more
930 if this function has already run. */
932 if (TREE_ASM_WRITTEN (decl))
935 TREE_ASM_WRITTEN (decl) = 1;
937 /* If storage size is erroneously variable, just continue.
938 Error message was already made. */
940 if (DECL_SIZE (decl))
942 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
947 /* This is better than explicit arithmetic, since it avoids overflow. */
948 size_tree = size_binop (CEIL_DIV_EXPR,
949 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
951 if (TREE_INT_CST_HIGH (size_tree) != 0)
953 error_with_decl (decl, "size of variable `%s' is too large");
958 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
960 /* Handle uninitialized definitions. */
962 /* ANSI specifies that a tentative definition which is not merged with
963 a non-tentative definition behaves exactly like a definition with an
964 initializer equal to zero. (Section 3.7.2)
965 -fno-common gives strict ANSI behavior. Usually you don't want it.
966 This matters only for variables with external linkage. */
967 if ((! flag_no_common || ! TREE_PUBLIC (decl))
968 && ! dont_output_data
969 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
971 int size = TREE_INT_CST_LOW (size_tree);
974 if (TREE_INT_CST_HIGH (size_tree) != 0)
975 error_with_decl (decl, "size of variable `%s' is too large");
976 /* Don't allocate zero bytes of common,
977 since that means "undefined external" in the linker. */
978 if (size == 0) rounded = 1;
979 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
980 so that each uninitialized object starts on such a boundary. */
981 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
982 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
983 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
985 #ifdef DBX_DEBUGGING_INFO
986 /* File-scope global variables are output here. */
987 if (write_symbols == DBX_DEBUG && top_level)
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);
998 /* Don't output any DWARF debugging information for variables here.
999 In the case of local variables, the information for them is output
1000 when we do our recursive traversal of the tree representation for
1001 the entire containing function. In the case of file-scope variables,
1002 we output information for all of them at the very end of compilation
1003 while we are doing our final traversal of the chain of file-scope
1007 if (flag_shared_data)
1010 if (TREE_PUBLIC (decl))
1012 #ifdef ASM_OUTPUT_SHARED_COMMON
1013 if (flag_shared_data)
1014 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1017 if (output_bytecode)
1019 BC_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1023 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1024 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1027 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1033 #ifdef ASM_OUTPUT_SHARED_LOCAL
1034 if (flag_shared_data)
1035 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1038 if (output_bytecode)
1040 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1044 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1045 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1048 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1055 /* Handle initialized definitions. */
1057 /* First make the assembler name(s) global if appropriate. */
1058 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1060 if (!first_global_object_name)
1061 STRIP_NAME_ENCODING(first_global_object_name, name);
1062 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1065 for (d = equivalents; d; d = TREE_CHAIN (d))
1067 tree e = TREE_VALUE (d);
1068 if (TREE_PUBLIC (e) && DECL_NAME (e))
1069 ASM_GLOBALIZE_LABEL (asm_out_file,
1070 XSTR (XEXP (DECL_RTL (e), 0), 0));
1074 /* Output any data that we will need to use the address of. */
1075 if (DECL_INITIAL (decl) == error_mark_node)
1076 reloc = contains_pointers_p (TREE_TYPE (decl));
1077 else if (DECL_INITIAL (decl))
1078 reloc = output_addressed_constants (DECL_INITIAL (decl));
1080 /* Switch to the proper section for this data. */
1081 #ifdef SELECT_SECTION
1082 SELECT_SECTION (decl, reloc);
1084 if (TREE_READONLY (decl)
1085 && ! TREE_THIS_VOLATILE (decl)
1086 && ! (flag_pic && reloc))
1087 readonly_data_section ();
1092 /* Record current section so we can restore it if dbxout.c clobbers it. */
1093 saved_in_section = in_section;
1095 /* Output the dbx info now that we have chosen the section. */
1097 #ifdef DBX_DEBUGGING_INFO
1098 /* File-scope global variables are output here. */
1099 if (write_symbols == DBX_DEBUG && top_level)
1100 dbxout_symbol (decl, 0);
1102 #ifdef SDB_DEBUGGING_INFO
1103 if (write_symbols == SDB_DEBUG && top_level
1104 /* Leave initialized global vars for end of compilation;
1105 see comment in compile_file. */
1106 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1107 sdbout_symbol (decl, 0);
1110 /* Don't output any DWARF debugging information for variables here.
1111 In the case of local variables, the information for them is output
1112 when we do our recursive traversal of the tree representation for
1113 the entire containing function. In the case of file-scope variables,
1114 we output information for all of them at the very end of compilation
1115 while we are doing our final traversal of the chain of file-scope
1118 if (in_section != saved_in_section)
1120 /* Switch to the proper section for this data. */
1121 #ifdef SELECT_SECTION
1122 SELECT_SECTION (decl, reloc);
1124 if (TREE_READONLY (decl)
1125 && ! TREE_THIS_VOLATILE (decl)
1126 && ! (flag_pic && reloc))
1127 readonly_data_section ();
1133 /* Compute and output the alignment of this data. */
1135 align = DECL_ALIGN (decl);
1136 /* In the case for initialing an array whose length isn't specified,
1137 where we have not yet been able to do the layout,
1138 figure out the proper alignment now. */
1139 if (dont_output_data && DECL_SIZE (decl) == 0
1140 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1141 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1143 /* Some object file formats have a maximum alignment which they support.
1144 In particular, a.out format supports a maximum alignment of 4. */
1145 #ifndef MAX_OFILE_ALIGNMENT
1146 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1148 if (align > MAX_OFILE_ALIGNMENT)
1150 warning_with_decl (decl,
1151 "alignment of `%s' is greater than maximum object file alignment");
1152 align = MAX_OFILE_ALIGNMENT;
1154 #ifdef DATA_ALIGNMENT
1155 /* On some machines, it is good to increase alignment sometimes. */
1156 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1158 #ifdef CONSTANT_ALIGNMENT
1159 if (DECL_INITIAL (decl))
1160 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1163 /* Reset the alignment in case we have made it tighter, so we can benefit
1164 from it in get_pointer_alignment. */
1165 DECL_ALIGN (decl) = align;
1167 if (align > BITS_PER_UNIT)
1169 if (output_bytecode)
1170 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1172 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1175 /* Do any machine/system dependent processing of the object. */
1176 #ifdef ASM_DECLARE_OBJECT_NAME
1177 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1179 /* Standard thing is just output label for the object. */
1180 if (output_bytecode)
1181 BC_OUTPUT_LABEL (asm_out_file, name);
1183 ASM_OUTPUT_LABEL (asm_out_file, name);
1184 #endif /* ASM_DECLARE_OBJECT_NAME */
1186 if (!dont_output_data)
1188 if (DECL_INITIAL (decl))
1189 /* Output the actual data. */
1190 output_constant (DECL_INITIAL (decl),
1191 int_size_in_bytes (TREE_TYPE (decl)));
1193 /* Leave space for it. */
1194 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1198 #ifdef XCOFF_DEBUGGING_INFO
1199 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1200 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1201 and `aa' hasn't been output yet, the assembler generates a stab entry with
1202 a value of zero, in addition to creating an unnecessary external entry
1203 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1205 /* File-scope global variables are output here. */
1206 if (write_symbols == XCOFF_DEBUG && top_level)
1208 saved_in_section = in_section;
1210 dbxout_symbol (decl, 0);
1212 if (in_section != saved_in_section)
1214 /* Switch to the proper section for this data. */
1215 #ifdef SELECT_SECTION
1216 SELECT_SECTION (decl, reloc);
1218 if (TREE_READONLY (decl)
1219 && ! TREE_THIS_VOLATILE (decl)
1220 && ! (flag_pic && reloc))
1221 readonly_data_section ();
1228 /* There must be a statement after a label. */
1233 /* Return 1 if type TYPE contains any pointers. */
1236 contains_pointers_p (type)
1239 switch (TREE_CODE (type))
1242 case REFERENCE_TYPE:
1243 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1244 so I'll play safe and return 1. */
1250 case QUAL_UNION_TYPE:
1253 /* For a type that has fields, see if the fields have pointers. */
1254 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1255 if (contains_pointers_p (TREE_TYPE (fields)))
1261 /* An array type contains pointers if its element type does. */
1262 return contains_pointers_p (TREE_TYPE (type));
1269 /* Output text storage for constructor CONSTR. Returns rtx of
1273 bc_output_constructor (constr)
1278 /* Must always be a literal; non-literal constructors are handled
1281 if (!TREE_CONSTANT (constr))
1288 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1290 BC_OUTPUT_ALIGN (asm_out_file, i);
1293 output_constant (constr, int_size_in_bytes (TREE_TYPE (constr)));
1297 /* Create storage for constructor CONSTR. */
1300 bc_output_data_constructor (constr)
1305 /* Put in data section */
1309 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1311 BC_OUTPUT_ALIGN (asm_out_file, i);
1313 /* The constructor is filled in at runtime. */
1314 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1318 /* Output something to declare an external symbol to the assembler.
1319 (Most assemblers don't need this, so we normally output nothing.)
1320 Do nothing if DECL is not external. */
1323 assemble_external (decl)
1326 if (output_bytecode)
1329 #ifdef ASM_OUTPUT_EXTERNAL
1330 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1331 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1333 rtx rtl = DECL_RTL (decl);
1335 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1336 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1338 /* Some systems do require some output. */
1339 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1340 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1346 /* Similar, for calling a library function FUN. */
1349 assemble_external_libcall (fun)
1352 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1353 if (!output_bytecode)
1355 /* Declare library function name external when first used, if nec. */
1356 if (! SYMBOL_REF_USED (fun))
1358 SYMBOL_REF_USED (fun) = 1;
1359 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1365 /* Declare the label NAME global. */
1368 assemble_global (name)
1371 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1374 /* Assemble a label named NAME. */
1377 assemble_label (name)
1380 if (output_bytecode)
1381 BC_OUTPUT_LABEL (asm_out_file, name);
1383 ASM_OUTPUT_LABEL (asm_out_file, name);
1386 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1387 If NAME starts with a *, the rest of NAME is output verbatim.
1388 Otherwise NAME is transformed in an implementation-defined way
1389 (usually by the addition of an underscore).
1390 Many macros in the tm file are defined to call this function. */
1393 assemble_name (file, name)
1399 if (output_bytecode)
1400 bc_emit_labelref (name);
1402 fputs (&name[1], file);
1406 if (output_bytecode)
1407 BC_OUTPUT_LABELREF (file, name);
1409 ASM_OUTPUT_LABELREF (file, name);
1413 /* Allocate SIZE bytes writable static space with a gensym name
1414 and return an RTX to refer to its address. */
1417 assemble_static_space (size)
1423 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1424 so that each uninitialized object starts on such a boundary. */
1425 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1426 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1427 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1430 if (flag_shared_data)
1434 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1437 namestring = (char *) obstack_alloc (saveable_obstack,
1439 strcpy (namestring, name);
1441 if (output_bytecode)
1442 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1444 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1446 if (output_bytecode)
1448 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1452 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1453 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1455 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1461 /* Assemble the static constant template for function entry trampolines.
1462 This is done at most once per compilation.
1463 Returns an RTX for the address of the template. */
1466 assemble_trampoline_template ()
1472 /* Shouldn't get here */
1473 if (output_bytecode)
1476 /* By default, put trampoline templates in read-only data section. */
1478 #ifdef TRAMPOLINE_SECTION
1479 TRAMPOLINE_SECTION ();
1481 readonly_data_section ();
1484 /* Write the assembler code to define one. */
1485 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1487 ASM_OUTPUT_ALIGN (asm_out_file, align);
1489 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1490 TRAMPOLINE_TEMPLATE (asm_out_file);
1492 /* Record the rtl to refer to it. */
1493 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1495 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1496 return gen_rtx (SYMBOL_REF, Pmode, name);
1499 /* Assemble the integer constant X into an object of SIZE bytes.
1500 X must be either a CONST_INT or CONST_DOUBLE.
1502 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1503 non-zero, abort if we can't output the constant. */
1506 assemble_integer (x, size, force)
1511 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1512 ASM_OUTPUT... macros. */
1516 #ifdef ASM_OUTPUT_CHAR
1518 ASM_OUTPUT_CHAR (asm_out_file, x);
1522 #ifdef ASM_OUTPUT_SHORT
1524 ASM_OUTPUT_SHORT (asm_out_file, x);
1528 #ifdef ASM_OUTPUT_INT
1530 ASM_OUTPUT_INT (asm_out_file, x);
1534 #ifdef ASM_OUTPUT_DOUBLE_INT
1536 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1540 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1542 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1547 /* If we couldn't do it that way, there are two other possibilities: First,
1548 if the machine can output an explicit byte and this is a 1 byte constant,
1549 we can use ASM_OUTPUT_BYTE. */
1551 #ifdef ASM_OUTPUT_BYTE
1552 if (size == 1 && GET_CODE (x) == CONST_INT)
1554 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1559 /* Finally, if SIZE is larger than a single word, try to output the constant
1560 one word at a time. */
1562 if (size > UNITS_PER_WORD)
1565 enum machine_mode mode
1566 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1569 for (i = 0; i < size / UNITS_PER_WORD; i++)
1571 word = operand_subword (x, i, 0, mode);
1576 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1580 if (i == size / UNITS_PER_WORD)
1582 /* If we output at least one word and then could not finish,
1583 there is no valid way to continue. */
1594 /* Assemble the floating-point constant D into an object of size MODE. */
1597 assemble_real (d, mode)
1599 enum machine_mode mode;
1601 jmp_buf output_constant_handler;
1603 if (setjmp (output_constant_handler))
1605 error ("floating point trap outputting a constant");
1606 #ifdef REAL_IS_NOT_DOUBLE
1607 bzero (&d, sizeof d);
1614 set_float_handler (output_constant_handler);
1618 #ifdef ASM_OUTPUT_BYTE_FLOAT
1620 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1623 #ifdef ASM_OUTPUT_SHORT_FLOAT
1625 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1628 #ifdef ASM_OUTPUT_FLOAT
1630 ASM_OUTPUT_FLOAT (asm_out_file, d);
1634 #ifdef ASM_OUTPUT_DOUBLE
1636 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1640 #ifdef ASM_OUTPUT_LONG_DOUBLE
1643 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1651 set_float_handler (NULL_PTR);
1654 /* Here we combine duplicate floating constants to make
1655 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1657 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1658 They are chained through the CONST_DOUBLE_CHAIN.
1659 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1660 In that case, CONST_DOUBLE_MEM is either a MEM,
1661 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1663 (CONST_DOUBLE_MEM is used only for top-level functions.
1664 See force_const_mem for explanation.) */
1666 static rtx const_double_chain;
1668 /* Return a CONST_DOUBLE for a value specified as a pair of ints.
1669 For an integer, I0 is the low-order word and I1 is the high-order word.
1670 For a real number, I0 is the word with the low address
1671 and I1 is the word with the high address. */
1674 immed_double_const (i0, i1, mode)
1675 HOST_WIDE_INT i0, i1;
1676 enum machine_mode mode;
1679 int in_current_obstack;
1681 if (GET_MODE_CLASS (mode) == MODE_INT
1682 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1684 /* We clear out all bits that don't belong in MODE, unless they and our
1685 sign bit are all one. So we get either a reasonable negative value
1686 or a reasonable unsigned value for this mode. */
1687 int width = GET_MODE_BITSIZE (mode);
1688 if (width < HOST_BITS_PER_WIDE_INT
1689 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1690 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1691 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1692 else if (width == HOST_BITS_PER_WIDE_INT
1693 && ! (i1 == ~0 && i0 < 0))
1695 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1696 /* We cannot represent this value as a constant. */
1699 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1701 ??? Strictly speaking, this is wrong if we create a CONST_INT
1702 for a large unsigned constant with the size of MODE being
1703 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1704 wider mode. In that case we will mis-interpret it as a negative
1707 Unfortunately, the only alternative is to make a CONST_DOUBLE
1708 for any constant in any mode if it is an unsigned constant larger
1709 than the maximum signed integer in an int on the host. However,
1710 doing this will break everyone that always expects to see a CONST_INT
1711 for SImode and smaller.
1713 We have always been making CONST_INTs in this case, so nothing new
1716 if (width <= HOST_BITS_PER_WIDE_INT)
1717 i1 = (i0 < 0) ? ~0 : 0;
1719 /* If this integer fits in one word, return a CONST_INT. */
1720 if ((i1 == 0 && i0 >= 0)
1721 || (i1 == ~0 && i0 < 0))
1722 return GEN_INT (i0);
1724 /* We use VOIDmode for integers. */
1728 /* Search the chain for an existing CONST_DOUBLE with the right value.
1729 If one is found, return it. */
1731 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1732 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1733 && GET_MODE (r) == mode)
1736 /* No; make a new one and add it to the chain.
1738 We may be called by an optimizer which may be discarding any memory
1739 allocated during its processing (such as combine and loop). However,
1740 we will be leaving this constant on the chain, so we cannot tolerate
1741 freed memory. So switch to saveable_obstack for this allocation
1742 and then switch back if we were in current_obstack. */
1744 push_obstacks_nochange ();
1745 rtl_in_saveable_obstack ();
1746 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1749 /* Don't touch const_double_chain in nested function; see force_const_mem.
1750 Also, don't touch it if not inside any function. */
1751 if (outer_function_chain == 0 && current_function_decl != 0)
1753 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1754 const_double_chain = r;
1757 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1758 Actual use of mem-slot is only through force_const_mem. */
1760 CONST_DOUBLE_MEM (r) = const0_rtx;
1765 /* Return a CONST_DOUBLE for a specified `double' value
1766 and machine mode. */
1769 immed_real_const_1 (d, mode)
1771 enum machine_mode mode;
1773 union real_extract u;
1775 int in_current_obstack;
1777 /* Get the desired `double' value as a sequence of ints
1778 since that is how they are stored in a CONST_DOUBLE. */
1782 /* Detect special cases. */
1784 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1785 if (!bcmp (&dconst0, &d, sizeof d))
1786 return CONST0_RTX (mode);
1787 /* Check for NaN first, because some ports (specifically the i386) do not
1788 emit correct ieee-fp code by default, and thus will generate a core
1789 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1790 does a floating point comparison. */
1791 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1792 return CONST1_RTX (mode);
1794 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1795 return immed_double_const (u.i[0], u.i[1], mode);
1797 /* The rest of this function handles the case where
1798 a float value requires more than 2 ints of space.
1799 It will be deleted as dead code on machines that don't need it. */
1801 /* Search the chain for an existing CONST_DOUBLE with the right value.
1802 If one is found, return it. */
1804 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1805 if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
1806 && GET_MODE (r) == mode)
1809 /* No; make a new one and add it to the chain.
1811 We may be called by an optimizer which may be discarding any memory
1812 allocated during its processing (such as combine and loop). However,
1813 we will be leaving this constant on the chain, so we cannot tolerate
1814 freed memory. So switch to saveable_obstack for this allocation
1815 and then switch back if we were in current_obstack. */
1817 push_obstacks_nochange ();
1818 rtl_in_saveable_obstack ();
1819 r = rtx_alloc (CONST_DOUBLE);
1821 bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
1824 /* Don't touch const_double_chain in nested function; see force_const_mem.
1825 Also, don't touch it if not inside any function. */
1826 if (outer_function_chain == 0 && current_function_decl != 0)
1828 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1829 const_double_chain = r;
1832 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1833 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1834 is only through force_const_mem. */
1836 CONST_DOUBLE_MEM (r) = const0_rtx;
1841 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1842 which must be a REAL_CST tree node. */
1845 immed_real_const (exp)
1848 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1851 /* At the end of a function, forget the memory-constants
1852 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1853 Also clear out real_constant_chain and clear out all the chain-pointers. */
1856 clear_const_double_mem ()
1858 register rtx r, next;
1860 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1861 See force_const_mem for explanation. */
1862 if (outer_function_chain != 0)
1865 for (r = const_double_chain; r; r = next)
1867 next = CONST_DOUBLE_CHAIN (r);
1868 CONST_DOUBLE_CHAIN (r) = 0;
1869 CONST_DOUBLE_MEM (r) = cc0_rtx;
1871 const_double_chain = 0;
1874 /* Given an expression EXP with a constant value,
1875 reduce it to the sum of an assembler symbol and an integer.
1876 Store them both in the structure *VALUE.
1877 Abort if EXP does not reduce. */
1882 HOST_WIDE_INT offset;
1886 decode_addr_const (exp, value)
1888 struct addr_const *value;
1890 register tree target = TREE_OPERAND (exp, 0);
1891 register int offset = 0;
1896 if (TREE_CODE (target) == COMPONENT_REF
1897 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
1900 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
1901 target = TREE_OPERAND (target, 0);
1903 else if (TREE_CODE (target) == ARRAY_REF)
1905 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
1906 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
1908 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
1909 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
1911 target = TREE_OPERAND (target, 0);
1917 switch (TREE_CODE (target))
1921 x = DECL_RTL (target);
1925 if (output_bytecode)
1926 /* FIXME: this may not be correct, check it */
1927 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
1929 x = gen_rtx (MEM, FUNCTION_MODE,
1930 gen_rtx (LABEL_REF, VOIDmode,
1931 label_rtx (TREE_OPERAND (exp, 0))));
1938 x = TREE_CST_RTL (target);
1945 if (!output_bytecode)
1947 if (GET_CODE (x) != MEM)
1953 value->offset = offset;
1956 /* Uniquize all constants that appear in memory.
1957 Each constant in memory thus far output is recorded
1958 in `const_hash_table' with a `struct constant_descriptor'
1959 that contains a polish representation of the value of
1962 We cannot store the trees in the hash table
1963 because the trees may be temporary. */
1965 struct constant_descriptor
1967 struct constant_descriptor *next;
1973 #define MAX_HASH_TABLE 1009
1974 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
1976 /* Compute a hash code for a constant expression. */
1983 register int len, hi, i;
1984 register enum tree_code code = TREE_CODE (exp);
1986 if (code == INTEGER_CST)
1988 p = (char *) &TREE_INT_CST_LOW (exp);
1989 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1991 else if (code == REAL_CST)
1993 p = (char *) &TREE_REAL_CST (exp);
1994 len = sizeof TREE_REAL_CST (exp);
1996 else if (code == STRING_CST)
1997 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
1998 else if (code == COMPLEX_CST)
1999 return const_hash (TREE_REALPART (exp)) * 5
2000 + const_hash (TREE_IMAGPART (exp));
2001 else if (code == CONSTRUCTOR)
2005 /* For record type, include the type in the hashing.
2006 We do not do so for array types
2007 because (1) the sizes of the elements are sufficient
2008 and (2) distinct array types can have the same constructor.
2009 Instead, we include the array size because the constructor could
2011 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2012 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2015 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2016 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2018 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2019 if (TREE_VALUE (link))
2020 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2024 else if (code == ADDR_EXPR)
2026 struct addr_const value;
2027 decode_addr_const (exp, &value);
2028 if (GET_CODE (value.base) == SYMBOL_REF)
2030 /* Don't hash the address of the SYMBOL_REF;
2031 only use the offset and the symbol name. */
2033 p = XSTR (value.base, 0);
2034 for (i = 0; p[i] != 0; i++)
2035 hi = ((hi * 613) + (unsigned)(p[i]));
2037 else if (GET_CODE (value.base) == LABEL_REF)
2038 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2040 hi &= (1 << HASHBITS) - 1;
2041 hi %= MAX_HASH_TABLE;
2044 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2045 return const_hash (TREE_OPERAND (exp, 0)) * 9
2046 + const_hash (TREE_OPERAND (exp, 1));
2047 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2048 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2050 /* Compute hashing function */
2052 for (i = 0; i < len; i++)
2053 hi = ((hi * 613) + (unsigned)(p[i]));
2055 hi &= (1 << HASHBITS) - 1;
2056 hi %= MAX_HASH_TABLE;
2060 /* Compare a constant expression EXP with a constant-descriptor DESC.
2061 Return 1 if DESC describes a constant with the same value as EXP. */
2064 compare_constant (exp, desc)
2066 struct constant_descriptor *desc;
2068 return 0 != compare_constant_1 (exp, desc->contents);
2071 /* Compare constant expression EXP with a substring P of a constant descriptor.
2072 If they match, return a pointer to the end of the substring matched.
2073 If they do not match, return 0.
2075 Since descriptors are written in polish prefix notation,
2076 this function can be used recursively to test one operand of EXP
2077 against a subdescriptor, and if it succeeds it returns the
2078 address of the subdescriptor for the next operand. */
2081 compare_constant_1 (exp, p)
2085 register char *strp;
2087 register enum tree_code code = TREE_CODE (exp);
2089 if (code != (enum tree_code) *p++)
2092 if (code == INTEGER_CST)
2094 /* Integer constants are the same only if the same width of type. */
2095 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2097 strp = (char *) &TREE_INT_CST_LOW (exp);
2098 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2100 else if (code == REAL_CST)
2102 /* Real constants are the same only if the same width of type. */
2103 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2105 strp = (char *) &TREE_REAL_CST (exp);
2106 len = sizeof TREE_REAL_CST (exp);
2108 else if (code == STRING_CST)
2110 if (flag_writable_strings)
2112 strp = TREE_STRING_POINTER (exp);
2113 len = TREE_STRING_LENGTH (exp);
2114 if (bcmp (&TREE_STRING_LENGTH (exp), p,
2115 sizeof TREE_STRING_LENGTH (exp)))
2117 p += sizeof TREE_STRING_LENGTH (exp);
2119 else if (code == COMPLEX_CST)
2121 p = compare_constant_1 (TREE_REALPART (exp), p);
2122 if (p == 0) return 0;
2123 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2126 else if (code == CONSTRUCTOR)
2129 int length = list_length (CONSTRUCTOR_ELTS (exp));
2132 if (bcmp (&length, p, sizeof length))
2136 /* For record constructors, insist that the types match.
2137 For arrays, just verify both constructors are for arrays. */
2138 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2139 type = TREE_TYPE (exp);
2142 if (bcmp (&type, p, sizeof type))
2146 /* For arrays, insist that the size in bytes match. */
2147 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2149 int size = int_size_in_bytes (TREE_TYPE (exp));
2150 if (bcmp (&size, p, sizeof size))
2155 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2157 if (TREE_VALUE (link))
2159 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2166 if (bcmp (&zero, p, sizeof zero))
2174 else if (code == ADDR_EXPR)
2176 struct addr_const value;
2177 decode_addr_const (exp, &value);
2178 strp = (char *) &value.offset;
2179 len = sizeof value.offset;
2180 /* Compare the offset. */
2182 if (*p++ != *strp++)
2184 /* Compare symbol name. */
2185 strp = XSTR (value.base, 0);
2186 len = strlen (strp) + 1;
2188 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2190 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2191 if (p == 0) return 0;
2192 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2195 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2197 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2201 /* Compare constant contents. */
2203 if (*p++ != *strp++)
2209 /* Construct a constant descriptor for the expression EXP.
2210 It is up to the caller to enter the descriptor in the hash table. */
2212 static struct constant_descriptor *
2213 record_constant (exp)
2216 struct constant_descriptor *next = 0;
2219 /* Make a struct constant_descriptor. The first two pointers will
2220 be filled in later. Here we just leave space for them. */
2222 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2223 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2224 record_constant_1 (exp);
2225 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2228 /* Add a description of constant expression EXP
2229 to the object growing in `permanent_obstack'.
2230 No need to return its address; the caller will get that
2231 from the obstack when the object is complete. */
2234 record_constant_1 (exp)
2237 register char *strp;
2239 register enum tree_code code = TREE_CODE (exp);
2241 obstack_1grow (&permanent_obstack, (unsigned int) code);
2243 if (code == INTEGER_CST)
2245 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2246 strp = (char *) &TREE_INT_CST_LOW (exp);
2247 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2249 else if (code == REAL_CST)
2251 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2252 strp = (char *) &TREE_REAL_CST (exp);
2253 len = sizeof TREE_REAL_CST (exp);
2255 else if (code == STRING_CST)
2257 if (flag_writable_strings)
2259 strp = TREE_STRING_POINTER (exp);
2260 len = TREE_STRING_LENGTH (exp);
2261 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2262 sizeof TREE_STRING_LENGTH (exp));
2264 else if (code == COMPLEX_CST)
2266 record_constant_1 (TREE_REALPART (exp));
2267 record_constant_1 (TREE_IMAGPART (exp));
2270 else if (code == CONSTRUCTOR)
2273 int length = list_length (CONSTRUCTOR_ELTS (exp));
2276 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2278 /* For record constructors, insist that the types match.
2279 For arrays, just verify both constructors are for arrays. */
2280 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2281 type = TREE_TYPE (exp);
2284 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2286 /* For arrays, insist that the size in bytes match. */
2287 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2289 int size = int_size_in_bytes (TREE_TYPE (exp));
2290 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2293 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2295 if (TREE_VALUE (link))
2296 record_constant_1 (TREE_VALUE (link));
2301 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
2307 else if (code == ADDR_EXPR)
2309 struct addr_const value;
2310 decode_addr_const (exp, &value);
2311 /* Record the offset. */
2312 obstack_grow (&permanent_obstack,
2313 (char *) &value.offset, sizeof value.offset);
2314 /* Record the symbol name. */
2315 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2316 strlen (XSTR (value.base, 0)) + 1);
2319 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2321 record_constant_1 (TREE_OPERAND (exp, 0));
2322 record_constant_1 (TREE_OPERAND (exp, 1));
2325 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2327 record_constant_1 (TREE_OPERAND (exp, 0));
2331 /* Record constant contents. */
2332 obstack_grow (&permanent_obstack, strp, len);
2335 /* Record a list of constant expressions that were passed to
2336 output_constant_def but that could not be output right away. */
2338 struct deferred_constant
2340 struct deferred_constant *next;
2346 static struct deferred_constant *deferred_constants;
2348 /* Nonzero means defer output of addressed subconstants
2349 (i.e., those for which output_constant_def is called.) */
2350 static int defer_addressed_constants_flag;
2352 /* Start deferring output of subconstants. */
2355 defer_addressed_constants ()
2357 defer_addressed_constants_flag++;
2360 /* Stop deferring output of subconstants,
2361 and output now all those that have been deferred. */
2364 output_deferred_addressed_constants ()
2366 struct deferred_constant *p, *next;
2368 defer_addressed_constants_flag--;
2370 if (defer_addressed_constants_flag > 0)
2373 for (p = deferred_constants; p; p = next)
2375 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2380 deferred_constants = 0;
2383 /* Return an rtx representing a reference to constant data in memory
2384 for the constant expression EXP.
2386 If assembler code for such a constant has already been output,
2387 return an rtx to refer to it.
2388 Otherwise, output such a constant in memory (or defer it for later)
2389 and generate an rtx for it.
2391 The TREE_CST_RTL of EXP is set up to point to that rtx.
2392 The const_hash_table records which constants already have label strings. */
2395 output_constant_def (exp)
2399 register struct constant_descriptor *desc;
2405 if (TREE_CODE (exp) == INTEGER_CST)
2406 abort (); /* No TREE_CST_RTL slot in these. */
2408 if (TREE_CST_RTL (exp))
2409 return TREE_CST_RTL (exp);
2411 /* Make sure any other constants whose addresses appear in EXP
2412 are assigned label numbers. */
2414 reloc = output_addressed_constants (exp);
2416 /* Compute hash code of EXP. Search the descriptors for that hash code
2417 to see if any of them describes EXP. If yes, the descriptor records
2418 the label number already assigned. */
2420 if (!output_bytecode)
2422 hash = const_hash (exp) % MAX_HASH_TABLE;
2424 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2425 if (compare_constant (exp, desc))
2427 found = desc->label;
2433 /* No constant equal to EXP is known to have been output.
2434 Make a constant descriptor to enter EXP in the hash table.
2435 Assign the label number and record it in the descriptor for
2436 future calls to this function to find. */
2438 /* Create a string containing the label name, in LABEL. */
2439 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2441 desc = record_constant (exp);
2442 desc->next = const_hash_table[hash];
2444 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2445 const_hash_table[hash] = desc;
2449 /* Create a string containing the label name, in LABEL. */
2450 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2454 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2456 push_obstacks_nochange ();
2457 if (TREE_PERMANENT (exp))
2458 end_temporary_allocation ();
2460 if (!output_bytecode)
2462 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2465 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2466 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2467 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
2468 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2469 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2473 /* Optionally set flags or add text to the name to record information
2474 such as that it is a function name. If the name is changed, the macro
2475 ASM_OUTPUT_LABELREF will have to know how to strip this information.
2476 And if it finds a * at the beginning after doing so, it must handle
2478 #ifdef ENCODE_SECTION_INFO
2479 ENCODE_SECTION_INFO (exp);
2482 /* If this is the first time we've seen this particular constant,
2483 output it (or defer its output for later). */
2486 if (defer_addressed_constants_flag)
2488 struct deferred_constant *p;
2489 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2491 /* We really should copy trees in depth here,
2492 but since this case is the only one that should happen now,
2493 let's do it later. */
2494 if (TREE_CODE (exp) != STRING_CST)
2497 push_obstacks_nochange ();
2498 suspend_momentary ();
2499 p->exp = copy_node (exp);
2502 p->labelno = const_labelno++;
2503 p->next = deferred_constants;
2504 deferred_constants = p;
2507 output_constant_def_contents (exp, reloc, const_labelno++);
2510 return TREE_CST_RTL (exp);
2513 /* Now output assembler code to define the label for EXP,
2514 and follow it with the data of EXP. */
2517 output_constant_def_contents (exp, reloc, labelno)
2524 /* First switch to text section, except for writable strings. */
2525 #ifdef SELECT_SECTION
2526 SELECT_SECTION (exp, reloc);
2528 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2529 || (flag_pic && reloc))
2532 readonly_data_section ();
2535 /* Align the location counter as required by EXP's data type. */
2536 align = TYPE_ALIGN (TREE_TYPE (exp));
2537 #ifdef CONSTANT_ALIGNMENT
2538 align = CONSTANT_ALIGNMENT (exp, align);
2541 if (align > BITS_PER_UNIT)
2543 if (!output_bytecode)
2545 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2549 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2553 /* Output the label itself. */
2554 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2556 /* Output the value of EXP. */
2557 output_constant (exp,
2558 (TREE_CODE (exp) == STRING_CST
2559 ? TREE_STRING_LENGTH (exp)
2560 : int_size_in_bytes (TREE_TYPE (exp))));
2564 /* Similar hash facility for making memory-constants
2565 from constant rtl-expressions. It is used on RISC machines
2566 where immediate integer arguments and constant addresses are restricted
2567 so that such constants must be stored in memory.
2569 This pool of constants is reinitialized for each function
2570 so each function gets its own constants-pool that comes right before it.
2572 All structures allocated here are discarded when functions are saved for
2573 inlining, so they do not need to be allocated permanently. */
2575 #define MAX_RTX_HASH_TABLE 61
2576 static struct constant_descriptor **const_rtx_hash_table;
2578 /* Structure to represent sufficient information about a constant so that
2579 it can be output when the constant pool is output, so that function
2580 integration can be done, and to simplify handling on machines that reference
2581 constant pool as base+displacement. */
2583 struct pool_constant
2585 struct constant_descriptor *desc;
2586 struct pool_constant *next;
2587 enum machine_mode mode;
2594 /* Pointers to first and last constant in pool. */
2596 static struct pool_constant *first_pool, *last_pool;
2598 /* Current offset in constant pool (does not include any machine-specific
2601 static int pool_offset;
2603 /* Structure used to maintain hash table mapping symbols used to their
2604 corresponding constants. */
2609 struct pool_constant *pool;
2610 struct pool_sym *next;
2613 static struct pool_sym **const_rtx_sym_hash_table;
2615 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2616 The argument is XSTR (... , 0) */
2618 #define SYMHASH(LABEL) \
2619 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2621 /* Initialize constant pool hashing for next function. */
2624 init_const_rtx_hash_table ()
2626 const_rtx_hash_table
2627 = ((struct constant_descriptor **)
2628 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2629 const_rtx_sym_hash_table
2630 = ((struct pool_sym **)
2631 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2632 bzero (const_rtx_hash_table,
2633 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2634 bzero (const_rtx_sym_hash_table,
2635 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2637 first_pool = last_pool = 0;
2641 /* Save and restore it for a nested function. */
2644 save_varasm_status (p)
2647 p->const_rtx_hash_table = const_rtx_hash_table;
2648 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2649 p->first_pool = first_pool;
2650 p->last_pool = last_pool;
2651 p->pool_offset = pool_offset;
2655 restore_varasm_status (p)
2658 const_rtx_hash_table = p->const_rtx_hash_table;
2659 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2660 first_pool = p->first_pool;
2661 last_pool = p->last_pool;
2662 pool_offset = p->pool_offset;
2665 enum kind { RTX_DOUBLE, RTX_INT };
2669 #ifdef ONLY_INT_FIELDS
2670 unsigned int kind : 16;
2671 unsigned int mode : 16;
2673 enum kind kind : 16;
2674 enum machine_mode mode : 16;
2677 union real_extract du;
2678 struct addr_const addr;
2682 /* Express an rtx for a constant integer (perhaps symbolic)
2683 as the sum of a symbol or label plus an explicit integer.
2684 They are stored into VALUE. */
2687 decode_rtx_const (mode, x, value)
2688 enum machine_mode mode;
2690 struct rtx_const *value;
2692 /* Clear the whole structure, including any gaps. */
2695 int *p = (int *) value;
2696 int *end = (int *) (value + 1);
2701 value->kind = RTX_INT; /* Most usual kind. */
2704 switch (GET_CODE (x))
2707 value->kind = RTX_DOUBLE;
2708 value->mode = GET_MODE (x);
2709 bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
2713 value->un.addr.offset = INTVAL (x);
2719 value->un.addr.base = x;
2724 if (GET_CODE (x) == PLUS)
2726 value->un.addr.base = XEXP (x, 0);
2727 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2729 value->un.addr.offset = INTVAL (XEXP (x, 1));
2731 else if (GET_CODE (x) == MINUS)
2733 value->un.addr.base = XEXP (x, 0);
2734 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2736 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2746 if (value->kind == RTX_INT && value->un.addr.base != 0)
2747 switch (GET_CODE (value->un.addr.base))
2751 /* Use the string's address, not the SYMBOL_REF's address,
2752 for the sake of addresses of library routines.
2753 For a LABEL_REF, compare labels. */
2754 value->un.addr.base = XEXP (value->un.addr.base, 0);
2758 /* Given a MINUS expression, simplify it if both sides
2759 include the same symbol. */
2762 simplify_subtraction (x)
2765 struct rtx_const val0, val1;
2767 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2768 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2770 if (val0.un.addr.base == val1.un.addr.base)
2771 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2775 /* Compute a hash code for a constant RTL expression. */
2778 const_hash_rtx (mode, x)
2779 enum machine_mode mode;
2784 struct rtx_const value;
2785 decode_rtx_const (mode, x, &value);
2787 /* Compute hashing function */
2789 for (i = 0; i < sizeof value / sizeof (int); i++)
2790 hi += ((int *) &value)[i];
2792 hi &= (1 << HASHBITS) - 1;
2793 hi %= MAX_RTX_HASH_TABLE;
2797 /* Compare a constant rtl object X with a constant-descriptor DESC.
2798 Return 1 if DESC describes a constant with the same value as X. */
2801 compare_constant_rtx (mode, x, desc)
2802 enum machine_mode mode;
2804 struct constant_descriptor *desc;
2806 register int *p = (int *) desc->contents;
2809 struct rtx_const value;
2811 decode_rtx_const (mode, x, &value);
2812 strp = (int *) &value;
2813 len = sizeof value / sizeof (int);
2815 /* Compare constant contents. */
2817 if (*p++ != *strp++)
2823 /* Construct a constant descriptor for the rtl-expression X.
2824 It is up to the caller to enter the descriptor in the hash table. */
2826 static struct constant_descriptor *
2827 record_constant_rtx (mode, x)
2828 enum machine_mode mode;
2831 struct constant_descriptor *ptr;
2833 struct rtx_const value;
2835 decode_rtx_const (mode, x, &value);
2837 obstack_grow (current_obstack, &ptr, sizeof ptr);
2838 obstack_grow (current_obstack, &label, sizeof label);
2840 /* Record constant contents. */
2841 obstack_grow (current_obstack, &value, sizeof value);
2843 return (struct constant_descriptor *) obstack_finish (current_obstack);
2846 /* Given a constant rtx X, make (or find) a memory constant for its value
2847 and return a MEM rtx to refer to it in memory. */
2850 force_const_mem (mode, x)
2851 enum machine_mode mode;
2855 register struct constant_descriptor *desc;
2860 /* If we want this CONST_DOUBLE in the same mode as it is in memory
2861 (this will always be true for floating CONST_DOUBLEs that have been
2862 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
2863 use the previous copy. Otherwise, make a new one. Note that in
2864 the unlikely event that this same CONST_DOUBLE is used in two different
2865 modes in an alternating fashion, we will allocate a lot of different
2866 memory locations, but this should be extremely rare. */
2868 /* Don't use CONST_DOUBLE_MEM in a nested function.
2869 Nested functions have their own constant pools,
2870 so they can't share the same values in CONST_DOUBLE_MEM
2871 with the containing function. */
2872 if (outer_function_chain == 0)
2873 if (GET_CODE (x) == CONST_DOUBLE
2874 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
2875 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
2876 return CONST_DOUBLE_MEM (x);
2878 /* Compute hash code of X. Search the descriptors for that hash code
2879 to see if any of them describes X. If yes, the descriptor records
2880 the label number already assigned. */
2882 hash = const_hash_rtx (mode, x);
2884 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
2885 if (compare_constant_rtx (mode, x, desc))
2887 found = desc->label;
2893 register struct pool_constant *pool;
2894 register struct pool_sym *sym;
2897 /* No constant equal to X is known to have been output.
2898 Make a constant descriptor to enter X in the hash table.
2899 Assign the label number and record it in the descriptor for
2900 future calls to this function to find. */
2902 desc = record_constant_rtx (mode, x);
2903 desc->next = const_rtx_hash_table[hash];
2904 const_rtx_hash_table[hash] = desc;
2906 /* Align the location counter as required by EXP's data type. */
2907 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
2908 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2909 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
2911 pool_offset += align - 1;
2912 pool_offset &= ~ (align - 1);
2914 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
2916 pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
2920 pool->labelno = const_labelno;
2921 pool->align = align;
2922 pool->offset = pool_offset;
2928 last_pool->next = pool;
2931 pool_offset += GET_MODE_SIZE (mode);
2933 /* Create a string containing the label name, in LABEL. */
2934 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2939 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
2941 /* Add label to symbol hash table. */
2942 hash = SYMHASH (found);
2943 sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
2946 sym->next = const_rtx_sym_hash_table[hash];
2947 const_rtx_sym_hash_table[hash] = sym;
2950 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2952 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
2954 RTX_UNCHANGING_P (def) = 1;
2955 /* Mark the symbol_ref as belonging to this constants pool. */
2956 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
2957 current_function_uses_const_pool = 1;
2959 if (outer_function_chain == 0)
2960 if (GET_CODE (x) == CONST_DOUBLE)
2962 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
2964 CONST_DOUBLE_CHAIN (x) = const_double_chain;
2965 const_double_chain = x;
2967 CONST_DOUBLE_MEM (x) = def;
2973 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
2974 the corresponding pool_constant structure. */
2976 static struct pool_constant *
2977 find_pool_constant (addr)
2980 struct pool_sym *sym;
2981 char *label = XSTR (addr, 0);
2983 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
2984 if (sym->label == label)
2990 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
2993 get_pool_constant (addr)
2996 return (find_pool_constant (addr))->constant;
2999 /* Similar, return the mode. */
3002 get_pool_mode (addr)
3005 return (find_pool_constant (addr))->mode;
3008 /* Similar, return the offset in the constant pool. */
3011 get_pool_offset (addr)
3014 return (find_pool_constant (addr))->offset;
3017 /* Return the size of the constant pool. */
3025 /* Write all the constants in the constant pool. */
3028 output_constant_pool (fnname, fndecl)
3032 struct pool_constant *pool;
3034 union real_extract u;
3036 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3037 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3040 for (pool = first_pool; pool; pool = pool->next)
3044 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3045 whose CODE_LABEL has been deleted. This can occur if a jump table
3046 is eliminated by optimization. If so, write a constant of zero
3047 instead. Note that this can also happen by turning the
3048 CODE_LABEL into a NOTE. */
3049 if (((GET_CODE (x) == LABEL_REF
3050 && (INSN_DELETED_P (XEXP (x, 0))
3051 || GET_CODE (XEXP (x, 0)) == NOTE)))
3052 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3053 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3054 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3055 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3058 /* First switch to correct section. */
3059 #ifdef SELECT_RTX_SECTION
3060 SELECT_RTX_SECTION (pool->mode, x);
3062 readonly_data_section ();
3065 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3066 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3067 pool->align, pool->labelno, done);
3070 if (pool->align > 1)
3071 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3073 /* Output the label. */
3074 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3076 /* Output the value of the constant itself. */
3077 switch (GET_MODE_CLASS (pool->mode))
3080 if (GET_CODE (x) != CONST_DOUBLE)
3083 bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
3084 assemble_real (u.d, pool->mode);
3088 case MODE_PARTIAL_INT:
3089 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3099 /* Done with this pool. */
3100 first_pool = last_pool = 0;
3103 /* Find all the constants whose addresses are referenced inside of EXP,
3104 and make sure assembler code with a label has been output for each one.
3105 Indicate whether an ADDR_EXPR has been encountered. */
3108 output_addressed_constants (exp)
3113 switch (TREE_CODE (exp))
3117 register tree constant = TREE_OPERAND (exp, 0);
3119 while (TREE_CODE (constant) == COMPONENT_REF)
3121 constant = TREE_OPERAND (constant, 0);
3124 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3125 || TREE_CODE (constant) == CONSTRUCTOR)
3126 /* No need to do anything here
3127 for addresses of variables or functions. */
3128 output_constant_def (constant);
3135 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3136 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3141 case NON_LVALUE_EXPR:
3142 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3148 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3149 if (TREE_VALUE (link) != 0)
3150 reloc |= output_addressed_constants (TREE_VALUE (link));
3161 /* Output assembler for byte constant */
3163 output_byte_asm (byte)
3166 if (output_bytecode)
3167 bc_emit_const ((char *) &byte, sizeof (char));
3168 #ifdef ASM_OUTPUT_BYTE
3171 ASM_OUTPUT_BYTE (asm_out_file, byte);
3176 /* Output assembler code for constant EXP to FILE, with no label.
3177 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3178 Assumes output_addressed_constants has been done on EXP already.
3180 Generate exactly SIZE bytes of assembler data, padding at the end
3181 with zeros if necessary. SIZE must always be specified.
3183 SIZE is important for structure constructors,
3184 since trailing members may have been omitted from the constructor.
3185 It is also important for initialization of arrays from string constants
3186 since the full length of the string constant might not be wanted.
3187 It is also needed for initialization of unions, where the initializer's
3188 type is just one member, and that may not be as long as the union.
3190 There a case in which we would fail to output exactly SIZE bytes:
3191 for a structure constructor that wants to produce more than SIZE bytes.
3192 But such constructors will never be generated for any possible input. */
3195 output_constant (exp, size)
3199 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3205 /* Allow a constructor with no elements for any data type.
3206 This means to fill the space with zeros. */
3207 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3209 if (output_bytecode)
3210 bc_emit_const_skip (size);
3212 assemble_zeros (size);
3216 /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
3217 That way we get the constant (we hope) inside it. */
3218 if (TREE_CODE (exp) == NOP_EXPR
3219 && TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)))
3220 exp = TREE_OPERAND (exp, 0);
3229 case REFERENCE_TYPE:
3230 /* ??? What about (int)((float)(int)&foo + 4) */
3231 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3232 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3233 exp = TREE_OPERAND (exp, 0);
3235 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3236 EXPAND_INITIALIZER),
3238 error ("initializer for integer value is too complicated");
3243 if (TREE_CODE (exp) != REAL_CST)
3244 error ("initializer for floating value is not a floating constant");
3246 assemble_real (TREE_REAL_CST (exp),
3247 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3252 output_constant (TREE_REALPART (exp), size / 2);
3253 output_constant (TREE_IMAGPART (exp), size / 2);
3254 size -= (size / 2) * 2;
3258 if (TREE_CODE (exp) == CONSTRUCTOR)
3260 output_constructor (exp, size);
3263 else if (TREE_CODE (exp) == STRING_CST)
3267 if (size > TREE_STRING_LENGTH (exp))
3269 excess = size - TREE_STRING_LENGTH (exp);
3270 size = TREE_STRING_LENGTH (exp);
3273 assemble_string (TREE_STRING_POINTER (exp), size);
3282 if (TREE_CODE (exp) == CONSTRUCTOR)
3283 output_constructor (exp, size);
3290 assemble_zeros (size);
3294 /* Bytecode specific code to output assembler for integer. */
3296 bc_assemble_integer (exp, size)
3304 /* FIXME: is this fold() business going to be as good as the
3305 expand_expr() using EXPAND_SUM above in the RTL case? I
3307 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3311 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3312 exp = TREE_OPERAND (exp, 0);
3313 if (TREE_CODE (exp) == INTEGER_CST)
3318 else if (TREE_CODE (exp) == PLUS_EXPR)
3320 const_part = TREE_OPERAND (exp, 0);
3321 while (TREE_CODE (const_part) == NOP_EXPR
3322 || TREE_CODE (const_part) == CONVERT_EXPR)
3323 const_part = TREE_OPERAND (const_part, 0);
3324 addr_part = TREE_OPERAND (exp, 1);
3325 while (TREE_CODE (addr_part) == NOP_EXPR
3326 || TREE_CODE (addr_part) == CONVERT_EXPR)
3327 addr_part = TREE_OPERAND (addr_part, 0);
3328 if (TREE_CODE (const_part) != INTEGER_CST)
3329 tmp = const_part, const_part = addr_part, addr_part = tmp;
3330 if (TREE_CODE (const_part) != INTEGER_CST
3331 || TREE_CODE (addr_part) != ADDR_EXPR)
3332 abort (); /* FIXME: we really haven't considered
3333 all the possible cases here. */
3335 else if (TREE_CODE (exp) == ADDR_EXPR)
3337 const_part = integer_zero_node;
3341 abort (); /* FIXME: ditto previous. */
3347 char c = TREE_INT_CST_LOW (const_part);
3353 short s = TREE_INT_CST_LOW (const_part);
3354 bc_emit ((char *) &s, 2);
3359 int i = TREE_INT_CST_LOW (const_part);
3360 bc_emit ((char *) &i, 4);
3365 #if WORDS_BIG_ENDIAN
3366 int i = TREE_INT_CST_HIGH (const_part);
3367 bc_emit ((char *) &i, 4);
3368 i = TREE_INT_CST_LOW (const_part);
3369 bc_emit ((char *) &i, 4);
3371 int i = TREE_INT_CST_LOW (const_part);
3372 bc_emit ((char *) &i, 4);
3373 i = TREE_INT_CST_HIGH (const_part);
3374 bc_emit ((char *) &i, 4);
3381 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3382 bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3383 TREE_INT_CST_LOW (const_part));
3385 abort (); /* FIXME: there may be more cases. */
3388 /* Subroutine of output_constant, used for CONSTRUCTORs
3389 (aggregate constants).
3390 Generate at least SIZE bytes, padding if necessary. */
3393 output_constructor (exp, size)
3397 register tree link, field = 0;
3398 /* Number of bytes output or skipped so far.
3399 In other words, current position within the constructor. */
3400 int total_bytes = 0;
3401 /* Non-zero means BYTE contains part of a byte, to be output. */
3402 int byte_buffer_in_use = 0;
3405 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3408 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3409 field = TYPE_FIELDS (TREE_TYPE (exp));
3411 /* As LINK goes through the elements of the constant,
3412 FIELD goes through the structure fields, if the constant is a structure.
3413 if the constant is a union, then we override this,
3414 by getting the field from the TREE_LIST element.
3415 But the constant could also be an array. Then FIELD is zero. */
3416 for (link = CONSTRUCTOR_ELTS (exp);
3418 link = TREE_CHAIN (link),
3419 field = field ? TREE_CHAIN (field) : 0)
3421 tree val = TREE_VALUE (link);
3424 /* the element in a union constructor specifies the proper field. */
3426 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3427 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3429 /* if available, use the type given by link */
3430 if (TREE_PURPOSE (link) != 0)
3431 field = TREE_PURPOSE (link);
3434 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3435 index = TREE_PURPOSE (link);
3437 /* Eliminate the marker that makes a cast not be an lvalue. */
3441 if (field == 0 || !DECL_BIT_FIELD (field))
3443 /* An element that is not a bit-field. */
3445 register int fieldsize;
3446 /* Since this structure is static,
3447 we know the positions are constant. */
3448 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3452 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3454 * TREE_INT_CST_LOW (index));
3456 /* Output any buffered-up bit-fields preceding this element. */
3457 if (byte_buffer_in_use)
3459 ASM_OUTPUT_BYTE (asm_out_file, byte);
3461 byte_buffer_in_use = 0;
3464 /* Advance to offset of this element.
3465 Note no alignment needed in an array, since that is guaranteed
3466 if each element has the proper size. */
3467 if ((field != 0 || index != 0) && bitpos != total_bytes)
3469 if (!output_bytecode)
3470 assemble_zeros (bitpos - total_bytes);
3472 bc_emit_const_skip (bitpos - total_bytes);
3473 total_bytes = bitpos;
3476 /* Determine size this element should occupy. */
3479 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3481 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3483 /* This avoids overflow trouble. */
3484 tree size_tree = size_binop (CEIL_DIV_EXPR,
3486 size_int (BITS_PER_UNIT));
3487 fieldsize = TREE_INT_CST_LOW (size_tree);
3491 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3492 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3496 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3498 /* Output the element's initial value. */
3500 assemble_zeros (fieldsize);
3502 output_constant (val, fieldsize);
3504 /* Count its size. */
3505 total_bytes += fieldsize;
3507 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3508 error ("invalid initial value for member `%s'",
3509 IDENTIFIER_POINTER (DECL_NAME (field)));
3512 /* Element that is a bit-field. */
3514 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3516 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3519 val = integer_zero_node;
3521 /* If this field does not start in this (or, next) byte,
3523 if (next_offset / BITS_PER_UNIT != total_bytes)
3525 /* Output remnant of any bit field in previous bytes. */
3526 if (byte_buffer_in_use)
3528 ASM_OUTPUT_BYTE (asm_out_file, byte);
3530 byte_buffer_in_use = 0;
3533 /* If still not at proper byte, advance to there. */
3534 if (next_offset / BITS_PER_UNIT != total_bytes)
3536 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3537 total_bytes = next_offset / BITS_PER_UNIT;
3541 if (! byte_buffer_in_use)
3544 /* We must split the element into pieces that fall within
3545 separate bytes, and combine each byte with previous or
3546 following bit-fields. */
3548 /* next_offset is the offset n fbits from the beginning of
3549 the structure to the next bit of this element to be processed.
3550 end_offset is the offset of the first bit past the end of
3552 while (next_offset < end_offset)
3556 int next_byte = next_offset / BITS_PER_UNIT;
3557 int next_bit = next_offset % BITS_PER_UNIT;
3559 /* Advance from byte to byte
3560 within this element when necessary. */
3561 while (next_byte != total_bytes)
3563 ASM_OUTPUT_BYTE (asm_out_file, byte);
3568 /* Number of bits we can process at once
3569 (all part of the same byte). */
3570 this_time = MIN (end_offset - next_offset,
3571 BITS_PER_UNIT - next_bit);
3572 #if BYTES_BIG_ENDIAN
3573 /* On big-endian machine, take the most significant bits
3574 first (of the bits that are significant)
3575 and put them into bytes from the most significant end. */
3576 shift = end_offset - next_offset - this_time;
3577 /* Don't try to take a bunch of bits that cross
3578 the word boundary in the INTEGER_CST. */
3579 if (shift < HOST_BITS_PER_WIDE_INT
3580 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3582 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3583 shift = HOST_BITS_PER_WIDE_INT;
3586 /* Now get the bits from the appropriate constant word. */
3587 if (shift < HOST_BITS_PER_WIDE_INT)
3589 value = TREE_INT_CST_LOW (val);
3591 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3593 value = TREE_INT_CST_HIGH (val);
3594 shift -= HOST_BITS_PER_WIDE_INT;
3598 byte |= (((value >> shift)
3599 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3600 << (BITS_PER_UNIT - this_time - next_bit));
3602 /* On little-endian machines,
3603 take first the least significant bits of the value
3604 and pack them starting at the least significant
3605 bits of the bytes. */
3606 shift = (next_offset
3607 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3608 /* Don't try to take a bunch of bits that cross
3609 the word boundary in the INTEGER_CST. */
3610 if (shift < HOST_BITS_PER_WIDE_INT
3611 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3613 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3614 shift = HOST_BITS_PER_WIDE_INT;
3617 /* Now get the bits from the appropriate constant word. */
3618 if (shift < HOST_BITS_PER_INT)
3619 value = TREE_INT_CST_LOW (val);
3620 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3622 value = TREE_INT_CST_HIGH (val);
3623 shift -= HOST_BITS_PER_WIDE_INT;
3627 byte |= ((value >> shift)
3628 & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
3630 next_offset += this_time;
3631 byte_buffer_in_use = 1;
3635 if (byte_buffer_in_use)
3637 ASM_OUTPUT_BYTE (asm_out_file, byte);
3640 if (total_bytes < size)
3641 assemble_zeros (size - total_bytes);
3645 #ifdef HANDLE_SYSV_PRAGMA
3647 /* Support #pragma weak by default if WEAK_ASM_OP is defined. */
3648 #if defined (HANDLE_PRAGMA_WEAK) || (defined (WEAK_ASM_OP) && defined (SET_ASM_OP))
3650 /* Output asm to handle ``#pragma weak'' */
3652 handle_pragma_weak (what, asm_out_file, name, value)
3653 enum pragma_state what;
3657 if (what == ps_name || what == ps_value)
3659 fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
3661 if (output_bytecode)
3662 BC_OUTPUT_LABELREF (asm_out_file, name);
3664 ASM_OUTPUT_LABELREF (asm_out_file, name);
3666 fputc ('\n', asm_out_file);
3667 if (what == ps_value)
3669 fprintf (asm_out_file, "\t%s\t", SET_ASM_OP);
3670 if (output_bytecode)
3671 BC_OUTPUT_LABELREF (asm_out_file, name);
3673 ASM_OUTPUT_LABELREF (asm_out_file, name);
3675 fputc (',', asm_out_file);
3676 if (output_bytecode)
3677 BC_OUTPUT_LABELREF (asm_out_file, value);
3679 ASM_OUTPUT_LABELREF (asm_out_file, value);
3681 fputc ('\n', asm_out_file);
3684 else if (! (what == ps_done || what == ps_start))
3685 warning ("malformed `#pragma weak'");
3688 #endif /* HANDLE_PRAGMA_WEAK or (WEAK_ASM_OP and SET_ASM_OP) */
3690 #endif /* HANDLE_SYSV_PRAGMA */