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 /* Compute and output the alignment of this data. */
1149 align = DECL_ALIGN (decl);
1150 /* In the case for initialing an array whose length isn't specified,
1151 where we have not yet been able to do the layout,
1152 figure out the proper alignment now. */
1153 if (dont_output_data && DECL_SIZE (decl) == 0
1154 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1155 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1157 /* Some object file formats have a maximum alignment which they support.
1158 In particular, a.out format supports a maximum alignment of 4. */
1159 #ifndef MAX_OFILE_ALIGNMENT
1160 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1162 if (align > MAX_OFILE_ALIGNMENT)
1164 warning_with_decl (decl,
1165 "alignment of `%s' is greater than maximum object file alignment");
1166 align = MAX_OFILE_ALIGNMENT;
1168 #ifdef DATA_ALIGNMENT
1169 /* On some machines, it is good to increase alignment sometimes. */
1170 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1172 #ifdef CONSTANT_ALIGNMENT
1173 if (DECL_INITIAL (decl))
1174 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1177 /* Reset the alignment in case we have made it tighter, so we can benefit
1178 from it in get_pointer_alignment. */
1179 DECL_ALIGN (decl) = align;
1181 if (align > BITS_PER_UNIT)
1183 if (output_bytecode)
1184 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1186 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1189 /* Do any machine/system dependent processing of the object. */
1190 #ifdef ASM_DECLARE_OBJECT_NAME
1191 last_assemble_variable_decl = decl;
1192 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1194 /* Standard thing is just output label for the object. */
1195 if (output_bytecode)
1196 BC_OUTPUT_LABEL (asm_out_file, name);
1198 ASM_OUTPUT_LABEL (asm_out_file, name);
1199 #endif /* ASM_DECLARE_OBJECT_NAME */
1201 if (!dont_output_data)
1203 if (DECL_INITIAL (decl))
1204 /* Output the actual data. */
1205 output_constant (DECL_INITIAL (decl),
1206 int_size_in_bytes (TREE_TYPE (decl)));
1208 /* Leave space for it. */
1209 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1213 #ifdef XCOFF_DEBUGGING_INFO
1214 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1215 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1216 and `aa' hasn't been output yet, the assembler generates a stab entry with
1217 a value of zero, in addition to creating an unnecessary external entry
1218 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1220 /* File-scope global variables are output here. */
1221 if (write_symbols == XCOFF_DEBUG && top_level)
1223 saved_in_section = in_section;
1225 dbxout_symbol (decl, 0);
1227 if (in_section != saved_in_section)
1229 /* Switch to the proper section for this data. */
1230 #ifdef SELECT_SECTION
1231 SELECT_SECTION (decl, reloc);
1233 if (TREE_READONLY (decl)
1234 && ! TREE_THIS_VOLATILE (decl)
1235 && ! (flag_pic && reloc))
1236 readonly_data_section ();
1243 /* There must be a statement after a label. */
1248 /* Return 1 if type TYPE contains any pointers. */
1251 contains_pointers_p (type)
1254 switch (TREE_CODE (type))
1257 case REFERENCE_TYPE:
1258 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1259 so I'll play safe and return 1. */
1265 case QUAL_UNION_TYPE:
1268 /* For a type that has fields, see if the fields have pointers. */
1269 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1270 if (contains_pointers_p (TREE_TYPE (fields)))
1276 /* An array type contains pointers if its element type does. */
1277 return contains_pointers_p (TREE_TYPE (type));
1284 /* Output text storage for constructor CONSTR. Returns rtx of
1288 bc_output_constructor (constr)
1293 /* Must always be a literal; non-literal constructors are handled
1296 if (!TREE_CONSTANT (constr))
1303 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1305 BC_OUTPUT_ALIGN (asm_out_file, i);
1308 output_constant (constr, int_size_in_bytes (TREE_TYPE (constr)));
1312 /* Create storage for constructor CONSTR. */
1315 bc_output_data_constructor (constr)
1320 /* Put in data section */
1324 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1326 BC_OUTPUT_ALIGN (asm_out_file, i);
1328 /* The constructor is filled in at runtime. */
1329 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1333 /* Output something to declare an external symbol to the assembler.
1334 (Most assemblers don't need this, so we normally output nothing.)
1335 Do nothing if DECL is not external. */
1338 assemble_external (decl)
1341 if (output_bytecode)
1344 #ifdef ASM_OUTPUT_EXTERNAL
1345 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1346 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1348 rtx rtl = DECL_RTL (decl);
1350 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1351 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1353 /* Some systems do require some output. */
1354 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1355 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1361 /* Similar, for calling a library function FUN. */
1364 assemble_external_libcall (fun)
1367 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1368 if (!output_bytecode)
1370 /* Declare library function name external when first used, if nec. */
1371 if (! SYMBOL_REF_USED (fun))
1373 SYMBOL_REF_USED (fun) = 1;
1374 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1380 /* Declare the label NAME global. */
1383 assemble_global (name)
1386 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1389 /* Assemble a label named NAME. */
1392 assemble_label (name)
1395 if (output_bytecode)
1396 BC_OUTPUT_LABEL (asm_out_file, name);
1398 ASM_OUTPUT_LABEL (asm_out_file, name);
1401 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1402 If NAME starts with a *, the rest of NAME is output verbatim.
1403 Otherwise NAME is transformed in an implementation-defined way
1404 (usually by the addition of an underscore).
1405 Many macros in the tm file are defined to call this function. */
1408 assemble_name (file, name)
1414 if (output_bytecode)
1415 bc_emit_labelref (name);
1417 fputs (&name[1], file);
1421 if (output_bytecode)
1422 BC_OUTPUT_LABELREF (file, name);
1424 ASM_OUTPUT_LABELREF (file, name);
1428 /* Allocate SIZE bytes writable static space with a gensym name
1429 and return an RTX to refer to its address. */
1432 assemble_static_space (size)
1438 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1439 so that each uninitialized object starts on such a boundary. */
1440 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1441 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1442 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1445 if (flag_shared_data)
1449 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1452 namestring = (char *) obstack_alloc (saveable_obstack,
1454 strcpy (namestring, name);
1456 if (output_bytecode)
1457 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1459 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1461 if (output_bytecode)
1463 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1467 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1468 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1470 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1476 /* Assemble the static constant template for function entry trampolines.
1477 This is done at most once per compilation.
1478 Returns an RTX for the address of the template. */
1481 assemble_trampoline_template ()
1487 /* Shouldn't get here */
1488 if (output_bytecode)
1491 /* By default, put trampoline templates in read-only data section. */
1493 #ifdef TRAMPOLINE_SECTION
1494 TRAMPOLINE_SECTION ();
1496 readonly_data_section ();
1499 /* Write the assembler code to define one. */
1500 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1502 ASM_OUTPUT_ALIGN (asm_out_file, align);
1504 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1505 TRAMPOLINE_TEMPLATE (asm_out_file);
1507 /* Record the rtl to refer to it. */
1508 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1510 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1511 return gen_rtx (SYMBOL_REF, Pmode, name);
1514 /* Assemble the integer constant X into an object of SIZE bytes.
1515 X must be either a CONST_INT or CONST_DOUBLE.
1517 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1518 non-zero, abort if we can't output the constant. */
1521 assemble_integer (x, size, force)
1526 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1527 ASM_OUTPUT... macros. */
1531 #ifdef ASM_OUTPUT_CHAR
1533 ASM_OUTPUT_CHAR (asm_out_file, x);
1537 #ifdef ASM_OUTPUT_SHORT
1539 ASM_OUTPUT_SHORT (asm_out_file, x);
1543 #ifdef ASM_OUTPUT_INT
1545 ASM_OUTPUT_INT (asm_out_file, x);
1549 #ifdef ASM_OUTPUT_DOUBLE_INT
1551 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1555 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1557 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1562 /* If we couldn't do it that way, there are two other possibilities: First,
1563 if the machine can output an explicit byte and this is a 1 byte constant,
1564 we can use ASM_OUTPUT_BYTE. */
1566 #ifdef ASM_OUTPUT_BYTE
1567 if (size == 1 && GET_CODE (x) == CONST_INT)
1569 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1574 /* Finally, if SIZE is larger than a single word, try to output the constant
1575 one word at a time. */
1577 if (size > UNITS_PER_WORD)
1580 enum machine_mode mode
1581 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1584 for (i = 0; i < size / UNITS_PER_WORD; i++)
1586 word = operand_subword (x, i, 0, mode);
1591 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1595 if (i == size / UNITS_PER_WORD)
1597 /* If we output at least one word and then could not finish,
1598 there is no valid way to continue. */
1609 /* Assemble the floating-point constant D into an object of size MODE. */
1612 assemble_real (d, mode)
1614 enum machine_mode mode;
1616 jmp_buf output_constant_handler;
1618 if (setjmp (output_constant_handler))
1620 error ("floating point trap outputting a constant");
1621 #ifdef REAL_IS_NOT_DOUBLE
1622 bzero (&d, sizeof d);
1629 set_float_handler (output_constant_handler);
1633 #ifdef ASM_OUTPUT_BYTE_FLOAT
1635 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1638 #ifdef ASM_OUTPUT_SHORT_FLOAT
1640 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1643 #ifdef ASM_OUTPUT_FLOAT
1645 ASM_OUTPUT_FLOAT (asm_out_file, d);
1649 #ifdef ASM_OUTPUT_DOUBLE
1651 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1655 #ifdef ASM_OUTPUT_LONG_DOUBLE
1658 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1666 set_float_handler (NULL_PTR);
1669 /* Here we combine duplicate floating constants to make
1670 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1672 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1673 They are chained through the CONST_DOUBLE_CHAIN.
1674 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1675 In that case, CONST_DOUBLE_MEM is either a MEM,
1676 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1678 (CONST_DOUBLE_MEM is used only for top-level functions.
1679 See force_const_mem for explanation.) */
1681 static rtx const_double_chain;
1683 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1684 For an integer, I0 is the low-order word and I1 is the high-order word.
1685 For a real number, I0 is the word with the low address
1686 and I1 is the word with the high address. */
1689 immed_double_const (i0, i1, mode)
1690 HOST_WIDE_INT i0, i1;
1691 enum machine_mode mode;
1694 int in_current_obstack;
1696 if (GET_MODE_CLASS (mode) == MODE_INT
1697 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1699 /* We clear out all bits that don't belong in MODE, unless they and our
1700 sign bit are all one. So we get either a reasonable negative value
1701 or a reasonable unsigned value for this mode. */
1702 int width = GET_MODE_BITSIZE (mode);
1703 if (width < HOST_BITS_PER_WIDE_INT
1704 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1705 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1706 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1707 else if (width == HOST_BITS_PER_WIDE_INT
1708 && ! (i1 == ~0 && i0 < 0))
1710 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1711 /* We cannot represent this value as a constant. */
1714 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1716 ??? Strictly speaking, this is wrong if we create a CONST_INT
1717 for a large unsigned constant with the size of MODE being
1718 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1719 wider mode. In that case we will mis-interpret it as a negative
1722 Unfortunately, the only alternative is to make a CONST_DOUBLE
1723 for any constant in any mode if it is an unsigned constant larger
1724 than the maximum signed integer in an int on the host. However,
1725 doing this will break everyone that always expects to see a CONST_INT
1726 for SImode and smaller.
1728 We have always been making CONST_INTs in this case, so nothing new
1731 if (width <= HOST_BITS_PER_WIDE_INT)
1732 i1 = (i0 < 0) ? ~0 : 0;
1734 /* If this integer fits in one word, return a CONST_INT. */
1735 if ((i1 == 0 && i0 >= 0)
1736 || (i1 == ~0 && i0 < 0))
1737 return GEN_INT (i0);
1739 /* We use VOIDmode for integers. */
1743 /* Search the chain for an existing CONST_DOUBLE with the right value.
1744 If one is found, return it. */
1746 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1747 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1748 && GET_MODE (r) == mode)
1751 /* No; make a new one and add it to the chain.
1753 We may be called by an optimizer which may be discarding any memory
1754 allocated during its processing (such as combine and loop). However,
1755 we will be leaving this constant on the chain, so we cannot tolerate
1756 freed memory. So switch to saveable_obstack for this allocation
1757 and then switch back if we were in current_obstack. */
1759 push_obstacks_nochange ();
1760 rtl_in_saveable_obstack ();
1761 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1764 /* Don't touch const_double_chain in nested function; see force_const_mem.
1765 Also, don't touch it if not inside any function. */
1766 if (outer_function_chain == 0 && current_function_decl != 0)
1768 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1769 const_double_chain = r;
1772 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1773 Actual use of mem-slot is only through force_const_mem. */
1775 CONST_DOUBLE_MEM (r) = const0_rtx;
1780 /* Return a CONST_DOUBLE for a specified `double' value
1781 and machine mode. */
1784 immed_real_const_1 (d, mode)
1786 enum machine_mode mode;
1788 union real_extract u;
1790 int in_current_obstack;
1792 /* Get the desired `double' value as a sequence of ints
1793 since that is how they are stored in a CONST_DOUBLE. */
1797 /* Detect special cases. */
1799 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1800 if (!bcmp (&dconst0, &d, sizeof d))
1801 return CONST0_RTX (mode);
1802 /* Check for NaN first, because some ports (specifically the i386) do not
1803 emit correct ieee-fp code by default, and thus will generate a core
1804 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1805 does a floating point comparison. */
1806 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1807 return CONST1_RTX (mode);
1809 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1810 return immed_double_const (u.i[0], u.i[1], mode);
1812 /* The rest of this function handles the case where
1813 a float value requires more than 2 ints of space.
1814 It will be deleted as dead code on machines that don't need it. */
1816 /* Search the chain for an existing CONST_DOUBLE with the right value.
1817 If one is found, return it. */
1819 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1820 if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
1821 && GET_MODE (r) == mode)
1824 /* No; make a new one and add it to the chain.
1826 We may be called by an optimizer which may be discarding any memory
1827 allocated during its processing (such as combine and loop). However,
1828 we will be leaving this constant on the chain, so we cannot tolerate
1829 freed memory. So switch to saveable_obstack for this allocation
1830 and then switch back if we were in current_obstack. */
1832 push_obstacks_nochange ();
1833 rtl_in_saveable_obstack ();
1834 r = rtx_alloc (CONST_DOUBLE);
1836 bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
1839 /* Don't touch const_double_chain in nested function; see force_const_mem.
1840 Also, don't touch it if not inside any function. */
1841 if (outer_function_chain == 0 && current_function_decl != 0)
1843 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1844 const_double_chain = r;
1847 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1848 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1849 is only through force_const_mem. */
1851 CONST_DOUBLE_MEM (r) = const0_rtx;
1856 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1857 which must be a REAL_CST tree node. */
1860 immed_real_const (exp)
1863 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1866 /* At the end of a function, forget the memory-constants
1867 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1868 Also clear out real_constant_chain and clear out all the chain-pointers. */
1871 clear_const_double_mem ()
1873 register rtx r, next;
1875 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1876 See force_const_mem for explanation. */
1877 if (outer_function_chain != 0)
1880 for (r = const_double_chain; r; r = next)
1882 next = CONST_DOUBLE_CHAIN (r);
1883 CONST_DOUBLE_CHAIN (r) = 0;
1884 CONST_DOUBLE_MEM (r) = cc0_rtx;
1886 const_double_chain = 0;
1889 /* Given an expression EXP with a constant value,
1890 reduce it to the sum of an assembler symbol and an integer.
1891 Store them both in the structure *VALUE.
1892 Abort if EXP does not reduce. */
1897 HOST_WIDE_INT offset;
1901 decode_addr_const (exp, value)
1903 struct addr_const *value;
1905 register tree target = TREE_OPERAND (exp, 0);
1906 register int offset = 0;
1911 if (TREE_CODE (target) == COMPONENT_REF
1912 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
1915 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
1916 target = TREE_OPERAND (target, 0);
1918 else if (TREE_CODE (target) == ARRAY_REF)
1920 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
1921 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
1923 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
1924 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
1926 target = TREE_OPERAND (target, 0);
1932 switch (TREE_CODE (target))
1936 x = DECL_RTL (target);
1940 if (output_bytecode)
1941 /* FIXME: this may not be correct, check it */
1942 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
1944 x = gen_rtx (MEM, FUNCTION_MODE,
1945 gen_rtx (LABEL_REF, VOIDmode,
1946 label_rtx (TREE_OPERAND (exp, 0))));
1953 x = TREE_CST_RTL (target);
1960 if (!output_bytecode)
1962 if (GET_CODE (x) != MEM)
1968 value->offset = offset;
1971 /* Uniquize all constants that appear in memory.
1972 Each constant in memory thus far output is recorded
1973 in `const_hash_table' with a `struct constant_descriptor'
1974 that contains a polish representation of the value of
1977 We cannot store the trees in the hash table
1978 because the trees may be temporary. */
1980 struct constant_descriptor
1982 struct constant_descriptor *next;
1988 #define MAX_HASH_TABLE 1009
1989 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
1991 /* Compute a hash code for a constant expression. */
1998 register int len, hi, i;
1999 register enum tree_code code = TREE_CODE (exp);
2001 if (code == INTEGER_CST)
2003 p = (char *) &TREE_INT_CST_LOW (exp);
2004 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2006 else if (code == REAL_CST)
2008 p = (char *) &TREE_REAL_CST (exp);
2009 len = sizeof TREE_REAL_CST (exp);
2011 else if (code == STRING_CST)
2012 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2013 else if (code == COMPLEX_CST)
2014 return const_hash (TREE_REALPART (exp)) * 5
2015 + const_hash (TREE_IMAGPART (exp));
2016 else if (code == CONSTRUCTOR)
2020 /* For record type, include the type in the hashing.
2021 We do not do so for array types
2022 because (1) the sizes of the elements are sufficient
2023 and (2) distinct array types can have the same constructor.
2024 Instead, we include the array size because the constructor could
2026 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2027 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2030 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2031 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2033 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2034 if (TREE_VALUE (link))
2035 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2039 else if (code == ADDR_EXPR)
2041 struct addr_const value;
2042 decode_addr_const (exp, &value);
2043 if (GET_CODE (value.base) == SYMBOL_REF)
2045 /* Don't hash the address of the SYMBOL_REF;
2046 only use the offset and the symbol name. */
2048 p = XSTR (value.base, 0);
2049 for (i = 0; p[i] != 0; i++)
2050 hi = ((hi * 613) + (unsigned)(p[i]));
2052 else if (GET_CODE (value.base) == LABEL_REF)
2053 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2055 hi &= (1 << HASHBITS) - 1;
2056 hi %= MAX_HASH_TABLE;
2059 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2060 return const_hash (TREE_OPERAND (exp, 0)) * 9
2061 + const_hash (TREE_OPERAND (exp, 1));
2062 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2063 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2065 /* Compute hashing function */
2067 for (i = 0; i < len; i++)
2068 hi = ((hi * 613) + (unsigned)(p[i]));
2070 hi &= (1 << HASHBITS) - 1;
2071 hi %= MAX_HASH_TABLE;
2075 /* Compare a constant expression EXP with a constant-descriptor DESC.
2076 Return 1 if DESC describes a constant with the same value as EXP. */
2079 compare_constant (exp, desc)
2081 struct constant_descriptor *desc;
2083 return 0 != compare_constant_1 (exp, desc->contents);
2086 /* Compare constant expression EXP with a substring P of a constant descriptor.
2087 If they match, return a pointer to the end of the substring matched.
2088 If they do not match, return 0.
2090 Since descriptors are written in polish prefix notation,
2091 this function can be used recursively to test one operand of EXP
2092 against a subdescriptor, and if it succeeds it returns the
2093 address of the subdescriptor for the next operand. */
2096 compare_constant_1 (exp, p)
2100 register char *strp;
2102 register enum tree_code code = TREE_CODE (exp);
2104 if (code != (enum tree_code) *p++)
2107 if (code == INTEGER_CST)
2109 /* Integer constants are the same only if the same width of type. */
2110 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2112 strp = (char *) &TREE_INT_CST_LOW (exp);
2113 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2115 else if (code == REAL_CST)
2117 /* Real constants are the same only if the same width of type. */
2118 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2120 strp = (char *) &TREE_REAL_CST (exp);
2121 len = sizeof TREE_REAL_CST (exp);
2123 else if (code == STRING_CST)
2125 if (flag_writable_strings)
2127 strp = TREE_STRING_POINTER (exp);
2128 len = TREE_STRING_LENGTH (exp);
2129 if (bcmp (&TREE_STRING_LENGTH (exp), p,
2130 sizeof TREE_STRING_LENGTH (exp)))
2132 p += sizeof TREE_STRING_LENGTH (exp);
2134 else if (code == COMPLEX_CST)
2136 p = compare_constant_1 (TREE_REALPART (exp), p);
2137 if (p == 0) return 0;
2138 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2141 else if (code == CONSTRUCTOR)
2144 int length = list_length (CONSTRUCTOR_ELTS (exp));
2147 if (bcmp (&length, p, sizeof length))
2151 /* For record constructors, insist that the types match.
2152 For arrays, just verify both constructors are for arrays. */
2153 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2154 type = TREE_TYPE (exp);
2157 if (bcmp (&type, p, sizeof type))
2161 /* For arrays, insist that the size in bytes match. */
2162 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2164 int size = int_size_in_bytes (TREE_TYPE (exp));
2165 if (bcmp (&size, p, sizeof size))
2170 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2172 if (TREE_VALUE (link))
2174 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2181 if (bcmp (&zero, p, sizeof zero))
2189 else if (code == ADDR_EXPR)
2191 struct addr_const value;
2192 decode_addr_const (exp, &value);
2193 strp = (char *) &value.offset;
2194 len = sizeof value.offset;
2195 /* Compare the offset. */
2197 if (*p++ != *strp++)
2199 /* Compare symbol name. */
2200 strp = XSTR (value.base, 0);
2201 len = strlen (strp) + 1;
2203 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2205 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2206 if (p == 0) return 0;
2207 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2210 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2212 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2216 /* Compare constant contents. */
2218 if (*p++ != *strp++)
2224 /* Construct a constant descriptor for the expression EXP.
2225 It is up to the caller to enter the descriptor in the hash table. */
2227 static struct constant_descriptor *
2228 record_constant (exp)
2231 struct constant_descriptor *next = 0;
2234 /* Make a struct constant_descriptor. The first two pointers will
2235 be filled in later. Here we just leave space for them. */
2237 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2238 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2239 record_constant_1 (exp);
2240 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2243 /* Add a description of constant expression EXP
2244 to the object growing in `permanent_obstack'.
2245 No need to return its address; the caller will get that
2246 from the obstack when the object is complete. */
2249 record_constant_1 (exp)
2252 register char *strp;
2254 register enum tree_code code = TREE_CODE (exp);
2256 obstack_1grow (&permanent_obstack, (unsigned int) code);
2258 if (code == INTEGER_CST)
2260 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2261 strp = (char *) &TREE_INT_CST_LOW (exp);
2262 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2264 else if (code == REAL_CST)
2266 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2267 strp = (char *) &TREE_REAL_CST (exp);
2268 len = sizeof TREE_REAL_CST (exp);
2270 else if (code == STRING_CST)
2272 if (flag_writable_strings)
2274 strp = TREE_STRING_POINTER (exp);
2275 len = TREE_STRING_LENGTH (exp);
2276 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2277 sizeof TREE_STRING_LENGTH (exp));
2279 else if (code == COMPLEX_CST)
2281 record_constant_1 (TREE_REALPART (exp));
2282 record_constant_1 (TREE_IMAGPART (exp));
2285 else if (code == CONSTRUCTOR)
2288 int length = list_length (CONSTRUCTOR_ELTS (exp));
2291 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2293 /* For record constructors, insist that the types match.
2294 For arrays, just verify both constructors are for arrays. */
2295 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2296 type = TREE_TYPE (exp);
2299 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2301 /* For arrays, insist that the size in bytes match. */
2302 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2304 int size = int_size_in_bytes (TREE_TYPE (exp));
2305 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2308 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2310 if (TREE_VALUE (link))
2311 record_constant_1 (TREE_VALUE (link));
2316 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
2322 else if (code == ADDR_EXPR)
2324 struct addr_const value;
2325 decode_addr_const (exp, &value);
2326 /* Record the offset. */
2327 obstack_grow (&permanent_obstack,
2328 (char *) &value.offset, sizeof value.offset);
2329 /* Record the symbol name. */
2330 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2331 strlen (XSTR (value.base, 0)) + 1);
2334 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2336 record_constant_1 (TREE_OPERAND (exp, 0));
2337 record_constant_1 (TREE_OPERAND (exp, 1));
2340 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2342 record_constant_1 (TREE_OPERAND (exp, 0));
2346 /* Record constant contents. */
2347 obstack_grow (&permanent_obstack, strp, len);
2350 /* Record a list of constant expressions that were passed to
2351 output_constant_def but that could not be output right away. */
2353 struct deferred_constant
2355 struct deferred_constant *next;
2361 static struct deferred_constant *deferred_constants;
2363 /* Nonzero means defer output of addressed subconstants
2364 (i.e., those for which output_constant_def is called.) */
2365 static int defer_addressed_constants_flag;
2367 /* Start deferring output of subconstants. */
2370 defer_addressed_constants ()
2372 defer_addressed_constants_flag++;
2375 /* Stop deferring output of subconstants,
2376 and output now all those that have been deferred. */
2379 output_deferred_addressed_constants ()
2381 struct deferred_constant *p, *next;
2383 defer_addressed_constants_flag--;
2385 if (defer_addressed_constants_flag > 0)
2388 for (p = deferred_constants; p; p = next)
2390 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2395 deferred_constants = 0;
2398 /* Make a copy of the whole tree structure for a constant.
2399 This handles the same types of nodes that compare_constant
2400 and record_constant handle. */
2406 switch (TREE_CODE (exp))
2412 /* For ADDR_EXPR, we do not want to copy the decl
2413 whose address is requested. */
2414 return copy_node (exp);
2417 return build_complex (copy_constant (TREE_REALPART (exp)),
2418 copy_constant (TREE_IMAGPART (exp)));
2422 return build (TREE_CODE (exp), TREE_TYPE (exp),
2423 copy_constant (TREE_OPERAND (exp, 0)),
2424 copy_constant (TREE_OPERAND (exp, 1)));
2428 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2429 copy_constant (TREE_OPERAND (exp, 0)));
2433 tree copy = copy_node (exp);
2434 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2437 CONSTRUCTOR_ELTS (exp) = list;
2438 for (tail = list; tail; tail = TREE_CHAIN (tail))
2439 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2449 /* Return an rtx representing a reference to constant data in memory
2450 for the constant expression EXP.
2452 If assembler code for such a constant has already been output,
2453 return an rtx to refer to it.
2454 Otherwise, output such a constant in memory (or defer it for later)
2455 and generate an rtx for it.
2457 The TREE_CST_RTL of EXP is set up to point to that rtx.
2458 The const_hash_table records which constants already have label strings. */
2461 output_constant_def (exp)
2465 register struct constant_descriptor *desc;
2471 if (TREE_CODE (exp) == INTEGER_CST)
2472 abort (); /* No TREE_CST_RTL slot in these. */
2474 if (TREE_CST_RTL (exp))
2475 return TREE_CST_RTL (exp);
2477 /* Make sure any other constants whose addresses appear in EXP
2478 are assigned label numbers. */
2480 reloc = output_addressed_constants (exp);
2482 /* Compute hash code of EXP. Search the descriptors for that hash code
2483 to see if any of them describes EXP. If yes, the descriptor records
2484 the label number already assigned. */
2486 if (!output_bytecode)
2488 hash = const_hash (exp) % MAX_HASH_TABLE;
2490 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2491 if (compare_constant (exp, desc))
2493 found = desc->label;
2499 /* No constant equal to EXP is known to have been output.
2500 Make a constant descriptor to enter EXP in the hash table.
2501 Assign the label number and record it in the descriptor for
2502 future calls to this function to find. */
2504 /* Create a string containing the label name, in LABEL. */
2505 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2507 desc = record_constant (exp);
2508 desc->next = const_hash_table[hash];
2510 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2511 const_hash_table[hash] = desc;
2515 /* Create a string containing the label name, in LABEL. */
2516 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2520 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2522 push_obstacks_nochange ();
2523 if (TREE_PERMANENT (exp))
2524 end_temporary_allocation ();
2526 if (!output_bytecode)
2528 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2531 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2532 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2533 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
2534 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2535 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2539 /* Optionally set flags or add text to the name to record information
2540 such as that it is a function name. If the name is changed, the macro
2541 ASM_OUTPUT_LABELREF will have to know how to strip this information.
2542 And if it finds a * at the beginning after doing so, it must handle
2544 #ifdef ENCODE_SECTION_INFO
2545 ENCODE_SECTION_INFO (exp);
2548 /* If this is the first time we've seen this particular constant,
2549 output it (or defer its output for later). */
2552 if (defer_addressed_constants_flag)
2554 struct deferred_constant *p;
2555 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2557 push_obstacks_nochange ();
2558 suspend_momentary ();
2559 p->exp = copy_constant (exp);
2562 p->labelno = const_labelno++;
2563 p->next = deferred_constants;
2564 deferred_constants = p;
2567 output_constant_def_contents (exp, reloc, const_labelno++);
2570 return TREE_CST_RTL (exp);
2573 /* Now output assembler code to define the label for EXP,
2574 and follow it with the data of EXP. */
2577 output_constant_def_contents (exp, reloc, labelno)
2584 /* First switch to text section, except for writable strings. */
2585 #ifdef SELECT_SECTION
2586 SELECT_SECTION (exp, reloc);
2588 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2589 || (flag_pic && reloc))
2592 readonly_data_section ();
2595 /* Align the location counter as required by EXP's data type. */
2596 align = TYPE_ALIGN (TREE_TYPE (exp));
2597 #ifdef CONSTANT_ALIGNMENT
2598 align = CONSTANT_ALIGNMENT (exp, align);
2601 if (align > BITS_PER_UNIT)
2603 if (!output_bytecode)
2605 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2609 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2613 /* Output the label itself. */
2614 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2616 /* Output the value of EXP. */
2617 output_constant (exp,
2618 (TREE_CODE (exp) == STRING_CST
2619 ? TREE_STRING_LENGTH (exp)
2620 : int_size_in_bytes (TREE_TYPE (exp))));
2624 /* Similar hash facility for making memory-constants
2625 from constant rtl-expressions. It is used on RISC machines
2626 where immediate integer arguments and constant addresses are restricted
2627 so that such constants must be stored in memory.
2629 This pool of constants is reinitialized for each function
2630 so each function gets its own constants-pool that comes right before it.
2632 All structures allocated here are discarded when functions are saved for
2633 inlining, so they do not need to be allocated permanently. */
2635 #define MAX_RTX_HASH_TABLE 61
2636 static struct constant_descriptor **const_rtx_hash_table;
2638 /* Structure to represent sufficient information about a constant so that
2639 it can be output when the constant pool is output, so that function
2640 integration can be done, and to simplify handling on machines that reference
2641 constant pool as base+displacement. */
2643 struct pool_constant
2645 struct constant_descriptor *desc;
2646 struct pool_constant *next;
2647 enum machine_mode mode;
2654 /* Pointers to first and last constant in pool. */
2656 static struct pool_constant *first_pool, *last_pool;
2658 /* Current offset in constant pool (does not include any machine-specific
2661 static int pool_offset;
2663 /* Structure used to maintain hash table mapping symbols used to their
2664 corresponding constants. */
2669 struct pool_constant *pool;
2670 struct pool_sym *next;
2673 static struct pool_sym **const_rtx_sym_hash_table;
2675 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2676 The argument is XSTR (... , 0) */
2678 #define SYMHASH(LABEL) \
2679 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2681 /* Initialize constant pool hashing for next function. */
2684 init_const_rtx_hash_table ()
2686 const_rtx_hash_table
2687 = ((struct constant_descriptor **)
2688 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2689 const_rtx_sym_hash_table
2690 = ((struct pool_sym **)
2691 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2692 bzero (const_rtx_hash_table,
2693 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2694 bzero (const_rtx_sym_hash_table,
2695 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2697 first_pool = last_pool = 0;
2701 /* Save and restore it for a nested function. */
2704 save_varasm_status (p)
2707 p->const_rtx_hash_table = const_rtx_hash_table;
2708 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2709 p->first_pool = first_pool;
2710 p->last_pool = last_pool;
2711 p->pool_offset = pool_offset;
2715 restore_varasm_status (p)
2718 const_rtx_hash_table = p->const_rtx_hash_table;
2719 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2720 first_pool = p->first_pool;
2721 last_pool = p->last_pool;
2722 pool_offset = p->pool_offset;
2725 enum kind { RTX_DOUBLE, RTX_INT };
2729 #ifdef ONLY_INT_FIELDS
2730 unsigned int kind : 16;
2731 unsigned int mode : 16;
2733 enum kind kind : 16;
2734 enum machine_mode mode : 16;
2737 union real_extract du;
2738 struct addr_const addr;
2742 /* Express an rtx for a constant integer (perhaps symbolic)
2743 as the sum of a symbol or label plus an explicit integer.
2744 They are stored into VALUE. */
2747 decode_rtx_const (mode, x, value)
2748 enum machine_mode mode;
2750 struct rtx_const *value;
2752 /* Clear the whole structure, including any gaps. */
2755 int *p = (int *) value;
2756 int *end = (int *) (value + 1);
2761 value->kind = RTX_INT; /* Most usual kind. */
2764 switch (GET_CODE (x))
2767 value->kind = RTX_DOUBLE;
2768 if (GET_MODE (x) != VOIDmode)
2769 value->mode = GET_MODE (x);
2770 bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
2774 value->un.addr.offset = INTVAL (x);
2780 value->un.addr.base = x;
2785 if (GET_CODE (x) == PLUS)
2787 value->un.addr.base = XEXP (x, 0);
2788 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2790 value->un.addr.offset = INTVAL (XEXP (x, 1));
2792 else if (GET_CODE (x) == MINUS)
2794 value->un.addr.base = XEXP (x, 0);
2795 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2797 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2807 if (value->kind == RTX_INT && value->un.addr.base != 0)
2808 switch (GET_CODE (value->un.addr.base))
2812 /* Use the string's address, not the SYMBOL_REF's address,
2813 for the sake of addresses of library routines.
2814 For a LABEL_REF, compare labels. */
2815 value->un.addr.base = XEXP (value->un.addr.base, 0);
2819 /* Given a MINUS expression, simplify it if both sides
2820 include the same symbol. */
2823 simplify_subtraction (x)
2826 struct rtx_const val0, val1;
2828 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2829 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2831 if (val0.un.addr.base == val1.un.addr.base)
2832 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2836 /* Compute a hash code for a constant RTL expression. */
2839 const_hash_rtx (mode, x)
2840 enum machine_mode mode;
2845 struct rtx_const value;
2846 decode_rtx_const (mode, x, &value);
2848 /* Compute hashing function */
2850 for (i = 0; i < sizeof value / sizeof (int); i++)
2851 hi += ((int *) &value)[i];
2853 hi &= (1 << HASHBITS) - 1;
2854 hi %= MAX_RTX_HASH_TABLE;
2858 /* Compare a constant rtl object X with a constant-descriptor DESC.
2859 Return 1 if DESC describes a constant with the same value as X. */
2862 compare_constant_rtx (mode, x, desc)
2863 enum machine_mode mode;
2865 struct constant_descriptor *desc;
2867 register int *p = (int *) desc->contents;
2870 struct rtx_const value;
2872 decode_rtx_const (mode, x, &value);
2873 strp = (int *) &value;
2874 len = sizeof value / sizeof (int);
2876 /* Compare constant contents. */
2878 if (*p++ != *strp++)
2884 /* Construct a constant descriptor for the rtl-expression X.
2885 It is up to the caller to enter the descriptor in the hash table. */
2887 static struct constant_descriptor *
2888 record_constant_rtx (mode, x)
2889 enum machine_mode mode;
2892 struct constant_descriptor *ptr;
2894 struct rtx_const value;
2896 decode_rtx_const (mode, x, &value);
2898 obstack_grow (current_obstack, &ptr, sizeof ptr);
2899 obstack_grow (current_obstack, &label, sizeof label);
2901 /* Record constant contents. */
2902 obstack_grow (current_obstack, &value, sizeof value);
2904 return (struct constant_descriptor *) obstack_finish (current_obstack);
2907 /* Given a constant rtx X, make (or find) a memory constant for its value
2908 and return a MEM rtx to refer to it in memory. */
2911 force_const_mem (mode, x)
2912 enum machine_mode mode;
2916 register struct constant_descriptor *desc;
2921 /* If we want this CONST_DOUBLE in the same mode as it is in memory
2922 (this will always be true for floating CONST_DOUBLEs that have been
2923 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
2924 use the previous copy. Otherwise, make a new one. Note that in
2925 the unlikely event that this same CONST_DOUBLE is used in two different
2926 modes in an alternating fashion, we will allocate a lot of different
2927 memory locations, but this should be extremely rare. */
2929 /* Don't use CONST_DOUBLE_MEM in a nested function.
2930 Nested functions have their own constant pools,
2931 so they can't share the same values in CONST_DOUBLE_MEM
2932 with the containing function. */
2933 if (outer_function_chain == 0)
2934 if (GET_CODE (x) == CONST_DOUBLE
2935 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
2936 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
2937 return CONST_DOUBLE_MEM (x);
2939 /* Compute hash code of X. Search the descriptors for that hash code
2940 to see if any of them describes X. If yes, the descriptor records
2941 the label number already assigned. */
2943 hash = const_hash_rtx (mode, x);
2945 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
2946 if (compare_constant_rtx (mode, x, desc))
2948 found = desc->label;
2954 register struct pool_constant *pool;
2955 register struct pool_sym *sym;
2958 /* No constant equal to X is known to have been output.
2959 Make a constant descriptor to enter X in the hash table.
2960 Assign the label number and record it in the descriptor for
2961 future calls to this function to find. */
2963 desc = record_constant_rtx (mode, x);
2964 desc->next = const_rtx_hash_table[hash];
2965 const_rtx_hash_table[hash] = desc;
2967 /* Align the location counter as required by EXP's data type. */
2968 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
2969 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2970 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
2972 pool_offset += align - 1;
2973 pool_offset &= ~ (align - 1);
2975 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
2977 pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
2981 pool->labelno = const_labelno;
2982 pool->align = align;
2983 pool->offset = pool_offset;
2989 last_pool->next = pool;
2992 pool_offset += GET_MODE_SIZE (mode);
2994 /* Create a string containing the label name, in LABEL. */
2995 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3000 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3002 /* Add label to symbol hash table. */
3003 hash = SYMHASH (found);
3004 sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
3007 sym->next = const_rtx_sym_hash_table[hash];
3008 const_rtx_sym_hash_table[hash] = sym;
3011 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3013 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3015 RTX_UNCHANGING_P (def) = 1;
3016 /* Mark the symbol_ref as belonging to this constants pool. */
3017 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3018 current_function_uses_const_pool = 1;
3020 if (outer_function_chain == 0)
3021 if (GET_CODE (x) == CONST_DOUBLE)
3023 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3025 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3026 const_double_chain = x;
3028 CONST_DOUBLE_MEM (x) = def;
3034 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3035 the corresponding pool_constant structure. */
3037 static struct pool_constant *
3038 find_pool_constant (addr)
3041 struct pool_sym *sym;
3042 char *label = XSTR (addr, 0);
3044 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3045 if (sym->label == label)
3051 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3054 get_pool_constant (addr)
3057 return (find_pool_constant (addr))->constant;
3060 /* Similar, return the mode. */
3063 get_pool_mode (addr)
3066 return (find_pool_constant (addr))->mode;
3069 /* Similar, return the offset in the constant pool. */
3072 get_pool_offset (addr)
3075 return (find_pool_constant (addr))->offset;
3078 /* Return the size of the constant pool. */
3086 /* Write all the constants in the constant pool. */
3089 output_constant_pool (fnname, fndecl)
3093 struct pool_constant *pool;
3095 union real_extract u;
3097 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3098 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3101 for (pool = first_pool; pool; pool = pool->next)
3105 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3106 whose CODE_LABEL has been deleted. This can occur if a jump table
3107 is eliminated by optimization. If so, write a constant of zero
3108 instead. Note that this can also happen by turning the
3109 CODE_LABEL into a NOTE. */
3110 if (((GET_CODE (x) == LABEL_REF
3111 && (INSN_DELETED_P (XEXP (x, 0))
3112 || GET_CODE (XEXP (x, 0)) == NOTE)))
3113 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3114 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3115 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3116 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3119 /* First switch to correct section. */
3120 #ifdef SELECT_RTX_SECTION
3121 SELECT_RTX_SECTION (pool->mode, x);
3123 readonly_data_section ();
3126 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3127 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3128 pool->align, pool->labelno, done);
3131 if (pool->align > 1)
3132 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3134 /* Output the label. */
3135 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3137 /* Output the value of the constant itself. */
3138 switch (GET_MODE_CLASS (pool->mode))
3141 if (GET_CODE (x) != CONST_DOUBLE)
3144 bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
3145 assemble_real (u.d, pool->mode);
3149 case MODE_PARTIAL_INT:
3150 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3160 /* Done with this pool. */
3161 first_pool = last_pool = 0;
3164 /* Find all the constants whose addresses are referenced inside of EXP,
3165 and make sure assembler code with a label has been output for each one.
3166 Indicate whether an ADDR_EXPR has been encountered. */
3169 output_addressed_constants (exp)
3174 switch (TREE_CODE (exp))
3178 register tree constant = TREE_OPERAND (exp, 0);
3180 while (TREE_CODE (constant) == COMPONENT_REF)
3182 constant = TREE_OPERAND (constant, 0);
3185 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3186 || TREE_CODE (constant) == CONSTRUCTOR)
3187 /* No need to do anything here
3188 for addresses of variables or functions. */
3189 output_constant_def (constant);
3196 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3197 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3202 case NON_LVALUE_EXPR:
3203 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3209 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3210 if (TREE_VALUE (link) != 0)
3211 reloc |= output_addressed_constants (TREE_VALUE (link));
3222 /* Output assembler for byte constant */
3224 output_byte_asm (byte)
3227 if (output_bytecode)
3228 bc_emit_const ((char *) &byte, sizeof (char));
3229 #ifdef ASM_OUTPUT_BYTE
3232 ASM_OUTPUT_BYTE (asm_out_file, byte);
3237 /* Output assembler code for constant EXP to FILE, with no label.
3238 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3239 Assumes output_addressed_constants has been done on EXP already.
3241 Generate exactly SIZE bytes of assembler data, padding at the end
3242 with zeros if necessary. SIZE must always be specified.
3244 SIZE is important for structure constructors,
3245 since trailing members may have been omitted from the constructor.
3246 It is also important for initialization of arrays from string constants
3247 since the full length of the string constant might not be wanted.
3248 It is also needed for initialization of unions, where the initializer's
3249 type is just one member, and that may not be as long as the union.
3251 There a case in which we would fail to output exactly SIZE bytes:
3252 for a structure constructor that wants to produce more than SIZE bytes.
3253 But such constructors will never be generated for any possible input. */
3256 output_constant (exp, size)
3260 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3266 /* Allow a constructor with no elements for any data type.
3267 This means to fill the space with zeros. */
3268 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3270 if (output_bytecode)
3271 bc_emit_const_skip (size);
3273 assemble_zeros (size);
3277 /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
3278 That way we get the constant (we hope) inside it. */
3279 if (TREE_CODE (exp) == NOP_EXPR
3280 && TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)))
3281 exp = TREE_OPERAND (exp, 0);
3290 case REFERENCE_TYPE:
3291 /* ??? What about (int)((float)(int)&foo + 4) */
3292 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3293 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3294 exp = TREE_OPERAND (exp, 0);
3296 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3297 EXPAND_INITIALIZER),
3299 error ("initializer for integer value is too complicated");
3304 if (TREE_CODE (exp) != REAL_CST)
3305 error ("initializer for floating value is not a floating constant");
3307 assemble_real (TREE_REAL_CST (exp),
3308 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3313 output_constant (TREE_REALPART (exp), size / 2);
3314 output_constant (TREE_IMAGPART (exp), size / 2);
3315 size -= (size / 2) * 2;
3319 if (TREE_CODE (exp) == CONSTRUCTOR)
3321 output_constructor (exp, size);
3324 else if (TREE_CODE (exp) == STRING_CST)
3328 if (size > TREE_STRING_LENGTH (exp))
3330 excess = size - TREE_STRING_LENGTH (exp);
3331 size = TREE_STRING_LENGTH (exp);
3334 assemble_string (TREE_STRING_POINTER (exp), size);
3343 if (TREE_CODE (exp) == CONSTRUCTOR)
3344 output_constructor (exp, size);
3351 assemble_zeros (size);
3355 /* Bytecode specific code to output assembler for integer. */
3357 bc_assemble_integer (exp, size)
3365 /* FIXME: is this fold() business going to be as good as the
3366 expand_expr() using EXPAND_SUM above in the RTL case? I
3368 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3372 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3373 exp = TREE_OPERAND (exp, 0);
3374 if (TREE_CODE (exp) == INTEGER_CST)
3379 else if (TREE_CODE (exp) == PLUS_EXPR)
3381 const_part = TREE_OPERAND (exp, 0);
3382 while (TREE_CODE (const_part) == NOP_EXPR
3383 || TREE_CODE (const_part) == CONVERT_EXPR)
3384 const_part = TREE_OPERAND (const_part, 0);
3385 addr_part = TREE_OPERAND (exp, 1);
3386 while (TREE_CODE (addr_part) == NOP_EXPR
3387 || TREE_CODE (addr_part) == CONVERT_EXPR)
3388 addr_part = TREE_OPERAND (addr_part, 0);
3389 if (TREE_CODE (const_part) != INTEGER_CST)
3390 tmp = const_part, const_part = addr_part, addr_part = tmp;
3391 if (TREE_CODE (const_part) != INTEGER_CST
3392 || TREE_CODE (addr_part) != ADDR_EXPR)
3393 abort (); /* FIXME: we really haven't considered
3394 all the possible cases here. */
3396 else if (TREE_CODE (exp) == ADDR_EXPR)
3398 const_part = integer_zero_node;
3402 abort (); /* FIXME: ditto previous. */
3408 char c = TREE_INT_CST_LOW (const_part);
3414 short s = TREE_INT_CST_LOW (const_part);
3415 bc_emit ((char *) &s, 2);
3420 int i = TREE_INT_CST_LOW (const_part);
3421 bc_emit ((char *) &i, 4);
3426 #if WORDS_BIG_ENDIAN
3427 int i = TREE_INT_CST_HIGH (const_part);
3428 bc_emit ((char *) &i, 4);
3429 i = TREE_INT_CST_LOW (const_part);
3430 bc_emit ((char *) &i, 4);
3432 int i = TREE_INT_CST_LOW (const_part);
3433 bc_emit ((char *) &i, 4);
3434 i = TREE_INT_CST_HIGH (const_part);
3435 bc_emit ((char *) &i, 4);
3442 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3443 bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3444 TREE_INT_CST_LOW (const_part));
3446 abort (); /* FIXME: there may be more cases. */
3449 /* Subroutine of output_constant, used for CONSTRUCTORs
3450 (aggregate constants).
3451 Generate at least SIZE bytes, padding if necessary. */
3454 output_constructor (exp, size)
3458 register tree link, field = 0;
3459 HOST_WIDE_INT min_index = 0;
3460 /* Number of bytes output or skipped so far.
3461 In other words, current position within the constructor. */
3462 int total_bytes = 0;
3463 /* Non-zero means BYTE contains part of a byte, to be output. */
3464 int byte_buffer_in_use = 0;
3467 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3470 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3471 field = TYPE_FIELDS (TREE_TYPE (exp));
3473 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3474 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3476 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3478 /* As LINK goes through the elements of the constant,
3479 FIELD goes through the structure fields, if the constant is a structure.
3480 if the constant is a union, then we override this,
3481 by getting the field from the TREE_LIST element.
3482 But the constant could also be an array. Then FIELD is zero. */
3483 for (link = CONSTRUCTOR_ELTS (exp);
3485 link = TREE_CHAIN (link),
3486 field = field ? TREE_CHAIN (field) : 0)
3488 tree val = TREE_VALUE (link);
3491 /* the element in a union constructor specifies the proper field. */
3493 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3494 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3496 /* if available, use the type given by link */
3497 if (TREE_PURPOSE (link) != 0)
3498 field = TREE_PURPOSE (link);
3501 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3502 index = TREE_PURPOSE (link);
3504 /* Eliminate the marker that makes a cast not be an lvalue. */
3508 if (field == 0 || !DECL_BIT_FIELD (field))
3510 /* An element that is not a bit-field. */
3512 register int fieldsize;
3513 /* Since this structure is static,
3514 we know the positions are constant. */
3515 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3519 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3521 * (TREE_INT_CST_LOW (index) - min_index));
3523 /* Output any buffered-up bit-fields preceding this element. */
3524 if (byte_buffer_in_use)
3526 ASM_OUTPUT_BYTE (asm_out_file, byte);
3528 byte_buffer_in_use = 0;
3531 /* Advance to offset of this element.
3532 Note no alignment needed in an array, since that is guaranteed
3533 if each element has the proper size. */
3534 if ((field != 0 || index != 0) && bitpos != total_bytes)
3536 if (!output_bytecode)
3537 assemble_zeros (bitpos - total_bytes);
3539 bc_emit_const_skip (bitpos - total_bytes);
3540 total_bytes = bitpos;
3543 /* Determine size this element should occupy. */
3546 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3548 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3550 /* This avoids overflow trouble. */
3551 tree size_tree = size_binop (CEIL_DIV_EXPR,
3553 size_int (BITS_PER_UNIT));
3554 fieldsize = TREE_INT_CST_LOW (size_tree);
3558 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3559 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3563 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3565 /* Output the element's initial value. */
3567 assemble_zeros (fieldsize);
3569 output_constant (val, fieldsize);
3571 /* Count its size. */
3572 total_bytes += fieldsize;
3574 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3575 error ("invalid initial value for member `%s'",
3576 IDENTIFIER_POINTER (DECL_NAME (field)));
3579 /* Element that is a bit-field. */
3581 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3583 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3586 val = integer_zero_node;
3588 /* If this field does not start in this (or, next) byte,
3590 if (next_offset / BITS_PER_UNIT != total_bytes)
3592 /* Output remnant of any bit field in previous bytes. */
3593 if (byte_buffer_in_use)
3595 ASM_OUTPUT_BYTE (asm_out_file, byte);
3597 byte_buffer_in_use = 0;
3600 /* If still not at proper byte, advance to there. */
3601 if (next_offset / BITS_PER_UNIT != total_bytes)
3603 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3604 total_bytes = next_offset / BITS_PER_UNIT;
3608 if (! byte_buffer_in_use)
3611 /* We must split the element into pieces that fall within
3612 separate bytes, and combine each byte with previous or
3613 following bit-fields. */
3615 /* next_offset is the offset n fbits from the beginning of
3616 the structure to the next bit of this element to be processed.
3617 end_offset is the offset of the first bit past the end of
3619 while (next_offset < end_offset)
3623 int next_byte = next_offset / BITS_PER_UNIT;
3624 int next_bit = next_offset % BITS_PER_UNIT;
3626 /* Advance from byte to byte
3627 within this element when necessary. */
3628 while (next_byte != total_bytes)
3630 ASM_OUTPUT_BYTE (asm_out_file, byte);
3635 /* Number of bits we can process at once
3636 (all part of the same byte). */
3637 this_time = MIN (end_offset - next_offset,
3638 BITS_PER_UNIT - next_bit);
3639 #if BYTES_BIG_ENDIAN
3640 /* On big-endian machine, take the most significant bits
3641 first (of the bits that are significant)
3642 and put them into bytes from the most significant end. */
3643 shift = end_offset - next_offset - this_time;
3644 /* Don't try to take a bunch of bits that cross
3645 the word boundary in the INTEGER_CST. */
3646 if (shift < HOST_BITS_PER_WIDE_INT
3647 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3649 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3650 shift = HOST_BITS_PER_WIDE_INT;
3653 /* Now get the bits from the appropriate constant word. */
3654 if (shift < HOST_BITS_PER_WIDE_INT)
3656 value = TREE_INT_CST_LOW (val);
3658 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3660 value = TREE_INT_CST_HIGH (val);
3661 shift -= HOST_BITS_PER_WIDE_INT;
3665 byte |= (((value >> shift)
3666 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3667 << (BITS_PER_UNIT - this_time - next_bit));
3669 /* On little-endian machines,
3670 take first the least significant bits of the value
3671 and pack them starting at the least significant
3672 bits of the bytes. */
3673 shift = (next_offset
3674 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3675 /* Don't try to take a bunch of bits that cross
3676 the word boundary in the INTEGER_CST. */
3677 if (shift < HOST_BITS_PER_WIDE_INT
3678 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3680 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3681 shift = HOST_BITS_PER_WIDE_INT;
3684 /* Now get the bits from the appropriate constant word. */
3685 if (shift < HOST_BITS_PER_INT)
3686 value = TREE_INT_CST_LOW (val);
3687 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3689 value = TREE_INT_CST_HIGH (val);
3690 shift -= HOST_BITS_PER_WIDE_INT;
3694 byte |= ((value >> shift)
3695 & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
3697 next_offset += this_time;
3698 byte_buffer_in_use = 1;
3702 if (byte_buffer_in_use)
3704 ASM_OUTPUT_BYTE (asm_out_file, byte);
3707 if (total_bytes < size)
3708 assemble_zeros (size - total_bytes);
3712 #ifdef HANDLE_SYSV_PRAGMA
3714 /* Support #pragma weak by default if WEAK_ASM_OP is defined. */
3715 #if defined (HANDLE_PRAGMA_WEAK) || (defined (WEAK_ASM_OP) && defined (SET_ASM_OP))
3717 /* See c-pragma.c for an identical definition. */
3733 /* Output asm to handle ``#pragma weak'' */
3735 handle_pragma_weak (what, asm_out_file, name, value)
3736 enum pragma_state what;
3740 if (what == ps_name || what == ps_value)
3742 fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
3744 if (output_bytecode)
3745 BC_OUTPUT_LABELREF (asm_out_file, name);
3747 ASM_OUTPUT_LABELREF (asm_out_file, name);
3749 fputc ('\n', asm_out_file);
3750 if (what == ps_value)
3752 fprintf (asm_out_file, "\t%s\t", SET_ASM_OP);
3753 if (output_bytecode)
3754 BC_OUTPUT_LABELREF (asm_out_file, name);
3756 ASM_OUTPUT_LABELREF (asm_out_file, name);
3758 fputc (',', asm_out_file);
3759 if (output_bytecode)
3760 BC_OUTPUT_LABELREF (asm_out_file, value);
3762 ASM_OUTPUT_LABELREF (asm_out_file, value);
3764 fputc ('\n', asm_out_file);
3767 else if (! (what == ps_done || what == ps_start))
3768 warning ("malformed `#pragma weak'");
3771 #endif /* HANDLE_PRAGMA_WEAK or (WEAK_ASM_OP and SET_ASM_OP) */
3773 #endif /* HANDLE_SYSV_PRAGMA */