1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92, 93, 1994 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* This file handles generation of all the assembler code
22 *except* the instructions of a function.
23 This includes declarations of variables and their initial values.
25 We also output the assembler code for constants stored in memory
26 and are responsible for combining constants with the same value. */
30 /* #include <stab.h> */
37 #include "hard-reg-set.h"
45 #ifdef XCOFF_DEBUGGING_INFO
52 #define ASM_STABS_OP ".stabs"
55 /* This macro gets just the user-specified name
56 out of the string in a SYMBOL_REF. On most machines,
57 we discard the * if any and that's all. */
58 #ifndef STRIP_NAME_ENCODING
59 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
60 (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
63 /* File in which assembler code is being written. */
65 extern FILE *asm_out_file;
67 /* The (assembler) name of the first globally-visible object output. */
68 char *first_global_object_name;
70 extern struct obstack *current_obstack;
71 extern struct obstack *saveable_obstack;
72 extern struct obstack *rtl_obstack;
73 extern struct obstack permanent_obstack;
74 #define obstack_chunk_alloc xmalloc
76 /* Number for making the label on the next
77 constant that is stored in memory. */
81 /* Number for making the label on the next
82 static variable internal to a function. */
86 /* Carry information from ASM_DECLARE_OBJECT_NAME
87 to ASM_FINISH_DECLARE_OBJECT. */
89 int size_directive_output;
91 /* The last decl for which assemble_variable was called,
92 if it did ASM_DECLARE_OBJECT_NAME.
93 If the last call to assemble_variable didn't do that,
96 tree last_assemble_variable_decl;
98 /* Nonzero if at least one function definition has been seen. */
99 static int function_defined;
101 extern FILE *asm_out_file;
103 static char *compare_constant_1 ();
104 static void record_constant_1 ();
105 static void output_constant_def_contents ();
106 static int contains_pointers_p ();
107 static void bc_output_ascii ();
109 void output_constant_pool ();
110 void assemble_name ();
111 int output_addressed_constants ();
112 void output_constant ();
113 void output_constructor ();
114 void output_byte_asm ();
115 void text_section ();
116 void readonly_data_section ();
117 void data_section ();
118 void named_section ();
119 static void bc_assemble_integer ();
121 #ifdef EXTRA_SECTIONS
122 static enum in_section {no_section, in_text, in_data, in_named, EXTRA_SECTIONS} in_section
125 static enum in_section {no_section, in_text, in_data, in_named} in_section
129 /* Return a non-zero value if DECL has a section attribute. */
130 #define IN_NAMED_SECTION(DECL) \
131 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
132 && DECL_SECTION_NAME (DECL) != NULL_TREE)
134 /* Text of section name when in_section == in_named. */
135 static char *in_named_name;
137 /* Define functions like text_section for any extra sections. */
138 #ifdef EXTRA_SECTION_FUNCTIONS
139 EXTRA_SECTION_FUNCTIONS
142 /* Tell assembler to switch to text section. */
147 if (in_section != in_text)
152 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
154 in_section = in_text;
158 /* Tell assembler to switch to data section. */
163 if (in_section != in_data)
169 if (flag_shared_data)
171 #ifdef SHARED_SECTION_ASM_OP
172 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
174 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
178 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
181 in_section = in_data;
185 /* Tell assembler to switch to read-only data section. This is normally
189 readonly_data_section ()
191 #ifdef READONLY_DATA_SECTION
192 READONLY_DATA_SECTION (); /* Note this can call data_section. */
198 /* Determine if we're in the text section. */
203 return in_section == in_text;
206 /* Tell assembler to change to named section. */
212 if (in_section != in_named || strcmp (name, in_named_name))
214 in_named_name = name;
215 in_section = in_named;
217 #ifdef ASM_OUTPUT_SECTION_NAME
218 ASM_OUTPUT_SECTION_NAME (asm_out_file, name);
220 /* Section attributes are not supported if this macro isn't provided -
221 some host formats don't support them at all. The front-end should
222 already have flagged this as an error. */
228 /* Create the rtl to represent a function, for a function definition.
229 DECL is a FUNCTION_DECL node which describes which function.
230 The rtl is stored into DECL. */
233 make_function_rtl (decl)
236 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
240 if (DECL_RTL (decl) == 0)
241 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
243 /* Record that at least one function has been defined. */
244 function_defined = 1;
248 /* Rename a nested function to avoid conflicts. */
249 if (decl_function_context (decl) != 0
250 && DECL_INITIAL (decl) != 0
251 && DECL_RTL (decl) == 0)
255 name = IDENTIFIER_POINTER (DECL_NAME (decl));
256 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
257 name = obstack_copy0 (saveable_obstack, label, strlen (label));
261 if (DECL_RTL (decl) == 0)
264 = gen_rtx (MEM, DECL_MODE (decl),
265 gen_rtx (SYMBOL_REF, Pmode, name));
267 /* Optionally set flags or add text to the name to record information
268 such as that it is a function name. If the name is changed, the macro
269 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
270 #ifdef ENCODE_SECTION_INFO
271 ENCODE_SECTION_INFO (decl);
275 /* Record at least one function has been defined. */
276 function_defined = 1;
279 /* Create the DECL_RTL for a declaration for a static or external
280 variable or static or external function.
281 ASMSPEC, if not 0, is the string which the user specified
282 as the assembler symbol name.
283 TOP_LEVEL is nonzero if this is a file-scope variable.
284 This is never called for PARM_DECLs. */
286 bc_make_decl_rtl (decl, asmspec, top_level)
291 register char *name = TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl));
293 if (DECL_RTL (decl) == 0)
295 /* Print an error message for register variables. */
296 if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
297 error ("function declared `register'");
298 else if (DECL_REGISTER (decl))
299 error ("global register variables not supported in the interpreter");
301 /* Handle ordinary static variables and functions. */
302 if (DECL_RTL (decl) == 0)
304 /* Can't use just the variable's own name for a variable
305 whose scope is less than the whole file.
306 Concatenate a distinguishing number. */
307 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
311 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
312 name = obstack_copy0 (saveable_obstack, label, strlen (label));
316 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
321 /* Given NAME, a putative register name, discard any customary prefixes. */
324 strip_reg_name (name)
327 #ifdef REGISTER_PREFIX
328 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
329 name += strlen (REGISTER_PREFIX);
331 if (name[0] == '%' || name[0] == '#')
336 /* Decode an `asm' spec for a declaration as a register name.
337 Return the register number, or -1 if nothing specified,
338 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
339 or -3 if ASMSPEC is `cc' and is not recognized,
340 or -4 if ASMSPEC is `memory' and is not recognized.
341 Accept an exact spelling or a decimal number.
342 Prefixes such as % are optional. */
345 decode_reg_name (asmspec)
352 /* Get rid of confusing prefixes. */
353 asmspec = strip_reg_name (asmspec);
355 /* Allow a decimal number as a "register name". */
356 for (i = strlen (asmspec) - 1; i >= 0; i--)
357 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
359 if (asmspec[0] != 0 && i < 0)
362 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
368 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
370 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
373 #ifdef ADDITIONAL_REGISTER_NAMES
375 static struct { char *name; int number; } table[]
376 = ADDITIONAL_REGISTER_NAMES;
378 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
379 if (! strcmp (asmspec, table[i].name))
380 return table[i].number;
382 #endif /* ADDITIONAL_REGISTER_NAMES */
384 if (!strcmp (asmspec, "memory"))
387 if (!strcmp (asmspec, "cc"))
396 /* Create the DECL_RTL for a declaration for a static or external variable
397 or static or external function.
398 ASMSPEC, if not 0, is the string which the user specified
399 as the assembler symbol name.
400 TOP_LEVEL is nonzero if this is a file-scope variable.
402 This is never called for PARM_DECL nodes. */
405 make_decl_rtl (decl, asmspec, top_level)
410 register char *name = 0;
415 bc_make_decl_rtl (decl, asmspec, top_level);
419 reg_number = decode_reg_name (asmspec);
421 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
422 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
424 if (reg_number == -2)
426 /* ASMSPEC is given, and not the name of a register. */
427 name = (char *) obstack_alloc (saveable_obstack,
428 strlen (asmspec) + 2);
430 strcpy (&name[1], asmspec);
433 /* For a duplicate declaration, we can be called twice on the
434 same DECL node. Don't discard the RTL already made. */
435 if (DECL_RTL (decl) == 0)
439 /* First detect errors in declaring global registers. */
440 if (DECL_REGISTER (decl) && reg_number == -1)
441 error_with_decl (decl,
442 "register name not specified for `%s'");
443 else if (DECL_REGISTER (decl) && reg_number < 0)
444 error_with_decl (decl,
445 "invalid register name for `%s'");
446 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
447 error_with_decl (decl,
448 "register name given for non-register variable `%s'");
449 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
450 error ("function declared `register'");
451 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
452 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
453 else if (DECL_REGISTER (decl)
454 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
455 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
456 /* Now handle properly declared static register variables. */
457 else if (DECL_REGISTER (decl))
460 #if 0 /* yylex should print the warning for this */
462 pedwarn ("ANSI C forbids global register variables");
464 if (DECL_INITIAL (decl) != 0 && top_level)
466 DECL_INITIAL (decl) = 0;
467 error ("global register variable has initial value");
469 if (fixed_regs[reg_number] == 0
470 && function_defined && top_level)
471 error ("global register variable follows a function definition");
472 if (TREE_THIS_VOLATILE (decl))
473 warning ("volatile register variables don't work as you might wish");
475 /* If the user specified one of the eliminables registers here,
476 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
477 confused with that register and be eliminated. Although this
478 usage is somewhat suspect, we nevertheless use the following
479 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
482 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
483 REGNO (DECL_RTL (decl)) = reg_number;
484 REG_USERVAR_P (DECL_RTL (decl)) = 1;
488 /* Make this register global, so not usable for anything
490 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
492 globalize_reg (reg_number + --nregs);
495 /* Specifying a section attribute on an uninitialized variable does not
496 (and cannot) cause it to be put in the given section. The linker
497 can only put initialized objects in specific sections, everything
498 else goes in bss for the linker to sort out later (otherwise the
499 linker would give a duplicate definition error for each compilation
500 unit that behaved thusly). So warn the user. */
501 else if (TREE_CODE (decl) == VAR_DECL
502 && DECL_SECTION_NAME (decl) != NULL_TREE
503 && DECL_INITIAL (decl) == NULL_TREE)
505 warning_with_decl (decl,
506 "section attribute ignored for uninitialized variable `%s'");
507 /* Remove the section name so subsequent declarations won't see it.
508 We are ignoring it, remember. */
509 DECL_SECTION_NAME (decl) = NULL_TREE;
512 /* Now handle ordinary static variables and functions (in memory).
513 Also handle vars declared register invalidly. */
514 if (DECL_RTL (decl) == 0)
516 /* Can't use just the variable's own name for a variable
517 whose scope is less than the whole file.
518 Concatenate a distinguishing number. */
519 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
523 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
524 name = obstack_copy0 (saveable_obstack, label, strlen (label));
531 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
532 gen_rtx (SYMBOL_REF, Pmode, name));
534 /* If this variable is to be treated as volatile, show its
535 tree node has side effects. If it has side effects, either
536 because of this test or from TREE_THIS_VOLATILE also
537 being set, show the MEM is volatile. */
538 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
539 && TREE_PUBLIC (decl))
540 TREE_SIDE_EFFECTS (decl) = 1;
541 if (TREE_SIDE_EFFECTS (decl))
542 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
544 if (TREE_READONLY (decl))
545 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
546 MEM_IN_STRUCT_P (DECL_RTL (decl))
547 = AGGREGATE_TYPE_P (TREE_TYPE (decl));
549 /* Optionally set flags or add text to the name to record information
550 such as that it is a function name.
551 If the name is changed, the macro ASM_OUTPUT_LABELREF
552 will have to know how to strip this information. */
553 #ifdef ENCODE_SECTION_INFO
554 ENCODE_SECTION_INFO (decl);
558 /* If the old RTL had the wrong mode, fix the mode. */
559 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
561 rtx rtl = DECL_RTL (decl);
562 PUT_MODE (rtl, DECL_MODE (decl));
566 /* Make the rtl for variable VAR be volatile.
567 Use this only for static variables. */
570 make_var_volatile (var)
573 if (GET_CODE (DECL_RTL (var)) != MEM)
576 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
579 /* Output alignment directive to align for constant expression EXP. */
582 assemble_constant_align (exp)
587 /* Align the location counter as required by EXP's data type. */
588 align = TYPE_ALIGN (TREE_TYPE (exp));
589 #ifdef CONSTANT_ALIGNMENT
590 align = CONSTANT_ALIGNMENT (exp, align);
593 if (align > BITS_PER_UNIT)
594 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
597 /* Output a string of literal assembler code
598 for an `asm' keyword used between functions. */
601 assemble_asm (string)
606 error ("asm statements not allowed in interpreter");
612 if (TREE_CODE (string) == ADDR_EXPR)
613 string = TREE_OPERAND (string, 0);
615 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
618 #if 0 /* This should no longer be needed, because
619 flag_gnu_linker should be 0 on these systems,
620 which should prevent any output
621 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
622 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
623 #ifndef ASM_OUTPUT_CONSTRUCTOR
624 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
626 #ifndef ASM_OUTPUT_DESTRUCTOR
627 #define ASM_OUTPUT_DESTRUCTOR(file, name)
632 /* Record an element in the table of global destructors.
633 How this is done depends on what sort of assembler and linker
636 NAME should be the name of a global function to be called
637 at exit time. This name is output using assemble_name. */
640 assemble_destructor (name)
643 #ifdef ASM_OUTPUT_DESTRUCTOR
644 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
648 /* Now tell GNU LD that this is part of the static destructor set. */
649 /* This code works for any machine provided you use GNU as/ld. */
650 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
651 assemble_name (asm_out_file, name);
652 fputc ('\n', asm_out_file);
657 /* Likewise for global constructors. */
660 assemble_constructor (name)
663 #ifdef ASM_OUTPUT_CONSTRUCTOR
664 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
668 /* Now tell GNU LD that this is part of the static constructor set. */
669 /* This code works for any machine provided you use GNU as/ld. */
670 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
671 assemble_name (asm_out_file, name);
672 fputc ('\n', asm_out_file);
677 /* Likewise for entries we want to record for garbage collection.
678 Garbage collection is still under development. */
681 assemble_gc_entry (name)
684 #ifdef ASM_OUTPUT_GC_ENTRY
685 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
689 /* Now tell GNU LD that this is part of the static constructor set. */
690 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
691 assemble_name (asm_out_file, name);
692 fputc ('\n', asm_out_file);
697 /* Output assembler code for the constant pool of a function and associated
698 with defining the name of the function. DECL describes the function.
699 NAME is the function's name. For the constant pool, we use the current
700 constant pool data. */
703 assemble_start_function (decl, fnname)
709 /* The following code does not need preprocessing in the assembler. */
713 output_constant_pool (fnname, decl);
715 if (IN_NAMED_SECTION (decl))
716 named_section (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)));
720 /* Tell assembler to move to target machine's alignment for functions. */
721 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
725 BC_OUTPUT_ALIGN (asm_out_file, align);
727 ASM_OUTPUT_ALIGN (asm_out_file, align);
730 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
731 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
734 #ifdef SDB_DEBUGGING_INFO
735 /* Output SDB definition of the function. */
736 if (write_symbols == SDB_DEBUG)
737 sdbout_mark_begin_function ();
740 #ifdef DBX_DEBUGGING_INFO
741 /* Output DBX definition of the function. */
742 if (write_symbols == DBX_DEBUG)
743 dbxout_begin_function (decl);
746 /* Make function name accessible from other files, if appropriate. */
748 if (TREE_PUBLIC (decl))
750 if (!first_global_object_name)
751 STRIP_NAME_ENCODING (first_global_object_name, fnname);
753 BC_GLOBALIZE_LABEL (asm_out_file, fnname);
755 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
758 /* Do any machine/system dependent processing of the function name */
759 #ifdef ASM_DECLARE_FUNCTION_NAME
760 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
762 /* Standard thing is just output label for the function. */
764 BC_OUTPUT_LABEL (asm_out_file, fnname);
766 ASM_OUTPUT_LABEL (asm_out_file, fnname);
767 #endif /* ASM_DECLARE_FUNCTION_NAME */
770 /* Output assembler code associated with defining the size of the
771 function. DECL describes the function. NAME is the function's name. */
774 assemble_end_function (decl, fnname)
778 #ifdef ASM_DECLARE_FUNCTION_SIZE
779 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
783 /* Assemble code to leave SIZE bytes of zeros. */
786 assemble_zeros (size)
791 bc_emit_const_skip (size);
795 #ifdef ASM_NO_SKIP_IN_TEXT
796 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
797 so we must output 0s explicitly in the text section. */
798 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
802 for (i = 0; i < size - 20; i += 20)
805 fprintf (asm_out_file,
806 "%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);
808 fprintf (asm_out_file,
809 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
815 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
817 fprintf (asm_out_file, "\tbyte 0");
820 for (; i < size; i++)
821 fprintf (asm_out_file, ",0");
822 fprintf (asm_out_file, "\n");
830 BC_OUTPUT_SKIP (asm_out_file, size);
832 ASM_OUTPUT_SKIP (asm_out_file, size);
836 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
839 assemble_align (align)
842 if (align > BITS_PER_UNIT)
843 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
846 /* Assemble a string constant with the specified C string as contents. */
849 assemble_string (p, size)
863 /* If the string is very long, split it up. */
867 int thissize = size - pos;
868 if (thissize > maximum)
872 bc_output_ascii (asm_out_file, p, thissize);
875 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
884 bc_output_ascii (file, p, size)
889 BC_OUTPUT_ASCII (file, p, size);
892 /* Assemble everything that is needed for a variable or function declaration.
893 Not used for automatic variables, and not used for function definitions.
894 Should not be called for variables of incomplete structure type.
896 TOP_LEVEL is nonzero if this variable has file scope.
897 AT_END is nonzero if this is the special handling, at end of compilation,
898 to define things that have had only tentative definitions.
899 DONT_OUTPUT_DATA if nonzero means don't actually output the
900 initial value (that will be done by the caller). */
903 assemble_variable (decl, top_level, at_end, dont_output_data)
912 enum in_section saved_in_section;
914 last_assemble_variable_decl = 0;
919 if (GET_CODE (DECL_RTL (decl)) == REG)
921 /* Do output symbol info for global register variables, but do nothing
924 if (TREE_ASM_WRITTEN (decl))
926 TREE_ASM_WRITTEN (decl) = 1;
928 if (!output_bytecode)
930 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
931 /* File-scope global variables are output here. */
932 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
934 dbxout_symbol (decl, 0);
936 #ifdef SDB_DEBUGGING_INFO
937 if (write_symbols == SDB_DEBUG && top_level
938 /* Leave initialized global vars for end of compilation;
939 see comment in compile_file. */
940 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
941 sdbout_symbol (decl, 0);
945 /* Don't output any DWARF debugging information for variables here.
946 In the case of local variables, the information for them is output
947 when we do our recursive traversal of the tree representation for
948 the entire containing function. In the case of file-scope variables,
949 we output information for all of them at the very end of compilation
950 while we are doing our final traversal of the chain of file-scope
956 /* Normally no need to say anything here for external references,
957 since assemble_external is called by the langauge-specific code
958 when a declaration is first seen. */
960 if (DECL_EXTERNAL (decl))
963 /* Output no assembler code for a function declaration.
964 Only definitions of functions output anything. */
966 if (TREE_CODE (decl) == FUNCTION_DECL)
969 /* If type was incomplete when the variable was declared,
970 see if it is complete now. */
972 if (DECL_SIZE (decl) == 0)
973 layout_decl (decl, 0);
975 /* Still incomplete => don't allocate it; treat the tentative defn
976 (which is what it must have been) as an `extern' reference. */
978 if (!dont_output_data && DECL_SIZE (decl) == 0)
980 error_with_file_and_line (DECL_SOURCE_FILE (decl),
981 DECL_SOURCE_LINE (decl),
982 "storage size of `%s' isn't known",
983 IDENTIFIER_POINTER (DECL_NAME (decl)));
984 TREE_ASM_WRITTEN (decl) = 1;
988 /* The first declaration of a variable that comes through this function
989 decides whether it is global (in C, has external linkage)
990 or local (in C, has internal linkage). So do nothing more
991 if this function has already run. */
993 if (TREE_ASM_WRITTEN (decl))
996 TREE_ASM_WRITTEN (decl) = 1;
998 /* If storage size is erroneously variable, just continue.
999 Error message was already made. */
1001 if (DECL_SIZE (decl))
1003 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1008 /* This is better than explicit arithmetic, since it avoids overflow. */
1009 size_tree = size_binop (CEIL_DIV_EXPR,
1010 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1012 if (TREE_INT_CST_HIGH (size_tree) != 0)
1014 error_with_decl (decl, "size of variable `%s' is too large");
1019 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1021 /* Handle uninitialized definitions. */
1023 /* ANSI specifies that a tentative definition which is not merged with
1024 a non-tentative definition behaves exactly like a definition with an
1025 initializer equal to zero. (Section 3.7.2)
1026 -fno-common gives strict ANSI behavior. Usually you don't want it.
1027 This matters only for variables with external linkage. */
1028 if ((! flag_no_common || ! TREE_PUBLIC (decl))
1029 && DECL_COMMON (decl)
1030 && ! dont_output_data
1031 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
1033 int size = TREE_INT_CST_LOW (size_tree);
1036 if (TREE_INT_CST_HIGH (size_tree) != 0)
1037 error_with_decl (decl, "size of variable `%s' is too large");
1038 /* Don't allocate zero bytes of common,
1039 since that means "undefined external" in the linker. */
1040 if (size == 0) rounded = 1;
1041 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1042 so that each uninitialized object starts on such a boundary. */
1043 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1044 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1045 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1047 #ifdef DBX_DEBUGGING_INFO
1048 /* File-scope global variables are output here. */
1049 if (write_symbols == DBX_DEBUG && top_level)
1050 dbxout_symbol (decl, 0);
1052 #ifdef SDB_DEBUGGING_INFO
1053 if (write_symbols == SDB_DEBUG && top_level
1054 /* Leave initialized global vars for end of compilation;
1055 see comment in compile_file. */
1056 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1057 sdbout_symbol (decl, 0);
1060 /* Don't output any DWARF debugging information for variables here.
1061 In the case of local variables, the information for them is output
1062 when we do our recursive traversal of the tree representation for
1063 the entire containing function. In the case of file-scope variables,
1064 we output information for all of them at the very end of compilation
1065 while we are doing our final traversal of the chain of file-scope
1069 if (flag_shared_data)
1072 if (TREE_PUBLIC (decl))
1074 #ifdef ASM_OUTPUT_SHARED_COMMON
1075 if (flag_shared_data)
1076 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1079 if (output_bytecode)
1081 BC_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1085 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1086 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1089 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1095 #ifdef ASM_OUTPUT_SHARED_LOCAL
1096 if (flag_shared_data)
1097 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1100 if (output_bytecode)
1102 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1106 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1107 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1110 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1117 /* Handle initialized definitions. */
1119 /* First make the assembler name(s) global if appropriate. */
1120 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1122 if (!first_global_object_name)
1123 STRIP_NAME_ENCODING(first_global_object_name, name);
1124 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1127 for (d = equivalents; d; d = TREE_CHAIN (d))
1129 tree e = TREE_VALUE (d);
1130 if (TREE_PUBLIC (e) && DECL_NAME (e))
1131 ASM_GLOBALIZE_LABEL (asm_out_file,
1132 XSTR (XEXP (DECL_RTL (e), 0), 0));
1136 /* Output any data that we will need to use the address of. */
1137 if (DECL_INITIAL (decl) == error_mark_node)
1138 reloc = contains_pointers_p (TREE_TYPE (decl));
1139 else if (DECL_INITIAL (decl))
1140 reloc = output_addressed_constants (DECL_INITIAL (decl));
1142 /* Switch to the proper section for this data. */
1143 if (IN_NAMED_SECTION (decl))
1144 named_section (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)));
1147 /* C++ can have const variables that get initialized from constructors,
1148 and thus can not be in a readonly section. We prevent this by
1149 verifying that the initial value is constant for objects put in a
1152 error_mark_node is used by the C front end to indicate that the
1153 initializer has not been seen yet. In this case, we assume that
1154 the initializer must be constant. */
1155 #ifdef SELECT_SECTION
1156 SELECT_SECTION (decl, reloc);
1158 if (TREE_READONLY (decl)
1159 && ! TREE_THIS_VOLATILE (decl)
1160 && DECL_INITIAL (decl)
1161 && (DECL_INITIAL (decl) == error_mark_node
1162 || TREE_CONSTANT (DECL_INITIAL (decl)))
1163 && ! (flag_pic && reloc))
1164 readonly_data_section ();
1170 /* dbxout.c needs to know this. */
1171 if (in_text_section ())
1172 DECL_IN_TEXT_SECTION (decl) = 1;
1174 /* Record current section so we can restore it if dbxout.c clobbers it. */
1175 saved_in_section = in_section;
1177 /* Output the dbx info now that we have chosen the section. */
1179 #ifdef DBX_DEBUGGING_INFO
1180 /* File-scope global variables are output here. */
1181 if (write_symbols == DBX_DEBUG && top_level)
1182 dbxout_symbol (decl, 0);
1184 #ifdef SDB_DEBUGGING_INFO
1185 if (write_symbols == SDB_DEBUG && top_level
1186 /* Leave initialized global vars for end of compilation;
1187 see comment in compile_file. */
1188 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1189 sdbout_symbol (decl, 0);
1192 /* Don't output any DWARF debugging information for variables here.
1193 In the case of local variables, the information for them is output
1194 when we do our recursive traversal of the tree representation for
1195 the entire containing function. In the case of file-scope variables,
1196 we output information for all of them at the very end of compilation
1197 while we are doing our final traversal of the chain of file-scope
1200 /* If the debugging output changed sections, reselect the section
1201 that's supposed to be selected. */
1202 if (in_section != saved_in_section)
1204 /* Switch to the proper section for this data. */
1205 #ifdef SELECT_SECTION
1206 SELECT_SECTION (decl, reloc);
1208 if (TREE_READONLY (decl)
1209 && ! TREE_THIS_VOLATILE (decl)
1210 && DECL_INITIAL (decl)
1211 && (DECL_INITIAL (decl) == error_mark_node
1212 || TREE_CONSTANT (DECL_INITIAL (decl)))
1213 && ! (flag_pic && reloc))
1214 readonly_data_section ();
1220 /* Compute and output the alignment of this data. */
1222 align = DECL_ALIGN (decl);
1223 /* In the case for initialing an array whose length isn't specified,
1224 where we have not yet been able to do the layout,
1225 figure out the proper alignment now. */
1226 if (dont_output_data && DECL_SIZE (decl) == 0
1227 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1228 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1230 /* Some object file formats have a maximum alignment which they support.
1231 In particular, a.out format supports a maximum alignment of 4. */
1232 #ifndef MAX_OFILE_ALIGNMENT
1233 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1235 if (align > MAX_OFILE_ALIGNMENT)
1237 warning_with_decl (decl,
1238 "alignment of `%s' is greater than maximum object file alignment");
1239 align = MAX_OFILE_ALIGNMENT;
1241 #ifdef DATA_ALIGNMENT
1242 /* On some machines, it is good to increase alignment sometimes. */
1243 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1245 #ifdef CONSTANT_ALIGNMENT
1246 if (DECL_INITIAL (decl))
1247 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1250 /* Reset the alignment in case we have made it tighter, so we can benefit
1251 from it in get_pointer_alignment. */
1252 DECL_ALIGN (decl) = align;
1254 if (align > BITS_PER_UNIT)
1256 if (output_bytecode)
1257 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1259 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1262 /* Do any machine/system dependent processing of the object. */
1263 #ifdef ASM_DECLARE_OBJECT_NAME
1264 last_assemble_variable_decl = decl;
1265 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1267 /* Standard thing is just output label for the object. */
1268 if (output_bytecode)
1269 BC_OUTPUT_LABEL (asm_out_file, name);
1271 ASM_OUTPUT_LABEL (asm_out_file, name);
1272 #endif /* ASM_DECLARE_OBJECT_NAME */
1274 if (!dont_output_data)
1276 if (DECL_INITIAL (decl))
1277 /* Output the actual data. */
1278 output_constant (DECL_INITIAL (decl),
1279 int_size_in_bytes (TREE_TYPE (decl)));
1281 /* Leave space for it. */
1282 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1286 #ifdef XCOFF_DEBUGGING_INFO
1287 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1288 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1289 and `aa' hasn't been output yet, the assembler generates a stab entry with
1290 a value of zero, in addition to creating an unnecessary external entry
1291 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1293 /* File-scope global variables are output here. */
1294 if (write_symbols == XCOFF_DEBUG && top_level)
1296 saved_in_section = in_section;
1298 dbxout_symbol (decl, 0);
1300 if (in_section != saved_in_section)
1302 /* Switch to the proper section for this data. */
1303 #ifdef SELECT_SECTION
1304 SELECT_SECTION (decl, reloc);
1306 if (TREE_READONLY (decl)
1307 && ! TREE_THIS_VOLATILE (decl)
1308 && DECL_INITIAL (decl)
1309 && (DECL_INITIAL (decl) == error_mark_node
1310 || TREE_CONSTANT (DECL_INITIAL (decl)))
1311 && ! (flag_pic && reloc))
1312 readonly_data_section ();
1319 /* There must be a statement after a label. */
1324 /* Return 1 if type TYPE contains any pointers. */
1327 contains_pointers_p (type)
1330 switch (TREE_CODE (type))
1333 case REFERENCE_TYPE:
1334 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1335 so I'll play safe and return 1. */
1341 case QUAL_UNION_TYPE:
1344 /* For a type that has fields, see if the fields have pointers. */
1345 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1346 if (TREE_CODE (fields) == FIELD_DECL
1347 && contains_pointers_p (TREE_TYPE (fields)))
1353 /* An array type contains pointers if its element type does. */
1354 return contains_pointers_p (TREE_TYPE (type));
1361 /* Output text storage for constructor CONSTR. Returns rtx of
1365 bc_output_constructor (constr)
1370 /* Must always be a literal; non-literal constructors are handled
1373 if (!TREE_CONSTANT (constr))
1380 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1382 BC_OUTPUT_ALIGN (asm_out_file, i);
1385 output_constant (constr, int_size_in_bytes (TREE_TYPE (constr)));
1389 /* Create storage for constructor CONSTR. */
1392 bc_output_data_constructor (constr)
1397 /* Put in data section */
1401 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1403 BC_OUTPUT_ALIGN (asm_out_file, i);
1405 /* The constructor is filled in at runtime. */
1406 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1410 /* Output something to declare an external symbol to the assembler.
1411 (Most assemblers don't need this, so we normally output nothing.)
1412 Do nothing if DECL is not external. */
1415 assemble_external (decl)
1418 if (output_bytecode)
1421 #ifdef ASM_OUTPUT_EXTERNAL
1422 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1423 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1425 rtx rtl = DECL_RTL (decl);
1427 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1428 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1430 /* Some systems do require some output. */
1431 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1432 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1438 /* Similar, for calling a library function FUN. */
1441 assemble_external_libcall (fun)
1444 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1445 if (!output_bytecode)
1447 /* Declare library function name external when first used, if nec. */
1448 if (! SYMBOL_REF_USED (fun))
1450 SYMBOL_REF_USED (fun) = 1;
1451 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1457 /* Declare the label NAME global. */
1460 assemble_global (name)
1463 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1466 /* Assemble a label named NAME. */
1469 assemble_label (name)
1472 if (output_bytecode)
1473 BC_OUTPUT_LABEL (asm_out_file, name);
1475 ASM_OUTPUT_LABEL (asm_out_file, name);
1478 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1479 If NAME starts with a *, the rest of NAME is output verbatim.
1480 Otherwise NAME is transformed in an implementation-defined way
1481 (usually by the addition of an underscore).
1482 Many macros in the tm file are defined to call this function. */
1485 assemble_name (file, name)
1491 STRIP_NAME_ENCODING (real_name, name);
1492 TREE_SYMBOL_REFERENCED (get_identifier (real_name)) = 1;
1496 if (output_bytecode)
1497 bc_emit_labelref (name);
1499 fputs (&name[1], file);
1503 if (output_bytecode)
1504 BC_OUTPUT_LABELREF (file, name);
1506 ASM_OUTPUT_LABELREF (file, name);
1510 /* Allocate SIZE bytes writable static space with a gensym name
1511 and return an RTX to refer to its address. */
1514 assemble_static_space (size)
1520 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1521 so that each uninitialized object starts on such a boundary. */
1522 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1523 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1524 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1527 if (flag_shared_data)
1531 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1534 namestring = (char *) obstack_alloc (saveable_obstack,
1536 strcpy (namestring, name);
1538 if (output_bytecode)
1539 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1541 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1543 if (output_bytecode)
1545 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1549 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1550 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1552 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1558 /* Assemble the static constant template for function entry trampolines.
1559 This is done at most once per compilation.
1560 Returns an RTX for the address of the template. */
1563 assemble_trampoline_template ()
1569 /* Shouldn't get here */
1570 if (output_bytecode)
1573 /* By default, put trampoline templates in read-only data section. */
1575 #ifdef TRAMPOLINE_SECTION
1576 TRAMPOLINE_SECTION ();
1578 readonly_data_section ();
1581 /* Write the assembler code to define one. */
1582 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1584 ASM_OUTPUT_ALIGN (asm_out_file, align);
1586 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1587 TRAMPOLINE_TEMPLATE (asm_out_file);
1589 /* Record the rtl to refer to it. */
1590 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1592 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1593 return gen_rtx (SYMBOL_REF, Pmode, name);
1596 /* Assemble the integer constant X into an object of SIZE bytes.
1597 X must be either a CONST_INT or CONST_DOUBLE.
1599 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1600 non-zero, abort if we can't output the constant. */
1603 assemble_integer (x, size, force)
1608 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1609 ASM_OUTPUT... macros. */
1613 #ifdef ASM_OUTPUT_CHAR
1615 ASM_OUTPUT_CHAR (asm_out_file, x);
1619 #ifdef ASM_OUTPUT_SHORT
1621 ASM_OUTPUT_SHORT (asm_out_file, x);
1625 #ifdef ASM_OUTPUT_INT
1627 ASM_OUTPUT_INT (asm_out_file, x);
1631 #ifdef ASM_OUTPUT_DOUBLE_INT
1633 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1637 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1639 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1644 /* If we couldn't do it that way, there are two other possibilities: First,
1645 if the machine can output an explicit byte and this is a 1 byte constant,
1646 we can use ASM_OUTPUT_BYTE. */
1648 #ifdef ASM_OUTPUT_BYTE
1649 if (size == 1 && GET_CODE (x) == CONST_INT)
1651 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1656 /* Finally, if SIZE is larger than a single word, try to output the constant
1657 one word at a time. */
1659 if (size > UNITS_PER_WORD)
1662 enum machine_mode mode
1663 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1666 for (i = 0; i < size / UNITS_PER_WORD; i++)
1668 word = operand_subword (x, i, 0, mode);
1673 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1677 if (i == size / UNITS_PER_WORD)
1679 /* If we output at least one word and then could not finish,
1680 there is no valid way to continue. */
1691 /* Assemble the floating-point constant D into an object of size MODE. */
1694 assemble_real (d, mode)
1696 enum machine_mode mode;
1698 jmp_buf output_constant_handler;
1700 if (setjmp (output_constant_handler))
1702 error ("floating point trap outputting a constant");
1703 #ifdef REAL_IS_NOT_DOUBLE
1704 bzero ((char *) &d, sizeof d);
1711 set_float_handler (output_constant_handler);
1715 #ifdef ASM_OUTPUT_BYTE_FLOAT
1717 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1720 #ifdef ASM_OUTPUT_SHORT_FLOAT
1722 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1725 #ifdef ASM_OUTPUT_FLOAT
1727 ASM_OUTPUT_FLOAT (asm_out_file, d);
1731 #ifdef ASM_OUTPUT_DOUBLE
1733 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1737 #ifdef ASM_OUTPUT_LONG_DOUBLE
1740 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1748 set_float_handler (NULL_PTR);
1751 /* Here we combine duplicate floating constants to make
1752 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1754 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1755 They are chained through the CONST_DOUBLE_CHAIN.
1756 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1757 In that case, CONST_DOUBLE_MEM is either a MEM,
1758 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1760 (CONST_DOUBLE_MEM is used only for top-level functions.
1761 See force_const_mem for explanation.) */
1763 static rtx const_double_chain;
1765 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1766 For an integer, I0 is the low-order word and I1 is the high-order word.
1767 For a real number, I0 is the word with the low address
1768 and I1 is the word with the high address. */
1771 immed_double_const (i0, i1, mode)
1772 HOST_WIDE_INT i0, i1;
1773 enum machine_mode mode;
1776 int in_current_obstack;
1778 if (GET_MODE_CLASS (mode) == MODE_INT
1779 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1781 /* We clear out all bits that don't belong in MODE, unless they and our
1782 sign bit are all one. So we get either a reasonable negative value
1783 or a reasonable unsigned value for this mode. */
1784 int width = GET_MODE_BITSIZE (mode);
1785 if (width < HOST_BITS_PER_WIDE_INT
1786 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1787 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1788 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1789 else if (width == HOST_BITS_PER_WIDE_INT
1790 && ! (i1 == ~0 && i0 < 0))
1792 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1793 /* We cannot represent this value as a constant. */
1796 /* If this would be an entire word for the target, but is not for
1797 the host, then sign-extend on the host so that the number will look
1798 the same way on the host that it would on the target.
1800 For example, when building a 64 bit alpha hosted 32 bit sparc
1801 targeted compiler, then we want the 32 bit unsigned value -1 to be
1802 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1803 The later confuses the sparc backend. */
1805 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1806 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1807 i0 |= ((HOST_WIDE_INT) (-1) << width);
1809 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1811 ??? Strictly speaking, this is wrong if we create a CONST_INT
1812 for a large unsigned constant with the size of MODE being
1813 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1814 wider mode. In that case we will mis-interpret it as a negative
1817 Unfortunately, the only alternative is to make a CONST_DOUBLE
1818 for any constant in any mode if it is an unsigned constant larger
1819 than the maximum signed integer in an int on the host. However,
1820 doing this will break everyone that always expects to see a CONST_INT
1821 for SImode and smaller.
1823 We have always been making CONST_INTs in this case, so nothing new
1826 if (width <= HOST_BITS_PER_WIDE_INT)
1827 i1 = (i0 < 0) ? ~0 : 0;
1829 /* If this integer fits in one word, return a CONST_INT. */
1830 if ((i1 == 0 && i0 >= 0)
1831 || (i1 == ~0 && i0 < 0))
1832 return GEN_INT (i0);
1834 /* We use VOIDmode for integers. */
1838 /* Search the chain for an existing CONST_DOUBLE with the right value.
1839 If one is found, return it. */
1841 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1842 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1843 && GET_MODE (r) == mode)
1846 /* No; make a new one and add it to the chain.
1848 We may be called by an optimizer which may be discarding any memory
1849 allocated during its processing (such as combine and loop). However,
1850 we will be leaving this constant on the chain, so we cannot tolerate
1851 freed memory. So switch to saveable_obstack for this allocation
1852 and then switch back if we were in current_obstack. */
1854 push_obstacks_nochange ();
1855 rtl_in_saveable_obstack ();
1856 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1859 /* Don't touch const_double_chain in nested function; see force_const_mem.
1860 Also, don't touch it if not inside any function. */
1861 if (outer_function_chain == 0 && current_function_decl != 0)
1863 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1864 const_double_chain = r;
1867 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1868 Actual use of mem-slot is only through force_const_mem. */
1870 CONST_DOUBLE_MEM (r) = const0_rtx;
1875 /* Return a CONST_DOUBLE for a specified `double' value
1876 and machine mode. */
1879 immed_real_const_1 (d, mode)
1881 enum machine_mode mode;
1883 union real_extract u;
1885 int in_current_obstack;
1887 /* Get the desired `double' value as a sequence of ints
1888 since that is how they are stored in a CONST_DOUBLE. */
1892 /* Detect special cases. */
1894 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1895 if (!bcmp ((char *) &dconst0, (char *) &d, sizeof d))
1896 return CONST0_RTX (mode);
1897 /* Check for NaN first, because some ports (specifically the i386) do not
1898 emit correct ieee-fp code by default, and thus will generate a core
1899 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1900 does a floating point comparison. */
1901 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1902 return CONST1_RTX (mode);
1904 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1905 return immed_double_const (u.i[0], u.i[1], mode);
1907 /* The rest of this function handles the case where
1908 a float value requires more than 2 ints of space.
1909 It will be deleted as dead code on machines that don't need it. */
1911 /* Search the chain for an existing CONST_DOUBLE with the right value.
1912 If one is found, return it. */
1914 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1915 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
1916 && GET_MODE (r) == mode)
1919 /* No; make a new one and add it to the chain.
1921 We may be called by an optimizer which may be discarding any memory
1922 allocated during its processing (such as combine and loop). However,
1923 we will be leaving this constant on the chain, so we cannot tolerate
1924 freed memory. So switch to saveable_obstack for this allocation
1925 and then switch back if we were in current_obstack. */
1927 push_obstacks_nochange ();
1928 rtl_in_saveable_obstack ();
1929 r = rtx_alloc (CONST_DOUBLE);
1931 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
1934 /* Don't touch const_double_chain in nested function; see force_const_mem.
1935 Also, don't touch it if not inside any function. */
1936 if (outer_function_chain == 0 && current_function_decl != 0)
1938 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1939 const_double_chain = r;
1942 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1943 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1944 is only through force_const_mem. */
1946 CONST_DOUBLE_MEM (r) = const0_rtx;
1951 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1952 which must be a REAL_CST tree node. */
1955 immed_real_const (exp)
1958 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1961 /* At the end of a function, forget the memory-constants
1962 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1963 Also clear out real_constant_chain and clear out all the chain-pointers. */
1966 clear_const_double_mem ()
1968 register rtx r, next;
1970 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1971 See force_const_mem for explanation. */
1972 if (outer_function_chain != 0)
1975 for (r = const_double_chain; r; r = next)
1977 next = CONST_DOUBLE_CHAIN (r);
1978 CONST_DOUBLE_CHAIN (r) = 0;
1979 CONST_DOUBLE_MEM (r) = cc0_rtx;
1981 const_double_chain = 0;
1984 /* Given an expression EXP with a constant value,
1985 reduce it to the sum of an assembler symbol and an integer.
1986 Store them both in the structure *VALUE.
1987 Abort if EXP does not reduce. */
1992 HOST_WIDE_INT offset;
1996 decode_addr_const (exp, value)
1998 struct addr_const *value;
2000 register tree target = TREE_OPERAND (exp, 0);
2001 register int offset = 0;
2006 if (TREE_CODE (target) == COMPONENT_REF
2007 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2010 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2011 target = TREE_OPERAND (target, 0);
2013 else if (TREE_CODE (target) == ARRAY_REF)
2015 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2016 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2018 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2019 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2021 target = TREE_OPERAND (target, 0);
2027 switch (TREE_CODE (target))
2031 x = DECL_RTL (target);
2035 if (output_bytecode)
2036 /* FIXME: this may not be correct, check it */
2037 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
2039 x = gen_rtx (MEM, FUNCTION_MODE,
2040 gen_rtx (LABEL_REF, VOIDmode,
2041 label_rtx (TREE_OPERAND (exp, 0))));
2048 x = TREE_CST_RTL (target);
2055 if (!output_bytecode)
2057 if (GET_CODE (x) != MEM)
2063 value->offset = offset;
2066 /* Uniquize all constants that appear in memory.
2067 Each constant in memory thus far output is recorded
2068 in `const_hash_table' with a `struct constant_descriptor'
2069 that contains a polish representation of the value of
2072 We cannot store the trees in the hash table
2073 because the trees may be temporary. */
2075 struct constant_descriptor
2077 struct constant_descriptor *next;
2083 #define MAX_HASH_TABLE 1009
2084 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2086 /* Compute a hash code for a constant expression. */
2093 register int len, hi, i;
2094 register enum tree_code code = TREE_CODE (exp);
2096 if (code == INTEGER_CST)
2098 p = (char *) &TREE_INT_CST_LOW (exp);
2099 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2101 else if (code == REAL_CST)
2103 p = (char *) &TREE_REAL_CST (exp);
2104 len = sizeof TREE_REAL_CST (exp);
2106 else if (code == STRING_CST)
2107 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2108 else if (code == COMPLEX_CST)
2109 return const_hash (TREE_REALPART (exp)) * 5
2110 + const_hash (TREE_IMAGPART (exp));
2111 else if (code == CONSTRUCTOR)
2115 /* For record type, include the type in the hashing.
2116 We do not do so for array types
2117 because (1) the sizes of the elements are sufficient
2118 and (2) distinct array types can have the same constructor.
2119 Instead, we include the array size because the constructor could
2121 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2122 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2125 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2126 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2128 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2129 if (TREE_VALUE (link))
2130 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2134 else if (code == ADDR_EXPR)
2136 struct addr_const value;
2137 decode_addr_const (exp, &value);
2138 if (GET_CODE (value.base) == SYMBOL_REF)
2140 /* Don't hash the address of the SYMBOL_REF;
2141 only use the offset and the symbol name. */
2143 p = XSTR (value.base, 0);
2144 for (i = 0; p[i] != 0; i++)
2145 hi = ((hi * 613) + (unsigned)(p[i]));
2147 else if (GET_CODE (value.base) == LABEL_REF)
2148 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2150 hi &= (1 << HASHBITS) - 1;
2151 hi %= MAX_HASH_TABLE;
2154 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2155 return const_hash (TREE_OPERAND (exp, 0)) * 9
2156 + const_hash (TREE_OPERAND (exp, 1));
2157 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2158 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2160 /* Compute hashing function */
2162 for (i = 0; i < len; i++)
2163 hi = ((hi * 613) + (unsigned)(p[i]));
2165 hi &= (1 << HASHBITS) - 1;
2166 hi %= MAX_HASH_TABLE;
2170 /* Compare a constant expression EXP with a constant-descriptor DESC.
2171 Return 1 if DESC describes a constant with the same value as EXP. */
2174 compare_constant (exp, desc)
2176 struct constant_descriptor *desc;
2178 return 0 != compare_constant_1 (exp, desc->contents);
2181 /* Compare constant expression EXP with a substring P of a constant descriptor.
2182 If they match, return a pointer to the end of the substring matched.
2183 If they do not match, return 0.
2185 Since descriptors are written in polish prefix notation,
2186 this function can be used recursively to test one operand of EXP
2187 against a subdescriptor, and if it succeeds it returns the
2188 address of the subdescriptor for the next operand. */
2191 compare_constant_1 (exp, p)
2195 register char *strp;
2197 register enum tree_code code = TREE_CODE (exp);
2199 if (code != (enum tree_code) *p++)
2202 if (code == INTEGER_CST)
2204 /* Integer constants are the same only if the same width of type. */
2205 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2207 strp = (char *) &TREE_INT_CST_LOW (exp);
2208 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2210 else if (code == REAL_CST)
2212 /* Real constants are the same only if the same width of type. */
2213 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2215 strp = (char *) &TREE_REAL_CST (exp);
2216 len = sizeof TREE_REAL_CST (exp);
2218 else if (code == STRING_CST)
2220 if (flag_writable_strings)
2222 strp = TREE_STRING_POINTER (exp);
2223 len = TREE_STRING_LENGTH (exp);
2224 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2225 sizeof TREE_STRING_LENGTH (exp)))
2227 p += sizeof TREE_STRING_LENGTH (exp);
2229 else if (code == COMPLEX_CST)
2231 p = compare_constant_1 (TREE_REALPART (exp), p);
2232 if (p == 0) return 0;
2233 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2236 else if (code == CONSTRUCTOR)
2239 int length = list_length (CONSTRUCTOR_ELTS (exp));
2242 if (bcmp ((char *) &length, p, sizeof length))
2246 /* For record constructors, insist that the types match.
2247 For arrays, just verify both constructors are for arrays. */
2248 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2249 type = TREE_TYPE (exp);
2252 if (bcmp ((char *) &type, p, sizeof type))
2256 /* For arrays, insist that the size in bytes match. */
2257 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2259 int size = int_size_in_bytes (TREE_TYPE (exp));
2260 if (bcmp ((char *) &size, p, sizeof size))
2265 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2267 if (TREE_VALUE (link))
2269 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2276 if (bcmp ((char *) &zero, p, sizeof zero))
2284 else if (code == ADDR_EXPR)
2286 struct addr_const value;
2287 decode_addr_const (exp, &value);
2288 strp = (char *) &value.offset;
2289 len = sizeof value.offset;
2290 /* Compare the offset. */
2292 if (*p++ != *strp++)
2294 /* Compare symbol name. */
2295 strp = XSTR (value.base, 0);
2296 len = strlen (strp) + 1;
2298 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2300 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2301 if (p == 0) return 0;
2302 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2305 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2307 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2311 /* Compare constant contents. */
2313 if (*p++ != *strp++)
2319 /* Construct a constant descriptor for the expression EXP.
2320 It is up to the caller to enter the descriptor in the hash table. */
2322 static struct constant_descriptor *
2323 record_constant (exp)
2326 struct constant_descriptor *next = 0;
2329 /* Make a struct constant_descriptor. The first two pointers will
2330 be filled in later. Here we just leave space for them. */
2332 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2333 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2334 record_constant_1 (exp);
2335 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2338 /* Add a description of constant expression EXP
2339 to the object growing in `permanent_obstack'.
2340 No need to return its address; the caller will get that
2341 from the obstack when the object is complete. */
2344 record_constant_1 (exp)
2347 register char *strp;
2349 register enum tree_code code = TREE_CODE (exp);
2351 obstack_1grow (&permanent_obstack, (unsigned int) code);
2353 if (code == INTEGER_CST)
2355 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2356 strp = (char *) &TREE_INT_CST_LOW (exp);
2357 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2359 else if (code == REAL_CST)
2361 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2362 strp = (char *) &TREE_REAL_CST (exp);
2363 len = sizeof TREE_REAL_CST (exp);
2365 else if (code == STRING_CST)
2367 if (flag_writable_strings)
2369 strp = TREE_STRING_POINTER (exp);
2370 len = TREE_STRING_LENGTH (exp);
2371 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2372 sizeof TREE_STRING_LENGTH (exp));
2374 else if (code == COMPLEX_CST)
2376 record_constant_1 (TREE_REALPART (exp));
2377 record_constant_1 (TREE_IMAGPART (exp));
2380 else if (code == CONSTRUCTOR)
2383 int length = list_length (CONSTRUCTOR_ELTS (exp));
2386 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2388 /* For record constructors, insist that the types match.
2389 For arrays, just verify both constructors are for arrays. */
2390 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2391 type = TREE_TYPE (exp);
2394 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2396 /* For arrays, insist that the size in bytes match. */
2397 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2399 int size = int_size_in_bytes (TREE_TYPE (exp));
2400 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2403 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2405 if (TREE_VALUE (link))
2406 record_constant_1 (TREE_VALUE (link));
2411 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
2417 else if (code == ADDR_EXPR)
2419 struct addr_const value;
2420 decode_addr_const (exp, &value);
2421 /* Record the offset. */
2422 obstack_grow (&permanent_obstack,
2423 (char *) &value.offset, sizeof value.offset);
2424 /* Record the symbol name. */
2425 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2426 strlen (XSTR (value.base, 0)) + 1);
2429 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2431 record_constant_1 (TREE_OPERAND (exp, 0));
2432 record_constant_1 (TREE_OPERAND (exp, 1));
2435 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2437 record_constant_1 (TREE_OPERAND (exp, 0));
2441 /* Record constant contents. */
2442 obstack_grow (&permanent_obstack, strp, len);
2445 /* Record a list of constant expressions that were passed to
2446 output_constant_def but that could not be output right away. */
2448 struct deferred_constant
2450 struct deferred_constant *next;
2456 static struct deferred_constant *deferred_constants;
2458 /* Nonzero means defer output of addressed subconstants
2459 (i.e., those for which output_constant_def is called.) */
2460 static int defer_addressed_constants_flag;
2462 /* Start deferring output of subconstants. */
2465 defer_addressed_constants ()
2467 defer_addressed_constants_flag++;
2470 /* Stop deferring output of subconstants,
2471 and output now all those that have been deferred. */
2474 output_deferred_addressed_constants ()
2476 struct deferred_constant *p, *next;
2478 defer_addressed_constants_flag--;
2480 if (defer_addressed_constants_flag > 0)
2483 for (p = deferred_constants; p; p = next)
2485 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2490 deferred_constants = 0;
2493 /* Make a copy of the whole tree structure for a constant.
2494 This handles the same types of nodes that compare_constant
2495 and record_constant handle. */
2501 switch (TREE_CODE (exp))
2507 /* For ADDR_EXPR, we do not want to copy the decl
2508 whose address is requested. */
2509 return copy_node (exp);
2512 return build_complex (copy_constant (TREE_REALPART (exp)),
2513 copy_constant (TREE_IMAGPART (exp)));
2517 return build (TREE_CODE (exp), TREE_TYPE (exp),
2518 copy_constant (TREE_OPERAND (exp, 0)),
2519 copy_constant (TREE_OPERAND (exp, 1)));
2523 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2524 copy_constant (TREE_OPERAND (exp, 0)));
2528 tree copy = copy_node (exp);
2529 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2532 CONSTRUCTOR_ELTS (copy) = list;
2533 for (tail = list; tail; tail = TREE_CHAIN (tail))
2534 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2544 /* Return an rtx representing a reference to constant data in memory
2545 for the constant expression EXP.
2547 If assembler code for such a constant has already been output,
2548 return an rtx to refer to it.
2549 Otherwise, output such a constant in memory (or defer it for later)
2550 and generate an rtx for it.
2552 The TREE_CST_RTL of EXP is set up to point to that rtx.
2553 The const_hash_table records which constants already have label strings. */
2556 output_constant_def (exp)
2560 register struct constant_descriptor *desc;
2566 if (TREE_CODE (exp) == INTEGER_CST)
2567 abort (); /* No TREE_CST_RTL slot in these. */
2569 if (TREE_CST_RTL (exp))
2570 return TREE_CST_RTL (exp);
2572 /* Make sure any other constants whose addresses appear in EXP
2573 are assigned label numbers. */
2575 reloc = output_addressed_constants (exp);
2577 /* Compute hash code of EXP. Search the descriptors for that hash code
2578 to see if any of them describes EXP. If yes, the descriptor records
2579 the label number already assigned. */
2581 hash = const_hash (exp) % MAX_HASH_TABLE;
2583 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2584 if (compare_constant (exp, desc))
2586 found = desc->label;
2592 /* No constant equal to EXP is known to have been output.
2593 Make a constant descriptor to enter EXP in the hash table.
2594 Assign the label number and record it in the descriptor for
2595 future calls to this function to find. */
2597 /* Create a string containing the label name, in LABEL. */
2598 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2600 desc = record_constant (exp);
2601 desc->next = const_hash_table[hash];
2603 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2604 const_hash_table[hash] = desc;
2608 /* Create a string containing the label name, in LABEL. */
2609 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2612 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2614 push_obstacks_nochange ();
2615 if (TREE_PERMANENT (exp))
2616 end_temporary_allocation ();
2618 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2621 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2622 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2623 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2624 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2628 /* Optionally set flags or add text to the name to record information
2629 such as that it is a function name. If the name is changed, the macro
2630 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2631 #ifdef ENCODE_SECTION_INFO
2632 ENCODE_SECTION_INFO (exp);
2635 /* If this is the first time we've seen this particular constant,
2636 output it (or defer its output for later). */
2639 if (defer_addressed_constants_flag)
2641 struct deferred_constant *p;
2642 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2644 push_obstacks_nochange ();
2645 suspend_momentary ();
2646 p->exp = copy_constant (exp);
2649 p->labelno = const_labelno++;
2650 p->next = deferred_constants;
2651 deferred_constants = p;
2654 output_constant_def_contents (exp, reloc, const_labelno++);
2657 return TREE_CST_RTL (exp);
2660 /* Now output assembler code to define the label for EXP,
2661 and follow it with the data of EXP. */
2664 output_constant_def_contents (exp, reloc, labelno)
2671 if (IN_NAMED_SECTION (exp))
2672 named_section (TREE_STRING_POINTER (DECL_SECTION_NAME (exp)));
2675 /* First switch to text section, except for writable strings. */
2676 #ifdef SELECT_SECTION
2677 SELECT_SECTION (exp, reloc);
2679 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2680 || (flag_pic && reloc))
2683 readonly_data_section ();
2687 /* Align the location counter as required by EXP's data type. */
2688 align = TYPE_ALIGN (TREE_TYPE (exp));
2689 #ifdef CONSTANT_ALIGNMENT
2690 align = CONSTANT_ALIGNMENT (exp, align);
2693 if (align > BITS_PER_UNIT)
2695 if (!output_bytecode)
2697 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2701 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2705 /* Output the label itself. */
2706 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2708 /* Output the value of EXP. */
2709 output_constant (exp,
2710 (TREE_CODE (exp) == STRING_CST
2711 ? TREE_STRING_LENGTH (exp)
2712 : int_size_in_bytes (TREE_TYPE (exp))));
2716 /* Similar hash facility for making memory-constants
2717 from constant rtl-expressions. It is used on RISC machines
2718 where immediate integer arguments and constant addresses are restricted
2719 so that such constants must be stored in memory.
2721 This pool of constants is reinitialized for each function
2722 so each function gets its own constants-pool that comes right before it.
2724 All structures allocated here are discarded when functions are saved for
2725 inlining, so they do not need to be allocated permanently. */
2727 #define MAX_RTX_HASH_TABLE 61
2728 static struct constant_descriptor **const_rtx_hash_table;
2730 /* Structure to represent sufficient information about a constant so that
2731 it can be output when the constant pool is output, so that function
2732 integration can be done, and to simplify handling on machines that reference
2733 constant pool as base+displacement. */
2735 struct pool_constant
2737 struct constant_descriptor *desc;
2738 struct pool_constant *next;
2739 enum machine_mode mode;
2746 /* Pointers to first and last constant in pool. */
2748 static struct pool_constant *first_pool, *last_pool;
2750 /* Current offset in constant pool (does not include any machine-specific
2753 static int pool_offset;
2755 /* Structure used to maintain hash table mapping symbols used to their
2756 corresponding constants. */
2761 struct pool_constant *pool;
2762 struct pool_sym *next;
2765 static struct pool_sym **const_rtx_sym_hash_table;
2767 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2768 The argument is XSTR (... , 0) */
2770 #define SYMHASH(LABEL) \
2771 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2773 /* Initialize constant pool hashing for next function. */
2776 init_const_rtx_hash_table ()
2778 const_rtx_hash_table
2779 = ((struct constant_descriptor **)
2780 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2781 const_rtx_sym_hash_table
2782 = ((struct pool_sym **)
2783 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2784 bzero ((char *) const_rtx_hash_table,
2785 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2786 bzero ((char *) const_rtx_sym_hash_table,
2787 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2789 first_pool = last_pool = 0;
2793 /* Save and restore it for a nested function. */
2796 save_varasm_status (p)
2799 p->const_rtx_hash_table = const_rtx_hash_table;
2800 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2801 p->first_pool = first_pool;
2802 p->last_pool = last_pool;
2803 p->pool_offset = pool_offset;
2807 restore_varasm_status (p)
2810 const_rtx_hash_table = p->const_rtx_hash_table;
2811 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2812 first_pool = p->first_pool;
2813 last_pool = p->last_pool;
2814 pool_offset = p->pool_offset;
2817 enum kind { RTX_DOUBLE, RTX_INT };
2821 #ifdef ONLY_INT_FIELDS
2822 unsigned int kind : 16;
2823 unsigned int mode : 16;
2825 enum kind kind : 16;
2826 enum machine_mode mode : 16;
2829 union real_extract du;
2830 struct addr_const addr;
2834 /* Express an rtx for a constant integer (perhaps symbolic)
2835 as the sum of a symbol or label plus an explicit integer.
2836 They are stored into VALUE. */
2839 decode_rtx_const (mode, x, value)
2840 enum machine_mode mode;
2842 struct rtx_const *value;
2844 /* Clear the whole structure, including any gaps. */
2847 int *p = (int *) value;
2848 int *end = (int *) (value + 1);
2853 value->kind = RTX_INT; /* Most usual kind. */
2856 switch (GET_CODE (x))
2859 value->kind = RTX_DOUBLE;
2860 if (GET_MODE (x) != VOIDmode)
2861 value->mode = GET_MODE (x);
2862 bcopy ((char *) &CONST_DOUBLE_LOW (x),
2863 (char *) &value->un.du, sizeof value->un.du);
2867 value->un.addr.offset = INTVAL (x);
2873 value->un.addr.base = x;
2878 if (GET_CODE (x) == PLUS)
2880 value->un.addr.base = XEXP (x, 0);
2881 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2883 value->un.addr.offset = INTVAL (XEXP (x, 1));
2885 else if (GET_CODE (x) == MINUS)
2887 value->un.addr.base = XEXP (x, 0);
2888 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2890 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2900 if (value->kind == RTX_INT && value->un.addr.base != 0)
2901 switch (GET_CODE (value->un.addr.base))
2905 /* Use the string's address, not the SYMBOL_REF's address,
2906 for the sake of addresses of library routines.
2907 For a LABEL_REF, compare labels. */
2908 value->un.addr.base = XEXP (value->un.addr.base, 0);
2912 /* Given a MINUS expression, simplify it if both sides
2913 include the same symbol. */
2916 simplify_subtraction (x)
2919 struct rtx_const val0, val1;
2921 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2922 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2924 if (val0.un.addr.base == val1.un.addr.base)
2925 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2929 /* Compute a hash code for a constant RTL expression. */
2932 const_hash_rtx (mode, x)
2933 enum machine_mode mode;
2938 struct rtx_const value;
2939 decode_rtx_const (mode, x, &value);
2941 /* Compute hashing function */
2943 for (i = 0; i < sizeof value / sizeof (int); i++)
2944 hi += ((int *) &value)[i];
2946 hi &= (1 << HASHBITS) - 1;
2947 hi %= MAX_RTX_HASH_TABLE;
2951 /* Compare a constant rtl object X with a constant-descriptor DESC.
2952 Return 1 if DESC describes a constant with the same value as X. */
2955 compare_constant_rtx (mode, x, desc)
2956 enum machine_mode mode;
2958 struct constant_descriptor *desc;
2960 register int *p = (int *) desc->contents;
2963 struct rtx_const value;
2965 decode_rtx_const (mode, x, &value);
2966 strp = (int *) &value;
2967 len = sizeof value / sizeof (int);
2969 /* Compare constant contents. */
2971 if (*p++ != *strp++)
2977 /* Construct a constant descriptor for the rtl-expression X.
2978 It is up to the caller to enter the descriptor in the hash table. */
2980 static struct constant_descriptor *
2981 record_constant_rtx (mode, x)
2982 enum machine_mode mode;
2985 struct constant_descriptor *ptr;
2987 struct rtx_const value;
2989 decode_rtx_const (mode, x, &value);
2991 /* Put these things in the saveable obstack so we can ensure it won't
2992 be freed if we are called from combine or some other phase that discards
2993 memory allocated from function_obstack (current_obstack). */
2994 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
2995 obstack_grow (saveable_obstack, &label, sizeof label);
2997 /* Record constant contents. */
2998 obstack_grow (saveable_obstack, &value, sizeof value);
3000 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3003 /* Given a constant rtx X, make (or find) a memory constant for its value
3004 and return a MEM rtx to refer to it in memory. */
3007 force_const_mem (mode, x)
3008 enum machine_mode mode;
3012 register struct constant_descriptor *desc;
3017 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3018 (this will always be true for floating CONST_DOUBLEs that have been
3019 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3020 use the previous copy. Otherwise, make a new one. Note that in
3021 the unlikely event that this same CONST_DOUBLE is used in two different
3022 modes in an alternating fashion, we will allocate a lot of different
3023 memory locations, but this should be extremely rare. */
3025 /* Don't use CONST_DOUBLE_MEM in a nested function.
3026 Nested functions have their own constant pools,
3027 so they can't share the same values in CONST_DOUBLE_MEM
3028 with the containing function. */
3029 if (outer_function_chain == 0)
3030 if (GET_CODE (x) == CONST_DOUBLE
3031 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3032 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3033 return CONST_DOUBLE_MEM (x);
3035 /* Compute hash code of X. Search the descriptors for that hash code
3036 to see if any of them describes X. If yes, the descriptor records
3037 the label number already assigned. */
3039 hash = const_hash_rtx (mode, x);
3041 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3042 if (compare_constant_rtx (mode, x, desc))
3044 found = desc->label;
3050 register struct pool_constant *pool;
3051 register struct pool_sym *sym;
3054 /* No constant equal to X is known to have been output.
3055 Make a constant descriptor to enter X in the hash table.
3056 Assign the label number and record it in the descriptor for
3057 future calls to this function to find. */
3059 desc = record_constant_rtx (mode, x);
3060 desc->next = const_rtx_hash_table[hash];
3061 const_rtx_hash_table[hash] = desc;
3063 /* Align the location counter as required by EXP's data type. */
3064 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3065 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3066 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3068 pool_offset += align - 1;
3069 pool_offset &= ~ (align - 1);
3071 /* If RTL is not being placed into the saveable obstack, make a
3072 copy of X that is in the saveable obstack in case we are being
3073 called from combine or some other phase that discards memory
3074 it allocates. We need only do this if it is a CONST, since
3075 no other RTX should be allocated in this situation. */
3076 if (rtl_obstack != saveable_obstack
3077 && GET_CODE (x) == CONST)
3079 push_obstacks_nochange ();
3080 rtl_in_saveable_obstack ();
3082 x = gen_rtx (CONST, GET_MODE (x),
3083 gen_rtx (PLUS, GET_MODE (x),
3084 XEXP (XEXP (x, 0), 0), XEXP (XEXP (x, 0), 1)));
3088 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3090 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3094 pool->labelno = const_labelno;
3095 pool->align = align;
3096 pool->offset = pool_offset;
3102 last_pool->next = pool;
3105 pool_offset += GET_MODE_SIZE (mode);
3107 /* Create a string containing the label name, in LABEL. */
3108 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3113 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3115 /* Add label to symbol hash table. */
3116 hash = SYMHASH (found);
3117 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3120 sym->next = const_rtx_sym_hash_table[hash];
3121 const_rtx_sym_hash_table[hash] = sym;
3124 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3126 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3128 RTX_UNCHANGING_P (def) = 1;
3129 /* Mark the symbol_ref as belonging to this constants pool. */
3130 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3131 current_function_uses_const_pool = 1;
3133 if (outer_function_chain == 0)
3134 if (GET_CODE (x) == CONST_DOUBLE)
3136 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3138 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3139 const_double_chain = x;
3141 CONST_DOUBLE_MEM (x) = def;
3147 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3148 the corresponding pool_constant structure. */
3150 static struct pool_constant *
3151 find_pool_constant (addr)
3154 struct pool_sym *sym;
3155 char *label = XSTR (addr, 0);
3157 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3158 if (sym->label == label)
3164 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3167 get_pool_constant (addr)
3170 return (find_pool_constant (addr))->constant;
3173 /* Similar, return the mode. */
3176 get_pool_mode (addr)
3179 return (find_pool_constant (addr))->mode;
3182 /* Similar, return the offset in the constant pool. */
3185 get_pool_offset (addr)
3188 return (find_pool_constant (addr))->offset;
3191 /* Return the size of the constant pool. */
3199 /* Write all the constants in the constant pool. */
3202 output_constant_pool (fnname, fndecl)
3206 struct pool_constant *pool;
3208 union real_extract u;
3210 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3211 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3214 for (pool = first_pool; pool; pool = pool->next)
3218 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3219 whose CODE_LABEL has been deleted. This can occur if a jump table
3220 is eliminated by optimization. If so, write a constant of zero
3221 instead. Note that this can also happen by turning the
3222 CODE_LABEL into a NOTE. */
3223 if (((GET_CODE (x) == LABEL_REF
3224 && (INSN_DELETED_P (XEXP (x, 0))
3225 || GET_CODE (XEXP (x, 0)) == NOTE)))
3226 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3227 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3228 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3229 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3232 /* First switch to correct section. */
3233 #ifdef SELECT_RTX_SECTION
3234 SELECT_RTX_SECTION (pool->mode, x);
3236 readonly_data_section ();
3239 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3240 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3241 pool->align, pool->labelno, done);
3244 if (pool->align > 1)
3245 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3247 /* Output the label. */
3248 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3250 /* Output the value of the constant itself. */
3251 switch (GET_MODE_CLASS (pool->mode))
3254 if (GET_CODE (x) != CONST_DOUBLE)
3257 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3258 assemble_real (u.d, pool->mode);
3262 case MODE_PARTIAL_INT:
3263 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3273 /* Done with this pool. */
3274 first_pool = last_pool = 0;
3277 /* Find all the constants whose addresses are referenced inside of EXP,
3278 and make sure assembler code with a label has been output for each one.
3279 Indicate whether an ADDR_EXPR has been encountered. */
3282 output_addressed_constants (exp)
3287 switch (TREE_CODE (exp))
3291 register tree constant = TREE_OPERAND (exp, 0);
3293 while (TREE_CODE (constant) == COMPONENT_REF)
3295 constant = TREE_OPERAND (constant, 0);
3298 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3299 || TREE_CODE (constant) == CONSTRUCTOR)
3300 /* No need to do anything here
3301 for addresses of variables or functions. */
3302 output_constant_def (constant);
3309 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3310 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3315 case NON_LVALUE_EXPR:
3316 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3322 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3323 if (TREE_VALUE (link) != 0)
3324 reloc |= output_addressed_constants (TREE_VALUE (link));
3335 /* Output assembler for byte constant */
3337 output_byte_asm (byte)
3340 if (output_bytecode)
3341 bc_emit_const ((char *) &byte, sizeof (char));
3342 #ifdef ASM_OUTPUT_BYTE
3345 ASM_OUTPUT_BYTE (asm_out_file, byte);
3350 /* Output assembler code for constant EXP to FILE, with no label.
3351 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3352 Assumes output_addressed_constants has been done on EXP already.
3354 Generate exactly SIZE bytes of assembler data, padding at the end
3355 with zeros if necessary. SIZE must always be specified.
3357 SIZE is important for structure constructors,
3358 since trailing members may have been omitted from the constructor.
3359 It is also important for initialization of arrays from string constants
3360 since the full length of the string constant might not be wanted.
3361 It is also needed for initialization of unions, where the initializer's
3362 type is just one member, and that may not be as long as the union.
3364 There a case in which we would fail to output exactly SIZE bytes:
3365 for a structure constructor that wants to produce more than SIZE bytes.
3366 But such constructors will never be generated for any possible input. */
3369 output_constant (exp, size)
3373 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3379 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3380 That way we get the constant (we hope) inside it. Also, strip
3381 off any NOP_EXPR that converts between two record or union types. */
3382 while ((TREE_CODE (exp) == NOP_EXPR
3383 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3384 || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3385 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
3386 || TREE_CODE (TREE_TYPE (exp)) == QUAL_UNION_TYPE))
3387 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3388 exp = TREE_OPERAND (exp, 0);
3390 /* Allow a constructor with no elements for any data type.
3391 This means to fill the space with zeros. */
3392 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3394 if (output_bytecode)
3395 bc_emit_const_skip (size);
3397 assemble_zeros (size);
3408 case REFERENCE_TYPE:
3409 /* ??? What about (int)((float)(int)&foo + 4) */
3410 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3411 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3412 exp = TREE_OPERAND (exp, 0);
3414 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3415 EXPAND_INITIALIZER),
3417 error ("initializer for integer value is too complicated");
3422 if (TREE_CODE (exp) != REAL_CST)
3423 error ("initializer for floating value is not a floating constant");
3425 assemble_real (TREE_REAL_CST (exp),
3426 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3431 output_constant (TREE_REALPART (exp), size / 2);
3432 output_constant (TREE_IMAGPART (exp), size / 2);
3433 size -= (size / 2) * 2;
3437 if (TREE_CODE (exp) == CONSTRUCTOR)
3439 output_constructor (exp, size);
3442 else if (TREE_CODE (exp) == STRING_CST)
3446 if (size > TREE_STRING_LENGTH (exp))
3448 excess = size - TREE_STRING_LENGTH (exp);
3449 size = TREE_STRING_LENGTH (exp);
3452 assemble_string (TREE_STRING_POINTER (exp), size);
3461 if (TREE_CODE (exp) == CONSTRUCTOR)
3462 output_constructor (exp, size);
3469 assemble_zeros (size);
3473 /* Bytecode specific code to output assembler for integer. */
3475 bc_assemble_integer (exp, size)
3483 /* FIXME: is this fold() business going to be as good as the
3484 expand_expr() using EXPAND_SUM above in the RTL case? I
3486 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3490 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3491 exp = TREE_OPERAND (exp, 0);
3492 if (TREE_CODE (exp) == INTEGER_CST)
3497 else if (TREE_CODE (exp) == PLUS_EXPR)
3499 const_part = TREE_OPERAND (exp, 0);
3500 while (TREE_CODE (const_part) == NOP_EXPR
3501 || TREE_CODE (const_part) == CONVERT_EXPR)
3502 const_part = TREE_OPERAND (const_part, 0);
3503 addr_part = TREE_OPERAND (exp, 1);
3504 while (TREE_CODE (addr_part) == NOP_EXPR
3505 || TREE_CODE (addr_part) == CONVERT_EXPR)
3506 addr_part = TREE_OPERAND (addr_part, 0);
3507 if (TREE_CODE (const_part) != INTEGER_CST)
3508 tmp = const_part, const_part = addr_part, addr_part = tmp;
3509 if (TREE_CODE (const_part) != INTEGER_CST
3510 || TREE_CODE (addr_part) != ADDR_EXPR)
3511 abort (); /* FIXME: we really haven't considered
3512 all the possible cases here. */
3514 else if (TREE_CODE (exp) == ADDR_EXPR)
3516 const_part = integer_zero_node;
3520 abort (); /* FIXME: ditto previous. */
3526 char c = TREE_INT_CST_LOW (const_part);
3532 short s = TREE_INT_CST_LOW (const_part);
3533 bc_emit ((char *) &s, 2);
3538 int i = TREE_INT_CST_LOW (const_part);
3539 bc_emit ((char *) &i, 4);
3544 #if WORDS_BIG_ENDIAN
3545 int i = TREE_INT_CST_HIGH (const_part);
3546 bc_emit ((char *) &i, 4);
3547 i = TREE_INT_CST_LOW (const_part);
3548 bc_emit ((char *) &i, 4);
3550 int i = TREE_INT_CST_LOW (const_part);
3551 bc_emit ((char *) &i, 4);
3552 i = TREE_INT_CST_HIGH (const_part);
3553 bc_emit ((char *) &i, 4);
3560 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3561 bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3562 TREE_INT_CST_LOW (const_part));
3564 abort (); /* FIXME: there may be more cases. */
3567 /* Subroutine of output_constant, used for CONSTRUCTORs
3568 (aggregate constants).
3569 Generate at least SIZE bytes, padding if necessary. */
3572 output_constructor (exp, size)
3576 register tree link, field = 0;
3577 HOST_WIDE_INT min_index = 0;
3578 /* Number of bytes output or skipped so far.
3579 In other words, current position within the constructor. */
3580 int total_bytes = 0;
3581 /* Non-zero means BYTE contains part of a byte, to be output. */
3582 int byte_buffer_in_use = 0;
3585 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3588 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3589 field = TYPE_FIELDS (TREE_TYPE (exp));
3591 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3592 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3594 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3596 /* As LINK goes through the elements of the constant,
3597 FIELD goes through the structure fields, if the constant is a structure.
3598 if the constant is a union, then we override this,
3599 by getting the field from the TREE_LIST element.
3600 But the constant could also be an array. Then FIELD is zero. */
3601 for (link = CONSTRUCTOR_ELTS (exp);
3603 link = TREE_CHAIN (link),
3604 field = field ? TREE_CHAIN (field) : 0)
3606 tree val = TREE_VALUE (link);
3609 /* the element in a union constructor specifies the proper field. */
3611 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3612 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3614 /* if available, use the type given by link */
3615 if (TREE_PURPOSE (link) != 0)
3616 field = TREE_PURPOSE (link);
3619 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3620 index = TREE_PURPOSE (link);
3622 /* Eliminate the marker that makes a cast not be an lvalue. */
3626 if (field == 0 || !DECL_BIT_FIELD (field))
3628 /* An element that is not a bit-field. */
3630 register int fieldsize;
3631 /* Since this structure is static,
3632 we know the positions are constant. */
3633 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3637 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3639 * (TREE_INT_CST_LOW (index) - min_index));
3641 /* Output any buffered-up bit-fields preceding this element. */
3642 if (byte_buffer_in_use)
3644 ASM_OUTPUT_BYTE (asm_out_file, byte);
3646 byte_buffer_in_use = 0;
3649 /* Advance to offset of this element.
3650 Note no alignment needed in an array, since that is guaranteed
3651 if each element has the proper size. */
3652 if ((field != 0 || index != 0) && bitpos != total_bytes)
3654 if (!output_bytecode)
3655 assemble_zeros (bitpos - total_bytes);
3657 bc_emit_const_skip (bitpos - total_bytes);
3658 total_bytes = bitpos;
3661 /* Determine size this element should occupy. */
3664 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3666 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3668 /* This avoids overflow trouble. */
3669 tree size_tree = size_binop (CEIL_DIV_EXPR,
3671 size_int (BITS_PER_UNIT));
3672 fieldsize = TREE_INT_CST_LOW (size_tree);
3676 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3677 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3681 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3683 /* Output the element's initial value. */
3685 assemble_zeros (fieldsize);
3687 output_constant (val, fieldsize);
3689 /* Count its size. */
3690 total_bytes += fieldsize;
3692 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3693 error ("invalid initial value for member `%s'",
3694 IDENTIFIER_POINTER (DECL_NAME (field)));
3697 /* Element that is a bit-field. */
3699 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3701 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3704 val = integer_zero_node;
3706 /* If this field does not start in this (or, next) byte,
3708 if (next_offset / BITS_PER_UNIT != total_bytes)
3710 /* Output remnant of any bit field in previous bytes. */
3711 if (byte_buffer_in_use)
3713 ASM_OUTPUT_BYTE (asm_out_file, byte);
3715 byte_buffer_in_use = 0;
3718 /* If still not at proper byte, advance to there. */
3719 if (next_offset / BITS_PER_UNIT != total_bytes)
3721 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3722 total_bytes = next_offset / BITS_PER_UNIT;
3726 if (! byte_buffer_in_use)
3729 /* We must split the element into pieces that fall within
3730 separate bytes, and combine each byte with previous or
3731 following bit-fields. */
3733 /* next_offset is the offset n fbits from the beginning of
3734 the structure to the next bit of this element to be processed.
3735 end_offset is the offset of the first bit past the end of
3737 while (next_offset < end_offset)
3741 int next_byte = next_offset / BITS_PER_UNIT;
3742 int next_bit = next_offset % BITS_PER_UNIT;
3744 /* Advance from byte to byte
3745 within this element when necessary. */
3746 while (next_byte != total_bytes)
3748 ASM_OUTPUT_BYTE (asm_out_file, byte);
3753 /* Number of bits we can process at once
3754 (all part of the same byte). */
3755 this_time = MIN (end_offset - next_offset,
3756 BITS_PER_UNIT - next_bit);
3757 #if BYTES_BIG_ENDIAN
3758 /* On big-endian machine, take the most significant bits
3759 first (of the bits that are significant)
3760 and put them into bytes from the most significant end. */
3761 shift = end_offset - next_offset - this_time;
3762 /* Don't try to take a bunch of bits that cross
3763 the word boundary in the INTEGER_CST. */
3764 if (shift < HOST_BITS_PER_WIDE_INT
3765 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3767 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3768 shift = HOST_BITS_PER_WIDE_INT;
3771 /* Now get the bits from the appropriate constant word. */
3772 if (shift < HOST_BITS_PER_WIDE_INT)
3774 value = TREE_INT_CST_LOW (val);
3776 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3778 value = TREE_INT_CST_HIGH (val);
3779 shift -= HOST_BITS_PER_WIDE_INT;
3783 byte |= (((value >> shift)
3784 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3785 << (BITS_PER_UNIT - this_time - next_bit));
3787 /* On little-endian machines,
3788 take first the least significant bits of the value
3789 and pack them starting at the least significant
3790 bits of the bytes. */
3791 shift = (next_offset
3792 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3793 /* Don't try to take a bunch of bits that cross
3794 the word boundary in the INTEGER_CST. */
3795 if (shift < HOST_BITS_PER_WIDE_INT
3796 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3798 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3799 shift = HOST_BITS_PER_WIDE_INT;
3802 /* Now get the bits from the appropriate constant word. */
3803 if (shift < HOST_BITS_PER_INT)
3804 value = TREE_INT_CST_LOW (val);
3805 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3807 value = TREE_INT_CST_HIGH (val);
3808 shift -= HOST_BITS_PER_WIDE_INT;
3812 byte |= ((value >> shift)
3813 & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
3815 next_offset += this_time;
3816 byte_buffer_in_use = 1;
3820 if (byte_buffer_in_use)
3822 ASM_OUTPUT_BYTE (asm_out_file, byte);
3825 if (total_bytes < size)
3826 assemble_zeros (size - total_bytes);
3830 #ifdef HANDLE_SYSV_PRAGMA
3832 /* Support #pragma weak by default if WEAK_ASM_OP and ASM_OUTPUT_DEF
3834 #if defined (WEAK_ASM_OP) && defined (ASM_OUTPUT_DEF)
3836 /* See c-pragma.c for an identical definition. */
3852 /* Output asm to handle ``#pragma weak'' */
3854 handle_pragma_weak (what, asm_out_file, name, value)
3855 enum pragma_state what;
3859 if (what == ps_name || what == ps_value)
3861 fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
3863 if (output_bytecode)
3864 BC_OUTPUT_LABELREF (asm_out_file, name);
3866 ASM_OUTPUT_LABELREF (asm_out_file, name);
3868 fputc ('\n', asm_out_file);
3869 if (what == ps_value)
3870 ASM_OUTPUT_DEF (asm_out_file, name, value);
3872 else if (! (what == ps_done || what == ps_start))
3873 warning ("malformed `#pragma weak'");
3876 #endif /* HANDLE_PRAGMA_WEAK or (WEAK_ASM_OP and SET_ASM_OP) */
3878 #endif /* WEAK_ASM_OP && ASM_OUTPUT_DEF */