(distribute_notes, case REG_DEAD): If a call uses a
[official-gcc.git] / gcc / varasm.c
blob928a941f48559dc46808558320b2840b1acac8bf
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)
9 any later version.
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. */
28 #include <stdio.h>
29 #include <setjmp.h>
30 /* #include <stab.h> */
31 #include "config.h"
32 #include "rtl.h"
33 #include "tree.h"
34 #include "flags.h"
35 #include "function.h"
36 #include "expr.h"
37 #include "hard-reg-set.h"
38 #include "regs.h"
39 #include "defaults.h"
40 #include "real.h"
41 #include "bytecode.h"
43 #include "obstack.h"
45 #ifdef XCOFF_DEBUGGING_INFO
46 #include "xcoffout.h"
47 #endif
49 #include <ctype.h>
51 #ifndef ASM_STABS_OP
52 #define ASM_STABS_OP ".stabs"
53 #endif
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] == '*'))
61 #endif
63 /* File in which assembler code is being written. */
65 extern FILE *asm_out_file;
67 /* The (assembler) name of the first globally-visible object output. */
68 char *first_global_object_name;
70 extern struct obstack *current_obstack;
71 extern struct obstack *saveable_obstack;
72 extern struct obstack permanent_obstack;
73 #define obstack_chunk_alloc xmalloc
75 /* Number for making the label on the next
76 constant that is stored in memory. */
78 int const_labelno;
80 /* Number for making the label on the next
81 static variable internal to a function. */
83 int var_labelno;
85 /* Carry information from ASM_DECLARE_OBJECT_NAME
86 to ASM_FINISH_DECLARE_OBJECT. */
88 int size_directive_output;
90 /* The last decl for which assemble_variable was called,
91 if it did ASM_DECLARE_OBJECT_NAME.
92 If the last call to assemble_variable didn't do that,
93 this holds 0. */
95 tree last_assemble_variable_decl;
97 /* Nonzero if at least one function definition has been seen. */
98 static int function_defined;
100 extern FILE *asm_out_file;
102 static char *compare_constant_1 ();
103 static void record_constant_1 ();
104 static void output_constant_def_contents ();
105 static int contains_pointers_p ();
106 static void bc_output_ascii ();
108 void output_constant_pool ();
109 void assemble_name ();
110 int output_addressed_constants ();
111 void output_constant ();
112 void output_constructor ();
113 void output_byte_asm ();
114 void text_section ();
115 void readonly_data_section ();
116 void data_section ();
117 void named_section ();
118 static void bc_assemble_integer ();
120 #ifdef EXTRA_SECTIONS
121 static enum in_section {no_section, in_text, in_data, in_named, EXTRA_SECTIONS} in_section
122 = no_section;
123 #else
124 static enum in_section {no_section, in_text, in_data, in_named} in_section
125 = no_section;
126 #endif
128 /* Return a non-zero value if DECL has a section attribute. */
129 #define IN_NAMED_SECTION(DECL) \
130 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
131 && DECL_SECTION_NAME (DECL) != NULL_TREE)
133 /* Text of section name when in_section == in_named. */
134 static char *in_named_name;
136 /* Define functions like text_section for any extra sections. */
137 #ifdef EXTRA_SECTION_FUNCTIONS
138 EXTRA_SECTION_FUNCTIONS
139 #endif
141 /* Tell assembler to switch to text section. */
143 void
144 text_section ()
146 if (in_section != in_text)
148 if (output_bytecode)
149 bc_text ();
150 else
151 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
153 in_section = in_text;
157 /* Tell assembler to switch to data section. */
159 void
160 data_section ()
162 if (in_section != in_data)
164 if (output_bytecode)
165 bc_data ();
166 else
168 if (flag_shared_data)
170 #ifdef SHARED_SECTION_ASM_OP
171 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
172 #else
173 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
174 #endif
176 else
177 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
180 in_section = in_data;
184 /* Tell assembler to switch to read-only data section. This is normally
185 the text section. */
187 void
188 readonly_data_section ()
190 #ifdef READONLY_DATA_SECTION
191 READONLY_DATA_SECTION (); /* Note this can call data_section. */
192 #else
193 text_section ();
194 #endif
197 /* Determine if we're in the text section. */
200 in_text_section ()
202 return in_section == in_text;
205 /* Tell assembler to change to named section. */
207 void
208 named_section (name)
209 char *name;
211 if (in_section != in_named || strcmp (name, in_named_name))
213 in_named_name = name;
214 in_section = in_named;
216 #ifdef ASM_OUTPUT_SECTION_NAME
217 ASM_OUTPUT_SECTION_NAME (asm_out_file, name);
218 #else
219 /* Section attributes are not supported if this macro isn't provided -
220 some host formats don't support them at all. The front-end should
221 already have flagged this as an error. */
222 abort ();
223 #endif
227 /* Create the rtl to represent a function, for a function definition.
228 DECL is a FUNCTION_DECL node which describes which function.
229 The rtl is stored into DECL. */
231 void
232 make_function_rtl (decl)
233 tree decl;
235 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
237 if (output_bytecode)
239 if (DECL_RTL (decl) == 0)
240 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
242 /* Record that at least one function has been defined. */
243 function_defined = 1;
244 return;
247 /* Rename a nested function to avoid conflicts. */
248 if (decl_function_context (decl) != 0
249 && DECL_INITIAL (decl) != 0
250 && DECL_RTL (decl) == 0)
252 char *label;
254 name = IDENTIFIER_POINTER (DECL_NAME (decl));
255 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
256 name = obstack_copy0 (saveable_obstack, label, strlen (label));
257 var_labelno++;
260 if (DECL_RTL (decl) == 0)
262 DECL_RTL (decl)
263 = gen_rtx (MEM, DECL_MODE (decl),
264 gen_rtx (SYMBOL_REF, Pmode, name));
266 /* Optionally set flags or add text to the name to record information
267 such as that it is a function name. If the name is changed, the macro
268 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
269 #ifdef ENCODE_SECTION_INFO
270 ENCODE_SECTION_INFO (decl);
271 #endif
274 /* Record at least one function has been defined. */
275 function_defined = 1;
278 /* Create the DECL_RTL for a declaration for a static or external
279 variable or static or external function.
280 ASMSPEC, if not 0, is the string which the user specified
281 as the assembler symbol name.
282 TOP_LEVEL is nonzero if this is a file-scope variable.
283 This is never called for PARM_DECLs. */
284 void
285 bc_make_decl_rtl (decl, asmspec, top_level)
286 tree decl;
287 char *asmspec;
288 int top_level;
290 register char *name = TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl));
292 if (DECL_RTL (decl) == 0)
294 /* Print an error message for register variables. */
295 if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
296 error ("function declared `register'");
297 else if (DECL_REGISTER (decl))
298 error ("global register variables not supported in the interpreter");
300 /* Handle ordinary static variables and functions. */
301 if (DECL_RTL (decl) == 0)
303 /* Can't use just the variable's own name for a variable
304 whose scope is less than the whole file.
305 Concatenate a distinguishing number. */
306 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
308 char *label;
310 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
311 name = obstack_copy0 (saveable_obstack, label, strlen (label));
312 var_labelno++;
315 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
320 /* Given NAME, a putative register name, discard any customary prefixes. */
322 static char *
323 strip_reg_name (name)
324 char *name;
326 #ifdef REGISTER_PREFIX
327 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
328 name += strlen (REGISTER_PREFIX);
329 #endif
330 if (name[0] == '%' || name[0] == '#')
331 name++;
332 return name;
335 /* Decode an `asm' spec for a declaration as a register name.
336 Return the register number, or -1 if nothing specified,
337 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
338 or -3 if ASMSPEC is `cc' and is not recognized,
339 or -4 if ASMSPEC is `memory' and is not recognized.
340 Accept an exact spelling or a decimal number.
341 Prefixes such as % are optional. */
344 decode_reg_name (asmspec)
345 char *asmspec;
347 if (asmspec != 0)
349 int i;
351 /* Get rid of confusing prefixes. */
352 asmspec = strip_reg_name (asmspec);
354 /* Allow a decimal number as a "register name". */
355 for (i = strlen (asmspec) - 1; i >= 0; i--)
356 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
357 break;
358 if (asmspec[0] != 0 && i < 0)
360 i = atoi (asmspec);
361 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
362 return i;
363 else
364 return -2;
367 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
368 if (reg_names[i][0]
369 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
370 return i;
372 #ifdef ADDITIONAL_REGISTER_NAMES
374 static struct { char *name; int number; } table[]
375 = ADDITIONAL_REGISTER_NAMES;
377 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
378 if (! strcmp (asmspec, table[i].name))
379 return table[i].number;
381 #endif /* ADDITIONAL_REGISTER_NAMES */
383 if (!strcmp (asmspec, "memory"))
384 return -4;
386 if (!strcmp (asmspec, "cc"))
387 return -3;
389 return -2;
392 return -1;
395 /* Create the DECL_RTL for a declaration for a static or external variable
396 or static or external function.
397 ASMSPEC, if not 0, is the string which the user specified
398 as the assembler symbol name.
399 TOP_LEVEL is nonzero if this is a file-scope variable.
401 This is never called for PARM_DECL nodes. */
403 void
404 make_decl_rtl (decl, asmspec, top_level)
405 tree decl;
406 char *asmspec;
407 int top_level;
409 register char *name = 0;
410 int reg_number;
412 if (output_bytecode)
414 bc_make_decl_rtl (decl, asmspec, top_level);
415 return;
418 reg_number = decode_reg_name (asmspec);
420 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
421 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
423 if (reg_number == -2)
425 /* ASMSPEC is given, and not the name of a register. */
426 name = (char *) obstack_alloc (saveable_obstack,
427 strlen (asmspec) + 2);
428 name[0] = '*';
429 strcpy (&name[1], asmspec);
432 /* For a duplicate declaration, we can be called twice on the
433 same DECL node. Don't discard the RTL already made. */
434 if (DECL_RTL (decl) == 0)
436 DECL_RTL (decl) = 0;
438 /* First detect errors in declaring global registers. */
439 if (DECL_REGISTER (decl) && reg_number == -1)
440 error_with_decl (decl,
441 "register name not specified for `%s'");
442 else if (DECL_REGISTER (decl) && reg_number < 0)
443 error_with_decl (decl,
444 "invalid register name for `%s'");
445 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
446 error_with_decl (decl,
447 "register name given for non-register variable `%s'");
448 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
449 error ("function declared `register'");
450 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
451 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
452 else if (DECL_REGISTER (decl)
453 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
454 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
455 /* Now handle properly declared static register variables. */
456 else if (DECL_REGISTER (decl))
458 int nregs;
459 #if 0 /* yylex should print the warning for this */
460 if (pedantic)
461 pedwarn ("ANSI C forbids global register variables");
462 #endif
463 if (DECL_INITIAL (decl) != 0 && top_level)
465 DECL_INITIAL (decl) = 0;
466 error ("global register variable has initial value");
468 if (fixed_regs[reg_number] == 0
469 && function_defined && top_level)
470 error ("global register variable follows a function definition");
471 if (TREE_THIS_VOLATILE (decl))
472 warning ("volatile register variables don't work as you might wish");
474 /* If the user specified one of the eliminables registers here,
475 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
476 confused with that register and be eliminated. Although this
477 usage is somewhat suspect, we nevertheless use the following
478 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
480 DECL_RTL (decl)
481 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
482 REGNO (DECL_RTL (decl)) = reg_number;
483 REG_USERVAR_P (DECL_RTL (decl)) = 1;
485 if (top_level)
487 /* Make this register global, so not usable for anything
488 else. */
489 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
490 while (nregs > 0)
491 globalize_reg (reg_number + --nregs);
494 /* Specifying a section attribute on an uninitialized variable does not
495 (and cannot) cause it to be put in the given section. The linker
496 can only put initialized objects in specific sections, everything
497 else goes in bss for the linker to sort out later (otherwise the
498 linker would give a duplicate definition error for each compilation
499 unit that behaved thusly). So warn the user. */
500 else if (TREE_CODE (decl) == VAR_DECL
501 && DECL_SECTION_NAME (decl) != NULL_TREE
502 && DECL_INITIAL (decl) == NULL_TREE)
504 warning_with_decl (decl,
505 "section attribute ignored for uninitialized variable `%s'");
506 /* Remove the section name so subsequent declarations won't see it.
507 We are ignoring it, remember. */
508 DECL_SECTION_NAME (decl) = NULL_TREE;
511 /* Now handle ordinary static variables and functions (in memory).
512 Also handle vars declared register invalidly. */
513 if (DECL_RTL (decl) == 0)
515 /* Can't use just the variable's own name for a variable
516 whose scope is less than the whole file.
517 Concatenate a distinguishing number. */
518 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
520 char *label;
522 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
523 name = obstack_copy0 (saveable_obstack, label, strlen (label));
524 var_labelno++;
527 if (name == 0)
528 abort ();
530 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
531 gen_rtx (SYMBOL_REF, Pmode, name));
533 /* If this variable is to be treated as volatile, show its
534 tree node has side effects. If it has side effects, either
535 because of this test or from TREE_THIS_VOLATILE also
536 being set, show the MEM is volatile. */
537 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
538 && TREE_PUBLIC (decl))
539 TREE_SIDE_EFFECTS (decl) = 1;
540 if (TREE_SIDE_EFFECTS (decl))
541 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
543 if (TREE_READONLY (decl))
544 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
545 MEM_IN_STRUCT_P (DECL_RTL (decl))
546 = AGGREGATE_TYPE_P (TREE_TYPE (decl));
548 /* Optionally set flags or add text to the name to record information
549 such as that it is a function name.
550 If the name is changed, the macro ASM_OUTPUT_LABELREF
551 will have to know how to strip this information. */
552 #ifdef ENCODE_SECTION_INFO
553 ENCODE_SECTION_INFO (decl);
554 #endif
557 /* If the old RTL had the wrong mode, fix the mode. */
558 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
560 rtx rtl = DECL_RTL (decl);
561 PUT_MODE (rtl, DECL_MODE (decl));
565 /* Make the rtl for variable VAR be volatile.
566 Use this only for static variables. */
568 void
569 make_var_volatile (var)
570 tree var;
572 if (GET_CODE (DECL_RTL (var)) != MEM)
573 abort ();
575 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
578 /* Output alignment directive to align for constant expression EXP. */
580 void
581 assemble_constant_align (exp)
582 tree exp;
584 int align;
586 /* Align the location counter as required by EXP's data type. */
587 align = TYPE_ALIGN (TREE_TYPE (exp));
588 #ifdef CONSTANT_ALIGNMENT
589 align = CONSTANT_ALIGNMENT (exp, align);
590 #endif
592 if (align > BITS_PER_UNIT)
593 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
596 /* Output a string of literal assembler code
597 for an `asm' keyword used between functions. */
599 void
600 assemble_asm (string)
601 tree string;
603 if (output_bytecode)
605 error ("asm statements not allowed in interpreter");
606 return;
609 app_enable ();
611 if (TREE_CODE (string) == ADDR_EXPR)
612 string = TREE_OPERAND (string, 0);
614 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
617 #if 0 /* This should no longer be needed, because
618 flag_gnu_linker should be 0 on these systems,
619 which should prevent any output
620 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
621 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
622 #ifndef ASM_OUTPUT_CONSTRUCTOR
623 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
624 #endif
625 #ifndef ASM_OUTPUT_DESTRUCTOR
626 #define ASM_OUTPUT_DESTRUCTOR(file, name)
627 #endif
628 #endif
629 #endif /* 0 */
631 /* Record an element in the table of global destructors.
632 How this is done depends on what sort of assembler and linker
633 are in use.
635 NAME should be the name of a global function to be called
636 at exit time. This name is output using assemble_name. */
638 void
639 assemble_destructor (name)
640 char *name;
642 #ifdef ASM_OUTPUT_DESTRUCTOR
643 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
644 #else
645 if (flag_gnu_linker)
647 /* Now tell GNU LD that this is part of the static destructor set. */
648 /* This code works for any machine provided you use GNU as/ld. */
649 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
650 assemble_name (asm_out_file, name);
651 fputc ('\n', asm_out_file);
653 #endif
656 /* Likewise for global constructors. */
658 void
659 assemble_constructor (name)
660 char *name;
662 #ifdef ASM_OUTPUT_CONSTRUCTOR
663 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
664 #else
665 if (flag_gnu_linker)
667 /* Now tell GNU LD that this is part of the static constructor set. */
668 /* This code works for any machine provided you use GNU as/ld. */
669 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
670 assemble_name (asm_out_file, name);
671 fputc ('\n', asm_out_file);
673 #endif
676 /* Likewise for entries we want to record for garbage collection.
677 Garbage collection is still under development. */
679 void
680 assemble_gc_entry (name)
681 char *name;
683 #ifdef ASM_OUTPUT_GC_ENTRY
684 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
685 #else
686 if (flag_gnu_linker)
688 /* Now tell GNU LD that this is part of the static constructor set. */
689 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
690 assemble_name (asm_out_file, name);
691 fputc ('\n', asm_out_file);
693 #endif
696 /* Output assembler code for the constant pool of a function and associated
697 with defining the name of the function. DECL describes the function.
698 NAME is the function's name. For the constant pool, we use the current
699 constant pool data. */
701 void
702 assemble_start_function (decl, fnname)
703 tree decl;
704 char *fnname;
706 int align;
708 /* The following code does not need preprocessing in the assembler. */
710 app_disable ();
712 output_constant_pool (fnname, decl);
714 if (IN_NAMED_SECTION (decl))
715 named_section (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)));
716 else
717 text_section ();
719 /* Tell assembler to move to target machine's alignment for functions. */
720 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
721 if (align > 0)
723 if (output_bytecode)
724 BC_OUTPUT_ALIGN (asm_out_file, align);
725 else
726 ASM_OUTPUT_ALIGN (asm_out_file, align);
729 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
730 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
731 #endif
733 #ifdef SDB_DEBUGGING_INFO
734 /* Output SDB definition of the function. */
735 if (write_symbols == SDB_DEBUG)
736 sdbout_mark_begin_function ();
737 #endif
739 #ifdef DBX_DEBUGGING_INFO
740 /* Output DBX definition of the function. */
741 if (write_symbols == DBX_DEBUG)
742 dbxout_begin_function (decl);
743 #endif
745 /* Make function name accessible from other files, if appropriate. */
747 if (TREE_PUBLIC (decl))
749 if (!first_global_object_name)
750 STRIP_NAME_ENCODING (first_global_object_name, fnname);
751 if (output_bytecode)
752 BC_GLOBALIZE_LABEL (asm_out_file, fnname);
753 else
754 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
757 /* Do any machine/system dependent processing of the function name */
758 #ifdef ASM_DECLARE_FUNCTION_NAME
759 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
760 #else
761 /* Standard thing is just output label for the function. */
762 if (output_bytecode)
763 BC_OUTPUT_LABEL (asm_out_file, fnname);
764 else
765 ASM_OUTPUT_LABEL (asm_out_file, fnname);
766 #endif /* ASM_DECLARE_FUNCTION_NAME */
769 /* Output assembler code associated with defining the size of the
770 function. DECL describes the function. NAME is the function's name. */
772 void
773 assemble_end_function (decl, fnname)
774 tree decl;
775 char *fnname;
777 #ifdef ASM_DECLARE_FUNCTION_SIZE
778 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
779 #endif
782 /* Assemble code to leave SIZE bytes of zeros. */
784 void
785 assemble_zeros (size)
786 int size;
788 if (output_bytecode)
790 bc_emit_const_skip (size);
791 return;
794 #ifdef ASM_NO_SKIP_IN_TEXT
795 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
796 so we must output 0s explicitly in the text section. */
797 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
799 int i;
801 for (i = 0; i < size - 20; i += 20)
803 #ifdef ASM_BYTE_OP
804 fprintf (asm_out_file,
805 "%s 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ASM_BYTE_OP);
806 #else
807 fprintf (asm_out_file,
808 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
809 #endif
811 if (i < size)
813 #ifdef ASM_BYTE_OP
814 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
815 #else
816 fprintf (asm_out_file, "\tbyte 0");
817 #endif
818 i++;
819 for (; i < size; i++)
820 fprintf (asm_out_file, ",0");
821 fprintf (asm_out_file, "\n");
824 else
825 #endif
826 if (size > 0)
828 if (output_bytecode)
829 BC_OUTPUT_SKIP (asm_out_file, size);
830 else
831 ASM_OUTPUT_SKIP (asm_out_file, size);
835 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
837 void
838 assemble_align (align)
839 int align;
841 if (align > BITS_PER_UNIT)
842 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
845 /* Assemble a string constant with the specified C string as contents. */
847 void
848 assemble_string (p, size)
849 char *p;
850 int size;
852 register int i;
853 int pos = 0;
854 int maximum = 2000;
856 if (output_bytecode)
858 bc_emit (p, size);
859 return;
862 /* If the string is very long, split it up. */
864 while (pos < size)
866 int thissize = size - pos;
867 if (thissize > maximum)
868 thissize = maximum;
870 if (output_bytecode)
871 bc_output_ascii (asm_out_file, p, thissize);
872 else
874 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
877 pos += thissize;
878 p += thissize;
882 static void
883 bc_output_ascii (file, p, size)
884 FILE *file;
885 char *p;
886 int size;
888 BC_OUTPUT_ASCII (file, p, size);
891 /* Assemble everything that is needed for a variable or function declaration.
892 Not used for automatic variables, and not used for function definitions.
893 Should not be called for variables of incomplete structure type.
895 TOP_LEVEL is nonzero if this variable has file scope.
896 AT_END is nonzero if this is the special handling, at end of compilation,
897 to define things that have had only tentative definitions.
898 DONT_OUTPUT_DATA if nonzero means don't actually output the
899 initial value (that will be done by the caller). */
901 void
902 assemble_variable (decl, top_level, at_end, dont_output_data)
903 tree decl;
904 int top_level;
905 int at_end;
907 register char *name;
908 int align;
909 tree size_tree;
910 int reloc = 0;
911 enum in_section saved_in_section;
913 last_assemble_variable_decl = 0;
915 if (output_bytecode)
916 return;
918 if (GET_CODE (DECL_RTL (decl)) == REG)
920 /* Do output symbol info for global register variables, but do nothing
921 else for them. */
923 if (TREE_ASM_WRITTEN (decl))
924 return;
925 TREE_ASM_WRITTEN (decl) = 1;
927 if (!output_bytecode)
929 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
930 /* File-scope global variables are output here. */
931 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
932 && top_level)
933 dbxout_symbol (decl, 0);
934 #endif
935 #ifdef SDB_DEBUGGING_INFO
936 if (write_symbols == SDB_DEBUG && top_level
937 /* Leave initialized global vars for end of compilation;
938 see comment in compile_file. */
939 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
940 sdbout_symbol (decl, 0);
941 #endif
944 /* Don't output any DWARF debugging information for variables here.
945 In the case of local variables, the information for them is output
946 when we do our recursive traversal of the tree representation for
947 the entire containing function. In the case of file-scope variables,
948 we output information for all of them at the very end of compilation
949 while we are doing our final traversal of the chain of file-scope
950 declarations. */
952 return;
955 /* Normally no need to say anything here for external references,
956 since assemble_external is called by the langauge-specific code
957 when a declaration is first seen. */
959 if (DECL_EXTERNAL (decl))
960 return;
962 /* Output no assembler code for a function declaration.
963 Only definitions of functions output anything. */
965 if (TREE_CODE (decl) == FUNCTION_DECL)
966 return;
968 /* If type was incomplete when the variable was declared,
969 see if it is complete now. */
971 if (DECL_SIZE (decl) == 0)
972 layout_decl (decl, 0);
974 /* Still incomplete => don't allocate it; treat the tentative defn
975 (which is what it must have been) as an `extern' reference. */
977 if (!dont_output_data && DECL_SIZE (decl) == 0)
979 error_with_file_and_line (DECL_SOURCE_FILE (decl),
980 DECL_SOURCE_LINE (decl),
981 "storage size of `%s' isn't known",
982 IDENTIFIER_POINTER (DECL_NAME (decl)));
983 return;
986 /* The first declaration of a variable that comes through this function
987 decides whether it is global (in C, has external linkage)
988 or local (in C, has internal linkage). So do nothing more
989 if this function has already run. */
991 if (TREE_ASM_WRITTEN (decl))
992 return;
994 TREE_ASM_WRITTEN (decl) = 1;
996 /* If storage size is erroneously variable, just continue.
997 Error message was already made. */
999 if (DECL_SIZE (decl))
1001 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1002 goto finish;
1004 app_disable ();
1006 /* This is better than explicit arithmetic, since it avoids overflow. */
1007 size_tree = size_binop (CEIL_DIV_EXPR,
1008 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1010 if (TREE_INT_CST_HIGH (size_tree) != 0)
1012 error_with_decl (decl, "size of variable `%s' is too large");
1013 goto finish;
1017 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1019 /* Handle uninitialized definitions. */
1021 /* ANSI specifies that a tentative definition which is not merged with
1022 a non-tentative definition behaves exactly like a definition with an
1023 initializer equal to zero. (Section 3.7.2)
1024 -fno-common gives strict ANSI behavior. Usually you don't want it.
1025 This matters only for variables with external linkage. */
1026 if ((! flag_no_common || ! TREE_PUBLIC (decl))
1027 && DECL_COMMON (decl)
1028 && ! dont_output_data
1029 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
1031 int size = TREE_INT_CST_LOW (size_tree);
1032 int rounded = size;
1034 if (TREE_INT_CST_HIGH (size_tree) != 0)
1035 error_with_decl (decl, "size of variable `%s' is too large");
1036 /* Don't allocate zero bytes of common,
1037 since that means "undefined external" in the linker. */
1038 if (size == 0) rounded = 1;
1039 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1040 so that each uninitialized object starts on such a boundary. */
1041 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1042 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1043 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1045 #ifdef DBX_DEBUGGING_INFO
1046 /* File-scope global variables are output here. */
1047 if (write_symbols == DBX_DEBUG && top_level)
1048 dbxout_symbol (decl, 0);
1049 #endif
1050 #ifdef SDB_DEBUGGING_INFO
1051 if (write_symbols == SDB_DEBUG && top_level
1052 /* Leave initialized global vars for end of compilation;
1053 see comment in compile_file. */
1054 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1055 sdbout_symbol (decl, 0);
1056 #endif
1058 /* Don't output any DWARF debugging information for variables here.
1059 In the case of local variables, the information for them is output
1060 when we do our recursive traversal of the tree representation for
1061 the entire containing function. In the case of file-scope variables,
1062 we output information for all of them at the very end of compilation
1063 while we are doing our final traversal of the chain of file-scope
1064 declarations. */
1066 #if 0
1067 if (flag_shared_data)
1068 data_section ();
1069 #endif
1070 if (TREE_PUBLIC (decl))
1072 #ifdef ASM_OUTPUT_SHARED_COMMON
1073 if (flag_shared_data)
1074 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1075 else
1076 #endif
1077 if (output_bytecode)
1079 BC_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1081 else
1083 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1084 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1085 DECL_ALIGN (decl));
1086 #else
1087 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1088 #endif
1091 else
1093 #ifdef ASM_OUTPUT_SHARED_LOCAL
1094 if (flag_shared_data)
1095 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1096 else
1097 #endif
1098 if (output_bytecode)
1100 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1102 else
1104 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1105 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1106 DECL_ALIGN (decl));
1107 #else
1108 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1109 #endif
1112 goto finish;
1115 /* Handle initialized definitions. */
1117 /* First make the assembler name(s) global if appropriate. */
1118 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1120 if (!first_global_object_name)
1121 STRIP_NAME_ENCODING(first_global_object_name, name);
1122 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1124 #if 0
1125 for (d = equivalents; d; d = TREE_CHAIN (d))
1127 tree e = TREE_VALUE (d);
1128 if (TREE_PUBLIC (e) && DECL_NAME (e))
1129 ASM_GLOBALIZE_LABEL (asm_out_file,
1130 XSTR (XEXP (DECL_RTL (e), 0), 0));
1132 #endif
1134 /* Output any data that we will need to use the address of. */
1135 if (DECL_INITIAL (decl) == error_mark_node)
1136 reloc = contains_pointers_p (TREE_TYPE (decl));
1137 else if (DECL_INITIAL (decl))
1138 reloc = output_addressed_constants (DECL_INITIAL (decl));
1140 /* Switch to the proper section for this data. */
1141 if (IN_NAMED_SECTION (decl))
1142 named_section (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)));
1143 else
1145 /* C++ can have const variables that get initialized from constructors,
1146 and thus can not be in a readonly section. We prevent this by
1147 verifying that the initial value is constant for objects put in a
1148 readonly section.
1150 error_mark_node is used by the C front end to indicate that the
1151 initializer has not been seen yet. In this case, we assume that
1152 the initializer must be constant. */
1153 #ifdef SELECT_SECTION
1154 SELECT_SECTION (decl, reloc);
1155 #else
1156 if (TREE_READONLY (decl)
1157 && ! TREE_THIS_VOLATILE (decl)
1158 && DECL_INITIAL (decl)
1159 && (DECL_INITIAL (decl) == error_mark_node
1160 || TREE_CONSTANT (DECL_INITIAL (decl)))
1161 && ! (flag_pic && reloc))
1162 readonly_data_section ();
1163 else
1164 data_section ();
1165 #endif
1168 /* dbxout.c needs to know this. */
1169 if (in_text_section ())
1170 DECL_IN_TEXT_SECTION (decl) = 1;
1172 /* Record current section so we can restore it if dbxout.c clobbers it. */
1173 saved_in_section = in_section;
1175 /* Output the dbx info now that we have chosen the section. */
1177 #ifdef DBX_DEBUGGING_INFO
1178 /* File-scope global variables are output here. */
1179 if (write_symbols == DBX_DEBUG && top_level)
1180 dbxout_symbol (decl, 0);
1181 #endif
1182 #ifdef SDB_DEBUGGING_INFO
1183 if (write_symbols == SDB_DEBUG && top_level
1184 /* Leave initialized global vars for end of compilation;
1185 see comment in compile_file. */
1186 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1187 sdbout_symbol (decl, 0);
1188 #endif
1190 /* Don't output any DWARF debugging information for variables here.
1191 In the case of local variables, the information for them is output
1192 when we do our recursive traversal of the tree representation for
1193 the entire containing function. In the case of file-scope variables,
1194 we output information for all of them at the very end of compilation
1195 while we are doing our final traversal of the chain of file-scope
1196 declarations. */
1198 /* If the debugging output changed sections, reselect the section
1199 that's supposed to be selected. */
1200 if (in_section != saved_in_section)
1202 /* Switch to the proper section for this data. */
1203 #ifdef SELECT_SECTION
1204 SELECT_SECTION (decl, reloc);
1205 #else
1206 if (TREE_READONLY (decl)
1207 && ! TREE_THIS_VOLATILE (decl)
1208 && DECL_INITIAL (decl)
1209 && (DECL_INITIAL (decl) == error_mark_node
1210 || TREE_CONSTANT (DECL_INITIAL (decl)))
1211 && ! (flag_pic && reloc))
1212 readonly_data_section ();
1213 else
1214 data_section ();
1215 #endif
1218 /* Compute and output the alignment of this data. */
1220 align = DECL_ALIGN (decl);
1221 /* In the case for initialing an array whose length isn't specified,
1222 where we have not yet been able to do the layout,
1223 figure out the proper alignment now. */
1224 if (dont_output_data && DECL_SIZE (decl) == 0
1225 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1226 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1228 /* Some object file formats have a maximum alignment which they support.
1229 In particular, a.out format supports a maximum alignment of 4. */
1230 #ifndef MAX_OFILE_ALIGNMENT
1231 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1232 #endif
1233 if (align > MAX_OFILE_ALIGNMENT)
1235 warning_with_decl (decl,
1236 "alignment of `%s' is greater than maximum object file alignment");
1237 align = MAX_OFILE_ALIGNMENT;
1239 #ifdef DATA_ALIGNMENT
1240 /* On some machines, it is good to increase alignment sometimes. */
1241 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1242 #endif
1243 #ifdef CONSTANT_ALIGNMENT
1244 if (DECL_INITIAL (decl))
1245 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1246 #endif
1248 /* Reset the alignment in case we have made it tighter, so we can benefit
1249 from it in get_pointer_alignment. */
1250 DECL_ALIGN (decl) = align;
1252 if (align > BITS_PER_UNIT)
1254 if (output_bytecode)
1255 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1256 else
1257 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1260 /* Do any machine/system dependent processing of the object. */
1261 #ifdef ASM_DECLARE_OBJECT_NAME
1262 last_assemble_variable_decl = decl;
1263 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1264 #else
1265 /* Standard thing is just output label for the object. */
1266 if (output_bytecode)
1267 BC_OUTPUT_LABEL (asm_out_file, name);
1268 else
1269 ASM_OUTPUT_LABEL (asm_out_file, name);
1270 #endif /* ASM_DECLARE_OBJECT_NAME */
1272 if (!dont_output_data)
1274 if (DECL_INITIAL (decl))
1275 /* Output the actual data. */
1276 output_constant (DECL_INITIAL (decl),
1277 int_size_in_bytes (TREE_TYPE (decl)));
1278 else
1279 /* Leave space for it. */
1280 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1283 finish:
1284 #ifdef XCOFF_DEBUGGING_INFO
1285 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1286 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1287 and `aa' hasn't been output yet, the assembler generates a stab entry with
1288 a value of zero, in addition to creating an unnecessary external entry
1289 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1291 /* File-scope global variables are output here. */
1292 if (write_symbols == XCOFF_DEBUG && top_level)
1294 saved_in_section = in_section;
1296 dbxout_symbol (decl, 0);
1298 if (in_section != saved_in_section)
1300 /* Switch to the proper section for this data. */
1301 #ifdef SELECT_SECTION
1302 SELECT_SECTION (decl, reloc);
1303 #else
1304 if (TREE_READONLY (decl)
1305 && ! TREE_THIS_VOLATILE (decl)
1306 && DECL_INITIAL (decl)
1307 && (DECL_INITIAL (decl) == error_mark_node
1308 || TREE_CONSTANT (DECL_INITIAL (decl)))
1309 && ! (flag_pic && reloc))
1310 readonly_data_section ();
1311 else
1312 data_section ();
1313 #endif
1316 #else
1317 /* There must be a statement after a label. */
1319 #endif
1322 /* Return 1 if type TYPE contains any pointers. */
1324 static int
1325 contains_pointers_p (type)
1326 tree type;
1328 switch (TREE_CODE (type))
1330 case POINTER_TYPE:
1331 case REFERENCE_TYPE:
1332 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1333 so I'll play safe and return 1. */
1334 case OFFSET_TYPE:
1335 return 1;
1337 case RECORD_TYPE:
1338 case UNION_TYPE:
1339 case QUAL_UNION_TYPE:
1341 tree fields;
1342 /* For a type that has fields, see if the fields have pointers. */
1343 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1344 if (TREE_CODE (fields) == FIELD_DECL
1345 && contains_pointers_p (TREE_TYPE (fields)))
1346 return 1;
1347 return 0;
1350 case ARRAY_TYPE:
1351 /* An array type contains pointers if its element type does. */
1352 return contains_pointers_p (TREE_TYPE (type));
1354 default:
1355 return 0;
1359 /* Output text storage for constructor CONSTR. Returns rtx of
1360 storage. */
1363 bc_output_constructor (constr)
1364 tree constr;
1366 int i;
1368 /* Must always be a literal; non-literal constructors are handled
1369 differently. */
1371 if (!TREE_CONSTANT (constr))
1372 abort ();
1374 /* Always const */
1375 text_section ();
1377 /* Align */
1378 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1379 if (i > 0)
1380 BC_OUTPUT_ALIGN (asm_out_file, i);
1382 /* Output data */
1383 output_constant (constr, int_size_in_bytes (TREE_TYPE (constr)));
1387 /* Create storage for constructor CONSTR. */
1389 void
1390 bc_output_data_constructor (constr)
1391 tree constr;
1393 int i;
1395 /* Put in data section */
1396 data_section ();
1398 /* Align */
1399 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1400 if (i > 0)
1401 BC_OUTPUT_ALIGN (asm_out_file, i);
1403 /* The constructor is filled in at runtime. */
1404 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1408 /* Output something to declare an external symbol to the assembler.
1409 (Most assemblers don't need this, so we normally output nothing.)
1410 Do nothing if DECL is not external. */
1412 void
1413 assemble_external (decl)
1414 tree decl;
1416 if (output_bytecode)
1417 return;
1419 #ifdef ASM_OUTPUT_EXTERNAL
1420 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1421 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1423 rtx rtl = DECL_RTL (decl);
1425 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1426 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1428 /* Some systems do require some output. */
1429 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1430 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1433 #endif
1436 /* Similar, for calling a library function FUN. */
1438 void
1439 assemble_external_libcall (fun)
1440 rtx fun;
1442 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1443 if (!output_bytecode)
1445 /* Declare library function name external when first used, if nec. */
1446 if (! SYMBOL_REF_USED (fun))
1448 SYMBOL_REF_USED (fun) = 1;
1449 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1452 #endif
1455 /* Declare the label NAME global. */
1457 void
1458 assemble_global (name)
1459 char *name;
1461 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1464 /* Assemble a label named NAME. */
1466 void
1467 assemble_label (name)
1468 char *name;
1470 if (output_bytecode)
1471 BC_OUTPUT_LABEL (asm_out_file, name);
1472 else
1473 ASM_OUTPUT_LABEL (asm_out_file, name);
1476 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1477 If NAME starts with a *, the rest of NAME is output verbatim.
1478 Otherwise NAME is transformed in an implementation-defined way
1479 (usually by the addition of an underscore).
1480 Many macros in the tm file are defined to call this function. */
1482 void
1483 assemble_name (file, name)
1484 FILE *file;
1485 char *name;
1487 tree id = get_identifier (name);
1488 TREE_SYMBOL_REFERENCED (id) = 1;
1490 if (name[0] == '*')
1492 if (output_bytecode)
1493 bc_emit_labelref (name);
1494 else
1495 fputs (&name[1], file);
1497 else
1499 if (output_bytecode)
1500 BC_OUTPUT_LABELREF (file, name);
1501 else
1502 ASM_OUTPUT_LABELREF (file, name);
1506 /* Allocate SIZE bytes writable static space with a gensym name
1507 and return an RTX to refer to its address. */
1510 assemble_static_space (size)
1511 int size;
1513 char name[12];
1514 char *namestring;
1515 rtx x;
1516 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1517 so that each uninitialized object starts on such a boundary. */
1518 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1519 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1520 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1522 #if 0
1523 if (flag_shared_data)
1524 data_section ();
1525 #endif
1527 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1528 ++const_labelno;
1530 namestring = (char *) obstack_alloc (saveable_obstack,
1531 strlen (name) + 2);
1532 strcpy (namestring, name);
1534 if (output_bytecode)
1535 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1536 else
1537 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1539 if (output_bytecode)
1541 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1543 else
1545 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1546 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1547 #else
1548 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1549 #endif
1551 return x;
1554 /* Assemble the static constant template for function entry trampolines.
1555 This is done at most once per compilation.
1556 Returns an RTX for the address of the template. */
1559 assemble_trampoline_template ()
1561 char label[256];
1562 char *name;
1563 int align;
1565 /* Shouldn't get here */
1566 if (output_bytecode)
1567 abort ();
1569 /* By default, put trampoline templates in read-only data section. */
1571 #ifdef TRAMPOLINE_SECTION
1572 TRAMPOLINE_SECTION ();
1573 #else
1574 readonly_data_section ();
1575 #endif
1577 /* Write the assembler code to define one. */
1578 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1579 if (align > 0)
1580 ASM_OUTPUT_ALIGN (asm_out_file, align);
1582 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1583 TRAMPOLINE_TEMPLATE (asm_out_file);
1585 /* Record the rtl to refer to it. */
1586 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1587 name
1588 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1589 return gen_rtx (SYMBOL_REF, Pmode, name);
1592 /* Assemble the integer constant X into an object of SIZE bytes.
1593 X must be either a CONST_INT or CONST_DOUBLE.
1595 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1596 non-zero, abort if we can't output the constant. */
1599 assemble_integer (x, size, force)
1600 rtx x;
1601 int size;
1602 int force;
1604 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1605 ASM_OUTPUT... macros. */
1607 switch (size)
1609 #ifdef ASM_OUTPUT_CHAR
1610 case 1:
1611 ASM_OUTPUT_CHAR (asm_out_file, x);
1612 return 1;
1613 #endif
1615 #ifdef ASM_OUTPUT_SHORT
1616 case 2:
1617 ASM_OUTPUT_SHORT (asm_out_file, x);
1618 return 1;
1619 #endif
1621 #ifdef ASM_OUTPUT_INT
1622 case 4:
1623 ASM_OUTPUT_INT (asm_out_file, x);
1624 return 1;
1625 #endif
1627 #ifdef ASM_OUTPUT_DOUBLE_INT
1628 case 8:
1629 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1630 return 1;
1631 #endif
1633 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1634 case 16:
1635 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1636 return 1;
1637 #endif
1640 /* If we couldn't do it that way, there are two other possibilities: First,
1641 if the machine can output an explicit byte and this is a 1 byte constant,
1642 we can use ASM_OUTPUT_BYTE. */
1644 #ifdef ASM_OUTPUT_BYTE
1645 if (size == 1 && GET_CODE (x) == CONST_INT)
1647 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1648 return 1;
1650 #endif
1652 /* Finally, if SIZE is larger than a single word, try to output the constant
1653 one word at a time. */
1655 if (size > UNITS_PER_WORD)
1657 int i;
1658 enum machine_mode mode
1659 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1660 rtx word;
1662 for (i = 0; i < size / UNITS_PER_WORD; i++)
1664 word = operand_subword (x, i, 0, mode);
1666 if (word == 0)
1667 break;
1669 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1670 break;
1673 if (i == size / UNITS_PER_WORD)
1674 return 1;
1675 /* If we output at least one word and then could not finish,
1676 there is no valid way to continue. */
1677 if (i > 0)
1678 abort ();
1681 if (force)
1682 abort ();
1684 return 0;
1687 /* Assemble the floating-point constant D into an object of size MODE. */
1689 void
1690 assemble_real (d, mode)
1691 REAL_VALUE_TYPE d;
1692 enum machine_mode mode;
1694 jmp_buf output_constant_handler;
1696 if (setjmp (output_constant_handler))
1698 error ("floating point trap outputting a constant");
1699 #ifdef REAL_IS_NOT_DOUBLE
1700 bzero ((char *) &d, sizeof d);
1701 d = dconst0;
1702 #else
1703 d = 0;
1704 #endif
1707 set_float_handler (output_constant_handler);
1709 switch (mode)
1711 #ifdef ASM_OUTPUT_BYTE_FLOAT
1712 case QFmode:
1713 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1714 break;
1715 #endif
1716 #ifdef ASM_OUTPUT_SHORT_FLOAT
1717 case HFmode:
1718 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1719 break;
1720 #endif
1721 #ifdef ASM_OUTPUT_FLOAT
1722 case SFmode:
1723 ASM_OUTPUT_FLOAT (asm_out_file, d);
1724 break;
1725 #endif
1727 #ifdef ASM_OUTPUT_DOUBLE
1728 case DFmode:
1729 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1730 break;
1731 #endif
1733 #ifdef ASM_OUTPUT_LONG_DOUBLE
1734 case XFmode:
1735 case TFmode:
1736 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1737 break;
1738 #endif
1740 default:
1741 abort ();
1744 set_float_handler (NULL_PTR);
1747 /* Here we combine duplicate floating constants to make
1748 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1750 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1751 They are chained through the CONST_DOUBLE_CHAIN.
1752 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1753 In that case, CONST_DOUBLE_MEM is either a MEM,
1754 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1756 (CONST_DOUBLE_MEM is used only for top-level functions.
1757 See force_const_mem for explanation.) */
1759 static rtx const_double_chain;
1761 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1762 For an integer, I0 is the low-order word and I1 is the high-order word.
1763 For a real number, I0 is the word with the low address
1764 and I1 is the word with the high address. */
1767 immed_double_const (i0, i1, mode)
1768 HOST_WIDE_INT i0, i1;
1769 enum machine_mode mode;
1771 register rtx r;
1772 int in_current_obstack;
1774 if (GET_MODE_CLASS (mode) == MODE_INT
1775 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1777 /* We clear out all bits that don't belong in MODE, unless they and our
1778 sign bit are all one. So we get either a reasonable negative value
1779 or a reasonable unsigned value for this mode. */
1780 int width = GET_MODE_BITSIZE (mode);
1781 if (width < HOST_BITS_PER_WIDE_INT
1782 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1783 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1784 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1785 else if (width == HOST_BITS_PER_WIDE_INT
1786 && ! (i1 == ~0 && i0 < 0))
1787 i1 = 0;
1788 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1789 /* We cannot represent this value as a constant. */
1790 abort ();
1792 /* If this would be an entire word for the target, but is not for
1793 the host, then sign-extend on the host so that the number will look
1794 the same way on the host that it would on the target.
1796 For example, when building a 64 bit alpha hosted 32 bit sparc
1797 targeted compiler, then we want the 32 bit unsigned value -1 to be
1798 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1799 The later confuses the sparc backend. */
1801 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1802 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1803 i0 |= ((HOST_WIDE_INT) (-1) << width);
1805 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1807 ??? Strictly speaking, this is wrong if we create a CONST_INT
1808 for a large unsigned constant with the size of MODE being
1809 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1810 wider mode. In that case we will mis-interpret it as a negative
1811 number.
1813 Unfortunately, the only alternative is to make a CONST_DOUBLE
1814 for any constant in any mode if it is an unsigned constant larger
1815 than the maximum signed integer in an int on the host. However,
1816 doing this will break everyone that always expects to see a CONST_INT
1817 for SImode and smaller.
1819 We have always been making CONST_INTs in this case, so nothing new
1820 is being broken. */
1822 if (width <= HOST_BITS_PER_WIDE_INT)
1823 i1 = (i0 < 0) ? ~0 : 0;
1825 /* If this integer fits in one word, return a CONST_INT. */
1826 if ((i1 == 0 && i0 >= 0)
1827 || (i1 == ~0 && i0 < 0))
1828 return GEN_INT (i0);
1830 /* We use VOIDmode for integers. */
1831 mode = VOIDmode;
1834 /* Search the chain for an existing CONST_DOUBLE with the right value.
1835 If one is found, return it. */
1837 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1838 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1839 && GET_MODE (r) == mode)
1840 return r;
1842 /* No; make a new one and add it to the chain.
1844 We may be called by an optimizer which may be discarding any memory
1845 allocated during its processing (such as combine and loop). However,
1846 we will be leaving this constant on the chain, so we cannot tolerate
1847 freed memory. So switch to saveable_obstack for this allocation
1848 and then switch back if we were in current_obstack. */
1850 push_obstacks_nochange ();
1851 rtl_in_saveable_obstack ();
1852 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1853 pop_obstacks ();
1855 /* Don't touch const_double_chain in nested function; see force_const_mem.
1856 Also, don't touch it if not inside any function. */
1857 if (outer_function_chain == 0 && current_function_decl != 0)
1859 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1860 const_double_chain = r;
1863 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1864 Actual use of mem-slot is only through force_const_mem. */
1866 CONST_DOUBLE_MEM (r) = const0_rtx;
1868 return r;
1871 /* Return a CONST_DOUBLE for a specified `double' value
1872 and machine mode. */
1875 immed_real_const_1 (d, mode)
1876 REAL_VALUE_TYPE d;
1877 enum machine_mode mode;
1879 union real_extract u;
1880 register rtx r;
1881 int in_current_obstack;
1883 /* Get the desired `double' value as a sequence of ints
1884 since that is how they are stored in a CONST_DOUBLE. */
1886 u.d = d;
1888 /* Detect special cases. */
1890 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1891 if (!bcmp ((char *) &dconst0, (char *) &d, sizeof d))
1892 return CONST0_RTX (mode);
1893 /* Check for NaN first, because some ports (specifically the i386) do not
1894 emit correct ieee-fp code by default, and thus will generate a core
1895 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1896 does a floating point comparison. */
1897 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1898 return CONST1_RTX (mode);
1900 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1901 return immed_double_const (u.i[0], u.i[1], mode);
1903 /* The rest of this function handles the case where
1904 a float value requires more than 2 ints of space.
1905 It will be deleted as dead code on machines that don't need it. */
1907 /* Search the chain for an existing CONST_DOUBLE with the right value.
1908 If one is found, return it. */
1910 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1911 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
1912 && GET_MODE (r) == mode)
1913 return r;
1915 /* No; make a new one and add it to the chain.
1917 We may be called by an optimizer which may be discarding any memory
1918 allocated during its processing (such as combine and loop). However,
1919 we will be leaving this constant on the chain, so we cannot tolerate
1920 freed memory. So switch to saveable_obstack for this allocation
1921 and then switch back if we were in current_obstack. */
1923 push_obstacks_nochange ();
1924 rtl_in_saveable_obstack ();
1925 r = rtx_alloc (CONST_DOUBLE);
1926 PUT_MODE (r, mode);
1927 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
1928 pop_obstacks ();
1930 /* Don't touch const_double_chain in nested function; see force_const_mem.
1931 Also, don't touch it if not inside any function. */
1932 if (outer_function_chain == 0 && current_function_decl != 0)
1934 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1935 const_double_chain = r;
1938 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1939 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1940 is only through force_const_mem. */
1942 CONST_DOUBLE_MEM (r) = const0_rtx;
1944 return r;
1947 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1948 which must be a REAL_CST tree node. */
1951 immed_real_const (exp)
1952 tree exp;
1954 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1957 /* At the end of a function, forget the memory-constants
1958 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1959 Also clear out real_constant_chain and clear out all the chain-pointers. */
1961 void
1962 clear_const_double_mem ()
1964 register rtx r, next;
1966 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1967 See force_const_mem for explanation. */
1968 if (outer_function_chain != 0)
1969 return;
1971 for (r = const_double_chain; r; r = next)
1973 next = CONST_DOUBLE_CHAIN (r);
1974 CONST_DOUBLE_CHAIN (r) = 0;
1975 CONST_DOUBLE_MEM (r) = cc0_rtx;
1977 const_double_chain = 0;
1980 /* Given an expression EXP with a constant value,
1981 reduce it to the sum of an assembler symbol and an integer.
1982 Store them both in the structure *VALUE.
1983 Abort if EXP does not reduce. */
1985 struct addr_const
1987 rtx base;
1988 HOST_WIDE_INT offset;
1991 static void
1992 decode_addr_const (exp, value)
1993 tree exp;
1994 struct addr_const *value;
1996 register tree target = TREE_OPERAND (exp, 0);
1997 register int offset = 0;
1998 register rtx x;
2000 while (1)
2002 if (TREE_CODE (target) == COMPONENT_REF
2003 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2004 == INTEGER_CST))
2006 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2007 target = TREE_OPERAND (target, 0);
2009 else if (TREE_CODE (target) == ARRAY_REF)
2011 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2012 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2013 abort ();
2014 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2015 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2016 / BITS_PER_UNIT);
2017 target = TREE_OPERAND (target, 0);
2019 else
2020 break;
2023 switch (TREE_CODE (target))
2025 case VAR_DECL:
2026 case FUNCTION_DECL:
2027 x = DECL_RTL (target);
2028 break;
2030 case LABEL_DECL:
2031 if (output_bytecode)
2032 /* FIXME: this may not be correct, check it */
2033 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
2034 else
2035 x = gen_rtx (MEM, FUNCTION_MODE,
2036 gen_rtx (LABEL_REF, VOIDmode,
2037 label_rtx (TREE_OPERAND (exp, 0))));
2038 break;
2040 case REAL_CST:
2041 case STRING_CST:
2042 case COMPLEX_CST:
2043 case CONSTRUCTOR:
2044 x = TREE_CST_RTL (target);
2045 break;
2047 default:
2048 abort ();
2051 if (!output_bytecode)
2053 if (GET_CODE (x) != MEM)
2054 abort ();
2055 x = XEXP (x, 0);
2058 value->base = x;
2059 value->offset = offset;
2062 /* Uniquize all constants that appear in memory.
2063 Each constant in memory thus far output is recorded
2064 in `const_hash_table' with a `struct constant_descriptor'
2065 that contains a polish representation of the value of
2066 the constant.
2068 We cannot store the trees in the hash table
2069 because the trees may be temporary. */
2071 struct constant_descriptor
2073 struct constant_descriptor *next;
2074 char *label;
2075 char contents[1];
2078 #define HASHBITS 30
2079 #define MAX_HASH_TABLE 1009
2080 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2082 /* Compute a hash code for a constant expression. */
2085 const_hash (exp)
2086 tree exp;
2088 register char *p;
2089 register int len, hi, i;
2090 register enum tree_code code = TREE_CODE (exp);
2092 if (code == INTEGER_CST)
2094 p = (char *) &TREE_INT_CST_LOW (exp);
2095 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2097 else if (code == REAL_CST)
2099 p = (char *) &TREE_REAL_CST (exp);
2100 len = sizeof TREE_REAL_CST (exp);
2102 else if (code == STRING_CST)
2103 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2104 else if (code == COMPLEX_CST)
2105 return const_hash (TREE_REALPART (exp)) * 5
2106 + const_hash (TREE_IMAGPART (exp));
2107 else if (code == CONSTRUCTOR)
2109 register tree link;
2111 /* For record type, include the type in the hashing.
2112 We do not do so for array types
2113 because (1) the sizes of the elements are sufficient
2114 and (2) distinct array types can have the same constructor.
2115 Instead, we include the array size because the constructor could
2116 be shorter. */
2117 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2118 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2119 % MAX_HASH_TABLE;
2120 else
2121 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2122 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2124 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2125 if (TREE_VALUE (link))
2126 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2128 return hi;
2130 else if (code == ADDR_EXPR)
2132 struct addr_const value;
2133 decode_addr_const (exp, &value);
2134 if (GET_CODE (value.base) == SYMBOL_REF)
2136 /* Don't hash the address of the SYMBOL_REF;
2137 only use the offset and the symbol name. */
2138 hi = value.offset;
2139 p = XSTR (value.base, 0);
2140 for (i = 0; p[i] != 0; i++)
2141 hi = ((hi * 613) + (unsigned)(p[i]));
2143 else if (GET_CODE (value.base) == LABEL_REF)
2144 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2146 hi &= (1 << HASHBITS) - 1;
2147 hi %= MAX_HASH_TABLE;
2148 return hi;
2150 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2151 return const_hash (TREE_OPERAND (exp, 0)) * 9
2152 + const_hash (TREE_OPERAND (exp, 1));
2153 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2154 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2156 /* Compute hashing function */
2157 hi = len;
2158 for (i = 0; i < len; i++)
2159 hi = ((hi * 613) + (unsigned)(p[i]));
2161 hi &= (1 << HASHBITS) - 1;
2162 hi %= MAX_HASH_TABLE;
2163 return hi;
2166 /* Compare a constant expression EXP with a constant-descriptor DESC.
2167 Return 1 if DESC describes a constant with the same value as EXP. */
2169 static int
2170 compare_constant (exp, desc)
2171 tree exp;
2172 struct constant_descriptor *desc;
2174 return 0 != compare_constant_1 (exp, desc->contents);
2177 /* Compare constant expression EXP with a substring P of a constant descriptor.
2178 If they match, return a pointer to the end of the substring matched.
2179 If they do not match, return 0.
2181 Since descriptors are written in polish prefix notation,
2182 this function can be used recursively to test one operand of EXP
2183 against a subdescriptor, and if it succeeds it returns the
2184 address of the subdescriptor for the next operand. */
2186 static char *
2187 compare_constant_1 (exp, p)
2188 tree exp;
2189 char *p;
2191 register char *strp;
2192 register int len;
2193 register enum tree_code code = TREE_CODE (exp);
2195 if (code != (enum tree_code) *p++)
2196 return 0;
2198 if (code == INTEGER_CST)
2200 /* Integer constants are the same only if the same width of type. */
2201 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2202 return 0;
2203 strp = (char *) &TREE_INT_CST_LOW (exp);
2204 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2206 else if (code == REAL_CST)
2208 /* Real constants are the same only if the same width of type. */
2209 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2210 return 0;
2211 strp = (char *) &TREE_REAL_CST (exp);
2212 len = sizeof TREE_REAL_CST (exp);
2214 else if (code == STRING_CST)
2216 if (flag_writable_strings)
2217 return 0;
2218 strp = TREE_STRING_POINTER (exp);
2219 len = TREE_STRING_LENGTH (exp);
2220 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2221 sizeof TREE_STRING_LENGTH (exp)))
2222 return 0;
2223 p += sizeof TREE_STRING_LENGTH (exp);
2225 else if (code == COMPLEX_CST)
2227 p = compare_constant_1 (TREE_REALPART (exp), p);
2228 if (p == 0) return 0;
2229 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2230 return p;
2232 else if (code == CONSTRUCTOR)
2234 register tree link;
2235 int length = list_length (CONSTRUCTOR_ELTS (exp));
2236 tree type;
2238 if (bcmp ((char *) &length, p, sizeof length))
2239 return 0;
2240 p += sizeof length;
2242 /* For record constructors, insist that the types match.
2243 For arrays, just verify both constructors are for arrays. */
2244 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2245 type = TREE_TYPE (exp);
2246 else
2247 type = 0;
2248 if (bcmp ((char *) &type, p, sizeof type))
2249 return 0;
2250 p += sizeof type;
2252 /* For arrays, insist that the size in bytes match. */
2253 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2255 int size = int_size_in_bytes (TREE_TYPE (exp));
2256 if (bcmp ((char *) &size, p, sizeof size))
2257 return 0;
2258 p += sizeof size;
2261 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2263 if (TREE_VALUE (link))
2265 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2266 return 0;
2268 else
2270 tree zero = 0;
2272 if (bcmp ((char *) &zero, p, sizeof zero))
2273 return 0;
2274 p += sizeof zero;
2278 return p;
2280 else if (code == ADDR_EXPR)
2282 struct addr_const value;
2283 decode_addr_const (exp, &value);
2284 strp = (char *) &value.offset;
2285 len = sizeof value.offset;
2286 /* Compare the offset. */
2287 while (--len >= 0)
2288 if (*p++ != *strp++)
2289 return 0;
2290 /* Compare symbol name. */
2291 strp = XSTR (value.base, 0);
2292 len = strlen (strp) + 1;
2294 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2296 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2297 if (p == 0) return 0;
2298 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2299 return p;
2301 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2303 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2304 return p;
2307 /* Compare constant contents. */
2308 while (--len >= 0)
2309 if (*p++ != *strp++)
2310 return 0;
2312 return p;
2315 /* Construct a constant descriptor for the expression EXP.
2316 It is up to the caller to enter the descriptor in the hash table. */
2318 static struct constant_descriptor *
2319 record_constant (exp)
2320 tree exp;
2322 struct constant_descriptor *next = 0;
2323 char *label = 0;
2325 /* Make a struct constant_descriptor. The first two pointers will
2326 be filled in later. Here we just leave space for them. */
2328 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2329 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2330 record_constant_1 (exp);
2331 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2334 /* Add a description of constant expression EXP
2335 to the object growing in `permanent_obstack'.
2336 No need to return its address; the caller will get that
2337 from the obstack when the object is complete. */
2339 static void
2340 record_constant_1 (exp)
2341 tree exp;
2343 register char *strp;
2344 register int len;
2345 register enum tree_code code = TREE_CODE (exp);
2347 obstack_1grow (&permanent_obstack, (unsigned int) code);
2349 if (code == INTEGER_CST)
2351 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2352 strp = (char *) &TREE_INT_CST_LOW (exp);
2353 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2355 else if (code == REAL_CST)
2357 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2358 strp = (char *) &TREE_REAL_CST (exp);
2359 len = sizeof TREE_REAL_CST (exp);
2361 else if (code == STRING_CST)
2363 if (flag_writable_strings)
2364 return;
2365 strp = TREE_STRING_POINTER (exp);
2366 len = TREE_STRING_LENGTH (exp);
2367 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2368 sizeof TREE_STRING_LENGTH (exp));
2370 else if (code == COMPLEX_CST)
2372 record_constant_1 (TREE_REALPART (exp));
2373 record_constant_1 (TREE_IMAGPART (exp));
2374 return;
2376 else if (code == CONSTRUCTOR)
2378 register tree link;
2379 int length = list_length (CONSTRUCTOR_ELTS (exp));
2380 tree type;
2382 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2384 /* For record constructors, insist that the types match.
2385 For arrays, just verify both constructors are for arrays. */
2386 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2387 type = TREE_TYPE (exp);
2388 else
2389 type = 0;
2390 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2392 /* For arrays, insist that the size in bytes match. */
2393 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2395 int size = int_size_in_bytes (TREE_TYPE (exp));
2396 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2399 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2401 if (TREE_VALUE (link))
2402 record_constant_1 (TREE_VALUE (link));
2403 else
2405 tree zero = 0;
2407 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
2411 return;
2413 else if (code == ADDR_EXPR)
2415 struct addr_const value;
2416 decode_addr_const (exp, &value);
2417 /* Record the offset. */
2418 obstack_grow (&permanent_obstack,
2419 (char *) &value.offset, sizeof value.offset);
2420 /* Record the symbol name. */
2421 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2422 strlen (XSTR (value.base, 0)) + 1);
2423 return;
2425 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2427 record_constant_1 (TREE_OPERAND (exp, 0));
2428 record_constant_1 (TREE_OPERAND (exp, 1));
2429 return;
2431 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2433 record_constant_1 (TREE_OPERAND (exp, 0));
2434 return;
2437 /* Record constant contents. */
2438 obstack_grow (&permanent_obstack, strp, len);
2441 /* Record a list of constant expressions that were passed to
2442 output_constant_def but that could not be output right away. */
2444 struct deferred_constant
2446 struct deferred_constant *next;
2447 tree exp;
2448 int reloc;
2449 int labelno;
2452 static struct deferred_constant *deferred_constants;
2454 /* Nonzero means defer output of addressed subconstants
2455 (i.e., those for which output_constant_def is called.) */
2456 static int defer_addressed_constants_flag;
2458 /* Start deferring output of subconstants. */
2460 void
2461 defer_addressed_constants ()
2463 defer_addressed_constants_flag++;
2466 /* Stop deferring output of subconstants,
2467 and output now all those that have been deferred. */
2469 void
2470 output_deferred_addressed_constants ()
2472 struct deferred_constant *p, *next;
2474 defer_addressed_constants_flag--;
2476 if (defer_addressed_constants_flag > 0)
2477 return;
2479 for (p = deferred_constants; p; p = next)
2481 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2482 next = p->next;
2483 free (p);
2486 deferred_constants = 0;
2489 /* Make a copy of the whole tree structure for a constant.
2490 This handles the same types of nodes that compare_constant
2491 and record_constant handle. */
2493 static tree
2494 copy_constant (exp)
2495 tree exp;
2497 switch (TREE_CODE (exp))
2499 case INTEGER_CST:
2500 case REAL_CST:
2501 case STRING_CST:
2502 case ADDR_EXPR:
2503 /* For ADDR_EXPR, we do not want to copy the decl
2504 whose address is requested. */
2505 return copy_node (exp);
2507 case COMPLEX_CST:
2508 return build_complex (copy_constant (TREE_REALPART (exp)),
2509 copy_constant (TREE_IMAGPART (exp)));
2511 case PLUS_EXPR:
2512 case MINUS_EXPR:
2513 return build (TREE_CODE (exp), TREE_TYPE (exp),
2514 copy_constant (TREE_OPERAND (exp, 0)),
2515 copy_constant (TREE_OPERAND (exp, 1)));
2517 case NOP_EXPR:
2518 case CONVERT_EXPR:
2519 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2520 copy_constant (TREE_OPERAND (exp, 0)));
2522 case CONSTRUCTOR:
2524 tree copy = copy_node (exp);
2525 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2526 tree tail;
2528 CONSTRUCTOR_ELTS (copy) = list;
2529 for (tail = list; tail; tail = TREE_CHAIN (tail))
2530 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2532 return copy;
2535 default:
2536 abort ();
2540 /* Return an rtx representing a reference to constant data in memory
2541 for the constant expression EXP.
2543 If assembler code for such a constant has already been output,
2544 return an rtx to refer to it.
2545 Otherwise, output such a constant in memory (or defer it for later)
2546 and generate an rtx for it.
2548 The TREE_CST_RTL of EXP is set up to point to that rtx.
2549 The const_hash_table records which constants already have label strings. */
2552 output_constant_def (exp)
2553 tree exp;
2555 register int hash;
2556 register struct constant_descriptor *desc;
2557 char label[256];
2558 char *found = 0;
2559 int reloc;
2560 register rtx def;
2562 if (TREE_CODE (exp) == INTEGER_CST)
2563 abort (); /* No TREE_CST_RTL slot in these. */
2565 if (TREE_CST_RTL (exp))
2566 return TREE_CST_RTL (exp);
2568 /* Make sure any other constants whose addresses appear in EXP
2569 are assigned label numbers. */
2571 reloc = output_addressed_constants (exp);
2573 /* Compute hash code of EXP. Search the descriptors for that hash code
2574 to see if any of them describes EXP. If yes, the descriptor records
2575 the label number already assigned. */
2577 hash = const_hash (exp) % MAX_HASH_TABLE;
2579 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2580 if (compare_constant (exp, desc))
2582 found = desc->label;
2583 break;
2586 if (found == 0)
2588 /* No constant equal to EXP is known to have been output.
2589 Make a constant descriptor to enter EXP in the hash table.
2590 Assign the label number and record it in the descriptor for
2591 future calls to this function to find. */
2593 /* Create a string containing the label name, in LABEL. */
2594 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2596 desc = record_constant (exp);
2597 desc->next = const_hash_table[hash];
2598 desc->label
2599 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2600 const_hash_table[hash] = desc;
2602 else
2604 /* Create a string containing the label name, in LABEL. */
2605 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2608 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2610 push_obstacks_nochange ();
2611 if (TREE_PERMANENT (exp))
2612 end_temporary_allocation ();
2614 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2616 TREE_CST_RTL (exp)
2617 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2618 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2619 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2620 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2622 pop_obstacks ();
2624 /* Optionally set flags or add text to the name to record information
2625 such as that it is a function name. If the name is changed, the macro
2626 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2627 #ifdef ENCODE_SECTION_INFO
2628 ENCODE_SECTION_INFO (exp);
2629 #endif
2631 /* If this is the first time we've seen this particular constant,
2632 output it (or defer its output for later). */
2633 if (found == 0)
2635 if (defer_addressed_constants_flag)
2637 struct deferred_constant *p;
2638 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2640 push_obstacks_nochange ();
2641 suspend_momentary ();
2642 p->exp = copy_constant (exp);
2643 pop_obstacks ();
2644 p->reloc = reloc;
2645 p->labelno = const_labelno++;
2646 p->next = deferred_constants;
2647 deferred_constants = p;
2649 else
2650 output_constant_def_contents (exp, reloc, const_labelno++);
2653 return TREE_CST_RTL (exp);
2656 /* Now output assembler code to define the label for EXP,
2657 and follow it with the data of EXP. */
2659 static void
2660 output_constant_def_contents (exp, reloc, labelno)
2661 tree exp;
2662 int reloc;
2663 int labelno;
2665 int align;
2667 if (IN_NAMED_SECTION (exp))
2668 named_section (TREE_STRING_POINTER (DECL_SECTION_NAME (exp)));
2669 else
2671 /* First switch to text section, except for writable strings. */
2672 #ifdef SELECT_SECTION
2673 SELECT_SECTION (exp, reloc);
2674 #else
2675 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2676 || (flag_pic && reloc))
2677 data_section ();
2678 else
2679 readonly_data_section ();
2680 #endif
2683 /* Align the location counter as required by EXP's data type. */
2684 align = TYPE_ALIGN (TREE_TYPE (exp));
2685 #ifdef CONSTANT_ALIGNMENT
2686 align = CONSTANT_ALIGNMENT (exp, align);
2687 #endif
2689 if (align > BITS_PER_UNIT)
2691 if (!output_bytecode)
2693 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2695 else
2697 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2701 /* Output the label itself. */
2702 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2704 /* Output the value of EXP. */
2705 output_constant (exp,
2706 (TREE_CODE (exp) == STRING_CST
2707 ? TREE_STRING_LENGTH (exp)
2708 : int_size_in_bytes (TREE_TYPE (exp))));
2712 /* Similar hash facility for making memory-constants
2713 from constant rtl-expressions. It is used on RISC machines
2714 where immediate integer arguments and constant addresses are restricted
2715 so that such constants must be stored in memory.
2717 This pool of constants is reinitialized for each function
2718 so each function gets its own constants-pool that comes right before it.
2720 All structures allocated here are discarded when functions are saved for
2721 inlining, so they do not need to be allocated permanently. */
2723 #define MAX_RTX_HASH_TABLE 61
2724 static struct constant_descriptor **const_rtx_hash_table;
2726 /* Structure to represent sufficient information about a constant so that
2727 it can be output when the constant pool is output, so that function
2728 integration can be done, and to simplify handling on machines that reference
2729 constant pool as base+displacement. */
2731 struct pool_constant
2733 struct constant_descriptor *desc;
2734 struct pool_constant *next;
2735 enum machine_mode mode;
2736 rtx constant;
2737 int labelno;
2738 int align;
2739 int offset;
2742 /* Pointers to first and last constant in pool. */
2744 static struct pool_constant *first_pool, *last_pool;
2746 /* Current offset in constant pool (does not include any machine-specific
2747 header. */
2749 static int pool_offset;
2751 /* Structure used to maintain hash table mapping symbols used to their
2752 corresponding constants. */
2754 struct pool_sym
2756 char *label;
2757 struct pool_constant *pool;
2758 struct pool_sym *next;
2761 static struct pool_sym **const_rtx_sym_hash_table;
2763 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2764 The argument is XSTR (... , 0) */
2766 #define SYMHASH(LABEL) \
2767 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2769 /* Initialize constant pool hashing for next function. */
2771 void
2772 init_const_rtx_hash_table ()
2774 const_rtx_hash_table
2775 = ((struct constant_descriptor **)
2776 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2777 const_rtx_sym_hash_table
2778 = ((struct pool_sym **)
2779 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2780 bzero ((char *) const_rtx_hash_table,
2781 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2782 bzero ((char *) const_rtx_sym_hash_table,
2783 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2785 first_pool = last_pool = 0;
2786 pool_offset = 0;
2789 /* Save and restore it for a nested function. */
2791 void
2792 save_varasm_status (p)
2793 struct function *p;
2795 p->const_rtx_hash_table = const_rtx_hash_table;
2796 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2797 p->first_pool = first_pool;
2798 p->last_pool = last_pool;
2799 p->pool_offset = pool_offset;
2802 void
2803 restore_varasm_status (p)
2804 struct function *p;
2806 const_rtx_hash_table = p->const_rtx_hash_table;
2807 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2808 first_pool = p->first_pool;
2809 last_pool = p->last_pool;
2810 pool_offset = p->pool_offset;
2813 enum kind { RTX_DOUBLE, RTX_INT };
2815 struct rtx_const
2817 #ifdef ONLY_INT_FIELDS
2818 unsigned int kind : 16;
2819 unsigned int mode : 16;
2820 #else
2821 enum kind kind : 16;
2822 enum machine_mode mode : 16;
2823 #endif
2824 union {
2825 union real_extract du;
2826 struct addr_const addr;
2827 } un;
2830 /* Express an rtx for a constant integer (perhaps symbolic)
2831 as the sum of a symbol or label plus an explicit integer.
2832 They are stored into VALUE. */
2834 static void
2835 decode_rtx_const (mode, x, value)
2836 enum machine_mode mode;
2837 rtx x;
2838 struct rtx_const *value;
2840 /* Clear the whole structure, including any gaps. */
2843 int *p = (int *) value;
2844 int *end = (int *) (value + 1);
2845 while (p < end)
2846 *p++ = 0;
2849 value->kind = RTX_INT; /* Most usual kind. */
2850 value->mode = mode;
2852 switch (GET_CODE (x))
2854 case CONST_DOUBLE:
2855 value->kind = RTX_DOUBLE;
2856 if (GET_MODE (x) != VOIDmode)
2857 value->mode = GET_MODE (x);
2858 bcopy ((char *) &CONST_DOUBLE_LOW (x),
2859 (char *) &value->un.du, sizeof value->un.du);
2860 break;
2862 case CONST_INT:
2863 value->un.addr.offset = INTVAL (x);
2864 break;
2866 case SYMBOL_REF:
2867 case LABEL_REF:
2868 case PC:
2869 value->un.addr.base = x;
2870 break;
2872 case CONST:
2873 x = XEXP (x, 0);
2874 if (GET_CODE (x) == PLUS)
2876 value->un.addr.base = XEXP (x, 0);
2877 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2878 abort ();
2879 value->un.addr.offset = INTVAL (XEXP (x, 1));
2881 else if (GET_CODE (x) == MINUS)
2883 value->un.addr.base = XEXP (x, 0);
2884 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2885 abort ();
2886 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2888 else
2889 abort ();
2890 break;
2892 default:
2893 abort ();
2896 if (value->kind == RTX_INT && value->un.addr.base != 0)
2897 switch (GET_CODE (value->un.addr.base))
2899 case SYMBOL_REF:
2900 case LABEL_REF:
2901 /* Use the string's address, not the SYMBOL_REF's address,
2902 for the sake of addresses of library routines.
2903 For a LABEL_REF, compare labels. */
2904 value->un.addr.base = XEXP (value->un.addr.base, 0);
2908 /* Given a MINUS expression, simplify it if both sides
2909 include the same symbol. */
2912 simplify_subtraction (x)
2913 rtx x;
2915 struct rtx_const val0, val1;
2917 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2918 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2920 if (val0.un.addr.base == val1.un.addr.base)
2921 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2922 return x;
2925 /* Compute a hash code for a constant RTL expression. */
2928 const_hash_rtx (mode, x)
2929 enum machine_mode mode;
2930 rtx x;
2932 register int hi, i;
2934 struct rtx_const value;
2935 decode_rtx_const (mode, x, &value);
2937 /* Compute hashing function */
2938 hi = 0;
2939 for (i = 0; i < sizeof value / sizeof (int); i++)
2940 hi += ((int *) &value)[i];
2942 hi &= (1 << HASHBITS) - 1;
2943 hi %= MAX_RTX_HASH_TABLE;
2944 return hi;
2947 /* Compare a constant rtl object X with a constant-descriptor DESC.
2948 Return 1 if DESC describes a constant with the same value as X. */
2950 static int
2951 compare_constant_rtx (mode, x, desc)
2952 enum machine_mode mode;
2953 rtx x;
2954 struct constant_descriptor *desc;
2956 register int *p = (int *) desc->contents;
2957 register int *strp;
2958 register int len;
2959 struct rtx_const value;
2961 decode_rtx_const (mode, x, &value);
2962 strp = (int *) &value;
2963 len = sizeof value / sizeof (int);
2965 /* Compare constant contents. */
2966 while (--len >= 0)
2967 if (*p++ != *strp++)
2968 return 0;
2970 return 1;
2973 /* Construct a constant descriptor for the rtl-expression X.
2974 It is up to the caller to enter the descriptor in the hash table. */
2976 static struct constant_descriptor *
2977 record_constant_rtx (mode, x)
2978 enum machine_mode mode;
2979 rtx x;
2981 struct constant_descriptor *ptr;
2982 char *label;
2983 struct rtx_const value;
2985 decode_rtx_const (mode, x, &value);
2987 obstack_grow (current_obstack, &ptr, sizeof ptr);
2988 obstack_grow (current_obstack, &label, sizeof label);
2990 /* Record constant contents. */
2991 obstack_grow (current_obstack, &value, sizeof value);
2993 return (struct constant_descriptor *) obstack_finish (current_obstack);
2996 /* Given a constant rtx X, make (or find) a memory constant for its value
2997 and return a MEM rtx to refer to it in memory. */
3000 force_const_mem (mode, x)
3001 enum machine_mode mode;
3002 rtx x;
3004 register int hash;
3005 register struct constant_descriptor *desc;
3006 char label[256];
3007 char *found = 0;
3008 rtx def;
3010 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3011 (this will always be true for floating CONST_DOUBLEs that have been
3012 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3013 use the previous copy. Otherwise, make a new one. Note that in
3014 the unlikely event that this same CONST_DOUBLE is used in two different
3015 modes in an alternating fashion, we will allocate a lot of different
3016 memory locations, but this should be extremely rare. */
3018 /* Don't use CONST_DOUBLE_MEM in a nested function.
3019 Nested functions have their own constant pools,
3020 so they can't share the same values in CONST_DOUBLE_MEM
3021 with the containing function. */
3022 if (outer_function_chain == 0)
3023 if (GET_CODE (x) == CONST_DOUBLE
3024 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3025 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3026 return CONST_DOUBLE_MEM (x);
3028 /* Compute hash code of X. Search the descriptors for that hash code
3029 to see if any of them describes X. If yes, the descriptor records
3030 the label number already assigned. */
3032 hash = const_hash_rtx (mode, x);
3034 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3035 if (compare_constant_rtx (mode, x, desc))
3037 found = desc->label;
3038 break;
3041 if (found == 0)
3043 register struct pool_constant *pool;
3044 register struct pool_sym *sym;
3045 int align;
3047 /* No constant equal to X is known to have been output.
3048 Make a constant descriptor to enter X in the hash table.
3049 Assign the label number and record it in the descriptor for
3050 future calls to this function to find. */
3052 desc = record_constant_rtx (mode, x);
3053 desc->next = const_rtx_hash_table[hash];
3054 const_rtx_hash_table[hash] = desc;
3056 /* Align the location counter as required by EXP's data type. */
3057 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3058 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3059 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3061 pool_offset += align - 1;
3062 pool_offset &= ~ (align - 1);
3064 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3066 pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
3067 pool->desc = desc;
3068 pool->constant = x;
3069 pool->mode = mode;
3070 pool->labelno = const_labelno;
3071 pool->align = align;
3072 pool->offset = pool_offset;
3073 pool->next = 0;
3075 if (last_pool == 0)
3076 first_pool = pool;
3077 else
3078 last_pool->next = pool;
3080 last_pool = pool;
3081 pool_offset += GET_MODE_SIZE (mode);
3083 /* Create a string containing the label name, in LABEL. */
3084 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3086 ++const_labelno;
3088 desc->label = found
3089 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3091 /* Add label to symbol hash table. */
3092 hash = SYMHASH (found);
3093 sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
3094 sym->label = found;
3095 sym->pool = pool;
3096 sym->next = const_rtx_sym_hash_table[hash];
3097 const_rtx_sym_hash_table[hash] = sym;
3100 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3102 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3104 RTX_UNCHANGING_P (def) = 1;
3105 /* Mark the symbol_ref as belonging to this constants pool. */
3106 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3107 current_function_uses_const_pool = 1;
3109 if (outer_function_chain == 0)
3110 if (GET_CODE (x) == CONST_DOUBLE)
3112 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3114 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3115 const_double_chain = x;
3117 CONST_DOUBLE_MEM (x) = def;
3120 return def;
3123 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3124 the corresponding pool_constant structure. */
3126 static struct pool_constant *
3127 find_pool_constant (addr)
3128 rtx addr;
3130 struct pool_sym *sym;
3131 char *label = XSTR (addr, 0);
3133 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3134 if (sym->label == label)
3135 return sym->pool;
3137 abort ();
3140 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3143 get_pool_constant (addr)
3144 rtx addr;
3146 return (find_pool_constant (addr))->constant;
3149 /* Similar, return the mode. */
3151 enum machine_mode
3152 get_pool_mode (addr)
3153 rtx addr;
3155 return (find_pool_constant (addr))->mode;
3158 /* Similar, return the offset in the constant pool. */
3161 get_pool_offset (addr)
3162 rtx addr;
3164 return (find_pool_constant (addr))->offset;
3167 /* Return the size of the constant pool. */
3170 get_pool_size ()
3172 return pool_offset;
3175 /* Write all the constants in the constant pool. */
3177 void
3178 output_constant_pool (fnname, fndecl)
3179 char *fnname;
3180 tree fndecl;
3182 struct pool_constant *pool;
3183 rtx x;
3184 union real_extract u;
3186 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3187 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3188 #endif
3190 for (pool = first_pool; pool; pool = pool->next)
3192 x = pool->constant;
3194 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3195 whose CODE_LABEL has been deleted. This can occur if a jump table
3196 is eliminated by optimization. If so, write a constant of zero
3197 instead. Note that this can also happen by turning the
3198 CODE_LABEL into a NOTE. */
3199 if (((GET_CODE (x) == LABEL_REF
3200 && (INSN_DELETED_P (XEXP (x, 0))
3201 || GET_CODE (XEXP (x, 0)) == NOTE)))
3202 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3203 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3204 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3205 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3206 x = const0_rtx;
3208 /* First switch to correct section. */
3209 #ifdef SELECT_RTX_SECTION
3210 SELECT_RTX_SECTION (pool->mode, x);
3211 #else
3212 readonly_data_section ();
3213 #endif
3215 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3216 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3217 pool->align, pool->labelno, done);
3218 #endif
3220 if (pool->align > 1)
3221 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3223 /* Output the label. */
3224 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3226 /* Output the value of the constant itself. */
3227 switch (GET_MODE_CLASS (pool->mode))
3229 case MODE_FLOAT:
3230 if (GET_CODE (x) != CONST_DOUBLE)
3231 abort ();
3233 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3234 assemble_real (u.d, pool->mode);
3235 break;
3237 case MODE_INT:
3238 case MODE_PARTIAL_INT:
3239 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3240 break;
3242 default:
3243 abort ();
3246 done: ;
3249 /* Done with this pool. */
3250 first_pool = last_pool = 0;
3253 /* Find all the constants whose addresses are referenced inside of EXP,
3254 and make sure assembler code with a label has been output for each one.
3255 Indicate whether an ADDR_EXPR has been encountered. */
3258 output_addressed_constants (exp)
3259 tree exp;
3261 int reloc = 0;
3263 switch (TREE_CODE (exp))
3265 case ADDR_EXPR:
3267 register tree constant = TREE_OPERAND (exp, 0);
3269 while (TREE_CODE (constant) == COMPONENT_REF)
3271 constant = TREE_OPERAND (constant, 0);
3274 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3275 || TREE_CODE (constant) == CONSTRUCTOR)
3276 /* No need to do anything here
3277 for addresses of variables or functions. */
3278 output_constant_def (constant);
3280 reloc = 1;
3281 break;
3283 case PLUS_EXPR:
3284 case MINUS_EXPR:
3285 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3286 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3287 break;
3289 case NOP_EXPR:
3290 case CONVERT_EXPR:
3291 case NON_LVALUE_EXPR:
3292 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3293 break;
3295 case CONSTRUCTOR:
3297 register tree link;
3298 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3299 if (TREE_VALUE (link) != 0)
3300 reloc |= output_addressed_constants (TREE_VALUE (link));
3302 break;
3304 case ERROR_MARK:
3305 break;
3307 return reloc;
3311 /* Output assembler for byte constant */
3312 void
3313 output_byte_asm (byte)
3314 int byte;
3316 if (output_bytecode)
3317 bc_emit_const ((char *) &byte, sizeof (char));
3318 #ifdef ASM_OUTPUT_BYTE
3319 else
3321 ASM_OUTPUT_BYTE (asm_out_file, byte);
3323 #endif
3326 /* Output assembler code for constant EXP to FILE, with no label.
3327 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3328 Assumes output_addressed_constants has been done on EXP already.
3330 Generate exactly SIZE bytes of assembler data, padding at the end
3331 with zeros if necessary. SIZE must always be specified.
3333 SIZE is important for structure constructors,
3334 since trailing members may have been omitted from the constructor.
3335 It is also important for initialization of arrays from string constants
3336 since the full length of the string constant might not be wanted.
3337 It is also needed for initialization of unions, where the initializer's
3338 type is just one member, and that may not be as long as the union.
3340 There a case in which we would fail to output exactly SIZE bytes:
3341 for a structure constructor that wants to produce more than SIZE bytes.
3342 But such constructors will never be generated for any possible input. */
3344 void
3345 output_constant (exp, size)
3346 register tree exp;
3347 register int size;
3349 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3350 rtx x;
3352 if (size == 0)
3353 return;
3355 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3356 That way we get the constant (we hope) inside it. Also, strip
3357 off any NOP_EXPR that converts between two record or union types. */
3358 while ((TREE_CODE (exp) == NOP_EXPR
3359 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3360 || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3361 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
3362 || TREE_CODE (TREE_TYPE (exp)) == QUAL_UNION_TYPE))
3363 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3364 exp = TREE_OPERAND (exp, 0);
3366 /* Allow a constructor with no elements for any data type.
3367 This means to fill the space with zeros. */
3368 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3370 if (output_bytecode)
3371 bc_emit_const_skip (size);
3372 else
3373 assemble_zeros (size);
3374 return;
3377 switch (code)
3379 case CHAR_TYPE:
3380 case BOOLEAN_TYPE:
3381 case INTEGER_TYPE:
3382 case ENUMERAL_TYPE:
3383 case POINTER_TYPE:
3384 case REFERENCE_TYPE:
3385 /* ??? What about (int)((float)(int)&foo + 4) */
3386 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3387 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3388 exp = TREE_OPERAND (exp, 0);
3390 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3391 EXPAND_INITIALIZER),
3392 size, 0))
3393 error ("initializer for integer value is too complicated");
3394 size = 0;
3395 break;
3397 case REAL_TYPE:
3398 if (TREE_CODE (exp) != REAL_CST)
3399 error ("initializer for floating value is not a floating constant");
3401 assemble_real (TREE_REAL_CST (exp),
3402 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3403 size = 0;
3404 break;
3406 case COMPLEX_TYPE:
3407 output_constant (TREE_REALPART (exp), size / 2);
3408 output_constant (TREE_IMAGPART (exp), size / 2);
3409 size -= (size / 2) * 2;
3410 break;
3412 case ARRAY_TYPE:
3413 if (TREE_CODE (exp) == CONSTRUCTOR)
3415 output_constructor (exp, size);
3416 return;
3418 else if (TREE_CODE (exp) == STRING_CST)
3420 int excess = 0;
3422 if (size > TREE_STRING_LENGTH (exp))
3424 excess = size - TREE_STRING_LENGTH (exp);
3425 size = TREE_STRING_LENGTH (exp);
3428 assemble_string (TREE_STRING_POINTER (exp), size);
3429 size = excess;
3431 else
3432 abort ();
3433 break;
3435 case RECORD_TYPE:
3436 case UNION_TYPE:
3437 if (TREE_CODE (exp) == CONSTRUCTOR)
3438 output_constructor (exp, size);
3439 else
3440 abort ();
3441 return;
3444 if (size > 0)
3445 assemble_zeros (size);
3449 /* Bytecode specific code to output assembler for integer. */
3450 static void
3451 bc_assemble_integer (exp, size)
3452 tree exp;
3453 int size;
3455 tree const_part;
3456 tree addr_part;
3457 tree tmp;
3459 /* FIXME: is this fold() business going to be as good as the
3460 expand_expr() using EXPAND_SUM above in the RTL case? I
3461 hate RMS.
3462 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3464 exp = fold (exp);
3466 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3467 exp = TREE_OPERAND (exp, 0);
3468 if (TREE_CODE (exp) == INTEGER_CST)
3470 const_part = exp;
3471 addr_part = 0;
3473 else if (TREE_CODE (exp) == PLUS_EXPR)
3475 const_part = TREE_OPERAND (exp, 0);
3476 while (TREE_CODE (const_part) == NOP_EXPR
3477 || TREE_CODE (const_part) == CONVERT_EXPR)
3478 const_part = TREE_OPERAND (const_part, 0);
3479 addr_part = TREE_OPERAND (exp, 1);
3480 while (TREE_CODE (addr_part) == NOP_EXPR
3481 || TREE_CODE (addr_part) == CONVERT_EXPR)
3482 addr_part = TREE_OPERAND (addr_part, 0);
3483 if (TREE_CODE (const_part) != INTEGER_CST)
3484 tmp = const_part, const_part = addr_part, addr_part = tmp;
3485 if (TREE_CODE (const_part) != INTEGER_CST
3486 || TREE_CODE (addr_part) != ADDR_EXPR)
3487 abort (); /* FIXME: we really haven't considered
3488 all the possible cases here. */
3490 else if (TREE_CODE (exp) == ADDR_EXPR)
3492 const_part = integer_zero_node;
3493 addr_part = exp;
3495 else
3496 abort (); /* FIXME: ditto previous. */
3498 if (addr_part == 0)
3500 if (size == 1)
3502 char c = TREE_INT_CST_LOW (const_part);
3503 bc_emit (&c, 1);
3504 size -= 1;
3506 else if (size == 2)
3508 short s = TREE_INT_CST_LOW (const_part);
3509 bc_emit ((char *) &s, 2);
3510 size -= 2;
3512 else if (size == 4)
3514 int i = TREE_INT_CST_LOW (const_part);
3515 bc_emit ((char *) &i, 4);
3516 size -= 4;
3518 else if (size == 8)
3520 #if WORDS_BIG_ENDIAN
3521 int i = TREE_INT_CST_HIGH (const_part);
3522 bc_emit ((char *) &i, 4);
3523 i = TREE_INT_CST_LOW (const_part);
3524 bc_emit ((char *) &i, 4);
3525 #else
3526 int i = TREE_INT_CST_LOW (const_part);
3527 bc_emit ((char *) &i, 4);
3528 i = TREE_INT_CST_HIGH (const_part);
3529 bc_emit ((char *) &i, 4);
3530 #endif
3531 size -= 8;
3534 else
3535 if (size == 4
3536 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3537 bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3538 TREE_INT_CST_LOW (const_part));
3539 else
3540 abort (); /* FIXME: there may be more cases. */
3543 /* Subroutine of output_constant, used for CONSTRUCTORs
3544 (aggregate constants).
3545 Generate at least SIZE bytes, padding if necessary. */
3547 void
3548 output_constructor (exp, size)
3549 tree exp;
3550 int size;
3552 register tree link, field = 0;
3553 HOST_WIDE_INT min_index = 0;
3554 /* Number of bytes output or skipped so far.
3555 In other words, current position within the constructor. */
3556 int total_bytes = 0;
3557 /* Non-zero means BYTE contains part of a byte, to be output. */
3558 int byte_buffer_in_use = 0;
3559 register int byte;
3561 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3562 abort ();
3564 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3565 field = TYPE_FIELDS (TREE_TYPE (exp));
3567 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3568 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3569 min_index
3570 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3572 /* As LINK goes through the elements of the constant,
3573 FIELD goes through the structure fields, if the constant is a structure.
3574 if the constant is a union, then we override this,
3575 by getting the field from the TREE_LIST element.
3576 But the constant could also be an array. Then FIELD is zero. */
3577 for (link = CONSTRUCTOR_ELTS (exp);
3578 link;
3579 link = TREE_CHAIN (link),
3580 field = field ? TREE_CHAIN (field) : 0)
3582 tree val = TREE_VALUE (link);
3583 tree index = 0;
3585 /* the element in a union constructor specifies the proper field. */
3587 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3588 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3590 /* if available, use the type given by link */
3591 if (TREE_PURPOSE (link) != 0)
3592 field = TREE_PURPOSE (link);
3595 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3596 index = TREE_PURPOSE (link);
3598 /* Eliminate the marker that makes a cast not be an lvalue. */
3599 if (val != 0)
3600 STRIP_NOPS (val);
3602 if (field == 0 || !DECL_BIT_FIELD (field))
3604 /* An element that is not a bit-field. */
3606 register int fieldsize;
3607 /* Since this structure is static,
3608 we know the positions are constant. */
3609 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3610 / BITS_PER_UNIT)
3611 : 0);
3612 if (index != 0)
3613 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3614 / BITS_PER_UNIT
3615 * (TREE_INT_CST_LOW (index) - min_index));
3617 /* Output any buffered-up bit-fields preceding this element. */
3618 if (byte_buffer_in_use)
3620 ASM_OUTPUT_BYTE (asm_out_file, byte);
3621 total_bytes++;
3622 byte_buffer_in_use = 0;
3625 /* Advance to offset of this element.
3626 Note no alignment needed in an array, since that is guaranteed
3627 if each element has the proper size. */
3628 if ((field != 0 || index != 0) && bitpos != total_bytes)
3630 if (!output_bytecode)
3631 assemble_zeros (bitpos - total_bytes);
3632 else
3633 bc_emit_const_skip (bitpos - total_bytes);
3634 total_bytes = bitpos;
3637 /* Determine size this element should occupy. */
3638 if (field)
3640 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3641 abort ();
3642 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3644 /* This avoids overflow trouble. */
3645 tree size_tree = size_binop (CEIL_DIV_EXPR,
3646 DECL_SIZE (field),
3647 size_int (BITS_PER_UNIT));
3648 fieldsize = TREE_INT_CST_LOW (size_tree);
3650 else
3652 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3653 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3656 else
3657 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3659 /* Output the element's initial value. */
3660 if (val == 0)
3661 assemble_zeros (fieldsize);
3662 else
3663 output_constant (val, fieldsize);
3665 /* Count its size. */
3666 total_bytes += fieldsize;
3668 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3669 error ("invalid initial value for member `%s'",
3670 IDENTIFIER_POINTER (DECL_NAME (field)));
3671 else
3673 /* Element that is a bit-field. */
3675 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3676 int end_offset
3677 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3679 if (val == 0)
3680 val = integer_zero_node;
3682 /* If this field does not start in this (or, next) byte,
3683 skip some bytes. */
3684 if (next_offset / BITS_PER_UNIT != total_bytes)
3686 /* Output remnant of any bit field in previous bytes. */
3687 if (byte_buffer_in_use)
3689 ASM_OUTPUT_BYTE (asm_out_file, byte);
3690 total_bytes++;
3691 byte_buffer_in_use = 0;
3694 /* If still not at proper byte, advance to there. */
3695 if (next_offset / BITS_PER_UNIT != total_bytes)
3697 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3698 total_bytes = next_offset / BITS_PER_UNIT;
3702 if (! byte_buffer_in_use)
3703 byte = 0;
3705 /* We must split the element into pieces that fall within
3706 separate bytes, and combine each byte with previous or
3707 following bit-fields. */
3709 /* next_offset is the offset n fbits from the beginning of
3710 the structure to the next bit of this element to be processed.
3711 end_offset is the offset of the first bit past the end of
3712 this element. */
3713 while (next_offset < end_offset)
3715 int this_time;
3716 int shift, value;
3717 int next_byte = next_offset / BITS_PER_UNIT;
3718 int next_bit = next_offset % BITS_PER_UNIT;
3720 /* Advance from byte to byte
3721 within this element when necessary. */
3722 while (next_byte != total_bytes)
3724 ASM_OUTPUT_BYTE (asm_out_file, byte);
3725 total_bytes++;
3726 byte = 0;
3729 /* Number of bits we can process at once
3730 (all part of the same byte). */
3731 this_time = MIN (end_offset - next_offset,
3732 BITS_PER_UNIT - next_bit);
3733 #if BYTES_BIG_ENDIAN
3734 /* On big-endian machine, take the most significant bits
3735 first (of the bits that are significant)
3736 and put them into bytes from the most significant end. */
3737 shift = end_offset - next_offset - this_time;
3738 /* Don't try to take a bunch of bits that cross
3739 the word boundary in the INTEGER_CST. */
3740 if (shift < HOST_BITS_PER_WIDE_INT
3741 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3743 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3744 shift = HOST_BITS_PER_WIDE_INT;
3747 /* Now get the bits from the appropriate constant word. */
3748 if (shift < HOST_BITS_PER_WIDE_INT)
3750 value = TREE_INT_CST_LOW (val);
3752 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3754 value = TREE_INT_CST_HIGH (val);
3755 shift -= HOST_BITS_PER_WIDE_INT;
3757 else
3758 abort ();
3759 byte |= (((value >> shift)
3760 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3761 << (BITS_PER_UNIT - this_time - next_bit));
3762 #else
3763 /* On little-endian machines,
3764 take first the least significant bits of the value
3765 and pack them starting at the least significant
3766 bits of the bytes. */
3767 shift = (next_offset
3768 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3769 /* Don't try to take a bunch of bits that cross
3770 the word boundary in the INTEGER_CST. */
3771 if (shift < HOST_BITS_PER_WIDE_INT
3772 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3774 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3775 shift = HOST_BITS_PER_WIDE_INT;
3778 /* Now get the bits from the appropriate constant word. */
3779 if (shift < HOST_BITS_PER_INT)
3780 value = TREE_INT_CST_LOW (val);
3781 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3783 value = TREE_INT_CST_HIGH (val);
3784 shift -= HOST_BITS_PER_WIDE_INT;
3786 else
3787 abort ();
3788 byte |= ((value >> shift)
3789 & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
3790 #endif
3791 next_offset += this_time;
3792 byte_buffer_in_use = 1;
3796 if (byte_buffer_in_use)
3798 ASM_OUTPUT_BYTE (asm_out_file, byte);
3799 total_bytes++;
3801 if (total_bytes < size)
3802 assemble_zeros (size - total_bytes);
3806 #ifdef HANDLE_SYSV_PRAGMA
3808 /* Support #pragma weak by default if WEAK_ASM_OP and ASM_OUTPUT_DEF
3809 are defined. */
3810 #if defined (WEAK_ASM_OP) && defined (ASM_OUTPUT_DEF)
3812 /* See c-pragma.c for an identical definition. */
3813 enum pragma_state
3815 ps_start,
3816 ps_done,
3817 ps_bad,
3818 ps_weak,
3819 ps_name,
3820 ps_equals,
3821 ps_value,
3822 ps_pack,
3823 ps_left,
3824 ps_align,
3825 ps_right
3828 /* Output asm to handle ``#pragma weak'' */
3829 void
3830 handle_pragma_weak (what, asm_out_file, name, value)
3831 enum pragma_state what;
3832 FILE *asm_out_file;
3833 char *name, *value;
3835 if (what == ps_name || what == ps_value)
3837 fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
3839 if (output_bytecode)
3840 BC_OUTPUT_LABELREF (asm_out_file, name);
3841 else
3842 ASM_OUTPUT_LABELREF (asm_out_file, name);
3844 fputc ('\n', asm_out_file);
3845 if (what == ps_value)
3846 ASM_OUTPUT_DEF (asm_out_file, name, value);
3848 else if (! (what == ps_done || what == ps_start))
3849 warning ("malformed `#pragma weak'");
3852 #endif /* HANDLE_PRAGMA_WEAK or (WEAK_ASM_OP and SET_ASM_OP) */
3854 #endif /* WEAK_ASM_OP && ASM_OUTPUT_DEF */