(output_constant): When eliminating conversions, treat ARRAY_TYPE like
[official-gcc.git] / gcc / varasm.c
blobd0733d34f5e2b8ee75bfbdfa4658733ef417e031
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 *rtl_obstack;
73 extern struct obstack permanent_obstack;
74 #define obstack_chunk_alloc xmalloc
76 /* Number for making the label on the next
77 constant that is stored in memory. */
79 int const_labelno;
81 /* Number for making the label on the next
82 static variable internal to a function. */
84 int var_labelno;
86 /* Carry information from ASM_DECLARE_OBJECT_NAME
87 to ASM_FINISH_DECLARE_OBJECT. */
89 int size_directive_output;
91 /* The last decl for which assemble_variable was called,
92 if it did ASM_DECLARE_OBJECT_NAME.
93 If the last call to assemble_variable didn't do that,
94 this holds 0. */
96 tree last_assemble_variable_decl;
98 /* Nonzero if at least one function definition has been seen. */
99 static int function_defined;
101 extern FILE *asm_out_file;
103 static char *compare_constant_1 ();
104 static void record_constant_1 ();
105 static void output_constant_def_contents ();
106 static int contains_pointers_p ();
107 static void bc_output_ascii ();
109 void output_constant_pool ();
110 void assemble_name ();
111 int output_addressed_constants ();
112 void output_constant ();
113 void output_constructor ();
114 void output_byte_asm ();
115 void text_section ();
116 void readonly_data_section ();
117 void data_section ();
118 void named_section ();
119 static void bc_assemble_integer ();
121 #ifdef EXTRA_SECTIONS
122 static enum in_section {no_section, in_text, in_data, in_named, EXTRA_SECTIONS} in_section
123 = no_section;
124 #else
125 static enum in_section {no_section, in_text, in_data, in_named} in_section
126 = no_section;
127 #endif
129 /* Return a non-zero value if DECL has a section attribute. */
130 #define IN_NAMED_SECTION(DECL) \
131 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
132 && DECL_SECTION_NAME (DECL) != NULL_TREE)
134 /* Text of section name when in_section == in_named. */
135 static char *in_named_name;
137 /* Define functions like text_section for any extra sections. */
138 #ifdef EXTRA_SECTION_FUNCTIONS
139 EXTRA_SECTION_FUNCTIONS
140 #endif
142 /* Tell assembler to switch to text section. */
144 void
145 text_section ()
147 if (in_section != in_text)
149 if (output_bytecode)
150 bc_text ();
151 else
152 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
154 in_section = in_text;
158 /* Tell assembler to switch to data section. */
160 void
161 data_section ()
163 if (in_section != in_data)
165 if (output_bytecode)
166 bc_data ();
167 else
169 if (flag_shared_data)
171 #ifdef SHARED_SECTION_ASM_OP
172 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
173 #else
174 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
175 #endif
177 else
178 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
181 in_section = in_data;
185 /* Tell assembler to switch to read-only data section. This is normally
186 the text section. */
188 void
189 readonly_data_section ()
191 #ifdef READONLY_DATA_SECTION
192 READONLY_DATA_SECTION (); /* Note this can call data_section. */
193 #else
194 text_section ();
195 #endif
198 /* Determine if we're in the text section. */
201 in_text_section ()
203 return in_section == in_text;
206 /* Tell assembler to change to section NAME for DECL.
207 If DECL is NULL, just switch to section NAME.
208 If NAME is NULL, get the name from DECL. */
210 void
211 named_section (decl, name)
212 tree decl;
213 char *name;
215 if (decl != NULL_TREE
216 && (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL))
217 abort ();
218 if (name == NULL)
219 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
221 if (in_section != in_named || strcmp (name, in_named_name))
223 in_named_name = name;
224 in_section = in_named;
226 #ifdef ASM_OUTPUT_SECTION_NAME
227 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name);
228 #else
229 /* Section attributes are not supported if this macro isn't provided -
230 some host formats don't support them at all. The front-end should
231 already have flagged this as an error. */
232 abort ();
233 #endif
237 /* Create the rtl to represent a function, for a function definition.
238 DECL is a FUNCTION_DECL node which describes which function.
239 The rtl is stored into DECL. */
241 void
242 make_function_rtl (decl)
243 tree decl;
245 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
247 if (output_bytecode)
249 if (DECL_RTL (decl) == 0)
250 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
252 /* Record that at least one function has been defined. */
253 function_defined = 1;
254 return;
257 /* Rename a nested function to avoid conflicts. */
258 if (decl_function_context (decl) != 0
259 && DECL_INITIAL (decl) != 0
260 && DECL_RTL (decl) == 0)
262 char *label;
264 name = IDENTIFIER_POINTER (DECL_NAME (decl));
265 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
266 name = obstack_copy0 (saveable_obstack, label, strlen (label));
267 var_labelno++;
270 if (DECL_RTL (decl) == 0)
272 DECL_RTL (decl)
273 = gen_rtx (MEM, DECL_MODE (decl),
274 gen_rtx (SYMBOL_REF, Pmode, name));
276 /* Optionally set flags or add text to the name to record information
277 such as that it is a function name. If the name is changed, the macro
278 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
279 #ifdef ENCODE_SECTION_INFO
280 ENCODE_SECTION_INFO (decl);
281 #endif
284 /* Record at least one function has been defined. */
285 function_defined = 1;
288 /* Create the DECL_RTL for a declaration for a static or external
289 variable or static or external function.
290 ASMSPEC, if not 0, is the string which the user specified
291 as the assembler symbol name.
292 TOP_LEVEL is nonzero if this is a file-scope variable.
293 This is never called for PARM_DECLs. */
294 void
295 bc_make_decl_rtl (decl, asmspec, top_level)
296 tree decl;
297 char *asmspec;
298 int top_level;
300 register char *name = TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl));
302 if (DECL_RTL (decl) == 0)
304 /* Print an error message for register variables. */
305 if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
306 error ("function declared `register'");
307 else if (DECL_REGISTER (decl))
308 error ("global register variables not supported in the interpreter");
310 /* Handle ordinary static variables and functions. */
311 if (DECL_RTL (decl) == 0)
313 /* Can't use just the variable's own name for a variable
314 whose scope is less than the whole file.
315 Concatenate a distinguishing number. */
316 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
318 char *label;
320 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
321 name = obstack_copy0 (saveable_obstack, label, strlen (label));
322 var_labelno++;
325 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
330 /* Given NAME, a putative register name, discard any customary prefixes. */
332 static char *
333 strip_reg_name (name)
334 char *name;
336 #ifdef REGISTER_PREFIX
337 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
338 name += strlen (REGISTER_PREFIX);
339 #endif
340 if (name[0] == '%' || name[0] == '#')
341 name++;
342 return name;
345 /* Decode an `asm' spec for a declaration as a register name.
346 Return the register number, or -1 if nothing specified,
347 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
348 or -3 if ASMSPEC is `cc' and is not recognized,
349 or -4 if ASMSPEC is `memory' and is not recognized.
350 Accept an exact spelling or a decimal number.
351 Prefixes such as % are optional. */
354 decode_reg_name (asmspec)
355 char *asmspec;
357 if (asmspec != 0)
359 int i;
361 /* Get rid of confusing prefixes. */
362 asmspec = strip_reg_name (asmspec);
364 /* Allow a decimal number as a "register name". */
365 for (i = strlen (asmspec) - 1; i >= 0; i--)
366 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
367 break;
368 if (asmspec[0] != 0 && i < 0)
370 i = atoi (asmspec);
371 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
372 return i;
373 else
374 return -2;
377 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
378 if (reg_names[i][0]
379 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
380 return i;
382 #ifdef ADDITIONAL_REGISTER_NAMES
384 static struct { char *name; int number; } table[]
385 = ADDITIONAL_REGISTER_NAMES;
387 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
388 if (! strcmp (asmspec, table[i].name))
389 return table[i].number;
391 #endif /* ADDITIONAL_REGISTER_NAMES */
393 if (!strcmp (asmspec, "memory"))
394 return -4;
396 if (!strcmp (asmspec, "cc"))
397 return -3;
399 return -2;
402 return -1;
405 /* Create the DECL_RTL for a declaration for a static or external variable
406 or static or external function.
407 ASMSPEC, if not 0, is the string which the user specified
408 as the assembler symbol name.
409 TOP_LEVEL is nonzero if this is a file-scope variable.
411 This is never called for PARM_DECL nodes. */
413 void
414 make_decl_rtl (decl, asmspec, top_level)
415 tree decl;
416 char *asmspec;
417 int top_level;
419 register char *name = 0;
420 int reg_number;
422 if (output_bytecode)
424 bc_make_decl_rtl (decl, asmspec, top_level);
425 return;
428 reg_number = decode_reg_name (asmspec);
430 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
431 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
433 if (reg_number == -2)
435 /* ASMSPEC is given, and not the name of a register. */
436 name = (char *) obstack_alloc (saveable_obstack,
437 strlen (asmspec) + 2);
438 name[0] = '*';
439 strcpy (&name[1], asmspec);
442 /* For a duplicate declaration, we can be called twice on the
443 same DECL node. Don't discard the RTL already made. */
444 if (DECL_RTL (decl) == 0)
446 DECL_RTL (decl) = 0;
448 /* First detect errors in declaring global registers. */
449 if (DECL_REGISTER (decl) && reg_number == -1)
450 error_with_decl (decl,
451 "register name not specified for `%s'");
452 else if (DECL_REGISTER (decl) && reg_number < 0)
453 error_with_decl (decl,
454 "invalid register name for `%s'");
455 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
456 error_with_decl (decl,
457 "register name given for non-register variable `%s'");
458 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
459 error ("function declared `register'");
460 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
461 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
462 else if (DECL_REGISTER (decl)
463 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
464 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
465 /* Now handle properly declared static register variables. */
466 else if (DECL_REGISTER (decl))
468 int nregs;
469 #if 0 /* yylex should print the warning for this */
470 if (pedantic)
471 pedwarn ("ANSI C forbids global register variables");
472 #endif
473 if (DECL_INITIAL (decl) != 0 && top_level)
475 DECL_INITIAL (decl) = 0;
476 error ("global register variable has initial value");
478 if (fixed_regs[reg_number] == 0
479 && function_defined && top_level)
480 error ("global register variable follows a function definition");
481 if (TREE_THIS_VOLATILE (decl))
482 warning ("volatile register variables don't work as you might wish");
484 /* If the user specified one of the eliminables registers here,
485 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
486 confused with that register and be eliminated. Although this
487 usage is somewhat suspect, we nevertheless use the following
488 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
490 DECL_RTL (decl)
491 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
492 REGNO (DECL_RTL (decl)) = reg_number;
493 REG_USERVAR_P (DECL_RTL (decl)) = 1;
495 if (top_level)
497 /* Make this register global, so not usable for anything
498 else. */
499 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
500 while (nregs > 0)
501 globalize_reg (reg_number + --nregs);
504 /* Specifying a section attribute on an uninitialized variable does not
505 (and cannot) cause it to be put in the given section. The linker
506 can only put initialized objects in specific sections, everything
507 else goes in bss for the linker to sort out later (otherwise the
508 linker would give a duplicate definition error for each compilation
509 unit that behaved thusly). So warn the user. */
510 else if (TREE_CODE (decl) == VAR_DECL
511 && DECL_SECTION_NAME (decl) != NULL_TREE
512 && DECL_INITIAL (decl) == NULL_TREE)
514 warning_with_decl (decl,
515 "section attribute ignored for uninitialized variable `%s'");
516 /* Remove the section name so subsequent declarations won't see it.
517 We are ignoring it, remember. */
518 DECL_SECTION_NAME (decl) = NULL_TREE;
521 /* Now handle ordinary static variables and functions (in memory).
522 Also handle vars declared register invalidly. */
523 if (DECL_RTL (decl) == 0)
525 /* Can't use just the variable's own name for a variable
526 whose scope is less than the whole file.
527 Concatenate a distinguishing number. */
528 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
530 char *label;
532 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
533 name = obstack_copy0 (saveable_obstack, label, strlen (label));
534 var_labelno++;
537 if (name == 0)
538 abort ();
540 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
541 gen_rtx (SYMBOL_REF, Pmode, name));
543 /* If this variable is to be treated as volatile, show its
544 tree node has side effects. If it has side effects, either
545 because of this test or from TREE_THIS_VOLATILE also
546 being set, show the MEM is volatile. */
547 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
548 && TREE_PUBLIC (decl))
549 TREE_SIDE_EFFECTS (decl) = 1;
550 if (TREE_SIDE_EFFECTS (decl))
551 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
553 if (TREE_READONLY (decl))
554 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
555 MEM_IN_STRUCT_P (DECL_RTL (decl))
556 = AGGREGATE_TYPE_P (TREE_TYPE (decl));
558 /* Optionally set flags or add text to the name to record information
559 such as that it is a function name.
560 If the name is changed, the macro ASM_OUTPUT_LABELREF
561 will have to know how to strip this information. */
562 #ifdef ENCODE_SECTION_INFO
563 ENCODE_SECTION_INFO (decl);
564 #endif
567 /* If the old RTL had the wrong mode, fix the mode. */
568 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
570 rtx rtl = DECL_RTL (decl);
571 PUT_MODE (rtl, DECL_MODE (decl));
575 /* Make the rtl for variable VAR be volatile.
576 Use this only for static variables. */
578 void
579 make_var_volatile (var)
580 tree var;
582 if (GET_CODE (DECL_RTL (var)) != MEM)
583 abort ();
585 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
588 /* Output alignment directive to align for constant expression EXP. */
590 void
591 assemble_constant_align (exp)
592 tree exp;
594 int align;
596 /* Align the location counter as required by EXP's data type. */
597 align = TYPE_ALIGN (TREE_TYPE (exp));
598 #ifdef CONSTANT_ALIGNMENT
599 align = CONSTANT_ALIGNMENT (exp, align);
600 #endif
602 if (align > BITS_PER_UNIT)
603 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
606 /* Output a string of literal assembler code
607 for an `asm' keyword used between functions. */
609 void
610 assemble_asm (string)
611 tree string;
613 if (output_bytecode)
615 error ("asm statements not allowed in interpreter");
616 return;
619 app_enable ();
621 if (TREE_CODE (string) == ADDR_EXPR)
622 string = TREE_OPERAND (string, 0);
624 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
627 #if 0 /* This should no longer be needed, because
628 flag_gnu_linker should be 0 on these systems,
629 which should prevent any output
630 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
631 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
632 #ifndef ASM_OUTPUT_CONSTRUCTOR
633 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
634 #endif
635 #ifndef ASM_OUTPUT_DESTRUCTOR
636 #define ASM_OUTPUT_DESTRUCTOR(file, name)
637 #endif
638 #endif
639 #endif /* 0 */
641 /* Record an element in the table of global destructors.
642 How this is done depends on what sort of assembler and linker
643 are in use.
645 NAME should be the name of a global function to be called
646 at exit time. This name is output using assemble_name. */
648 void
649 assemble_destructor (name)
650 char *name;
652 #ifdef ASM_OUTPUT_DESTRUCTOR
653 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
654 #else
655 if (flag_gnu_linker)
657 /* Now tell GNU LD that this is part of the static destructor set. */
658 /* This code works for any machine provided you use GNU as/ld. */
659 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
660 assemble_name (asm_out_file, name);
661 fputc ('\n', asm_out_file);
663 #endif
666 /* Likewise for global constructors. */
668 void
669 assemble_constructor (name)
670 char *name;
672 #ifdef ASM_OUTPUT_CONSTRUCTOR
673 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
674 #else
675 if (flag_gnu_linker)
677 /* Now tell GNU LD that this is part of the static constructor set. */
678 /* This code works for any machine provided you use GNU as/ld. */
679 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
680 assemble_name (asm_out_file, name);
681 fputc ('\n', asm_out_file);
683 #endif
686 /* Likewise for entries we want to record for garbage collection.
687 Garbage collection is still under development. */
689 void
690 assemble_gc_entry (name)
691 char *name;
693 #ifdef ASM_OUTPUT_GC_ENTRY
694 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
695 #else
696 if (flag_gnu_linker)
698 /* Now tell GNU LD that this is part of the static constructor set. */
699 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
700 assemble_name (asm_out_file, name);
701 fputc ('\n', asm_out_file);
703 #endif
706 /* Output assembler code for the constant pool of a function and associated
707 with defining the name of the function. DECL describes the function.
708 NAME is the function's name. For the constant pool, we use the current
709 constant pool data. */
711 void
712 assemble_start_function (decl, fnname)
713 tree decl;
714 char *fnname;
716 int align;
718 /* The following code does not need preprocessing in the assembler. */
720 app_disable ();
722 output_constant_pool (fnname, decl);
724 if (IN_NAMED_SECTION (decl))
725 named_section (decl, NULL);
726 else
727 text_section ();
729 /* Tell assembler to move to target machine's alignment for functions. */
730 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
731 if (align > 0)
733 if (output_bytecode)
734 BC_OUTPUT_ALIGN (asm_out_file, align);
735 else
736 ASM_OUTPUT_ALIGN (asm_out_file, align);
739 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
740 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
741 #endif
743 #ifdef SDB_DEBUGGING_INFO
744 /* Output SDB definition of the function. */
745 if (write_symbols == SDB_DEBUG)
746 sdbout_mark_begin_function ();
747 #endif
749 #ifdef DBX_DEBUGGING_INFO
750 /* Output DBX definition of the function. */
751 if (write_symbols == DBX_DEBUG)
752 dbxout_begin_function (decl);
753 #endif
755 /* Make function name accessible from other files, if appropriate. */
757 if (TREE_PUBLIC (decl))
759 if (!first_global_object_name)
760 STRIP_NAME_ENCODING (first_global_object_name, fnname);
761 if (output_bytecode)
762 BC_GLOBALIZE_LABEL (asm_out_file, fnname);
763 else
764 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
767 /* Do any machine/system dependent processing of the function name */
768 #ifdef ASM_DECLARE_FUNCTION_NAME
769 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
770 #else
771 /* Standard thing is just output label for the function. */
772 if (output_bytecode)
773 BC_OUTPUT_LABEL (asm_out_file, fnname);
774 else
775 ASM_OUTPUT_LABEL (asm_out_file, fnname);
776 #endif /* ASM_DECLARE_FUNCTION_NAME */
779 /* Output assembler code associated with defining the size of the
780 function. DECL describes the function. NAME is the function's name. */
782 void
783 assemble_end_function (decl, fnname)
784 tree decl;
785 char *fnname;
787 #ifdef ASM_DECLARE_FUNCTION_SIZE
788 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
789 #endif
792 /* Assemble code to leave SIZE bytes of zeros. */
794 void
795 assemble_zeros (size)
796 int size;
798 if (output_bytecode)
800 bc_emit_const_skip (size);
801 return;
804 #ifdef ASM_NO_SKIP_IN_TEXT
805 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
806 so we must output 0s explicitly in the text section. */
807 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
809 int i;
811 for (i = 0; i < size - 20; i += 20)
813 #ifdef ASM_BYTE_OP
814 fprintf (asm_out_file,
815 "%s 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", ASM_BYTE_OP);
816 #else
817 fprintf (asm_out_file,
818 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
819 #endif
821 if (i < size)
823 #ifdef ASM_BYTE_OP
824 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
825 #else
826 fprintf (asm_out_file, "\tbyte 0");
827 #endif
828 i++;
829 for (; i < size; i++)
830 fprintf (asm_out_file, ",0");
831 fprintf (asm_out_file, "\n");
834 else
835 #endif
836 if (size > 0)
838 if (output_bytecode)
839 BC_OUTPUT_SKIP (asm_out_file, size);
840 else
841 ASM_OUTPUT_SKIP (asm_out_file, size);
845 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
847 void
848 assemble_align (align)
849 int align;
851 if (align > BITS_PER_UNIT)
852 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
855 /* Assemble a string constant with the specified C string as contents. */
857 void
858 assemble_string (p, size)
859 char *p;
860 int size;
862 register int i;
863 int pos = 0;
864 int maximum = 2000;
866 if (output_bytecode)
868 bc_emit (p, size);
869 return;
872 /* If the string is very long, split it up. */
874 while (pos < size)
876 int thissize = size - pos;
877 if (thissize > maximum)
878 thissize = maximum;
880 if (output_bytecode)
881 bc_output_ascii (asm_out_file, p, thissize);
882 else
884 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
887 pos += thissize;
888 p += thissize;
892 static void
893 bc_output_ascii (file, p, size)
894 FILE *file;
895 char *p;
896 int size;
898 BC_OUTPUT_ASCII (file, p, size);
901 /* Assemble everything that is needed for a variable or function declaration.
902 Not used for automatic variables, and not used for function definitions.
903 Should not be called for variables of incomplete structure type.
905 TOP_LEVEL is nonzero if this variable has file scope.
906 AT_END is nonzero if this is the special handling, at end of compilation,
907 to define things that have had only tentative definitions.
908 DONT_OUTPUT_DATA if nonzero means don't actually output the
909 initial value (that will be done by the caller). */
911 void
912 assemble_variable (decl, top_level, at_end, dont_output_data)
913 tree decl;
914 int top_level;
915 int at_end;
917 register char *name;
918 int align;
919 tree size_tree;
920 int reloc = 0;
921 enum in_section saved_in_section;
923 last_assemble_variable_decl = 0;
925 if (output_bytecode)
926 return;
928 if (GET_CODE (DECL_RTL (decl)) == REG)
930 /* Do output symbol info for global register variables, but do nothing
931 else for them. */
933 if (TREE_ASM_WRITTEN (decl))
934 return;
935 TREE_ASM_WRITTEN (decl) = 1;
937 if (!output_bytecode)
939 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
940 /* File-scope global variables are output here. */
941 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
942 && top_level)
943 dbxout_symbol (decl, 0);
944 #endif
945 #ifdef SDB_DEBUGGING_INFO
946 if (write_symbols == SDB_DEBUG && top_level
947 /* Leave initialized global vars for end of compilation;
948 see comment in compile_file. */
949 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
950 sdbout_symbol (decl, 0);
951 #endif
954 /* Don't output any DWARF debugging information for variables here.
955 In the case of local variables, the information for them is output
956 when we do our recursive traversal of the tree representation for
957 the entire containing function. In the case of file-scope variables,
958 we output information for all of them at the very end of compilation
959 while we are doing our final traversal of the chain of file-scope
960 declarations. */
962 return;
965 /* Normally no need to say anything here for external references,
966 since assemble_external is called by the langauge-specific code
967 when a declaration is first seen. */
969 if (DECL_EXTERNAL (decl))
970 return;
972 /* Output no assembler code for a function declaration.
973 Only definitions of functions output anything. */
975 if (TREE_CODE (decl) == FUNCTION_DECL)
976 return;
978 /* If type was incomplete when the variable was declared,
979 see if it is complete now. */
981 if (DECL_SIZE (decl) == 0)
982 layout_decl (decl, 0);
984 /* Still incomplete => don't allocate it; treat the tentative defn
985 (which is what it must have been) as an `extern' reference. */
987 if (!dont_output_data && DECL_SIZE (decl) == 0)
989 error_with_file_and_line (DECL_SOURCE_FILE (decl),
990 DECL_SOURCE_LINE (decl),
991 "storage size of `%s' isn't known",
992 IDENTIFIER_POINTER (DECL_NAME (decl)));
993 TREE_ASM_WRITTEN (decl) = 1;
994 return;
997 /* The first declaration of a variable that comes through this function
998 decides whether it is global (in C, has external linkage)
999 or local (in C, has internal linkage). So do nothing more
1000 if this function has already run. */
1002 if (TREE_ASM_WRITTEN (decl))
1003 return;
1005 TREE_ASM_WRITTEN (decl) = 1;
1007 /* If storage size is erroneously variable, just continue.
1008 Error message was already made. */
1010 if (DECL_SIZE (decl))
1012 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1013 goto finish;
1015 app_disable ();
1017 /* This is better than explicit arithmetic, since it avoids overflow. */
1018 size_tree = size_binop (CEIL_DIV_EXPR,
1019 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1021 if (TREE_INT_CST_HIGH (size_tree) != 0)
1023 error_with_decl (decl, "size of variable `%s' is too large");
1024 goto finish;
1028 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1030 /* Handle uninitialized definitions. */
1032 /* ANSI specifies that a tentative definition which is not merged with
1033 a non-tentative definition behaves exactly like a definition with an
1034 initializer equal to zero. (Section 3.7.2)
1035 -fno-common gives strict ANSI behavior. Usually you don't want it.
1036 This matters only for variables with external linkage. */
1037 if ((! flag_no_common || ! TREE_PUBLIC (decl))
1038 && DECL_COMMON (decl)
1039 && ! dont_output_data
1040 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
1042 int size = TREE_INT_CST_LOW (size_tree);
1043 int rounded = size;
1045 if (TREE_INT_CST_HIGH (size_tree) != 0)
1046 error_with_decl (decl, "size of variable `%s' is too large");
1047 /* Don't allocate zero bytes of common,
1048 since that means "undefined external" in the linker. */
1049 if (size == 0) rounded = 1;
1050 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1051 so that each uninitialized object starts on such a boundary. */
1052 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1053 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1054 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1056 #ifdef DBX_DEBUGGING_INFO
1057 /* File-scope global variables are output here. */
1058 if (write_symbols == DBX_DEBUG && top_level)
1059 dbxout_symbol (decl, 0);
1060 #endif
1061 #ifdef SDB_DEBUGGING_INFO
1062 if (write_symbols == SDB_DEBUG && top_level
1063 /* Leave initialized global vars for end of compilation;
1064 see comment in compile_file. */
1065 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1066 sdbout_symbol (decl, 0);
1067 #endif
1069 /* Don't output any DWARF debugging information for variables here.
1070 In the case of local variables, the information for them is output
1071 when we do our recursive traversal of the tree representation for
1072 the entire containing function. In the case of file-scope variables,
1073 we output information for all of them at the very end of compilation
1074 while we are doing our final traversal of the chain of file-scope
1075 declarations. */
1077 #if 0
1078 if (flag_shared_data)
1079 data_section ();
1080 #endif
1081 if (TREE_PUBLIC (decl))
1083 #ifdef ASM_OUTPUT_SHARED_COMMON
1084 if (flag_shared_data)
1085 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1086 else
1087 #endif
1088 if (output_bytecode)
1090 BC_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1092 else
1094 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1095 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1096 DECL_ALIGN (decl));
1097 #else
1098 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1099 #endif
1102 else
1104 #ifdef ASM_OUTPUT_SHARED_LOCAL
1105 if (flag_shared_data)
1106 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1107 else
1108 #endif
1109 if (output_bytecode)
1111 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1113 else
1115 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1116 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1117 DECL_ALIGN (decl));
1118 #else
1119 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1120 #endif
1123 goto finish;
1126 /* Handle initialized definitions. */
1128 /* First make the assembler name(s) global if appropriate. */
1129 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1131 if (!first_global_object_name)
1132 STRIP_NAME_ENCODING(first_global_object_name, name);
1133 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1135 #if 0
1136 for (d = equivalents; d; d = TREE_CHAIN (d))
1138 tree e = TREE_VALUE (d);
1139 if (TREE_PUBLIC (e) && DECL_NAME (e))
1140 ASM_GLOBALIZE_LABEL (asm_out_file,
1141 XSTR (XEXP (DECL_RTL (e), 0), 0));
1143 #endif
1145 /* Output any data that we will need to use the address of. */
1146 if (DECL_INITIAL (decl) == error_mark_node)
1147 reloc = contains_pointers_p (TREE_TYPE (decl));
1148 else if (DECL_INITIAL (decl))
1149 reloc = output_addressed_constants (DECL_INITIAL (decl));
1151 /* Switch to the proper section for this data. */
1152 if (IN_NAMED_SECTION (decl))
1153 named_section (decl, NULL);
1154 else
1156 /* C++ can have const variables that get initialized from constructors,
1157 and thus can not be in a readonly section. We prevent this by
1158 verifying that the initial value is constant for objects put in a
1159 readonly section.
1161 error_mark_node is used by the C front end to indicate that the
1162 initializer has not been seen yet. In this case, we assume that
1163 the initializer must be constant. */
1164 #ifdef SELECT_SECTION
1165 SELECT_SECTION (decl, reloc);
1166 #else
1167 if (TREE_READONLY (decl)
1168 && ! TREE_THIS_VOLATILE (decl)
1169 && DECL_INITIAL (decl)
1170 && (DECL_INITIAL (decl) == error_mark_node
1171 || TREE_CONSTANT (DECL_INITIAL (decl)))
1172 && ! (flag_pic && reloc))
1173 readonly_data_section ();
1174 else
1175 data_section ();
1176 #endif
1179 /* dbxout.c needs to know this. */
1180 if (in_text_section ())
1181 DECL_IN_TEXT_SECTION (decl) = 1;
1183 /* Record current section so we can restore it if dbxout.c clobbers it. */
1184 saved_in_section = in_section;
1186 /* Output the dbx info now that we have chosen the section. */
1188 #ifdef DBX_DEBUGGING_INFO
1189 /* File-scope global variables are output here. */
1190 if (write_symbols == DBX_DEBUG && top_level)
1191 dbxout_symbol (decl, 0);
1192 #endif
1193 #ifdef SDB_DEBUGGING_INFO
1194 if (write_symbols == SDB_DEBUG && top_level
1195 /* Leave initialized global vars for end of compilation;
1196 see comment in compile_file. */
1197 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1198 sdbout_symbol (decl, 0);
1199 #endif
1201 /* Don't output any DWARF debugging information for variables here.
1202 In the case of local variables, the information for them is output
1203 when we do our recursive traversal of the tree representation for
1204 the entire containing function. In the case of file-scope variables,
1205 we output information for all of them at the very end of compilation
1206 while we are doing our final traversal of the chain of file-scope
1207 declarations. */
1209 /* If the debugging output changed sections, reselect the section
1210 that's supposed to be selected. */
1211 if (in_section != saved_in_section)
1213 /* Switch to the proper section for this data. */
1214 #ifdef SELECT_SECTION
1215 SELECT_SECTION (decl, reloc);
1216 #else
1217 if (TREE_READONLY (decl)
1218 && ! TREE_THIS_VOLATILE (decl)
1219 && DECL_INITIAL (decl)
1220 && (DECL_INITIAL (decl) == error_mark_node
1221 || TREE_CONSTANT (DECL_INITIAL (decl)))
1222 && ! (flag_pic && reloc))
1223 readonly_data_section ();
1224 else
1225 data_section ();
1226 #endif
1229 /* Compute and output the alignment of this data. */
1231 align = DECL_ALIGN (decl);
1232 /* In the case for initialing an array whose length isn't specified,
1233 where we have not yet been able to do the layout,
1234 figure out the proper alignment now. */
1235 if (dont_output_data && DECL_SIZE (decl) == 0
1236 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1237 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1239 /* Some object file formats have a maximum alignment which they support.
1240 In particular, a.out format supports a maximum alignment of 4. */
1241 #ifndef MAX_OFILE_ALIGNMENT
1242 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1243 #endif
1244 if (align > MAX_OFILE_ALIGNMENT)
1246 warning_with_decl (decl,
1247 "alignment of `%s' is greater than maximum object file alignment");
1248 align = MAX_OFILE_ALIGNMENT;
1250 #ifdef DATA_ALIGNMENT
1251 /* On some machines, it is good to increase alignment sometimes. */
1252 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1253 #endif
1254 #ifdef CONSTANT_ALIGNMENT
1255 if (DECL_INITIAL (decl))
1256 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1257 #endif
1259 /* Reset the alignment in case we have made it tighter, so we can benefit
1260 from it in get_pointer_alignment. */
1261 DECL_ALIGN (decl) = align;
1263 if (align > BITS_PER_UNIT)
1265 if (output_bytecode)
1266 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1267 else
1268 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1271 /* Do any machine/system dependent processing of the object. */
1272 #ifdef ASM_DECLARE_OBJECT_NAME
1273 last_assemble_variable_decl = decl;
1274 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1275 #else
1276 /* Standard thing is just output label for the object. */
1277 if (output_bytecode)
1278 BC_OUTPUT_LABEL (asm_out_file, name);
1279 else
1280 ASM_OUTPUT_LABEL (asm_out_file, name);
1281 #endif /* ASM_DECLARE_OBJECT_NAME */
1283 if (!dont_output_data)
1285 if (DECL_INITIAL (decl))
1286 /* Output the actual data. */
1287 output_constant (DECL_INITIAL (decl),
1288 int_size_in_bytes (TREE_TYPE (decl)));
1289 else
1290 /* Leave space for it. */
1291 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1294 finish:
1295 #ifdef XCOFF_DEBUGGING_INFO
1296 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1297 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1298 and `aa' hasn't been output yet, the assembler generates a stab entry with
1299 a value of zero, in addition to creating an unnecessary external entry
1300 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1302 /* File-scope global variables are output here. */
1303 if (write_symbols == XCOFF_DEBUG && top_level)
1305 saved_in_section = in_section;
1307 dbxout_symbol (decl, 0);
1309 if (in_section != saved_in_section)
1311 /* Switch to the proper section for this data. */
1312 #ifdef SELECT_SECTION
1313 SELECT_SECTION (decl, reloc);
1314 #else
1315 if (TREE_READONLY (decl)
1316 && ! TREE_THIS_VOLATILE (decl)
1317 && DECL_INITIAL (decl)
1318 && (DECL_INITIAL (decl) == error_mark_node
1319 || TREE_CONSTANT (DECL_INITIAL (decl)))
1320 && ! (flag_pic && reloc))
1321 readonly_data_section ();
1322 else
1323 data_section ();
1324 #endif
1327 #else
1328 /* There must be a statement after a label. */
1330 #endif
1333 /* Return 1 if type TYPE contains any pointers. */
1335 static int
1336 contains_pointers_p (type)
1337 tree type;
1339 switch (TREE_CODE (type))
1341 case POINTER_TYPE:
1342 case REFERENCE_TYPE:
1343 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1344 so I'll play safe and return 1. */
1345 case OFFSET_TYPE:
1346 return 1;
1348 case RECORD_TYPE:
1349 case UNION_TYPE:
1350 case QUAL_UNION_TYPE:
1352 tree fields;
1353 /* For a type that has fields, see if the fields have pointers. */
1354 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1355 if (TREE_CODE (fields) == FIELD_DECL
1356 && contains_pointers_p (TREE_TYPE (fields)))
1357 return 1;
1358 return 0;
1361 case ARRAY_TYPE:
1362 /* An array type contains pointers if its element type does. */
1363 return contains_pointers_p (TREE_TYPE (type));
1365 default:
1366 return 0;
1370 /* Output text storage for constructor CONSTR. */
1372 void
1373 bc_output_constructor (constr)
1374 tree constr;
1376 int i;
1378 /* Must always be a literal; non-literal constructors are handled
1379 differently. */
1381 if (!TREE_CONSTANT (constr))
1382 abort ();
1384 /* Always const */
1385 text_section ();
1387 /* Align */
1388 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1389 if (i > 0)
1390 BC_OUTPUT_ALIGN (asm_out_file, i);
1392 /* Output data */
1393 output_constant (constr, int_size_in_bytes (TREE_TYPE (constr)));
1397 /* Create storage for constructor CONSTR. */
1399 void
1400 bc_output_data_constructor (constr)
1401 tree constr;
1403 int i;
1405 /* Put in data section */
1406 data_section ();
1408 /* Align */
1409 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1410 if (i > 0)
1411 BC_OUTPUT_ALIGN (asm_out_file, i);
1413 /* The constructor is filled in at runtime. */
1414 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1418 /* Output something to declare an external symbol to the assembler.
1419 (Most assemblers don't need this, so we normally output nothing.)
1420 Do nothing if DECL is not external. */
1422 void
1423 assemble_external (decl)
1424 tree decl;
1426 if (output_bytecode)
1427 return;
1429 #ifdef ASM_OUTPUT_EXTERNAL
1430 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1431 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1433 rtx rtl = DECL_RTL (decl);
1435 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1436 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1438 /* Some systems do require some output. */
1439 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1440 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1443 #endif
1446 /* Similar, for calling a library function FUN. */
1448 void
1449 assemble_external_libcall (fun)
1450 rtx fun;
1452 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1453 if (!output_bytecode)
1455 /* Declare library function name external when first used, if nec. */
1456 if (! SYMBOL_REF_USED (fun))
1458 SYMBOL_REF_USED (fun) = 1;
1459 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1462 #endif
1465 /* Declare the label NAME global. */
1467 void
1468 assemble_global (name)
1469 char *name;
1471 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1474 /* Assemble a label named NAME. */
1476 void
1477 assemble_label (name)
1478 char *name;
1480 if (output_bytecode)
1481 BC_OUTPUT_LABEL (asm_out_file, name);
1482 else
1483 ASM_OUTPUT_LABEL (asm_out_file, name);
1486 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1487 If NAME starts with a *, the rest of NAME is output verbatim.
1488 Otherwise NAME is transformed in an implementation-defined way
1489 (usually by the addition of an underscore).
1490 Many macros in the tm file are defined to call this function. */
1492 void
1493 assemble_name (file, name)
1494 FILE *file;
1495 char *name;
1497 char *real_name;
1499 STRIP_NAME_ENCODING (real_name, name);
1500 TREE_SYMBOL_REFERENCED (get_identifier (real_name)) = 1;
1502 if (name[0] == '*')
1504 if (output_bytecode)
1505 bc_emit_labelref (name);
1506 else
1507 fputs (&name[1], file);
1509 else
1511 if (output_bytecode)
1512 BC_OUTPUT_LABELREF (file, name);
1513 else
1514 ASM_OUTPUT_LABELREF (file, name);
1518 /* Allocate SIZE bytes writable static space with a gensym name
1519 and return an RTX to refer to its address. */
1522 assemble_static_space (size)
1523 int size;
1525 char name[12];
1526 char *namestring;
1527 rtx x;
1528 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1529 so that each uninitialized object starts on such a boundary. */
1530 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1531 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1532 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1534 #if 0
1535 if (flag_shared_data)
1536 data_section ();
1537 #endif
1539 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1540 ++const_labelno;
1542 namestring = (char *) obstack_alloc (saveable_obstack,
1543 strlen (name) + 2);
1544 strcpy (namestring, name);
1546 if (output_bytecode)
1547 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1548 else
1549 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1551 if (output_bytecode)
1553 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1555 else
1557 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1558 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1559 #else
1560 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1561 #endif
1563 return x;
1566 /* Assemble the static constant template for function entry trampolines.
1567 This is done at most once per compilation.
1568 Returns an RTX for the address of the template. */
1571 assemble_trampoline_template ()
1573 char label[256];
1574 char *name;
1575 int align;
1577 /* Shouldn't get here */
1578 if (output_bytecode)
1579 abort ();
1581 /* By default, put trampoline templates in read-only data section. */
1583 #ifdef TRAMPOLINE_SECTION
1584 TRAMPOLINE_SECTION ();
1585 #else
1586 readonly_data_section ();
1587 #endif
1589 /* Write the assembler code to define one. */
1590 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1591 if (align > 0)
1592 ASM_OUTPUT_ALIGN (asm_out_file, align);
1594 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1595 TRAMPOLINE_TEMPLATE (asm_out_file);
1597 /* Record the rtl to refer to it. */
1598 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1599 name
1600 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1601 return gen_rtx (SYMBOL_REF, Pmode, name);
1604 /* Assemble the integer constant X into an object of SIZE bytes.
1605 X must be either a CONST_INT or CONST_DOUBLE.
1607 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1608 non-zero, abort if we can't output the constant. */
1611 assemble_integer (x, size, force)
1612 rtx x;
1613 int size;
1614 int force;
1616 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1617 ASM_OUTPUT... macros. */
1619 switch (size)
1621 #ifdef ASM_OUTPUT_CHAR
1622 case 1:
1623 ASM_OUTPUT_CHAR (asm_out_file, x);
1624 return 1;
1625 #endif
1627 #ifdef ASM_OUTPUT_SHORT
1628 case 2:
1629 ASM_OUTPUT_SHORT (asm_out_file, x);
1630 return 1;
1631 #endif
1633 #ifdef ASM_OUTPUT_INT
1634 case 4:
1635 ASM_OUTPUT_INT (asm_out_file, x);
1636 return 1;
1637 #endif
1639 #ifdef ASM_OUTPUT_DOUBLE_INT
1640 case 8:
1641 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1642 return 1;
1643 #endif
1645 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1646 case 16:
1647 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1648 return 1;
1649 #endif
1652 /* If we couldn't do it that way, there are two other possibilities: First,
1653 if the machine can output an explicit byte and this is a 1 byte constant,
1654 we can use ASM_OUTPUT_BYTE. */
1656 #ifdef ASM_OUTPUT_BYTE
1657 if (size == 1 && GET_CODE (x) == CONST_INT)
1659 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1660 return 1;
1662 #endif
1664 /* Finally, if SIZE is larger than a single word, try to output the constant
1665 one word at a time. */
1667 if (size > UNITS_PER_WORD)
1669 int i;
1670 enum machine_mode mode
1671 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1672 rtx word;
1674 for (i = 0; i < size / UNITS_PER_WORD; i++)
1676 word = operand_subword (x, i, 0, mode);
1678 if (word == 0)
1679 break;
1681 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1682 break;
1685 if (i == size / UNITS_PER_WORD)
1686 return 1;
1687 /* If we output at least one word and then could not finish,
1688 there is no valid way to continue. */
1689 if (i > 0)
1690 abort ();
1693 if (force)
1694 abort ();
1696 return 0;
1699 /* Assemble the floating-point constant D into an object of size MODE. */
1701 void
1702 assemble_real (d, mode)
1703 REAL_VALUE_TYPE d;
1704 enum machine_mode mode;
1706 jmp_buf output_constant_handler;
1708 if (setjmp (output_constant_handler))
1710 error ("floating point trap outputting a constant");
1711 #ifdef REAL_IS_NOT_DOUBLE
1712 bzero ((char *) &d, sizeof d);
1713 d = dconst0;
1714 #else
1715 d = 0;
1716 #endif
1719 set_float_handler (output_constant_handler);
1721 switch (mode)
1723 #ifdef ASM_OUTPUT_BYTE_FLOAT
1724 case QFmode:
1725 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1726 break;
1727 #endif
1728 #ifdef ASM_OUTPUT_SHORT_FLOAT
1729 case HFmode:
1730 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1731 break;
1732 #endif
1733 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1734 case TQFmode:
1735 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1736 break;
1737 #endif
1738 #ifdef ASM_OUTPUT_FLOAT
1739 case SFmode:
1740 ASM_OUTPUT_FLOAT (asm_out_file, d);
1741 break;
1742 #endif
1744 #ifdef ASM_OUTPUT_DOUBLE
1745 case DFmode:
1746 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1747 break;
1748 #endif
1750 #ifdef ASM_OUTPUT_LONG_DOUBLE
1751 case XFmode:
1752 case TFmode:
1753 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1754 break;
1755 #endif
1757 default:
1758 abort ();
1761 set_float_handler (NULL_PTR);
1764 /* Here we combine duplicate floating constants to make
1765 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1767 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1768 They are chained through the CONST_DOUBLE_CHAIN.
1769 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1770 In that case, CONST_DOUBLE_MEM is either a MEM,
1771 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1773 (CONST_DOUBLE_MEM is used only for top-level functions.
1774 See force_const_mem for explanation.) */
1776 static rtx const_double_chain;
1778 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1779 For an integer, I0 is the low-order word and I1 is the high-order word.
1780 For a real number, I0 is the word with the low address
1781 and I1 is the word with the high address. */
1784 immed_double_const (i0, i1, mode)
1785 HOST_WIDE_INT i0, i1;
1786 enum machine_mode mode;
1788 register rtx r;
1789 int in_current_obstack;
1791 if (GET_MODE_CLASS (mode) == MODE_INT
1792 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1794 /* We clear out all bits that don't belong in MODE, unless they and our
1795 sign bit are all one. So we get either a reasonable negative value
1796 or a reasonable unsigned value for this mode. */
1797 int width = GET_MODE_BITSIZE (mode);
1798 if (width < HOST_BITS_PER_WIDE_INT
1799 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1800 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1801 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1802 else if (width == HOST_BITS_PER_WIDE_INT
1803 && ! (i1 == ~0 && i0 < 0))
1804 i1 = 0;
1805 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1806 /* We cannot represent this value as a constant. */
1807 abort ();
1809 /* If this would be an entire word for the target, but is not for
1810 the host, then sign-extend on the host so that the number will look
1811 the same way on the host that it would on the target.
1813 For example, when building a 64 bit alpha hosted 32 bit sparc
1814 targeted compiler, then we want the 32 bit unsigned value -1 to be
1815 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1816 The later confuses the sparc backend. */
1818 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1819 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1820 i0 |= ((HOST_WIDE_INT) (-1) << width);
1822 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1824 ??? Strictly speaking, this is wrong if we create a CONST_INT
1825 for a large unsigned constant with the size of MODE being
1826 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1827 wider mode. In that case we will mis-interpret it as a negative
1828 number.
1830 Unfortunately, the only alternative is to make a CONST_DOUBLE
1831 for any constant in any mode if it is an unsigned constant larger
1832 than the maximum signed integer in an int on the host. However,
1833 doing this will break everyone that always expects to see a CONST_INT
1834 for SImode and smaller.
1836 We have always been making CONST_INTs in this case, so nothing new
1837 is being broken. */
1839 if (width <= HOST_BITS_PER_WIDE_INT)
1840 i1 = (i0 < 0) ? ~0 : 0;
1842 /* If this integer fits in one word, return a CONST_INT. */
1843 if ((i1 == 0 && i0 >= 0)
1844 || (i1 == ~0 && i0 < 0))
1845 return GEN_INT (i0);
1847 /* We use VOIDmode for integers. */
1848 mode = VOIDmode;
1851 /* Search the chain for an existing CONST_DOUBLE with the right value.
1852 If one is found, return it. */
1854 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1855 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1856 && GET_MODE (r) == mode)
1857 return r;
1859 /* No; make a new one and add it to the chain.
1861 We may be called by an optimizer which may be discarding any memory
1862 allocated during its processing (such as combine and loop). However,
1863 we will be leaving this constant on the chain, so we cannot tolerate
1864 freed memory. So switch to saveable_obstack for this allocation
1865 and then switch back if we were in current_obstack. */
1867 push_obstacks_nochange ();
1868 rtl_in_saveable_obstack ();
1869 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1870 pop_obstacks ();
1872 /* Don't touch const_double_chain in nested function; see force_const_mem.
1873 Also, don't touch it if not inside any function. */
1874 if (outer_function_chain == 0 && current_function_decl != 0)
1876 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1877 const_double_chain = r;
1880 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1881 Actual use of mem-slot is only through force_const_mem. */
1883 CONST_DOUBLE_MEM (r) = const0_rtx;
1885 return r;
1888 /* Return a CONST_DOUBLE for a specified `double' value
1889 and machine mode. */
1892 immed_real_const_1 (d, mode)
1893 REAL_VALUE_TYPE d;
1894 enum machine_mode mode;
1896 union real_extract u;
1897 register rtx r;
1898 int in_current_obstack;
1900 /* Get the desired `double' value as a sequence of ints
1901 since that is how they are stored in a CONST_DOUBLE. */
1903 u.d = d;
1905 /* Detect special cases. */
1907 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1908 if (!bcmp ((char *) &dconst0, (char *) &d, sizeof d))
1909 return CONST0_RTX (mode);
1910 /* Check for NaN first, because some ports (specifically the i386) do not
1911 emit correct ieee-fp code by default, and thus will generate a core
1912 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1913 does a floating point comparison. */
1914 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1915 return CONST1_RTX (mode);
1917 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1918 return immed_double_const (u.i[0], u.i[1], mode);
1920 /* The rest of this function handles the case where
1921 a float value requires more than 2 ints of space.
1922 It will be deleted as dead code on machines that don't need it. */
1924 /* Search the chain for an existing CONST_DOUBLE with the right value.
1925 If one is found, return it. */
1927 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1928 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
1929 && GET_MODE (r) == mode)
1930 return r;
1932 /* No; make a new one and add it to the chain.
1934 We may be called by an optimizer which may be discarding any memory
1935 allocated during its processing (such as combine and loop). However,
1936 we will be leaving this constant on the chain, so we cannot tolerate
1937 freed memory. So switch to saveable_obstack for this allocation
1938 and then switch back if we were in current_obstack. */
1940 push_obstacks_nochange ();
1941 rtl_in_saveable_obstack ();
1942 r = rtx_alloc (CONST_DOUBLE);
1943 PUT_MODE (r, mode);
1944 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
1945 pop_obstacks ();
1947 /* Don't touch const_double_chain in nested function; see force_const_mem.
1948 Also, don't touch it if not inside any function. */
1949 if (outer_function_chain == 0 && current_function_decl != 0)
1951 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1952 const_double_chain = r;
1955 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1956 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1957 is only through force_const_mem. */
1959 CONST_DOUBLE_MEM (r) = const0_rtx;
1961 return r;
1964 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1965 which must be a REAL_CST tree node. */
1968 immed_real_const (exp)
1969 tree exp;
1971 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1974 /* At the end of a function, forget the memory-constants
1975 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1976 Also clear out real_constant_chain and clear out all the chain-pointers. */
1978 void
1979 clear_const_double_mem ()
1981 register rtx r, next;
1983 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1984 See force_const_mem for explanation. */
1985 if (outer_function_chain != 0)
1986 return;
1988 for (r = const_double_chain; r; r = next)
1990 next = CONST_DOUBLE_CHAIN (r);
1991 CONST_DOUBLE_CHAIN (r) = 0;
1992 CONST_DOUBLE_MEM (r) = cc0_rtx;
1994 const_double_chain = 0;
1997 /* Given an expression EXP with a constant value,
1998 reduce it to the sum of an assembler symbol and an integer.
1999 Store them both in the structure *VALUE.
2000 Abort if EXP does not reduce. */
2002 struct addr_const
2004 rtx base;
2005 HOST_WIDE_INT offset;
2008 static void
2009 decode_addr_const (exp, value)
2010 tree exp;
2011 struct addr_const *value;
2013 register tree target = TREE_OPERAND (exp, 0);
2014 register int offset = 0;
2015 register rtx x;
2017 while (1)
2019 if (TREE_CODE (target) == COMPONENT_REF
2020 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2021 == INTEGER_CST))
2023 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2024 target = TREE_OPERAND (target, 0);
2026 else if (TREE_CODE (target) == ARRAY_REF)
2028 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2029 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2030 abort ();
2031 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2032 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2033 / BITS_PER_UNIT);
2034 target = TREE_OPERAND (target, 0);
2036 else
2037 break;
2040 switch (TREE_CODE (target))
2042 case VAR_DECL:
2043 case FUNCTION_DECL:
2044 x = DECL_RTL (target);
2045 break;
2047 case LABEL_DECL:
2048 if (output_bytecode)
2049 /* FIXME: this may not be correct, check it */
2050 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
2051 else
2052 x = gen_rtx (MEM, FUNCTION_MODE,
2053 gen_rtx (LABEL_REF, VOIDmode,
2054 label_rtx (TREE_OPERAND (exp, 0))));
2055 break;
2057 case REAL_CST:
2058 case STRING_CST:
2059 case COMPLEX_CST:
2060 case CONSTRUCTOR:
2061 x = TREE_CST_RTL (target);
2062 break;
2064 default:
2065 abort ();
2068 if (!output_bytecode)
2070 if (GET_CODE (x) != MEM)
2071 abort ();
2072 x = XEXP (x, 0);
2075 value->base = x;
2076 value->offset = offset;
2079 /* Uniquize all constants that appear in memory.
2080 Each constant in memory thus far output is recorded
2081 in `const_hash_table' with a `struct constant_descriptor'
2082 that contains a polish representation of the value of
2083 the constant.
2085 We cannot store the trees in the hash table
2086 because the trees may be temporary. */
2088 struct constant_descriptor
2090 struct constant_descriptor *next;
2091 char *label;
2092 char contents[1];
2095 #define HASHBITS 30
2096 #define MAX_HASH_TABLE 1009
2097 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2099 /* Compute a hash code for a constant expression. */
2102 const_hash (exp)
2103 tree exp;
2105 register char *p;
2106 register int len, hi, i;
2107 register enum tree_code code = TREE_CODE (exp);
2109 if (code == INTEGER_CST)
2111 p = (char *) &TREE_INT_CST_LOW (exp);
2112 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2114 else if (code == REAL_CST)
2116 p = (char *) &TREE_REAL_CST (exp);
2117 len = sizeof TREE_REAL_CST (exp);
2119 else if (code == STRING_CST)
2120 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2121 else if (code == COMPLEX_CST)
2122 return const_hash (TREE_REALPART (exp)) * 5
2123 + const_hash (TREE_IMAGPART (exp));
2124 else if (code == CONSTRUCTOR)
2126 register tree link;
2128 /* For record type, include the type in the hashing.
2129 We do not do so for array types
2130 because (1) the sizes of the elements are sufficient
2131 and (2) distinct array types can have the same constructor.
2132 Instead, we include the array size because the constructor could
2133 be shorter. */
2134 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2135 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2136 % MAX_HASH_TABLE;
2137 else
2138 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2139 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2141 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2142 if (TREE_VALUE (link))
2143 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2145 return hi;
2147 else if (code == ADDR_EXPR)
2149 struct addr_const value;
2150 decode_addr_const (exp, &value);
2151 if (GET_CODE (value.base) == SYMBOL_REF)
2153 /* Don't hash the address of the SYMBOL_REF;
2154 only use the offset and the symbol name. */
2155 hi = value.offset;
2156 p = XSTR (value.base, 0);
2157 for (i = 0; p[i] != 0; i++)
2158 hi = ((hi * 613) + (unsigned)(p[i]));
2160 else if (GET_CODE (value.base) == LABEL_REF)
2161 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2163 hi &= (1 << HASHBITS) - 1;
2164 hi %= MAX_HASH_TABLE;
2165 return hi;
2167 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2168 return const_hash (TREE_OPERAND (exp, 0)) * 9
2169 + const_hash (TREE_OPERAND (exp, 1));
2170 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2171 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2173 /* Compute hashing function */
2174 hi = len;
2175 for (i = 0; i < len; i++)
2176 hi = ((hi * 613) + (unsigned)(p[i]));
2178 hi &= (1 << HASHBITS) - 1;
2179 hi %= MAX_HASH_TABLE;
2180 return hi;
2183 /* Compare a constant expression EXP with a constant-descriptor DESC.
2184 Return 1 if DESC describes a constant with the same value as EXP. */
2186 static int
2187 compare_constant (exp, desc)
2188 tree exp;
2189 struct constant_descriptor *desc;
2191 return 0 != compare_constant_1 (exp, desc->contents);
2194 /* Compare constant expression EXP with a substring P of a constant descriptor.
2195 If they match, return a pointer to the end of the substring matched.
2196 If they do not match, return 0.
2198 Since descriptors are written in polish prefix notation,
2199 this function can be used recursively to test one operand of EXP
2200 against a subdescriptor, and if it succeeds it returns the
2201 address of the subdescriptor for the next operand. */
2203 static char *
2204 compare_constant_1 (exp, p)
2205 tree exp;
2206 char *p;
2208 register char *strp;
2209 register int len;
2210 register enum tree_code code = TREE_CODE (exp);
2212 if (code != (enum tree_code) *p++)
2213 return 0;
2215 if (code == INTEGER_CST)
2217 /* Integer constants are the same only if the same width of type. */
2218 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2219 return 0;
2220 strp = (char *) &TREE_INT_CST_LOW (exp);
2221 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2223 else if (code == REAL_CST)
2225 /* Real constants are the same only if the same width of type. */
2226 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2227 return 0;
2228 strp = (char *) &TREE_REAL_CST (exp);
2229 len = sizeof TREE_REAL_CST (exp);
2231 else if (code == STRING_CST)
2233 if (flag_writable_strings)
2234 return 0;
2235 strp = TREE_STRING_POINTER (exp);
2236 len = TREE_STRING_LENGTH (exp);
2237 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2238 sizeof TREE_STRING_LENGTH (exp)))
2239 return 0;
2240 p += sizeof TREE_STRING_LENGTH (exp);
2242 else if (code == COMPLEX_CST)
2244 p = compare_constant_1 (TREE_REALPART (exp), p);
2245 if (p == 0) return 0;
2246 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2247 return p;
2249 else if (code == CONSTRUCTOR)
2251 register tree link;
2252 int length = list_length (CONSTRUCTOR_ELTS (exp));
2253 tree type;
2255 if (bcmp ((char *) &length, p, sizeof length))
2256 return 0;
2257 p += sizeof length;
2259 /* For record constructors, insist that the types match.
2260 For arrays, just verify both constructors are for arrays. */
2261 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2262 type = TREE_TYPE (exp);
2263 else
2264 type = 0;
2265 if (bcmp ((char *) &type, p, sizeof type))
2266 return 0;
2267 p += sizeof type;
2269 /* For arrays, insist that the size in bytes match. */
2270 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2272 int size = int_size_in_bytes (TREE_TYPE (exp));
2273 if (bcmp ((char *) &size, p, sizeof size))
2274 return 0;
2275 p += sizeof size;
2278 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2280 if (TREE_VALUE (link))
2282 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2283 return 0;
2285 else
2287 tree zero = 0;
2289 if (bcmp ((char *) &zero, p, sizeof zero))
2290 return 0;
2291 p += sizeof zero;
2295 return p;
2297 else if (code == ADDR_EXPR)
2299 struct addr_const value;
2300 decode_addr_const (exp, &value);
2301 strp = (char *) &value.offset;
2302 len = sizeof value.offset;
2303 /* Compare the offset. */
2304 while (--len >= 0)
2305 if (*p++ != *strp++)
2306 return 0;
2307 /* Compare symbol name. */
2308 strp = XSTR (value.base, 0);
2309 len = strlen (strp) + 1;
2311 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2313 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2314 if (p == 0) return 0;
2315 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2316 return p;
2318 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2320 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2321 return p;
2324 /* Compare constant contents. */
2325 while (--len >= 0)
2326 if (*p++ != *strp++)
2327 return 0;
2329 return p;
2332 /* Construct a constant descriptor for the expression EXP.
2333 It is up to the caller to enter the descriptor in the hash table. */
2335 static struct constant_descriptor *
2336 record_constant (exp)
2337 tree exp;
2339 struct constant_descriptor *next = 0;
2340 char *label = 0;
2342 /* Make a struct constant_descriptor. The first two pointers will
2343 be filled in later. Here we just leave space for them. */
2345 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2346 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2347 record_constant_1 (exp);
2348 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2351 /* Add a description of constant expression EXP
2352 to the object growing in `permanent_obstack'.
2353 No need to return its address; the caller will get that
2354 from the obstack when the object is complete. */
2356 static void
2357 record_constant_1 (exp)
2358 tree exp;
2360 register char *strp;
2361 register int len;
2362 register enum tree_code code = TREE_CODE (exp);
2364 obstack_1grow (&permanent_obstack, (unsigned int) code);
2366 if (code == INTEGER_CST)
2368 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2369 strp = (char *) &TREE_INT_CST_LOW (exp);
2370 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2372 else if (code == REAL_CST)
2374 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2375 strp = (char *) &TREE_REAL_CST (exp);
2376 len = sizeof TREE_REAL_CST (exp);
2378 else if (code == STRING_CST)
2380 if (flag_writable_strings)
2381 return;
2382 strp = TREE_STRING_POINTER (exp);
2383 len = TREE_STRING_LENGTH (exp);
2384 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2385 sizeof TREE_STRING_LENGTH (exp));
2387 else if (code == COMPLEX_CST)
2389 record_constant_1 (TREE_REALPART (exp));
2390 record_constant_1 (TREE_IMAGPART (exp));
2391 return;
2393 else if (code == CONSTRUCTOR)
2395 register tree link;
2396 int length = list_length (CONSTRUCTOR_ELTS (exp));
2397 tree type;
2399 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2401 /* For record constructors, insist that the types match.
2402 For arrays, just verify both constructors are for arrays. */
2403 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2404 type = TREE_TYPE (exp);
2405 else
2406 type = 0;
2407 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2409 /* For arrays, insist that the size in bytes match. */
2410 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2412 int size = int_size_in_bytes (TREE_TYPE (exp));
2413 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2416 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2418 if (TREE_VALUE (link))
2419 record_constant_1 (TREE_VALUE (link));
2420 else
2422 tree zero = 0;
2424 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
2428 return;
2430 else if (code == ADDR_EXPR)
2432 struct addr_const value;
2433 decode_addr_const (exp, &value);
2434 /* Record the offset. */
2435 obstack_grow (&permanent_obstack,
2436 (char *) &value.offset, sizeof value.offset);
2437 /* Record the symbol name. */
2438 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2439 strlen (XSTR (value.base, 0)) + 1);
2440 return;
2442 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2444 record_constant_1 (TREE_OPERAND (exp, 0));
2445 record_constant_1 (TREE_OPERAND (exp, 1));
2446 return;
2448 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2450 record_constant_1 (TREE_OPERAND (exp, 0));
2451 return;
2454 /* Record constant contents. */
2455 obstack_grow (&permanent_obstack, strp, len);
2458 /* Record a list of constant expressions that were passed to
2459 output_constant_def but that could not be output right away. */
2461 struct deferred_constant
2463 struct deferred_constant *next;
2464 tree exp;
2465 int reloc;
2466 int labelno;
2469 static struct deferred_constant *deferred_constants;
2471 /* Nonzero means defer output of addressed subconstants
2472 (i.e., those for which output_constant_def is called.) */
2473 static int defer_addressed_constants_flag;
2475 /* Start deferring output of subconstants. */
2477 void
2478 defer_addressed_constants ()
2480 defer_addressed_constants_flag++;
2483 /* Stop deferring output of subconstants,
2484 and output now all those that have been deferred. */
2486 void
2487 output_deferred_addressed_constants ()
2489 struct deferred_constant *p, *next;
2491 defer_addressed_constants_flag--;
2493 if (defer_addressed_constants_flag > 0)
2494 return;
2496 for (p = deferred_constants; p; p = next)
2498 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2499 next = p->next;
2500 free (p);
2503 deferred_constants = 0;
2506 /* Make a copy of the whole tree structure for a constant.
2507 This handles the same types of nodes that compare_constant
2508 and record_constant handle. */
2510 static tree
2511 copy_constant (exp)
2512 tree exp;
2514 switch (TREE_CODE (exp))
2516 case INTEGER_CST:
2517 case REAL_CST:
2518 case STRING_CST:
2519 case ADDR_EXPR:
2520 /* For ADDR_EXPR, we do not want to copy the decl
2521 whose address is requested. */
2522 return copy_node (exp);
2524 case COMPLEX_CST:
2525 return build_complex (copy_constant (TREE_REALPART (exp)),
2526 copy_constant (TREE_IMAGPART (exp)));
2528 case PLUS_EXPR:
2529 case MINUS_EXPR:
2530 return build (TREE_CODE (exp), TREE_TYPE (exp),
2531 copy_constant (TREE_OPERAND (exp, 0)),
2532 copy_constant (TREE_OPERAND (exp, 1)));
2534 case NOP_EXPR:
2535 case CONVERT_EXPR:
2536 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2537 copy_constant (TREE_OPERAND (exp, 0)));
2539 case CONSTRUCTOR:
2541 tree copy = copy_node (exp);
2542 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2543 tree tail;
2545 CONSTRUCTOR_ELTS (copy) = list;
2546 for (tail = list; tail; tail = TREE_CHAIN (tail))
2547 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2549 return copy;
2552 default:
2553 abort ();
2557 /* Return an rtx representing a reference to constant data in memory
2558 for the constant expression EXP.
2560 If assembler code for such a constant has already been output,
2561 return an rtx to refer to it.
2562 Otherwise, output such a constant in memory (or defer it for later)
2563 and generate an rtx for it.
2565 The TREE_CST_RTL of EXP is set up to point to that rtx.
2566 The const_hash_table records which constants already have label strings. */
2569 output_constant_def (exp)
2570 tree exp;
2572 register int hash;
2573 register struct constant_descriptor *desc;
2574 char label[256];
2575 char *found = 0;
2576 int reloc;
2577 register rtx def;
2579 if (TREE_CODE (exp) == INTEGER_CST)
2580 abort (); /* No TREE_CST_RTL slot in these. */
2582 if (TREE_CST_RTL (exp))
2583 return TREE_CST_RTL (exp);
2585 /* Make sure any other constants whose addresses appear in EXP
2586 are assigned label numbers. */
2588 reloc = output_addressed_constants (exp);
2590 /* Compute hash code of EXP. Search the descriptors for that hash code
2591 to see if any of them describes EXP. If yes, the descriptor records
2592 the label number already assigned. */
2594 hash = const_hash (exp) % MAX_HASH_TABLE;
2596 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2597 if (compare_constant (exp, desc))
2599 found = desc->label;
2600 break;
2603 if (found == 0)
2605 /* No constant equal to EXP is known to have been output.
2606 Make a constant descriptor to enter EXP in the hash table.
2607 Assign the label number and record it in the descriptor for
2608 future calls to this function to find. */
2610 /* Create a string containing the label name, in LABEL. */
2611 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2613 desc = record_constant (exp);
2614 desc->next = const_hash_table[hash];
2615 desc->label
2616 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2617 const_hash_table[hash] = desc;
2619 else
2621 /* Create a string containing the label name, in LABEL. */
2622 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2625 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2627 push_obstacks_nochange ();
2628 if (TREE_PERMANENT (exp))
2629 end_temporary_allocation ();
2631 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2633 TREE_CST_RTL (exp)
2634 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2635 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2636 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2637 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2639 pop_obstacks ();
2641 /* Optionally set flags or add text to the name to record information
2642 such as that it is a function name. If the name is changed, the macro
2643 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2644 #ifdef ENCODE_SECTION_INFO
2645 ENCODE_SECTION_INFO (exp);
2646 #endif
2648 /* If this is the first time we've seen this particular constant,
2649 output it (or defer its output for later). */
2650 if (found == 0)
2652 if (defer_addressed_constants_flag)
2654 struct deferred_constant *p;
2655 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2657 push_obstacks_nochange ();
2658 suspend_momentary ();
2659 p->exp = copy_constant (exp);
2660 pop_obstacks ();
2661 p->reloc = reloc;
2662 p->labelno = const_labelno++;
2663 p->next = deferred_constants;
2664 deferred_constants = p;
2666 else
2667 output_constant_def_contents (exp, reloc, const_labelno++);
2670 return TREE_CST_RTL (exp);
2673 /* Now output assembler code to define the label for EXP,
2674 and follow it with the data of EXP. */
2676 static void
2677 output_constant_def_contents (exp, reloc, labelno)
2678 tree exp;
2679 int reloc;
2680 int labelno;
2682 int align;
2684 if (IN_NAMED_SECTION (exp))
2685 named_section (exp, NULL);
2686 else
2688 /* First switch to text section, except for writable strings. */
2689 #ifdef SELECT_SECTION
2690 SELECT_SECTION (exp, reloc);
2691 #else
2692 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2693 || (flag_pic && reloc))
2694 data_section ();
2695 else
2696 readonly_data_section ();
2697 #endif
2700 /* Align the location counter as required by EXP's data type. */
2701 align = TYPE_ALIGN (TREE_TYPE (exp));
2702 #ifdef CONSTANT_ALIGNMENT
2703 align = CONSTANT_ALIGNMENT (exp, align);
2704 #endif
2706 if (align > BITS_PER_UNIT)
2708 if (!output_bytecode)
2710 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2712 else
2714 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2718 /* Output the label itself. */
2719 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2721 /* Output the value of EXP. */
2722 output_constant (exp,
2723 (TREE_CODE (exp) == STRING_CST
2724 ? TREE_STRING_LENGTH (exp)
2725 : int_size_in_bytes (TREE_TYPE (exp))));
2729 /* Similar hash facility for making memory-constants
2730 from constant rtl-expressions. It is used on RISC machines
2731 where immediate integer arguments and constant addresses are restricted
2732 so that such constants must be stored in memory.
2734 This pool of constants is reinitialized for each function
2735 so each function gets its own constants-pool that comes right before it.
2737 All structures allocated here are discarded when functions are saved for
2738 inlining, so they do not need to be allocated permanently. */
2740 #define MAX_RTX_HASH_TABLE 61
2741 static struct constant_descriptor **const_rtx_hash_table;
2743 /* Structure to represent sufficient information about a constant so that
2744 it can be output when the constant pool is output, so that function
2745 integration can be done, and to simplify handling on machines that reference
2746 constant pool as base+displacement. */
2748 struct pool_constant
2750 struct constant_descriptor *desc;
2751 struct pool_constant *next;
2752 enum machine_mode mode;
2753 rtx constant;
2754 int labelno;
2755 int align;
2756 int offset;
2759 /* Pointers to first and last constant in pool. */
2761 static struct pool_constant *first_pool, *last_pool;
2763 /* Current offset in constant pool (does not include any machine-specific
2764 header. */
2766 static int pool_offset;
2768 /* Structure used to maintain hash table mapping symbols used to their
2769 corresponding constants. */
2771 struct pool_sym
2773 char *label;
2774 struct pool_constant *pool;
2775 struct pool_sym *next;
2778 static struct pool_sym **const_rtx_sym_hash_table;
2780 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2781 The argument is XSTR (... , 0) */
2783 #define SYMHASH(LABEL) \
2784 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2786 /* Initialize constant pool hashing for next function. */
2788 void
2789 init_const_rtx_hash_table ()
2791 const_rtx_hash_table
2792 = ((struct constant_descriptor **)
2793 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2794 const_rtx_sym_hash_table
2795 = ((struct pool_sym **)
2796 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2797 bzero ((char *) const_rtx_hash_table,
2798 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2799 bzero ((char *) const_rtx_sym_hash_table,
2800 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2802 first_pool = last_pool = 0;
2803 pool_offset = 0;
2806 /* Save and restore it for a nested function. */
2808 void
2809 save_varasm_status (p)
2810 struct function *p;
2812 p->const_rtx_hash_table = const_rtx_hash_table;
2813 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2814 p->first_pool = first_pool;
2815 p->last_pool = last_pool;
2816 p->pool_offset = pool_offset;
2819 void
2820 restore_varasm_status (p)
2821 struct function *p;
2823 const_rtx_hash_table = p->const_rtx_hash_table;
2824 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2825 first_pool = p->first_pool;
2826 last_pool = p->last_pool;
2827 pool_offset = p->pool_offset;
2830 enum kind { RTX_DOUBLE, RTX_INT };
2832 struct rtx_const
2834 #ifdef ONLY_INT_FIELDS
2835 unsigned int kind : 16;
2836 unsigned int mode : 16;
2837 #else
2838 enum kind kind : 16;
2839 enum machine_mode mode : 16;
2840 #endif
2841 union {
2842 union real_extract du;
2843 struct addr_const addr;
2844 } un;
2847 /* Express an rtx for a constant integer (perhaps symbolic)
2848 as the sum of a symbol or label plus an explicit integer.
2849 They are stored into VALUE. */
2851 static void
2852 decode_rtx_const (mode, x, value)
2853 enum machine_mode mode;
2854 rtx x;
2855 struct rtx_const *value;
2857 /* Clear the whole structure, including any gaps. */
2860 int *p = (int *) value;
2861 int *end = (int *) (value + 1);
2862 while (p < end)
2863 *p++ = 0;
2866 value->kind = RTX_INT; /* Most usual kind. */
2867 value->mode = mode;
2869 switch (GET_CODE (x))
2871 case CONST_DOUBLE:
2872 value->kind = RTX_DOUBLE;
2873 if (GET_MODE (x) != VOIDmode)
2874 value->mode = GET_MODE (x);
2875 bcopy ((char *) &CONST_DOUBLE_LOW (x),
2876 (char *) &value->un.du, sizeof value->un.du);
2877 break;
2879 case CONST_INT:
2880 value->un.addr.offset = INTVAL (x);
2881 break;
2883 case SYMBOL_REF:
2884 case LABEL_REF:
2885 case PC:
2886 value->un.addr.base = x;
2887 break;
2889 case CONST:
2890 x = XEXP (x, 0);
2891 if (GET_CODE (x) == PLUS)
2893 value->un.addr.base = XEXP (x, 0);
2894 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2895 abort ();
2896 value->un.addr.offset = INTVAL (XEXP (x, 1));
2898 else if (GET_CODE (x) == MINUS)
2900 value->un.addr.base = XEXP (x, 0);
2901 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2902 abort ();
2903 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2905 else
2906 abort ();
2907 break;
2909 default:
2910 abort ();
2913 if (value->kind == RTX_INT && value->un.addr.base != 0)
2914 switch (GET_CODE (value->un.addr.base))
2916 case SYMBOL_REF:
2917 case LABEL_REF:
2918 /* Use the string's address, not the SYMBOL_REF's address,
2919 for the sake of addresses of library routines.
2920 For a LABEL_REF, compare labels. */
2921 value->un.addr.base = XEXP (value->un.addr.base, 0);
2925 /* Given a MINUS expression, simplify it if both sides
2926 include the same symbol. */
2929 simplify_subtraction (x)
2930 rtx x;
2932 struct rtx_const val0, val1;
2934 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2935 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2937 if (val0.un.addr.base == val1.un.addr.base)
2938 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2939 return x;
2942 /* Compute a hash code for a constant RTL expression. */
2945 const_hash_rtx (mode, x)
2946 enum machine_mode mode;
2947 rtx x;
2949 register int hi, i;
2951 struct rtx_const value;
2952 decode_rtx_const (mode, x, &value);
2954 /* Compute hashing function */
2955 hi = 0;
2956 for (i = 0; i < sizeof value / sizeof (int); i++)
2957 hi += ((int *) &value)[i];
2959 hi &= (1 << HASHBITS) - 1;
2960 hi %= MAX_RTX_HASH_TABLE;
2961 return hi;
2964 /* Compare a constant rtl object X with a constant-descriptor DESC.
2965 Return 1 if DESC describes a constant with the same value as X. */
2967 static int
2968 compare_constant_rtx (mode, x, desc)
2969 enum machine_mode mode;
2970 rtx x;
2971 struct constant_descriptor *desc;
2973 register int *p = (int *) desc->contents;
2974 register int *strp;
2975 register int len;
2976 struct rtx_const value;
2978 decode_rtx_const (mode, x, &value);
2979 strp = (int *) &value;
2980 len = sizeof value / sizeof (int);
2982 /* Compare constant contents. */
2983 while (--len >= 0)
2984 if (*p++ != *strp++)
2985 return 0;
2987 return 1;
2990 /* Construct a constant descriptor for the rtl-expression X.
2991 It is up to the caller to enter the descriptor in the hash table. */
2993 static struct constant_descriptor *
2994 record_constant_rtx (mode, x)
2995 enum machine_mode mode;
2996 rtx x;
2998 struct constant_descriptor *ptr;
2999 char *label;
3000 struct rtx_const value;
3002 decode_rtx_const (mode, x, &value);
3004 /* Put these things in the saveable obstack so we can ensure it won't
3005 be freed if we are called from combine or some other phase that discards
3006 memory allocated from function_obstack (current_obstack). */
3007 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3008 obstack_grow (saveable_obstack, &label, sizeof label);
3010 /* Record constant contents. */
3011 obstack_grow (saveable_obstack, &value, sizeof value);
3013 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3016 /* Given a constant rtx X, make (or find) a memory constant for its value
3017 and return a MEM rtx to refer to it in memory. */
3020 force_const_mem (mode, x)
3021 enum machine_mode mode;
3022 rtx x;
3024 register int hash;
3025 register struct constant_descriptor *desc;
3026 char label[256];
3027 char *found = 0;
3028 rtx def;
3030 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3031 (this will always be true for floating CONST_DOUBLEs that have been
3032 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3033 use the previous copy. Otherwise, make a new one. Note that in
3034 the unlikely event that this same CONST_DOUBLE is used in two different
3035 modes in an alternating fashion, we will allocate a lot of different
3036 memory locations, but this should be extremely rare. */
3038 /* Don't use CONST_DOUBLE_MEM in a nested function.
3039 Nested functions have their own constant pools,
3040 so they can't share the same values in CONST_DOUBLE_MEM
3041 with the containing function. */
3042 if (outer_function_chain == 0)
3043 if (GET_CODE (x) == CONST_DOUBLE
3044 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3045 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3046 return CONST_DOUBLE_MEM (x);
3048 /* Compute hash code of X. Search the descriptors for that hash code
3049 to see if any of them describes X. If yes, the descriptor records
3050 the label number already assigned. */
3052 hash = const_hash_rtx (mode, x);
3054 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3055 if (compare_constant_rtx (mode, x, desc))
3057 found = desc->label;
3058 break;
3061 if (found == 0)
3063 register struct pool_constant *pool;
3064 register struct pool_sym *sym;
3065 int align;
3067 /* No constant equal to X is known to have been output.
3068 Make a constant descriptor to enter X in the hash table.
3069 Assign the label number and record it in the descriptor for
3070 future calls to this function to find. */
3072 desc = record_constant_rtx (mode, x);
3073 desc->next = const_rtx_hash_table[hash];
3074 const_rtx_hash_table[hash] = desc;
3076 /* Align the location counter as required by EXP's data type. */
3077 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3078 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3079 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3081 pool_offset += align - 1;
3082 pool_offset &= ~ (align - 1);
3084 /* If RTL is not being placed into the saveable obstack, make a
3085 copy of X that is in the saveable obstack in case we are being
3086 called from combine or some other phase that discards memory
3087 it allocates. We need only do this if it is a CONST, since
3088 no other RTX should be allocated in this situation. */
3089 if (rtl_obstack != saveable_obstack
3090 && GET_CODE (x) == CONST)
3092 push_obstacks_nochange ();
3093 rtl_in_saveable_obstack ();
3095 x = gen_rtx (CONST, GET_MODE (x),
3096 gen_rtx (PLUS, GET_MODE (x),
3097 XEXP (XEXP (x, 0), 0), XEXP (XEXP (x, 0), 1)));
3098 pop_obstacks ();
3101 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3103 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3104 pool->desc = desc;
3105 pool->constant = x;
3106 pool->mode = mode;
3107 pool->labelno = const_labelno;
3108 pool->align = align;
3109 pool->offset = pool_offset;
3110 pool->next = 0;
3112 if (last_pool == 0)
3113 first_pool = pool;
3114 else
3115 last_pool->next = pool;
3117 last_pool = pool;
3118 pool_offset += GET_MODE_SIZE (mode);
3120 /* Create a string containing the label name, in LABEL. */
3121 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3123 ++const_labelno;
3125 desc->label = found
3126 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3128 /* Add label to symbol hash table. */
3129 hash = SYMHASH (found);
3130 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3131 sym->label = found;
3132 sym->pool = pool;
3133 sym->next = const_rtx_sym_hash_table[hash];
3134 const_rtx_sym_hash_table[hash] = sym;
3137 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3139 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3141 RTX_UNCHANGING_P (def) = 1;
3142 /* Mark the symbol_ref as belonging to this constants pool. */
3143 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3144 current_function_uses_const_pool = 1;
3146 if (outer_function_chain == 0)
3147 if (GET_CODE (x) == CONST_DOUBLE)
3149 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3151 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3152 const_double_chain = x;
3154 CONST_DOUBLE_MEM (x) = def;
3157 return def;
3160 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3161 the corresponding pool_constant structure. */
3163 static struct pool_constant *
3164 find_pool_constant (addr)
3165 rtx addr;
3167 struct pool_sym *sym;
3168 char *label = XSTR (addr, 0);
3170 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3171 if (sym->label == label)
3172 return sym->pool;
3174 abort ();
3177 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3180 get_pool_constant (addr)
3181 rtx addr;
3183 return (find_pool_constant (addr))->constant;
3186 /* Similar, return the mode. */
3188 enum machine_mode
3189 get_pool_mode (addr)
3190 rtx addr;
3192 return (find_pool_constant (addr))->mode;
3195 /* Similar, return the offset in the constant pool. */
3198 get_pool_offset (addr)
3199 rtx addr;
3201 return (find_pool_constant (addr))->offset;
3204 /* Return the size of the constant pool. */
3207 get_pool_size ()
3209 return pool_offset;
3212 /* Write all the constants in the constant pool. */
3214 void
3215 output_constant_pool (fnname, fndecl)
3216 char *fnname;
3217 tree fndecl;
3219 struct pool_constant *pool;
3220 rtx x;
3221 union real_extract u;
3223 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3224 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3225 #endif
3227 for (pool = first_pool; pool; pool = pool->next)
3229 x = pool->constant;
3231 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3232 whose CODE_LABEL has been deleted. This can occur if a jump table
3233 is eliminated by optimization. If so, write a constant of zero
3234 instead. Note that this can also happen by turning the
3235 CODE_LABEL into a NOTE. */
3236 if (((GET_CODE (x) == LABEL_REF
3237 && (INSN_DELETED_P (XEXP (x, 0))
3238 || GET_CODE (XEXP (x, 0)) == NOTE)))
3239 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3240 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3241 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3242 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3243 x = const0_rtx;
3245 /* First switch to correct section. */
3246 #ifdef SELECT_RTX_SECTION
3247 SELECT_RTX_SECTION (pool->mode, x);
3248 #else
3249 readonly_data_section ();
3250 #endif
3252 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3253 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3254 pool->align, pool->labelno, done);
3255 #endif
3257 if (pool->align > 1)
3258 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3260 /* Output the label. */
3261 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3263 /* Output the value of the constant itself. */
3264 switch (GET_MODE_CLASS (pool->mode))
3266 case MODE_FLOAT:
3267 if (GET_CODE (x) != CONST_DOUBLE)
3268 abort ();
3270 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3271 assemble_real (u.d, pool->mode);
3272 break;
3274 case MODE_INT:
3275 case MODE_PARTIAL_INT:
3276 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3277 break;
3279 default:
3280 abort ();
3283 done: ;
3286 /* Done with this pool. */
3287 first_pool = last_pool = 0;
3290 /* Find all the constants whose addresses are referenced inside of EXP,
3291 and make sure assembler code with a label has been output for each one.
3292 Indicate whether an ADDR_EXPR has been encountered. */
3295 output_addressed_constants (exp)
3296 tree exp;
3298 int reloc = 0;
3300 switch (TREE_CODE (exp))
3302 case ADDR_EXPR:
3304 register tree constant = TREE_OPERAND (exp, 0);
3306 while (TREE_CODE (constant) == COMPONENT_REF)
3308 constant = TREE_OPERAND (constant, 0);
3311 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3312 || TREE_CODE (constant) == CONSTRUCTOR)
3313 /* No need to do anything here
3314 for addresses of variables or functions. */
3315 output_constant_def (constant);
3317 reloc = 1;
3318 break;
3320 case PLUS_EXPR:
3321 case MINUS_EXPR:
3322 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3323 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3324 break;
3326 case NOP_EXPR:
3327 case CONVERT_EXPR:
3328 case NON_LVALUE_EXPR:
3329 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3330 break;
3332 case CONSTRUCTOR:
3334 register tree link;
3335 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3336 if (TREE_VALUE (link) != 0)
3337 reloc |= output_addressed_constants (TREE_VALUE (link));
3339 break;
3341 case ERROR_MARK:
3342 break;
3344 return reloc;
3348 /* Output assembler for byte constant */
3349 void
3350 output_byte_asm (byte)
3351 int byte;
3353 if (output_bytecode)
3354 bc_emit_const ((char *) &byte, sizeof (char));
3355 #ifdef ASM_OUTPUT_BYTE
3356 else
3358 ASM_OUTPUT_BYTE (asm_out_file, byte);
3360 #endif
3363 /* Output assembler code for constant EXP to FILE, with no label.
3364 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3365 Assumes output_addressed_constants has been done on EXP already.
3367 Generate exactly SIZE bytes of assembler data, padding at the end
3368 with zeros if necessary. SIZE must always be specified.
3370 SIZE is important for structure constructors,
3371 since trailing members may have been omitted from the constructor.
3372 It is also important for initialization of arrays from string constants
3373 since the full length of the string constant might not be wanted.
3374 It is also needed for initialization of unions, where the initializer's
3375 type is just one member, and that may not be as long as the union.
3377 There a case in which we would fail to output exactly SIZE bytes:
3378 for a structure constructor that wants to produce more than SIZE bytes.
3379 But such constructors will never be generated for any possible input. */
3381 void
3382 output_constant (exp, size)
3383 register tree exp;
3384 register int size;
3386 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3387 rtx x;
3389 if (size == 0)
3390 return;
3392 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3393 That way we get the constant (we hope) inside it. Also, strip off any
3394 NOP_EXPR that converts between two record, union, or array types. */
3395 while ((TREE_CODE (exp) == NOP_EXPR
3396 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3397 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3398 || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3399 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
3400 || TREE_CODE (TREE_TYPE (exp)) == QUAL_UNION_TYPE))
3401 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3402 exp = TREE_OPERAND (exp, 0);
3404 /* Allow a constructor with no elements for any data type.
3405 This means to fill the space with zeros. */
3406 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3408 if (output_bytecode)
3409 bc_emit_const_skip (size);
3410 else
3411 assemble_zeros (size);
3412 return;
3415 switch (code)
3417 case CHAR_TYPE:
3418 case BOOLEAN_TYPE:
3419 case INTEGER_TYPE:
3420 case ENUMERAL_TYPE:
3421 case POINTER_TYPE:
3422 case REFERENCE_TYPE:
3423 /* ??? What about (int)((float)(int)&foo + 4) */
3424 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3425 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3426 exp = TREE_OPERAND (exp, 0);
3428 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3429 EXPAND_INITIALIZER),
3430 size, 0))
3431 error ("initializer for integer value is too complicated");
3432 size = 0;
3433 break;
3435 case REAL_TYPE:
3436 if (TREE_CODE (exp) != REAL_CST)
3437 error ("initializer for floating value is not a floating constant");
3439 assemble_real (TREE_REAL_CST (exp),
3440 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3441 size = 0;
3442 break;
3444 case COMPLEX_TYPE:
3445 output_constant (TREE_REALPART (exp), size / 2);
3446 output_constant (TREE_IMAGPART (exp), size / 2);
3447 size -= (size / 2) * 2;
3448 break;
3450 case ARRAY_TYPE:
3451 if (TREE_CODE (exp) == CONSTRUCTOR)
3453 output_constructor (exp, size);
3454 return;
3456 else if (TREE_CODE (exp) == STRING_CST)
3458 int excess = 0;
3460 if (size > TREE_STRING_LENGTH (exp))
3462 excess = size - TREE_STRING_LENGTH (exp);
3463 size = TREE_STRING_LENGTH (exp);
3466 assemble_string (TREE_STRING_POINTER (exp), size);
3467 size = excess;
3469 else
3470 abort ();
3471 break;
3473 case RECORD_TYPE:
3474 case UNION_TYPE:
3475 if (TREE_CODE (exp) == CONSTRUCTOR)
3476 output_constructor (exp, size);
3477 else
3478 abort ();
3479 return;
3482 if (size > 0)
3483 assemble_zeros (size);
3487 /* Bytecode specific code to output assembler for integer. */
3488 static void
3489 bc_assemble_integer (exp, size)
3490 tree exp;
3491 int size;
3493 tree const_part;
3494 tree addr_part;
3495 tree tmp;
3497 /* FIXME: is this fold() business going to be as good as the
3498 expand_expr() using EXPAND_SUM above in the RTL case? I
3499 hate RMS.
3500 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3502 exp = fold (exp);
3504 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3505 exp = TREE_OPERAND (exp, 0);
3506 if (TREE_CODE (exp) == INTEGER_CST)
3508 const_part = exp;
3509 addr_part = 0;
3511 else if (TREE_CODE (exp) == PLUS_EXPR)
3513 const_part = TREE_OPERAND (exp, 0);
3514 while (TREE_CODE (const_part) == NOP_EXPR
3515 || TREE_CODE (const_part) == CONVERT_EXPR)
3516 const_part = TREE_OPERAND (const_part, 0);
3517 addr_part = TREE_OPERAND (exp, 1);
3518 while (TREE_CODE (addr_part) == NOP_EXPR
3519 || TREE_CODE (addr_part) == CONVERT_EXPR)
3520 addr_part = TREE_OPERAND (addr_part, 0);
3521 if (TREE_CODE (const_part) != INTEGER_CST)
3522 tmp = const_part, const_part = addr_part, addr_part = tmp;
3523 if (TREE_CODE (const_part) != INTEGER_CST
3524 || TREE_CODE (addr_part) != ADDR_EXPR)
3525 abort (); /* FIXME: we really haven't considered
3526 all the possible cases here. */
3528 else if (TREE_CODE (exp) == ADDR_EXPR)
3530 const_part = integer_zero_node;
3531 addr_part = exp;
3533 else
3534 abort (); /* FIXME: ditto previous. */
3536 if (addr_part == 0)
3538 if (size == 1)
3540 char c = TREE_INT_CST_LOW (const_part);
3541 bc_emit (&c, 1);
3542 size -= 1;
3544 else if (size == 2)
3546 short s = TREE_INT_CST_LOW (const_part);
3547 bc_emit ((char *) &s, 2);
3548 size -= 2;
3550 else if (size == 4)
3552 int i = TREE_INT_CST_LOW (const_part);
3553 bc_emit ((char *) &i, 4);
3554 size -= 4;
3556 else if (size == 8)
3558 if (WORDS_BIG_ENDIAN)
3560 int i = TREE_INT_CST_HIGH (const_part);
3561 bc_emit ((char *) &i, 4);
3562 i = TREE_INT_CST_LOW (const_part);
3563 bc_emit ((char *) &i, 4);
3565 else
3567 int i = TREE_INT_CST_LOW (const_part);
3568 bc_emit ((char *) &i, 4);
3569 i = TREE_INT_CST_HIGH (const_part);
3570 bc_emit ((char *) &i, 4);
3572 size -= 8;
3575 else
3576 if (size == 4
3577 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3578 bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3579 TREE_INT_CST_LOW (const_part));
3580 else
3581 abort (); /* FIXME: there may be more cases. */
3584 /* Subroutine of output_constant, used for CONSTRUCTORs
3585 (aggregate constants).
3586 Generate at least SIZE bytes, padding if necessary. */
3588 void
3589 output_constructor (exp, size)
3590 tree exp;
3591 int size;
3593 register tree link, field = 0;
3594 HOST_WIDE_INT min_index = 0;
3595 /* Number of bytes output or skipped so far.
3596 In other words, current position within the constructor. */
3597 int total_bytes = 0;
3598 /* Non-zero means BYTE contains part of a byte, to be output. */
3599 int byte_buffer_in_use = 0;
3600 register int byte;
3602 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3603 abort ();
3605 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3606 field = TYPE_FIELDS (TREE_TYPE (exp));
3608 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3609 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3610 min_index
3611 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3613 /* As LINK goes through the elements of the constant,
3614 FIELD goes through the structure fields, if the constant is a structure.
3615 if the constant is a union, then we override this,
3616 by getting the field from the TREE_LIST element.
3617 But the constant could also be an array. Then FIELD is zero. */
3618 for (link = CONSTRUCTOR_ELTS (exp);
3619 link;
3620 link = TREE_CHAIN (link),
3621 field = field ? TREE_CHAIN (field) : 0)
3623 tree val = TREE_VALUE (link);
3624 tree index = 0;
3626 /* the element in a union constructor specifies the proper field. */
3628 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3629 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3631 /* if available, use the type given by link */
3632 if (TREE_PURPOSE (link) != 0)
3633 field = TREE_PURPOSE (link);
3636 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3637 index = TREE_PURPOSE (link);
3639 /* Eliminate the marker that makes a cast not be an lvalue. */
3640 if (val != 0)
3641 STRIP_NOPS (val);
3643 if (field == 0 || !DECL_BIT_FIELD (field))
3645 /* An element that is not a bit-field. */
3647 register int fieldsize;
3648 /* Since this structure is static,
3649 we know the positions are constant. */
3650 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3651 / BITS_PER_UNIT)
3652 : 0);
3653 if (index != 0)
3654 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3655 / BITS_PER_UNIT
3656 * (TREE_INT_CST_LOW (index) - min_index));
3658 /* Output any buffered-up bit-fields preceding this element. */
3659 if (byte_buffer_in_use)
3661 ASM_OUTPUT_BYTE (asm_out_file, byte);
3662 total_bytes++;
3663 byte_buffer_in_use = 0;
3666 /* Advance to offset of this element.
3667 Note no alignment needed in an array, since that is guaranteed
3668 if each element has the proper size. */
3669 if ((field != 0 || index != 0) && bitpos != total_bytes)
3671 if (!output_bytecode)
3672 assemble_zeros (bitpos - total_bytes);
3673 else
3674 bc_emit_const_skip (bitpos - total_bytes);
3675 total_bytes = bitpos;
3678 /* Determine size this element should occupy. */
3679 if (field)
3681 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3682 abort ();
3683 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3685 /* This avoids overflow trouble. */
3686 tree size_tree = size_binop (CEIL_DIV_EXPR,
3687 DECL_SIZE (field),
3688 size_int (BITS_PER_UNIT));
3689 fieldsize = TREE_INT_CST_LOW (size_tree);
3691 else
3693 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3694 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3697 else
3698 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3700 /* Output the element's initial value. */
3701 if (val == 0)
3702 assemble_zeros (fieldsize);
3703 else
3704 output_constant (val, fieldsize);
3706 /* Count its size. */
3707 total_bytes += fieldsize;
3709 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3710 error ("invalid initial value for member `%s'",
3711 IDENTIFIER_POINTER (DECL_NAME (field)));
3712 else
3714 /* Element that is a bit-field. */
3716 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3717 int end_offset
3718 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3720 if (val == 0)
3721 val = integer_zero_node;
3723 /* If this field does not start in this (or, next) byte,
3724 skip some bytes. */
3725 if (next_offset / BITS_PER_UNIT != total_bytes)
3727 /* Output remnant of any bit field in previous bytes. */
3728 if (byte_buffer_in_use)
3730 ASM_OUTPUT_BYTE (asm_out_file, byte);
3731 total_bytes++;
3732 byte_buffer_in_use = 0;
3735 /* If still not at proper byte, advance to there. */
3736 if (next_offset / BITS_PER_UNIT != total_bytes)
3738 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3739 total_bytes = next_offset / BITS_PER_UNIT;
3743 if (! byte_buffer_in_use)
3744 byte = 0;
3746 /* We must split the element into pieces that fall within
3747 separate bytes, and combine each byte with previous or
3748 following bit-fields. */
3750 /* next_offset is the offset n fbits from the beginning of
3751 the structure to the next bit of this element to be processed.
3752 end_offset is the offset of the first bit past the end of
3753 this element. */
3754 while (next_offset < end_offset)
3756 int this_time;
3757 int shift, value;
3758 int next_byte = next_offset / BITS_PER_UNIT;
3759 int next_bit = next_offset % BITS_PER_UNIT;
3761 /* Advance from byte to byte
3762 within this element when necessary. */
3763 while (next_byte != total_bytes)
3765 ASM_OUTPUT_BYTE (asm_out_file, byte);
3766 total_bytes++;
3767 byte = 0;
3770 /* Number of bits we can process at once
3771 (all part of the same byte). */
3772 this_time = MIN (end_offset - next_offset,
3773 BITS_PER_UNIT - next_bit);
3774 if (BYTES_BIG_ENDIAN)
3776 /* On big-endian machine, take the most significant bits
3777 first (of the bits that are significant)
3778 and put them into bytes from the most significant end. */
3779 shift = end_offset - next_offset - this_time;
3780 /* Don't try to take a bunch of bits that cross
3781 the word boundary in the INTEGER_CST. */
3782 if (shift < HOST_BITS_PER_WIDE_INT
3783 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3785 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3786 shift = HOST_BITS_PER_WIDE_INT;
3789 /* Now get the bits from the appropriate constant word. */
3790 if (shift < HOST_BITS_PER_WIDE_INT)
3792 value = TREE_INT_CST_LOW (val);
3794 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3796 value = TREE_INT_CST_HIGH (val);
3797 shift -= HOST_BITS_PER_WIDE_INT;
3799 else
3800 abort ();
3801 byte |= (((value >> shift)
3802 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3803 << (BITS_PER_UNIT - this_time - next_bit));
3805 else
3807 /* On little-endian machines,
3808 take first the least significant bits of the value
3809 and pack them starting at the least significant
3810 bits of the bytes. */
3811 shift = (next_offset
3812 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3813 /* Don't try to take a bunch of bits that cross
3814 the word boundary in the INTEGER_CST. */
3815 if (shift < HOST_BITS_PER_WIDE_INT
3816 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3818 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3819 shift = HOST_BITS_PER_WIDE_INT;
3822 /* Now get the bits from the appropriate constant word. */
3823 if (shift < HOST_BITS_PER_INT)
3824 value = TREE_INT_CST_LOW (val);
3825 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3827 value = TREE_INT_CST_HIGH (val);
3828 shift -= HOST_BITS_PER_WIDE_INT;
3830 else
3831 abort ();
3832 byte |= (((value >> shift)
3833 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3834 << next_bit);
3836 next_offset += this_time;
3837 byte_buffer_in_use = 1;
3841 if (byte_buffer_in_use)
3843 ASM_OUTPUT_BYTE (asm_out_file, byte);
3844 total_bytes++;
3846 if (total_bytes < size)
3847 assemble_zeros (size - total_bytes);
3851 #ifdef HANDLE_SYSV_PRAGMA
3853 /* Support #pragma weak by default if WEAK_ASM_OP and ASM_OUTPUT_DEF
3854 are defined. */
3855 #if defined (WEAK_ASM_OP) && defined (ASM_OUTPUT_DEF)
3857 /* See c-pragma.c for an identical definition. */
3858 enum pragma_state
3860 ps_start,
3861 ps_done,
3862 ps_bad,
3863 ps_weak,
3864 ps_name,
3865 ps_equals,
3866 ps_value,
3867 ps_pack,
3868 ps_left,
3869 ps_align,
3870 ps_right
3873 /* Output asm to handle ``#pragma weak'' */
3874 void
3875 handle_pragma_weak (what, asm_out_file, name, value)
3876 enum pragma_state what;
3877 FILE *asm_out_file;
3878 char *name, *value;
3880 if (what == ps_name || what == ps_value)
3882 fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
3884 if (output_bytecode)
3885 BC_OUTPUT_LABELREF (asm_out_file, name);
3886 else
3887 ASM_OUTPUT_LABELREF (asm_out_file, name);
3889 fputc ('\n', asm_out_file);
3890 if (what == ps_value)
3891 ASM_OUTPUT_DEF (asm_out_file, name, value);
3893 else if (! (what == ps_done || what == ps_start))
3894 warning ("malformed `#pragma weak'");
3897 #endif /* HANDLE_PRAGMA_WEAK or (WEAK_ASM_OP and SET_ASM_OP) */
3899 #endif /* WEAK_ASM_OP && ASM_OUTPUT_DEF */