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 /* The last decl for which assemble_variable was called,
91 if it did ASM_DECLARE_OBJECT_NAME.
92 If the last call to assemble_variable didn't do that,
95 tree last_assemble_variable_decl;
97 /* Nonzero if at least one function definition has been seen. */
98 static int function_defined;
100 extern FILE *asm_out_file;
102 static char *compare_constant_1 ();
103 static void record_constant_1 ();
104 static void output_constant_def_contents ();
105 static int contains_pointers_p ();
106 static void bc_output_ascii ();
108 void output_constant_pool ();
109 void assemble_name ();
110 int output_addressed_constants ();
111 void output_constant ();
112 void output_constructor ();
113 void output_byte_asm ();
114 void text_section ();
115 void readonly_data_section ();
116 void data_section ();
117 static void bc_assemble_integer ();
119 #ifdef EXTRA_SECTIONS
120 static enum in_section {no_section, in_text, in_data, EXTRA_SECTIONS} in_section
123 static enum in_section {no_section, in_text, in_data} in_section
127 /* Define functions like text_section for any extra sections. */
128 #ifdef EXTRA_SECTION_FUNCTIONS
129 EXTRA_SECTION_FUNCTIONS
132 /* Tell assembler to switch to text section. */
137 if (in_section != in_text)
142 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
144 in_section = in_text;
148 /* Tell assembler to switch to data section. */
153 if (in_section != in_data)
159 if (flag_shared_data)
161 #ifdef SHARED_SECTION_ASM_OP
162 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
164 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
168 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
171 in_section = in_data;
175 /* Tell assembler to switch to read-only data section. This is normally
179 readonly_data_section ()
181 #ifdef READONLY_DATA_SECTION
182 READONLY_DATA_SECTION (); /* Note this can call data_section. */
188 /* Determine if we're in the text section. */
193 return in_section == in_text;
196 /* Create the rtl to represent a function, for a function definition.
197 DECL is a FUNCTION_DECL node which describes which function.
198 The rtl is stored into DECL. */
201 make_function_rtl (decl)
204 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
208 if (DECL_RTL (decl) == 0)
209 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
211 /* Record that at least one function has been defined. */
212 function_defined = 1;
216 /* Rename a nested function to avoid conflicts. */
217 if (decl_function_context (decl) != 0
218 && DECL_INITIAL (decl) != 0
219 && DECL_RTL (decl) == 0)
223 name = IDENTIFIER_POINTER (DECL_NAME (decl));
224 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
225 name = obstack_copy0 (saveable_obstack, label, strlen (label));
229 if (DECL_RTL (decl) == 0)
232 = gen_rtx (MEM, DECL_MODE (decl),
233 gen_rtx (SYMBOL_REF, Pmode, name));
235 /* Optionally set flags or add text to the name to record information
236 such as that it is a function name. If the name is changed, the macro
237 ASM_OUTPUT_LABELREF will have to know how to strip this information.
238 And if it finds a * at the beginning after doing so, it must handle
240 #ifdef ENCODE_SECTION_INFO
241 ENCODE_SECTION_INFO (decl);
245 /* Record at least one function has been defined. */
246 function_defined = 1;
249 /* Create the DECL_RTL for a declaration for a static or external
250 variable or static or external function.
251 ASMSPEC, if not 0, is the string which the user specified
252 as the assembler symbol name.
253 TOP_LEVEL is nonzero if this is a file-scope variable.
254 This is never called for PARM_DECLs. */
256 bc_make_decl_rtl (decl, asmspec, top_level)
261 register char *name = TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl));
263 if (DECL_RTL (decl) == 0)
265 /* Print an error message for register variables. */
266 if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
267 error ("function declared `register'");
268 else if (DECL_REGISTER (decl))
269 error ("global register variables not supported in the interpreter");
271 /* Handle ordinary static variables and functions. */
272 if (DECL_RTL (decl) == 0)
274 /* Can't use just the variable's own name for a variable
275 whose scope is less than the whole file.
276 Concatenate a distinguishing number. */
277 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
281 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
282 name = obstack_copy0 (saveable_obstack, label, strlen (label));
286 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
291 /* Given NAME, a putative register name, discard any customary prefixes. */
294 strip_reg_name (name)
297 #ifdef REGISTER_PREFIX
298 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
299 name += strlen (REGISTER_PREFIX);
301 if (name[0] == '%' || name[0] == '#')
306 /* Decode an `asm' spec for a declaration as a register name.
307 Return the register number, or -1 if nothing specified,
308 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
309 or -3 if ASMSPEC is `cc' and is not recognized,
310 or -4 if ASMSPEC is `memory' and is not recognized.
311 Accept an exact spelling or a decimal number.
312 Prefixes such as % are optional. */
315 decode_reg_name (asmspec)
322 /* Get rid of confusing prefixes. */
323 asmspec = strip_reg_name (asmspec);
325 /* Allow a decimal number as a "register name". */
326 for (i = strlen (asmspec) - 1; i >= 0; i--)
327 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
329 if (asmspec[0] != 0 && i < 0)
332 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
338 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
340 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
343 #ifdef ADDITIONAL_REGISTER_NAMES
345 static struct { char *name; int number; } table[]
346 = ADDITIONAL_REGISTER_NAMES;
348 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
349 if (! strcmp (asmspec, table[i].name))
350 return table[i].number;
352 #endif /* ADDITIONAL_REGISTER_NAMES */
354 if (!strcmp (asmspec, "memory"))
357 if (!strcmp (asmspec, "cc"))
366 /* Create the DECL_RTL for a declaration for a static or external variable
367 or static or external function.
368 ASMSPEC, if not 0, is the string which the user specified
369 as the assembler symbol name.
370 TOP_LEVEL is nonzero if this is a file-scope variable.
372 This is never called for PARM_DECL nodes. */
375 make_decl_rtl (decl, asmspec, top_level)
385 bc_make_decl_rtl (decl, asmspec, top_level);
389 reg_number = decode_reg_name (asmspec);
391 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
392 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
394 if (reg_number == -2)
396 /* ASMSPEC is given, and not the name of a register. */
397 name = (char *) obstack_alloc (saveable_obstack,
398 strlen (asmspec) + 2);
400 strcpy (&name[1], asmspec);
403 /* For a duplicate declaration, we can be called twice on the
404 same DECL node. Don't discard the RTL already made. */
405 if (DECL_RTL (decl) == 0)
409 /* First detect errors in declaring global registers. */
410 if (DECL_REGISTER (decl) && reg_number == -1)
411 error_with_decl (decl,
412 "register name not specified for `%s'");
413 else if (DECL_REGISTER (decl) && reg_number < 0)
414 error_with_decl (decl,
415 "invalid register name for `%s'");
416 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
417 error_with_decl (decl,
418 "register name given for non-register variable `%s'");
419 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
420 error ("function declared `register'");
421 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
422 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
423 else if (DECL_REGISTER (decl)
424 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
425 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
426 /* Now handle properly declared static register variables. */
427 else if (DECL_REGISTER (decl))
430 #if 0 /* yylex should print the warning for this */
432 pedwarn ("ANSI C forbids global register variables");
434 if (DECL_INITIAL (decl) != 0 && top_level)
436 DECL_INITIAL (decl) = 0;
437 error ("global register variable has initial value");
439 if (fixed_regs[reg_number] == 0
440 && function_defined && top_level)
441 error ("global register variable follows a function definition");
442 if (TREE_THIS_VOLATILE (decl))
443 warning ("volatile register variables don't work as you might wish");
445 /* If the user specified one of the eliminables registers here,
446 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
447 confused with that register and be eliminated. Although this
448 usage is somewhat suspect, we nevertheless use the following
449 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
452 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
453 REGNO (DECL_RTL (decl)) = reg_number;
454 REG_USERVAR_P (DECL_RTL (decl)) = 1;
458 /* Make this register fixed, so not usable for anything else. */
459 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
461 global_regs[reg_number + --nregs] = 1;
466 /* Now handle ordinary static variables and functions (in memory).
467 Also handle vars declared register invalidly. */
468 if (DECL_RTL (decl) == 0)
470 /* Can't use just the variable's own name for a variable
471 whose scope is less than the whole file.
472 Concatenate a distinguishing number. */
473 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
477 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
478 name = obstack_copy0 (saveable_obstack, label, strlen (label));
482 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
483 gen_rtx (SYMBOL_REF, Pmode, name));
485 /* If this variable is to be treated as volatile, show its
486 tree node has side effects. If it has side effects, either
487 because of this test or from TREE_THIS_VOLATILE also
488 being set, show the MEM is volatile. */
489 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
490 && TREE_PUBLIC (decl))
491 TREE_SIDE_EFFECTS (decl) = 1;
492 if (TREE_SIDE_EFFECTS (decl))
493 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
495 if (TREE_READONLY (decl))
496 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
497 MEM_IN_STRUCT_P (DECL_RTL (decl))
498 = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
499 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
500 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
501 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE);
503 /* Optionally set flags or add text to the name to record information
504 such as that it is a function name.
505 If the name is changed, the macro ASM_OUTPUT_LABELREF
506 will have to know how to strip this information.
507 And if it finds a * at the beginning after doing so,
508 it must handle that too. */
509 #ifdef ENCODE_SECTION_INFO
510 ENCODE_SECTION_INFO (decl);
514 /* If the old RTL had the wrong mode, fix the mode. */
515 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
517 rtx rtl = DECL_RTL (decl);
518 PUT_MODE (rtl, DECL_MODE (decl));
522 /* Make the rtl for variable VAR be volatile.
523 Use this only for static variables. */
526 make_var_volatile (var)
529 if (GET_CODE (DECL_RTL (var)) != MEM)
532 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
535 /* Output alignment directive to align for constant expression EXP. */
538 assemble_constant_align (exp)
543 /* Align the location counter as required by EXP's data type. */
544 align = TYPE_ALIGN (TREE_TYPE (exp));
545 #ifdef CONSTANT_ALIGNMENT
546 align = CONSTANT_ALIGNMENT (exp, align);
549 if (align > BITS_PER_UNIT)
550 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
553 /* Output a string of literal assembler code
554 for an `asm' keyword used between functions. */
557 assemble_asm (string)
562 error ("asm statements not allowed in interpreter");
568 if (TREE_CODE (string) == ADDR_EXPR)
569 string = TREE_OPERAND (string, 0);
571 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
574 #if 0 /* This should no longer be needed, because
575 flag_gnu_linker should be 0 on these systems,
576 which should prevent any output
577 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
578 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
579 #ifndef ASM_OUTPUT_CONSTRUCTOR
580 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
582 #ifndef ASM_OUTPUT_DESTRUCTOR
583 #define ASM_OUTPUT_DESTRUCTOR(file, name)
588 /* Record an element in the table of global destructors.
589 How this is done depends on what sort of assembler and linker
592 NAME should be the name of a global function to be called
593 at exit time. This name is output using assemble_name. */
596 assemble_destructor (name)
599 #ifdef ASM_OUTPUT_DESTRUCTOR
600 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
604 /* Now tell GNU LD that this is part of the static destructor set. */
605 /* This code works for any machine provided you use GNU as/ld. */
606 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
607 assemble_name (asm_out_file, name);
608 fputc ('\n', asm_out_file);
613 /* Likewise for global constructors. */
616 assemble_constructor (name)
619 #ifdef ASM_OUTPUT_CONSTRUCTOR
620 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
624 /* Now tell GNU LD that this is part of the static constructor set. */
625 /* This code works for any machine provided you use GNU as/ld. */
626 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
627 assemble_name (asm_out_file, name);
628 fputc ('\n', asm_out_file);
633 /* Likewise for entries we want to record for garbage collection.
634 Garbage collection is still under development. */
637 assemble_gc_entry (name)
640 #ifdef ASM_OUTPUT_GC_ENTRY
641 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
645 /* Now tell GNU LD that this is part of the static constructor set. */
646 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
647 assemble_name (asm_out_file, name);
648 fputc ('\n', asm_out_file);
653 /* Output assembler code for the constant pool of a function and associated
654 with defining the name of the function. DECL describes the function.
655 NAME is the function's name. For the constant pool, we use the current
656 constant pool data. */
659 assemble_start_function (decl, fnname)
665 /* The following code does not need preprocessing in the assembler. */
669 output_constant_pool (fnname, decl);
674 /* Tell assembler to move to target machine's alignment for functions. */
675 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
679 BC_OUTPUT_ALIGN (asm_out_file, align);
681 ASM_OUTPUT_ALIGN (asm_out_file, align);
684 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
685 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
688 #ifdef SDB_DEBUGGING_INFO
689 /* Output SDB definition of the function. */
690 if (write_symbols == SDB_DEBUG)
691 sdbout_mark_begin_function ();
694 #ifdef DBX_DEBUGGING_INFO
695 /* Output DBX definition of the function. */
696 if (write_symbols == DBX_DEBUG)
697 dbxout_begin_function (decl);
700 /* Make function name accessible from other files, if appropriate. */
702 if (TREE_PUBLIC (decl))
704 if (!first_global_object_name)
705 STRIP_NAME_ENCODING (first_global_object_name, fnname);
707 BC_GLOBALIZE_LABEL (asm_out_file, fnname);
709 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
712 /* Do any machine/system dependent processing of the function name */
713 #ifdef ASM_DECLARE_FUNCTION_NAME
714 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
716 /* Standard thing is just output label for the function. */
718 BC_OUTPUT_LABEL (asm_out_file, fnname);
720 ASM_OUTPUT_LABEL (asm_out_file, fnname);
721 #endif /* ASM_DECLARE_FUNCTION_NAME */
724 /* Output assembler code associated with defining the size of the
725 function. DECL describes the function. NAME is the function's name. */
728 assemble_end_function (decl, fnname)
732 #ifdef ASM_DECLARE_FUNCTION_SIZE
733 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
737 /* Assemble code to leave SIZE bytes of zeros. */
740 assemble_zeros (size)
745 bc_emit_const_skip (size);
749 #ifdef ASM_NO_SKIP_IN_TEXT
750 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
751 so we must output 0s explicitly in the text section. */
752 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
756 for (i = 0; i < size - 20; i += 20)
759 fprintf (asm_out_file,
760 "%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);
762 fprintf (asm_out_file,
763 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
769 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
771 fprintf (asm_out_file, "\tbyte 0");
774 for (; i < size; i++)
775 fprintf (asm_out_file, ",0");
776 fprintf (asm_out_file, "\n");
784 BC_OUTPUT_SKIP (asm_out_file, size);
786 ASM_OUTPUT_SKIP (asm_out_file, size);
790 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
793 assemble_align (align)
796 if (align > BITS_PER_UNIT)
797 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
800 /* Assemble a string constant with the specified C string as contents. */
803 assemble_string (p, size)
817 /* If the string is very long, split it up. */
821 int thissize = size - pos;
822 if (thissize > maximum)
826 bc_output_ascii (asm_out_file, p, thissize);
829 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
838 bc_output_ascii (file, p, size)
843 BC_OUTPUT_ASCII (file, p, size);
846 /* Assemble everything that is needed for a variable or function declaration.
847 Not used for automatic variables, and not used for function definitions.
848 Should not be called for variables of incomplete structure type.
850 TOP_LEVEL is nonzero if this variable has file scope.
851 AT_END is nonzero if this is the special handling, at end of compilation,
852 to define things that have had only tentative definitions.
853 DONT_OUTPUT_DATA if nonzero means don't actually output the
854 initial value (that will be done by the caller). */
857 assemble_variable (decl, top_level, at_end, dont_output_data)
866 enum in_section saved_in_section;
868 last_assemble_variable_decl = 0;
873 if (GET_CODE (DECL_RTL (decl)) == REG)
875 /* Do output symbol info for global register variables, but do nothing
878 if (TREE_ASM_WRITTEN (decl))
880 TREE_ASM_WRITTEN (decl) = 1;
882 if (!output_bytecode)
884 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
885 /* File-scope global variables are output here. */
886 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
888 dbxout_symbol (decl, 0);
890 #ifdef SDB_DEBUGGING_INFO
891 if (write_symbols == SDB_DEBUG && top_level
892 /* Leave initialized global vars for end of compilation;
893 see comment in compile_file. */
894 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
895 sdbout_symbol (decl, 0);
899 /* Don't output any DWARF debugging information for variables here.
900 In the case of local variables, the information for them is output
901 when we do our recursive traversal of the tree representation for
902 the entire containing function. In the case of file-scope variables,
903 we output information for all of them at the very end of compilation
904 while we are doing our final traversal of the chain of file-scope
910 /* Normally no need to say anything here for external references,
911 since assemble_external is called by the langauge-specific code
912 when a declaration is first seen. */
914 if (DECL_EXTERNAL (decl))
917 /* Output no assembler code for a function declaration.
918 Only definitions of functions output anything. */
920 if (TREE_CODE (decl) == FUNCTION_DECL)
923 /* If type was incomplete when the variable was declared,
924 see if it is complete now. */
926 if (DECL_SIZE (decl) == 0)
927 layout_decl (decl, 0);
929 /* Still incomplete => don't allocate it; treat the tentative defn
930 (which is what it must have been) as an `extern' reference. */
932 if (!dont_output_data && DECL_SIZE (decl) == 0)
934 error_with_file_and_line (DECL_SOURCE_FILE (decl),
935 DECL_SOURCE_LINE (decl),
936 "storage size of `%s' isn't known",
937 IDENTIFIER_POINTER (DECL_NAME (decl)));
941 /* The first declaration of a variable that comes through this function
942 decides whether it is global (in C, has external linkage)
943 or local (in C, has internal linkage). So do nothing more
944 if this function has already run. */
946 if (TREE_ASM_WRITTEN (decl))
949 TREE_ASM_WRITTEN (decl) = 1;
951 /* If storage size is erroneously variable, just continue.
952 Error message was already made. */
954 if (DECL_SIZE (decl))
956 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
961 /* This is better than explicit arithmetic, since it avoids overflow. */
962 size_tree = size_binop (CEIL_DIV_EXPR,
963 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
965 if (TREE_INT_CST_HIGH (size_tree) != 0)
967 error_with_decl (decl, "size of variable `%s' is too large");
972 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
974 /* Handle uninitialized definitions. */
976 /* ANSI specifies that a tentative definition which is not merged with
977 a non-tentative definition behaves exactly like a definition with an
978 initializer equal to zero. (Section 3.7.2)
979 -fno-common gives strict ANSI behavior. Usually you don't want it.
980 This matters only for variables with external linkage. */
981 if ((! flag_no_common || ! TREE_PUBLIC (decl))
982 && ! dont_output_data
983 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
985 int size = TREE_INT_CST_LOW (size_tree);
988 if (TREE_INT_CST_HIGH (size_tree) != 0)
989 error_with_decl (decl, "size of variable `%s' is too large");
990 /* Don't allocate zero bytes of common,
991 since that means "undefined external" in the linker. */
992 if (size == 0) rounded = 1;
993 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
994 so that each uninitialized object starts on such a boundary. */
995 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
996 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
997 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
999 #ifdef DBX_DEBUGGING_INFO
1000 /* File-scope global variables are output here. */
1001 if (write_symbols == DBX_DEBUG && top_level)
1002 dbxout_symbol (decl, 0);
1004 #ifdef SDB_DEBUGGING_INFO
1005 if (write_symbols == SDB_DEBUG && top_level
1006 /* Leave initialized global vars for end of compilation;
1007 see comment in compile_file. */
1008 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1009 sdbout_symbol (decl, 0);
1012 /* Don't output any DWARF debugging information for variables here.
1013 In the case of local variables, the information for them is output
1014 when we do our recursive traversal of the tree representation for
1015 the entire containing function. In the case of file-scope variables,
1016 we output information for all of them at the very end of compilation
1017 while we are doing our final traversal of the chain of file-scope
1021 if (flag_shared_data)
1024 if (TREE_PUBLIC (decl))
1026 #ifdef ASM_OUTPUT_SHARED_COMMON
1027 if (flag_shared_data)
1028 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1031 if (output_bytecode)
1033 BC_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1037 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1038 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1041 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1047 #ifdef ASM_OUTPUT_SHARED_LOCAL
1048 if (flag_shared_data)
1049 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1052 if (output_bytecode)
1054 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1058 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1059 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1062 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1069 /* Handle initialized definitions. */
1071 /* First make the assembler name(s) global if appropriate. */
1072 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1074 if (!first_global_object_name)
1075 STRIP_NAME_ENCODING(first_global_object_name, name);
1076 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1079 for (d = equivalents; d; d = TREE_CHAIN (d))
1081 tree e = TREE_VALUE (d);
1082 if (TREE_PUBLIC (e) && DECL_NAME (e))
1083 ASM_GLOBALIZE_LABEL (asm_out_file,
1084 XSTR (XEXP (DECL_RTL (e), 0), 0));
1088 /* Output any data that we will need to use the address of. */
1089 if (DECL_INITIAL (decl) == error_mark_node)
1090 reloc = contains_pointers_p (TREE_TYPE (decl));
1091 else if (DECL_INITIAL (decl))
1092 reloc = output_addressed_constants (DECL_INITIAL (decl));
1094 /* Switch to the proper section for this data. */
1095 #ifdef SELECT_SECTION
1096 SELECT_SECTION (decl, reloc);
1098 if (TREE_READONLY (decl)
1099 && ! TREE_THIS_VOLATILE (decl)
1100 && ! (flag_pic && reloc))
1101 readonly_data_section ();
1106 /* Record current section so we can restore it if dbxout.c clobbers it. */
1107 saved_in_section = in_section;
1109 /* Output the dbx info now that we have chosen the section. */
1111 #ifdef DBX_DEBUGGING_INFO
1112 /* File-scope global variables are output here. */
1113 if (write_symbols == DBX_DEBUG && top_level)
1114 dbxout_symbol (decl, 0);
1116 #ifdef SDB_DEBUGGING_INFO
1117 if (write_symbols == SDB_DEBUG && top_level
1118 /* Leave initialized global vars for end of compilation;
1119 see comment in compile_file. */
1120 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1121 sdbout_symbol (decl, 0);
1124 /* Don't output any DWARF debugging information for variables here.
1125 In the case of local variables, the information for them is output
1126 when we do our recursive traversal of the tree representation for
1127 the entire containing function. In the case of file-scope variables,
1128 we output information for all of them at the very end of compilation
1129 while we are doing our final traversal of the chain of file-scope
1132 if (in_section != saved_in_section)
1134 /* Switch to the proper section for this data. */
1135 #ifdef SELECT_SECTION
1136 SELECT_SECTION (decl, reloc);
1138 if (TREE_READONLY (decl)
1139 && ! TREE_THIS_VOLATILE (decl)
1140 && ! (flag_pic && reloc))
1141 readonly_data_section ();
1147 /* dbxout.c needs to know this. */
1148 if (in_text_section ())
1149 DECL_IN_TEXT_SECTION (decl) = 1;
1151 /* Compute and output the alignment of this data. */
1153 align = DECL_ALIGN (decl);
1154 /* In the case for initialing an array whose length isn't specified,
1155 where we have not yet been able to do the layout,
1156 figure out the proper alignment now. */
1157 if (dont_output_data && DECL_SIZE (decl) == 0
1158 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1159 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1161 /* Some object file formats have a maximum alignment which they support.
1162 In particular, a.out format supports a maximum alignment of 4. */
1163 #ifndef MAX_OFILE_ALIGNMENT
1164 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1166 if (align > MAX_OFILE_ALIGNMENT)
1168 warning_with_decl (decl,
1169 "alignment of `%s' is greater than maximum object file alignment");
1170 align = MAX_OFILE_ALIGNMENT;
1172 #ifdef DATA_ALIGNMENT
1173 /* On some machines, it is good to increase alignment sometimes. */
1174 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1176 #ifdef CONSTANT_ALIGNMENT
1177 if (DECL_INITIAL (decl))
1178 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1181 /* Reset the alignment in case we have made it tighter, so we can benefit
1182 from it in get_pointer_alignment. */
1183 DECL_ALIGN (decl) = align;
1185 if (align > BITS_PER_UNIT)
1187 if (output_bytecode)
1188 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1190 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1193 /* Do any machine/system dependent processing of the object. */
1194 #ifdef ASM_DECLARE_OBJECT_NAME
1195 last_assemble_variable_decl = decl;
1196 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1198 /* Standard thing is just output label for the object. */
1199 if (output_bytecode)
1200 BC_OUTPUT_LABEL (asm_out_file, name);
1202 ASM_OUTPUT_LABEL (asm_out_file, name);
1203 #endif /* ASM_DECLARE_OBJECT_NAME */
1205 if (!dont_output_data)
1207 if (DECL_INITIAL (decl))
1208 /* Output the actual data. */
1209 output_constant (DECL_INITIAL (decl),
1210 int_size_in_bytes (TREE_TYPE (decl)));
1212 /* Leave space for it. */
1213 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1217 #ifdef XCOFF_DEBUGGING_INFO
1218 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1219 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1220 and `aa' hasn't been output yet, the assembler generates a stab entry with
1221 a value of zero, in addition to creating an unnecessary external entry
1222 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1224 /* File-scope global variables are output here. */
1225 if (write_symbols == XCOFF_DEBUG && top_level)
1227 saved_in_section = in_section;
1229 dbxout_symbol (decl, 0);
1231 if (in_section != saved_in_section)
1233 /* Switch to the proper section for this data. */
1234 #ifdef SELECT_SECTION
1235 SELECT_SECTION (decl, reloc);
1237 if (TREE_READONLY (decl)
1238 && ! TREE_THIS_VOLATILE (decl)
1239 && ! (flag_pic && reloc))
1240 readonly_data_section ();
1247 /* There must be a statement after a label. */
1252 /* Return 1 if type TYPE contains any pointers. */
1255 contains_pointers_p (type)
1258 switch (TREE_CODE (type))
1261 case REFERENCE_TYPE:
1262 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1263 so I'll play safe and return 1. */
1269 case QUAL_UNION_TYPE:
1272 /* For a type that has fields, see if the fields have pointers. */
1273 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1274 if (contains_pointers_p (TREE_TYPE (fields)))
1280 /* An array type contains pointers if its element type does. */
1281 return contains_pointers_p (TREE_TYPE (type));
1288 /* Output text storage for constructor CONSTR. Returns rtx of
1292 bc_output_constructor (constr)
1297 /* Must always be a literal; non-literal constructors are handled
1300 if (!TREE_CONSTANT (constr))
1307 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1309 BC_OUTPUT_ALIGN (asm_out_file, i);
1312 output_constant (constr, int_size_in_bytes (TREE_TYPE (constr)));
1316 /* Create storage for constructor CONSTR. */
1319 bc_output_data_constructor (constr)
1324 /* Put in data section */
1328 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1330 BC_OUTPUT_ALIGN (asm_out_file, i);
1332 /* The constructor is filled in at runtime. */
1333 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1337 /* Output something to declare an external symbol to the assembler.
1338 (Most assemblers don't need this, so we normally output nothing.)
1339 Do nothing if DECL is not external. */
1342 assemble_external (decl)
1345 if (output_bytecode)
1348 #ifdef ASM_OUTPUT_EXTERNAL
1349 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1350 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1352 rtx rtl = DECL_RTL (decl);
1354 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1355 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1357 /* Some systems do require some output. */
1358 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1359 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1365 /* Similar, for calling a library function FUN. */
1368 assemble_external_libcall (fun)
1371 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1372 if (!output_bytecode)
1374 /* Declare library function name external when first used, if nec. */
1375 if (! SYMBOL_REF_USED (fun))
1377 SYMBOL_REF_USED (fun) = 1;
1378 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1384 /* Declare the label NAME global. */
1387 assemble_global (name)
1390 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1393 /* Assemble a label named NAME. */
1396 assemble_label (name)
1399 if (output_bytecode)
1400 BC_OUTPUT_LABEL (asm_out_file, name);
1402 ASM_OUTPUT_LABEL (asm_out_file, name);
1405 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1406 If NAME starts with a *, the rest of NAME is output verbatim.
1407 Otherwise NAME is transformed in an implementation-defined way
1408 (usually by the addition of an underscore).
1409 Many macros in the tm file are defined to call this function. */
1412 assemble_name (file, name)
1418 if (output_bytecode)
1419 bc_emit_labelref (name);
1421 fputs (&name[1], file);
1425 if (output_bytecode)
1426 BC_OUTPUT_LABELREF (file, name);
1428 ASM_OUTPUT_LABELREF (file, name);
1432 /* Allocate SIZE bytes writable static space with a gensym name
1433 and return an RTX to refer to its address. */
1436 assemble_static_space (size)
1442 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1443 so that each uninitialized object starts on such a boundary. */
1444 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1445 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1446 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1449 if (flag_shared_data)
1453 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1456 namestring = (char *) obstack_alloc (saveable_obstack,
1458 strcpy (namestring, name);
1460 if (output_bytecode)
1461 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1463 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1465 if (output_bytecode)
1467 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1471 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1472 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1474 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1480 /* Assemble the static constant template for function entry trampolines.
1481 This is done at most once per compilation.
1482 Returns an RTX for the address of the template. */
1485 assemble_trampoline_template ()
1491 /* Shouldn't get here */
1492 if (output_bytecode)
1495 /* By default, put trampoline templates in read-only data section. */
1497 #ifdef TRAMPOLINE_SECTION
1498 TRAMPOLINE_SECTION ();
1500 readonly_data_section ();
1503 /* Write the assembler code to define one. */
1504 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1506 ASM_OUTPUT_ALIGN (asm_out_file, align);
1508 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1509 TRAMPOLINE_TEMPLATE (asm_out_file);
1511 /* Record the rtl to refer to it. */
1512 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1514 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1515 return gen_rtx (SYMBOL_REF, Pmode, name);
1518 /* Assemble the integer constant X into an object of SIZE bytes.
1519 X must be either a CONST_INT or CONST_DOUBLE.
1521 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1522 non-zero, abort if we can't output the constant. */
1525 assemble_integer (x, size, force)
1530 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1531 ASM_OUTPUT... macros. */
1535 #ifdef ASM_OUTPUT_CHAR
1537 ASM_OUTPUT_CHAR (asm_out_file, x);
1541 #ifdef ASM_OUTPUT_SHORT
1543 ASM_OUTPUT_SHORT (asm_out_file, x);
1547 #ifdef ASM_OUTPUT_INT
1549 ASM_OUTPUT_INT (asm_out_file, x);
1553 #ifdef ASM_OUTPUT_DOUBLE_INT
1555 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1559 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1561 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1566 /* If we couldn't do it that way, there are two other possibilities: First,
1567 if the machine can output an explicit byte and this is a 1 byte constant,
1568 we can use ASM_OUTPUT_BYTE. */
1570 #ifdef ASM_OUTPUT_BYTE
1571 if (size == 1 && GET_CODE (x) == CONST_INT)
1573 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1578 /* Finally, if SIZE is larger than a single word, try to output the constant
1579 one word at a time. */
1581 if (size > UNITS_PER_WORD)
1584 enum machine_mode mode
1585 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1588 for (i = 0; i < size / UNITS_PER_WORD; i++)
1590 word = operand_subword (x, i, 0, mode);
1595 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1599 if (i == size / UNITS_PER_WORD)
1601 /* If we output at least one word and then could not finish,
1602 there is no valid way to continue. */
1613 /* Assemble the floating-point constant D into an object of size MODE. */
1616 assemble_real (d, mode)
1618 enum machine_mode mode;
1620 jmp_buf output_constant_handler;
1622 if (setjmp (output_constant_handler))
1624 error ("floating point trap outputting a constant");
1625 #ifdef REAL_IS_NOT_DOUBLE
1626 bzero (&d, sizeof d);
1633 set_float_handler (output_constant_handler);
1637 #ifdef ASM_OUTPUT_BYTE_FLOAT
1639 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1642 #ifdef ASM_OUTPUT_SHORT_FLOAT
1644 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1647 #ifdef ASM_OUTPUT_FLOAT
1649 ASM_OUTPUT_FLOAT (asm_out_file, d);
1653 #ifdef ASM_OUTPUT_DOUBLE
1655 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1659 #ifdef ASM_OUTPUT_LONG_DOUBLE
1662 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1670 set_float_handler (NULL_PTR);
1673 /* Here we combine duplicate floating constants to make
1674 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1676 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1677 They are chained through the CONST_DOUBLE_CHAIN.
1678 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1679 In that case, CONST_DOUBLE_MEM is either a MEM,
1680 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1682 (CONST_DOUBLE_MEM is used only for top-level functions.
1683 See force_const_mem for explanation.) */
1685 static rtx const_double_chain;
1687 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1688 For an integer, I0 is the low-order word and I1 is the high-order word.
1689 For a real number, I0 is the word with the low address
1690 and I1 is the word with the high address. */
1693 immed_double_const (i0, i1, mode)
1694 HOST_WIDE_INT i0, i1;
1695 enum machine_mode mode;
1698 int in_current_obstack;
1700 if (GET_MODE_CLASS (mode) == MODE_INT
1701 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1703 /* We clear out all bits that don't belong in MODE, unless they and our
1704 sign bit are all one. So we get either a reasonable negative value
1705 or a reasonable unsigned value for this mode. */
1706 int width = GET_MODE_BITSIZE (mode);
1707 if (width < HOST_BITS_PER_WIDE_INT
1708 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1709 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1710 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1711 else if (width == HOST_BITS_PER_WIDE_INT
1712 && ! (i1 == ~0 && i0 < 0))
1714 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1715 /* We cannot represent this value as a constant. */
1718 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1720 ??? Strictly speaking, this is wrong if we create a CONST_INT
1721 for a large unsigned constant with the size of MODE being
1722 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1723 wider mode. In that case we will mis-interpret it as a negative
1726 Unfortunately, the only alternative is to make a CONST_DOUBLE
1727 for any constant in any mode if it is an unsigned constant larger
1728 than the maximum signed integer in an int on the host. However,
1729 doing this will break everyone that always expects to see a CONST_INT
1730 for SImode and smaller.
1732 We have always been making CONST_INTs in this case, so nothing new
1735 if (width <= HOST_BITS_PER_WIDE_INT)
1736 i1 = (i0 < 0) ? ~0 : 0;
1738 /* If this integer fits in one word, return a CONST_INT. */
1739 if ((i1 == 0 && i0 >= 0)
1740 || (i1 == ~0 && i0 < 0))
1741 return GEN_INT (i0);
1743 /* We use VOIDmode for integers. */
1747 /* Search the chain for an existing CONST_DOUBLE with the right value.
1748 If one is found, return it. */
1750 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1751 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1752 && GET_MODE (r) == mode)
1755 /* No; make a new one and add it to the chain.
1757 We may be called by an optimizer which may be discarding any memory
1758 allocated during its processing (such as combine and loop). However,
1759 we will be leaving this constant on the chain, so we cannot tolerate
1760 freed memory. So switch to saveable_obstack for this allocation
1761 and then switch back if we were in current_obstack. */
1763 push_obstacks_nochange ();
1764 rtl_in_saveable_obstack ();
1765 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1768 /* Don't touch const_double_chain in nested function; see force_const_mem.
1769 Also, don't touch it if not inside any function. */
1770 if (outer_function_chain == 0 && current_function_decl != 0)
1772 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1773 const_double_chain = r;
1776 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1777 Actual use of mem-slot is only through force_const_mem. */
1779 CONST_DOUBLE_MEM (r) = const0_rtx;
1784 /* Return a CONST_DOUBLE for a specified `double' value
1785 and machine mode. */
1788 immed_real_const_1 (d, mode)
1790 enum machine_mode mode;
1792 union real_extract u;
1794 int in_current_obstack;
1796 /* Get the desired `double' value as a sequence of ints
1797 since that is how they are stored in a CONST_DOUBLE. */
1801 /* Detect special cases. */
1803 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1804 if (!bcmp (&dconst0, &d, sizeof d))
1805 return CONST0_RTX (mode);
1806 /* Check for NaN first, because some ports (specifically the i386) do not
1807 emit correct ieee-fp code by default, and thus will generate a core
1808 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1809 does a floating point comparison. */
1810 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1811 return CONST1_RTX (mode);
1813 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1814 return immed_double_const (u.i[0], u.i[1], mode);
1816 /* The rest of this function handles the case where
1817 a float value requires more than 2 ints of space.
1818 It will be deleted as dead code on machines that don't need it. */
1820 /* Search the chain for an existing CONST_DOUBLE with the right value.
1821 If one is found, return it. */
1823 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1824 if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
1825 && GET_MODE (r) == mode)
1828 /* No; make a new one and add it to the chain.
1830 We may be called by an optimizer which may be discarding any memory
1831 allocated during its processing (such as combine and loop). However,
1832 we will be leaving this constant on the chain, so we cannot tolerate
1833 freed memory. So switch to saveable_obstack for this allocation
1834 and then switch back if we were in current_obstack. */
1836 push_obstacks_nochange ();
1837 rtl_in_saveable_obstack ();
1838 r = rtx_alloc (CONST_DOUBLE);
1840 bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
1843 /* Don't touch const_double_chain in nested function; see force_const_mem.
1844 Also, don't touch it if not inside any function. */
1845 if (outer_function_chain == 0 && current_function_decl != 0)
1847 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1848 const_double_chain = r;
1851 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1852 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1853 is only through force_const_mem. */
1855 CONST_DOUBLE_MEM (r) = const0_rtx;
1860 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1861 which must be a REAL_CST tree node. */
1864 immed_real_const (exp)
1867 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1870 /* At the end of a function, forget the memory-constants
1871 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1872 Also clear out real_constant_chain and clear out all the chain-pointers. */
1875 clear_const_double_mem ()
1877 register rtx r, next;
1879 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1880 See force_const_mem for explanation. */
1881 if (outer_function_chain != 0)
1884 for (r = const_double_chain; r; r = next)
1886 next = CONST_DOUBLE_CHAIN (r);
1887 CONST_DOUBLE_CHAIN (r) = 0;
1888 CONST_DOUBLE_MEM (r) = cc0_rtx;
1890 const_double_chain = 0;
1893 /* Given an expression EXP with a constant value,
1894 reduce it to the sum of an assembler symbol and an integer.
1895 Store them both in the structure *VALUE.
1896 Abort if EXP does not reduce. */
1901 HOST_WIDE_INT offset;
1905 decode_addr_const (exp, value)
1907 struct addr_const *value;
1909 register tree target = TREE_OPERAND (exp, 0);
1910 register int offset = 0;
1915 if (TREE_CODE (target) == COMPONENT_REF
1916 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
1919 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
1920 target = TREE_OPERAND (target, 0);
1922 else if (TREE_CODE (target) == ARRAY_REF)
1924 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
1925 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
1927 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
1928 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
1930 target = TREE_OPERAND (target, 0);
1936 switch (TREE_CODE (target))
1940 x = DECL_RTL (target);
1944 if (output_bytecode)
1945 /* FIXME: this may not be correct, check it */
1946 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
1948 x = gen_rtx (MEM, FUNCTION_MODE,
1949 gen_rtx (LABEL_REF, VOIDmode,
1950 label_rtx (TREE_OPERAND (exp, 0))));
1957 x = TREE_CST_RTL (target);
1964 if (!output_bytecode)
1966 if (GET_CODE (x) != MEM)
1972 value->offset = offset;
1975 /* Uniquize all constants that appear in memory.
1976 Each constant in memory thus far output is recorded
1977 in `const_hash_table' with a `struct constant_descriptor'
1978 that contains a polish representation of the value of
1981 We cannot store the trees in the hash table
1982 because the trees may be temporary. */
1984 struct constant_descriptor
1986 struct constant_descriptor *next;
1992 #define MAX_HASH_TABLE 1009
1993 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
1995 /* Compute a hash code for a constant expression. */
2002 register int len, hi, i;
2003 register enum tree_code code = TREE_CODE (exp);
2005 if (code == INTEGER_CST)
2007 p = (char *) &TREE_INT_CST_LOW (exp);
2008 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2010 else if (code == REAL_CST)
2012 p = (char *) &TREE_REAL_CST (exp);
2013 len = sizeof TREE_REAL_CST (exp);
2015 else if (code == STRING_CST)
2016 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2017 else if (code == COMPLEX_CST)
2018 return const_hash (TREE_REALPART (exp)) * 5
2019 + const_hash (TREE_IMAGPART (exp));
2020 else if (code == CONSTRUCTOR)
2024 /* For record type, include the type in the hashing.
2025 We do not do so for array types
2026 because (1) the sizes of the elements are sufficient
2027 and (2) distinct array types can have the same constructor.
2028 Instead, we include the array size because the constructor could
2030 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2031 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2034 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2035 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2037 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2038 if (TREE_VALUE (link))
2039 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2043 else if (code == ADDR_EXPR)
2045 struct addr_const value;
2046 decode_addr_const (exp, &value);
2047 if (GET_CODE (value.base) == SYMBOL_REF)
2049 /* Don't hash the address of the SYMBOL_REF;
2050 only use the offset and the symbol name. */
2052 p = XSTR (value.base, 0);
2053 for (i = 0; p[i] != 0; i++)
2054 hi = ((hi * 613) + (unsigned)(p[i]));
2056 else if (GET_CODE (value.base) == LABEL_REF)
2057 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2059 hi &= (1 << HASHBITS) - 1;
2060 hi %= MAX_HASH_TABLE;
2063 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2064 return const_hash (TREE_OPERAND (exp, 0)) * 9
2065 + const_hash (TREE_OPERAND (exp, 1));
2066 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2067 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2069 /* Compute hashing function */
2071 for (i = 0; i < len; i++)
2072 hi = ((hi * 613) + (unsigned)(p[i]));
2074 hi &= (1 << HASHBITS) - 1;
2075 hi %= MAX_HASH_TABLE;
2079 /* Compare a constant expression EXP with a constant-descriptor DESC.
2080 Return 1 if DESC describes a constant with the same value as EXP. */
2083 compare_constant (exp, desc)
2085 struct constant_descriptor *desc;
2087 return 0 != compare_constant_1 (exp, desc->contents);
2090 /* Compare constant expression EXP with a substring P of a constant descriptor.
2091 If they match, return a pointer to the end of the substring matched.
2092 If they do not match, return 0.
2094 Since descriptors are written in polish prefix notation,
2095 this function can be used recursively to test one operand of EXP
2096 against a subdescriptor, and if it succeeds it returns the
2097 address of the subdescriptor for the next operand. */
2100 compare_constant_1 (exp, p)
2104 register char *strp;
2106 register enum tree_code code = TREE_CODE (exp);
2108 if (code != (enum tree_code) *p++)
2111 if (code == INTEGER_CST)
2113 /* Integer constants are the same only if the same width of type. */
2114 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2116 strp = (char *) &TREE_INT_CST_LOW (exp);
2117 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2119 else if (code == REAL_CST)
2121 /* Real constants are the same only if the same width of type. */
2122 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2124 strp = (char *) &TREE_REAL_CST (exp);
2125 len = sizeof TREE_REAL_CST (exp);
2127 else if (code == STRING_CST)
2129 if (flag_writable_strings)
2131 strp = TREE_STRING_POINTER (exp);
2132 len = TREE_STRING_LENGTH (exp);
2133 if (bcmp (&TREE_STRING_LENGTH (exp), p,
2134 sizeof TREE_STRING_LENGTH (exp)))
2136 p += sizeof TREE_STRING_LENGTH (exp);
2138 else if (code == COMPLEX_CST)
2140 p = compare_constant_1 (TREE_REALPART (exp), p);
2141 if (p == 0) return 0;
2142 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2145 else if (code == CONSTRUCTOR)
2148 int length = list_length (CONSTRUCTOR_ELTS (exp));
2151 if (bcmp (&length, p, sizeof length))
2155 /* For record constructors, insist that the types match.
2156 For arrays, just verify both constructors are for arrays. */
2157 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2158 type = TREE_TYPE (exp);
2161 if (bcmp (&type, p, sizeof type))
2165 /* For arrays, insist that the size in bytes match. */
2166 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2168 int size = int_size_in_bytes (TREE_TYPE (exp));
2169 if (bcmp (&size, p, sizeof size))
2174 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2176 if (TREE_VALUE (link))
2178 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2185 if (bcmp (&zero, p, sizeof zero))
2193 else if (code == ADDR_EXPR)
2195 struct addr_const value;
2196 decode_addr_const (exp, &value);
2197 strp = (char *) &value.offset;
2198 len = sizeof value.offset;
2199 /* Compare the offset. */
2201 if (*p++ != *strp++)
2203 /* Compare symbol name. */
2204 strp = XSTR (value.base, 0);
2205 len = strlen (strp) + 1;
2207 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2209 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2210 if (p == 0) return 0;
2211 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2214 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2216 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2220 /* Compare constant contents. */
2222 if (*p++ != *strp++)
2228 /* Construct a constant descriptor for the expression EXP.
2229 It is up to the caller to enter the descriptor in the hash table. */
2231 static struct constant_descriptor *
2232 record_constant (exp)
2235 struct constant_descriptor *next = 0;
2238 /* Make a struct constant_descriptor. The first two pointers will
2239 be filled in later. Here we just leave space for them. */
2241 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2242 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2243 record_constant_1 (exp);
2244 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2247 /* Add a description of constant expression EXP
2248 to the object growing in `permanent_obstack'.
2249 No need to return its address; the caller will get that
2250 from the obstack when the object is complete. */
2253 record_constant_1 (exp)
2256 register char *strp;
2258 register enum tree_code code = TREE_CODE (exp);
2260 obstack_1grow (&permanent_obstack, (unsigned int) code);
2262 if (code == INTEGER_CST)
2264 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2265 strp = (char *) &TREE_INT_CST_LOW (exp);
2266 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2268 else if (code == REAL_CST)
2270 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2271 strp = (char *) &TREE_REAL_CST (exp);
2272 len = sizeof TREE_REAL_CST (exp);
2274 else if (code == STRING_CST)
2276 if (flag_writable_strings)
2278 strp = TREE_STRING_POINTER (exp);
2279 len = TREE_STRING_LENGTH (exp);
2280 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2281 sizeof TREE_STRING_LENGTH (exp));
2283 else if (code == COMPLEX_CST)
2285 record_constant_1 (TREE_REALPART (exp));
2286 record_constant_1 (TREE_IMAGPART (exp));
2289 else if (code == CONSTRUCTOR)
2292 int length = list_length (CONSTRUCTOR_ELTS (exp));
2295 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2297 /* For record constructors, insist that the types match.
2298 For arrays, just verify both constructors are for arrays. */
2299 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2300 type = TREE_TYPE (exp);
2303 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2305 /* For arrays, insist that the size in bytes match. */
2306 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2308 int size = int_size_in_bytes (TREE_TYPE (exp));
2309 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2312 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2314 if (TREE_VALUE (link))
2315 record_constant_1 (TREE_VALUE (link));
2320 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
2326 else if (code == ADDR_EXPR)
2328 struct addr_const value;
2329 decode_addr_const (exp, &value);
2330 /* Record the offset. */
2331 obstack_grow (&permanent_obstack,
2332 (char *) &value.offset, sizeof value.offset);
2333 /* Record the symbol name. */
2334 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2335 strlen (XSTR (value.base, 0)) + 1);
2338 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2340 record_constant_1 (TREE_OPERAND (exp, 0));
2341 record_constant_1 (TREE_OPERAND (exp, 1));
2344 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2346 record_constant_1 (TREE_OPERAND (exp, 0));
2350 /* Record constant contents. */
2351 obstack_grow (&permanent_obstack, strp, len);
2354 /* Record a list of constant expressions that were passed to
2355 output_constant_def but that could not be output right away. */
2357 struct deferred_constant
2359 struct deferred_constant *next;
2365 static struct deferred_constant *deferred_constants;
2367 /* Nonzero means defer output of addressed subconstants
2368 (i.e., those for which output_constant_def is called.) */
2369 static int defer_addressed_constants_flag;
2371 /* Start deferring output of subconstants. */
2374 defer_addressed_constants ()
2376 defer_addressed_constants_flag++;
2379 /* Stop deferring output of subconstants,
2380 and output now all those that have been deferred. */
2383 output_deferred_addressed_constants ()
2385 struct deferred_constant *p, *next;
2387 defer_addressed_constants_flag--;
2389 if (defer_addressed_constants_flag > 0)
2392 for (p = deferred_constants; p; p = next)
2394 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2399 deferred_constants = 0;
2402 /* Make a copy of the whole tree structure for a constant.
2403 This handles the same types of nodes that compare_constant
2404 and record_constant handle. */
2410 switch (TREE_CODE (exp))
2416 /* For ADDR_EXPR, we do not want to copy the decl
2417 whose address is requested. */
2418 return copy_node (exp);
2421 return build_complex (copy_constant (TREE_REALPART (exp)),
2422 copy_constant (TREE_IMAGPART (exp)));
2426 return build (TREE_CODE (exp), TREE_TYPE (exp),
2427 copy_constant (TREE_OPERAND (exp, 0)),
2428 copy_constant (TREE_OPERAND (exp, 1)));
2432 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2433 copy_constant (TREE_OPERAND (exp, 0)));
2437 tree copy = copy_node (exp);
2438 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2441 CONSTRUCTOR_ELTS (exp) = list;
2442 for (tail = list; tail; tail = TREE_CHAIN (tail))
2443 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2453 /* Return an rtx representing a reference to constant data in memory
2454 for the constant expression EXP.
2456 If assembler code for such a constant has already been output,
2457 return an rtx to refer to it.
2458 Otherwise, output such a constant in memory (or defer it for later)
2459 and generate an rtx for it.
2461 The TREE_CST_RTL of EXP is set up to point to that rtx.
2462 The const_hash_table records which constants already have label strings. */
2465 output_constant_def (exp)
2469 register struct constant_descriptor *desc;
2475 if (TREE_CODE (exp) == INTEGER_CST)
2476 abort (); /* No TREE_CST_RTL slot in these. */
2478 if (TREE_CST_RTL (exp))
2479 return TREE_CST_RTL (exp);
2481 /* Make sure any other constants whose addresses appear in EXP
2482 are assigned label numbers. */
2484 reloc = output_addressed_constants (exp);
2486 /* Compute hash code of EXP. Search the descriptors for that hash code
2487 to see if any of them describes EXP. If yes, the descriptor records
2488 the label number already assigned. */
2490 if (!output_bytecode)
2492 hash = const_hash (exp) % MAX_HASH_TABLE;
2494 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2495 if (compare_constant (exp, desc))
2497 found = desc->label;
2503 /* No constant equal to EXP is known to have been output.
2504 Make a constant descriptor to enter EXP in the hash table.
2505 Assign the label number and record it in the descriptor for
2506 future calls to this function to find. */
2508 /* Create a string containing the label name, in LABEL. */
2509 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2511 desc = record_constant (exp);
2512 desc->next = const_hash_table[hash];
2514 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2515 const_hash_table[hash] = desc;
2519 /* Create a string containing the label name, in LABEL. */
2520 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2524 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2526 push_obstacks_nochange ();
2527 if (TREE_PERMANENT (exp))
2528 end_temporary_allocation ();
2530 if (!output_bytecode)
2532 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2535 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2536 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2537 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
2538 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2539 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2543 /* Optionally set flags or add text to the name to record information
2544 such as that it is a function name. If the name is changed, the macro
2545 ASM_OUTPUT_LABELREF will have to know how to strip this information.
2546 And if it finds a * at the beginning after doing so, it must handle
2548 #ifdef ENCODE_SECTION_INFO
2549 ENCODE_SECTION_INFO (exp);
2552 /* If this is the first time we've seen this particular constant,
2553 output it (or defer its output for later). */
2556 if (defer_addressed_constants_flag)
2558 struct deferred_constant *p;
2559 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2561 push_obstacks_nochange ();
2562 suspend_momentary ();
2563 p->exp = copy_constant (exp);
2566 p->labelno = const_labelno++;
2567 p->next = deferred_constants;
2568 deferred_constants = p;
2571 output_constant_def_contents (exp, reloc, const_labelno++);
2574 return TREE_CST_RTL (exp);
2577 /* Now output assembler code to define the label for EXP,
2578 and follow it with the data of EXP. */
2581 output_constant_def_contents (exp, reloc, labelno)
2588 /* First switch to text section, except for writable strings. */
2589 #ifdef SELECT_SECTION
2590 SELECT_SECTION (exp, reloc);
2592 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2593 || (flag_pic && reloc))
2596 readonly_data_section ();
2599 /* Align the location counter as required by EXP's data type. */
2600 align = TYPE_ALIGN (TREE_TYPE (exp));
2601 #ifdef CONSTANT_ALIGNMENT
2602 align = CONSTANT_ALIGNMENT (exp, align);
2605 if (align > BITS_PER_UNIT)
2607 if (!output_bytecode)
2609 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2613 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2617 /* Output the label itself. */
2618 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2620 /* Output the value of EXP. */
2621 output_constant (exp,
2622 (TREE_CODE (exp) == STRING_CST
2623 ? TREE_STRING_LENGTH (exp)
2624 : int_size_in_bytes (TREE_TYPE (exp))));
2628 /* Similar hash facility for making memory-constants
2629 from constant rtl-expressions. It is used on RISC machines
2630 where immediate integer arguments and constant addresses are restricted
2631 so that such constants must be stored in memory.
2633 This pool of constants is reinitialized for each function
2634 so each function gets its own constants-pool that comes right before it.
2636 All structures allocated here are discarded when functions are saved for
2637 inlining, so they do not need to be allocated permanently. */
2639 #define MAX_RTX_HASH_TABLE 61
2640 static struct constant_descriptor **const_rtx_hash_table;
2642 /* Structure to represent sufficient information about a constant so that
2643 it can be output when the constant pool is output, so that function
2644 integration can be done, and to simplify handling on machines that reference
2645 constant pool as base+displacement. */
2647 struct pool_constant
2649 struct constant_descriptor *desc;
2650 struct pool_constant *next;
2651 enum machine_mode mode;
2658 /* Pointers to first and last constant in pool. */
2660 static struct pool_constant *first_pool, *last_pool;
2662 /* Current offset in constant pool (does not include any machine-specific
2665 static int pool_offset;
2667 /* Structure used to maintain hash table mapping symbols used to their
2668 corresponding constants. */
2673 struct pool_constant *pool;
2674 struct pool_sym *next;
2677 static struct pool_sym **const_rtx_sym_hash_table;
2679 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2680 The argument is XSTR (... , 0) */
2682 #define SYMHASH(LABEL) \
2683 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2685 /* Initialize constant pool hashing for next function. */
2688 init_const_rtx_hash_table ()
2690 const_rtx_hash_table
2691 = ((struct constant_descriptor **)
2692 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2693 const_rtx_sym_hash_table
2694 = ((struct pool_sym **)
2695 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2696 bzero (const_rtx_hash_table,
2697 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2698 bzero (const_rtx_sym_hash_table,
2699 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2701 first_pool = last_pool = 0;
2705 /* Save and restore it for a nested function. */
2708 save_varasm_status (p)
2711 p->const_rtx_hash_table = const_rtx_hash_table;
2712 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2713 p->first_pool = first_pool;
2714 p->last_pool = last_pool;
2715 p->pool_offset = pool_offset;
2719 restore_varasm_status (p)
2722 const_rtx_hash_table = p->const_rtx_hash_table;
2723 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2724 first_pool = p->first_pool;
2725 last_pool = p->last_pool;
2726 pool_offset = p->pool_offset;
2729 enum kind { RTX_DOUBLE, RTX_INT };
2733 #ifdef ONLY_INT_FIELDS
2734 unsigned int kind : 16;
2735 unsigned int mode : 16;
2737 enum kind kind : 16;
2738 enum machine_mode mode : 16;
2741 union real_extract du;
2742 struct addr_const addr;
2746 /* Express an rtx for a constant integer (perhaps symbolic)
2747 as the sum of a symbol or label plus an explicit integer.
2748 They are stored into VALUE. */
2751 decode_rtx_const (mode, x, value)
2752 enum machine_mode mode;
2754 struct rtx_const *value;
2756 /* Clear the whole structure, including any gaps. */
2759 int *p = (int *) value;
2760 int *end = (int *) (value + 1);
2765 value->kind = RTX_INT; /* Most usual kind. */
2768 switch (GET_CODE (x))
2771 value->kind = RTX_DOUBLE;
2772 if (GET_MODE (x) != VOIDmode)
2773 value->mode = GET_MODE (x);
2774 bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
2778 value->un.addr.offset = INTVAL (x);
2784 value->un.addr.base = x;
2789 if (GET_CODE (x) == PLUS)
2791 value->un.addr.base = XEXP (x, 0);
2792 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2794 value->un.addr.offset = INTVAL (XEXP (x, 1));
2796 else if (GET_CODE (x) == MINUS)
2798 value->un.addr.base = XEXP (x, 0);
2799 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2801 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2811 if (value->kind == RTX_INT && value->un.addr.base != 0)
2812 switch (GET_CODE (value->un.addr.base))
2816 /* Use the string's address, not the SYMBOL_REF's address,
2817 for the sake of addresses of library routines.
2818 For a LABEL_REF, compare labels. */
2819 value->un.addr.base = XEXP (value->un.addr.base, 0);
2823 /* Given a MINUS expression, simplify it if both sides
2824 include the same symbol. */
2827 simplify_subtraction (x)
2830 struct rtx_const val0, val1;
2832 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2833 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2835 if (val0.un.addr.base == val1.un.addr.base)
2836 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2840 /* Compute a hash code for a constant RTL expression. */
2843 const_hash_rtx (mode, x)
2844 enum machine_mode mode;
2849 struct rtx_const value;
2850 decode_rtx_const (mode, x, &value);
2852 /* Compute hashing function */
2854 for (i = 0; i < sizeof value / sizeof (int); i++)
2855 hi += ((int *) &value)[i];
2857 hi &= (1 << HASHBITS) - 1;
2858 hi %= MAX_RTX_HASH_TABLE;
2862 /* Compare a constant rtl object X with a constant-descriptor DESC.
2863 Return 1 if DESC describes a constant with the same value as X. */
2866 compare_constant_rtx (mode, x, desc)
2867 enum machine_mode mode;
2869 struct constant_descriptor *desc;
2871 register int *p = (int *) desc->contents;
2874 struct rtx_const value;
2876 decode_rtx_const (mode, x, &value);
2877 strp = (int *) &value;
2878 len = sizeof value / sizeof (int);
2880 /* Compare constant contents. */
2882 if (*p++ != *strp++)
2888 /* Construct a constant descriptor for the rtl-expression X.
2889 It is up to the caller to enter the descriptor in the hash table. */
2891 static struct constant_descriptor *
2892 record_constant_rtx (mode, x)
2893 enum machine_mode mode;
2896 struct constant_descriptor *ptr;
2898 struct rtx_const value;
2900 decode_rtx_const (mode, x, &value);
2902 obstack_grow (current_obstack, &ptr, sizeof ptr);
2903 obstack_grow (current_obstack, &label, sizeof label);
2905 /* Record constant contents. */
2906 obstack_grow (current_obstack, &value, sizeof value);
2908 return (struct constant_descriptor *) obstack_finish (current_obstack);
2911 /* Given a constant rtx X, make (or find) a memory constant for its value
2912 and return a MEM rtx to refer to it in memory. */
2915 force_const_mem (mode, x)
2916 enum machine_mode mode;
2920 register struct constant_descriptor *desc;
2925 /* If we want this CONST_DOUBLE in the same mode as it is in memory
2926 (this will always be true for floating CONST_DOUBLEs that have been
2927 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
2928 use the previous copy. Otherwise, make a new one. Note that in
2929 the unlikely event that this same CONST_DOUBLE is used in two different
2930 modes in an alternating fashion, we will allocate a lot of different
2931 memory locations, but this should be extremely rare. */
2933 /* Don't use CONST_DOUBLE_MEM in a nested function.
2934 Nested functions have their own constant pools,
2935 so they can't share the same values in CONST_DOUBLE_MEM
2936 with the containing function. */
2937 if (outer_function_chain == 0)
2938 if (GET_CODE (x) == CONST_DOUBLE
2939 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
2940 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
2941 return CONST_DOUBLE_MEM (x);
2943 /* Compute hash code of X. Search the descriptors for that hash code
2944 to see if any of them describes X. If yes, the descriptor records
2945 the label number already assigned. */
2947 hash = const_hash_rtx (mode, x);
2949 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
2950 if (compare_constant_rtx (mode, x, desc))
2952 found = desc->label;
2958 register struct pool_constant *pool;
2959 register struct pool_sym *sym;
2962 /* No constant equal to X is known to have been output.
2963 Make a constant descriptor to enter X in the hash table.
2964 Assign the label number and record it in the descriptor for
2965 future calls to this function to find. */
2967 desc = record_constant_rtx (mode, x);
2968 desc->next = const_rtx_hash_table[hash];
2969 const_rtx_hash_table[hash] = desc;
2971 /* Align the location counter as required by EXP's data type. */
2972 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
2973 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2974 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
2976 pool_offset += align - 1;
2977 pool_offset &= ~ (align - 1);
2979 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
2981 pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
2985 pool->labelno = const_labelno;
2986 pool->align = align;
2987 pool->offset = pool_offset;
2993 last_pool->next = pool;
2996 pool_offset += GET_MODE_SIZE (mode);
2998 /* Create a string containing the label name, in LABEL. */
2999 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3004 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3006 /* Add label to symbol hash table. */
3007 hash = SYMHASH (found);
3008 sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
3011 sym->next = const_rtx_sym_hash_table[hash];
3012 const_rtx_sym_hash_table[hash] = sym;
3015 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3017 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3019 RTX_UNCHANGING_P (def) = 1;
3020 /* Mark the symbol_ref as belonging to this constants pool. */
3021 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3022 current_function_uses_const_pool = 1;
3024 if (outer_function_chain == 0)
3025 if (GET_CODE (x) == CONST_DOUBLE)
3027 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3029 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3030 const_double_chain = x;
3032 CONST_DOUBLE_MEM (x) = def;
3038 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3039 the corresponding pool_constant structure. */
3041 static struct pool_constant *
3042 find_pool_constant (addr)
3045 struct pool_sym *sym;
3046 char *label = XSTR (addr, 0);
3048 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3049 if (sym->label == label)
3055 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3058 get_pool_constant (addr)
3061 return (find_pool_constant (addr))->constant;
3064 /* Similar, return the mode. */
3067 get_pool_mode (addr)
3070 return (find_pool_constant (addr))->mode;
3073 /* Similar, return the offset in the constant pool. */
3076 get_pool_offset (addr)
3079 return (find_pool_constant (addr))->offset;
3082 /* Return the size of the constant pool. */
3090 /* Write all the constants in the constant pool. */
3093 output_constant_pool (fnname, fndecl)
3097 struct pool_constant *pool;
3099 union real_extract u;
3101 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3102 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3105 for (pool = first_pool; pool; pool = pool->next)
3109 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3110 whose CODE_LABEL has been deleted. This can occur if a jump table
3111 is eliminated by optimization. If so, write a constant of zero
3112 instead. Note that this can also happen by turning the
3113 CODE_LABEL into a NOTE. */
3114 if (((GET_CODE (x) == LABEL_REF
3115 && (INSN_DELETED_P (XEXP (x, 0))
3116 || GET_CODE (XEXP (x, 0)) == NOTE)))
3117 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3118 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3119 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3120 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3123 /* First switch to correct section. */
3124 #ifdef SELECT_RTX_SECTION
3125 SELECT_RTX_SECTION (pool->mode, x);
3127 readonly_data_section ();
3130 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3131 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3132 pool->align, pool->labelno, done);
3135 if (pool->align > 1)
3136 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3138 /* Output the label. */
3139 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3141 /* Output the value of the constant itself. */
3142 switch (GET_MODE_CLASS (pool->mode))
3145 if (GET_CODE (x) != CONST_DOUBLE)
3148 bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
3149 assemble_real (u.d, pool->mode);
3153 case MODE_PARTIAL_INT:
3154 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3164 /* Done with this pool. */
3165 first_pool = last_pool = 0;
3168 /* Find all the constants whose addresses are referenced inside of EXP,
3169 and make sure assembler code with a label has been output for each one.
3170 Indicate whether an ADDR_EXPR has been encountered. */
3173 output_addressed_constants (exp)
3178 switch (TREE_CODE (exp))
3182 register tree constant = TREE_OPERAND (exp, 0);
3184 while (TREE_CODE (constant) == COMPONENT_REF)
3186 constant = TREE_OPERAND (constant, 0);
3189 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3190 || TREE_CODE (constant) == CONSTRUCTOR)
3191 /* No need to do anything here
3192 for addresses of variables or functions. */
3193 output_constant_def (constant);
3200 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3201 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3206 case NON_LVALUE_EXPR:
3207 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3213 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3214 if (TREE_VALUE (link) != 0)
3215 reloc |= output_addressed_constants (TREE_VALUE (link));
3226 /* Output assembler for byte constant */
3228 output_byte_asm (byte)
3231 if (output_bytecode)
3232 bc_emit_const ((char *) &byte, sizeof (char));
3233 #ifdef ASM_OUTPUT_BYTE
3236 ASM_OUTPUT_BYTE (asm_out_file, byte);
3241 /* Output assembler code for constant EXP to FILE, with no label.
3242 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3243 Assumes output_addressed_constants has been done on EXP already.
3245 Generate exactly SIZE bytes of assembler data, padding at the end
3246 with zeros if necessary. SIZE must always be specified.
3248 SIZE is important for structure constructors,
3249 since trailing members may have been omitted from the constructor.
3250 It is also important for initialization of arrays from string constants
3251 since the full length of the string constant might not be wanted.
3252 It is also needed for initialization of unions, where the initializer's
3253 type is just one member, and that may not be as long as the union.
3255 There a case in which we would fail to output exactly SIZE bytes:
3256 for a structure constructor that wants to produce more than SIZE bytes.
3257 But such constructors will never be generated for any possible input. */
3260 output_constant (exp, size)
3264 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3270 /* Allow a constructor with no elements for any data type.
3271 This means to fill the space with zeros. */
3272 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3274 if (output_bytecode)
3275 bc_emit_const_skip (size);
3277 assemble_zeros (size);
3281 /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
3282 That way we get the constant (we hope) inside it. */
3283 if (TREE_CODE (exp) == NOP_EXPR
3284 && TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)))
3285 exp = TREE_OPERAND (exp, 0);
3294 case REFERENCE_TYPE:
3295 /* ??? What about (int)((float)(int)&foo + 4) */
3296 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3297 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3298 exp = TREE_OPERAND (exp, 0);
3300 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3301 EXPAND_INITIALIZER),
3303 error ("initializer for integer value is too complicated");
3308 if (TREE_CODE (exp) != REAL_CST)
3309 error ("initializer for floating value is not a floating constant");
3311 assemble_real (TREE_REAL_CST (exp),
3312 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3317 output_constant (TREE_REALPART (exp), size / 2);
3318 output_constant (TREE_IMAGPART (exp), size / 2);
3319 size -= (size / 2) * 2;
3323 if (TREE_CODE (exp) == CONSTRUCTOR)
3325 output_constructor (exp, size);
3328 else if (TREE_CODE (exp) == STRING_CST)
3332 if (size > TREE_STRING_LENGTH (exp))
3334 excess = size - TREE_STRING_LENGTH (exp);
3335 size = TREE_STRING_LENGTH (exp);
3338 assemble_string (TREE_STRING_POINTER (exp), size);
3347 if (TREE_CODE (exp) == CONSTRUCTOR)
3348 output_constructor (exp, size);
3355 assemble_zeros (size);
3359 /* Bytecode specific code to output assembler for integer. */
3361 bc_assemble_integer (exp, size)
3369 /* FIXME: is this fold() business going to be as good as the
3370 expand_expr() using EXPAND_SUM above in the RTL case? I
3372 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3376 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3377 exp = TREE_OPERAND (exp, 0);
3378 if (TREE_CODE (exp) == INTEGER_CST)
3383 else if (TREE_CODE (exp) == PLUS_EXPR)
3385 const_part = TREE_OPERAND (exp, 0);
3386 while (TREE_CODE (const_part) == NOP_EXPR
3387 || TREE_CODE (const_part) == CONVERT_EXPR)
3388 const_part = TREE_OPERAND (const_part, 0);
3389 addr_part = TREE_OPERAND (exp, 1);
3390 while (TREE_CODE (addr_part) == NOP_EXPR
3391 || TREE_CODE (addr_part) == CONVERT_EXPR)
3392 addr_part = TREE_OPERAND (addr_part, 0);
3393 if (TREE_CODE (const_part) != INTEGER_CST)
3394 tmp = const_part, const_part = addr_part, addr_part = tmp;
3395 if (TREE_CODE (const_part) != INTEGER_CST
3396 || TREE_CODE (addr_part) != ADDR_EXPR)
3397 abort (); /* FIXME: we really haven't considered
3398 all the possible cases here. */
3400 else if (TREE_CODE (exp) == ADDR_EXPR)
3402 const_part = integer_zero_node;
3406 abort (); /* FIXME: ditto previous. */
3412 char c = TREE_INT_CST_LOW (const_part);
3418 short s = TREE_INT_CST_LOW (const_part);
3419 bc_emit ((char *) &s, 2);
3424 int i = TREE_INT_CST_LOW (const_part);
3425 bc_emit ((char *) &i, 4);
3430 #if WORDS_BIG_ENDIAN
3431 int i = TREE_INT_CST_HIGH (const_part);
3432 bc_emit ((char *) &i, 4);
3433 i = TREE_INT_CST_LOW (const_part);
3434 bc_emit ((char *) &i, 4);
3436 int i = TREE_INT_CST_LOW (const_part);
3437 bc_emit ((char *) &i, 4);
3438 i = TREE_INT_CST_HIGH (const_part);
3439 bc_emit ((char *) &i, 4);
3446 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3447 bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3448 TREE_INT_CST_LOW (const_part));
3450 abort (); /* FIXME: there may be more cases. */
3453 /* Subroutine of output_constant, used for CONSTRUCTORs
3454 (aggregate constants).
3455 Generate at least SIZE bytes, padding if necessary. */
3458 output_constructor (exp, size)
3462 register tree link, field = 0;
3463 HOST_WIDE_INT min_index = 0;
3464 /* Number of bytes output or skipped so far.
3465 In other words, current position within the constructor. */
3466 int total_bytes = 0;
3467 /* Non-zero means BYTE contains part of a byte, to be output. */
3468 int byte_buffer_in_use = 0;
3471 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3474 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3475 field = TYPE_FIELDS (TREE_TYPE (exp));
3477 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3478 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3480 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3482 /* As LINK goes through the elements of the constant,
3483 FIELD goes through the structure fields, if the constant is a structure.
3484 if the constant is a union, then we override this,
3485 by getting the field from the TREE_LIST element.
3486 But the constant could also be an array. Then FIELD is zero. */
3487 for (link = CONSTRUCTOR_ELTS (exp);
3489 link = TREE_CHAIN (link),
3490 field = field ? TREE_CHAIN (field) : 0)
3492 tree val = TREE_VALUE (link);
3495 /* the element in a union constructor specifies the proper field. */
3497 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3498 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3500 /* if available, use the type given by link */
3501 if (TREE_PURPOSE (link) != 0)
3502 field = TREE_PURPOSE (link);
3505 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3506 index = TREE_PURPOSE (link);
3508 /* Eliminate the marker that makes a cast not be an lvalue. */
3512 if (field == 0 || !DECL_BIT_FIELD (field))
3514 /* An element that is not a bit-field. */
3516 register int fieldsize;
3517 /* Since this structure is static,
3518 we know the positions are constant. */
3519 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3523 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3525 * (TREE_INT_CST_LOW (index) - min_index));
3527 /* Output any buffered-up bit-fields preceding this element. */
3528 if (byte_buffer_in_use)
3530 ASM_OUTPUT_BYTE (asm_out_file, byte);
3532 byte_buffer_in_use = 0;
3535 /* Advance to offset of this element.
3536 Note no alignment needed in an array, since that is guaranteed
3537 if each element has the proper size. */
3538 if ((field != 0 || index != 0) && bitpos != total_bytes)
3540 if (!output_bytecode)
3541 assemble_zeros (bitpos - total_bytes);
3543 bc_emit_const_skip (bitpos - total_bytes);
3544 total_bytes = bitpos;
3547 /* Determine size this element should occupy. */
3550 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3552 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3554 /* This avoids overflow trouble. */
3555 tree size_tree = size_binop (CEIL_DIV_EXPR,
3557 size_int (BITS_PER_UNIT));
3558 fieldsize = TREE_INT_CST_LOW (size_tree);
3562 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3563 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3567 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3569 /* Output the element's initial value. */
3571 assemble_zeros (fieldsize);
3573 output_constant (val, fieldsize);
3575 /* Count its size. */
3576 total_bytes += fieldsize;
3578 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3579 error ("invalid initial value for member `%s'",
3580 IDENTIFIER_POINTER (DECL_NAME (field)));
3583 /* Element that is a bit-field. */
3585 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3587 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3590 val = integer_zero_node;
3592 /* If this field does not start in this (or, next) byte,
3594 if (next_offset / BITS_PER_UNIT != total_bytes)
3596 /* Output remnant of any bit field in previous bytes. */
3597 if (byte_buffer_in_use)
3599 ASM_OUTPUT_BYTE (asm_out_file, byte);
3601 byte_buffer_in_use = 0;
3604 /* If still not at proper byte, advance to there. */
3605 if (next_offset / BITS_PER_UNIT != total_bytes)
3607 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3608 total_bytes = next_offset / BITS_PER_UNIT;
3612 if (! byte_buffer_in_use)
3615 /* We must split the element into pieces that fall within
3616 separate bytes, and combine each byte with previous or
3617 following bit-fields. */
3619 /* next_offset is the offset n fbits from the beginning of
3620 the structure to the next bit of this element to be processed.
3621 end_offset is the offset of the first bit past the end of
3623 while (next_offset < end_offset)
3627 int next_byte = next_offset / BITS_PER_UNIT;
3628 int next_bit = next_offset % BITS_PER_UNIT;
3630 /* Advance from byte to byte
3631 within this element when necessary. */
3632 while (next_byte != total_bytes)
3634 ASM_OUTPUT_BYTE (asm_out_file, byte);
3639 /* Number of bits we can process at once
3640 (all part of the same byte). */
3641 this_time = MIN (end_offset - next_offset,
3642 BITS_PER_UNIT - next_bit);
3643 #if BYTES_BIG_ENDIAN
3644 /* On big-endian machine, take the most significant bits
3645 first (of the bits that are significant)
3646 and put them into bytes from the most significant end. */
3647 shift = end_offset - next_offset - this_time;
3648 /* Don't try to take a bunch of bits that cross
3649 the word boundary in the INTEGER_CST. */
3650 if (shift < HOST_BITS_PER_WIDE_INT
3651 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3653 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3654 shift = HOST_BITS_PER_WIDE_INT;
3657 /* Now get the bits from the appropriate constant word. */
3658 if (shift < HOST_BITS_PER_WIDE_INT)
3660 value = TREE_INT_CST_LOW (val);
3662 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3664 value = TREE_INT_CST_HIGH (val);
3665 shift -= HOST_BITS_PER_WIDE_INT;
3669 byte |= (((value >> shift)
3670 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3671 << (BITS_PER_UNIT - this_time - next_bit));
3673 /* On little-endian machines,
3674 take first the least significant bits of the value
3675 and pack them starting at the least significant
3676 bits of the bytes. */
3677 shift = (next_offset
3678 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3679 /* Don't try to take a bunch of bits that cross
3680 the word boundary in the INTEGER_CST. */
3681 if (shift < HOST_BITS_PER_WIDE_INT
3682 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3684 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3685 shift = HOST_BITS_PER_WIDE_INT;
3688 /* Now get the bits from the appropriate constant word. */
3689 if (shift < HOST_BITS_PER_INT)
3690 value = TREE_INT_CST_LOW (val);
3691 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3693 value = TREE_INT_CST_HIGH (val);
3694 shift -= HOST_BITS_PER_WIDE_INT;
3698 byte |= ((value >> shift)
3699 & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
3701 next_offset += this_time;
3702 byte_buffer_in_use = 1;
3706 if (byte_buffer_in_use)
3708 ASM_OUTPUT_BYTE (asm_out_file, byte);
3711 if (total_bytes < size)
3712 assemble_zeros (size - total_bytes);
3716 #ifdef HANDLE_SYSV_PRAGMA
3718 /* Support #pragma weak by default if WEAK_ASM_OP is defined. */
3719 #if defined (HANDLE_PRAGMA_WEAK) || (defined (WEAK_ASM_OP) && defined (SET_ASM_OP))
3721 /* See c-pragma.c for an identical definition. */
3737 /* Output asm to handle ``#pragma weak'' */
3739 handle_pragma_weak (what, asm_out_file, name, value)
3740 enum pragma_state what;
3744 if (what == ps_name || what == ps_value)
3746 fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
3748 if (output_bytecode)
3749 BC_OUTPUT_LABELREF (asm_out_file, name);
3751 ASM_OUTPUT_LABELREF (asm_out_file, name);
3753 fputc ('\n', asm_out_file);
3754 if (what == ps_value)
3756 fprintf (asm_out_file, "\t%s\t", SET_ASM_OP);
3757 if (output_bytecode)
3758 BC_OUTPUT_LABELREF (asm_out_file, name);
3760 ASM_OUTPUT_LABELREF (asm_out_file, name);
3762 fputc (',', asm_out_file);
3763 if (output_bytecode)
3764 BC_OUTPUT_LABELREF (asm_out_file, value);
3766 ASM_OUTPUT_LABELREF (asm_out_file, value);
3768 fputc ('\n', asm_out_file);
3771 else if (! (what == ps_done || what == ps_start))
3772 warning ("malformed `#pragma weak'");
3775 #endif /* HANDLE_PRAGMA_WEAK or (WEAK_ASM_OP and SET_ASM_OP) */
3777 #endif /* HANDLE_SYSV_PRAGMA */