1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92, 93, 94, 1995 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> */
38 #include "hard-reg-set.h"
46 #ifdef XCOFF_DEBUGGING_INFO
53 #define ASM_STABS_OP ".stabs"
56 /* This macro gets just the user-specified name
57 out of the string in a SYMBOL_REF. On most machines,
58 we discard the * if any and that's all. */
59 #ifndef STRIP_NAME_ENCODING
60 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
61 (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
64 /* File in which assembler code is being written. */
66 extern FILE *asm_out_file;
68 /* The (assembler) name of the first globally-visible object output. */
69 char *first_global_object_name;
71 extern struct obstack *current_obstack;
72 extern struct obstack *saveable_obstack;
73 extern struct obstack *rtl_obstack;
74 extern struct obstack permanent_obstack;
75 #define obstack_chunk_alloc xmalloc
77 /* Number for making the label on the next
78 constant that is stored in memory. */
82 /* Number for making the label on the next
83 static variable internal to a function. */
87 /* Carry information from ASM_DECLARE_OBJECT_NAME
88 to ASM_FINISH_DECLARE_OBJECT. */
90 int size_directive_output;
92 /* The last decl for which assemble_variable was called,
93 if it did ASM_DECLARE_OBJECT_NAME.
94 If the last call to assemble_variable didn't do that,
97 tree last_assemble_variable_decl;
100 #if defined (HANDLE_PRAGMA_WEAK) || (defined (WEAK_ASM_OP) && defined (ASM_OUTPUT_DEF))
101 /* Any weak symbol declarations waiting to be emitted. */
105 struct weak_syms *next;
110 static struct weak_syms *weak_decls;
113 /* Nonzero if at least one function definition has been seen. */
115 static int function_defined;
118 struct constant_descriptor;
120 struct pool_constant;
122 static void bc_make_decl_rtl PROTO((tree, char *, int));
123 static char *strip_reg_name PROTO((char *));
124 static void bc_output_ascii PROTO((FILE *, char *, int));
125 static int contains_pointers_p PROTO((tree));
126 static void decode_addr_const PROTO((tree, struct addr_const *));
127 static int const_hash PROTO((tree));
128 static int compare_constant PROTO((tree,
129 struct constant_descriptor *));
130 static char *compare_constant_1 PROTO((tree, char *));
131 static struct constant_descriptor *record_constant PROTO((tree));
132 static void record_constant_1 PROTO((tree));
133 static tree copy_constant PROTO((tree));
134 static void output_constant_def_contents PROTO((tree, int, int));
135 static void decode_rtx_const PROTO((enum machine_mode, rtx,
136 struct rtx_const *));
137 static int const_hash_rtx PROTO((enum machine_mode, rtx));
138 static int compare_constant_rtx PROTO((enum machine_mode, rtx,
139 struct constant_descriptor *));
140 static struct constant_descriptor *record_constant_rtx PROTO((enum machine_mode,
142 static struct pool_constant *find_pool_constant PROTO((rtx));
143 static int output_addressed_constants PROTO((tree));
144 static void bc_assemble_integer PROTO((tree, int));
145 static void output_constructor PROTO((tree, int));
147 #ifdef EXTRA_SECTIONS
148 static enum in_section {no_section, in_text, in_data, in_named, EXTRA_SECTIONS} in_section
151 static enum in_section {no_section, in_text, in_data, in_named} in_section
155 /* Return a non-zero value if DECL has a section attribute. */
156 #define IN_NAMED_SECTION(DECL) \
157 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
158 && DECL_SECTION_NAME (DECL) != NULL_TREE)
160 /* Text of section name when in_section == in_named. */
161 static char *in_named_name;
163 /* Define functions like text_section for any extra sections. */
164 #ifdef EXTRA_SECTION_FUNCTIONS
165 EXTRA_SECTION_FUNCTIONS
168 /* Tell assembler to switch to text section. */
173 if (in_section != in_text)
178 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
180 in_section = in_text;
184 /* Tell assembler to switch to data section. */
189 if (in_section != in_data)
195 if (flag_shared_data)
197 #ifdef SHARED_SECTION_ASM_OP
198 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
200 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
204 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
207 in_section = in_data;
211 /* Tell assembler to switch to read-only data section. This is normally
215 readonly_data_section ()
217 #ifdef READONLY_DATA_SECTION
218 READONLY_DATA_SECTION (); /* Note this can call data_section. */
224 /* Determine if we're in the text section. */
229 return in_section == in_text;
232 /* Tell assembler to change to section NAME for DECL.
233 If DECL is NULL, just switch to section NAME.
234 If NAME is NULL, get the name from DECL. */
237 named_section (decl, name)
241 if (decl != NULL_TREE
242 && (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL))
245 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
247 if (in_section != in_named || strcmp (name, in_named_name))
249 in_named_name = name;
250 in_section = in_named;
252 #ifdef ASM_OUTPUT_SECTION_NAME
253 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name);
255 /* Section attributes are not supported if this macro isn't provided -
256 some host formats don't support them at all. The front-end should
257 already have flagged this as an error. */
263 /* Switch to the section for function DECL.
265 If DECL is NULL_TREE, switch to the text section.
266 ??? It's not clear that we will ever be passed NULL_TREE, but it's
267 safer to handle it. */
270 function_section (decl)
273 if (decl != NULL_TREE
274 && DECL_SECTION_NAME (decl) != NULL_TREE)
275 named_section (decl, (char *) 0);
280 /* Create the rtl to represent a function, for a function definition.
281 DECL is a FUNCTION_DECL node which describes which function.
282 The rtl is stored into DECL. */
285 make_function_rtl (decl)
288 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
292 if (DECL_RTL (decl) == 0)
293 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
295 /* Record that at least one function has been defined. */
296 function_defined = 1;
300 /* Rename a nested function to avoid conflicts. */
301 if (decl_function_context (decl) != 0
302 && DECL_INITIAL (decl) != 0
303 && DECL_RTL (decl) == 0)
307 name = IDENTIFIER_POINTER (DECL_NAME (decl));
308 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
309 name = obstack_copy0 (saveable_obstack, label, strlen (label));
313 if (DECL_RTL (decl) == 0)
316 = gen_rtx (MEM, DECL_MODE (decl),
317 gen_rtx (SYMBOL_REF, Pmode, name));
319 /* Optionally set flags or add text to the name to record information
320 such as that it is a function name. If the name is changed, the macro
321 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
322 #ifdef ENCODE_SECTION_INFO
323 ENCODE_SECTION_INFO (decl);
327 /* Record at least one function has been defined. */
328 function_defined = 1;
331 /* Create the DECL_RTL for a declaration for a static or external
332 variable or static or external function.
333 ASMSPEC, if not 0, is the string which the user specified
334 as the assembler symbol name.
335 TOP_LEVEL is nonzero if this is a file-scope variable.
336 This is never called for PARM_DECLs. */
339 bc_make_decl_rtl (decl, asmspec, top_level)
344 register char *name = TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl));
346 if (DECL_RTL (decl) == 0)
348 /* Print an error message for register variables. */
349 if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
350 error ("function declared `register'");
351 else if (DECL_REGISTER (decl))
352 error ("global register variables not supported in the interpreter");
354 /* Handle ordinary static variables and functions. */
355 if (DECL_RTL (decl) == 0)
357 /* Can't use just the variable's own name for a variable
358 whose scope is less than the whole file.
359 Concatenate a distinguishing number. */
360 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
364 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
365 name = obstack_copy0 (saveable_obstack, label, strlen (label));
369 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
374 /* Given NAME, a putative register name, discard any customary prefixes. */
377 strip_reg_name (name)
380 #ifdef REGISTER_PREFIX
381 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
382 name += strlen (REGISTER_PREFIX);
384 if (name[0] == '%' || name[0] == '#')
389 /* Decode an `asm' spec for a declaration as a register name.
390 Return the register number, or -1 if nothing specified,
391 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
392 or -3 if ASMSPEC is `cc' and is not recognized,
393 or -4 if ASMSPEC is `memory' and is not recognized.
394 Accept an exact spelling or a decimal number.
395 Prefixes such as % are optional. */
398 decode_reg_name (asmspec)
405 /* Get rid of confusing prefixes. */
406 asmspec = strip_reg_name (asmspec);
408 /* Allow a decimal number as a "register name". */
409 for (i = strlen (asmspec) - 1; i >= 0; i--)
410 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
412 if (asmspec[0] != 0 && i < 0)
415 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
421 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
423 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
426 #ifdef ADDITIONAL_REGISTER_NAMES
428 static struct { char *name; int number; } table[]
429 = ADDITIONAL_REGISTER_NAMES;
431 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
432 if (! strcmp (asmspec, table[i].name))
433 return table[i].number;
435 #endif /* ADDITIONAL_REGISTER_NAMES */
437 if (!strcmp (asmspec, "memory"))
440 if (!strcmp (asmspec, "cc"))
449 /* Create the DECL_RTL for a declaration for a static or external variable
450 or static or external function.
451 ASMSPEC, if not 0, is the string which the user specified
452 as the assembler symbol name.
453 TOP_LEVEL is nonzero if this is a file-scope variable.
455 This is never called for PARM_DECL nodes. */
458 make_decl_rtl (decl, asmspec, top_level)
463 register char *name = 0;
468 bc_make_decl_rtl (decl, asmspec, top_level);
472 reg_number = decode_reg_name (asmspec);
474 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
475 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
477 if (reg_number == -2)
479 /* ASMSPEC is given, and not the name of a register. */
480 name = (char *) obstack_alloc (saveable_obstack,
481 strlen (asmspec) + 2);
483 strcpy (&name[1], asmspec);
486 /* For a duplicate declaration, we can be called twice on the
487 same DECL node. Don't discard the RTL already made. */
488 if (DECL_RTL (decl) == 0)
492 /* First detect errors in declaring global registers. */
493 if (DECL_REGISTER (decl) && reg_number == -1)
494 error_with_decl (decl,
495 "register name not specified for `%s'");
496 else if (DECL_REGISTER (decl) && reg_number < 0)
497 error_with_decl (decl,
498 "invalid register name for `%s'");
499 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
500 error_with_decl (decl,
501 "register name given for non-register variable `%s'");
502 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
503 error ("function declared `register'");
504 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
505 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
506 else if (DECL_REGISTER (decl)
507 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
508 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
509 /* Now handle properly declared static register variables. */
510 else if (DECL_REGISTER (decl))
513 #if 0 /* yylex should print the warning for this */
515 pedwarn ("ANSI C forbids global register variables");
517 if (DECL_INITIAL (decl) != 0 && top_level)
519 DECL_INITIAL (decl) = 0;
520 error ("global register variable has initial value");
522 if (fixed_regs[reg_number] == 0
523 && function_defined && top_level)
524 error ("global register variable follows a function definition");
525 if (TREE_THIS_VOLATILE (decl))
526 warning ("volatile register variables don't work as you might wish");
528 /* If the user specified one of the eliminables registers here,
529 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
530 confused with that register and be eliminated. Although this
531 usage is somewhat suspect, we nevertheless use the following
532 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
535 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
536 REGNO (DECL_RTL (decl)) = reg_number;
537 REG_USERVAR_P (DECL_RTL (decl)) = 1;
541 /* Make this register global, so not usable for anything
543 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
545 globalize_reg (reg_number + --nregs);
548 /* Specifying a section attribute on an uninitialized variable does not
549 (and cannot) cause it to be put in the given section. The linker
550 can only put initialized objects in specific sections, everything
551 else goes in bss for the linker to sort out later (otherwise the
552 linker would give a duplicate definition error for each compilation
553 unit that behaved thusly). So warn the user. */
554 else if (TREE_CODE (decl) == VAR_DECL
555 && DECL_SECTION_NAME (decl) != NULL_TREE
556 && DECL_INITIAL (decl) == NULL_TREE
557 && DECL_COMMON (decl)
560 warning_with_decl (decl,
561 "section attribute ignored for uninitialized variable `%s'");
562 /* Remove the section name so subsequent declarations won't see it.
563 We are ignoring it, remember. */
564 DECL_SECTION_NAME (decl) = NULL_TREE;
567 /* Now handle ordinary static variables and functions (in memory).
568 Also handle vars declared register invalidly. */
569 if (DECL_RTL (decl) == 0)
571 /* Can't use just the variable's own name for a variable
572 whose scope is less than the whole file.
573 Concatenate a distinguishing number. */
574 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
578 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
579 name = obstack_copy0 (saveable_obstack, label, strlen (label));
586 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
587 gen_rtx (SYMBOL_REF, Pmode, name));
589 /* If this variable is to be treated as volatile, show its
590 tree node has side effects. If it has side effects, either
591 because of this test or from TREE_THIS_VOLATILE also
592 being set, show the MEM is volatile. */
593 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
594 && TREE_PUBLIC (decl))
595 TREE_SIDE_EFFECTS (decl) = 1;
596 if (TREE_SIDE_EFFECTS (decl))
597 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
599 if (TREE_READONLY (decl))
600 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
601 MEM_IN_STRUCT_P (DECL_RTL (decl))
602 = AGGREGATE_TYPE_P (TREE_TYPE (decl));
604 /* Optionally set flags or add text to the name to record information
605 such as that it is a function name.
606 If the name is changed, the macro ASM_OUTPUT_LABELREF
607 will have to know how to strip this information. */
608 #ifdef ENCODE_SECTION_INFO
609 ENCODE_SECTION_INFO (decl);
613 /* If the old RTL had the wrong mode, fix the mode. */
614 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
616 rtx rtl = DECL_RTL (decl);
617 PUT_MODE (rtl, DECL_MODE (decl));
621 /* Make the rtl for variable VAR be volatile.
622 Use this only for static variables. */
625 make_var_volatile (var)
628 if (GET_CODE (DECL_RTL (var)) != MEM)
631 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
634 /* Output alignment directive to align for constant expression EXP. */
637 assemble_constant_align (exp)
642 /* Align the location counter as required by EXP's data type. */
643 align = TYPE_ALIGN (TREE_TYPE (exp));
644 #ifdef CONSTANT_ALIGNMENT
645 align = CONSTANT_ALIGNMENT (exp, align);
648 if (align > BITS_PER_UNIT)
649 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
652 /* Output a string of literal assembler code
653 for an `asm' keyword used between functions. */
656 assemble_asm (string)
661 error ("asm statements not allowed in interpreter");
667 if (TREE_CODE (string) == ADDR_EXPR)
668 string = TREE_OPERAND (string, 0);
670 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
673 #if 0 /* This should no longer be needed, because
674 flag_gnu_linker should be 0 on these systems,
675 which should prevent any output
676 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
677 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
678 #ifndef ASM_OUTPUT_CONSTRUCTOR
679 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
681 #ifndef ASM_OUTPUT_DESTRUCTOR
682 #define ASM_OUTPUT_DESTRUCTOR(file, name)
687 /* Record an element in the table of global destructors.
688 How this is done depends on what sort of assembler and linker
691 NAME should be the name of a global function to be called
692 at exit time. This name is output using assemble_name. */
695 assemble_destructor (name)
698 #ifdef ASM_OUTPUT_DESTRUCTOR
699 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
703 /* Now tell GNU LD that this is part of the static destructor set. */
704 /* This code works for any machine provided you use GNU as/ld. */
705 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
706 assemble_name (asm_out_file, name);
707 fputc ('\n', asm_out_file);
712 /* Likewise for global constructors. */
715 assemble_constructor (name)
718 #ifdef ASM_OUTPUT_CONSTRUCTOR
719 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
723 /* Now tell GNU LD that this is part of the static constructor set. */
724 /* This code works for any machine provided you use GNU as/ld. */
725 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
726 assemble_name (asm_out_file, name);
727 fputc ('\n', asm_out_file);
732 /* Likewise for entries we want to record for garbage collection.
733 Garbage collection is still under development. */
736 assemble_gc_entry (name)
739 #ifdef ASM_OUTPUT_GC_ENTRY
740 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
744 /* Now tell GNU LD that this is part of the static constructor set. */
745 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
746 assemble_name (asm_out_file, name);
747 fputc ('\n', asm_out_file);
752 /* Output assembler code for the constant pool of a function and associated
753 with defining the name of the function. DECL describes the function.
754 NAME is the function's name. For the constant pool, we use the current
755 constant pool data. */
758 assemble_start_function (decl, fnname)
764 /* The following code does not need preprocessing in the assembler. */
768 output_constant_pool (fnname, decl);
770 function_section (decl);
772 /* Tell assembler to move to target machine's alignment for functions. */
773 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
777 BC_OUTPUT_ALIGN (asm_out_file, align);
779 ASM_OUTPUT_ALIGN (asm_out_file, align);
782 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
783 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
786 #ifdef SDB_DEBUGGING_INFO
787 /* Output SDB definition of the function. */
788 if (write_symbols == SDB_DEBUG)
789 sdbout_mark_begin_function ();
792 #ifdef DBX_DEBUGGING_INFO
793 /* Output DBX definition of the function. */
794 if (write_symbols == DBX_DEBUG)
795 dbxout_begin_function (decl);
798 /* Make function name accessible from other files, if appropriate. */
800 if (TREE_PUBLIC (decl))
802 if (!first_global_object_name)
803 STRIP_NAME_ENCODING (first_global_object_name, fnname);
805 BC_GLOBALIZE_LABEL (asm_out_file, fnname);
807 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
810 /* Do any machine/system dependent processing of the function name */
811 #ifdef ASM_DECLARE_FUNCTION_NAME
812 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
814 /* Standard thing is just output label for the function. */
816 BC_OUTPUT_LABEL (asm_out_file, fnname);
818 ASM_OUTPUT_LABEL (asm_out_file, fnname);
819 #endif /* ASM_DECLARE_FUNCTION_NAME */
822 /* Output assembler code associated with defining the size of the
823 function. DECL describes the function. NAME is the function's name. */
826 assemble_end_function (decl, fnname)
830 #ifdef ASM_DECLARE_FUNCTION_SIZE
831 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
835 /* Assemble code to leave SIZE bytes of zeros. */
838 assemble_zeros (size)
843 bc_emit_const_skip (size);
847 #ifdef ASM_NO_SKIP_IN_TEXT
848 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
849 so we must output 0s explicitly in the text section. */
850 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
854 for (i = 0; i < size - 20; i += 20)
857 fprintf (asm_out_file,
858 "%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);
860 fprintf (asm_out_file,
861 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
867 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
869 fprintf (asm_out_file, "\tbyte 0");
872 for (; i < size; i++)
873 fprintf (asm_out_file, ",0");
874 fprintf (asm_out_file, "\n");
882 BC_OUTPUT_SKIP (asm_out_file, size);
884 ASM_OUTPUT_SKIP (asm_out_file, size);
888 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
891 assemble_align (align)
894 if (align > BITS_PER_UNIT)
895 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
898 /* Assemble a string constant with the specified C string as contents. */
901 assemble_string (p, size)
915 /* If the string is very long, split it up. */
919 int thissize = size - pos;
920 if (thissize > maximum)
924 bc_output_ascii (asm_out_file, p, thissize);
927 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
936 bc_output_ascii (file, p, size)
941 BC_OUTPUT_ASCII (file, p, size);
944 /* Assemble everything that is needed for a variable or function declaration.
945 Not used for automatic variables, and not used for function definitions.
946 Should not be called for variables of incomplete structure type.
948 TOP_LEVEL is nonzero if this variable has file scope.
949 AT_END is nonzero if this is the special handling, at end of compilation,
950 to define things that have had only tentative definitions.
951 DONT_OUTPUT_DATA if nonzero means don't actually output the
952 initial value (that will be done by the caller). */
955 assemble_variable (decl, top_level, at_end, dont_output_data)
959 int dont_output_data;
965 enum in_section saved_in_section;
967 last_assemble_variable_decl = 0;
972 if (GET_CODE (DECL_RTL (decl)) == REG)
974 /* Do output symbol info for global register variables, but do nothing
977 if (TREE_ASM_WRITTEN (decl))
979 TREE_ASM_WRITTEN (decl) = 1;
981 if (!output_bytecode)
983 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
984 /* File-scope global variables are output here. */
985 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
987 dbxout_symbol (decl, 0);
989 #ifdef SDB_DEBUGGING_INFO
990 if (write_symbols == SDB_DEBUG && top_level
991 /* Leave initialized global vars for end of compilation;
992 see comment in compile_file. */
993 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
994 sdbout_symbol (decl, 0);
998 /* Don't output any DWARF debugging information for variables here.
999 In the case of local variables, the information for them is output
1000 when we do our recursive traversal of the tree representation for
1001 the entire containing function. In the case of file-scope variables,
1002 we output information for all of them at the very end of compilation
1003 while we are doing our final traversal of the chain of file-scope
1009 /* Normally no need to say anything here for external references,
1010 since assemble_external is called by the langauge-specific code
1011 when a declaration is first seen. */
1013 if (DECL_EXTERNAL (decl))
1016 /* Output no assembler code for a function declaration.
1017 Only definitions of functions output anything. */
1019 if (TREE_CODE (decl) == FUNCTION_DECL)
1022 /* If type was incomplete when the variable was declared,
1023 see if it is complete now. */
1025 if (DECL_SIZE (decl) == 0)
1026 layout_decl (decl, 0);
1028 /* Still incomplete => don't allocate it; treat the tentative defn
1029 (which is what it must have been) as an `extern' reference. */
1031 if (!dont_output_data && DECL_SIZE (decl) == 0)
1033 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1034 DECL_SOURCE_LINE (decl),
1035 "storage size of `%s' isn't known",
1036 IDENTIFIER_POINTER (DECL_NAME (decl)));
1037 TREE_ASM_WRITTEN (decl) = 1;
1041 /* The first declaration of a variable that comes through this function
1042 decides whether it is global (in C, has external linkage)
1043 or local (in C, has internal linkage). So do nothing more
1044 if this function has already run. */
1046 if (TREE_ASM_WRITTEN (decl))
1049 TREE_ASM_WRITTEN (decl) = 1;
1053 if (! dont_output_data)
1055 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1058 /* This is better than explicit arithmetic, since it avoids overflow. */
1059 size_tree = size_binop (CEIL_DIV_EXPR,
1060 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1062 if (TREE_INT_CST_HIGH (size_tree) != 0)
1064 error_with_decl (decl, "size of variable `%s' is too large");
1069 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1071 /* Handle uninitialized definitions. */
1073 /* ANSI specifies that a tentative definition which is not merged with
1074 a non-tentative definition behaves exactly like a definition with an
1075 initializer equal to zero. (Section 3.7.2)
1076 -fno-common gives strict ANSI behavior. Usually you don't want it.
1077 This matters only for variables with external linkage. */
1078 if ((! flag_no_common || ! TREE_PUBLIC (decl))
1079 && DECL_COMMON (decl)
1080 && ! dont_output_data
1081 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
1083 int size = TREE_INT_CST_LOW (size_tree);
1086 if (TREE_INT_CST_HIGH (size_tree) != 0)
1087 error_with_decl (decl, "size of variable `%s' is too large");
1088 /* Don't allocate zero bytes of common,
1089 since that means "undefined external" in the linker. */
1090 if (size == 0) rounded = 1;
1091 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1092 so that each uninitialized object starts on such a boundary. */
1093 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1094 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1095 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1097 #ifdef DBX_DEBUGGING_INFO
1098 /* File-scope global variables are output here. */
1099 if (write_symbols == DBX_DEBUG && top_level)
1100 dbxout_symbol (decl, 0);
1102 #ifdef SDB_DEBUGGING_INFO
1103 if (write_symbols == SDB_DEBUG && top_level
1104 /* Leave initialized global vars for end of compilation;
1105 see comment in compile_file. */
1106 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1107 sdbout_symbol (decl, 0);
1110 /* Don't output any DWARF debugging information for variables here.
1111 In the case of local variables, the information for them is output
1112 when we do our recursive traversal of the tree representation for
1113 the entire containing function. In the case of file-scope variables,
1114 we output information for all of them at the very end of compilation
1115 while we are doing our final traversal of the chain of file-scope
1119 if (flag_shared_data)
1122 if (TREE_PUBLIC (decl))
1124 #ifdef ASM_OUTPUT_SHARED_COMMON
1125 if (flag_shared_data)
1126 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1129 if (output_bytecode)
1131 BC_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1135 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1136 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1139 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1145 #ifdef ASM_OUTPUT_SHARED_LOCAL
1146 if (flag_shared_data)
1147 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1150 if (output_bytecode)
1152 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1156 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1157 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1160 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1167 /* Handle initialized definitions. */
1169 /* First make the assembler name(s) global if appropriate. */
1170 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1172 if (!first_global_object_name)
1173 STRIP_NAME_ENCODING(first_global_object_name, name);
1174 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1177 for (d = equivalents; d; d = TREE_CHAIN (d))
1179 tree e = TREE_VALUE (d);
1180 if (TREE_PUBLIC (e) && DECL_NAME (e))
1181 ASM_GLOBALIZE_LABEL (asm_out_file,
1182 XSTR (XEXP (DECL_RTL (e), 0), 0));
1186 /* Output any data that we will need to use the address of. */
1187 if (DECL_INITIAL (decl) == error_mark_node)
1188 reloc = contains_pointers_p (TREE_TYPE (decl));
1189 else if (DECL_INITIAL (decl))
1190 reloc = output_addressed_constants (DECL_INITIAL (decl));
1192 /* Switch to the proper section for this data. */
1193 if (IN_NAMED_SECTION (decl))
1194 named_section (decl, NULL);
1197 /* C++ can have const variables that get initialized from constructors,
1198 and thus can not be in a readonly section. We prevent this by
1199 verifying that the initial value is constant for objects put in a
1202 error_mark_node is used by the C front end to indicate that the
1203 initializer has not been seen yet. In this case, we assume that
1204 the initializer must be constant. */
1205 #ifdef SELECT_SECTION
1206 SELECT_SECTION (decl, reloc);
1208 if (TREE_READONLY (decl)
1209 && ! TREE_THIS_VOLATILE (decl)
1210 && DECL_INITIAL (decl)
1211 && (DECL_INITIAL (decl) == error_mark_node
1212 || TREE_CONSTANT (DECL_INITIAL (decl)))
1213 && ! (flag_pic && reloc))
1214 readonly_data_section ();
1220 /* dbxout.c needs to know this. */
1221 if (in_text_section ())
1222 DECL_IN_TEXT_SECTION (decl) = 1;
1224 /* Record current section so we can restore it if dbxout.c clobbers it. */
1225 saved_in_section = in_section;
1227 /* Output the dbx info now that we have chosen the section. */
1229 #ifdef DBX_DEBUGGING_INFO
1230 /* File-scope global variables are output here. */
1231 if (write_symbols == DBX_DEBUG && top_level)
1232 dbxout_symbol (decl, 0);
1234 #ifdef SDB_DEBUGGING_INFO
1235 if (write_symbols == SDB_DEBUG && top_level
1236 /* Leave initialized global vars for end of compilation;
1237 see comment in compile_file. */
1238 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1239 sdbout_symbol (decl, 0);
1242 /* Don't output any DWARF debugging information for variables here.
1243 In the case of local variables, the information for them is output
1244 when we do our recursive traversal of the tree representation for
1245 the entire containing function. In the case of file-scope variables,
1246 we output information for all of them at the very end of compilation
1247 while we are doing our final traversal of the chain of file-scope
1250 /* If the debugging output changed sections, reselect the section
1251 that's supposed to be selected. */
1252 if (in_section != saved_in_section)
1254 /* Switch to the proper section for this data. */
1255 #ifdef SELECT_SECTION
1256 SELECT_SECTION (decl, reloc);
1258 if (TREE_READONLY (decl)
1259 && ! TREE_THIS_VOLATILE (decl)
1260 && DECL_INITIAL (decl)
1261 && (DECL_INITIAL (decl) == error_mark_node
1262 || TREE_CONSTANT (DECL_INITIAL (decl)))
1263 && ! (flag_pic && reloc))
1264 readonly_data_section ();
1270 /* Compute and output the alignment of this data. */
1272 align = DECL_ALIGN (decl);
1273 /* In the case for initialing an array whose length isn't specified,
1274 where we have not yet been able to do the layout,
1275 figure out the proper alignment now. */
1276 if (dont_output_data && DECL_SIZE (decl) == 0
1277 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1278 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1280 /* Some object file formats have a maximum alignment which they support.
1281 In particular, a.out format supports a maximum alignment of 4. */
1282 #ifndef MAX_OFILE_ALIGNMENT
1283 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1285 if (align > MAX_OFILE_ALIGNMENT)
1287 warning_with_decl (decl,
1288 "alignment of `%s' is greater than maximum object file alignment");
1289 align = MAX_OFILE_ALIGNMENT;
1291 #ifdef DATA_ALIGNMENT
1292 /* On some machines, it is good to increase alignment sometimes. */
1293 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1295 #ifdef CONSTANT_ALIGNMENT
1296 if (DECL_INITIAL (decl))
1297 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1300 /* Reset the alignment in case we have made it tighter, so we can benefit
1301 from it in get_pointer_alignment. */
1302 DECL_ALIGN (decl) = align;
1304 if (align > BITS_PER_UNIT)
1306 if (output_bytecode)
1307 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1309 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1312 /* Do any machine/system dependent processing of the object. */
1313 #ifdef ASM_DECLARE_OBJECT_NAME
1314 last_assemble_variable_decl = decl;
1315 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1317 /* Standard thing is just output label for the object. */
1318 if (output_bytecode)
1319 BC_OUTPUT_LABEL (asm_out_file, name);
1321 ASM_OUTPUT_LABEL (asm_out_file, name);
1322 #endif /* ASM_DECLARE_OBJECT_NAME */
1324 if (!dont_output_data)
1326 if (DECL_INITIAL (decl))
1327 /* Output the actual data. */
1328 output_constant (DECL_INITIAL (decl), TREE_INT_CST_LOW (size_tree));
1330 /* Leave space for it. */
1331 assemble_zeros (TREE_INT_CST_LOW (size_tree));
1335 #ifdef XCOFF_DEBUGGING_INFO
1336 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1337 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1338 and `aa' hasn't been output yet, the assembler generates a stab entry with
1339 a value of zero, in addition to creating an unnecessary external entry
1340 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1342 /* File-scope global variables are output here. */
1343 if (write_symbols == XCOFF_DEBUG && top_level)
1345 saved_in_section = in_section;
1347 dbxout_symbol (decl, 0);
1349 if (in_section != saved_in_section)
1351 /* Switch to the proper section for this data. */
1352 #ifdef SELECT_SECTION
1353 SELECT_SECTION (decl, reloc);
1355 if (TREE_READONLY (decl)
1356 && ! TREE_THIS_VOLATILE (decl)
1357 && DECL_INITIAL (decl)
1358 && (DECL_INITIAL (decl) == error_mark_node
1359 || TREE_CONSTANT (DECL_INITIAL (decl)))
1360 && ! (flag_pic && reloc))
1361 readonly_data_section ();
1368 /* There must be a statement after a label. */
1373 /* Return 1 if type TYPE contains any pointers. */
1376 contains_pointers_p (type)
1379 switch (TREE_CODE (type))
1382 case REFERENCE_TYPE:
1383 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1384 so I'll play safe and return 1. */
1390 case QUAL_UNION_TYPE:
1393 /* For a type that has fields, see if the fields have pointers. */
1394 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1395 if (TREE_CODE (fields) == FIELD_DECL
1396 && contains_pointers_p (TREE_TYPE (fields)))
1402 /* An array type contains pointers if its element type does. */
1403 return contains_pointers_p (TREE_TYPE (type));
1410 /* Output text storage for constructor CONSTR. */
1413 bc_output_constructor (constr, size)
1419 /* Must always be a literal; non-literal constructors are handled
1422 if (!TREE_CONSTANT (constr))
1429 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++)
1433 BC_OUTPUT_ALIGN (asm_out_file, i);
1436 output_constant (constr, size);
1439 /* Create storage for constructor CONSTR. */
1442 bc_output_data_constructor (constr)
1447 /* Put in data section */
1451 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1453 BC_OUTPUT_ALIGN (asm_out_file, i);
1455 /* The constructor is filled in at runtime. */
1456 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1459 /* Output something to declare an external symbol to the assembler.
1460 (Most assemblers don't need this, so we normally output nothing.)
1461 Do nothing if DECL is not external. */
1464 assemble_external (decl)
1467 if (output_bytecode)
1470 #ifdef ASM_OUTPUT_EXTERNAL
1471 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1472 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1474 rtx rtl = DECL_RTL (decl);
1476 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1477 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1479 /* Some systems do require some output. */
1480 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1481 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1487 /* Similar, for calling a library function FUN. */
1490 assemble_external_libcall (fun)
1493 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1494 if (!output_bytecode)
1496 /* Declare library function name external when first used, if nec. */
1497 if (! SYMBOL_REF_USED (fun))
1499 SYMBOL_REF_USED (fun) = 1;
1500 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1506 /* Declare the label NAME global. */
1509 assemble_global (name)
1512 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1515 /* Assemble a label named NAME. */
1518 assemble_label (name)
1521 if (output_bytecode)
1522 BC_OUTPUT_LABEL (asm_out_file, name);
1524 ASM_OUTPUT_LABEL (asm_out_file, name);
1527 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1528 If NAME starts with a *, the rest of NAME is output verbatim.
1529 Otherwise NAME is transformed in an implementation-defined way
1530 (usually by the addition of an underscore).
1531 Many macros in the tm file are defined to call this function. */
1534 assemble_name (file, name)
1540 STRIP_NAME_ENCODING (real_name, name);
1541 TREE_SYMBOL_REFERENCED (get_identifier (real_name)) = 1;
1545 if (output_bytecode)
1546 bc_emit_labelref (name);
1548 fputs (&name[1], file);
1552 if (output_bytecode)
1553 BC_OUTPUT_LABELREF (file, name);
1555 ASM_OUTPUT_LABELREF (file, name);
1559 /* Allocate SIZE bytes writable static space with a gensym name
1560 and return an RTX to refer to its address. */
1563 assemble_static_space (size)
1569 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1570 so that each uninitialized object starts on such a boundary. */
1571 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1572 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1573 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1576 if (flag_shared_data)
1580 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1583 namestring = (char *) obstack_alloc (saveable_obstack,
1585 strcpy (namestring, name);
1587 if (output_bytecode)
1588 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1590 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1592 if (output_bytecode)
1594 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1598 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1599 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1601 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1607 /* Assemble the static constant template for function entry trampolines.
1608 This is done at most once per compilation.
1609 Returns an RTX for the address of the template. */
1612 assemble_trampoline_template ()
1618 /* Shouldn't get here */
1619 if (output_bytecode)
1622 /* By default, put trampoline templates in read-only data section. */
1624 #ifdef TRAMPOLINE_SECTION
1625 TRAMPOLINE_SECTION ();
1627 readonly_data_section ();
1630 /* Write the assembler code to define one. */
1631 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1633 ASM_OUTPUT_ALIGN (asm_out_file, align);
1635 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1636 TRAMPOLINE_TEMPLATE (asm_out_file);
1638 /* Record the rtl to refer to it. */
1639 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1641 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1642 return gen_rtx (SYMBOL_REF, Pmode, name);
1645 /* Assemble the integer constant X into an object of SIZE bytes.
1646 X must be either a CONST_INT or CONST_DOUBLE.
1648 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1649 non-zero, abort if we can't output the constant. */
1652 assemble_integer (x, size, force)
1657 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1658 ASM_OUTPUT... macros. */
1662 #ifdef ASM_OUTPUT_CHAR
1664 ASM_OUTPUT_CHAR (asm_out_file, x);
1668 #ifdef ASM_OUTPUT_SHORT
1670 ASM_OUTPUT_SHORT (asm_out_file, x);
1674 #ifdef ASM_OUTPUT_INT
1676 ASM_OUTPUT_INT (asm_out_file, x);
1680 #ifdef ASM_OUTPUT_DOUBLE_INT
1682 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1686 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1688 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1693 /* If we couldn't do it that way, there are two other possibilities: First,
1694 if the machine can output an explicit byte and this is a 1 byte constant,
1695 we can use ASM_OUTPUT_BYTE. */
1697 #ifdef ASM_OUTPUT_BYTE
1698 if (size == 1 && GET_CODE (x) == CONST_INT)
1700 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1705 /* Finally, if SIZE is larger than a single word, try to output the constant
1706 one word at a time. */
1708 if (size > UNITS_PER_WORD)
1711 enum machine_mode mode
1712 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1715 for (i = 0; i < size / UNITS_PER_WORD; i++)
1717 word = operand_subword (x, i, 0, mode);
1722 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1726 if (i == size / UNITS_PER_WORD)
1728 /* If we output at least one word and then could not finish,
1729 there is no valid way to continue. */
1740 /* Assemble the floating-point constant D into an object of size MODE. */
1743 assemble_real (d, mode)
1745 enum machine_mode mode;
1747 jmp_buf output_constant_handler;
1749 if (setjmp (output_constant_handler))
1751 error ("floating point trap outputting a constant");
1752 #ifdef REAL_IS_NOT_DOUBLE
1753 bzero ((char *) &d, sizeof d);
1760 set_float_handler (output_constant_handler);
1764 #ifdef ASM_OUTPUT_BYTE_FLOAT
1766 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1769 #ifdef ASM_OUTPUT_SHORT_FLOAT
1771 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1774 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1776 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1779 #ifdef ASM_OUTPUT_FLOAT
1781 ASM_OUTPUT_FLOAT (asm_out_file, d);
1785 #ifdef ASM_OUTPUT_DOUBLE
1787 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1791 #ifdef ASM_OUTPUT_LONG_DOUBLE
1794 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1802 set_float_handler (NULL_PTR);
1805 /* Here we combine duplicate floating constants to make
1806 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1808 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1809 They are chained through the CONST_DOUBLE_CHAIN.
1810 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1811 In that case, CONST_DOUBLE_MEM is either a MEM,
1812 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1814 (CONST_DOUBLE_MEM is used only for top-level functions.
1815 See force_const_mem for explanation.) */
1817 static rtx const_double_chain;
1819 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1820 For an integer, I0 is the low-order word and I1 is the high-order word.
1821 For a real number, I0 is the word with the low address
1822 and I1 is the word with the high address. */
1825 immed_double_const (i0, i1, mode)
1826 HOST_WIDE_INT i0, i1;
1827 enum machine_mode mode;
1830 int in_current_obstack;
1832 if (GET_MODE_CLASS (mode) == MODE_INT
1833 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1835 /* We clear out all bits that don't belong in MODE, unless they and our
1836 sign bit are all one. So we get either a reasonable negative value
1837 or a reasonable unsigned value for this mode. */
1838 int width = GET_MODE_BITSIZE (mode);
1839 if (width < HOST_BITS_PER_WIDE_INT
1840 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1841 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1842 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1843 else if (width == HOST_BITS_PER_WIDE_INT
1844 && ! (i1 == ~0 && i0 < 0))
1846 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1847 /* We cannot represent this value as a constant. */
1850 /* If this would be an entire word for the target, but is not for
1851 the host, then sign-extend on the host so that the number will look
1852 the same way on the host that it would on the target.
1854 For example, when building a 64 bit alpha hosted 32 bit sparc
1855 targeted compiler, then we want the 32 bit unsigned value -1 to be
1856 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1857 The later confuses the sparc backend. */
1859 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1860 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1861 i0 |= ((HOST_WIDE_INT) (-1) << width);
1863 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1865 ??? Strictly speaking, this is wrong if we create a CONST_INT
1866 for a large unsigned constant with the size of MODE being
1867 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1868 wider mode. In that case we will mis-interpret it as a negative
1871 Unfortunately, the only alternative is to make a CONST_DOUBLE
1872 for any constant in any mode if it is an unsigned constant larger
1873 than the maximum signed integer in an int on the host. However,
1874 doing this will break everyone that always expects to see a CONST_INT
1875 for SImode and smaller.
1877 We have always been making CONST_INTs in this case, so nothing new
1880 if (width <= HOST_BITS_PER_WIDE_INT)
1881 i1 = (i0 < 0) ? ~0 : 0;
1883 /* If this integer fits in one word, return a CONST_INT. */
1884 if ((i1 == 0 && i0 >= 0)
1885 || (i1 == ~0 && i0 < 0))
1886 return GEN_INT (i0);
1888 /* We use VOIDmode for integers. */
1892 /* Search the chain for an existing CONST_DOUBLE with the right value.
1893 If one is found, return it. */
1895 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1896 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1897 && GET_MODE (r) == mode)
1900 /* No; make a new one and add it to the chain.
1902 We may be called by an optimizer which may be discarding any memory
1903 allocated during its processing (such as combine and loop). However,
1904 we will be leaving this constant on the chain, so we cannot tolerate
1905 freed memory. So switch to saveable_obstack for this allocation
1906 and then switch back if we were in current_obstack. */
1908 push_obstacks_nochange ();
1909 rtl_in_saveable_obstack ();
1910 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1913 /* Don't touch const_double_chain in nested function; see force_const_mem.
1914 Also, don't touch it if not inside any function. */
1915 if (outer_function_chain == 0 && current_function_decl != 0)
1917 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1918 const_double_chain = r;
1921 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1922 Actual use of mem-slot is only through force_const_mem. */
1924 CONST_DOUBLE_MEM (r) = const0_rtx;
1929 /* Return a CONST_DOUBLE for a specified `double' value
1930 and machine mode. */
1933 immed_real_const_1 (d, mode)
1935 enum machine_mode mode;
1937 union real_extract u;
1939 int in_current_obstack;
1941 /* Get the desired `double' value as a sequence of ints
1942 since that is how they are stored in a CONST_DOUBLE. */
1946 /* Detect special cases. */
1948 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1949 if (!bcmp ((char *) &dconst0, (char *) &d, sizeof d))
1950 return CONST0_RTX (mode);
1951 /* Check for NaN first, because some ports (specifically the i386) do not
1952 emit correct ieee-fp code by default, and thus will generate a core
1953 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1954 does a floating point comparison. */
1955 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1956 return CONST1_RTX (mode);
1958 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1959 return immed_double_const (u.i[0], u.i[1], mode);
1961 /* The rest of this function handles the case where
1962 a float value requires more than 2 ints of space.
1963 It will be deleted as dead code on machines that don't need it. */
1965 /* Search the chain for an existing CONST_DOUBLE with the right value.
1966 If one is found, return it. */
1968 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1969 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
1970 && GET_MODE (r) == mode)
1973 /* No; make a new one and add it to the chain.
1975 We may be called by an optimizer which may be discarding any memory
1976 allocated during its processing (such as combine and loop). However,
1977 we will be leaving this constant on the chain, so we cannot tolerate
1978 freed memory. So switch to saveable_obstack for this allocation
1979 and then switch back if we were in current_obstack. */
1981 push_obstacks_nochange ();
1982 rtl_in_saveable_obstack ();
1983 r = rtx_alloc (CONST_DOUBLE);
1985 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
1988 /* Don't touch const_double_chain in nested function; see force_const_mem.
1989 Also, don't touch it if not inside any function. */
1990 if (outer_function_chain == 0 && current_function_decl != 0)
1992 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1993 const_double_chain = r;
1996 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1997 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1998 is only through force_const_mem. */
2000 CONST_DOUBLE_MEM (r) = const0_rtx;
2005 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2006 which must be a REAL_CST tree node. */
2009 immed_real_const (exp)
2012 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2015 /* At the end of a function, forget the memory-constants
2016 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2017 Also clear out real_constant_chain and clear out all the chain-pointers. */
2020 clear_const_double_mem ()
2022 register rtx r, next;
2024 /* Don't touch CONST_DOUBLE_MEM for nested functions.
2025 See force_const_mem for explanation. */
2026 if (outer_function_chain != 0)
2029 for (r = const_double_chain; r; r = next)
2031 next = CONST_DOUBLE_CHAIN (r);
2032 CONST_DOUBLE_CHAIN (r) = 0;
2033 CONST_DOUBLE_MEM (r) = cc0_rtx;
2035 const_double_chain = 0;
2038 /* Given an expression EXP with a constant value,
2039 reduce it to the sum of an assembler symbol and an integer.
2040 Store them both in the structure *VALUE.
2041 Abort if EXP does not reduce. */
2046 HOST_WIDE_INT offset;
2050 decode_addr_const (exp, value)
2052 struct addr_const *value;
2054 register tree target = TREE_OPERAND (exp, 0);
2055 register int offset = 0;
2060 if (TREE_CODE (target) == COMPONENT_REF
2061 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2064 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2065 target = TREE_OPERAND (target, 0);
2067 else if (TREE_CODE (target) == ARRAY_REF)
2069 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2070 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2072 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2073 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2075 target = TREE_OPERAND (target, 0);
2081 switch (TREE_CODE (target))
2085 x = DECL_RTL (target);
2089 if (output_bytecode)
2090 /* FIXME: this may not be correct, check it */
2091 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
2093 x = gen_rtx (MEM, FUNCTION_MODE,
2094 gen_rtx (LABEL_REF, VOIDmode,
2095 label_rtx (TREE_OPERAND (exp, 0))));
2102 x = TREE_CST_RTL (target);
2109 if (!output_bytecode)
2111 if (GET_CODE (x) != MEM)
2117 value->offset = offset;
2120 /* Uniquize all constants that appear in memory.
2121 Each constant in memory thus far output is recorded
2122 in `const_hash_table' with a `struct constant_descriptor'
2123 that contains a polish representation of the value of
2126 We cannot store the trees in the hash table
2127 because the trees may be temporary. */
2129 struct constant_descriptor
2131 struct constant_descriptor *next;
2137 #define MAX_HASH_TABLE 1009
2138 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2140 /* Compute a hash code for a constant expression. */
2147 register int len, hi, i;
2148 register enum tree_code code = TREE_CODE (exp);
2150 if (code == INTEGER_CST)
2152 p = (char *) &TREE_INT_CST_LOW (exp);
2153 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2155 else if (code == REAL_CST)
2157 p = (char *) &TREE_REAL_CST (exp);
2158 len = sizeof TREE_REAL_CST (exp);
2160 else if (code == STRING_CST)
2161 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2162 else if (code == COMPLEX_CST)
2163 return const_hash (TREE_REALPART (exp)) * 5
2164 + const_hash (TREE_IMAGPART (exp));
2165 else if (code == CONSTRUCTOR && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2167 len = int_size_in_bytes (TREE_TYPE (exp));
2168 p = (char*) alloca (len);
2169 get_set_constructor_bytes (exp, (unsigned char *) p, len);
2171 else if (code == CONSTRUCTOR)
2175 /* For record type, include the type in the hashing.
2176 We do not do so for array types
2177 because (1) the sizes of the elements are sufficient
2178 and (2) distinct array types can have the same constructor.
2179 Instead, we include the array size because the constructor could
2181 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2182 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2185 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2186 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2188 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2189 if (TREE_VALUE (link))
2190 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2194 else if (code == ADDR_EXPR)
2196 struct addr_const value;
2197 decode_addr_const (exp, &value);
2198 if (GET_CODE (value.base) == SYMBOL_REF)
2200 /* Don't hash the address of the SYMBOL_REF;
2201 only use the offset and the symbol name. */
2203 p = XSTR (value.base, 0);
2204 for (i = 0; p[i] != 0; i++)
2205 hi = ((hi * 613) + (unsigned)(p[i]));
2207 else if (GET_CODE (value.base) == LABEL_REF)
2208 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2210 hi &= (1 << HASHBITS) - 1;
2211 hi %= MAX_HASH_TABLE;
2214 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2215 return const_hash (TREE_OPERAND (exp, 0)) * 9
2216 + const_hash (TREE_OPERAND (exp, 1));
2217 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2218 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2220 /* Compute hashing function */
2222 for (i = 0; i < len; i++)
2223 hi = ((hi * 613) + (unsigned)(p[i]));
2225 hi &= (1 << HASHBITS) - 1;
2226 hi %= MAX_HASH_TABLE;
2230 /* Compare a constant expression EXP with a constant-descriptor DESC.
2231 Return 1 if DESC describes a constant with the same value as EXP. */
2234 compare_constant (exp, desc)
2236 struct constant_descriptor *desc;
2238 return 0 != compare_constant_1 (exp, desc->contents);
2241 /* Compare constant expression EXP with a substring P of a constant descriptor.
2242 If they match, return a pointer to the end of the substring matched.
2243 If they do not match, return 0.
2245 Since descriptors are written in polish prefix notation,
2246 this function can be used recursively to test one operand of EXP
2247 against a subdescriptor, and if it succeeds it returns the
2248 address of the subdescriptor for the next operand. */
2251 compare_constant_1 (exp, p)
2255 register char *strp;
2257 register enum tree_code code = TREE_CODE (exp);
2259 if (code != (enum tree_code) *p++)
2262 if (code == INTEGER_CST)
2264 /* Integer constants are the same only if the same width of type. */
2265 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2267 strp = (char *) &TREE_INT_CST_LOW (exp);
2268 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2270 else if (code == REAL_CST)
2272 /* Real constants are the same only if the same width of type. */
2273 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2275 strp = (char *) &TREE_REAL_CST (exp);
2276 len = sizeof TREE_REAL_CST (exp);
2278 else if (code == STRING_CST)
2280 if (flag_writable_strings)
2282 strp = TREE_STRING_POINTER (exp);
2283 len = TREE_STRING_LENGTH (exp);
2284 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2285 sizeof TREE_STRING_LENGTH (exp)))
2287 p += sizeof TREE_STRING_LENGTH (exp);
2289 else if (code == COMPLEX_CST)
2291 p = compare_constant_1 (TREE_REALPART (exp), p);
2292 if (p == 0) return 0;
2293 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2296 else if (code == CONSTRUCTOR && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2298 len = int_size_in_bytes (TREE_TYPE (exp));
2299 strp = (char*) alloca (len);
2300 get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2302 else if (code == CONSTRUCTOR)
2305 int length = list_length (CONSTRUCTOR_ELTS (exp));
2308 if (bcmp ((char *) &length, p, sizeof length))
2312 /* For record constructors, insist that the types match.
2313 For arrays, just verify both constructors are for arrays. */
2314 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2315 type = TREE_TYPE (exp);
2318 if (bcmp ((char *) &type, p, sizeof type))
2322 /* For arrays, insist that the size in bytes match. */
2323 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2325 int size = int_size_in_bytes (TREE_TYPE (exp));
2326 if (bcmp ((char *) &size, p, sizeof size))
2331 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2333 if (TREE_VALUE (link))
2335 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2342 if (bcmp ((char *) &zero, p, sizeof zero))
2350 else if (code == ADDR_EXPR)
2352 struct addr_const value;
2353 decode_addr_const (exp, &value);
2354 strp = (char *) &value.offset;
2355 len = sizeof value.offset;
2356 /* Compare the offset. */
2358 if (*p++ != *strp++)
2360 /* Compare symbol name. */
2361 strp = XSTR (value.base, 0);
2362 len = strlen (strp) + 1;
2364 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2366 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2367 if (p == 0) return 0;
2368 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2371 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2373 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2377 /* Compare constant contents. */
2379 if (*p++ != *strp++)
2385 /* Construct a constant descriptor for the expression EXP.
2386 It is up to the caller to enter the descriptor in the hash table. */
2388 static struct constant_descriptor *
2389 record_constant (exp)
2392 struct constant_descriptor *next = 0;
2395 /* Make a struct constant_descriptor. The first two pointers will
2396 be filled in later. Here we just leave space for them. */
2398 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2399 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2400 record_constant_1 (exp);
2401 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2404 /* Add a description of constant expression EXP
2405 to the object growing in `permanent_obstack'.
2406 No need to return its address; the caller will get that
2407 from the obstack when the object is complete. */
2410 record_constant_1 (exp)
2413 register char *strp;
2415 register enum tree_code code = TREE_CODE (exp);
2417 obstack_1grow (&permanent_obstack, (unsigned int) code);
2422 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2423 strp = (char *) &TREE_INT_CST_LOW (exp);
2424 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2428 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2429 strp = (char *) &TREE_REAL_CST (exp);
2430 len = sizeof TREE_REAL_CST (exp);
2434 if (flag_writable_strings)
2437 strp = TREE_STRING_POINTER (exp);
2438 len = TREE_STRING_LENGTH (exp);
2439 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2440 sizeof TREE_STRING_LENGTH (exp));
2444 record_constant_1 (TREE_REALPART (exp));
2445 record_constant_1 (TREE_IMAGPART (exp));
2449 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2451 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2452 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2453 obstack_blank (&permanent_obstack, nbytes);
2454 get_set_constructor_bytes
2455 (exp, (unsigned char *) permanent_obstack.next_free, nbytes);
2461 int length = list_length (CONSTRUCTOR_ELTS (exp));
2464 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2466 /* For record constructors, insist that the types match.
2467 For arrays, just verify both constructors are for arrays. */
2468 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2469 type = TREE_TYPE (exp);
2472 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2474 /* For arrays, insist that the size in bytes match. */
2475 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2477 int size = int_size_in_bytes (TREE_TYPE (exp));
2478 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2481 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2483 if (TREE_VALUE (link))
2484 record_constant_1 (TREE_VALUE (link));
2489 obstack_grow (&permanent_obstack,
2490 (char *) &zero, sizeof zero);
2498 struct addr_const value;
2500 decode_addr_const (exp, &value);
2501 /* Record the offset. */
2502 obstack_grow (&permanent_obstack,
2503 (char *) &value.offset, sizeof value.offset);
2504 /* Record the symbol name. */
2505 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2506 strlen (XSTR (value.base, 0)) + 1);
2512 record_constant_1 (TREE_OPERAND (exp, 0));
2513 record_constant_1 (TREE_OPERAND (exp, 1));
2518 case NON_LVALUE_EXPR:
2519 record_constant_1 (TREE_OPERAND (exp, 0));
2526 /* Record constant contents. */
2527 obstack_grow (&permanent_obstack, strp, len);
2530 /* Record a list of constant expressions that were passed to
2531 output_constant_def but that could not be output right away. */
2533 struct deferred_constant
2535 struct deferred_constant *next;
2541 static struct deferred_constant *deferred_constants;
2543 /* Nonzero means defer output of addressed subconstants
2544 (i.e., those for which output_constant_def is called.) */
2545 static int defer_addressed_constants_flag;
2547 /* Start deferring output of subconstants. */
2550 defer_addressed_constants ()
2552 defer_addressed_constants_flag++;
2555 /* Stop deferring output of subconstants,
2556 and output now all those that have been deferred. */
2559 output_deferred_addressed_constants ()
2561 struct deferred_constant *p, *next;
2563 defer_addressed_constants_flag--;
2565 if (defer_addressed_constants_flag > 0)
2568 for (p = deferred_constants; p; p = next)
2570 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2575 deferred_constants = 0;
2578 /* Make a copy of the whole tree structure for a constant.
2579 This handles the same types of nodes that compare_constant
2580 and record_constant handle. */
2586 switch (TREE_CODE (exp))
2589 /* For ADDR_EXPR, we do not want to copy the decl whose address
2590 is requested. We do want to copy constants though. */
2591 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2592 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2593 copy_constant (TREE_OPERAND (exp, 0)));
2595 return copy_node (exp);
2600 return copy_node (exp);
2603 return build_complex (copy_constant (TREE_REALPART (exp)),
2604 copy_constant (TREE_IMAGPART (exp)));
2608 return build (TREE_CODE (exp), TREE_TYPE (exp),
2609 copy_constant (TREE_OPERAND (exp, 0)),
2610 copy_constant (TREE_OPERAND (exp, 1)));
2614 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2615 copy_constant (TREE_OPERAND (exp, 0)));
2619 tree copy = copy_node (exp);
2620 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2623 CONSTRUCTOR_ELTS (copy) = list;
2624 for (tail = list; tail; tail = TREE_CHAIN (tail))
2625 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2626 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2627 for (tail = list; tail; tail = TREE_CHAIN (tail))
2628 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2638 /* Return an rtx representing a reference to constant data in memory
2639 for the constant expression EXP.
2641 If assembler code for such a constant has already been output,
2642 return an rtx to refer to it.
2643 Otherwise, output such a constant in memory (or defer it for later)
2644 and generate an rtx for it.
2646 The TREE_CST_RTL of EXP is set up to point to that rtx.
2647 The const_hash_table records which constants already have label strings. */
2650 output_constant_def (exp)
2654 register struct constant_descriptor *desc;
2660 if (TREE_CODE (exp) == INTEGER_CST)
2661 abort (); /* No TREE_CST_RTL slot in these. */
2663 if (TREE_CST_RTL (exp))
2664 return TREE_CST_RTL (exp);
2666 /* Make sure any other constants whose addresses appear in EXP
2667 are assigned label numbers. */
2669 reloc = output_addressed_constants (exp);
2671 /* Compute hash code of EXP. Search the descriptors for that hash code
2672 to see if any of them describes EXP. If yes, the descriptor records
2673 the label number already assigned. */
2675 hash = const_hash (exp) % MAX_HASH_TABLE;
2677 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2678 if (compare_constant (exp, desc))
2680 found = desc->label;
2686 /* No constant equal to EXP is known to have been output.
2687 Make a constant descriptor to enter EXP in the hash table.
2688 Assign the label number and record it in the descriptor for
2689 future calls to this function to find. */
2691 /* Create a string containing the label name, in LABEL. */
2692 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2694 desc = record_constant (exp);
2695 desc->next = const_hash_table[hash];
2697 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2698 const_hash_table[hash] = desc;
2702 /* Create a string containing the label name, in LABEL. */
2703 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2706 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2708 push_obstacks_nochange ();
2709 if (TREE_PERMANENT (exp))
2710 end_temporary_allocation ();
2712 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2715 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2716 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2717 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2718 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2722 /* Optionally set flags or add text to the name to record information
2723 such as that it is a function name. If the name is changed, the macro
2724 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2725 #ifdef ENCODE_SECTION_INFO
2726 ENCODE_SECTION_INFO (exp);
2729 /* If this is the first time we've seen this particular constant,
2730 output it (or defer its output for later). */
2733 if (defer_addressed_constants_flag)
2735 struct deferred_constant *p;
2736 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2738 push_obstacks_nochange ();
2739 suspend_momentary ();
2740 p->exp = copy_constant (exp);
2743 p->labelno = const_labelno++;
2744 p->next = deferred_constants;
2745 deferred_constants = p;
2748 output_constant_def_contents (exp, reloc, const_labelno++);
2751 return TREE_CST_RTL (exp);
2754 /* Now output assembler code to define the label for EXP,
2755 and follow it with the data of EXP. */
2758 output_constant_def_contents (exp, reloc, labelno)
2765 if (IN_NAMED_SECTION (exp))
2766 named_section (exp, NULL);
2769 /* First switch to text section, except for writable strings. */
2770 #ifdef SELECT_SECTION
2771 SELECT_SECTION (exp, reloc);
2773 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2774 || (flag_pic && reloc))
2777 readonly_data_section ();
2781 /* Align the location counter as required by EXP's data type. */
2782 align = TYPE_ALIGN (TREE_TYPE (exp));
2783 #ifdef CONSTANT_ALIGNMENT
2784 align = CONSTANT_ALIGNMENT (exp, align);
2787 if (align > BITS_PER_UNIT)
2789 if (!output_bytecode)
2791 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2795 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2799 /* Output the label itself. */
2800 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2802 /* Output the value of EXP. */
2803 output_constant (exp,
2804 (TREE_CODE (exp) == STRING_CST
2805 ? TREE_STRING_LENGTH (exp)
2806 : int_size_in_bytes (TREE_TYPE (exp))));
2810 /* Similar hash facility for making memory-constants
2811 from constant rtl-expressions. It is used on RISC machines
2812 where immediate integer arguments and constant addresses are restricted
2813 so that such constants must be stored in memory.
2815 This pool of constants is reinitialized for each function
2816 so each function gets its own constants-pool that comes right before it.
2818 All structures allocated here are discarded when functions are saved for
2819 inlining, so they do not need to be allocated permanently. */
2821 #define MAX_RTX_HASH_TABLE 61
2822 static struct constant_descriptor **const_rtx_hash_table;
2824 /* Structure to represent sufficient information about a constant so that
2825 it can be output when the constant pool is output, so that function
2826 integration can be done, and to simplify handling on machines that reference
2827 constant pool as base+displacement. */
2829 struct pool_constant
2831 struct constant_descriptor *desc;
2832 struct pool_constant *next;
2833 enum machine_mode mode;
2840 /* Pointers to first and last constant in pool. */
2842 static struct pool_constant *first_pool, *last_pool;
2844 /* Current offset in constant pool (does not include any machine-specific
2847 static int pool_offset;
2849 /* Structure used to maintain hash table mapping symbols used to their
2850 corresponding constants. */
2855 struct pool_constant *pool;
2856 struct pool_sym *next;
2859 static struct pool_sym **const_rtx_sym_hash_table;
2861 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2862 The argument is XSTR (... , 0) */
2864 #define SYMHASH(LABEL) \
2865 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2867 /* Initialize constant pool hashing for next function. */
2870 init_const_rtx_hash_table ()
2872 const_rtx_hash_table
2873 = ((struct constant_descriptor **)
2874 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2875 const_rtx_sym_hash_table
2876 = ((struct pool_sym **)
2877 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2878 bzero ((char *) const_rtx_hash_table,
2879 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2880 bzero ((char *) const_rtx_sym_hash_table,
2881 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2883 first_pool = last_pool = 0;
2887 /* Save and restore status for a nested function. */
2890 save_varasm_status (p)
2893 p->const_rtx_hash_table = const_rtx_hash_table;
2894 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2895 p->first_pool = first_pool;
2896 p->last_pool = last_pool;
2897 p->pool_offset = pool_offset;
2901 restore_varasm_status (p)
2904 const_rtx_hash_table = p->const_rtx_hash_table;
2905 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2906 first_pool = p->first_pool;
2907 last_pool = p->last_pool;
2908 pool_offset = p->pool_offset;
2911 enum kind { RTX_DOUBLE, RTX_INT };
2915 #ifdef ONLY_INT_FIELDS
2916 unsigned int kind : 16;
2917 unsigned int mode : 16;
2919 enum kind kind : 16;
2920 enum machine_mode mode : 16;
2923 union real_extract du;
2924 struct addr_const addr;
2928 /* Express an rtx for a constant integer (perhaps symbolic)
2929 as the sum of a symbol or label plus an explicit integer.
2930 They are stored into VALUE. */
2933 decode_rtx_const (mode, x, value)
2934 enum machine_mode mode;
2936 struct rtx_const *value;
2938 /* Clear the whole structure, including any gaps. */
2941 int *p = (int *) value;
2942 int *end = (int *) (value + 1);
2947 value->kind = RTX_INT; /* Most usual kind. */
2950 switch (GET_CODE (x))
2953 value->kind = RTX_DOUBLE;
2954 if (GET_MODE (x) != VOIDmode)
2955 value->mode = GET_MODE (x);
2956 bcopy ((char *) &CONST_DOUBLE_LOW (x),
2957 (char *) &value->un.du, sizeof value->un.du);
2961 value->un.addr.offset = INTVAL (x);
2967 value->un.addr.base = x;
2972 if (GET_CODE (x) == PLUS)
2974 value->un.addr.base = XEXP (x, 0);
2975 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2977 value->un.addr.offset = INTVAL (XEXP (x, 1));
2979 else if (GET_CODE (x) == MINUS)
2981 value->un.addr.base = XEXP (x, 0);
2982 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2984 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2994 if (value->kind == RTX_INT && value->un.addr.base != 0)
2995 switch (GET_CODE (value->un.addr.base))
2999 /* Use the string's address, not the SYMBOL_REF's address,
3000 for the sake of addresses of library routines.
3001 For a LABEL_REF, compare labels. */
3002 value->un.addr.base = XEXP (value->un.addr.base, 0);
3006 /* Given a MINUS expression, simplify it if both sides
3007 include the same symbol. */
3010 simplify_subtraction (x)
3013 struct rtx_const val0, val1;
3015 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3016 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3018 if (val0.un.addr.base == val1.un.addr.base)
3019 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3023 /* Compute a hash code for a constant RTL expression. */
3026 const_hash_rtx (mode, x)
3027 enum machine_mode mode;
3032 struct rtx_const value;
3033 decode_rtx_const (mode, x, &value);
3035 /* Compute hashing function */
3037 for (i = 0; i < sizeof value / sizeof (int); i++)
3038 hi += ((int *) &value)[i];
3040 hi &= (1 << HASHBITS) - 1;
3041 hi %= MAX_RTX_HASH_TABLE;
3045 /* Compare a constant rtl object X with a constant-descriptor DESC.
3046 Return 1 if DESC describes a constant with the same value as X. */
3049 compare_constant_rtx (mode, x, desc)
3050 enum machine_mode mode;
3052 struct constant_descriptor *desc;
3054 register int *p = (int *) desc->contents;
3057 struct rtx_const value;
3059 decode_rtx_const (mode, x, &value);
3060 strp = (int *) &value;
3061 len = sizeof value / sizeof (int);
3063 /* Compare constant contents. */
3065 if (*p++ != *strp++)
3071 /* Construct a constant descriptor for the rtl-expression X.
3072 It is up to the caller to enter the descriptor in the hash table. */
3074 static struct constant_descriptor *
3075 record_constant_rtx (mode, x)
3076 enum machine_mode mode;
3079 struct constant_descriptor *ptr;
3081 struct rtx_const value;
3083 decode_rtx_const (mode, x, &value);
3085 /* Put these things in the saveable obstack so we can ensure it won't
3086 be freed if we are called from combine or some other phase that discards
3087 memory allocated from function_obstack (current_obstack). */
3088 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3089 obstack_grow (saveable_obstack, &label, sizeof label);
3091 /* Record constant contents. */
3092 obstack_grow (saveable_obstack, &value, sizeof value);
3094 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3097 /* Given a constant rtx X, make (or find) a memory constant for its value
3098 and return a MEM rtx to refer to it in memory. */
3101 force_const_mem (mode, x)
3102 enum machine_mode mode;
3106 register struct constant_descriptor *desc;
3111 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3112 (this will always be true for floating CONST_DOUBLEs that have been
3113 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3114 use the previous copy. Otherwise, make a new one. Note that in
3115 the unlikely event that this same CONST_DOUBLE is used in two different
3116 modes in an alternating fashion, we will allocate a lot of different
3117 memory locations, but this should be extremely rare. */
3119 /* Don't use CONST_DOUBLE_MEM in a nested function.
3120 Nested functions have their own constant pools,
3121 so they can't share the same values in CONST_DOUBLE_MEM
3122 with the containing function. */
3123 if (outer_function_chain == 0)
3124 if (GET_CODE (x) == CONST_DOUBLE
3125 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3126 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3127 return CONST_DOUBLE_MEM (x);
3129 /* Compute hash code of X. Search the descriptors for that hash code
3130 to see if any of them describes X. If yes, the descriptor records
3131 the label number already assigned. */
3133 hash = const_hash_rtx (mode, x);
3135 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3136 if (compare_constant_rtx (mode, x, desc))
3138 found = desc->label;
3144 register struct pool_constant *pool;
3145 register struct pool_sym *sym;
3148 /* No constant equal to X is known to have been output.
3149 Make a constant descriptor to enter X in the hash table.
3150 Assign the label number and record it in the descriptor for
3151 future calls to this function to find. */
3153 desc = record_constant_rtx (mode, x);
3154 desc->next = const_rtx_hash_table[hash];
3155 const_rtx_hash_table[hash] = desc;
3157 /* Align the location counter as required by EXP's data type. */
3158 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3159 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3160 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3162 pool_offset += align - 1;
3163 pool_offset &= ~ (align - 1);
3165 /* If RTL is not being placed into the saveable obstack, make a
3166 copy of X that is in the saveable obstack in case we are being
3167 called from combine or some other phase that discards memory
3168 it allocates. We need only do this if it is a CONST, since
3169 no other RTX should be allocated in this situation. */
3170 if (rtl_obstack != saveable_obstack
3171 && GET_CODE (x) == CONST)
3173 push_obstacks_nochange ();
3174 rtl_in_saveable_obstack ();
3176 x = gen_rtx (CONST, GET_MODE (x),
3177 gen_rtx (PLUS, GET_MODE (x),
3178 XEXP (XEXP (x, 0), 0), XEXP (XEXP (x, 0), 1)));
3182 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3184 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3188 pool->labelno = const_labelno;
3189 pool->align = align;
3190 pool->offset = pool_offset;
3196 last_pool->next = pool;
3199 pool_offset += GET_MODE_SIZE (mode);
3201 /* Create a string containing the label name, in LABEL. */
3202 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3207 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3209 /* Add label to symbol hash table. */
3210 hash = SYMHASH (found);
3211 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3214 sym->next = const_rtx_sym_hash_table[hash];
3215 const_rtx_sym_hash_table[hash] = sym;
3218 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3220 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3222 RTX_UNCHANGING_P (def) = 1;
3223 /* Mark the symbol_ref as belonging to this constants pool. */
3224 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3225 current_function_uses_const_pool = 1;
3227 if (outer_function_chain == 0)
3228 if (GET_CODE (x) == CONST_DOUBLE)
3230 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3232 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3233 const_double_chain = x;
3235 CONST_DOUBLE_MEM (x) = def;
3241 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3242 the corresponding pool_constant structure. */
3244 static struct pool_constant *
3245 find_pool_constant (addr)
3248 struct pool_sym *sym;
3249 char *label = XSTR (addr, 0);
3251 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3252 if (sym->label == label)
3258 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3261 get_pool_constant (addr)
3264 return (find_pool_constant (addr))->constant;
3267 /* Similar, return the mode. */
3270 get_pool_mode (addr)
3273 return (find_pool_constant (addr))->mode;
3276 /* Similar, return the offset in the constant pool. */
3279 get_pool_offset (addr)
3282 return (find_pool_constant (addr))->offset;
3285 /* Return the size of the constant pool. */
3293 /* Write all the constants in the constant pool. */
3296 output_constant_pool (fnname, fndecl)
3300 struct pool_constant *pool;
3302 union real_extract u;
3304 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3305 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3308 for (pool = first_pool; pool; pool = pool->next)
3312 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3313 whose CODE_LABEL has been deleted. This can occur if a jump table
3314 is eliminated by optimization. If so, write a constant of zero
3315 instead. Note that this can also happen by turning the
3316 CODE_LABEL into a NOTE. */
3317 if (((GET_CODE (x) == LABEL_REF
3318 && (INSN_DELETED_P (XEXP (x, 0))
3319 || GET_CODE (XEXP (x, 0)) == NOTE)))
3320 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3321 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3322 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3323 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3326 /* First switch to correct section. */
3327 #ifdef SELECT_RTX_SECTION
3328 SELECT_RTX_SECTION (pool->mode, x);
3330 readonly_data_section ();
3333 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3334 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3335 pool->align, pool->labelno, done);
3338 if (pool->align > 1)
3339 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3341 /* Output the label. */
3342 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3344 /* Output the value of the constant itself. */
3345 switch (GET_MODE_CLASS (pool->mode))
3348 if (GET_CODE (x) != CONST_DOUBLE)
3351 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3352 assemble_real (u.d, pool->mode);
3356 case MODE_PARTIAL_INT:
3357 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3367 /* Done with this pool. */
3368 first_pool = last_pool = 0;
3371 /* Find all the constants whose addresses are referenced inside of EXP,
3372 and make sure assembler code with a label has been output for each one.
3373 Indicate whether an ADDR_EXPR has been encountered. */
3376 output_addressed_constants (exp)
3381 switch (TREE_CODE (exp))
3385 register tree constant = TREE_OPERAND (exp, 0);
3387 while (TREE_CODE (constant) == COMPONENT_REF)
3389 constant = TREE_OPERAND (constant, 0);
3392 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3393 || TREE_CODE (constant) == CONSTRUCTOR)
3394 /* No need to do anything here
3395 for addresses of variables or functions. */
3396 output_constant_def (constant);
3403 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3404 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3409 case NON_LVALUE_EXPR:
3410 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3416 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3417 if (TREE_VALUE (link) != 0)
3418 reloc |= output_addressed_constants (TREE_VALUE (link));
3428 /* Output assembler code for constant EXP to FILE, with no label.
3429 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3430 Assumes output_addressed_constants has been done on EXP already.
3432 Generate exactly SIZE bytes of assembler data, padding at the end
3433 with zeros if necessary. SIZE must always be specified.
3435 SIZE is important for structure constructors,
3436 since trailing members may have been omitted from the constructor.
3437 It is also important for initialization of arrays from string constants
3438 since the full length of the string constant might not be wanted.
3439 It is also needed for initialization of unions, where the initializer's
3440 type is just one member, and that may not be as long as the union.
3442 There a case in which we would fail to output exactly SIZE bytes:
3443 for a structure constructor that wants to produce more than SIZE bytes.
3444 But such constructors will never be generated for any possible input. */
3447 output_constant (exp, size)
3451 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3457 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3458 That way we get the constant (we hope) inside it. Also, strip off any
3459 NOP_EXPR that converts between two record, union, array, or set types. */
3460 while ((TREE_CODE (exp) == NOP_EXPR
3461 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3462 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
3463 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3464 exp = TREE_OPERAND (exp, 0);
3466 /* Allow a constructor with no elements for any data type.
3467 This means to fill the space with zeros. */
3468 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3470 if (output_bytecode)
3471 bc_emit_const_skip (size);
3473 assemble_zeros (size);
3484 case REFERENCE_TYPE:
3485 /* ??? What about (int)((float)(int)&foo + 4) */
3486 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3487 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3488 exp = TREE_OPERAND (exp, 0);
3490 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3491 EXPAND_INITIALIZER),
3493 error ("initializer for integer value is too complicated");
3498 if (TREE_CODE (exp) != REAL_CST)
3499 error ("initializer for floating value is not a floating constant");
3501 assemble_real (TREE_REAL_CST (exp),
3502 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3507 output_constant (TREE_REALPART (exp), size / 2);
3508 output_constant (TREE_IMAGPART (exp), size / 2);
3509 size -= (size / 2) * 2;
3513 if (TREE_CODE (exp) == CONSTRUCTOR)
3515 output_constructor (exp, size);
3518 else if (TREE_CODE (exp) == STRING_CST)
3522 if (size > TREE_STRING_LENGTH (exp))
3524 excess = size - TREE_STRING_LENGTH (exp);
3525 size = TREE_STRING_LENGTH (exp);
3528 assemble_string (TREE_STRING_POINTER (exp), size);
3537 if (TREE_CODE (exp) == CONSTRUCTOR)
3538 output_constructor (exp, size);
3544 if (TREE_CODE (exp) == INTEGER_CST)
3545 assemble_integer (expand_expr (exp, NULL_RTX,
3546 VOIDmode, EXPAND_INITIALIZER),
3548 else if (TREE_CODE (exp) == CONSTRUCTOR)
3550 unsigned char *buffer = (unsigned char *) alloca (size);
3551 if (get_set_constructor_bytes (exp, buffer, size))
3553 assemble_string ((char *) buffer, size);
3556 error ("unknown set constructor type");
3561 assemble_zeros (size);
3564 /* Bytecode specific code to output assembler for integer. */
3567 bc_assemble_integer (exp, size)
3575 /* FIXME: is this fold() business going to be as good as the
3576 expand_expr() using EXPAND_SUM above in the RTL case? I
3578 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3582 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3583 exp = TREE_OPERAND (exp, 0);
3584 if (TREE_CODE (exp) == INTEGER_CST)
3589 else if (TREE_CODE (exp) == PLUS_EXPR)
3591 const_part = TREE_OPERAND (exp, 0);
3592 while (TREE_CODE (const_part) == NOP_EXPR
3593 || TREE_CODE (const_part) == CONVERT_EXPR)
3594 const_part = TREE_OPERAND (const_part, 0);
3595 addr_part = TREE_OPERAND (exp, 1);
3596 while (TREE_CODE (addr_part) == NOP_EXPR
3597 || TREE_CODE (addr_part) == CONVERT_EXPR)
3598 addr_part = TREE_OPERAND (addr_part, 0);
3599 if (TREE_CODE (const_part) != INTEGER_CST)
3600 tmp = const_part, const_part = addr_part, addr_part = tmp;
3601 if (TREE_CODE (const_part) != INTEGER_CST
3602 || TREE_CODE (addr_part) != ADDR_EXPR)
3603 abort (); /* FIXME: we really haven't considered
3604 all the possible cases here. */
3606 else if (TREE_CODE (exp) == ADDR_EXPR)
3608 const_part = integer_zero_node;
3612 abort (); /* FIXME: ditto previous. */
3618 char c = TREE_INT_CST_LOW (const_part);
3624 short s = TREE_INT_CST_LOW (const_part);
3625 bc_emit ((char *) &s, 2);
3630 int i = TREE_INT_CST_LOW (const_part);
3631 bc_emit ((char *) &i, 4);
3636 if (WORDS_BIG_ENDIAN)
3638 int i = TREE_INT_CST_HIGH (const_part);
3639 bc_emit ((char *) &i, 4);
3640 i = TREE_INT_CST_LOW (const_part);
3641 bc_emit ((char *) &i, 4);
3645 int i = TREE_INT_CST_LOW (const_part);
3646 bc_emit ((char *) &i, 4);
3647 i = TREE_INT_CST_HIGH (const_part);
3648 bc_emit ((char *) &i, 4);
3655 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3656 bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3657 TREE_INT_CST_LOW (const_part));
3659 abort (); /* FIXME: there may be more cases. */
3662 /* Subroutine of output_constant, used for CONSTRUCTORs
3663 (aggregate constants).
3664 Generate at least SIZE bytes, padding if necessary. */
3667 output_constructor (exp, size)
3671 register tree link, field = 0;
3672 HOST_WIDE_INT min_index = 0;
3673 /* Number of bytes output or skipped so far.
3674 In other words, current position within the constructor. */
3675 int total_bytes = 0;
3676 /* Non-zero means BYTE contains part of a byte, to be output. */
3677 int byte_buffer_in_use = 0;
3680 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3683 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3684 field = TYPE_FIELDS (TREE_TYPE (exp));
3686 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3687 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3689 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3691 /* As LINK goes through the elements of the constant,
3692 FIELD goes through the structure fields, if the constant is a structure.
3693 if the constant is a union, then we override this,
3694 by getting the field from the TREE_LIST element.
3695 But the constant could also be an array. Then FIELD is zero. */
3696 for (link = CONSTRUCTOR_ELTS (exp);
3698 link = TREE_CHAIN (link),
3699 field = field ? TREE_CHAIN (field) : 0)
3701 tree val = TREE_VALUE (link);
3704 /* the element in a union constructor specifies the proper field. */
3706 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3707 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3709 /* if available, use the type given by link */
3710 if (TREE_PURPOSE (link) != 0)
3711 field = TREE_PURPOSE (link);
3714 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3715 index = TREE_PURPOSE (link);
3717 /* Eliminate the marker that makes a cast not be an lvalue. */
3721 if (field == 0 || !DECL_BIT_FIELD (field))
3723 /* An element that is not a bit-field. */
3725 register int fieldsize;
3726 /* Since this structure is static,
3727 we know the positions are constant. */
3728 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3732 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3734 * (TREE_INT_CST_LOW (index) - min_index));
3736 /* Output any buffered-up bit-fields preceding this element. */
3737 if (byte_buffer_in_use)
3739 ASM_OUTPUT_BYTE (asm_out_file, byte);
3741 byte_buffer_in_use = 0;
3744 /* Advance to offset of this element.
3745 Note no alignment needed in an array, since that is guaranteed
3746 if each element has the proper size. */
3747 if ((field != 0 || index != 0) && bitpos != total_bytes)
3749 if (!output_bytecode)
3750 assemble_zeros (bitpos - total_bytes);
3752 bc_emit_const_skip (bitpos - total_bytes);
3753 total_bytes = bitpos;
3756 /* Determine size this element should occupy. */
3759 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3761 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3763 /* This avoids overflow trouble. */
3764 tree size_tree = size_binop (CEIL_DIV_EXPR,
3766 size_int (BITS_PER_UNIT));
3767 fieldsize = TREE_INT_CST_LOW (size_tree);
3771 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3772 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3776 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3778 /* Output the element's initial value. */
3780 assemble_zeros (fieldsize);
3782 output_constant (val, fieldsize);
3784 /* Count its size. */
3785 total_bytes += fieldsize;
3787 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3788 error ("invalid initial value for member `%s'",
3789 IDENTIFIER_POINTER (DECL_NAME (field)));
3792 /* Element that is a bit-field. */
3794 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3796 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3799 val = integer_zero_node;
3801 /* If this field does not start in this (or, next) byte,
3803 if (next_offset / BITS_PER_UNIT != total_bytes)
3805 /* Output remnant of any bit field in previous bytes. */
3806 if (byte_buffer_in_use)
3808 ASM_OUTPUT_BYTE (asm_out_file, byte);
3810 byte_buffer_in_use = 0;
3813 /* If still not at proper byte, advance to there. */
3814 if (next_offset / BITS_PER_UNIT != total_bytes)
3816 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3817 total_bytes = next_offset / BITS_PER_UNIT;
3821 if (! byte_buffer_in_use)
3824 /* We must split the element into pieces that fall within
3825 separate bytes, and combine each byte with previous or
3826 following bit-fields. */
3828 /* next_offset is the offset n fbits from the beginning of
3829 the structure to the next bit of this element to be processed.
3830 end_offset is the offset of the first bit past the end of
3832 while (next_offset < end_offset)
3836 HOST_WIDE_INT value;
3837 int next_byte = next_offset / BITS_PER_UNIT;
3838 int next_bit = next_offset % BITS_PER_UNIT;
3840 /* Advance from byte to byte
3841 within this element when necessary. */
3842 while (next_byte != total_bytes)
3844 ASM_OUTPUT_BYTE (asm_out_file, byte);
3849 /* Number of bits we can process at once
3850 (all part of the same byte). */
3851 this_time = MIN (end_offset - next_offset,
3852 BITS_PER_UNIT - next_bit);
3853 if (BYTES_BIG_ENDIAN)
3855 /* On big-endian machine, take the most significant bits
3856 first (of the bits that are significant)
3857 and put them into bytes from the most significant end. */
3858 shift = end_offset - next_offset - this_time;
3859 /* Don't try to take a bunch of bits that cross
3860 the word boundary in the INTEGER_CST. */
3861 if (shift < HOST_BITS_PER_WIDE_INT
3862 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3864 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3865 shift = HOST_BITS_PER_WIDE_INT;
3868 /* Now get the bits from the appropriate constant word. */
3869 if (shift < HOST_BITS_PER_WIDE_INT)
3871 value = TREE_INT_CST_LOW (val);
3873 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3875 value = TREE_INT_CST_HIGH (val);
3876 shift -= HOST_BITS_PER_WIDE_INT;
3880 byte |= (((value >> shift)
3881 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3882 << (BITS_PER_UNIT - this_time - next_bit));
3886 /* On little-endian machines,
3887 take first the least significant bits of the value
3888 and pack them starting at the least significant
3889 bits of the bytes. */
3890 shift = (next_offset
3891 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3892 /* Don't try to take a bunch of bits that cross
3893 the word boundary in the INTEGER_CST. */
3894 if (shift < HOST_BITS_PER_WIDE_INT
3895 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3897 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3898 shift = HOST_BITS_PER_WIDE_INT;
3901 /* Now get the bits from the appropriate constant word. */
3902 if (shift < HOST_BITS_PER_INT)
3903 value = TREE_INT_CST_LOW (val);
3904 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3906 value = TREE_INT_CST_HIGH (val);
3907 shift -= HOST_BITS_PER_WIDE_INT;
3911 byte |= (((value >> shift)
3912 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3915 next_offset += this_time;
3916 byte_buffer_in_use = 1;
3920 if (byte_buffer_in_use)
3922 ASM_OUTPUT_BYTE (asm_out_file, byte);
3925 if (total_bytes < size)
3926 assemble_zeros (size - total_bytes);
3929 /* Support #pragma weak by default if WEAK_ASM_OP and ASM_OUTPUT_DEF
3931 #if !defined (HANDLE_PRAGMA_WEAK) && defined (WEAK_ASM_OP) && defined (ASM_OUTPUT_DEF)
3932 #define HANDLE_PRAGMA_WEAK 1
3935 #if defined (HANDLE_SYSV_PRAGMA) && defined (HANDLE_PRAGMA_WEAK)
3937 /* See c-pragma.c for an identical definition. */
3953 /* Output asm to handle ``#pragma weak'' */
3955 handle_pragma_weak (what, out_file, name, value)
3956 enum pragma_state what;
3960 if (what == ps_name || what == ps_value)
3962 struct weak_syms *weak =
3963 (struct weak_syms *)permalloc (sizeof (struct weak_syms));
3964 weak->next = weak_decls;
3965 weak->name = permalloc (strlen (name) + 1);
3966 strcpy (weak->name, name);
3968 if (what != ps_value)
3969 weak->value = NULL_PTR;
3973 weak->value = permalloc (strlen (value) + 1);
3974 strcpy (weak->value, value);
3979 else if (! (what == ps_done || what == ps_start))
3980 warning ("malformed `#pragma weak'");
3983 #endif /* HANDLE_SYSV_PRAGMA && HANDLE_PRAGMA_WEAK */
3985 /* Declare DECL to be a weak symbol. */
3991 if (! TREE_PUBLIC (decl))
3992 error_with_decl (decl, "weak declaration of `%s' must be public");
3994 handle_pragma_weak (ps_name, asm_out_file,
3995 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
3999 /* Emit any pending weak declarations. */
4004 #ifdef HANDLE_PRAGMA_WEAK
4005 if (HANDLE_PRAGMA_WEAK)
4007 struct weak_syms *t;
4008 for (t = weak_decls; t; t = t->next)
4010 fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
4012 if (output_bytecode)
4013 BC_OUTPUT_LABELREF (asm_out_file, t->name);
4015 ASM_OUTPUT_LABELREF (asm_out_file, t->name);
4017 fputc ('\n', asm_out_file);
4019 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4026 assemble_alias (decl, target)
4029 #ifdef ASM_OUTPUT_DEF
4032 make_decl_rtl (decl, (char*)0, 1);
4033 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4035 /* Make name accessible from other files, if appropriate. */
4037 if (TREE_PUBLIC (decl))
4039 if (output_bytecode)
4040 BC_GLOBALIZE_LABEL (asm_out_file, name);
4042 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4045 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4047 warning ("alias definitions not supported in this configuration");