1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92, 93, 1994 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This file handles generation of all the assembler code
22 *except* the instructions of a function.
23 This includes declarations of variables and their initial values.
25 We also output the assembler code for constants stored in memory
26 and are responsible for combining constants with the same value. */
30 /* #include <stab.h> */
37 #include "hard-reg-set.h"
45 #ifdef XCOFF_DEBUGGING_INFO
52 #define ASM_STABS_OP ".stabs"
55 /* This macro gets just the user-specified name
56 out of the string in a SYMBOL_REF. On most machines,
57 we discard the * if any and that's all. */
58 #ifndef STRIP_NAME_ENCODING
59 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
60 (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
63 /* File in which assembler code is being written. */
65 extern FILE *asm_out_file;
67 /* The (assembler) name of the first globally-visible object output. */
68 char *first_global_object_name;
70 extern struct obstack *current_obstack;
71 extern struct obstack *saveable_obstack;
72 extern struct obstack permanent_obstack;
73 #define obstack_chunk_alloc xmalloc
75 /* Number for making the label on the next
76 constant that is stored in memory. */
80 /* Number for making the label on the next
81 static variable internal to a function. */
85 /* Carry information from ASM_DECLARE_OBJECT_NAME
86 to ASM_FINISH_DECLARE_OBJECT. */
88 int size_directive_output;
90 /* The last decl for which assemble_variable was called,
91 if it did ASM_DECLARE_OBJECT_NAME.
92 If the last call to assemble_variable didn't do that,
95 tree last_assemble_variable_decl;
97 /* Nonzero if at least one function definition has been seen. */
98 static int function_defined;
100 extern FILE *asm_out_file;
102 static char *compare_constant_1 ();
103 static void record_constant_1 ();
104 static void output_constant_def_contents ();
105 static int contains_pointers_p ();
106 static void bc_output_ascii ();
108 void output_constant_pool ();
109 void assemble_name ();
110 int output_addressed_constants ();
111 void output_constant ();
112 void output_constructor ();
113 void output_byte_asm ();
114 void text_section ();
115 void readonly_data_section ();
116 void data_section ();
117 void named_section ();
118 static void bc_assemble_integer ();
120 #ifdef EXTRA_SECTIONS
121 static enum in_section {no_section, in_text, in_data, in_named, EXTRA_SECTIONS} in_section
124 static enum in_section {no_section, in_text, in_data, in_named} in_section
128 /* Return a non-zero value if DECL has a section attribute. */
129 #define IN_NAMED_SECTION(DECL) \
130 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
131 && DECL_SECTION_NAME (DECL) != NULL_TREE)
133 /* Text of section name when in_section == in_named. */
134 static char *in_named_name;
136 /* Define functions like text_section for any extra sections. */
137 #ifdef EXTRA_SECTION_FUNCTIONS
138 EXTRA_SECTION_FUNCTIONS
141 /* Tell assembler to switch to text section. */
146 if (in_section != in_text)
151 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
153 in_section = in_text;
157 /* Tell assembler to switch to data section. */
162 if (in_section != in_data)
168 if (flag_shared_data)
170 #ifdef SHARED_SECTION_ASM_OP
171 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
173 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
177 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
180 in_section = in_data;
184 /* Tell assembler to switch to read-only data section. This is normally
188 readonly_data_section ()
190 #ifdef READONLY_DATA_SECTION
191 READONLY_DATA_SECTION (); /* Note this can call data_section. */
197 /* Determine if we're in the text section. */
202 return in_section == in_text;
205 /* Tell assembler to change to named section. */
211 if (in_section != in_named || strcmp (name, in_named_name))
213 in_named_name = name;
214 in_section = in_named;
216 #ifdef ASM_OUTPUT_SECTION_NAME
217 ASM_OUTPUT_SECTION_NAME (asm_out_file, name);
219 /* Section attributes are not supported if this macro isn't provided -
220 some host formats don't support them at all. The front-end should
221 already have flagged this as an error. */
227 /* Create the rtl to represent a function, for a function definition.
228 DECL is a FUNCTION_DECL node which describes which function.
229 The rtl is stored into DECL. */
232 make_function_rtl (decl)
235 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
239 if (DECL_RTL (decl) == 0)
240 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
242 /* Record that at least one function has been defined. */
243 function_defined = 1;
247 /* Rename a nested function to avoid conflicts. */
248 if (decl_function_context (decl) != 0
249 && DECL_INITIAL (decl) != 0
250 && DECL_RTL (decl) == 0)
254 name = IDENTIFIER_POINTER (DECL_NAME (decl));
255 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
256 name = obstack_copy0 (saveable_obstack, label, strlen (label));
260 if (DECL_RTL (decl) == 0)
263 = gen_rtx (MEM, DECL_MODE (decl),
264 gen_rtx (SYMBOL_REF, Pmode, name));
266 /* Optionally set flags or add text to the name to record information
267 such as that it is a function name. If the name is changed, the macro
268 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
269 #ifdef ENCODE_SECTION_INFO
270 ENCODE_SECTION_INFO (decl);
274 /* Record at least one function has been defined. */
275 function_defined = 1;
278 /* Create the DECL_RTL for a declaration for a static or external
279 variable or static or external function.
280 ASMSPEC, if not 0, is the string which the user specified
281 as the assembler symbol name.
282 TOP_LEVEL is nonzero if this is a file-scope variable.
283 This is never called for PARM_DECLs. */
285 bc_make_decl_rtl (decl, asmspec, top_level)
290 register char *name = TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl));
292 if (DECL_RTL (decl) == 0)
294 /* Print an error message for register variables. */
295 if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
296 error ("function declared `register'");
297 else if (DECL_REGISTER (decl))
298 error ("global register variables not supported in the interpreter");
300 /* Handle ordinary static variables and functions. */
301 if (DECL_RTL (decl) == 0)
303 /* Can't use just the variable's own name for a variable
304 whose scope is less than the whole file.
305 Concatenate a distinguishing number. */
306 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
310 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
311 name = obstack_copy0 (saveable_obstack, label, strlen (label));
315 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
320 /* Given NAME, a putative register name, discard any customary prefixes. */
323 strip_reg_name (name)
326 #ifdef REGISTER_PREFIX
327 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
328 name += strlen (REGISTER_PREFIX);
330 if (name[0] == '%' || name[0] == '#')
335 /* Decode an `asm' spec for a declaration as a register name.
336 Return the register number, or -1 if nothing specified,
337 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
338 or -3 if ASMSPEC is `cc' and is not recognized,
339 or -4 if ASMSPEC is `memory' and is not recognized.
340 Accept an exact spelling or a decimal number.
341 Prefixes such as % are optional. */
344 decode_reg_name (asmspec)
351 /* Get rid of confusing prefixes. */
352 asmspec = strip_reg_name (asmspec);
354 /* Allow a decimal number as a "register name". */
355 for (i = strlen (asmspec) - 1; i >= 0; i--)
356 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
358 if (asmspec[0] != 0 && i < 0)
361 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
367 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
369 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
372 #ifdef ADDITIONAL_REGISTER_NAMES
374 static struct { char *name; int number; } table[]
375 = ADDITIONAL_REGISTER_NAMES;
377 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
378 if (! strcmp (asmspec, table[i].name))
379 return table[i].number;
381 #endif /* ADDITIONAL_REGISTER_NAMES */
383 if (!strcmp (asmspec, "memory"))
386 if (!strcmp (asmspec, "cc"))
395 /* Create the DECL_RTL for a declaration for a static or external variable
396 or static or external function.
397 ASMSPEC, if not 0, is the string which the user specified
398 as the assembler symbol name.
399 TOP_LEVEL is nonzero if this is a file-scope variable.
401 This is never called for PARM_DECL nodes. */
404 make_decl_rtl (decl, asmspec, top_level)
409 register char *name = 0;
414 bc_make_decl_rtl (decl, asmspec, top_level);
418 reg_number = decode_reg_name (asmspec);
420 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
421 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
423 if (reg_number == -2)
425 /* ASMSPEC is given, and not the name of a register. */
426 name = (char *) obstack_alloc (saveable_obstack,
427 strlen (asmspec) + 2);
429 strcpy (&name[1], asmspec);
432 /* For a duplicate declaration, we can be called twice on the
433 same DECL node. Don't discard the RTL already made. */
434 if (DECL_RTL (decl) == 0)
438 /* First detect errors in declaring global registers. */
439 if (DECL_REGISTER (decl) && reg_number == -1)
440 error_with_decl (decl,
441 "register name not specified for `%s'");
442 else if (DECL_REGISTER (decl) && reg_number < 0)
443 error_with_decl (decl,
444 "invalid register name for `%s'");
445 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
446 error_with_decl (decl,
447 "register name given for non-register variable `%s'");
448 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
449 error ("function declared `register'");
450 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
451 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
452 else if (DECL_REGISTER (decl)
453 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
454 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
455 /* Now handle properly declared static register variables. */
456 else if (DECL_REGISTER (decl))
459 #if 0 /* yylex should print the warning for this */
461 pedwarn ("ANSI C forbids global register variables");
463 if (DECL_INITIAL (decl) != 0 && top_level)
465 DECL_INITIAL (decl) = 0;
466 error ("global register variable has initial value");
468 if (fixed_regs[reg_number] == 0
469 && function_defined && top_level)
470 error ("global register variable follows a function definition");
471 if (TREE_THIS_VOLATILE (decl))
472 warning ("volatile register variables don't work as you might wish");
474 /* If the user specified one of the eliminables registers here,
475 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
476 confused with that register and be eliminated. Although this
477 usage is somewhat suspect, we nevertheless use the following
478 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
481 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
482 REGNO (DECL_RTL (decl)) = reg_number;
483 REG_USERVAR_P (DECL_RTL (decl)) = 1;
487 /* Make this register global, so not usable for anything
489 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
491 globalize_reg (reg_number + --nregs);
494 /* Specifying a section attribute on an uninitialized variable does not
495 (and cannot) cause it to be put in the given section. The linker
496 can only put initialized objects in specific sections, everything
497 else goes in bss for the linker to sort out later (otherwise the
498 linker would give a duplicate definition error for each compilation
499 unit that behaved thusly). So warn the user. */
500 else if (TREE_CODE (decl) == VAR_DECL
501 && DECL_SECTION_NAME (decl) != NULL_TREE
502 && DECL_INITIAL (decl) == NULL_TREE)
504 warning_with_decl (decl,
505 "section attribute ignored for uninitialized variable `%s'");
506 /* Remove the section name so subsequent declarations won't see it.
507 We are ignoring it, remember. */
508 DECL_SECTION_NAME (decl) = NULL_TREE;
511 /* Now handle ordinary static variables and functions (in memory).
512 Also handle vars declared register invalidly. */
513 if (DECL_RTL (decl) == 0)
515 /* Can't use just the variable's own name for a variable
516 whose scope is less than the whole file.
517 Concatenate a distinguishing number. */
518 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
522 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
523 name = obstack_copy0 (saveable_obstack, label, strlen (label));
530 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
531 gen_rtx (SYMBOL_REF, Pmode, name));
533 /* If this variable is to be treated as volatile, show its
534 tree node has side effects. If it has side effects, either
535 because of this test or from TREE_THIS_VOLATILE also
536 being set, show the MEM is volatile. */
537 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
538 && TREE_PUBLIC (decl))
539 TREE_SIDE_EFFECTS (decl) = 1;
540 if (TREE_SIDE_EFFECTS (decl))
541 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
543 if (TREE_READONLY (decl))
544 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
545 MEM_IN_STRUCT_P (DECL_RTL (decl))
546 = AGGREGATE_TYPE_P (TREE_TYPE (decl));
548 /* Optionally set flags or add text to the name to record information
549 such as that it is a function name.
550 If the name is changed, the macro ASM_OUTPUT_LABELREF
551 will have to know how to strip this information. */
552 #ifdef ENCODE_SECTION_INFO
553 ENCODE_SECTION_INFO (decl);
557 /* If the old RTL had the wrong mode, fix the mode. */
558 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
560 rtx rtl = DECL_RTL (decl);
561 PUT_MODE (rtl, DECL_MODE (decl));
565 /* Make the rtl for variable VAR be volatile.
566 Use this only for static variables. */
569 make_var_volatile (var)
572 if (GET_CODE (DECL_RTL (var)) != MEM)
575 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
578 /* Output alignment directive to align for constant expression EXP. */
581 assemble_constant_align (exp)
586 /* Align the location counter as required by EXP's data type. */
587 align = TYPE_ALIGN (TREE_TYPE (exp));
588 #ifdef CONSTANT_ALIGNMENT
589 align = CONSTANT_ALIGNMENT (exp, align);
592 if (align > BITS_PER_UNIT)
593 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
596 /* Output a string of literal assembler code
597 for an `asm' keyword used between functions. */
600 assemble_asm (string)
605 error ("asm statements not allowed in interpreter");
611 if (TREE_CODE (string) == ADDR_EXPR)
612 string = TREE_OPERAND (string, 0);
614 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
617 #if 0 /* This should no longer be needed, because
618 flag_gnu_linker should be 0 on these systems,
619 which should prevent any output
620 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
621 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
622 #ifndef ASM_OUTPUT_CONSTRUCTOR
623 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
625 #ifndef ASM_OUTPUT_DESTRUCTOR
626 #define ASM_OUTPUT_DESTRUCTOR(file, name)
631 /* Record an element in the table of global destructors.
632 How this is done depends on what sort of assembler and linker
635 NAME should be the name of a global function to be called
636 at exit time. This name is output using assemble_name. */
639 assemble_destructor (name)
642 #ifdef ASM_OUTPUT_DESTRUCTOR
643 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
647 /* Now tell GNU LD that this is part of the static destructor set. */
648 /* This code works for any machine provided you use GNU as/ld. */
649 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
650 assemble_name (asm_out_file, name);
651 fputc ('\n', asm_out_file);
656 /* Likewise for global constructors. */
659 assemble_constructor (name)
662 #ifdef ASM_OUTPUT_CONSTRUCTOR
663 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
667 /* Now tell GNU LD that this is part of the static constructor set. */
668 /* This code works for any machine provided you use GNU as/ld. */
669 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
670 assemble_name (asm_out_file, name);
671 fputc ('\n', asm_out_file);
676 /* Likewise for entries we want to record for garbage collection.
677 Garbage collection is still under development. */
680 assemble_gc_entry (name)
683 #ifdef ASM_OUTPUT_GC_ENTRY
684 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
688 /* Now tell GNU LD that this is part of the static constructor set. */
689 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
690 assemble_name (asm_out_file, name);
691 fputc ('\n', asm_out_file);
696 /* Output assembler code for the constant pool of a function and associated
697 with defining the name of the function. DECL describes the function.
698 NAME is the function's name. For the constant pool, we use the current
699 constant pool data. */
702 assemble_start_function (decl, fnname)
708 /* The following code does not need preprocessing in the assembler. */
712 output_constant_pool (fnname, decl);
714 if (IN_NAMED_SECTION (decl))
715 named_section (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)));
719 /* Tell assembler to move to target machine's alignment for functions. */
720 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
724 BC_OUTPUT_ALIGN (asm_out_file, align);
726 ASM_OUTPUT_ALIGN (asm_out_file, align);
729 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
730 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
733 #ifdef SDB_DEBUGGING_INFO
734 /* Output SDB definition of the function. */
735 if (write_symbols == SDB_DEBUG)
736 sdbout_mark_begin_function ();
739 #ifdef DBX_DEBUGGING_INFO
740 /* Output DBX definition of the function. */
741 if (write_symbols == DBX_DEBUG)
742 dbxout_begin_function (decl);
745 /* Make function name accessible from other files, if appropriate. */
747 if (TREE_PUBLIC (decl))
749 if (!first_global_object_name)
750 STRIP_NAME_ENCODING (first_global_object_name, fnname);
752 BC_GLOBALIZE_LABEL (asm_out_file, fnname);
754 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
757 /* Do any machine/system dependent processing of the function name */
758 #ifdef ASM_DECLARE_FUNCTION_NAME
759 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
761 /* Standard thing is just output label for the function. */
763 BC_OUTPUT_LABEL (asm_out_file, fnname);
765 ASM_OUTPUT_LABEL (asm_out_file, fnname);
766 #endif /* ASM_DECLARE_FUNCTION_NAME */
769 /* Output assembler code associated with defining the size of the
770 function. DECL describes the function. NAME is the function's name. */
773 assemble_end_function (decl, fnname)
777 #ifdef ASM_DECLARE_FUNCTION_SIZE
778 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
782 /* Assemble code to leave SIZE bytes of zeros. */
785 assemble_zeros (size)
790 bc_emit_const_skip (size);
794 #ifdef ASM_NO_SKIP_IN_TEXT
795 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
796 so we must output 0s explicitly in the text section. */
797 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
801 for (i = 0; i < size - 20; i += 20)
804 fprintf (asm_out_file,
805 "%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);
807 fprintf (asm_out_file,
808 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
814 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
816 fprintf (asm_out_file, "\tbyte 0");
819 for (; i < size; i++)
820 fprintf (asm_out_file, ",0");
821 fprintf (asm_out_file, "\n");
829 BC_OUTPUT_SKIP (asm_out_file, size);
831 ASM_OUTPUT_SKIP (asm_out_file, size);
835 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
838 assemble_align (align)
841 if (align > BITS_PER_UNIT)
842 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
845 /* Assemble a string constant with the specified C string as contents. */
848 assemble_string (p, size)
862 /* If the string is very long, split it up. */
866 int thissize = size - pos;
867 if (thissize > maximum)
871 bc_output_ascii (asm_out_file, p, thissize);
874 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
883 bc_output_ascii (file, p, size)
888 BC_OUTPUT_ASCII (file, p, size);
891 /* Assemble everything that is needed for a variable or function declaration.
892 Not used for automatic variables, and not used for function definitions.
893 Should not be called for variables of incomplete structure type.
895 TOP_LEVEL is nonzero if this variable has file scope.
896 AT_END is nonzero if this is the special handling, at end of compilation,
897 to define things that have had only tentative definitions.
898 DONT_OUTPUT_DATA if nonzero means don't actually output the
899 initial value (that will be done by the caller). */
902 assemble_variable (decl, top_level, at_end, dont_output_data)
911 enum in_section saved_in_section;
913 last_assemble_variable_decl = 0;
918 if (GET_CODE (DECL_RTL (decl)) == REG)
920 /* Do output symbol info for global register variables, but do nothing
923 if (TREE_ASM_WRITTEN (decl))
925 TREE_ASM_WRITTEN (decl) = 1;
927 if (!output_bytecode)
929 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
930 /* File-scope global variables are output here. */
931 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
933 dbxout_symbol (decl, 0);
935 #ifdef SDB_DEBUGGING_INFO
936 if (write_symbols == SDB_DEBUG && top_level
937 /* Leave initialized global vars for end of compilation;
938 see comment in compile_file. */
939 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
940 sdbout_symbol (decl, 0);
944 /* Don't output any DWARF debugging information for variables here.
945 In the case of local variables, the information for them is output
946 when we do our recursive traversal of the tree representation for
947 the entire containing function. In the case of file-scope variables,
948 we output information for all of them at the very end of compilation
949 while we are doing our final traversal of the chain of file-scope
955 /* Normally no need to say anything here for external references,
956 since assemble_external is called by the langauge-specific code
957 when a declaration is first seen. */
959 if (DECL_EXTERNAL (decl))
962 /* Output no assembler code for a function declaration.
963 Only definitions of functions output anything. */
965 if (TREE_CODE (decl) == FUNCTION_DECL)
968 /* If type was incomplete when the variable was declared,
969 see if it is complete now. */
971 if (DECL_SIZE (decl) == 0)
972 layout_decl (decl, 0);
974 /* Still incomplete => don't allocate it; treat the tentative defn
975 (which is what it must have been) as an `extern' reference. */
977 if (!dont_output_data && DECL_SIZE (decl) == 0)
979 error_with_file_and_line (DECL_SOURCE_FILE (decl),
980 DECL_SOURCE_LINE (decl),
981 "storage size of `%s' isn't known",
982 IDENTIFIER_POINTER (DECL_NAME (decl)));
986 /* The first declaration of a variable that comes through this function
987 decides whether it is global (in C, has external linkage)
988 or local (in C, has internal linkage). So do nothing more
989 if this function has already run. */
991 if (TREE_ASM_WRITTEN (decl))
994 TREE_ASM_WRITTEN (decl) = 1;
996 /* If storage size is erroneously variable, just continue.
997 Error message was already made. */
999 if (DECL_SIZE (decl))
1001 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1006 /* This is better than explicit arithmetic, since it avoids overflow. */
1007 size_tree = size_binop (CEIL_DIV_EXPR,
1008 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1010 if (TREE_INT_CST_HIGH (size_tree) != 0)
1012 error_with_decl (decl, "size of variable `%s' is too large");
1017 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1019 /* Handle uninitialized definitions. */
1021 /* ANSI specifies that a tentative definition which is not merged with
1022 a non-tentative definition behaves exactly like a definition with an
1023 initializer equal to zero. (Section 3.7.2)
1024 -fno-common gives strict ANSI behavior. Usually you don't want it.
1025 This matters only for variables with external linkage. */
1026 if ((! flag_no_common || ! TREE_PUBLIC (decl))
1027 && DECL_COMMON (decl)
1028 && ! dont_output_data
1029 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
1031 int size = TREE_INT_CST_LOW (size_tree);
1034 if (TREE_INT_CST_HIGH (size_tree) != 0)
1035 error_with_decl (decl, "size of variable `%s' is too large");
1036 /* Don't allocate zero bytes of common,
1037 since that means "undefined external" in the linker. */
1038 if (size == 0) rounded = 1;
1039 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1040 so that each uninitialized object starts on such a boundary. */
1041 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1042 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1043 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1045 #ifdef DBX_DEBUGGING_INFO
1046 /* File-scope global variables are output here. */
1047 if (write_symbols == DBX_DEBUG && top_level)
1048 dbxout_symbol (decl, 0);
1050 #ifdef SDB_DEBUGGING_INFO
1051 if (write_symbols == SDB_DEBUG && top_level
1052 /* Leave initialized global vars for end of compilation;
1053 see comment in compile_file. */
1054 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1055 sdbout_symbol (decl, 0);
1058 /* Don't output any DWARF debugging information for variables here.
1059 In the case of local variables, the information for them is output
1060 when we do our recursive traversal of the tree representation for
1061 the entire containing function. In the case of file-scope variables,
1062 we output information for all of them at the very end of compilation
1063 while we are doing our final traversal of the chain of file-scope
1067 if (flag_shared_data)
1070 if (TREE_PUBLIC (decl))
1072 #ifdef ASM_OUTPUT_SHARED_COMMON
1073 if (flag_shared_data)
1074 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1077 if (output_bytecode)
1079 BC_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1083 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1084 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1087 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1093 #ifdef ASM_OUTPUT_SHARED_LOCAL
1094 if (flag_shared_data)
1095 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1098 if (output_bytecode)
1100 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1104 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1105 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1108 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1115 /* Handle initialized definitions. */
1117 /* First make the assembler name(s) global if appropriate. */
1118 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1120 if (!first_global_object_name)
1121 STRIP_NAME_ENCODING(first_global_object_name, name);
1122 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1125 for (d = equivalents; d; d = TREE_CHAIN (d))
1127 tree e = TREE_VALUE (d);
1128 if (TREE_PUBLIC (e) && DECL_NAME (e))
1129 ASM_GLOBALIZE_LABEL (asm_out_file,
1130 XSTR (XEXP (DECL_RTL (e), 0), 0));
1134 /* Output any data that we will need to use the address of. */
1135 if (DECL_INITIAL (decl) == error_mark_node)
1136 reloc = contains_pointers_p (TREE_TYPE (decl));
1137 else if (DECL_INITIAL (decl))
1138 reloc = output_addressed_constants (DECL_INITIAL (decl));
1140 /* Switch to the proper section for this data. */
1141 if (IN_NAMED_SECTION (decl))
1142 named_section (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)));
1145 /* C++ can have const variables that get initialized from constructors,
1146 and thus can not be in a readonly section. We prevent this by
1147 verifying that the initial value is constant for objects put in a
1150 error_mark_node is used by the C front end to indicate that the
1151 initializer has not been seen yet. In this case, we assume that
1152 the initializer must be constant. */
1153 #ifdef SELECT_SECTION
1154 SELECT_SECTION (decl, reloc);
1156 if (TREE_READONLY (decl)
1157 && ! TREE_THIS_VOLATILE (decl)
1158 && DECL_INITIAL (decl)
1159 && (DECL_INITIAL (decl) == error_mark_node
1160 || TREE_CONSTANT (DECL_INITIAL (decl)))
1161 && ! (flag_pic && reloc))
1162 readonly_data_section ();
1168 /* dbxout.c needs to know this. */
1169 if (in_text_section ())
1170 DECL_IN_TEXT_SECTION (decl) = 1;
1172 /* Record current section so we can restore it if dbxout.c clobbers it. */
1173 saved_in_section = in_section;
1175 /* Output the dbx info now that we have chosen the section. */
1177 #ifdef DBX_DEBUGGING_INFO
1178 /* File-scope global variables are output here. */
1179 if (write_symbols == DBX_DEBUG && top_level)
1180 dbxout_symbol (decl, 0);
1182 #ifdef SDB_DEBUGGING_INFO
1183 if (write_symbols == SDB_DEBUG && top_level
1184 /* Leave initialized global vars for end of compilation;
1185 see comment in compile_file. */
1186 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1187 sdbout_symbol (decl, 0);
1190 /* Don't output any DWARF debugging information for variables here.
1191 In the case of local variables, the information for them is output
1192 when we do our recursive traversal of the tree representation for
1193 the entire containing function. In the case of file-scope variables,
1194 we output information for all of them at the very end of compilation
1195 while we are doing our final traversal of the chain of file-scope
1198 /* If the debugging output changed sections, reselect the section
1199 that's supposed to be selected. */
1200 if (in_section != saved_in_section)
1202 /* Switch to the proper section for this data. */
1203 #ifdef SELECT_SECTION
1204 SELECT_SECTION (decl, reloc);
1206 if (TREE_READONLY (decl)
1207 && ! TREE_THIS_VOLATILE (decl)
1208 && DECL_INITIAL (decl)
1209 && (DECL_INITIAL (decl) == error_mark_node
1210 || TREE_CONSTANT (DECL_INITIAL (decl)))
1211 && ! (flag_pic && reloc))
1212 readonly_data_section ();
1218 /* Compute and output the alignment of this data. */
1220 align = DECL_ALIGN (decl);
1221 /* In the case for initialing an array whose length isn't specified,
1222 where we have not yet been able to do the layout,
1223 figure out the proper alignment now. */
1224 if (dont_output_data && DECL_SIZE (decl) == 0
1225 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1226 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1228 /* Some object file formats have a maximum alignment which they support.
1229 In particular, a.out format supports a maximum alignment of 4. */
1230 #ifndef MAX_OFILE_ALIGNMENT
1231 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1233 if (align > MAX_OFILE_ALIGNMENT)
1235 warning_with_decl (decl,
1236 "alignment of `%s' is greater than maximum object file alignment");
1237 align = MAX_OFILE_ALIGNMENT;
1239 #ifdef DATA_ALIGNMENT
1240 /* On some machines, it is good to increase alignment sometimes. */
1241 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1243 #ifdef CONSTANT_ALIGNMENT
1244 if (DECL_INITIAL (decl))
1245 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1248 /* Reset the alignment in case we have made it tighter, so we can benefit
1249 from it in get_pointer_alignment. */
1250 DECL_ALIGN (decl) = align;
1252 if (align > BITS_PER_UNIT)
1254 if (output_bytecode)
1255 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1257 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1260 /* Do any machine/system dependent processing of the object. */
1261 #ifdef ASM_DECLARE_OBJECT_NAME
1262 last_assemble_variable_decl = decl;
1263 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1265 /* Standard thing is just output label for the object. */
1266 if (output_bytecode)
1267 BC_OUTPUT_LABEL (asm_out_file, name);
1269 ASM_OUTPUT_LABEL (asm_out_file, name);
1270 #endif /* ASM_DECLARE_OBJECT_NAME */
1272 if (!dont_output_data)
1274 if (DECL_INITIAL (decl))
1275 /* Output the actual data. */
1276 output_constant (DECL_INITIAL (decl),
1277 int_size_in_bytes (TREE_TYPE (decl)));
1279 /* Leave space for it. */
1280 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1284 #ifdef XCOFF_DEBUGGING_INFO
1285 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1286 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1287 and `aa' hasn't been output yet, the assembler generates a stab entry with
1288 a value of zero, in addition to creating an unnecessary external entry
1289 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1291 /* File-scope global variables are output here. */
1292 if (write_symbols == XCOFF_DEBUG && top_level)
1294 saved_in_section = in_section;
1296 dbxout_symbol (decl, 0);
1298 if (in_section != saved_in_section)
1300 /* Switch to the proper section for this data. */
1301 #ifdef SELECT_SECTION
1302 SELECT_SECTION (decl, reloc);
1304 if (TREE_READONLY (decl)
1305 && ! TREE_THIS_VOLATILE (decl)
1306 && DECL_INITIAL (decl)
1307 && (DECL_INITIAL (decl) == error_mark_node
1308 || TREE_CONSTANT (DECL_INITIAL (decl)))
1309 && ! (flag_pic && reloc))
1310 readonly_data_section ();
1317 /* There must be a statement after a label. */
1322 /* Return 1 if type TYPE contains any pointers. */
1325 contains_pointers_p (type)
1328 switch (TREE_CODE (type))
1331 case REFERENCE_TYPE:
1332 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1333 so I'll play safe and return 1. */
1339 case QUAL_UNION_TYPE:
1342 /* For a type that has fields, see if the fields have pointers. */
1343 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1344 if (TREE_CODE (fields) == FIELD_DECL
1345 && contains_pointers_p (TREE_TYPE (fields)))
1351 /* An array type contains pointers if its element type does. */
1352 return contains_pointers_p (TREE_TYPE (type));
1359 /* Output text storage for constructor CONSTR. Returns rtx of
1363 bc_output_constructor (constr)
1368 /* Must always be a literal; non-literal constructors are handled
1371 if (!TREE_CONSTANT (constr))
1378 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1380 BC_OUTPUT_ALIGN (asm_out_file, i);
1383 output_constant (constr, int_size_in_bytes (TREE_TYPE (constr)));
1387 /* Create storage for constructor CONSTR. */
1390 bc_output_data_constructor (constr)
1395 /* Put in data section */
1399 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1401 BC_OUTPUT_ALIGN (asm_out_file, i);
1403 /* The constructor is filled in at runtime. */
1404 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1408 /* Output something to declare an external symbol to the assembler.
1409 (Most assemblers don't need this, so we normally output nothing.)
1410 Do nothing if DECL is not external. */
1413 assemble_external (decl)
1416 if (output_bytecode)
1419 #ifdef ASM_OUTPUT_EXTERNAL
1420 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1421 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1423 rtx rtl = DECL_RTL (decl);
1425 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1426 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1428 /* Some systems do require some output. */
1429 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1430 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1436 /* Similar, for calling a library function FUN. */
1439 assemble_external_libcall (fun)
1442 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1443 if (!output_bytecode)
1445 /* Declare library function name external when first used, if nec. */
1446 if (! SYMBOL_REF_USED (fun))
1448 SYMBOL_REF_USED (fun) = 1;
1449 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1455 /* Declare the label NAME global. */
1458 assemble_global (name)
1461 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1464 /* Assemble a label named NAME. */
1467 assemble_label (name)
1470 if (output_bytecode)
1471 BC_OUTPUT_LABEL (asm_out_file, name);
1473 ASM_OUTPUT_LABEL (asm_out_file, name);
1476 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1477 If NAME starts with a *, the rest of NAME is output verbatim.
1478 Otherwise NAME is transformed in an implementation-defined way
1479 (usually by the addition of an underscore).
1480 Many macros in the tm file are defined to call this function. */
1483 assemble_name (file, name)
1489 STRIP_NAME_ENCODING (real_name, name);
1490 TREE_SYMBOL_REFERENCED (get_identifier (real_name)) = 1;
1494 if (output_bytecode)
1495 bc_emit_labelref (name);
1497 fputs (&name[1], file);
1501 if (output_bytecode)
1502 BC_OUTPUT_LABELREF (file, name);
1504 ASM_OUTPUT_LABELREF (file, name);
1508 /* Allocate SIZE bytes writable static space with a gensym name
1509 and return an RTX to refer to its address. */
1512 assemble_static_space (size)
1518 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1519 so that each uninitialized object starts on such a boundary. */
1520 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1521 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1522 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1525 if (flag_shared_data)
1529 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1532 namestring = (char *) obstack_alloc (saveable_obstack,
1534 strcpy (namestring, name);
1536 if (output_bytecode)
1537 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1539 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1541 if (output_bytecode)
1543 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1547 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1548 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1550 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1556 /* Assemble the static constant template for function entry trampolines.
1557 This is done at most once per compilation.
1558 Returns an RTX for the address of the template. */
1561 assemble_trampoline_template ()
1567 /* Shouldn't get here */
1568 if (output_bytecode)
1571 /* By default, put trampoline templates in read-only data section. */
1573 #ifdef TRAMPOLINE_SECTION
1574 TRAMPOLINE_SECTION ();
1576 readonly_data_section ();
1579 /* Write the assembler code to define one. */
1580 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1582 ASM_OUTPUT_ALIGN (asm_out_file, align);
1584 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1585 TRAMPOLINE_TEMPLATE (asm_out_file);
1587 /* Record the rtl to refer to it. */
1588 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1590 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1591 return gen_rtx (SYMBOL_REF, Pmode, name);
1594 /* Assemble the integer constant X into an object of SIZE bytes.
1595 X must be either a CONST_INT or CONST_DOUBLE.
1597 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1598 non-zero, abort if we can't output the constant. */
1601 assemble_integer (x, size, force)
1606 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1607 ASM_OUTPUT... macros. */
1611 #ifdef ASM_OUTPUT_CHAR
1613 ASM_OUTPUT_CHAR (asm_out_file, x);
1617 #ifdef ASM_OUTPUT_SHORT
1619 ASM_OUTPUT_SHORT (asm_out_file, x);
1623 #ifdef ASM_OUTPUT_INT
1625 ASM_OUTPUT_INT (asm_out_file, x);
1629 #ifdef ASM_OUTPUT_DOUBLE_INT
1631 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1635 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1637 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1642 /* If we couldn't do it that way, there are two other possibilities: First,
1643 if the machine can output an explicit byte and this is a 1 byte constant,
1644 we can use ASM_OUTPUT_BYTE. */
1646 #ifdef ASM_OUTPUT_BYTE
1647 if (size == 1 && GET_CODE (x) == CONST_INT)
1649 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1654 /* Finally, if SIZE is larger than a single word, try to output the constant
1655 one word at a time. */
1657 if (size > UNITS_PER_WORD)
1660 enum machine_mode mode
1661 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1664 for (i = 0; i < size / UNITS_PER_WORD; i++)
1666 word = operand_subword (x, i, 0, mode);
1671 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1675 if (i == size / UNITS_PER_WORD)
1677 /* If we output at least one word and then could not finish,
1678 there is no valid way to continue. */
1689 /* Assemble the floating-point constant D into an object of size MODE. */
1692 assemble_real (d, mode)
1694 enum machine_mode mode;
1696 jmp_buf output_constant_handler;
1698 if (setjmp (output_constant_handler))
1700 error ("floating point trap outputting a constant");
1701 #ifdef REAL_IS_NOT_DOUBLE
1702 bzero ((char *) &d, sizeof d);
1709 set_float_handler (output_constant_handler);
1713 #ifdef ASM_OUTPUT_BYTE_FLOAT
1715 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1718 #ifdef ASM_OUTPUT_SHORT_FLOAT
1720 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1723 #ifdef ASM_OUTPUT_FLOAT
1725 ASM_OUTPUT_FLOAT (asm_out_file, d);
1729 #ifdef ASM_OUTPUT_DOUBLE
1731 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1735 #ifdef ASM_OUTPUT_LONG_DOUBLE
1738 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1746 set_float_handler (NULL_PTR);
1749 /* Here we combine duplicate floating constants to make
1750 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1752 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1753 They are chained through the CONST_DOUBLE_CHAIN.
1754 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1755 In that case, CONST_DOUBLE_MEM is either a MEM,
1756 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1758 (CONST_DOUBLE_MEM is used only for top-level functions.
1759 See force_const_mem for explanation.) */
1761 static rtx const_double_chain;
1763 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1764 For an integer, I0 is the low-order word and I1 is the high-order word.
1765 For a real number, I0 is the word with the low address
1766 and I1 is the word with the high address. */
1769 immed_double_const (i0, i1, mode)
1770 HOST_WIDE_INT i0, i1;
1771 enum machine_mode mode;
1774 int in_current_obstack;
1776 if (GET_MODE_CLASS (mode) == MODE_INT
1777 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1779 /* We clear out all bits that don't belong in MODE, unless they and our
1780 sign bit are all one. So we get either a reasonable negative value
1781 or a reasonable unsigned value for this mode. */
1782 int width = GET_MODE_BITSIZE (mode);
1783 if (width < HOST_BITS_PER_WIDE_INT
1784 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1785 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1786 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1787 else if (width == HOST_BITS_PER_WIDE_INT
1788 && ! (i1 == ~0 && i0 < 0))
1790 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1791 /* We cannot represent this value as a constant. */
1794 /* If this would be an entire word for the target, but is not for
1795 the host, then sign-extend on the host so that the number will look
1796 the same way on the host that it would on the target.
1798 For example, when building a 64 bit alpha hosted 32 bit sparc
1799 targeted compiler, then we want the 32 bit unsigned value -1 to be
1800 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1801 The later confuses the sparc backend. */
1803 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1804 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1805 i0 |= ((HOST_WIDE_INT) (-1) << width);
1807 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1809 ??? Strictly speaking, this is wrong if we create a CONST_INT
1810 for a large unsigned constant with the size of MODE being
1811 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1812 wider mode. In that case we will mis-interpret it as a negative
1815 Unfortunately, the only alternative is to make a CONST_DOUBLE
1816 for any constant in any mode if it is an unsigned constant larger
1817 than the maximum signed integer in an int on the host. However,
1818 doing this will break everyone that always expects to see a CONST_INT
1819 for SImode and smaller.
1821 We have always been making CONST_INTs in this case, so nothing new
1824 if (width <= HOST_BITS_PER_WIDE_INT)
1825 i1 = (i0 < 0) ? ~0 : 0;
1827 /* If this integer fits in one word, return a CONST_INT. */
1828 if ((i1 == 0 && i0 >= 0)
1829 || (i1 == ~0 && i0 < 0))
1830 return GEN_INT (i0);
1832 /* We use VOIDmode for integers. */
1836 /* Search the chain for an existing CONST_DOUBLE with the right value.
1837 If one is found, return it. */
1839 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1840 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1841 && GET_MODE (r) == mode)
1844 /* No; make a new one and add it to the chain.
1846 We may be called by an optimizer which may be discarding any memory
1847 allocated during its processing (such as combine and loop). However,
1848 we will be leaving this constant on the chain, so we cannot tolerate
1849 freed memory. So switch to saveable_obstack for this allocation
1850 and then switch back if we were in current_obstack. */
1852 push_obstacks_nochange ();
1853 rtl_in_saveable_obstack ();
1854 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1857 /* Don't touch const_double_chain in nested function; see force_const_mem.
1858 Also, don't touch it if not inside any function. */
1859 if (outer_function_chain == 0 && current_function_decl != 0)
1861 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1862 const_double_chain = r;
1865 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1866 Actual use of mem-slot is only through force_const_mem. */
1868 CONST_DOUBLE_MEM (r) = const0_rtx;
1873 /* Return a CONST_DOUBLE for a specified `double' value
1874 and machine mode. */
1877 immed_real_const_1 (d, mode)
1879 enum machine_mode mode;
1881 union real_extract u;
1883 int in_current_obstack;
1885 /* Get the desired `double' value as a sequence of ints
1886 since that is how they are stored in a CONST_DOUBLE. */
1890 /* Detect special cases. */
1892 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1893 if (!bcmp ((char *) &dconst0, (char *) &d, sizeof d))
1894 return CONST0_RTX (mode);
1895 /* Check for NaN first, because some ports (specifically the i386) do not
1896 emit correct ieee-fp code by default, and thus will generate a core
1897 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1898 does a floating point comparison. */
1899 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1900 return CONST1_RTX (mode);
1902 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1903 return immed_double_const (u.i[0], u.i[1], mode);
1905 /* The rest of this function handles the case where
1906 a float value requires more than 2 ints of space.
1907 It will be deleted as dead code on machines that don't need it. */
1909 /* Search the chain for an existing CONST_DOUBLE with the right value.
1910 If one is found, return it. */
1912 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1913 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
1914 && GET_MODE (r) == mode)
1917 /* No; make a new one and add it to the chain.
1919 We may be called by an optimizer which may be discarding any memory
1920 allocated during its processing (such as combine and loop). However,
1921 we will be leaving this constant on the chain, so we cannot tolerate
1922 freed memory. So switch to saveable_obstack for this allocation
1923 and then switch back if we were in current_obstack. */
1925 push_obstacks_nochange ();
1926 rtl_in_saveable_obstack ();
1927 r = rtx_alloc (CONST_DOUBLE);
1929 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
1932 /* Don't touch const_double_chain in nested function; see force_const_mem.
1933 Also, don't touch it if not inside any function. */
1934 if (outer_function_chain == 0 && current_function_decl != 0)
1936 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1937 const_double_chain = r;
1940 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1941 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1942 is only through force_const_mem. */
1944 CONST_DOUBLE_MEM (r) = const0_rtx;
1949 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1950 which must be a REAL_CST tree node. */
1953 immed_real_const (exp)
1956 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1959 /* At the end of a function, forget the memory-constants
1960 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1961 Also clear out real_constant_chain and clear out all the chain-pointers. */
1964 clear_const_double_mem ()
1966 register rtx r, next;
1968 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1969 See force_const_mem for explanation. */
1970 if (outer_function_chain != 0)
1973 for (r = const_double_chain; r; r = next)
1975 next = CONST_DOUBLE_CHAIN (r);
1976 CONST_DOUBLE_CHAIN (r) = 0;
1977 CONST_DOUBLE_MEM (r) = cc0_rtx;
1979 const_double_chain = 0;
1982 /* Given an expression EXP with a constant value,
1983 reduce it to the sum of an assembler symbol and an integer.
1984 Store them both in the structure *VALUE.
1985 Abort if EXP does not reduce. */
1990 HOST_WIDE_INT offset;
1994 decode_addr_const (exp, value)
1996 struct addr_const *value;
1998 register tree target = TREE_OPERAND (exp, 0);
1999 register int offset = 0;
2004 if (TREE_CODE (target) == COMPONENT_REF
2005 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2008 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2009 target = TREE_OPERAND (target, 0);
2011 else if (TREE_CODE (target) == ARRAY_REF)
2013 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2014 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2016 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2017 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2019 target = TREE_OPERAND (target, 0);
2025 switch (TREE_CODE (target))
2029 x = DECL_RTL (target);
2033 if (output_bytecode)
2034 /* FIXME: this may not be correct, check it */
2035 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
2037 x = gen_rtx (MEM, FUNCTION_MODE,
2038 gen_rtx (LABEL_REF, VOIDmode,
2039 label_rtx (TREE_OPERAND (exp, 0))));
2046 x = TREE_CST_RTL (target);
2053 if (!output_bytecode)
2055 if (GET_CODE (x) != MEM)
2061 value->offset = offset;
2064 /* Uniquize all constants that appear in memory.
2065 Each constant in memory thus far output is recorded
2066 in `const_hash_table' with a `struct constant_descriptor'
2067 that contains a polish representation of the value of
2070 We cannot store the trees in the hash table
2071 because the trees may be temporary. */
2073 struct constant_descriptor
2075 struct constant_descriptor *next;
2081 #define MAX_HASH_TABLE 1009
2082 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2084 /* Compute a hash code for a constant expression. */
2091 register int len, hi, i;
2092 register enum tree_code code = TREE_CODE (exp);
2094 if (code == INTEGER_CST)
2096 p = (char *) &TREE_INT_CST_LOW (exp);
2097 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2099 else if (code == REAL_CST)
2101 p = (char *) &TREE_REAL_CST (exp);
2102 len = sizeof TREE_REAL_CST (exp);
2104 else if (code == STRING_CST)
2105 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2106 else if (code == COMPLEX_CST)
2107 return const_hash (TREE_REALPART (exp)) * 5
2108 + const_hash (TREE_IMAGPART (exp));
2109 else if (code == CONSTRUCTOR)
2113 /* For record type, include the type in the hashing.
2114 We do not do so for array types
2115 because (1) the sizes of the elements are sufficient
2116 and (2) distinct array types can have the same constructor.
2117 Instead, we include the array size because the constructor could
2119 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2120 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2123 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2124 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2126 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2127 if (TREE_VALUE (link))
2128 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2132 else if (code == ADDR_EXPR)
2134 struct addr_const value;
2135 decode_addr_const (exp, &value);
2136 if (GET_CODE (value.base) == SYMBOL_REF)
2138 /* Don't hash the address of the SYMBOL_REF;
2139 only use the offset and the symbol name. */
2141 p = XSTR (value.base, 0);
2142 for (i = 0; p[i] != 0; i++)
2143 hi = ((hi * 613) + (unsigned)(p[i]));
2145 else if (GET_CODE (value.base) == LABEL_REF)
2146 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2148 hi &= (1 << HASHBITS) - 1;
2149 hi %= MAX_HASH_TABLE;
2152 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2153 return const_hash (TREE_OPERAND (exp, 0)) * 9
2154 + const_hash (TREE_OPERAND (exp, 1));
2155 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2156 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2158 /* Compute hashing function */
2160 for (i = 0; i < len; i++)
2161 hi = ((hi * 613) + (unsigned)(p[i]));
2163 hi &= (1 << HASHBITS) - 1;
2164 hi %= MAX_HASH_TABLE;
2168 /* Compare a constant expression EXP with a constant-descriptor DESC.
2169 Return 1 if DESC describes a constant with the same value as EXP. */
2172 compare_constant (exp, desc)
2174 struct constant_descriptor *desc;
2176 return 0 != compare_constant_1 (exp, desc->contents);
2179 /* Compare constant expression EXP with a substring P of a constant descriptor.
2180 If they match, return a pointer to the end of the substring matched.
2181 If they do not match, return 0.
2183 Since descriptors are written in polish prefix notation,
2184 this function can be used recursively to test one operand of EXP
2185 against a subdescriptor, and if it succeeds it returns the
2186 address of the subdescriptor for the next operand. */
2189 compare_constant_1 (exp, p)
2193 register char *strp;
2195 register enum tree_code code = TREE_CODE (exp);
2197 if (code != (enum tree_code) *p++)
2200 if (code == INTEGER_CST)
2202 /* Integer constants are the same only if the same width of type. */
2203 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2205 strp = (char *) &TREE_INT_CST_LOW (exp);
2206 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2208 else if (code == REAL_CST)
2210 /* Real constants are the same only if the same width of type. */
2211 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2213 strp = (char *) &TREE_REAL_CST (exp);
2214 len = sizeof TREE_REAL_CST (exp);
2216 else if (code == STRING_CST)
2218 if (flag_writable_strings)
2220 strp = TREE_STRING_POINTER (exp);
2221 len = TREE_STRING_LENGTH (exp);
2222 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2223 sizeof TREE_STRING_LENGTH (exp)))
2225 p += sizeof TREE_STRING_LENGTH (exp);
2227 else if (code == COMPLEX_CST)
2229 p = compare_constant_1 (TREE_REALPART (exp), p);
2230 if (p == 0) return 0;
2231 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2234 else if (code == CONSTRUCTOR)
2237 int length = list_length (CONSTRUCTOR_ELTS (exp));
2240 if (bcmp ((char *) &length, p, sizeof length))
2244 /* For record constructors, insist that the types match.
2245 For arrays, just verify both constructors are for arrays. */
2246 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2247 type = TREE_TYPE (exp);
2250 if (bcmp ((char *) &type, p, sizeof type))
2254 /* For arrays, insist that the size in bytes match. */
2255 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2257 int size = int_size_in_bytes (TREE_TYPE (exp));
2258 if (bcmp ((char *) &size, p, sizeof size))
2263 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2265 if (TREE_VALUE (link))
2267 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2274 if (bcmp ((char *) &zero, p, sizeof zero))
2282 else if (code == ADDR_EXPR)
2284 struct addr_const value;
2285 decode_addr_const (exp, &value);
2286 strp = (char *) &value.offset;
2287 len = sizeof value.offset;
2288 /* Compare the offset. */
2290 if (*p++ != *strp++)
2292 /* Compare symbol name. */
2293 strp = XSTR (value.base, 0);
2294 len = strlen (strp) + 1;
2296 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2298 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2299 if (p == 0) return 0;
2300 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2303 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2305 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2309 /* Compare constant contents. */
2311 if (*p++ != *strp++)
2317 /* Construct a constant descriptor for the expression EXP.
2318 It is up to the caller to enter the descriptor in the hash table. */
2320 static struct constant_descriptor *
2321 record_constant (exp)
2324 struct constant_descriptor *next = 0;
2327 /* Make a struct constant_descriptor. The first two pointers will
2328 be filled in later. Here we just leave space for them. */
2330 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2331 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2332 record_constant_1 (exp);
2333 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2336 /* Add a description of constant expression EXP
2337 to the object growing in `permanent_obstack'.
2338 No need to return its address; the caller will get that
2339 from the obstack when the object is complete. */
2342 record_constant_1 (exp)
2345 register char *strp;
2347 register enum tree_code code = TREE_CODE (exp);
2349 obstack_1grow (&permanent_obstack, (unsigned int) code);
2351 if (code == INTEGER_CST)
2353 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2354 strp = (char *) &TREE_INT_CST_LOW (exp);
2355 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2357 else if (code == REAL_CST)
2359 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2360 strp = (char *) &TREE_REAL_CST (exp);
2361 len = sizeof TREE_REAL_CST (exp);
2363 else if (code == STRING_CST)
2365 if (flag_writable_strings)
2367 strp = TREE_STRING_POINTER (exp);
2368 len = TREE_STRING_LENGTH (exp);
2369 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2370 sizeof TREE_STRING_LENGTH (exp));
2372 else if (code == COMPLEX_CST)
2374 record_constant_1 (TREE_REALPART (exp));
2375 record_constant_1 (TREE_IMAGPART (exp));
2378 else if (code == CONSTRUCTOR)
2381 int length = list_length (CONSTRUCTOR_ELTS (exp));
2384 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2386 /* For record constructors, insist that the types match.
2387 For arrays, just verify both constructors are for arrays. */
2388 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2389 type = TREE_TYPE (exp);
2392 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2394 /* For arrays, insist that the size in bytes match. */
2395 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2397 int size = int_size_in_bytes (TREE_TYPE (exp));
2398 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2401 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2403 if (TREE_VALUE (link))
2404 record_constant_1 (TREE_VALUE (link));
2409 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
2415 else if (code == ADDR_EXPR)
2417 struct addr_const value;
2418 decode_addr_const (exp, &value);
2419 /* Record the offset. */
2420 obstack_grow (&permanent_obstack,
2421 (char *) &value.offset, sizeof value.offset);
2422 /* Record the symbol name. */
2423 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2424 strlen (XSTR (value.base, 0)) + 1);
2427 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2429 record_constant_1 (TREE_OPERAND (exp, 0));
2430 record_constant_1 (TREE_OPERAND (exp, 1));
2433 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2435 record_constant_1 (TREE_OPERAND (exp, 0));
2439 /* Record constant contents. */
2440 obstack_grow (&permanent_obstack, strp, len);
2443 /* Record a list of constant expressions that were passed to
2444 output_constant_def but that could not be output right away. */
2446 struct deferred_constant
2448 struct deferred_constant *next;
2454 static struct deferred_constant *deferred_constants;
2456 /* Nonzero means defer output of addressed subconstants
2457 (i.e., those for which output_constant_def is called.) */
2458 static int defer_addressed_constants_flag;
2460 /* Start deferring output of subconstants. */
2463 defer_addressed_constants ()
2465 defer_addressed_constants_flag++;
2468 /* Stop deferring output of subconstants,
2469 and output now all those that have been deferred. */
2472 output_deferred_addressed_constants ()
2474 struct deferred_constant *p, *next;
2476 defer_addressed_constants_flag--;
2478 if (defer_addressed_constants_flag > 0)
2481 for (p = deferred_constants; p; p = next)
2483 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2488 deferred_constants = 0;
2491 /* Make a copy of the whole tree structure for a constant.
2492 This handles the same types of nodes that compare_constant
2493 and record_constant handle. */
2499 switch (TREE_CODE (exp))
2505 /* For ADDR_EXPR, we do not want to copy the decl
2506 whose address is requested. */
2507 return copy_node (exp);
2510 return build_complex (copy_constant (TREE_REALPART (exp)),
2511 copy_constant (TREE_IMAGPART (exp)));
2515 return build (TREE_CODE (exp), TREE_TYPE (exp),
2516 copy_constant (TREE_OPERAND (exp, 0)),
2517 copy_constant (TREE_OPERAND (exp, 1)));
2521 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2522 copy_constant (TREE_OPERAND (exp, 0)));
2526 tree copy = copy_node (exp);
2527 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2530 CONSTRUCTOR_ELTS (copy) = list;
2531 for (tail = list; tail; tail = TREE_CHAIN (tail))
2532 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2542 /* Return an rtx representing a reference to constant data in memory
2543 for the constant expression EXP.
2545 If assembler code for such a constant has already been output,
2546 return an rtx to refer to it.
2547 Otherwise, output such a constant in memory (or defer it for later)
2548 and generate an rtx for it.
2550 The TREE_CST_RTL of EXP is set up to point to that rtx.
2551 The const_hash_table records which constants already have label strings. */
2554 output_constant_def (exp)
2558 register struct constant_descriptor *desc;
2564 if (TREE_CODE (exp) == INTEGER_CST)
2565 abort (); /* No TREE_CST_RTL slot in these. */
2567 if (TREE_CST_RTL (exp))
2568 return TREE_CST_RTL (exp);
2570 /* Make sure any other constants whose addresses appear in EXP
2571 are assigned label numbers. */
2573 reloc = output_addressed_constants (exp);
2575 /* Compute hash code of EXP. Search the descriptors for that hash code
2576 to see if any of them describes EXP. If yes, the descriptor records
2577 the label number already assigned. */
2579 hash = const_hash (exp) % MAX_HASH_TABLE;
2581 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2582 if (compare_constant (exp, desc))
2584 found = desc->label;
2590 /* No constant equal to EXP is known to have been output.
2591 Make a constant descriptor to enter EXP in the hash table.
2592 Assign the label number and record it in the descriptor for
2593 future calls to this function to find. */
2595 /* Create a string containing the label name, in LABEL. */
2596 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2598 desc = record_constant (exp);
2599 desc->next = const_hash_table[hash];
2601 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2602 const_hash_table[hash] = desc;
2606 /* Create a string containing the label name, in LABEL. */
2607 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2610 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2612 push_obstacks_nochange ();
2613 if (TREE_PERMANENT (exp))
2614 end_temporary_allocation ();
2616 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2619 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2620 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2621 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2622 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2626 /* Optionally set flags or add text to the name to record information
2627 such as that it is a function name. If the name is changed, the macro
2628 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2629 #ifdef ENCODE_SECTION_INFO
2630 ENCODE_SECTION_INFO (exp);
2633 /* If this is the first time we've seen this particular constant,
2634 output it (or defer its output for later). */
2637 if (defer_addressed_constants_flag)
2639 struct deferred_constant *p;
2640 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2642 push_obstacks_nochange ();
2643 suspend_momentary ();
2644 p->exp = copy_constant (exp);
2647 p->labelno = const_labelno++;
2648 p->next = deferred_constants;
2649 deferred_constants = p;
2652 output_constant_def_contents (exp, reloc, const_labelno++);
2655 return TREE_CST_RTL (exp);
2658 /* Now output assembler code to define the label for EXP,
2659 and follow it with the data of EXP. */
2662 output_constant_def_contents (exp, reloc, labelno)
2669 if (IN_NAMED_SECTION (exp))
2670 named_section (TREE_STRING_POINTER (DECL_SECTION_NAME (exp)));
2673 /* First switch to text section, except for writable strings. */
2674 #ifdef SELECT_SECTION
2675 SELECT_SECTION (exp, reloc);
2677 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2678 || (flag_pic && reloc))
2681 readonly_data_section ();
2685 /* Align the location counter as required by EXP's data type. */
2686 align = TYPE_ALIGN (TREE_TYPE (exp));
2687 #ifdef CONSTANT_ALIGNMENT
2688 align = CONSTANT_ALIGNMENT (exp, align);
2691 if (align > BITS_PER_UNIT)
2693 if (!output_bytecode)
2695 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2699 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2703 /* Output the label itself. */
2704 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2706 /* Output the value of EXP. */
2707 output_constant (exp,
2708 (TREE_CODE (exp) == STRING_CST
2709 ? TREE_STRING_LENGTH (exp)
2710 : int_size_in_bytes (TREE_TYPE (exp))));
2714 /* Similar hash facility for making memory-constants
2715 from constant rtl-expressions. It is used on RISC machines
2716 where immediate integer arguments and constant addresses are restricted
2717 so that such constants must be stored in memory.
2719 This pool of constants is reinitialized for each function
2720 so each function gets its own constants-pool that comes right before it.
2722 All structures allocated here are discarded when functions are saved for
2723 inlining, so they do not need to be allocated permanently. */
2725 #define MAX_RTX_HASH_TABLE 61
2726 static struct constant_descriptor **const_rtx_hash_table;
2728 /* Structure to represent sufficient information about a constant so that
2729 it can be output when the constant pool is output, so that function
2730 integration can be done, and to simplify handling on machines that reference
2731 constant pool as base+displacement. */
2733 struct pool_constant
2735 struct constant_descriptor *desc;
2736 struct pool_constant *next;
2737 enum machine_mode mode;
2744 /* Pointers to first and last constant in pool. */
2746 static struct pool_constant *first_pool, *last_pool;
2748 /* Current offset in constant pool (does not include any machine-specific
2751 static int pool_offset;
2753 /* Structure used to maintain hash table mapping symbols used to their
2754 corresponding constants. */
2759 struct pool_constant *pool;
2760 struct pool_sym *next;
2763 static struct pool_sym **const_rtx_sym_hash_table;
2765 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2766 The argument is XSTR (... , 0) */
2768 #define SYMHASH(LABEL) \
2769 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2771 /* Initialize constant pool hashing for next function. */
2774 init_const_rtx_hash_table ()
2776 const_rtx_hash_table
2777 = ((struct constant_descriptor **)
2778 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2779 const_rtx_sym_hash_table
2780 = ((struct pool_sym **)
2781 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2782 bzero ((char *) const_rtx_hash_table,
2783 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2784 bzero ((char *) const_rtx_sym_hash_table,
2785 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2787 first_pool = last_pool = 0;
2791 /* Save and restore it for a nested function. */
2794 save_varasm_status (p)
2797 p->const_rtx_hash_table = const_rtx_hash_table;
2798 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2799 p->first_pool = first_pool;
2800 p->last_pool = last_pool;
2801 p->pool_offset = pool_offset;
2805 restore_varasm_status (p)
2808 const_rtx_hash_table = p->const_rtx_hash_table;
2809 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2810 first_pool = p->first_pool;
2811 last_pool = p->last_pool;
2812 pool_offset = p->pool_offset;
2815 enum kind { RTX_DOUBLE, RTX_INT };
2819 #ifdef ONLY_INT_FIELDS
2820 unsigned int kind : 16;
2821 unsigned int mode : 16;
2823 enum kind kind : 16;
2824 enum machine_mode mode : 16;
2827 union real_extract du;
2828 struct addr_const addr;
2832 /* Express an rtx for a constant integer (perhaps symbolic)
2833 as the sum of a symbol or label plus an explicit integer.
2834 They are stored into VALUE. */
2837 decode_rtx_const (mode, x, value)
2838 enum machine_mode mode;
2840 struct rtx_const *value;
2842 /* Clear the whole structure, including any gaps. */
2845 int *p = (int *) value;
2846 int *end = (int *) (value + 1);
2851 value->kind = RTX_INT; /* Most usual kind. */
2854 switch (GET_CODE (x))
2857 value->kind = RTX_DOUBLE;
2858 if (GET_MODE (x) != VOIDmode)
2859 value->mode = GET_MODE (x);
2860 bcopy ((char *) &CONST_DOUBLE_LOW (x),
2861 (char *) &value->un.du, sizeof value->un.du);
2865 value->un.addr.offset = INTVAL (x);
2871 value->un.addr.base = x;
2876 if (GET_CODE (x) == PLUS)
2878 value->un.addr.base = XEXP (x, 0);
2879 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2881 value->un.addr.offset = INTVAL (XEXP (x, 1));
2883 else if (GET_CODE (x) == MINUS)
2885 value->un.addr.base = XEXP (x, 0);
2886 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2888 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2898 if (value->kind == RTX_INT && value->un.addr.base != 0)
2899 switch (GET_CODE (value->un.addr.base))
2903 /* Use the string's address, not the SYMBOL_REF's address,
2904 for the sake of addresses of library routines.
2905 For a LABEL_REF, compare labels. */
2906 value->un.addr.base = XEXP (value->un.addr.base, 0);
2910 /* Given a MINUS expression, simplify it if both sides
2911 include the same symbol. */
2914 simplify_subtraction (x)
2917 struct rtx_const val0, val1;
2919 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2920 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2922 if (val0.un.addr.base == val1.un.addr.base)
2923 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2927 /* Compute a hash code for a constant RTL expression. */
2930 const_hash_rtx (mode, x)
2931 enum machine_mode mode;
2936 struct rtx_const value;
2937 decode_rtx_const (mode, x, &value);
2939 /* Compute hashing function */
2941 for (i = 0; i < sizeof value / sizeof (int); i++)
2942 hi += ((int *) &value)[i];
2944 hi &= (1 << HASHBITS) - 1;
2945 hi %= MAX_RTX_HASH_TABLE;
2949 /* Compare a constant rtl object X with a constant-descriptor DESC.
2950 Return 1 if DESC describes a constant with the same value as X. */
2953 compare_constant_rtx (mode, x, desc)
2954 enum machine_mode mode;
2956 struct constant_descriptor *desc;
2958 register int *p = (int *) desc->contents;
2961 struct rtx_const value;
2963 decode_rtx_const (mode, x, &value);
2964 strp = (int *) &value;
2965 len = sizeof value / sizeof (int);
2967 /* Compare constant contents. */
2969 if (*p++ != *strp++)
2975 /* Construct a constant descriptor for the rtl-expression X.
2976 It is up to the caller to enter the descriptor in the hash table. */
2978 static struct constant_descriptor *
2979 record_constant_rtx (mode, x)
2980 enum machine_mode mode;
2983 struct constant_descriptor *ptr;
2985 struct rtx_const value;
2987 decode_rtx_const (mode, x, &value);
2989 obstack_grow (current_obstack, &ptr, sizeof ptr);
2990 obstack_grow (current_obstack, &label, sizeof label);
2992 /* Record constant contents. */
2993 obstack_grow (current_obstack, &value, sizeof value);
2995 return (struct constant_descriptor *) obstack_finish (current_obstack);
2998 /* Given a constant rtx X, make (or find) a memory constant for its value
2999 and return a MEM rtx to refer to it in memory. */
3002 force_const_mem (mode, x)
3003 enum machine_mode mode;
3007 register struct constant_descriptor *desc;
3012 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3013 (this will always be true for floating CONST_DOUBLEs that have been
3014 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3015 use the previous copy. Otherwise, make a new one. Note that in
3016 the unlikely event that this same CONST_DOUBLE is used in two different
3017 modes in an alternating fashion, we will allocate a lot of different
3018 memory locations, but this should be extremely rare. */
3020 /* Don't use CONST_DOUBLE_MEM in a nested function.
3021 Nested functions have their own constant pools,
3022 so they can't share the same values in CONST_DOUBLE_MEM
3023 with the containing function. */
3024 if (outer_function_chain == 0)
3025 if (GET_CODE (x) == CONST_DOUBLE
3026 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3027 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3028 return CONST_DOUBLE_MEM (x);
3030 /* Compute hash code of X. Search the descriptors for that hash code
3031 to see if any of them describes X. If yes, the descriptor records
3032 the label number already assigned. */
3034 hash = const_hash_rtx (mode, x);
3036 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3037 if (compare_constant_rtx (mode, x, desc))
3039 found = desc->label;
3045 register struct pool_constant *pool;
3046 register struct pool_sym *sym;
3049 /* No constant equal to X is known to have been output.
3050 Make a constant descriptor to enter X in the hash table.
3051 Assign the label number and record it in the descriptor for
3052 future calls to this function to find. */
3054 desc = record_constant_rtx (mode, x);
3055 desc->next = const_rtx_hash_table[hash];
3056 const_rtx_hash_table[hash] = desc;
3058 /* Align the location counter as required by EXP's data type. */
3059 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3060 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3061 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3063 pool_offset += align - 1;
3064 pool_offset &= ~ (align - 1);
3066 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3068 pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
3072 pool->labelno = const_labelno;
3073 pool->align = align;
3074 pool->offset = pool_offset;
3080 last_pool->next = pool;
3083 pool_offset += GET_MODE_SIZE (mode);
3085 /* Create a string containing the label name, in LABEL. */
3086 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3091 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3093 /* Add label to symbol hash table. */
3094 hash = SYMHASH (found);
3095 sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
3098 sym->next = const_rtx_sym_hash_table[hash];
3099 const_rtx_sym_hash_table[hash] = sym;
3102 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3104 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3106 RTX_UNCHANGING_P (def) = 1;
3107 /* Mark the symbol_ref as belonging to this constants pool. */
3108 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3109 current_function_uses_const_pool = 1;
3111 if (outer_function_chain == 0)
3112 if (GET_CODE (x) == CONST_DOUBLE)
3114 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3116 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3117 const_double_chain = x;
3119 CONST_DOUBLE_MEM (x) = def;
3125 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3126 the corresponding pool_constant structure. */
3128 static struct pool_constant *
3129 find_pool_constant (addr)
3132 struct pool_sym *sym;
3133 char *label = XSTR (addr, 0);
3135 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3136 if (sym->label == label)
3142 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3145 get_pool_constant (addr)
3148 return (find_pool_constant (addr))->constant;
3151 /* Similar, return the mode. */
3154 get_pool_mode (addr)
3157 return (find_pool_constant (addr))->mode;
3160 /* Similar, return the offset in the constant pool. */
3163 get_pool_offset (addr)
3166 return (find_pool_constant (addr))->offset;
3169 /* Return the size of the constant pool. */
3177 /* Write all the constants in the constant pool. */
3180 output_constant_pool (fnname, fndecl)
3184 struct pool_constant *pool;
3186 union real_extract u;
3188 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3189 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3192 for (pool = first_pool; pool; pool = pool->next)
3196 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3197 whose CODE_LABEL has been deleted. This can occur if a jump table
3198 is eliminated by optimization. If so, write a constant of zero
3199 instead. Note that this can also happen by turning the
3200 CODE_LABEL into a NOTE. */
3201 if (((GET_CODE (x) == LABEL_REF
3202 && (INSN_DELETED_P (XEXP (x, 0))
3203 || GET_CODE (XEXP (x, 0)) == NOTE)))
3204 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3205 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3206 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3207 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3210 /* First switch to correct section. */
3211 #ifdef SELECT_RTX_SECTION
3212 SELECT_RTX_SECTION (pool->mode, x);
3214 readonly_data_section ();
3217 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3218 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3219 pool->align, pool->labelno, done);
3222 if (pool->align > 1)
3223 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3225 /* Output the label. */
3226 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3228 /* Output the value of the constant itself. */
3229 switch (GET_MODE_CLASS (pool->mode))
3232 if (GET_CODE (x) != CONST_DOUBLE)
3235 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3236 assemble_real (u.d, pool->mode);
3240 case MODE_PARTIAL_INT:
3241 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3251 /* Done with this pool. */
3252 first_pool = last_pool = 0;
3255 /* Find all the constants whose addresses are referenced inside of EXP,
3256 and make sure assembler code with a label has been output for each one.
3257 Indicate whether an ADDR_EXPR has been encountered. */
3260 output_addressed_constants (exp)
3265 switch (TREE_CODE (exp))
3269 register tree constant = TREE_OPERAND (exp, 0);
3271 while (TREE_CODE (constant) == COMPONENT_REF)
3273 constant = TREE_OPERAND (constant, 0);
3276 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3277 || TREE_CODE (constant) == CONSTRUCTOR)
3278 /* No need to do anything here
3279 for addresses of variables or functions. */
3280 output_constant_def (constant);
3287 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3288 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3293 case NON_LVALUE_EXPR:
3294 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3300 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3301 if (TREE_VALUE (link) != 0)
3302 reloc |= output_addressed_constants (TREE_VALUE (link));
3313 /* Output assembler for byte constant */
3315 output_byte_asm (byte)
3318 if (output_bytecode)
3319 bc_emit_const ((char *) &byte, sizeof (char));
3320 #ifdef ASM_OUTPUT_BYTE
3323 ASM_OUTPUT_BYTE (asm_out_file, byte);
3328 /* Output assembler code for constant EXP to FILE, with no label.
3329 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3330 Assumes output_addressed_constants has been done on EXP already.
3332 Generate exactly SIZE bytes of assembler data, padding at the end
3333 with zeros if necessary. SIZE must always be specified.
3335 SIZE is important for structure constructors,
3336 since trailing members may have been omitted from the constructor.
3337 It is also important for initialization of arrays from string constants
3338 since the full length of the string constant might not be wanted.
3339 It is also needed for initialization of unions, where the initializer's
3340 type is just one member, and that may not be as long as the union.
3342 There a case in which we would fail to output exactly SIZE bytes:
3343 for a structure constructor that wants to produce more than SIZE bytes.
3344 But such constructors will never be generated for any possible input. */
3347 output_constant (exp, size)
3351 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3357 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3358 That way we get the constant (we hope) inside it. Also, strip
3359 off any NOP_EXPR that converts between two record or union types. */
3360 while ((TREE_CODE (exp) == NOP_EXPR
3361 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3362 || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3363 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
3364 || TREE_CODE (TREE_TYPE (exp)) == QUAL_UNION_TYPE))
3365 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3366 exp = TREE_OPERAND (exp, 0);
3368 /* Allow a constructor with no elements for any data type.
3369 This means to fill the space with zeros. */
3370 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3372 if (output_bytecode)
3373 bc_emit_const_skip (size);
3375 assemble_zeros (size);
3386 case REFERENCE_TYPE:
3387 /* ??? What about (int)((float)(int)&foo + 4) */
3388 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3389 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3390 exp = TREE_OPERAND (exp, 0);
3392 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3393 EXPAND_INITIALIZER),
3395 error ("initializer for integer value is too complicated");
3400 if (TREE_CODE (exp) != REAL_CST)
3401 error ("initializer for floating value is not a floating constant");
3403 assemble_real (TREE_REAL_CST (exp),
3404 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3409 output_constant (TREE_REALPART (exp), size / 2);
3410 output_constant (TREE_IMAGPART (exp), size / 2);
3411 size -= (size / 2) * 2;
3415 if (TREE_CODE (exp) == CONSTRUCTOR)
3417 output_constructor (exp, size);
3420 else if (TREE_CODE (exp) == STRING_CST)
3424 if (size > TREE_STRING_LENGTH (exp))
3426 excess = size - TREE_STRING_LENGTH (exp);
3427 size = TREE_STRING_LENGTH (exp);
3430 assemble_string (TREE_STRING_POINTER (exp), size);
3439 if (TREE_CODE (exp) == CONSTRUCTOR)
3440 output_constructor (exp, size);
3447 assemble_zeros (size);
3451 /* Bytecode specific code to output assembler for integer. */
3453 bc_assemble_integer (exp, size)
3461 /* FIXME: is this fold() business going to be as good as the
3462 expand_expr() using EXPAND_SUM above in the RTL case? I
3464 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3468 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3469 exp = TREE_OPERAND (exp, 0);
3470 if (TREE_CODE (exp) == INTEGER_CST)
3475 else if (TREE_CODE (exp) == PLUS_EXPR)
3477 const_part = TREE_OPERAND (exp, 0);
3478 while (TREE_CODE (const_part) == NOP_EXPR
3479 || TREE_CODE (const_part) == CONVERT_EXPR)
3480 const_part = TREE_OPERAND (const_part, 0);
3481 addr_part = TREE_OPERAND (exp, 1);
3482 while (TREE_CODE (addr_part) == NOP_EXPR
3483 || TREE_CODE (addr_part) == CONVERT_EXPR)
3484 addr_part = TREE_OPERAND (addr_part, 0);
3485 if (TREE_CODE (const_part) != INTEGER_CST)
3486 tmp = const_part, const_part = addr_part, addr_part = tmp;
3487 if (TREE_CODE (const_part) != INTEGER_CST
3488 || TREE_CODE (addr_part) != ADDR_EXPR)
3489 abort (); /* FIXME: we really haven't considered
3490 all the possible cases here. */
3492 else if (TREE_CODE (exp) == ADDR_EXPR)
3494 const_part = integer_zero_node;
3498 abort (); /* FIXME: ditto previous. */
3504 char c = TREE_INT_CST_LOW (const_part);
3510 short s = TREE_INT_CST_LOW (const_part);
3511 bc_emit ((char *) &s, 2);
3516 int i = TREE_INT_CST_LOW (const_part);
3517 bc_emit ((char *) &i, 4);
3522 #if WORDS_BIG_ENDIAN
3523 int i = TREE_INT_CST_HIGH (const_part);
3524 bc_emit ((char *) &i, 4);
3525 i = TREE_INT_CST_LOW (const_part);
3526 bc_emit ((char *) &i, 4);
3528 int i = TREE_INT_CST_LOW (const_part);
3529 bc_emit ((char *) &i, 4);
3530 i = TREE_INT_CST_HIGH (const_part);
3531 bc_emit ((char *) &i, 4);
3538 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3539 bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3540 TREE_INT_CST_LOW (const_part));
3542 abort (); /* FIXME: there may be more cases. */
3545 /* Subroutine of output_constant, used for CONSTRUCTORs
3546 (aggregate constants).
3547 Generate at least SIZE bytes, padding if necessary. */
3550 output_constructor (exp, size)
3554 register tree link, field = 0;
3555 HOST_WIDE_INT min_index = 0;
3556 /* Number of bytes output or skipped so far.
3557 In other words, current position within the constructor. */
3558 int total_bytes = 0;
3559 /* Non-zero means BYTE contains part of a byte, to be output. */
3560 int byte_buffer_in_use = 0;
3563 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3566 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3567 field = TYPE_FIELDS (TREE_TYPE (exp));
3569 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3570 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3572 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3574 /* As LINK goes through the elements of the constant,
3575 FIELD goes through the structure fields, if the constant is a structure.
3576 if the constant is a union, then we override this,
3577 by getting the field from the TREE_LIST element.
3578 But the constant could also be an array. Then FIELD is zero. */
3579 for (link = CONSTRUCTOR_ELTS (exp);
3581 link = TREE_CHAIN (link),
3582 field = field ? TREE_CHAIN (field) : 0)
3584 tree val = TREE_VALUE (link);
3587 /* the element in a union constructor specifies the proper field. */
3589 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3590 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3592 /* if available, use the type given by link */
3593 if (TREE_PURPOSE (link) != 0)
3594 field = TREE_PURPOSE (link);
3597 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3598 index = TREE_PURPOSE (link);
3600 /* Eliminate the marker that makes a cast not be an lvalue. */
3604 if (field == 0 || !DECL_BIT_FIELD (field))
3606 /* An element that is not a bit-field. */
3608 register int fieldsize;
3609 /* Since this structure is static,
3610 we know the positions are constant. */
3611 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3615 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3617 * (TREE_INT_CST_LOW (index) - min_index));
3619 /* Output any buffered-up bit-fields preceding this element. */
3620 if (byte_buffer_in_use)
3622 ASM_OUTPUT_BYTE (asm_out_file, byte);
3624 byte_buffer_in_use = 0;
3627 /* Advance to offset of this element.
3628 Note no alignment needed in an array, since that is guaranteed
3629 if each element has the proper size. */
3630 if ((field != 0 || index != 0) && bitpos != total_bytes)
3632 if (!output_bytecode)
3633 assemble_zeros (bitpos - total_bytes);
3635 bc_emit_const_skip (bitpos - total_bytes);
3636 total_bytes = bitpos;
3639 /* Determine size this element should occupy. */
3642 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3644 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3646 /* This avoids overflow trouble. */
3647 tree size_tree = size_binop (CEIL_DIV_EXPR,
3649 size_int (BITS_PER_UNIT));
3650 fieldsize = TREE_INT_CST_LOW (size_tree);
3654 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3655 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3659 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3661 /* Output the element's initial value. */
3663 assemble_zeros (fieldsize);
3665 output_constant (val, fieldsize);
3667 /* Count its size. */
3668 total_bytes += fieldsize;
3670 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3671 error ("invalid initial value for member `%s'",
3672 IDENTIFIER_POINTER (DECL_NAME (field)));
3675 /* Element that is a bit-field. */
3677 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3679 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3682 val = integer_zero_node;
3684 /* If this field does not start in this (or, next) byte,
3686 if (next_offset / BITS_PER_UNIT != total_bytes)
3688 /* Output remnant of any bit field in previous bytes. */
3689 if (byte_buffer_in_use)
3691 ASM_OUTPUT_BYTE (asm_out_file, byte);
3693 byte_buffer_in_use = 0;
3696 /* If still not at proper byte, advance to there. */
3697 if (next_offset / BITS_PER_UNIT != total_bytes)
3699 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3700 total_bytes = next_offset / BITS_PER_UNIT;
3704 if (! byte_buffer_in_use)
3707 /* We must split the element into pieces that fall within
3708 separate bytes, and combine each byte with previous or
3709 following bit-fields. */
3711 /* next_offset is the offset n fbits from the beginning of
3712 the structure to the next bit of this element to be processed.
3713 end_offset is the offset of the first bit past the end of
3715 while (next_offset < end_offset)
3719 int next_byte = next_offset / BITS_PER_UNIT;
3720 int next_bit = next_offset % BITS_PER_UNIT;
3722 /* Advance from byte to byte
3723 within this element when necessary. */
3724 while (next_byte != total_bytes)
3726 ASM_OUTPUT_BYTE (asm_out_file, byte);
3731 /* Number of bits we can process at once
3732 (all part of the same byte). */
3733 this_time = MIN (end_offset - next_offset,
3734 BITS_PER_UNIT - next_bit);
3735 #if BYTES_BIG_ENDIAN
3736 /* On big-endian machine, take the most significant bits
3737 first (of the bits that are significant)
3738 and put them into bytes from the most significant end. */
3739 shift = end_offset - next_offset - this_time;
3740 /* Don't try to take a bunch of bits that cross
3741 the word boundary in the INTEGER_CST. */
3742 if (shift < HOST_BITS_PER_WIDE_INT
3743 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3745 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3746 shift = HOST_BITS_PER_WIDE_INT;
3749 /* Now get the bits from the appropriate constant word. */
3750 if (shift < HOST_BITS_PER_WIDE_INT)
3752 value = TREE_INT_CST_LOW (val);
3754 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3756 value = TREE_INT_CST_HIGH (val);
3757 shift -= HOST_BITS_PER_WIDE_INT;
3761 byte |= (((value >> shift)
3762 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3763 << (BITS_PER_UNIT - this_time - next_bit));
3765 /* On little-endian machines,
3766 take first the least significant bits of the value
3767 and pack them starting at the least significant
3768 bits of the bytes. */
3769 shift = (next_offset
3770 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3771 /* Don't try to take a bunch of bits that cross
3772 the word boundary in the INTEGER_CST. */
3773 if (shift < HOST_BITS_PER_WIDE_INT
3774 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3776 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3777 shift = HOST_BITS_PER_WIDE_INT;
3780 /* Now get the bits from the appropriate constant word. */
3781 if (shift < HOST_BITS_PER_INT)
3782 value = TREE_INT_CST_LOW (val);
3783 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3785 value = TREE_INT_CST_HIGH (val);
3786 shift -= HOST_BITS_PER_WIDE_INT;
3790 byte |= ((value >> shift)
3791 & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
3793 next_offset += this_time;
3794 byte_buffer_in_use = 1;
3798 if (byte_buffer_in_use)
3800 ASM_OUTPUT_BYTE (asm_out_file, byte);
3803 if (total_bytes < size)
3804 assemble_zeros (size - total_bytes);
3808 #ifdef HANDLE_SYSV_PRAGMA
3810 /* Support #pragma weak by default if WEAK_ASM_OP and ASM_OUTPUT_DEF
3812 #if defined (WEAK_ASM_OP) && defined (ASM_OUTPUT_DEF)
3814 /* See c-pragma.c for an identical definition. */
3830 /* Output asm to handle ``#pragma weak'' */
3832 handle_pragma_weak (what, asm_out_file, name, value)
3833 enum pragma_state what;
3837 if (what == ps_name || what == ps_value)
3839 fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
3841 if (output_bytecode)
3842 BC_OUTPUT_LABELREF (asm_out_file, name);
3844 ASM_OUTPUT_LABELREF (asm_out_file, name);
3846 fputc ('\n', asm_out_file);
3847 if (what == ps_value)
3848 ASM_OUTPUT_DEF (asm_out_file, name, value);
3850 else if (! (what == ps_done || what == ps_start))
3851 warning ("malformed `#pragma weak'");
3854 #endif /* HANDLE_PRAGMA_WEAK or (WEAK_ASM_OP and SET_ASM_OP) */
3856 #endif /* WEAK_ASM_OP && ASM_OUTPUT_DEF */