1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92, 93, 1994 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 *rtl_obstack;
73 extern struct obstack permanent_obstack;
74 #define obstack_chunk_alloc xmalloc
76 /* Number for making the label on the next
77 constant that is stored in memory. */
81 /* Number for making the label on the next
82 static variable internal to a function. */
86 /* Carry information from ASM_DECLARE_OBJECT_NAME
87 to ASM_FINISH_DECLARE_OBJECT. */
89 int size_directive_output;
91 /* The last decl for which assemble_variable was called,
92 if it did ASM_DECLARE_OBJECT_NAME.
93 If the last call to assemble_variable didn't do that,
96 tree last_assemble_variable_decl;
98 /* Nonzero if at least one function definition has been seen. */
99 static int function_defined;
101 extern FILE *asm_out_file;
103 static char *compare_constant_1 ();
104 static void record_constant_1 ();
105 static void output_constant_def_contents ();
106 static int contains_pointers_p ();
107 static void bc_output_ascii ();
109 void output_constant_pool ();
110 void assemble_name ();
111 int output_addressed_constants ();
112 void output_constant ();
113 void output_constructor ();
114 void output_byte_asm ();
115 void text_section ();
116 void readonly_data_section ();
117 void data_section ();
118 void named_section ();
119 static void bc_assemble_integer ();
121 #ifdef EXTRA_SECTIONS
122 static enum in_section {no_section, in_text, in_data, in_named, EXTRA_SECTIONS} in_section
125 static enum in_section {no_section, in_text, in_data, in_named} in_section
129 /* Return a non-zero value if DECL has a section attribute. */
130 #define IN_NAMED_SECTION(DECL) \
131 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
132 && DECL_SECTION_NAME (DECL) != NULL_TREE)
134 /* Text of section name when in_section == in_named. */
135 static char *in_named_name;
137 /* Define functions like text_section for any extra sections. */
138 #ifdef EXTRA_SECTION_FUNCTIONS
139 EXTRA_SECTION_FUNCTIONS
142 /* Tell assembler to switch to text section. */
147 if (in_section != in_text)
152 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
154 in_section = in_text;
158 /* Tell assembler to switch to data section. */
163 if (in_section != in_data)
169 if (flag_shared_data)
171 #ifdef SHARED_SECTION_ASM_OP
172 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
174 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
178 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
181 in_section = in_data;
185 /* Tell assembler to switch to read-only data section. This is normally
189 readonly_data_section ()
191 #ifdef READONLY_DATA_SECTION
192 READONLY_DATA_SECTION (); /* Note this can call data_section. */
198 /* Determine if we're in the text section. */
203 return in_section == in_text;
206 /* Tell assembler to change to section NAME for DECL.
207 If DECL is NULL, just switch to section NAME.
208 If NAME is NULL, get the name from DECL. */
211 named_section (decl, name)
215 if (decl != NULL_TREE
216 && (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL))
219 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
221 if (in_section != in_named || strcmp (name, in_named_name))
223 in_named_name = name;
224 in_section = in_named;
226 #ifdef ASM_OUTPUT_SECTION_NAME
227 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name);
229 /* Section attributes are not supported if this macro isn't provided -
230 some host formats don't support them at all. The front-end should
231 already have flagged this as an error. */
237 /* Create the rtl to represent a function, for a function definition.
238 DECL is a FUNCTION_DECL node which describes which function.
239 The rtl is stored into DECL. */
242 make_function_rtl (decl)
245 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
249 if (DECL_RTL (decl) == 0)
250 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
252 /* Record that at least one function has been defined. */
253 function_defined = 1;
257 /* Rename a nested function to avoid conflicts. */
258 if (decl_function_context (decl) != 0
259 && DECL_INITIAL (decl) != 0
260 && DECL_RTL (decl) == 0)
264 name = IDENTIFIER_POINTER (DECL_NAME (decl));
265 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
266 name = obstack_copy0 (saveable_obstack, label, strlen (label));
270 if (DECL_RTL (decl) == 0)
273 = gen_rtx (MEM, DECL_MODE (decl),
274 gen_rtx (SYMBOL_REF, Pmode, name));
276 /* Optionally set flags or add text to the name to record information
277 such as that it is a function name. If the name is changed, the macro
278 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
279 #ifdef ENCODE_SECTION_INFO
280 ENCODE_SECTION_INFO (decl);
284 /* Record at least one function has been defined. */
285 function_defined = 1;
288 /* Create the DECL_RTL for a declaration for a static or external
289 variable or static or external function.
290 ASMSPEC, if not 0, is the string which the user specified
291 as the assembler symbol name.
292 TOP_LEVEL is nonzero if this is a file-scope variable.
293 This is never called for PARM_DECLs. */
295 bc_make_decl_rtl (decl, asmspec, top_level)
300 register char *name = TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl));
302 if (DECL_RTL (decl) == 0)
304 /* Print an error message for register variables. */
305 if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
306 error ("function declared `register'");
307 else if (DECL_REGISTER (decl))
308 error ("global register variables not supported in the interpreter");
310 /* Handle ordinary static variables and functions. */
311 if (DECL_RTL (decl) == 0)
313 /* Can't use just the variable's own name for a variable
314 whose scope is less than the whole file.
315 Concatenate a distinguishing number. */
316 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
320 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
321 name = obstack_copy0 (saveable_obstack, label, strlen (label));
325 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
330 /* Given NAME, a putative register name, discard any customary prefixes. */
333 strip_reg_name (name)
336 #ifdef REGISTER_PREFIX
337 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
338 name += strlen (REGISTER_PREFIX);
340 if (name[0] == '%' || name[0] == '#')
345 /* Decode an `asm' spec for a declaration as a register name.
346 Return the register number, or -1 if nothing specified,
347 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
348 or -3 if ASMSPEC is `cc' and is not recognized,
349 or -4 if ASMSPEC is `memory' and is not recognized.
350 Accept an exact spelling or a decimal number.
351 Prefixes such as % are optional. */
354 decode_reg_name (asmspec)
361 /* Get rid of confusing prefixes. */
362 asmspec = strip_reg_name (asmspec);
364 /* Allow a decimal number as a "register name". */
365 for (i = strlen (asmspec) - 1; i >= 0; i--)
366 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
368 if (asmspec[0] != 0 && i < 0)
371 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
377 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
379 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
382 #ifdef ADDITIONAL_REGISTER_NAMES
384 static struct { char *name; int number; } table[]
385 = ADDITIONAL_REGISTER_NAMES;
387 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
388 if (! strcmp (asmspec, table[i].name))
389 return table[i].number;
391 #endif /* ADDITIONAL_REGISTER_NAMES */
393 if (!strcmp (asmspec, "memory"))
396 if (!strcmp (asmspec, "cc"))
405 /* Create the DECL_RTL for a declaration for a static or external variable
406 or static or external function.
407 ASMSPEC, if not 0, is the string which the user specified
408 as the assembler symbol name.
409 TOP_LEVEL is nonzero if this is a file-scope variable.
411 This is never called for PARM_DECL nodes. */
414 make_decl_rtl (decl, asmspec, top_level)
419 register char *name = 0;
424 bc_make_decl_rtl (decl, asmspec, top_level);
428 reg_number = decode_reg_name (asmspec);
430 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
431 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
433 if (reg_number == -2)
435 /* ASMSPEC is given, and not the name of a register. */
436 name = (char *) obstack_alloc (saveable_obstack,
437 strlen (asmspec) + 2);
439 strcpy (&name[1], asmspec);
442 /* For a duplicate declaration, we can be called twice on the
443 same DECL node. Don't discard the RTL already made. */
444 if (DECL_RTL (decl) == 0)
448 /* First detect errors in declaring global registers. */
449 if (DECL_REGISTER (decl) && reg_number == -1)
450 error_with_decl (decl,
451 "register name not specified for `%s'");
452 else if (DECL_REGISTER (decl) && reg_number < 0)
453 error_with_decl (decl,
454 "invalid register name for `%s'");
455 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
456 error_with_decl (decl,
457 "register name given for non-register variable `%s'");
458 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
459 error ("function declared `register'");
460 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
461 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
462 else if (DECL_REGISTER (decl)
463 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
464 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
465 /* Now handle properly declared static register variables. */
466 else if (DECL_REGISTER (decl))
469 #if 0 /* yylex should print the warning for this */
471 pedwarn ("ANSI C forbids global register variables");
473 if (DECL_INITIAL (decl) != 0 && top_level)
475 DECL_INITIAL (decl) = 0;
476 error ("global register variable has initial value");
478 if (fixed_regs[reg_number] == 0
479 && function_defined && top_level)
480 error ("global register variable follows a function definition");
481 if (TREE_THIS_VOLATILE (decl))
482 warning ("volatile register variables don't work as you might wish");
484 /* If the user specified one of the eliminables registers here,
485 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
486 confused with that register and be eliminated. Although this
487 usage is somewhat suspect, we nevertheless use the following
488 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
491 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
492 REGNO (DECL_RTL (decl)) = reg_number;
493 REG_USERVAR_P (DECL_RTL (decl)) = 1;
497 /* Make this register global, so not usable for anything
499 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
501 globalize_reg (reg_number + --nregs);
504 /* Specifying a section attribute on an uninitialized variable does not
505 (and cannot) cause it to be put in the given section. The linker
506 can only put initialized objects in specific sections, everything
507 else goes in bss for the linker to sort out later (otherwise the
508 linker would give a duplicate definition error for each compilation
509 unit that behaved thusly). So warn the user. */
510 else if (TREE_CODE (decl) == VAR_DECL
511 && DECL_SECTION_NAME (decl) != NULL_TREE
512 && DECL_INITIAL (decl) == NULL_TREE)
514 warning_with_decl (decl,
515 "section attribute ignored for uninitialized variable `%s'");
516 /* Remove the section name so subsequent declarations won't see it.
517 We are ignoring it, remember. */
518 DECL_SECTION_NAME (decl) = NULL_TREE;
521 /* Now handle ordinary static variables and functions (in memory).
522 Also handle vars declared register invalidly. */
523 if (DECL_RTL (decl) == 0)
525 /* Can't use just the variable's own name for a variable
526 whose scope is less than the whole file.
527 Concatenate a distinguishing number. */
528 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
532 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
533 name = obstack_copy0 (saveable_obstack, label, strlen (label));
540 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
541 gen_rtx (SYMBOL_REF, Pmode, name));
543 /* If this variable is to be treated as volatile, show its
544 tree node has side effects. If it has side effects, either
545 because of this test or from TREE_THIS_VOLATILE also
546 being set, show the MEM is volatile. */
547 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
548 && TREE_PUBLIC (decl))
549 TREE_SIDE_EFFECTS (decl) = 1;
550 if (TREE_SIDE_EFFECTS (decl))
551 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
553 if (TREE_READONLY (decl))
554 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
555 MEM_IN_STRUCT_P (DECL_RTL (decl))
556 = AGGREGATE_TYPE_P (TREE_TYPE (decl));
558 /* Optionally set flags or add text to the name to record information
559 such as that it is a function name.
560 If the name is changed, the macro ASM_OUTPUT_LABELREF
561 will have to know how to strip this information. */
562 #ifdef ENCODE_SECTION_INFO
563 ENCODE_SECTION_INFO (decl);
567 /* If the old RTL had the wrong mode, fix the mode. */
568 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
570 rtx rtl = DECL_RTL (decl);
571 PUT_MODE (rtl, DECL_MODE (decl));
575 /* Make the rtl for variable VAR be volatile.
576 Use this only for static variables. */
579 make_var_volatile (var)
582 if (GET_CODE (DECL_RTL (var)) != MEM)
585 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
588 /* Output alignment directive to align for constant expression EXP. */
591 assemble_constant_align (exp)
596 /* Align the location counter as required by EXP's data type. */
597 align = TYPE_ALIGN (TREE_TYPE (exp));
598 #ifdef CONSTANT_ALIGNMENT
599 align = CONSTANT_ALIGNMENT (exp, align);
602 if (align > BITS_PER_UNIT)
603 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
606 /* Output a string of literal assembler code
607 for an `asm' keyword used between functions. */
610 assemble_asm (string)
615 error ("asm statements not allowed in interpreter");
621 if (TREE_CODE (string) == ADDR_EXPR)
622 string = TREE_OPERAND (string, 0);
624 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
627 #if 0 /* This should no longer be needed, because
628 flag_gnu_linker should be 0 on these systems,
629 which should prevent any output
630 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
631 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
632 #ifndef ASM_OUTPUT_CONSTRUCTOR
633 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
635 #ifndef ASM_OUTPUT_DESTRUCTOR
636 #define ASM_OUTPUT_DESTRUCTOR(file, name)
641 /* Record an element in the table of global destructors.
642 How this is done depends on what sort of assembler and linker
645 NAME should be the name of a global function to be called
646 at exit time. This name is output using assemble_name. */
649 assemble_destructor (name)
652 #ifdef ASM_OUTPUT_DESTRUCTOR
653 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
657 /* Now tell GNU LD that this is part of the static destructor set. */
658 /* This code works for any machine provided you use GNU as/ld. */
659 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
660 assemble_name (asm_out_file, name);
661 fputc ('\n', asm_out_file);
666 /* Likewise for global constructors. */
669 assemble_constructor (name)
672 #ifdef ASM_OUTPUT_CONSTRUCTOR
673 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
677 /* Now tell GNU LD that this is part of the static constructor set. */
678 /* This code works for any machine provided you use GNU as/ld. */
679 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
680 assemble_name (asm_out_file, name);
681 fputc ('\n', asm_out_file);
686 /* Likewise for entries we want to record for garbage collection.
687 Garbage collection is still under development. */
690 assemble_gc_entry (name)
693 #ifdef ASM_OUTPUT_GC_ENTRY
694 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
698 /* Now tell GNU LD that this is part of the static constructor set. */
699 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
700 assemble_name (asm_out_file, name);
701 fputc ('\n', asm_out_file);
706 /* Output assembler code for the constant pool of a function and associated
707 with defining the name of the function. DECL describes the function.
708 NAME is the function's name. For the constant pool, we use the current
709 constant pool data. */
712 assemble_start_function (decl, fnname)
718 /* The following code does not need preprocessing in the assembler. */
722 output_constant_pool (fnname, decl);
724 if (IN_NAMED_SECTION (decl))
725 named_section (decl, NULL);
729 /* Tell assembler to move to target machine's alignment for functions. */
730 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
734 BC_OUTPUT_ALIGN (asm_out_file, align);
736 ASM_OUTPUT_ALIGN (asm_out_file, align);
739 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
740 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
743 #ifdef SDB_DEBUGGING_INFO
744 /* Output SDB definition of the function. */
745 if (write_symbols == SDB_DEBUG)
746 sdbout_mark_begin_function ();
749 #ifdef DBX_DEBUGGING_INFO
750 /* Output DBX definition of the function. */
751 if (write_symbols == DBX_DEBUG)
752 dbxout_begin_function (decl);
755 /* Make function name accessible from other files, if appropriate. */
757 if (TREE_PUBLIC (decl))
759 if (!first_global_object_name)
760 STRIP_NAME_ENCODING (first_global_object_name, fnname);
762 BC_GLOBALIZE_LABEL (asm_out_file, fnname);
764 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
767 /* Do any machine/system dependent processing of the function name */
768 #ifdef ASM_DECLARE_FUNCTION_NAME
769 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
771 /* Standard thing is just output label for the function. */
773 BC_OUTPUT_LABEL (asm_out_file, fnname);
775 ASM_OUTPUT_LABEL (asm_out_file, fnname);
776 #endif /* ASM_DECLARE_FUNCTION_NAME */
779 /* Output assembler code associated with defining the size of the
780 function. DECL describes the function. NAME is the function's name. */
783 assemble_end_function (decl, fnname)
787 #ifdef ASM_DECLARE_FUNCTION_SIZE
788 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
792 /* Assemble code to leave SIZE bytes of zeros. */
795 assemble_zeros (size)
800 bc_emit_const_skip (size);
804 #ifdef ASM_NO_SKIP_IN_TEXT
805 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
806 so we must output 0s explicitly in the text section. */
807 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
811 for (i = 0; i < size - 20; i += 20)
814 fprintf (asm_out_file,
815 "%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);
817 fprintf (asm_out_file,
818 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
824 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
826 fprintf (asm_out_file, "\tbyte 0");
829 for (; i < size; i++)
830 fprintf (asm_out_file, ",0");
831 fprintf (asm_out_file, "\n");
839 BC_OUTPUT_SKIP (asm_out_file, size);
841 ASM_OUTPUT_SKIP (asm_out_file, size);
845 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
848 assemble_align (align)
851 if (align > BITS_PER_UNIT)
852 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
855 /* Assemble a string constant with the specified C string as contents. */
858 assemble_string (p, size)
872 /* If the string is very long, split it up. */
876 int thissize = size - pos;
877 if (thissize > maximum)
881 bc_output_ascii (asm_out_file, p, thissize);
884 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
893 bc_output_ascii (file, p, size)
898 BC_OUTPUT_ASCII (file, p, size);
901 /* Assemble everything that is needed for a variable or function declaration.
902 Not used for automatic variables, and not used for function definitions.
903 Should not be called for variables of incomplete structure type.
905 TOP_LEVEL is nonzero if this variable has file scope.
906 AT_END is nonzero if this is the special handling, at end of compilation,
907 to define things that have had only tentative definitions.
908 DONT_OUTPUT_DATA if nonzero means don't actually output the
909 initial value (that will be done by the caller). */
912 assemble_variable (decl, top_level, at_end, dont_output_data)
921 enum in_section saved_in_section;
923 last_assemble_variable_decl = 0;
928 if (GET_CODE (DECL_RTL (decl)) == REG)
930 /* Do output symbol info for global register variables, but do nothing
933 if (TREE_ASM_WRITTEN (decl))
935 TREE_ASM_WRITTEN (decl) = 1;
937 if (!output_bytecode)
939 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
940 /* File-scope global variables are output here. */
941 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
943 dbxout_symbol (decl, 0);
945 #ifdef SDB_DEBUGGING_INFO
946 if (write_symbols == SDB_DEBUG && top_level
947 /* Leave initialized global vars for end of compilation;
948 see comment in compile_file. */
949 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
950 sdbout_symbol (decl, 0);
954 /* Don't output any DWARF debugging information for variables here.
955 In the case of local variables, the information for them is output
956 when we do our recursive traversal of the tree representation for
957 the entire containing function. In the case of file-scope variables,
958 we output information for all of them at the very end of compilation
959 while we are doing our final traversal of the chain of file-scope
965 /* Normally no need to say anything here for external references,
966 since assemble_external is called by the langauge-specific code
967 when a declaration is first seen. */
969 if (DECL_EXTERNAL (decl))
972 /* Output no assembler code for a function declaration.
973 Only definitions of functions output anything. */
975 if (TREE_CODE (decl) == FUNCTION_DECL)
978 /* If type was incomplete when the variable was declared,
979 see if it is complete now. */
981 if (DECL_SIZE (decl) == 0)
982 layout_decl (decl, 0);
984 /* Still incomplete => don't allocate it; treat the tentative defn
985 (which is what it must have been) as an `extern' reference. */
987 if (!dont_output_data && DECL_SIZE (decl) == 0)
989 error_with_file_and_line (DECL_SOURCE_FILE (decl),
990 DECL_SOURCE_LINE (decl),
991 "storage size of `%s' isn't known",
992 IDENTIFIER_POINTER (DECL_NAME (decl)));
993 TREE_ASM_WRITTEN (decl) = 1;
997 /* The first declaration of a variable that comes through this function
998 decides whether it is global (in C, has external linkage)
999 or local (in C, has internal linkage). So do nothing more
1000 if this function has already run. */
1002 if (TREE_ASM_WRITTEN (decl))
1005 TREE_ASM_WRITTEN (decl) = 1;
1007 /* If storage size is erroneously variable, just continue.
1008 Error message was already made. */
1010 if (DECL_SIZE (decl))
1012 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1017 /* This is better than explicit arithmetic, since it avoids overflow. */
1018 size_tree = size_binop (CEIL_DIV_EXPR,
1019 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1021 if (TREE_INT_CST_HIGH (size_tree) != 0)
1023 error_with_decl (decl, "size of variable `%s' is too large");
1028 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1030 /* Handle uninitialized definitions. */
1032 /* ANSI specifies that a tentative definition which is not merged with
1033 a non-tentative definition behaves exactly like a definition with an
1034 initializer equal to zero. (Section 3.7.2)
1035 -fno-common gives strict ANSI behavior. Usually you don't want it.
1036 This matters only for variables with external linkage. */
1037 if ((! flag_no_common || ! TREE_PUBLIC (decl))
1038 && DECL_COMMON (decl)
1039 && ! dont_output_data
1040 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
1042 int size = TREE_INT_CST_LOW (size_tree);
1045 if (TREE_INT_CST_HIGH (size_tree) != 0)
1046 error_with_decl (decl, "size of variable `%s' is too large");
1047 /* Don't allocate zero bytes of common,
1048 since that means "undefined external" in the linker. */
1049 if (size == 0) rounded = 1;
1050 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1051 so that each uninitialized object starts on such a boundary. */
1052 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1053 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1054 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1056 #ifdef DBX_DEBUGGING_INFO
1057 /* File-scope global variables are output here. */
1058 if (write_symbols == DBX_DEBUG && top_level)
1059 dbxout_symbol (decl, 0);
1061 #ifdef SDB_DEBUGGING_INFO
1062 if (write_symbols == SDB_DEBUG && top_level
1063 /* Leave initialized global vars for end of compilation;
1064 see comment in compile_file. */
1065 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1066 sdbout_symbol (decl, 0);
1069 /* Don't output any DWARF debugging information for variables here.
1070 In the case of local variables, the information for them is output
1071 when we do our recursive traversal of the tree representation for
1072 the entire containing function. In the case of file-scope variables,
1073 we output information for all of them at the very end of compilation
1074 while we are doing our final traversal of the chain of file-scope
1078 if (flag_shared_data)
1081 if (TREE_PUBLIC (decl))
1083 #ifdef ASM_OUTPUT_SHARED_COMMON
1084 if (flag_shared_data)
1085 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1088 if (output_bytecode)
1090 BC_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1094 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1095 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1098 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1104 #ifdef ASM_OUTPUT_SHARED_LOCAL
1105 if (flag_shared_data)
1106 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1109 if (output_bytecode)
1111 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1115 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1116 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1119 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1126 /* Handle initialized definitions. */
1128 /* First make the assembler name(s) global if appropriate. */
1129 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1131 if (!first_global_object_name)
1132 STRIP_NAME_ENCODING(first_global_object_name, name);
1133 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1136 for (d = equivalents; d; d = TREE_CHAIN (d))
1138 tree e = TREE_VALUE (d);
1139 if (TREE_PUBLIC (e) && DECL_NAME (e))
1140 ASM_GLOBALIZE_LABEL (asm_out_file,
1141 XSTR (XEXP (DECL_RTL (e), 0), 0));
1145 /* Output any data that we will need to use the address of. */
1146 if (DECL_INITIAL (decl) == error_mark_node)
1147 reloc = contains_pointers_p (TREE_TYPE (decl));
1148 else if (DECL_INITIAL (decl))
1149 reloc = output_addressed_constants (DECL_INITIAL (decl));
1151 /* Switch to the proper section for this data. */
1152 if (IN_NAMED_SECTION (decl))
1153 named_section (decl, NULL);
1156 /* C++ can have const variables that get initialized from constructors,
1157 and thus can not be in a readonly section. We prevent this by
1158 verifying that the initial value is constant for objects put in a
1161 error_mark_node is used by the C front end to indicate that the
1162 initializer has not been seen yet. In this case, we assume that
1163 the initializer must be constant. */
1164 #ifdef SELECT_SECTION
1165 SELECT_SECTION (decl, reloc);
1167 if (TREE_READONLY (decl)
1168 && ! TREE_THIS_VOLATILE (decl)
1169 && DECL_INITIAL (decl)
1170 && (DECL_INITIAL (decl) == error_mark_node
1171 || TREE_CONSTANT (DECL_INITIAL (decl)))
1172 && ! (flag_pic && reloc))
1173 readonly_data_section ();
1179 /* dbxout.c needs to know this. */
1180 if (in_text_section ())
1181 DECL_IN_TEXT_SECTION (decl) = 1;
1183 /* Record current section so we can restore it if dbxout.c clobbers it. */
1184 saved_in_section = in_section;
1186 /* Output the dbx info now that we have chosen the section. */
1188 #ifdef DBX_DEBUGGING_INFO
1189 /* File-scope global variables are output here. */
1190 if (write_symbols == DBX_DEBUG && top_level)
1191 dbxout_symbol (decl, 0);
1193 #ifdef SDB_DEBUGGING_INFO
1194 if (write_symbols == SDB_DEBUG && top_level
1195 /* Leave initialized global vars for end of compilation;
1196 see comment in compile_file. */
1197 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1198 sdbout_symbol (decl, 0);
1201 /* Don't output any DWARF debugging information for variables here.
1202 In the case of local variables, the information for them is output
1203 when we do our recursive traversal of the tree representation for
1204 the entire containing function. In the case of file-scope variables,
1205 we output information for all of them at the very end of compilation
1206 while we are doing our final traversal of the chain of file-scope
1209 /* If the debugging output changed sections, reselect the section
1210 that's supposed to be selected. */
1211 if (in_section != saved_in_section)
1213 /* Switch to the proper section for this data. */
1214 #ifdef SELECT_SECTION
1215 SELECT_SECTION (decl, reloc);
1217 if (TREE_READONLY (decl)
1218 && ! TREE_THIS_VOLATILE (decl)
1219 && DECL_INITIAL (decl)
1220 && (DECL_INITIAL (decl) == error_mark_node
1221 || TREE_CONSTANT (DECL_INITIAL (decl)))
1222 && ! (flag_pic && reloc))
1223 readonly_data_section ();
1229 /* Compute and output the alignment of this data. */
1231 align = DECL_ALIGN (decl);
1232 /* In the case for initialing an array whose length isn't specified,
1233 where we have not yet been able to do the layout,
1234 figure out the proper alignment now. */
1235 if (dont_output_data && DECL_SIZE (decl) == 0
1236 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1237 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1239 /* Some object file formats have a maximum alignment which they support.
1240 In particular, a.out format supports a maximum alignment of 4. */
1241 #ifndef MAX_OFILE_ALIGNMENT
1242 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1244 if (align > MAX_OFILE_ALIGNMENT)
1246 warning_with_decl (decl,
1247 "alignment of `%s' is greater than maximum object file alignment");
1248 align = MAX_OFILE_ALIGNMENT;
1250 #ifdef DATA_ALIGNMENT
1251 /* On some machines, it is good to increase alignment sometimes. */
1252 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1254 #ifdef CONSTANT_ALIGNMENT
1255 if (DECL_INITIAL (decl))
1256 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1259 /* Reset the alignment in case we have made it tighter, so we can benefit
1260 from it in get_pointer_alignment. */
1261 DECL_ALIGN (decl) = align;
1263 if (align > BITS_PER_UNIT)
1265 if (output_bytecode)
1266 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1268 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1271 /* Do any machine/system dependent processing of the object. */
1272 #ifdef ASM_DECLARE_OBJECT_NAME
1273 last_assemble_variable_decl = decl;
1274 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1276 /* Standard thing is just output label for the object. */
1277 if (output_bytecode)
1278 BC_OUTPUT_LABEL (asm_out_file, name);
1280 ASM_OUTPUT_LABEL (asm_out_file, name);
1281 #endif /* ASM_DECLARE_OBJECT_NAME */
1283 if (!dont_output_data)
1285 if (DECL_INITIAL (decl))
1286 /* Output the actual data. */
1287 output_constant (DECL_INITIAL (decl),
1288 int_size_in_bytes (TREE_TYPE (decl)));
1290 /* Leave space for it. */
1291 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1295 #ifdef XCOFF_DEBUGGING_INFO
1296 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1297 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1298 and `aa' hasn't been output yet, the assembler generates a stab entry with
1299 a value of zero, in addition to creating an unnecessary external entry
1300 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1302 /* File-scope global variables are output here. */
1303 if (write_symbols == XCOFF_DEBUG && top_level)
1305 saved_in_section = in_section;
1307 dbxout_symbol (decl, 0);
1309 if (in_section != saved_in_section)
1311 /* Switch to the proper section for this data. */
1312 #ifdef SELECT_SECTION
1313 SELECT_SECTION (decl, reloc);
1315 if (TREE_READONLY (decl)
1316 && ! TREE_THIS_VOLATILE (decl)
1317 && DECL_INITIAL (decl)
1318 && (DECL_INITIAL (decl) == error_mark_node
1319 || TREE_CONSTANT (DECL_INITIAL (decl)))
1320 && ! (flag_pic && reloc))
1321 readonly_data_section ();
1328 /* There must be a statement after a label. */
1333 /* Return 1 if type TYPE contains any pointers. */
1336 contains_pointers_p (type)
1339 switch (TREE_CODE (type))
1342 case REFERENCE_TYPE:
1343 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1344 so I'll play safe and return 1. */
1350 case QUAL_UNION_TYPE:
1353 /* For a type that has fields, see if the fields have pointers. */
1354 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1355 if (TREE_CODE (fields) == FIELD_DECL
1356 && contains_pointers_p (TREE_TYPE (fields)))
1362 /* An array type contains pointers if its element type does. */
1363 return contains_pointers_p (TREE_TYPE (type));
1370 /* Output text storage for constructor CONSTR. */
1373 bc_output_constructor (constr)
1378 /* Must always be a literal; non-literal constructors are handled
1381 if (!TREE_CONSTANT (constr))
1388 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1390 BC_OUTPUT_ALIGN (asm_out_file, i);
1393 output_constant (constr, int_size_in_bytes (TREE_TYPE (constr)));
1397 /* Create storage for constructor CONSTR. */
1400 bc_output_data_constructor (constr)
1405 /* Put in data section */
1409 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1411 BC_OUTPUT_ALIGN (asm_out_file, i);
1413 /* The constructor is filled in at runtime. */
1414 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1418 /* Output something to declare an external symbol to the assembler.
1419 (Most assemblers don't need this, so we normally output nothing.)
1420 Do nothing if DECL is not external. */
1423 assemble_external (decl)
1426 if (output_bytecode)
1429 #ifdef ASM_OUTPUT_EXTERNAL
1430 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1431 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1433 rtx rtl = DECL_RTL (decl);
1435 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1436 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1438 /* Some systems do require some output. */
1439 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1440 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1446 /* Similar, for calling a library function FUN. */
1449 assemble_external_libcall (fun)
1452 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1453 if (!output_bytecode)
1455 /* Declare library function name external when first used, if nec. */
1456 if (! SYMBOL_REF_USED (fun))
1458 SYMBOL_REF_USED (fun) = 1;
1459 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1465 /* Declare the label NAME global. */
1468 assemble_global (name)
1471 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1474 /* Assemble a label named NAME. */
1477 assemble_label (name)
1480 if (output_bytecode)
1481 BC_OUTPUT_LABEL (asm_out_file, name);
1483 ASM_OUTPUT_LABEL (asm_out_file, name);
1486 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1487 If NAME starts with a *, the rest of NAME is output verbatim.
1488 Otherwise NAME is transformed in an implementation-defined way
1489 (usually by the addition of an underscore).
1490 Many macros in the tm file are defined to call this function. */
1493 assemble_name (file, name)
1499 STRIP_NAME_ENCODING (real_name, name);
1500 TREE_SYMBOL_REFERENCED (get_identifier (real_name)) = 1;
1504 if (output_bytecode)
1505 bc_emit_labelref (name);
1507 fputs (&name[1], file);
1511 if (output_bytecode)
1512 BC_OUTPUT_LABELREF (file, name);
1514 ASM_OUTPUT_LABELREF (file, name);
1518 /* Allocate SIZE bytes writable static space with a gensym name
1519 and return an RTX to refer to its address. */
1522 assemble_static_space (size)
1528 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1529 so that each uninitialized object starts on such a boundary. */
1530 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1531 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1532 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1535 if (flag_shared_data)
1539 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1542 namestring = (char *) obstack_alloc (saveable_obstack,
1544 strcpy (namestring, name);
1546 if (output_bytecode)
1547 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1549 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1551 if (output_bytecode)
1553 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1557 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1558 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1560 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1566 /* Assemble the static constant template for function entry trampolines.
1567 This is done at most once per compilation.
1568 Returns an RTX for the address of the template. */
1571 assemble_trampoline_template ()
1577 /* Shouldn't get here */
1578 if (output_bytecode)
1581 /* By default, put trampoline templates in read-only data section. */
1583 #ifdef TRAMPOLINE_SECTION
1584 TRAMPOLINE_SECTION ();
1586 readonly_data_section ();
1589 /* Write the assembler code to define one. */
1590 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1592 ASM_OUTPUT_ALIGN (asm_out_file, align);
1594 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1595 TRAMPOLINE_TEMPLATE (asm_out_file);
1597 /* Record the rtl to refer to it. */
1598 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1600 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1601 return gen_rtx (SYMBOL_REF, Pmode, name);
1604 /* Assemble the integer constant X into an object of SIZE bytes.
1605 X must be either a CONST_INT or CONST_DOUBLE.
1607 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1608 non-zero, abort if we can't output the constant. */
1611 assemble_integer (x, size, force)
1616 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1617 ASM_OUTPUT... macros. */
1621 #ifdef ASM_OUTPUT_CHAR
1623 ASM_OUTPUT_CHAR (asm_out_file, x);
1627 #ifdef ASM_OUTPUT_SHORT
1629 ASM_OUTPUT_SHORT (asm_out_file, x);
1633 #ifdef ASM_OUTPUT_INT
1635 ASM_OUTPUT_INT (asm_out_file, x);
1639 #ifdef ASM_OUTPUT_DOUBLE_INT
1641 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1645 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1647 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1652 /* If we couldn't do it that way, there are two other possibilities: First,
1653 if the machine can output an explicit byte and this is a 1 byte constant,
1654 we can use ASM_OUTPUT_BYTE. */
1656 #ifdef ASM_OUTPUT_BYTE
1657 if (size == 1 && GET_CODE (x) == CONST_INT)
1659 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1664 /* Finally, if SIZE is larger than a single word, try to output the constant
1665 one word at a time. */
1667 if (size > UNITS_PER_WORD)
1670 enum machine_mode mode
1671 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1674 for (i = 0; i < size / UNITS_PER_WORD; i++)
1676 word = operand_subword (x, i, 0, mode);
1681 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1685 if (i == size / UNITS_PER_WORD)
1687 /* If we output at least one word and then could not finish,
1688 there is no valid way to continue. */
1699 /* Assemble the floating-point constant D into an object of size MODE. */
1702 assemble_real (d, mode)
1704 enum machine_mode mode;
1706 jmp_buf output_constant_handler;
1708 if (setjmp (output_constant_handler))
1710 error ("floating point trap outputting a constant");
1711 #ifdef REAL_IS_NOT_DOUBLE
1712 bzero ((char *) &d, sizeof d);
1719 set_float_handler (output_constant_handler);
1723 #ifdef ASM_OUTPUT_BYTE_FLOAT
1725 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1728 #ifdef ASM_OUTPUT_SHORT_FLOAT
1730 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1733 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1735 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1738 #ifdef ASM_OUTPUT_FLOAT
1740 ASM_OUTPUT_FLOAT (asm_out_file, d);
1744 #ifdef ASM_OUTPUT_DOUBLE
1746 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1750 #ifdef ASM_OUTPUT_LONG_DOUBLE
1753 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1761 set_float_handler (NULL_PTR);
1764 /* Here we combine duplicate floating constants to make
1765 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1767 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1768 They are chained through the CONST_DOUBLE_CHAIN.
1769 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1770 In that case, CONST_DOUBLE_MEM is either a MEM,
1771 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1773 (CONST_DOUBLE_MEM is used only for top-level functions.
1774 See force_const_mem for explanation.) */
1776 static rtx const_double_chain;
1778 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1779 For an integer, I0 is the low-order word and I1 is the high-order word.
1780 For a real number, I0 is the word with the low address
1781 and I1 is the word with the high address. */
1784 immed_double_const (i0, i1, mode)
1785 HOST_WIDE_INT i0, i1;
1786 enum machine_mode mode;
1789 int in_current_obstack;
1791 if (GET_MODE_CLASS (mode) == MODE_INT
1792 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1794 /* We clear out all bits that don't belong in MODE, unless they and our
1795 sign bit are all one. So we get either a reasonable negative value
1796 or a reasonable unsigned value for this mode. */
1797 int width = GET_MODE_BITSIZE (mode);
1798 if (width < HOST_BITS_PER_WIDE_INT
1799 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1800 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1801 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1802 else if (width == HOST_BITS_PER_WIDE_INT
1803 && ! (i1 == ~0 && i0 < 0))
1805 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1806 /* We cannot represent this value as a constant. */
1809 /* If this would be an entire word for the target, but is not for
1810 the host, then sign-extend on the host so that the number will look
1811 the same way on the host that it would on the target.
1813 For example, when building a 64 bit alpha hosted 32 bit sparc
1814 targeted compiler, then we want the 32 bit unsigned value -1 to be
1815 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1816 The later confuses the sparc backend. */
1818 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1819 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1820 i0 |= ((HOST_WIDE_INT) (-1) << width);
1822 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1824 ??? Strictly speaking, this is wrong if we create a CONST_INT
1825 for a large unsigned constant with the size of MODE being
1826 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1827 wider mode. In that case we will mis-interpret it as a negative
1830 Unfortunately, the only alternative is to make a CONST_DOUBLE
1831 for any constant in any mode if it is an unsigned constant larger
1832 than the maximum signed integer in an int on the host. However,
1833 doing this will break everyone that always expects to see a CONST_INT
1834 for SImode and smaller.
1836 We have always been making CONST_INTs in this case, so nothing new
1839 if (width <= HOST_BITS_PER_WIDE_INT)
1840 i1 = (i0 < 0) ? ~0 : 0;
1842 /* If this integer fits in one word, return a CONST_INT. */
1843 if ((i1 == 0 && i0 >= 0)
1844 || (i1 == ~0 && i0 < 0))
1845 return GEN_INT (i0);
1847 /* We use VOIDmode for integers. */
1851 /* Search the chain for an existing CONST_DOUBLE with the right value.
1852 If one is found, return it. */
1854 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1855 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1856 && GET_MODE (r) == mode)
1859 /* No; make a new one and add it to the chain.
1861 We may be called by an optimizer which may be discarding any memory
1862 allocated during its processing (such as combine and loop). However,
1863 we will be leaving this constant on the chain, so we cannot tolerate
1864 freed memory. So switch to saveable_obstack for this allocation
1865 and then switch back if we were in current_obstack. */
1867 push_obstacks_nochange ();
1868 rtl_in_saveable_obstack ();
1869 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1872 /* Don't touch const_double_chain in nested function; see force_const_mem.
1873 Also, don't touch it if not inside any function. */
1874 if (outer_function_chain == 0 && current_function_decl != 0)
1876 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1877 const_double_chain = r;
1880 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1881 Actual use of mem-slot is only through force_const_mem. */
1883 CONST_DOUBLE_MEM (r) = const0_rtx;
1888 /* Return a CONST_DOUBLE for a specified `double' value
1889 and machine mode. */
1892 immed_real_const_1 (d, mode)
1894 enum machine_mode mode;
1896 union real_extract u;
1898 int in_current_obstack;
1900 /* Get the desired `double' value as a sequence of ints
1901 since that is how they are stored in a CONST_DOUBLE. */
1905 /* Detect special cases. */
1907 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1908 if (!bcmp ((char *) &dconst0, (char *) &d, sizeof d))
1909 return CONST0_RTX (mode);
1910 /* Check for NaN first, because some ports (specifically the i386) do not
1911 emit correct ieee-fp code by default, and thus will generate a core
1912 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1913 does a floating point comparison. */
1914 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1915 return CONST1_RTX (mode);
1917 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1918 return immed_double_const (u.i[0], u.i[1], mode);
1920 /* The rest of this function handles the case where
1921 a float value requires more than 2 ints of space.
1922 It will be deleted as dead code on machines that don't need it. */
1924 /* Search the chain for an existing CONST_DOUBLE with the right value.
1925 If one is found, return it. */
1927 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1928 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
1929 && GET_MODE (r) == mode)
1932 /* No; make a new one and add it to the chain.
1934 We may be called by an optimizer which may be discarding any memory
1935 allocated during its processing (such as combine and loop). However,
1936 we will be leaving this constant on the chain, so we cannot tolerate
1937 freed memory. So switch to saveable_obstack for this allocation
1938 and then switch back if we were in current_obstack. */
1940 push_obstacks_nochange ();
1941 rtl_in_saveable_obstack ();
1942 r = rtx_alloc (CONST_DOUBLE);
1944 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
1947 /* Don't touch const_double_chain in nested function; see force_const_mem.
1948 Also, don't touch it if not inside any function. */
1949 if (outer_function_chain == 0 && current_function_decl != 0)
1951 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1952 const_double_chain = r;
1955 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1956 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1957 is only through force_const_mem. */
1959 CONST_DOUBLE_MEM (r) = const0_rtx;
1964 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1965 which must be a REAL_CST tree node. */
1968 immed_real_const (exp)
1971 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1974 /* At the end of a function, forget the memory-constants
1975 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1976 Also clear out real_constant_chain and clear out all the chain-pointers. */
1979 clear_const_double_mem ()
1981 register rtx r, next;
1983 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1984 See force_const_mem for explanation. */
1985 if (outer_function_chain != 0)
1988 for (r = const_double_chain; r; r = next)
1990 next = CONST_DOUBLE_CHAIN (r);
1991 CONST_DOUBLE_CHAIN (r) = 0;
1992 CONST_DOUBLE_MEM (r) = cc0_rtx;
1994 const_double_chain = 0;
1997 /* Given an expression EXP with a constant value,
1998 reduce it to the sum of an assembler symbol and an integer.
1999 Store them both in the structure *VALUE.
2000 Abort if EXP does not reduce. */
2005 HOST_WIDE_INT offset;
2009 decode_addr_const (exp, value)
2011 struct addr_const *value;
2013 register tree target = TREE_OPERAND (exp, 0);
2014 register int offset = 0;
2019 if (TREE_CODE (target) == COMPONENT_REF
2020 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2023 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2024 target = TREE_OPERAND (target, 0);
2026 else if (TREE_CODE (target) == ARRAY_REF)
2028 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2029 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2031 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2032 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2034 target = TREE_OPERAND (target, 0);
2040 switch (TREE_CODE (target))
2044 x = DECL_RTL (target);
2048 if (output_bytecode)
2049 /* FIXME: this may not be correct, check it */
2050 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
2052 x = gen_rtx (MEM, FUNCTION_MODE,
2053 gen_rtx (LABEL_REF, VOIDmode,
2054 label_rtx (TREE_OPERAND (exp, 0))));
2061 x = TREE_CST_RTL (target);
2068 if (!output_bytecode)
2070 if (GET_CODE (x) != MEM)
2076 value->offset = offset;
2079 /* Uniquize all constants that appear in memory.
2080 Each constant in memory thus far output is recorded
2081 in `const_hash_table' with a `struct constant_descriptor'
2082 that contains a polish representation of the value of
2085 We cannot store the trees in the hash table
2086 because the trees may be temporary. */
2088 struct constant_descriptor
2090 struct constant_descriptor *next;
2096 #define MAX_HASH_TABLE 1009
2097 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2099 /* Compute a hash code for a constant expression. */
2106 register int len, hi, i;
2107 register enum tree_code code = TREE_CODE (exp);
2109 if (code == INTEGER_CST)
2111 p = (char *) &TREE_INT_CST_LOW (exp);
2112 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2114 else if (code == REAL_CST)
2116 p = (char *) &TREE_REAL_CST (exp);
2117 len = sizeof TREE_REAL_CST (exp);
2119 else if (code == STRING_CST)
2120 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2121 else if (code == COMPLEX_CST)
2122 return const_hash (TREE_REALPART (exp)) * 5
2123 + const_hash (TREE_IMAGPART (exp));
2124 else if (code == CONSTRUCTOR)
2128 /* For record type, include the type in the hashing.
2129 We do not do so for array types
2130 because (1) the sizes of the elements are sufficient
2131 and (2) distinct array types can have the same constructor.
2132 Instead, we include the array size because the constructor could
2134 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2135 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2138 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2139 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2141 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2142 if (TREE_VALUE (link))
2143 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2147 else if (code == ADDR_EXPR)
2149 struct addr_const value;
2150 decode_addr_const (exp, &value);
2151 if (GET_CODE (value.base) == SYMBOL_REF)
2153 /* Don't hash the address of the SYMBOL_REF;
2154 only use the offset and the symbol name. */
2156 p = XSTR (value.base, 0);
2157 for (i = 0; p[i] != 0; i++)
2158 hi = ((hi * 613) + (unsigned)(p[i]));
2160 else if (GET_CODE (value.base) == LABEL_REF)
2161 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2163 hi &= (1 << HASHBITS) - 1;
2164 hi %= MAX_HASH_TABLE;
2167 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2168 return const_hash (TREE_OPERAND (exp, 0)) * 9
2169 + const_hash (TREE_OPERAND (exp, 1));
2170 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2171 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2173 /* Compute hashing function */
2175 for (i = 0; i < len; i++)
2176 hi = ((hi * 613) + (unsigned)(p[i]));
2178 hi &= (1 << HASHBITS) - 1;
2179 hi %= MAX_HASH_TABLE;
2183 /* Compare a constant expression EXP with a constant-descriptor DESC.
2184 Return 1 if DESC describes a constant with the same value as EXP. */
2187 compare_constant (exp, desc)
2189 struct constant_descriptor *desc;
2191 return 0 != compare_constant_1 (exp, desc->contents);
2194 /* Compare constant expression EXP with a substring P of a constant descriptor.
2195 If they match, return a pointer to the end of the substring matched.
2196 If they do not match, return 0.
2198 Since descriptors are written in polish prefix notation,
2199 this function can be used recursively to test one operand of EXP
2200 against a subdescriptor, and if it succeeds it returns the
2201 address of the subdescriptor for the next operand. */
2204 compare_constant_1 (exp, p)
2208 register char *strp;
2210 register enum tree_code code = TREE_CODE (exp);
2212 if (code != (enum tree_code) *p++)
2215 if (code == INTEGER_CST)
2217 /* Integer constants are the same only if the same width of type. */
2218 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2220 strp = (char *) &TREE_INT_CST_LOW (exp);
2221 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2223 else if (code == REAL_CST)
2225 /* Real constants are the same only if the same width of type. */
2226 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2228 strp = (char *) &TREE_REAL_CST (exp);
2229 len = sizeof TREE_REAL_CST (exp);
2231 else if (code == STRING_CST)
2233 if (flag_writable_strings)
2235 strp = TREE_STRING_POINTER (exp);
2236 len = TREE_STRING_LENGTH (exp);
2237 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2238 sizeof TREE_STRING_LENGTH (exp)))
2240 p += sizeof TREE_STRING_LENGTH (exp);
2242 else if (code == COMPLEX_CST)
2244 p = compare_constant_1 (TREE_REALPART (exp), p);
2245 if (p == 0) return 0;
2246 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2249 else if (code == CONSTRUCTOR)
2252 int length = list_length (CONSTRUCTOR_ELTS (exp));
2255 if (bcmp ((char *) &length, p, sizeof length))
2259 /* For record constructors, insist that the types match.
2260 For arrays, just verify both constructors are for arrays. */
2261 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2262 type = TREE_TYPE (exp);
2265 if (bcmp ((char *) &type, p, sizeof type))
2269 /* For arrays, insist that the size in bytes match. */
2270 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2272 int size = int_size_in_bytes (TREE_TYPE (exp));
2273 if (bcmp ((char *) &size, p, sizeof size))
2278 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2280 if (TREE_VALUE (link))
2282 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2289 if (bcmp ((char *) &zero, p, sizeof zero))
2297 else if (code == ADDR_EXPR)
2299 struct addr_const value;
2300 decode_addr_const (exp, &value);
2301 strp = (char *) &value.offset;
2302 len = sizeof value.offset;
2303 /* Compare the offset. */
2305 if (*p++ != *strp++)
2307 /* Compare symbol name. */
2308 strp = XSTR (value.base, 0);
2309 len = strlen (strp) + 1;
2311 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2313 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2314 if (p == 0) return 0;
2315 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2318 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2320 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2324 /* Compare constant contents. */
2326 if (*p++ != *strp++)
2332 /* Construct a constant descriptor for the expression EXP.
2333 It is up to the caller to enter the descriptor in the hash table. */
2335 static struct constant_descriptor *
2336 record_constant (exp)
2339 struct constant_descriptor *next = 0;
2342 /* Make a struct constant_descriptor. The first two pointers will
2343 be filled in later. Here we just leave space for them. */
2345 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2346 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2347 record_constant_1 (exp);
2348 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2351 /* Add a description of constant expression EXP
2352 to the object growing in `permanent_obstack'.
2353 No need to return its address; the caller will get that
2354 from the obstack when the object is complete. */
2357 record_constant_1 (exp)
2360 register char *strp;
2362 register enum tree_code code = TREE_CODE (exp);
2364 obstack_1grow (&permanent_obstack, (unsigned int) code);
2366 if (code == INTEGER_CST)
2368 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2369 strp = (char *) &TREE_INT_CST_LOW (exp);
2370 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2372 else if (code == REAL_CST)
2374 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2375 strp = (char *) &TREE_REAL_CST (exp);
2376 len = sizeof TREE_REAL_CST (exp);
2378 else if (code == STRING_CST)
2380 if (flag_writable_strings)
2382 strp = TREE_STRING_POINTER (exp);
2383 len = TREE_STRING_LENGTH (exp);
2384 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2385 sizeof TREE_STRING_LENGTH (exp));
2387 else if (code == COMPLEX_CST)
2389 record_constant_1 (TREE_REALPART (exp));
2390 record_constant_1 (TREE_IMAGPART (exp));
2393 else if (code == CONSTRUCTOR)
2396 int length = list_length (CONSTRUCTOR_ELTS (exp));
2399 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2401 /* For record constructors, insist that the types match.
2402 For arrays, just verify both constructors are for arrays. */
2403 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2404 type = TREE_TYPE (exp);
2407 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2409 /* For arrays, insist that the size in bytes match. */
2410 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2412 int size = int_size_in_bytes (TREE_TYPE (exp));
2413 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2416 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2418 if (TREE_VALUE (link))
2419 record_constant_1 (TREE_VALUE (link));
2424 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
2430 else if (code == ADDR_EXPR)
2432 struct addr_const value;
2433 decode_addr_const (exp, &value);
2434 /* Record the offset. */
2435 obstack_grow (&permanent_obstack,
2436 (char *) &value.offset, sizeof value.offset);
2437 /* Record the symbol name. */
2438 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2439 strlen (XSTR (value.base, 0)) + 1);
2442 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2444 record_constant_1 (TREE_OPERAND (exp, 0));
2445 record_constant_1 (TREE_OPERAND (exp, 1));
2448 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2450 record_constant_1 (TREE_OPERAND (exp, 0));
2454 /* Record constant contents. */
2455 obstack_grow (&permanent_obstack, strp, len);
2458 /* Record a list of constant expressions that were passed to
2459 output_constant_def but that could not be output right away. */
2461 struct deferred_constant
2463 struct deferred_constant *next;
2469 static struct deferred_constant *deferred_constants;
2471 /* Nonzero means defer output of addressed subconstants
2472 (i.e., those for which output_constant_def is called.) */
2473 static int defer_addressed_constants_flag;
2475 /* Start deferring output of subconstants. */
2478 defer_addressed_constants ()
2480 defer_addressed_constants_flag++;
2483 /* Stop deferring output of subconstants,
2484 and output now all those that have been deferred. */
2487 output_deferred_addressed_constants ()
2489 struct deferred_constant *p, *next;
2491 defer_addressed_constants_flag--;
2493 if (defer_addressed_constants_flag > 0)
2496 for (p = deferred_constants; p; p = next)
2498 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2503 deferred_constants = 0;
2506 /* Make a copy of the whole tree structure for a constant.
2507 This handles the same types of nodes that compare_constant
2508 and record_constant handle. */
2514 switch (TREE_CODE (exp))
2520 /* For ADDR_EXPR, we do not want to copy the decl
2521 whose address is requested. */
2522 return copy_node (exp);
2525 return build_complex (copy_constant (TREE_REALPART (exp)),
2526 copy_constant (TREE_IMAGPART (exp)));
2530 return build (TREE_CODE (exp), TREE_TYPE (exp),
2531 copy_constant (TREE_OPERAND (exp, 0)),
2532 copy_constant (TREE_OPERAND (exp, 1)));
2536 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2537 copy_constant (TREE_OPERAND (exp, 0)));
2541 tree copy = copy_node (exp);
2542 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2545 CONSTRUCTOR_ELTS (copy) = list;
2546 for (tail = list; tail; tail = TREE_CHAIN (tail))
2547 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2557 /* Return an rtx representing a reference to constant data in memory
2558 for the constant expression EXP.
2560 If assembler code for such a constant has already been output,
2561 return an rtx to refer to it.
2562 Otherwise, output such a constant in memory (or defer it for later)
2563 and generate an rtx for it.
2565 The TREE_CST_RTL of EXP is set up to point to that rtx.
2566 The const_hash_table records which constants already have label strings. */
2569 output_constant_def (exp)
2573 register struct constant_descriptor *desc;
2579 if (TREE_CODE (exp) == INTEGER_CST)
2580 abort (); /* No TREE_CST_RTL slot in these. */
2582 if (TREE_CST_RTL (exp))
2583 return TREE_CST_RTL (exp);
2585 /* Make sure any other constants whose addresses appear in EXP
2586 are assigned label numbers. */
2588 reloc = output_addressed_constants (exp);
2590 /* Compute hash code of EXP. Search the descriptors for that hash code
2591 to see if any of them describes EXP. If yes, the descriptor records
2592 the label number already assigned. */
2594 hash = const_hash (exp) % MAX_HASH_TABLE;
2596 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2597 if (compare_constant (exp, desc))
2599 found = desc->label;
2605 /* No constant equal to EXP is known to have been output.
2606 Make a constant descriptor to enter EXP in the hash table.
2607 Assign the label number and record it in the descriptor for
2608 future calls to this function to find. */
2610 /* Create a string containing the label name, in LABEL. */
2611 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2613 desc = record_constant (exp);
2614 desc->next = const_hash_table[hash];
2616 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2617 const_hash_table[hash] = desc;
2621 /* Create a string containing the label name, in LABEL. */
2622 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2625 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2627 push_obstacks_nochange ();
2628 if (TREE_PERMANENT (exp))
2629 end_temporary_allocation ();
2631 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2634 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2635 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2636 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2637 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2641 /* Optionally set flags or add text to the name to record information
2642 such as that it is a function name. If the name is changed, the macro
2643 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2644 #ifdef ENCODE_SECTION_INFO
2645 ENCODE_SECTION_INFO (exp);
2648 /* If this is the first time we've seen this particular constant,
2649 output it (or defer its output for later). */
2652 if (defer_addressed_constants_flag)
2654 struct deferred_constant *p;
2655 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2657 push_obstacks_nochange ();
2658 suspend_momentary ();
2659 p->exp = copy_constant (exp);
2662 p->labelno = const_labelno++;
2663 p->next = deferred_constants;
2664 deferred_constants = p;
2667 output_constant_def_contents (exp, reloc, const_labelno++);
2670 return TREE_CST_RTL (exp);
2673 /* Now output assembler code to define the label for EXP,
2674 and follow it with the data of EXP. */
2677 output_constant_def_contents (exp, reloc, labelno)
2684 if (IN_NAMED_SECTION (exp))
2685 named_section (exp, NULL);
2688 /* First switch to text section, except for writable strings. */
2689 #ifdef SELECT_SECTION
2690 SELECT_SECTION (exp, reloc);
2692 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2693 || (flag_pic && reloc))
2696 readonly_data_section ();
2700 /* Align the location counter as required by EXP's data type. */
2701 align = TYPE_ALIGN (TREE_TYPE (exp));
2702 #ifdef CONSTANT_ALIGNMENT
2703 align = CONSTANT_ALIGNMENT (exp, align);
2706 if (align > BITS_PER_UNIT)
2708 if (!output_bytecode)
2710 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2714 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2718 /* Output the label itself. */
2719 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2721 /* Output the value of EXP. */
2722 output_constant (exp,
2723 (TREE_CODE (exp) == STRING_CST
2724 ? TREE_STRING_LENGTH (exp)
2725 : int_size_in_bytes (TREE_TYPE (exp))));
2729 /* Similar hash facility for making memory-constants
2730 from constant rtl-expressions. It is used on RISC machines
2731 where immediate integer arguments and constant addresses are restricted
2732 so that such constants must be stored in memory.
2734 This pool of constants is reinitialized for each function
2735 so each function gets its own constants-pool that comes right before it.
2737 All structures allocated here are discarded when functions are saved for
2738 inlining, so they do not need to be allocated permanently. */
2740 #define MAX_RTX_HASH_TABLE 61
2741 static struct constant_descriptor **const_rtx_hash_table;
2743 /* Structure to represent sufficient information about a constant so that
2744 it can be output when the constant pool is output, so that function
2745 integration can be done, and to simplify handling on machines that reference
2746 constant pool as base+displacement. */
2748 struct pool_constant
2750 struct constant_descriptor *desc;
2751 struct pool_constant *next;
2752 enum machine_mode mode;
2759 /* Pointers to first and last constant in pool. */
2761 static struct pool_constant *first_pool, *last_pool;
2763 /* Current offset in constant pool (does not include any machine-specific
2766 static int pool_offset;
2768 /* Structure used to maintain hash table mapping symbols used to their
2769 corresponding constants. */
2774 struct pool_constant *pool;
2775 struct pool_sym *next;
2778 static struct pool_sym **const_rtx_sym_hash_table;
2780 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2781 The argument is XSTR (... , 0) */
2783 #define SYMHASH(LABEL) \
2784 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2786 /* Initialize constant pool hashing for next function. */
2789 init_const_rtx_hash_table ()
2791 const_rtx_hash_table
2792 = ((struct constant_descriptor **)
2793 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2794 const_rtx_sym_hash_table
2795 = ((struct pool_sym **)
2796 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2797 bzero ((char *) const_rtx_hash_table,
2798 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2799 bzero ((char *) const_rtx_sym_hash_table,
2800 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2802 first_pool = last_pool = 0;
2806 /* Save and restore it for a nested function. */
2809 save_varasm_status (p)
2812 p->const_rtx_hash_table = const_rtx_hash_table;
2813 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2814 p->first_pool = first_pool;
2815 p->last_pool = last_pool;
2816 p->pool_offset = pool_offset;
2820 restore_varasm_status (p)
2823 const_rtx_hash_table = p->const_rtx_hash_table;
2824 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2825 first_pool = p->first_pool;
2826 last_pool = p->last_pool;
2827 pool_offset = p->pool_offset;
2830 enum kind { RTX_DOUBLE, RTX_INT };
2834 #ifdef ONLY_INT_FIELDS
2835 unsigned int kind : 16;
2836 unsigned int mode : 16;
2838 enum kind kind : 16;
2839 enum machine_mode mode : 16;
2842 union real_extract du;
2843 struct addr_const addr;
2847 /* Express an rtx for a constant integer (perhaps symbolic)
2848 as the sum of a symbol or label plus an explicit integer.
2849 They are stored into VALUE. */
2852 decode_rtx_const (mode, x, value)
2853 enum machine_mode mode;
2855 struct rtx_const *value;
2857 /* Clear the whole structure, including any gaps. */
2860 int *p = (int *) value;
2861 int *end = (int *) (value + 1);
2866 value->kind = RTX_INT; /* Most usual kind. */
2869 switch (GET_CODE (x))
2872 value->kind = RTX_DOUBLE;
2873 if (GET_MODE (x) != VOIDmode)
2874 value->mode = GET_MODE (x);
2875 bcopy ((char *) &CONST_DOUBLE_LOW (x),
2876 (char *) &value->un.du, sizeof value->un.du);
2880 value->un.addr.offset = INTVAL (x);
2886 value->un.addr.base = x;
2891 if (GET_CODE (x) == PLUS)
2893 value->un.addr.base = XEXP (x, 0);
2894 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2896 value->un.addr.offset = INTVAL (XEXP (x, 1));
2898 else if (GET_CODE (x) == MINUS)
2900 value->un.addr.base = XEXP (x, 0);
2901 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2903 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2913 if (value->kind == RTX_INT && value->un.addr.base != 0)
2914 switch (GET_CODE (value->un.addr.base))
2918 /* Use the string's address, not the SYMBOL_REF's address,
2919 for the sake of addresses of library routines.
2920 For a LABEL_REF, compare labels. */
2921 value->un.addr.base = XEXP (value->un.addr.base, 0);
2925 /* Given a MINUS expression, simplify it if both sides
2926 include the same symbol. */
2929 simplify_subtraction (x)
2932 struct rtx_const val0, val1;
2934 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2935 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2937 if (val0.un.addr.base == val1.un.addr.base)
2938 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2942 /* Compute a hash code for a constant RTL expression. */
2945 const_hash_rtx (mode, x)
2946 enum machine_mode mode;
2951 struct rtx_const value;
2952 decode_rtx_const (mode, x, &value);
2954 /* Compute hashing function */
2956 for (i = 0; i < sizeof value / sizeof (int); i++)
2957 hi += ((int *) &value)[i];
2959 hi &= (1 << HASHBITS) - 1;
2960 hi %= MAX_RTX_HASH_TABLE;
2964 /* Compare a constant rtl object X with a constant-descriptor DESC.
2965 Return 1 if DESC describes a constant with the same value as X. */
2968 compare_constant_rtx (mode, x, desc)
2969 enum machine_mode mode;
2971 struct constant_descriptor *desc;
2973 register int *p = (int *) desc->contents;
2976 struct rtx_const value;
2978 decode_rtx_const (mode, x, &value);
2979 strp = (int *) &value;
2980 len = sizeof value / sizeof (int);
2982 /* Compare constant contents. */
2984 if (*p++ != *strp++)
2990 /* Construct a constant descriptor for the rtl-expression X.
2991 It is up to the caller to enter the descriptor in the hash table. */
2993 static struct constant_descriptor *
2994 record_constant_rtx (mode, x)
2995 enum machine_mode mode;
2998 struct constant_descriptor *ptr;
3000 struct rtx_const value;
3002 decode_rtx_const (mode, x, &value);
3004 /* Put these things in the saveable obstack so we can ensure it won't
3005 be freed if we are called from combine or some other phase that discards
3006 memory allocated from function_obstack (current_obstack). */
3007 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3008 obstack_grow (saveable_obstack, &label, sizeof label);
3010 /* Record constant contents. */
3011 obstack_grow (saveable_obstack, &value, sizeof value);
3013 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3016 /* Given a constant rtx X, make (or find) a memory constant for its value
3017 and return a MEM rtx to refer to it in memory. */
3020 force_const_mem (mode, x)
3021 enum machine_mode mode;
3025 register struct constant_descriptor *desc;
3030 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3031 (this will always be true for floating CONST_DOUBLEs that have been
3032 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3033 use the previous copy. Otherwise, make a new one. Note that in
3034 the unlikely event that this same CONST_DOUBLE is used in two different
3035 modes in an alternating fashion, we will allocate a lot of different
3036 memory locations, but this should be extremely rare. */
3038 /* Don't use CONST_DOUBLE_MEM in a nested function.
3039 Nested functions have their own constant pools,
3040 so they can't share the same values in CONST_DOUBLE_MEM
3041 with the containing function. */
3042 if (outer_function_chain == 0)
3043 if (GET_CODE (x) == CONST_DOUBLE
3044 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3045 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3046 return CONST_DOUBLE_MEM (x);
3048 /* Compute hash code of X. Search the descriptors for that hash code
3049 to see if any of them describes X. If yes, the descriptor records
3050 the label number already assigned. */
3052 hash = const_hash_rtx (mode, x);
3054 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3055 if (compare_constant_rtx (mode, x, desc))
3057 found = desc->label;
3063 register struct pool_constant *pool;
3064 register struct pool_sym *sym;
3067 /* No constant equal to X is known to have been output.
3068 Make a constant descriptor to enter X in the hash table.
3069 Assign the label number and record it in the descriptor for
3070 future calls to this function to find. */
3072 desc = record_constant_rtx (mode, x);
3073 desc->next = const_rtx_hash_table[hash];
3074 const_rtx_hash_table[hash] = desc;
3076 /* Align the location counter as required by EXP's data type. */
3077 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3078 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3079 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3081 pool_offset += align - 1;
3082 pool_offset &= ~ (align - 1);
3084 /* If RTL is not being placed into the saveable obstack, make a
3085 copy of X that is in the saveable obstack in case we are being
3086 called from combine or some other phase that discards memory
3087 it allocates. We need only do this if it is a CONST, since
3088 no other RTX should be allocated in this situation. */
3089 if (rtl_obstack != saveable_obstack
3090 && GET_CODE (x) == CONST)
3092 push_obstacks_nochange ();
3093 rtl_in_saveable_obstack ();
3095 x = gen_rtx (CONST, GET_MODE (x),
3096 gen_rtx (PLUS, GET_MODE (x),
3097 XEXP (XEXP (x, 0), 0), XEXP (XEXP (x, 0), 1)));
3101 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3103 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3107 pool->labelno = const_labelno;
3108 pool->align = align;
3109 pool->offset = pool_offset;
3115 last_pool->next = pool;
3118 pool_offset += GET_MODE_SIZE (mode);
3120 /* Create a string containing the label name, in LABEL. */
3121 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3126 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3128 /* Add label to symbol hash table. */
3129 hash = SYMHASH (found);
3130 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3133 sym->next = const_rtx_sym_hash_table[hash];
3134 const_rtx_sym_hash_table[hash] = sym;
3137 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3139 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3141 RTX_UNCHANGING_P (def) = 1;
3142 /* Mark the symbol_ref as belonging to this constants pool. */
3143 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3144 current_function_uses_const_pool = 1;
3146 if (outer_function_chain == 0)
3147 if (GET_CODE (x) == CONST_DOUBLE)
3149 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3151 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3152 const_double_chain = x;
3154 CONST_DOUBLE_MEM (x) = def;
3160 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3161 the corresponding pool_constant structure. */
3163 static struct pool_constant *
3164 find_pool_constant (addr)
3167 struct pool_sym *sym;
3168 char *label = XSTR (addr, 0);
3170 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3171 if (sym->label == label)
3177 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3180 get_pool_constant (addr)
3183 return (find_pool_constant (addr))->constant;
3186 /* Similar, return the mode. */
3189 get_pool_mode (addr)
3192 return (find_pool_constant (addr))->mode;
3195 /* Similar, return the offset in the constant pool. */
3198 get_pool_offset (addr)
3201 return (find_pool_constant (addr))->offset;
3204 /* Return the size of the constant pool. */
3212 /* Write all the constants in the constant pool. */
3215 output_constant_pool (fnname, fndecl)
3219 struct pool_constant *pool;
3221 union real_extract u;
3223 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3224 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3227 for (pool = first_pool; pool; pool = pool->next)
3231 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3232 whose CODE_LABEL has been deleted. This can occur if a jump table
3233 is eliminated by optimization. If so, write a constant of zero
3234 instead. Note that this can also happen by turning the
3235 CODE_LABEL into a NOTE. */
3236 if (((GET_CODE (x) == LABEL_REF
3237 && (INSN_DELETED_P (XEXP (x, 0))
3238 || GET_CODE (XEXP (x, 0)) == NOTE)))
3239 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3240 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3241 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3242 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3245 /* First switch to correct section. */
3246 #ifdef SELECT_RTX_SECTION
3247 SELECT_RTX_SECTION (pool->mode, x);
3249 readonly_data_section ();
3252 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3253 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3254 pool->align, pool->labelno, done);
3257 if (pool->align > 1)
3258 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3260 /* Output the label. */
3261 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3263 /* Output the value of the constant itself. */
3264 switch (GET_MODE_CLASS (pool->mode))
3267 if (GET_CODE (x) != CONST_DOUBLE)
3270 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3271 assemble_real (u.d, pool->mode);
3275 case MODE_PARTIAL_INT:
3276 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3286 /* Done with this pool. */
3287 first_pool = last_pool = 0;
3290 /* Find all the constants whose addresses are referenced inside of EXP,
3291 and make sure assembler code with a label has been output for each one.
3292 Indicate whether an ADDR_EXPR has been encountered. */
3295 output_addressed_constants (exp)
3300 switch (TREE_CODE (exp))
3304 register tree constant = TREE_OPERAND (exp, 0);
3306 while (TREE_CODE (constant) == COMPONENT_REF)
3308 constant = TREE_OPERAND (constant, 0);
3311 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3312 || TREE_CODE (constant) == CONSTRUCTOR)
3313 /* No need to do anything here
3314 for addresses of variables or functions. */
3315 output_constant_def (constant);
3322 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3323 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3328 case NON_LVALUE_EXPR:
3329 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3335 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3336 if (TREE_VALUE (link) != 0)
3337 reloc |= output_addressed_constants (TREE_VALUE (link));
3348 /* Output assembler for byte constant */
3350 output_byte_asm (byte)
3353 if (output_bytecode)
3354 bc_emit_const ((char *) &byte, sizeof (char));
3355 #ifdef ASM_OUTPUT_BYTE
3358 ASM_OUTPUT_BYTE (asm_out_file, byte);
3363 /* Output assembler code for constant EXP to FILE, with no label.
3364 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3365 Assumes output_addressed_constants has been done on EXP already.
3367 Generate exactly SIZE bytes of assembler data, padding at the end
3368 with zeros if necessary. SIZE must always be specified.
3370 SIZE is important for structure constructors,
3371 since trailing members may have been omitted from the constructor.
3372 It is also important for initialization of arrays from string constants
3373 since the full length of the string constant might not be wanted.
3374 It is also needed for initialization of unions, where the initializer's
3375 type is just one member, and that may not be as long as the union.
3377 There a case in which we would fail to output exactly SIZE bytes:
3378 for a structure constructor that wants to produce more than SIZE bytes.
3379 But such constructors will never be generated for any possible input. */
3382 output_constant (exp, size)
3386 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3392 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3393 That way we get the constant (we hope) inside it. Also, strip off any
3394 NOP_EXPR that converts between two record, union, or array types. */
3395 while ((TREE_CODE (exp) == NOP_EXPR
3396 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3397 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3398 || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3399 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
3400 || TREE_CODE (TREE_TYPE (exp)) == QUAL_UNION_TYPE))
3401 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3402 exp = TREE_OPERAND (exp, 0);
3404 /* Allow a constructor with no elements for any data type.
3405 This means to fill the space with zeros. */
3406 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3408 if (output_bytecode)
3409 bc_emit_const_skip (size);
3411 assemble_zeros (size);
3422 case REFERENCE_TYPE:
3423 /* ??? What about (int)((float)(int)&foo + 4) */
3424 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3425 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3426 exp = TREE_OPERAND (exp, 0);
3428 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3429 EXPAND_INITIALIZER),
3431 error ("initializer for integer value is too complicated");
3436 if (TREE_CODE (exp) != REAL_CST)
3437 error ("initializer for floating value is not a floating constant");
3439 assemble_real (TREE_REAL_CST (exp),
3440 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3445 output_constant (TREE_REALPART (exp), size / 2);
3446 output_constant (TREE_IMAGPART (exp), size / 2);
3447 size -= (size / 2) * 2;
3451 if (TREE_CODE (exp) == CONSTRUCTOR)
3453 output_constructor (exp, size);
3456 else if (TREE_CODE (exp) == STRING_CST)
3460 if (size > TREE_STRING_LENGTH (exp))
3462 excess = size - TREE_STRING_LENGTH (exp);
3463 size = TREE_STRING_LENGTH (exp);
3466 assemble_string (TREE_STRING_POINTER (exp), size);
3475 if (TREE_CODE (exp) == CONSTRUCTOR)
3476 output_constructor (exp, size);
3483 assemble_zeros (size);
3487 /* Bytecode specific code to output assembler for integer. */
3489 bc_assemble_integer (exp, size)
3497 /* FIXME: is this fold() business going to be as good as the
3498 expand_expr() using EXPAND_SUM above in the RTL case? I
3500 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3504 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3505 exp = TREE_OPERAND (exp, 0);
3506 if (TREE_CODE (exp) == INTEGER_CST)
3511 else if (TREE_CODE (exp) == PLUS_EXPR)
3513 const_part = TREE_OPERAND (exp, 0);
3514 while (TREE_CODE (const_part) == NOP_EXPR
3515 || TREE_CODE (const_part) == CONVERT_EXPR)
3516 const_part = TREE_OPERAND (const_part, 0);
3517 addr_part = TREE_OPERAND (exp, 1);
3518 while (TREE_CODE (addr_part) == NOP_EXPR
3519 || TREE_CODE (addr_part) == CONVERT_EXPR)
3520 addr_part = TREE_OPERAND (addr_part, 0);
3521 if (TREE_CODE (const_part) != INTEGER_CST)
3522 tmp = const_part, const_part = addr_part, addr_part = tmp;
3523 if (TREE_CODE (const_part) != INTEGER_CST
3524 || TREE_CODE (addr_part) != ADDR_EXPR)
3525 abort (); /* FIXME: we really haven't considered
3526 all the possible cases here. */
3528 else if (TREE_CODE (exp) == ADDR_EXPR)
3530 const_part = integer_zero_node;
3534 abort (); /* FIXME: ditto previous. */
3540 char c = TREE_INT_CST_LOW (const_part);
3546 short s = TREE_INT_CST_LOW (const_part);
3547 bc_emit ((char *) &s, 2);
3552 int i = TREE_INT_CST_LOW (const_part);
3553 bc_emit ((char *) &i, 4);
3558 if (WORDS_BIG_ENDIAN)
3560 int i = TREE_INT_CST_HIGH (const_part);
3561 bc_emit ((char *) &i, 4);
3562 i = TREE_INT_CST_LOW (const_part);
3563 bc_emit ((char *) &i, 4);
3567 int i = TREE_INT_CST_LOW (const_part);
3568 bc_emit ((char *) &i, 4);
3569 i = TREE_INT_CST_HIGH (const_part);
3570 bc_emit ((char *) &i, 4);
3577 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3578 bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3579 TREE_INT_CST_LOW (const_part));
3581 abort (); /* FIXME: there may be more cases. */
3584 /* Subroutine of output_constant, used for CONSTRUCTORs
3585 (aggregate constants).
3586 Generate at least SIZE bytes, padding if necessary. */
3589 output_constructor (exp, size)
3593 register tree link, field = 0;
3594 HOST_WIDE_INT min_index = 0;
3595 /* Number of bytes output or skipped so far.
3596 In other words, current position within the constructor. */
3597 int total_bytes = 0;
3598 /* Non-zero means BYTE contains part of a byte, to be output. */
3599 int byte_buffer_in_use = 0;
3602 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3605 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3606 field = TYPE_FIELDS (TREE_TYPE (exp));
3608 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3609 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3611 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3613 /* As LINK goes through the elements of the constant,
3614 FIELD goes through the structure fields, if the constant is a structure.
3615 if the constant is a union, then we override this,
3616 by getting the field from the TREE_LIST element.
3617 But the constant could also be an array. Then FIELD is zero. */
3618 for (link = CONSTRUCTOR_ELTS (exp);
3620 link = TREE_CHAIN (link),
3621 field = field ? TREE_CHAIN (field) : 0)
3623 tree val = TREE_VALUE (link);
3626 /* the element in a union constructor specifies the proper field. */
3628 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3629 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3631 /* if available, use the type given by link */
3632 if (TREE_PURPOSE (link) != 0)
3633 field = TREE_PURPOSE (link);
3636 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3637 index = TREE_PURPOSE (link);
3639 /* Eliminate the marker that makes a cast not be an lvalue. */
3643 if (field == 0 || !DECL_BIT_FIELD (field))
3645 /* An element that is not a bit-field. */
3647 register int fieldsize;
3648 /* Since this structure is static,
3649 we know the positions are constant. */
3650 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3654 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3656 * (TREE_INT_CST_LOW (index) - min_index));
3658 /* Output any buffered-up bit-fields preceding this element. */
3659 if (byte_buffer_in_use)
3661 ASM_OUTPUT_BYTE (asm_out_file, byte);
3663 byte_buffer_in_use = 0;
3666 /* Advance to offset of this element.
3667 Note no alignment needed in an array, since that is guaranteed
3668 if each element has the proper size. */
3669 if ((field != 0 || index != 0) && bitpos != total_bytes)
3671 if (!output_bytecode)
3672 assemble_zeros (bitpos - total_bytes);
3674 bc_emit_const_skip (bitpos - total_bytes);
3675 total_bytes = bitpos;
3678 /* Determine size this element should occupy. */
3681 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3683 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3685 /* This avoids overflow trouble. */
3686 tree size_tree = size_binop (CEIL_DIV_EXPR,
3688 size_int (BITS_PER_UNIT));
3689 fieldsize = TREE_INT_CST_LOW (size_tree);
3693 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3694 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3698 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3700 /* Output the element's initial value. */
3702 assemble_zeros (fieldsize);
3704 output_constant (val, fieldsize);
3706 /* Count its size. */
3707 total_bytes += fieldsize;
3709 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3710 error ("invalid initial value for member `%s'",
3711 IDENTIFIER_POINTER (DECL_NAME (field)));
3714 /* Element that is a bit-field. */
3716 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3718 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3721 val = integer_zero_node;
3723 /* If this field does not start in this (or, next) byte,
3725 if (next_offset / BITS_PER_UNIT != total_bytes)
3727 /* Output remnant of any bit field in previous bytes. */
3728 if (byte_buffer_in_use)
3730 ASM_OUTPUT_BYTE (asm_out_file, byte);
3732 byte_buffer_in_use = 0;
3735 /* If still not at proper byte, advance to there. */
3736 if (next_offset / BITS_PER_UNIT != total_bytes)
3738 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3739 total_bytes = next_offset / BITS_PER_UNIT;
3743 if (! byte_buffer_in_use)
3746 /* We must split the element into pieces that fall within
3747 separate bytes, and combine each byte with previous or
3748 following bit-fields. */
3750 /* next_offset is the offset n fbits from the beginning of
3751 the structure to the next bit of this element to be processed.
3752 end_offset is the offset of the first bit past the end of
3754 while (next_offset < end_offset)
3758 HOST_WIDE_INT value;
3759 int next_byte = next_offset / BITS_PER_UNIT;
3760 int next_bit = next_offset % BITS_PER_UNIT;
3762 /* Advance from byte to byte
3763 within this element when necessary. */
3764 while (next_byte != total_bytes)
3766 ASM_OUTPUT_BYTE (asm_out_file, byte);
3771 /* Number of bits we can process at once
3772 (all part of the same byte). */
3773 this_time = MIN (end_offset - next_offset,
3774 BITS_PER_UNIT - next_bit);
3775 if (BYTES_BIG_ENDIAN)
3777 /* On big-endian machine, take the most significant bits
3778 first (of the bits that are significant)
3779 and put them into bytes from the most significant end. */
3780 shift = end_offset - next_offset - this_time;
3781 /* Don't try to take a bunch of bits that cross
3782 the word boundary in the INTEGER_CST. */
3783 if (shift < HOST_BITS_PER_WIDE_INT
3784 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3786 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3787 shift = HOST_BITS_PER_WIDE_INT;
3790 /* Now get the bits from the appropriate constant word. */
3791 if (shift < HOST_BITS_PER_WIDE_INT)
3793 value = TREE_INT_CST_LOW (val);
3795 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3797 value = TREE_INT_CST_HIGH (val);
3798 shift -= HOST_BITS_PER_WIDE_INT;
3802 byte |= (((value >> shift)
3803 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3804 << (BITS_PER_UNIT - this_time - next_bit));
3808 /* On little-endian machines,
3809 take first the least significant bits of the value
3810 and pack them starting at the least significant
3811 bits of the bytes. */
3812 shift = (next_offset
3813 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3814 /* Don't try to take a bunch of bits that cross
3815 the word boundary in the INTEGER_CST. */
3816 if (shift < HOST_BITS_PER_WIDE_INT
3817 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3819 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3820 shift = HOST_BITS_PER_WIDE_INT;
3823 /* Now get the bits from the appropriate constant word. */
3824 if (shift < HOST_BITS_PER_INT)
3825 value = TREE_INT_CST_LOW (val);
3826 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3828 value = TREE_INT_CST_HIGH (val);
3829 shift -= HOST_BITS_PER_WIDE_INT;
3833 byte |= (((value >> shift)
3834 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3837 next_offset += this_time;
3838 byte_buffer_in_use = 1;
3842 if (byte_buffer_in_use)
3844 ASM_OUTPUT_BYTE (asm_out_file, byte);
3847 if (total_bytes < size)
3848 assemble_zeros (size - total_bytes);
3852 #ifdef HANDLE_SYSV_PRAGMA
3854 /* Support #pragma weak by default if WEAK_ASM_OP and ASM_OUTPUT_DEF
3856 #if defined (WEAK_ASM_OP) && defined (ASM_OUTPUT_DEF)
3858 /* See c-pragma.c for an identical definition. */
3874 /* Output asm to handle ``#pragma weak'' */
3876 handle_pragma_weak (what, asm_out_file, name, value)
3877 enum pragma_state what;
3881 if (what == ps_name || what == ps_value)
3883 fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
3885 if (output_bytecode)
3886 BC_OUTPUT_LABELREF (asm_out_file, name);
3888 ASM_OUTPUT_LABELREF (asm_out_file, name);
3890 fputc ('\n', asm_out_file);
3891 if (what == ps_value)
3892 ASM_OUTPUT_DEF (asm_out_file, name, value);
3894 else if (! (what == ps_done || what == ps_start))
3895 warning ("malformed `#pragma weak'");
3898 #endif /* HANDLE_PRAGMA_WEAK or (WEAK_ASM_OP and SET_ASM_OP) */
3900 #endif /* WEAK_ASM_OP && ASM_OUTPUT_DEF */