Pass -mno-regnames to assembler.
[official-gcc.git] / gcc / varasm.c
blob5702646ee84969b1d1cc9c3f314f694bb08b53ec
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92-5, 1996 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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file handles generation of all the assembler code
23 *except* the instructions of a function.
24 This includes declarations of variables and their initial values.
26 We also output the assembler code for constants stored in memory
27 and are responsible for combining constants with the same value. */
29 #include <stdio.h>
30 #include <setjmp.h>
31 /* #include <stab.h> */
32 #include "config.h"
33 #include "rtl.h"
34 #include "tree.h"
35 #include "flags.h"
36 #include "function.h"
37 #include "expr.h"
38 #include "output.h"
39 #include "hard-reg-set.h"
40 #include "regs.h"
41 #include "defaults.h"
42 #include "real.h"
43 #include "bytecode.h"
45 #include "obstack.h"
46 #include "c-pragma.h"
48 #ifdef XCOFF_DEBUGGING_INFO
49 #include "xcoffout.h"
50 #endif
52 #include <ctype.h>
54 #ifndef ASM_STABS_OP
55 #define ASM_STABS_OP ".stabs"
56 #endif
58 /* This macro gets just the user-specified name
59 out of the string in a SYMBOL_REF. On most machines,
60 we discard the * if any and that's all. */
61 #ifndef STRIP_NAME_ENCODING
62 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
63 (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
64 #endif
66 /* File in which assembler code is being written. */
68 extern FILE *asm_out_file;
70 /* The (assembler) name of the first globally-visible object output. */
71 char *first_global_object_name;
73 extern struct obstack *current_obstack;
74 extern struct obstack *saveable_obstack;
75 extern struct obstack *rtl_obstack;
76 extern struct obstack permanent_obstack;
77 #define obstack_chunk_alloc xmalloc
79 /* Number for making the label on the next
80 constant that is stored in memory. */
82 int const_labelno;
84 /* Number for making the label on the next
85 static variable internal to a function. */
87 int var_labelno;
89 /* Carry information from ASM_DECLARE_OBJECT_NAME
90 to ASM_FINISH_DECLARE_OBJECT. */
92 int size_directive_output;
94 /* The last decl for which assemble_variable was called,
95 if it did ASM_DECLARE_OBJECT_NAME.
96 If the last call to assemble_variable didn't do that,
97 this holds 0. */
99 tree last_assemble_variable_decl;
102 #ifdef HANDLE_PRAGMA_WEAK
103 /* Any weak symbol declarations waiting to be emitted. */
105 struct weak_syms
107 struct weak_syms *next;
108 char *name;
109 char *value;
112 static struct weak_syms *weak_decls;
113 #endif
115 /* Nonzero if at least one function definition has been seen. */
117 static int function_defined;
119 struct addr_const;
120 struct constant_descriptor;
121 struct rtx_const;
122 struct pool_constant;
124 static void bc_make_decl_rtl PROTO((tree, char *, int));
125 static char *strip_reg_name PROTO((char *));
126 static void bc_output_ascii PROTO((FILE *, char *, int));
127 static int contains_pointers_p PROTO((tree));
128 static void decode_addr_const PROTO((tree, struct addr_const *));
129 static int const_hash PROTO((tree));
130 static int compare_constant PROTO((tree,
131 struct constant_descriptor *));
132 static char *compare_constant_1 PROTO((tree, char *));
133 static struct constant_descriptor *record_constant PROTO((tree));
134 static void record_constant_1 PROTO((tree));
135 static tree copy_constant PROTO((tree));
136 static void output_constant_def_contents PROTO((tree, int, int));
137 static void decode_rtx_const PROTO((enum machine_mode, rtx,
138 struct rtx_const *));
139 static int const_hash_rtx PROTO((enum machine_mode, rtx));
140 static int compare_constant_rtx PROTO((enum machine_mode, rtx,
141 struct constant_descriptor *));
142 static struct constant_descriptor *record_constant_rtx PROTO((enum machine_mode,
143 rtx));
144 static struct pool_constant *find_pool_constant PROTO((rtx));
145 static int output_addressed_constants PROTO((tree));
146 static void bc_assemble_integer PROTO((tree, int));
147 static void output_constructor PROTO((tree, int));
149 static enum in_section { no_section, in_text, in_data, in_named
150 #ifdef BSS_SECTION_ASM_OP
151 , in_bss
152 #endif
153 #ifdef EXTRA_SECTIONS
154 , EXTRA_SECTIONS
155 #endif
156 } in_section = no_section;
158 /* Return a non-zero value if DECL has a section attribute. */
159 #define IN_NAMED_SECTION(DECL) \
160 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
161 && DECL_SECTION_NAME (DECL) != NULL_TREE)
163 /* Text of section name when in_section == in_named. */
164 static char *in_named_name;
166 /* Define functions like text_section for any extra sections. */
167 #ifdef EXTRA_SECTION_FUNCTIONS
168 EXTRA_SECTION_FUNCTIONS
169 #endif
171 /* Tell assembler to switch to text section. */
173 void
174 text_section ()
176 if (in_section != in_text)
178 if (output_bytecode)
179 bc_text ();
180 else
181 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
183 in_section = in_text;
187 /* Tell assembler to switch to data section. */
189 void
190 data_section ()
192 if (in_section != in_data)
194 if (output_bytecode)
195 bc_data ();
196 else
198 if (flag_shared_data)
200 #ifdef SHARED_SECTION_ASM_OP
201 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
202 #else
203 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
204 #endif
206 else
207 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
210 in_section = in_data;
214 /* Tell assembler to switch to read-only data section. This is normally
215 the text section. */
217 void
218 readonly_data_section ()
220 #ifdef READONLY_DATA_SECTION
221 READONLY_DATA_SECTION (); /* Note this can call data_section. */
222 #else
223 text_section ();
224 #endif
227 /* Determine if we're in the text section. */
230 in_text_section ()
232 return in_section == in_text;
235 /* Determine if we're in the data section. */
238 in_data_section ()
240 return in_section == in_data;
243 /* Tell assembler to change to section NAME for DECL.
244 If DECL is NULL, just switch to section NAME.
245 If NAME is NULL, get the name from DECL. */
247 void
248 named_section (decl, name)
249 tree decl;
250 char *name;
252 if (decl != NULL_TREE
253 && TREE_CODE_CLASS (TREE_CODE (decl)) != 'd')
254 abort ();
255 if (name == NULL)
256 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
258 if (in_section != in_named || strcmp (name, in_named_name))
260 in_named_name = obstack_alloc (&permanent_obstack, strlen (name) + 1);
261 strcpy (in_named_name, name);
262 in_section = in_named;
264 #ifdef ASM_OUTPUT_SECTION_NAME
265 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name);
266 #else
267 /* Section attributes are not supported if this macro isn't provided -
268 some host formats don't support them at all. The front-end should
269 already have flagged this as an error. */
270 abort ();
271 #endif
275 #ifdef BSS_SECTION_ASM_OP
277 /* Tell the assembler to switch to the bss section. */
279 void
280 bss_section (decl, name)
282 if (in_section != in_bss)
284 if (output_bytecode)
285 bc_data ();
286 else
288 #ifdef SHARED_BSS_SECTION_ASM_OP
289 if (flag_shared_data)
290 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
291 else
292 #endif
293 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
296 in_section = in_bss;
300 #ifdef ASM_OUTPUT_BSS
302 /* Utility function for ASM_OUTPUT_BSS for targets to use if
303 they don't support alignments in .bss.
304 ??? It is believed that this function will work in most cases so such
305 support is localized here. */
307 static void
308 asm_output_bss (file, decl, name, size, rounded)
309 FILE *file;
310 tree decl;
311 char *name;
312 int size, rounded;
314 ASM_GLOBALIZE_LABEL (file, name);
315 bss_section ();
316 #ifdef ASM_DECLARE_OBJECT_NAME
317 last_assemble_variable_decl = decl;
318 ASM_DECLARE_OBJECT_NAME (file, name, decl);
319 #else
320 /* Standard thing is just output label for the object. */
321 ASM_OUTPUT_LABEL (file, name);
322 #endif /* ASM_DECLARE_OBJECT_NAME */
323 ASM_OUTPUT_SKIP (file, rounded);
326 #endif
328 #ifdef ASM_OUTPUT_ALIGNED_BSS
330 /* Utility function for targets to use in implementing
331 ASM_OUTPUT_ALIGNED_BSS.
332 ??? It is believed that this function will work in most cases so such
333 support is localized here. */
335 static void
336 asm_output_aligned_bss (file, decl, name, size, align)
337 FILE *file;
338 tree decl;
339 char *name;
340 int size, align;
342 ASM_GLOBALIZE_LABEL (file, name);
343 bss_section ();
344 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
345 #ifdef ASM_DECLARE_OBJECT_NAME
346 last_assemble_variable_decl = decl;
347 ASM_DECLARE_OBJECT_NAME (file, name, decl);
348 #else
349 /* Standard thing is just output label for the object. */
350 ASM_OUTPUT_LABEL (file, name);
351 #endif /* ASM_DECLARE_OBJECT_NAME */
352 ASM_OUTPUT_SKIP (file, size);
355 #endif
357 #endif /* BSS_SECTION_ASM_OP */
359 /* Switch to the section for function DECL.
361 If DECL is NULL_TREE, switch to the text section.
362 ??? It's not clear that we will ever be passed NULL_TREE, but it's
363 safer to handle it. */
365 void
366 function_section (decl)
367 tree decl;
369 if (decl != NULL_TREE
370 && DECL_SECTION_NAME (decl) != NULL_TREE)
371 named_section (decl, (char *) 0);
372 else
373 text_section ();
376 /* Switch to section for variable DECL.
378 RELOC is the `reloc' argument to SELECT_SECTION. */
380 void
381 variable_section (decl, reloc)
382 tree decl;
383 int reloc;
385 if (IN_NAMED_SECTION (decl))
386 named_section (decl, NULL);
387 else
389 /* C++ can have const variables that get initialized from constructors,
390 and thus can not be in a readonly section. We prevent this by
391 verifying that the initial value is constant for objects put in a
392 readonly section.
394 error_mark_node is used by the C front end to indicate that the
395 initializer has not been seen yet. In this case, we assume that
396 the initializer must be constant.
398 C++ uses error_mark_node for variables that have complicated
399 initializers, but these variables go in BSS so we won't be called
400 for them. */
402 #ifdef SELECT_SECTION
403 SELECT_SECTION (decl, reloc);
404 #else
405 if (TREE_READONLY (decl)
406 && ! TREE_THIS_VOLATILE (decl)
407 && DECL_INITIAL (decl)
408 && (DECL_INITIAL (decl) == error_mark_node
409 || TREE_CONSTANT (DECL_INITIAL (decl)))
410 && ! (flag_pic && reloc))
411 readonly_data_section ();
412 else
413 data_section ();
414 #endif
418 /* Create the rtl to represent a function, for a function definition.
419 DECL is a FUNCTION_DECL node which describes which function.
420 The rtl is stored into DECL. */
422 void
423 make_function_rtl (decl)
424 tree decl;
426 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
428 if (output_bytecode)
430 if (DECL_RTL (decl) == 0)
431 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
433 /* Record that at least one function has been defined. */
434 function_defined = 1;
435 return;
438 /* Rename a nested function to avoid conflicts. */
439 if (decl_function_context (decl) != 0
440 && DECL_INITIAL (decl) != 0
441 && DECL_RTL (decl) == 0)
443 char *label;
445 name = IDENTIFIER_POINTER (DECL_NAME (decl));
446 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
447 name = obstack_copy0 (saveable_obstack, label, strlen (label));
448 var_labelno++;
451 if (DECL_RTL (decl) == 0)
453 DECL_RTL (decl)
454 = gen_rtx (MEM, DECL_MODE (decl),
455 gen_rtx (SYMBOL_REF, Pmode, name));
457 /* Optionally set flags or add text to the name to record information
458 such as that it is a function name. If the name is changed, the macro
459 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
460 #ifdef ENCODE_SECTION_INFO
461 ENCODE_SECTION_INFO (decl);
462 #endif
465 /* Record at least one function has been defined. */
466 function_defined = 1;
469 /* Create the DECL_RTL for a declaration for a static or external
470 variable or static or external function.
471 ASMSPEC, if not 0, is the string which the user specified
472 as the assembler symbol name.
473 TOP_LEVEL is nonzero if this is a file-scope variable.
474 This is never called for PARM_DECLs. */
476 static void
477 bc_make_decl_rtl (decl, asmspec, top_level)
478 tree decl;
479 char *asmspec;
480 int top_level;
482 register char *name = TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl));
484 if (DECL_RTL (decl) == 0)
486 /* Print an error message for register variables. */
487 if (DECL_REGISTER (decl))
488 error ("global register variables not supported in the interpreter");
490 /* Handle ordinary static variables and functions. */
491 if (DECL_RTL (decl) == 0)
493 /* Can't use just the variable's own name for a variable
494 whose scope is less than the whole file.
495 Concatenate a distinguishing number. */
496 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
498 char *label;
500 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
501 name = obstack_copy0 (saveable_obstack, label, strlen (label));
502 var_labelno++;
505 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
510 /* Given NAME, a putative register name, discard any customary prefixes. */
512 static char *
513 strip_reg_name (name)
514 char *name;
516 #ifdef REGISTER_PREFIX
517 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
518 name += strlen (REGISTER_PREFIX);
519 #endif
520 if (name[0] == '%' || name[0] == '#')
521 name++;
522 return name;
525 /* Decode an `asm' spec for a declaration as a register name.
526 Return the register number, or -1 if nothing specified,
527 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
528 or -3 if ASMSPEC is `cc' and is not recognized,
529 or -4 if ASMSPEC is `memory' and is not recognized.
530 Accept an exact spelling or a decimal number.
531 Prefixes such as % are optional. */
534 decode_reg_name (asmspec)
535 char *asmspec;
537 if (asmspec != 0)
539 int i;
541 /* Get rid of confusing prefixes. */
542 asmspec = strip_reg_name (asmspec);
544 /* Allow a decimal number as a "register name". */
545 for (i = strlen (asmspec) - 1; i >= 0; i--)
546 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
547 break;
548 if (asmspec[0] != 0 && i < 0)
550 i = atoi (asmspec);
551 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
552 return i;
553 else
554 return -2;
557 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
558 if (reg_names[i][0]
559 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
560 return i;
562 #ifdef ADDITIONAL_REGISTER_NAMES
564 static struct { char *name; int number; } table[]
565 = ADDITIONAL_REGISTER_NAMES;
567 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
568 if (! strcmp (asmspec, table[i].name))
569 return table[i].number;
571 #endif /* ADDITIONAL_REGISTER_NAMES */
573 if (!strcmp (asmspec, "memory"))
574 return -4;
576 if (!strcmp (asmspec, "cc"))
577 return -3;
579 return -2;
582 return -1;
585 /* Create the DECL_RTL for a declaration for a static or external variable
586 or static or external function.
587 ASMSPEC, if not 0, is the string which the user specified
588 as the assembler symbol name.
589 TOP_LEVEL is nonzero if this is a file-scope variable.
591 This is never called for PARM_DECL nodes. */
593 void
594 make_decl_rtl (decl, asmspec, top_level)
595 tree decl;
596 char *asmspec;
597 int top_level;
599 register char *name = 0;
600 int reg_number;
602 if (output_bytecode)
604 bc_make_decl_rtl (decl, asmspec, top_level);
605 return;
608 reg_number = decode_reg_name (asmspec);
610 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
611 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
613 if (reg_number == -2)
615 /* ASMSPEC is given, and not the name of a register. */
616 name = (char *) obstack_alloc (saveable_obstack,
617 strlen (asmspec) + 2);
618 name[0] = '*';
619 strcpy (&name[1], asmspec);
622 /* For a duplicate declaration, we can be called twice on the
623 same DECL node. Don't discard the RTL already made. */
624 if (DECL_RTL (decl) == 0)
626 DECL_RTL (decl) = 0;
628 /* First detect errors in declaring global registers. */
629 if (TREE_CODE (decl) != FUNCTION_DECL
630 && DECL_REGISTER (decl) && reg_number == -1)
631 error_with_decl (decl,
632 "register name not specified for `%s'");
633 else if (TREE_CODE (decl) != FUNCTION_DECL
634 && DECL_REGISTER (decl) && reg_number < 0)
635 error_with_decl (decl,
636 "invalid register name for `%s'");
637 else if ((reg_number >= 0 || reg_number == -3)
638 && (TREE_CODE (decl) == FUNCTION_DECL
639 && ! DECL_REGISTER (decl)))
640 error_with_decl (decl,
641 "register name given for non-register variable `%s'");
642 else if (TREE_CODE (decl) != FUNCTION_DECL
643 && DECL_REGISTER (decl)
644 && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
645 error_with_decl (decl,
646 "data type of `%s' isn't suitable for a register");
647 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl)
648 && ! HARD_REGNO_MODE_OK (reg_number,
649 TYPE_MODE (TREE_TYPE (decl))))
650 error_with_decl (decl,
651 "register number for `%s' isn't suitable for data type");
652 /* Now handle properly declared static register variables. */
653 else if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
655 int nregs;
657 if (DECL_INITIAL (decl) != 0 && top_level)
659 DECL_INITIAL (decl) = 0;
660 error ("global register variable has initial value");
662 if (fixed_regs[reg_number] == 0
663 && function_defined && top_level)
664 error ("global register variable follows a function definition");
665 if (TREE_THIS_VOLATILE (decl))
666 warning ("volatile register variables don't work as you might wish");
668 /* If the user specified one of the eliminables registers here,
669 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
670 confused with that register and be eliminated. Although this
671 usage is somewhat suspect, we nevertheless use the following
672 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
674 DECL_RTL (decl)
675 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
676 REGNO (DECL_RTL (decl)) = reg_number;
677 REG_USERVAR_P (DECL_RTL (decl)) = 1;
679 if (top_level)
681 /* Make this register global, so not usable for anything
682 else. */
683 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
684 while (nregs > 0)
685 globalize_reg (reg_number + --nregs);
688 /* Specifying a section attribute on an uninitialized variable does not
689 (and cannot) cause it to be put in the given section. The linker
690 can only put initialized objects in specific sections, everything
691 else goes in bss for the linker to sort out later (otherwise the
692 linker would give a duplicate definition error for each compilation
693 unit that behaved thusly). So warn the user. */
694 else if (TREE_CODE (decl) == VAR_DECL
695 && DECL_SECTION_NAME (decl) != NULL_TREE
696 && DECL_INITIAL (decl) == NULL_TREE
697 && DECL_COMMON (decl))
699 warning_with_decl (decl,
700 "section attribute ignored for uninitialized variable `%s'");
701 /* Remove the section name so subsequent declarations won't see it.
702 We are ignoring it, remember. */
703 DECL_SECTION_NAME (decl) = NULL_TREE;
706 /* Now handle ordinary static variables and functions (in memory).
707 Also handle vars declared register invalidly. */
708 if (DECL_RTL (decl) == 0)
710 /* Can't use just the variable's own name for a variable
711 whose scope is less than the whole file.
712 Concatenate a distinguishing number. */
713 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
715 char *label;
717 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
718 name = obstack_copy0 (saveable_obstack, label, strlen (label));
719 var_labelno++;
722 if (name == 0)
723 abort ();
725 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
726 gen_rtx (SYMBOL_REF, Pmode, name));
727 DECL_ASSEMBLER_NAME (decl) = get_identifier (name);
729 /* If this variable is to be treated as volatile, show its
730 tree node has side effects. If it has side effects, either
731 because of this test or from TREE_THIS_VOLATILE also
732 being set, show the MEM is volatile. */
733 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
734 && TREE_PUBLIC (decl))
735 TREE_SIDE_EFFECTS (decl) = 1;
736 if (TREE_SIDE_EFFECTS (decl))
737 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
739 if (TREE_READONLY (decl))
740 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
741 MEM_IN_STRUCT_P (DECL_RTL (decl))
742 = AGGREGATE_TYPE_P (TREE_TYPE (decl));
744 /* Optionally set flags or add text to the name to record information
745 such as that it is a function name.
746 If the name is changed, the macro ASM_OUTPUT_LABELREF
747 will have to know how to strip this information. */
748 #ifdef ENCODE_SECTION_INFO
749 ENCODE_SECTION_INFO (decl);
750 #endif
753 /* If the old RTL had the wrong mode, fix the mode. */
754 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
756 rtx rtl = DECL_RTL (decl);
757 PUT_MODE (rtl, DECL_MODE (decl));
761 /* Make the rtl for variable VAR be volatile.
762 Use this only for static variables. */
764 void
765 make_var_volatile (var)
766 tree var;
768 if (GET_CODE (DECL_RTL (var)) != MEM)
769 abort ();
771 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
774 /* Output alignment directive to align for constant expression EXP. */
776 void
777 assemble_constant_align (exp)
778 tree exp;
780 int align;
782 /* Align the location counter as required by EXP's data type. */
783 align = TYPE_ALIGN (TREE_TYPE (exp));
784 #ifdef CONSTANT_ALIGNMENT
785 align = CONSTANT_ALIGNMENT (exp, align);
786 #endif
788 if (align > BITS_PER_UNIT)
789 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
792 /* Output a string of literal assembler code
793 for an `asm' keyword used between functions. */
795 void
796 assemble_asm (string)
797 tree string;
799 if (output_bytecode)
801 error ("asm statements not allowed in interpreter");
802 return;
805 app_enable ();
807 if (TREE_CODE (string) == ADDR_EXPR)
808 string = TREE_OPERAND (string, 0);
810 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
813 #if 0 /* This should no longer be needed, because
814 flag_gnu_linker should be 0 on these systems,
815 which should prevent any output
816 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
817 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
818 #ifndef ASM_OUTPUT_CONSTRUCTOR
819 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
820 #endif
821 #ifndef ASM_OUTPUT_DESTRUCTOR
822 #define ASM_OUTPUT_DESTRUCTOR(file, name)
823 #endif
824 #endif
825 #endif /* 0 */
827 /* Record an element in the table of global destructors.
828 How this is done depends on what sort of assembler and linker
829 are in use.
831 NAME should be the name of a global function to be called
832 at exit time. This name is output using assemble_name. */
834 void
835 assemble_destructor (name)
836 char *name;
838 #ifdef ASM_OUTPUT_DESTRUCTOR
839 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
840 #else
841 if (flag_gnu_linker)
843 /* Now tell GNU LD that this is part of the static destructor set. */
844 /* This code works for any machine provided you use GNU as/ld. */
845 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
846 assemble_name (asm_out_file, name);
847 fputc ('\n', asm_out_file);
849 #endif
852 /* Likewise for global constructors. */
854 void
855 assemble_constructor (name)
856 char *name;
858 #ifdef ASM_OUTPUT_CONSTRUCTOR
859 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
860 #else
861 if (flag_gnu_linker)
863 /* Now tell GNU LD that this is part of the static constructor set. */
864 /* This code works for any machine provided you use GNU as/ld. */
865 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
866 assemble_name (asm_out_file, name);
867 fputc ('\n', asm_out_file);
869 #endif
872 /* Likewise for entries we want to record for garbage collection.
873 Garbage collection is still under development. */
875 void
876 assemble_gc_entry (name)
877 char *name;
879 #ifdef ASM_OUTPUT_GC_ENTRY
880 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
881 #else
882 if (flag_gnu_linker)
884 /* Now tell GNU LD that this is part of the static constructor set. */
885 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
886 assemble_name (asm_out_file, name);
887 fputc ('\n', asm_out_file);
889 #endif
892 /* Output assembler code for the constant pool of a function and associated
893 with defining the name of the function. DECL describes the function.
894 NAME is the function's name. For the constant pool, we use the current
895 constant pool data. */
897 void
898 assemble_start_function (decl, fnname)
899 tree decl;
900 char *fnname;
902 int align;
904 /* The following code does not need preprocessing in the assembler. */
906 app_disable ();
908 output_constant_pool (fnname, decl);
910 #ifdef ASM_OUTPUT_SECTION_NAME
911 /* If the function is to be put in its own section and it's not in a section
912 already, indicate so. */
913 if (flag_function_sections
914 && DECL_SECTION_NAME (decl) == NULL_TREE)
916 #ifdef UNIQUE_SECTION
917 DECL_SECTION_NAME(decl) = UNIQUE_SECTION (decl);
918 #else
919 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
920 /* Strip off any encoding in name. */
921 STRIP_NAME_ENCODING (name, name);
922 DECL_SECTION_NAME (decl) = build_string (strlen (name), name);
923 #endif
925 #endif
927 function_section (decl);
929 /* Tell assembler to move to target machine's alignment for functions. */
930 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
931 if (align > 0)
933 if (output_bytecode)
934 BC_OUTPUT_ALIGN (asm_out_file, align);
935 else
936 ASM_OUTPUT_ALIGN (asm_out_file, align);
939 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
940 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
941 #endif
943 #ifdef SDB_DEBUGGING_INFO
944 /* Output SDB definition of the function. */
945 if (write_symbols == SDB_DEBUG)
946 sdbout_mark_begin_function ();
947 #endif
949 #ifdef DBX_DEBUGGING_INFO
950 /* Output DBX definition of the function. */
951 if (write_symbols == DBX_DEBUG)
952 dbxout_begin_function (decl);
953 #endif
955 /* Make function name accessible from other files, if appropriate. */
957 if (TREE_PUBLIC (decl))
959 if (!first_global_object_name)
961 char *p;
963 STRIP_NAME_ENCODING (p, fnname);
964 first_global_object_name = permalloc (strlen (p) + 1);
965 strcpy (first_global_object_name, p);
968 #ifdef ASM_WEAKEN_LABEL
969 if (DECL_WEAK (decl))
970 ASM_WEAKEN_LABEL (asm_out_file, fnname);
971 else
972 #endif
973 if (output_bytecode)
974 BC_GLOBALIZE_LABEL (asm_out_file, fnname);
975 else
976 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
979 /* Do any machine/system dependent processing of the function name */
980 if (output_bytecode)
981 BC_OUTPUT_LABEL (asm_out_file, fnname);
982 else
984 #ifdef ASM_DECLARE_FUNCTION_NAME
985 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
986 #else
987 /* Standard thing is just output label for the function. */
988 ASM_OUTPUT_LABEL (asm_out_file, fnname);
989 #endif /* ASM_DECLARE_FUNCTION_NAME */
993 /* Output assembler code associated with defining the size of the
994 function. DECL describes the function. NAME is the function's name. */
996 void
997 assemble_end_function (decl, fnname)
998 tree decl;
999 char *fnname;
1001 #ifdef ASM_DECLARE_FUNCTION_SIZE
1002 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1003 #endif
1006 /* Assemble code to leave SIZE bytes of zeros. */
1008 void
1009 assemble_zeros (size)
1010 int size;
1012 if (output_bytecode)
1014 bc_emit_const_skip (size);
1015 return;
1018 #ifdef ASM_NO_SKIP_IN_TEXT
1019 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1020 so we must output 0s explicitly in the text section. */
1021 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1023 int i;
1025 for (i = 0; i < size - 20; i += 20)
1027 #ifdef ASM_BYTE_OP
1028 fprintf (asm_out_file,
1029 "%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);
1030 #else
1031 fprintf (asm_out_file,
1032 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1033 #endif
1035 if (i < size)
1037 #ifdef ASM_BYTE_OP
1038 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
1039 #else
1040 fprintf (asm_out_file, "\tbyte 0");
1041 #endif
1042 i++;
1043 for (; i < size; i++)
1044 fprintf (asm_out_file, ",0");
1045 fprintf (asm_out_file, "\n");
1048 else
1049 #endif
1050 if (size > 0)
1052 if (output_bytecode)
1053 BC_OUTPUT_SKIP (asm_out_file, size);
1054 else
1055 ASM_OUTPUT_SKIP (asm_out_file, size);
1059 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1061 void
1062 assemble_align (align)
1063 int align;
1065 if (align > BITS_PER_UNIT)
1066 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1069 /* Assemble a string constant with the specified C string as contents. */
1071 void
1072 assemble_string (p, size)
1073 char *p;
1074 int size;
1076 register int i;
1077 int pos = 0;
1078 int maximum = 2000;
1080 if (output_bytecode)
1082 bc_emit (p, size);
1083 return;
1086 /* If the string is very long, split it up. */
1088 while (pos < size)
1090 int thissize = size - pos;
1091 if (thissize > maximum)
1092 thissize = maximum;
1094 if (output_bytecode)
1095 bc_output_ascii (asm_out_file, p, thissize);
1096 else
1098 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1101 pos += thissize;
1102 p += thissize;
1106 static void
1107 bc_output_ascii (file, p, size)
1108 FILE *file;
1109 char *p;
1110 int size;
1112 BC_OUTPUT_ASCII (file, p, size);
1115 /* Assemble everything that is needed for a variable or function declaration.
1116 Not used for automatic variables, and not used for function definitions.
1117 Should not be called for variables of incomplete structure type.
1119 TOP_LEVEL is nonzero if this variable has file scope.
1120 AT_END is nonzero if this is the special handling, at end of compilation,
1121 to define things that have had only tentative definitions.
1122 DONT_OUTPUT_DATA if nonzero means don't actually output the
1123 initial value (that will be done by the caller). */
1125 void
1126 assemble_variable (decl, top_level, at_end, dont_output_data)
1127 tree decl;
1128 int top_level;
1129 int at_end;
1130 int dont_output_data;
1132 register char *name;
1133 int align;
1134 tree size_tree;
1135 int reloc = 0;
1136 enum in_section saved_in_section;
1138 last_assemble_variable_decl = 0;
1140 if (output_bytecode)
1141 return;
1143 if (GET_CODE (DECL_RTL (decl)) == REG)
1145 /* Do output symbol info for global register variables, but do nothing
1146 else for them. */
1148 if (TREE_ASM_WRITTEN (decl))
1149 return;
1150 TREE_ASM_WRITTEN (decl) = 1;
1152 if (!output_bytecode)
1154 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1155 /* File-scope global variables are output here. */
1156 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1157 && top_level)
1158 dbxout_symbol (decl, 0);
1159 #endif
1160 #ifdef SDB_DEBUGGING_INFO
1161 if (write_symbols == SDB_DEBUG && top_level
1162 /* Leave initialized global vars for end of compilation;
1163 see comment in compile_file. */
1164 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1165 sdbout_symbol (decl, 0);
1166 #endif
1169 /* Don't output any DWARF debugging information for variables here.
1170 In the case of local variables, the information for them is output
1171 when we do our recursive traversal of the tree representation for
1172 the entire containing function. In the case of file-scope variables,
1173 we output information for all of them at the very end of compilation
1174 while we are doing our final traversal of the chain of file-scope
1175 declarations. */
1177 return;
1180 /* Normally no need to say anything here for external references,
1181 since assemble_external is called by the language-specific code
1182 when a declaration is first seen. */
1184 if (DECL_EXTERNAL (decl))
1185 return;
1187 /* Output no assembler code for a function declaration.
1188 Only definitions of functions output anything. */
1190 if (TREE_CODE (decl) == FUNCTION_DECL)
1191 return;
1193 /* If type was incomplete when the variable was declared,
1194 see if it is complete now. */
1196 if (DECL_SIZE (decl) == 0)
1197 layout_decl (decl, 0);
1199 /* Still incomplete => don't allocate it; treat the tentative defn
1200 (which is what it must have been) as an `extern' reference. */
1202 if (!dont_output_data && DECL_SIZE (decl) == 0)
1204 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1205 DECL_SOURCE_LINE (decl),
1206 "storage size of `%s' isn't known",
1207 IDENTIFIER_POINTER (DECL_NAME (decl)));
1208 TREE_ASM_WRITTEN (decl) = 1;
1209 return;
1212 /* The first declaration of a variable that comes through this function
1213 decides whether it is global (in C, has external linkage)
1214 or local (in C, has internal linkage). So do nothing more
1215 if this function has already run. */
1217 if (TREE_ASM_WRITTEN (decl))
1218 return;
1220 TREE_ASM_WRITTEN (decl) = 1;
1222 app_disable ();
1224 if (! dont_output_data)
1226 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1227 goto finish;
1229 /* This is better than explicit arithmetic, since it avoids overflow. */
1230 size_tree = size_binop (CEIL_DIV_EXPR,
1231 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1233 if (TREE_INT_CST_HIGH (size_tree) != 0)
1235 error_with_decl (decl, "size of variable `%s' is too large");
1236 goto finish;
1240 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1242 /* Handle uninitialized definitions. */
1244 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1245 /* If the target can't output uninitialized but not common global data
1246 in .bss, then we have to use .data. */
1247 #if ! defined (ASM_OUTPUT_BSS) && ! defined (ASM_OUTPUT_ALIGNED_BSS)
1248 && (DECL_COMMON (decl) || ! TREE_PUBLIC (decl))
1249 #endif
1250 && ! dont_output_data)
1252 int size = TREE_INT_CST_LOW (size_tree);
1253 int rounded = size;
1255 /* Don't allocate zero bytes of common,
1256 since that means "undefined external" in the linker. */
1257 if (size == 0) rounded = 1;
1258 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1259 so that each uninitialized object starts on such a boundary. */
1260 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1261 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1262 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1264 #ifdef DBX_DEBUGGING_INFO
1265 /* File-scope global variables are output here. */
1266 if (write_symbols == DBX_DEBUG && top_level)
1267 dbxout_symbol (decl, 0);
1268 #endif
1269 #ifdef SDB_DEBUGGING_INFO
1270 if (write_symbols == SDB_DEBUG && top_level
1271 /* Leave initialized global vars for end of compilation;
1272 see comment in compile_file. */
1273 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1274 sdbout_symbol (decl, 0);
1275 #endif
1277 /* Don't output any DWARF debugging information for variables here.
1278 In the case of local variables, the information for them is output
1279 when we do our recursive traversal of the tree representation for
1280 the entire containing function. In the case of file-scope variables,
1281 we output information for all of them at the very end of compilation
1282 while we are doing our final traversal of the chain of file-scope
1283 declarations. */
1285 #if 0 /* ??? We should either delete this or add a comment describing what
1286 it was intended to do and why we shouldn't delete it. */
1287 if (flag_shared_data)
1288 data_section ();
1289 #endif
1291 if (TREE_PUBLIC (decl)
1292 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1293 && DECL_COMMON (decl)
1294 #endif
1297 #ifdef ASM_OUTPUT_SHARED_COMMON
1298 if (flag_shared_data)
1299 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1300 else
1301 #endif
1302 if (output_bytecode)
1304 BC_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1306 else
1308 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1309 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1310 DECL_ALIGN (decl));
1311 #else
1312 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1313 #endif
1316 #if defined (ASM_OUTPUT_BSS) || defined (ASM_OUTPUT_ALIGNED_BSS)
1317 else if (TREE_PUBLIC (decl))
1319 #ifdef ASM_OUTPUT_SHARED_BSS
1320 if (flag_shared_data)
1321 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1322 else
1323 #endif
1324 if (output_bytecode)
1326 BC_OUTPUT_BSS (asm_out_file, name, size, rounded);
1328 else
1330 #ifdef ASM_OUTPUT_ALIGNED_BSS
1331 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size,
1332 DECL_ALIGN (decl));
1333 #else
1334 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded);
1335 #endif
1338 #endif /* ASM_OUTPUT_BSS || ASM_OUTPUT_ALIGNED_BSS */
1339 else
1341 #ifdef ASM_OUTPUT_SHARED_LOCAL
1342 if (flag_shared_data)
1343 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1344 else
1345 #endif
1346 if (output_bytecode)
1348 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1350 else
1352 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1353 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1354 DECL_ALIGN (decl));
1355 #else
1356 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1357 #endif
1360 goto finish;
1363 /* Handle initialized definitions.
1364 Also handle uninitialized global definitions if -fno-common and the
1365 target doesn't support ASM_OUTPUT_BSS. */
1367 /* First make the assembler name(s) global if appropriate. */
1368 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1370 if (!first_global_object_name)
1372 char *p;
1374 STRIP_NAME_ENCODING (p, name);
1375 first_global_object_name = permalloc (strlen (p) + 1);
1376 strcpy (first_global_object_name, p);
1379 #ifdef ASM_WEAKEN_LABEL
1380 if (DECL_WEAK (decl))
1381 ASM_WEAKEN_LABEL (asm_out_file, name);
1382 else
1383 #endif
1384 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1386 #if 0
1387 for (d = equivalents; d; d = TREE_CHAIN (d))
1389 tree e = TREE_VALUE (d);
1390 if (TREE_PUBLIC (e) && DECL_NAME (e))
1391 ASM_GLOBALIZE_LABEL (asm_out_file,
1392 XSTR (XEXP (DECL_RTL (e), 0), 0));
1394 #endif
1396 /* Output any data that we will need to use the address of. */
1397 if (DECL_INITIAL (decl) == error_mark_node)
1398 reloc = contains_pointers_p (TREE_TYPE (decl));
1399 else if (DECL_INITIAL (decl))
1400 reloc = output_addressed_constants (DECL_INITIAL (decl));
1402 /* Switch to the appropriate section. */
1403 variable_section (decl, reloc);
1405 /* dbxout.c needs to know this. */
1406 if (in_text_section ())
1407 DECL_IN_TEXT_SECTION (decl) = 1;
1409 /* Record current section so we can restore it if dbxout.c clobbers it. */
1410 saved_in_section = in_section;
1412 /* Output the dbx info now that we have chosen the section. */
1414 #ifdef DBX_DEBUGGING_INFO
1415 /* File-scope global variables are output here. */
1416 if (write_symbols == DBX_DEBUG && top_level)
1417 dbxout_symbol (decl, 0);
1418 #endif
1419 #ifdef SDB_DEBUGGING_INFO
1420 if (write_symbols == SDB_DEBUG && top_level
1421 /* Leave initialized global vars for end of compilation;
1422 see comment in compile_file. */
1423 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1424 sdbout_symbol (decl, 0);
1425 #endif
1427 /* Don't output any DWARF debugging information for variables here.
1428 In the case of local variables, the information for them is output
1429 when we do our recursive traversal of the tree representation for
1430 the entire containing function. In the case of file-scope variables,
1431 we output information for all of them at the very end of compilation
1432 while we are doing our final traversal of the chain of file-scope
1433 declarations. */
1435 /* If the debugging output changed sections, reselect the section
1436 that's supposed to be selected. */
1437 if (in_section != saved_in_section)
1438 variable_section (decl, reloc);
1440 /* Compute and output the alignment of this data. */
1442 align = DECL_ALIGN (decl);
1443 /* In the case for initialing an array whose length isn't specified,
1444 where we have not yet been able to do the layout,
1445 figure out the proper alignment now. */
1446 if (dont_output_data && DECL_SIZE (decl) == 0
1447 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1448 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1450 /* Some object file formats have a maximum alignment which they support.
1451 In particular, a.out format supports a maximum alignment of 4. */
1452 #ifndef MAX_OFILE_ALIGNMENT
1453 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1454 #endif
1455 if (align > MAX_OFILE_ALIGNMENT)
1457 warning_with_decl (decl,
1458 "alignment of `%s' is greater than maximum object file alignment");
1459 align = MAX_OFILE_ALIGNMENT;
1461 #ifdef DATA_ALIGNMENT
1462 /* On some machines, it is good to increase alignment sometimes. */
1463 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1464 #endif
1465 #ifdef CONSTANT_ALIGNMENT
1466 if (DECL_INITIAL (decl))
1467 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1468 #endif
1470 /* Reset the alignment in case we have made it tighter, so we can benefit
1471 from it in get_pointer_alignment. */
1472 DECL_ALIGN (decl) = align;
1474 if (align > BITS_PER_UNIT)
1476 if (output_bytecode)
1477 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1478 else
1479 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1482 /* Do any machine/system dependent processing of the object. */
1483 if (output_bytecode)
1484 BC_OUTPUT_LABEL (asm_out_file, name);
1485 else
1487 #ifdef ASM_DECLARE_OBJECT_NAME
1488 last_assemble_variable_decl = decl;
1489 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1490 #else
1491 /* Standard thing is just output label for the object. */
1492 ASM_OUTPUT_LABEL (asm_out_file, name);
1493 #endif /* ASM_DECLARE_OBJECT_NAME */
1496 if (!dont_output_data)
1498 if (DECL_INITIAL (decl))
1499 /* Output the actual data. */
1500 output_constant (DECL_INITIAL (decl), TREE_INT_CST_LOW (size_tree));
1501 else
1502 /* Leave space for it. */
1503 assemble_zeros (TREE_INT_CST_LOW (size_tree));
1506 finish:
1507 #ifdef XCOFF_DEBUGGING_INFO
1508 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1509 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1510 and `aa' hasn't been output yet, the assembler generates a stab entry with
1511 a value of zero, in addition to creating an unnecessary external entry
1512 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1514 /* File-scope global variables are output here. */
1515 if (write_symbols == XCOFF_DEBUG && top_level)
1517 saved_in_section = in_section;
1519 dbxout_symbol (decl, 0);
1521 if (in_section != saved_in_section)
1522 variable_section (decl, reloc);
1524 #else
1525 /* There must be a statement after a label. */
1527 #endif
1530 /* Return 1 if type TYPE contains any pointers. */
1532 static int
1533 contains_pointers_p (type)
1534 tree type;
1536 switch (TREE_CODE (type))
1538 case POINTER_TYPE:
1539 case REFERENCE_TYPE:
1540 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1541 so I'll play safe and return 1. */
1542 case OFFSET_TYPE:
1543 return 1;
1545 case RECORD_TYPE:
1546 case UNION_TYPE:
1547 case QUAL_UNION_TYPE:
1549 tree fields;
1550 /* For a type that has fields, see if the fields have pointers. */
1551 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1552 if (TREE_CODE (fields) == FIELD_DECL
1553 && contains_pointers_p (TREE_TYPE (fields)))
1554 return 1;
1555 return 0;
1558 case ARRAY_TYPE:
1559 /* An array type contains pointers if its element type does. */
1560 return contains_pointers_p (TREE_TYPE (type));
1562 default:
1563 return 0;
1567 /* Output text storage for constructor CONSTR. */
1569 void
1570 bc_output_constructor (constr, size)
1571 tree constr;
1572 int size;
1574 int i;
1576 /* Must always be a literal; non-literal constructors are handled
1577 differently. */
1579 if (!TREE_CONSTANT (constr))
1580 abort ();
1582 /* Always const */
1583 text_section ();
1585 /* Align */
1586 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++)
1589 if (i > 0)
1590 BC_OUTPUT_ALIGN (asm_out_file, i);
1592 /* Output data */
1593 output_constant (constr, size);
1596 /* Create storage for constructor CONSTR. */
1598 void
1599 bc_output_data_constructor (constr)
1600 tree constr;
1602 int i;
1604 /* Put in data section */
1605 data_section ();
1607 /* Align */
1608 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1609 if (i > 0)
1610 BC_OUTPUT_ALIGN (asm_out_file, i);
1612 /* The constructor is filled in at runtime. */
1613 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1616 /* Output something to declare an external symbol to the assembler.
1617 (Most assemblers don't need this, so we normally output nothing.)
1618 Do nothing if DECL is not external. */
1620 void
1621 assemble_external (decl)
1622 tree decl;
1624 if (output_bytecode)
1625 return;
1627 #ifdef ASM_OUTPUT_EXTERNAL
1628 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1629 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1631 rtx rtl = DECL_RTL (decl);
1633 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1634 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1636 /* Some systems do require some output. */
1637 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1638 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1641 #endif
1644 /* Similar, for calling a library function FUN. */
1646 void
1647 assemble_external_libcall (fun)
1648 rtx fun;
1650 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1651 if (!output_bytecode)
1653 /* Declare library function name external when first used, if nec. */
1654 if (! SYMBOL_REF_USED (fun))
1656 SYMBOL_REF_USED (fun) = 1;
1657 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1660 #endif
1663 /* Declare the label NAME global. */
1665 void
1666 assemble_global (name)
1667 char *name;
1669 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1672 /* Assemble a label named NAME. */
1674 void
1675 assemble_label (name)
1676 char *name;
1678 if (output_bytecode)
1679 BC_OUTPUT_LABEL (asm_out_file, name);
1680 else
1681 ASM_OUTPUT_LABEL (asm_out_file, name);
1684 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1685 If NAME starts with a *, the rest of NAME is output verbatim.
1686 Otherwise NAME is transformed in an implementation-defined way
1687 (usually by the addition of an underscore).
1688 Many macros in the tm file are defined to call this function. */
1690 void
1691 assemble_name (file, name)
1692 FILE *file;
1693 char *name;
1695 char *real_name;
1696 int save_warn_id_clash = warn_id_clash;
1698 STRIP_NAME_ENCODING (real_name, name);
1700 /* Don't warn about an identifier name length clash on this name, since
1701 it can be a user symbol suffixed by a number. */
1702 warn_id_clash = 0;
1703 TREE_SYMBOL_REFERENCED (get_identifier (real_name)) = 1;
1704 warn_id_clash = save_warn_id_clash;
1706 if (name[0] == '*')
1708 if (output_bytecode)
1709 bc_emit_labelref (name, 0);
1710 else
1711 fputs (&name[1], file);
1713 else
1715 if (output_bytecode)
1716 BC_OUTPUT_LABELREF (file, name);
1717 else
1718 ASM_OUTPUT_LABELREF (file, name);
1722 /* Allocate SIZE bytes writable static space with a gensym name
1723 and return an RTX to refer to its address. */
1726 assemble_static_space (size)
1727 int size;
1729 char name[12];
1730 char *namestring;
1731 rtx x;
1732 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1733 so that each uninitialized object starts on such a boundary. */
1734 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1735 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1736 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1738 #if 0
1739 if (flag_shared_data)
1740 data_section ();
1741 #endif
1743 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1744 ++const_labelno;
1746 namestring = (char *) obstack_alloc (saveable_obstack,
1747 strlen (name) + 2);
1748 strcpy (namestring, name);
1750 if (output_bytecode)
1751 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1752 else
1753 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1755 if (output_bytecode)
1757 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1759 else
1761 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1762 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1763 #else
1764 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1765 #endif
1767 return x;
1770 /* Assemble the static constant template for function entry trampolines.
1771 This is done at most once per compilation.
1772 Returns an RTX for the address of the template. */
1774 #ifdef TRAMPOLINE_TEMPLATE
1776 assemble_trampoline_template ()
1778 char label[256];
1779 char *name;
1780 int align;
1782 /* Shouldn't get here */
1783 if (output_bytecode)
1784 abort ();
1786 /* By default, put trampoline templates in read-only data section. */
1788 #ifdef TRAMPOLINE_SECTION
1789 TRAMPOLINE_SECTION ();
1790 #else
1791 readonly_data_section ();
1792 #endif
1794 /* Write the assembler code to define one. */
1795 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1796 if (align > 0)
1797 ASM_OUTPUT_ALIGN (asm_out_file, align);
1799 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1800 TRAMPOLINE_TEMPLATE (asm_out_file);
1802 /* Record the rtl to refer to it. */
1803 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1804 name
1805 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1806 return gen_rtx (SYMBOL_REF, Pmode, name);
1808 #endif
1810 /* Assemble the integer constant X into an object of SIZE bytes.
1811 X must be either a CONST_INT or CONST_DOUBLE.
1813 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1814 non-zero, abort if we can't output the constant. */
1817 assemble_integer (x, size, force)
1818 rtx x;
1819 int size;
1820 int force;
1822 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1823 ASM_OUTPUT... macros. */
1825 switch (size)
1827 #ifdef ASM_OUTPUT_CHAR
1828 case 1:
1829 ASM_OUTPUT_CHAR (asm_out_file, x);
1830 return 1;
1831 #endif
1833 #ifdef ASM_OUTPUT_SHORT
1834 case 2:
1835 ASM_OUTPUT_SHORT (asm_out_file, x);
1836 return 1;
1837 #endif
1839 #ifdef ASM_OUTPUT_INT
1840 case 4:
1841 ASM_OUTPUT_INT (asm_out_file, x);
1842 return 1;
1843 #endif
1845 #ifdef ASM_OUTPUT_DOUBLE_INT
1846 case 8:
1847 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1848 return 1;
1849 #endif
1851 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1852 case 16:
1853 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1854 return 1;
1855 #endif
1858 /* If we couldn't do it that way, there are two other possibilities: First,
1859 if the machine can output an explicit byte and this is a 1 byte constant,
1860 we can use ASM_OUTPUT_BYTE. */
1862 #ifdef ASM_OUTPUT_BYTE
1863 if (size == 1 && GET_CODE (x) == CONST_INT)
1865 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1866 return 1;
1868 #endif
1870 /* Finally, if SIZE is larger than a single word, try to output the constant
1871 one word at a time. */
1873 if (size > UNITS_PER_WORD)
1875 int i;
1876 enum machine_mode mode
1877 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1878 rtx word;
1880 for (i = 0; i < size / UNITS_PER_WORD; i++)
1882 word = operand_subword (x, i, 0, mode);
1884 if (word == 0)
1885 break;
1887 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1888 break;
1891 if (i == size / UNITS_PER_WORD)
1892 return 1;
1893 /* If we output at least one word and then could not finish,
1894 there is no valid way to continue. */
1895 if (i > 0)
1896 abort ();
1899 if (force)
1900 abort ();
1902 return 0;
1905 /* Assemble the floating-point constant D into an object of size MODE. */
1907 void
1908 assemble_real (d, mode)
1909 REAL_VALUE_TYPE d;
1910 enum machine_mode mode;
1912 jmp_buf output_constant_handler;
1914 if (setjmp (output_constant_handler))
1916 error ("floating point trap outputting a constant");
1917 #ifdef REAL_IS_NOT_DOUBLE
1918 bzero ((char *) &d, sizeof d);
1919 d = dconst0;
1920 #else
1921 d = 0;
1922 #endif
1925 set_float_handler (output_constant_handler);
1927 switch (mode)
1929 #ifdef ASM_OUTPUT_BYTE_FLOAT
1930 case QFmode:
1931 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1932 break;
1933 #endif
1934 #ifdef ASM_OUTPUT_SHORT_FLOAT
1935 case HFmode:
1936 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1937 break;
1938 #endif
1939 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1940 case TQFmode:
1941 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1942 break;
1943 #endif
1944 #ifdef ASM_OUTPUT_FLOAT
1945 case SFmode:
1946 ASM_OUTPUT_FLOAT (asm_out_file, d);
1947 break;
1948 #endif
1950 #ifdef ASM_OUTPUT_DOUBLE
1951 case DFmode:
1952 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1953 break;
1954 #endif
1956 #ifdef ASM_OUTPUT_LONG_DOUBLE
1957 case XFmode:
1958 case TFmode:
1959 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1960 break;
1961 #endif
1963 default:
1964 abort ();
1967 set_float_handler (NULL_PTR);
1970 /* Here we combine duplicate floating constants to make
1971 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1973 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1974 They are chained through the CONST_DOUBLE_CHAIN.
1975 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1976 In that case, CONST_DOUBLE_MEM is either a MEM,
1977 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1979 (CONST_DOUBLE_MEM is used only for top-level functions.
1980 See force_const_mem for explanation.) */
1982 static rtx const_double_chain;
1984 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1985 For an integer, I0 is the low-order word and I1 is the high-order word.
1986 For a real number, I0 is the word with the low address
1987 and I1 is the word with the high address. */
1990 immed_double_const (i0, i1, mode)
1991 HOST_WIDE_INT i0, i1;
1992 enum machine_mode mode;
1994 register rtx r;
1995 int in_current_obstack;
1997 if (GET_MODE_CLASS (mode) == MODE_INT
1998 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
2000 /* We clear out all bits that don't belong in MODE, unless they and our
2001 sign bit are all one. So we get either a reasonable negative value
2002 or a reasonable unsigned value for this mode. */
2003 int width = GET_MODE_BITSIZE (mode);
2004 if (width < HOST_BITS_PER_WIDE_INT
2005 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
2006 != ((HOST_WIDE_INT) (-1) << (width - 1))))
2007 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
2008 else if (width == HOST_BITS_PER_WIDE_INT
2009 && ! (i1 == ~0 && i0 < 0))
2010 i1 = 0;
2011 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2012 /* We cannot represent this value as a constant. */
2013 abort ();
2015 /* If this would be an entire word for the target, but is not for
2016 the host, then sign-extend on the host so that the number will look
2017 the same way on the host that it would on the target.
2019 For example, when building a 64 bit alpha hosted 32 bit sparc
2020 targeted compiler, then we want the 32 bit unsigned value -1 to be
2021 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2022 The later confuses the sparc backend. */
2024 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
2025 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2026 i0 |= ((HOST_WIDE_INT) (-1) << width);
2028 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2030 ??? Strictly speaking, this is wrong if we create a CONST_INT
2031 for a large unsigned constant with the size of MODE being
2032 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2033 wider mode. In that case we will mis-interpret it as a negative
2034 number.
2036 Unfortunately, the only alternative is to make a CONST_DOUBLE
2037 for any constant in any mode if it is an unsigned constant larger
2038 than the maximum signed integer in an int on the host. However,
2039 doing this will break everyone that always expects to see a CONST_INT
2040 for SImode and smaller.
2042 We have always been making CONST_INTs in this case, so nothing new
2043 is being broken. */
2045 if (width <= HOST_BITS_PER_WIDE_INT)
2046 i1 = (i0 < 0) ? ~0 : 0;
2048 /* If this integer fits in one word, return a CONST_INT. */
2049 if ((i1 == 0 && i0 >= 0)
2050 || (i1 == ~0 && i0 < 0))
2051 return GEN_INT (i0);
2053 /* We use VOIDmode for integers. */
2054 mode = VOIDmode;
2057 /* Search the chain for an existing CONST_DOUBLE with the right value.
2058 If one is found, return it. */
2060 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2061 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2062 && GET_MODE (r) == mode)
2063 return r;
2065 /* No; make a new one and add it to the chain.
2067 We may be called by an optimizer which may be discarding any memory
2068 allocated during its processing (such as combine and loop). However,
2069 we will be leaving this constant on the chain, so we cannot tolerate
2070 freed memory. So switch to saveable_obstack for this allocation
2071 and then switch back if we were in current_obstack. */
2073 push_obstacks_nochange ();
2074 rtl_in_saveable_obstack ();
2075 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
2076 pop_obstacks ();
2078 /* Don't touch const_double_chain in nested function; see force_const_mem.
2079 Also, don't touch it if not inside any function. */
2080 if (outer_function_chain == 0 && current_function_decl != 0)
2082 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2083 const_double_chain = r;
2086 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
2087 Actual use of mem-slot is only through force_const_mem. */
2089 CONST_DOUBLE_MEM (r) = const0_rtx;
2091 return r;
2094 /* Return a CONST_DOUBLE for a specified `double' value
2095 and machine mode. */
2098 immed_real_const_1 (d, mode)
2099 REAL_VALUE_TYPE d;
2100 enum machine_mode mode;
2102 union real_extract u;
2103 register rtx r;
2104 int in_current_obstack;
2106 /* Get the desired `double' value as a sequence of ints
2107 since that is how they are stored in a CONST_DOUBLE. */
2109 u.d = d;
2111 /* Detect special cases. */
2113 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
2114 if (!bcmp ((char *) &dconst0, (char *) &d, sizeof d))
2115 return CONST0_RTX (mode);
2116 /* Check for NaN first, because some ports (specifically the i386) do not
2117 emit correct ieee-fp code by default, and thus will generate a core
2118 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2119 does a floating point comparison. */
2120 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2121 return CONST1_RTX (mode);
2123 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2124 return immed_double_const (u.i[0], u.i[1], mode);
2126 /* The rest of this function handles the case where
2127 a float value requires more than 2 ints of space.
2128 It will be deleted as dead code on machines that don't need it. */
2130 /* Search the chain for an existing CONST_DOUBLE with the right value.
2131 If one is found, return it. */
2133 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2134 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2135 && GET_MODE (r) == mode)
2136 return r;
2138 /* No; make a new one and add it to the chain.
2140 We may be called by an optimizer which may be discarding any memory
2141 allocated during its processing (such as combine and loop). However,
2142 we will be leaving this constant on the chain, so we cannot tolerate
2143 freed memory. So switch to saveable_obstack for this allocation
2144 and then switch back if we were in current_obstack. */
2146 push_obstacks_nochange ();
2147 rtl_in_saveable_obstack ();
2148 r = rtx_alloc (CONST_DOUBLE);
2149 PUT_MODE (r, mode);
2150 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
2151 pop_obstacks ();
2153 /* Don't touch const_double_chain in nested function; see force_const_mem.
2154 Also, don't touch it if not inside any function. */
2155 if (outer_function_chain == 0 && current_function_decl != 0)
2157 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2158 const_double_chain = r;
2161 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2162 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2163 is only through force_const_mem. */
2165 CONST_DOUBLE_MEM (r) = const0_rtx;
2167 return r;
2170 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2171 which must be a REAL_CST tree node. */
2174 immed_real_const (exp)
2175 tree exp;
2177 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2180 /* At the end of a function, forget the memory-constants
2181 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2182 Also clear out real_constant_chain and clear out all the chain-pointers. */
2184 void
2185 clear_const_double_mem ()
2187 register rtx r, next;
2189 /* Don't touch CONST_DOUBLE_MEM for nested functions.
2190 See force_const_mem for explanation. */
2191 if (outer_function_chain != 0)
2192 return;
2194 for (r = const_double_chain; r; r = next)
2196 next = CONST_DOUBLE_CHAIN (r);
2197 CONST_DOUBLE_CHAIN (r) = 0;
2198 CONST_DOUBLE_MEM (r) = cc0_rtx;
2200 const_double_chain = 0;
2203 /* Given an expression EXP with a constant value,
2204 reduce it to the sum of an assembler symbol and an integer.
2205 Store them both in the structure *VALUE.
2206 Abort if EXP does not reduce. */
2208 struct addr_const
2210 rtx base;
2211 HOST_WIDE_INT offset;
2214 static void
2215 decode_addr_const (exp, value)
2216 tree exp;
2217 struct addr_const *value;
2219 register tree target = TREE_OPERAND (exp, 0);
2220 register int offset = 0;
2221 register rtx x;
2223 while (1)
2225 if (TREE_CODE (target) == COMPONENT_REF
2226 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2227 == INTEGER_CST))
2229 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2230 target = TREE_OPERAND (target, 0);
2232 else if (TREE_CODE (target) == ARRAY_REF)
2234 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2235 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2236 abort ();
2237 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2238 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2239 / BITS_PER_UNIT);
2240 target = TREE_OPERAND (target, 0);
2242 else
2243 break;
2246 switch (TREE_CODE (target))
2248 case VAR_DECL:
2249 case FUNCTION_DECL:
2250 x = DECL_RTL (target);
2251 break;
2253 case LABEL_DECL:
2254 if (output_bytecode)
2255 /* FIXME: this may not be correct, check it */
2256 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
2257 else
2258 x = gen_rtx (MEM, FUNCTION_MODE,
2259 gen_rtx (LABEL_REF, VOIDmode,
2260 label_rtx (TREE_OPERAND (exp, 0))));
2261 break;
2263 case REAL_CST:
2264 case STRING_CST:
2265 case COMPLEX_CST:
2266 case CONSTRUCTOR:
2267 x = TREE_CST_RTL (target);
2268 break;
2270 default:
2271 abort ();
2274 if (!output_bytecode)
2276 if (GET_CODE (x) != MEM)
2277 abort ();
2278 x = XEXP (x, 0);
2281 value->base = x;
2282 value->offset = offset;
2285 /* Uniquize all constants that appear in memory.
2286 Each constant in memory thus far output is recorded
2287 in `const_hash_table' with a `struct constant_descriptor'
2288 that contains a polish representation of the value of
2289 the constant.
2291 We cannot store the trees in the hash table
2292 because the trees may be temporary. */
2294 struct constant_descriptor
2296 struct constant_descriptor *next;
2297 char *label;
2298 char contents[1];
2301 #define HASHBITS 30
2302 #define MAX_HASH_TABLE 1009
2303 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2305 /* Compute a hash code for a constant expression. */
2307 static int
2308 const_hash (exp)
2309 tree exp;
2311 register char *p;
2312 register int len, hi, i;
2313 register enum tree_code code = TREE_CODE (exp);
2315 if (code == INTEGER_CST)
2317 p = (char *) &TREE_INT_CST_LOW (exp);
2318 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2320 else if (code == REAL_CST)
2322 p = (char *) &TREE_REAL_CST (exp);
2323 len = sizeof TREE_REAL_CST (exp);
2325 else if (code == STRING_CST)
2326 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2327 else if (code == COMPLEX_CST)
2328 return const_hash (TREE_REALPART (exp)) * 5
2329 + const_hash (TREE_IMAGPART (exp));
2330 else if (code == CONSTRUCTOR && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2332 len = int_size_in_bytes (TREE_TYPE (exp));
2333 p = (char*) alloca (len);
2334 get_set_constructor_bytes (exp, (unsigned char *) p, len);
2336 else if (code == CONSTRUCTOR)
2338 register tree link;
2340 /* For record type, include the type in the hashing.
2341 We do not do so for array types
2342 because (1) the sizes of the elements are sufficient
2343 and (2) distinct array types can have the same constructor.
2344 Instead, we include the array size because the constructor could
2345 be shorter. */
2346 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2347 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2348 % MAX_HASH_TABLE;
2349 else
2350 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2351 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2353 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2354 if (TREE_VALUE (link))
2355 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2357 return hi;
2359 else if (code == ADDR_EXPR)
2361 struct addr_const value;
2362 decode_addr_const (exp, &value);
2363 if (GET_CODE (value.base) == SYMBOL_REF)
2365 /* Don't hash the address of the SYMBOL_REF;
2366 only use the offset and the symbol name. */
2367 hi = value.offset;
2368 p = XSTR (value.base, 0);
2369 for (i = 0; p[i] != 0; i++)
2370 hi = ((hi * 613) + (unsigned)(p[i]));
2372 else if (GET_CODE (value.base) == LABEL_REF)
2373 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2375 hi &= (1 << HASHBITS) - 1;
2376 hi %= MAX_HASH_TABLE;
2377 return hi;
2379 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2380 return const_hash (TREE_OPERAND (exp, 0)) * 9
2381 + const_hash (TREE_OPERAND (exp, 1));
2382 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2383 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2385 /* Compute hashing function */
2386 hi = len;
2387 for (i = 0; i < len; i++)
2388 hi = ((hi * 613) + (unsigned)(p[i]));
2390 hi &= (1 << HASHBITS) - 1;
2391 hi %= MAX_HASH_TABLE;
2392 return hi;
2395 /* Compare a constant expression EXP with a constant-descriptor DESC.
2396 Return 1 if DESC describes a constant with the same value as EXP. */
2398 static int
2399 compare_constant (exp, desc)
2400 tree exp;
2401 struct constant_descriptor *desc;
2403 return 0 != compare_constant_1 (exp, desc->contents);
2406 /* Compare constant expression EXP with a substring P of a constant descriptor.
2407 If they match, return a pointer to the end of the substring matched.
2408 If they do not match, return 0.
2410 Since descriptors are written in polish prefix notation,
2411 this function can be used recursively to test one operand of EXP
2412 against a subdescriptor, and if it succeeds it returns the
2413 address of the subdescriptor for the next operand. */
2415 static char *
2416 compare_constant_1 (exp, p)
2417 tree exp;
2418 char *p;
2420 register char *strp;
2421 register int len;
2422 register enum tree_code code = TREE_CODE (exp);
2424 if (code != (enum tree_code) *p++)
2425 return 0;
2427 if (code == INTEGER_CST)
2429 /* Integer constants are the same only if the same width of type. */
2430 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2431 return 0;
2432 strp = (char *) &TREE_INT_CST_LOW (exp);
2433 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2435 else if (code == REAL_CST)
2437 /* Real constants are the same only if the same width of type. */
2438 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2439 return 0;
2440 strp = (char *) &TREE_REAL_CST (exp);
2441 len = sizeof TREE_REAL_CST (exp);
2443 else if (code == STRING_CST)
2445 if (flag_writable_strings)
2446 return 0;
2447 strp = TREE_STRING_POINTER (exp);
2448 len = TREE_STRING_LENGTH (exp);
2449 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2450 sizeof TREE_STRING_LENGTH (exp)))
2451 return 0;
2452 p += sizeof TREE_STRING_LENGTH (exp);
2454 else if (code == COMPLEX_CST)
2456 p = compare_constant_1 (TREE_REALPART (exp), p);
2457 if (p == 0) return 0;
2458 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2459 return p;
2461 else if (code == CONSTRUCTOR && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2463 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2464 strp = (char*) alloca (len);
2465 get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2466 if (bcmp ((char *) &xlen, p, sizeof xlen))
2467 return 0;
2468 p += sizeof xlen;
2470 else if (code == CONSTRUCTOR)
2472 register tree link;
2473 int length = list_length (CONSTRUCTOR_ELTS (exp));
2474 tree type;
2476 if (bcmp ((char *) &length, p, sizeof length))
2477 return 0;
2478 p += sizeof length;
2480 /* For record constructors, insist that the types match.
2481 For arrays, just verify both constructors are for arrays. */
2482 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2483 type = TREE_TYPE (exp);
2484 else
2485 type = 0;
2486 if (bcmp ((char *) &type, p, sizeof type))
2487 return 0;
2488 p += sizeof type;
2490 /* For arrays, insist that the size in bytes match. */
2491 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2493 int size = int_size_in_bytes (TREE_TYPE (exp));
2494 if (bcmp ((char *) &size, p, sizeof size))
2495 return 0;
2496 p += sizeof size;
2499 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2501 if (TREE_VALUE (link))
2503 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2504 return 0;
2506 else
2508 tree zero = 0;
2510 if (bcmp ((char *) &zero, p, sizeof zero))
2511 return 0;
2512 p += sizeof zero;
2516 return p;
2518 else if (code == ADDR_EXPR)
2520 struct addr_const value;
2521 decode_addr_const (exp, &value);
2522 strp = (char *) &value.offset;
2523 len = sizeof value.offset;
2524 /* Compare the offset. */
2525 while (--len >= 0)
2526 if (*p++ != *strp++)
2527 return 0;
2528 /* Compare symbol name. */
2529 strp = XSTR (value.base, 0);
2530 len = strlen (strp) + 1;
2532 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2534 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2535 if (p == 0) return 0;
2536 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2537 return p;
2539 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2541 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2542 return p;
2545 /* Compare constant contents. */
2546 while (--len >= 0)
2547 if (*p++ != *strp++)
2548 return 0;
2550 return p;
2553 /* Construct a constant descriptor for the expression EXP.
2554 It is up to the caller to enter the descriptor in the hash table. */
2556 static struct constant_descriptor *
2557 record_constant (exp)
2558 tree exp;
2560 struct constant_descriptor *next = 0;
2561 char *label = 0;
2563 /* Make a struct constant_descriptor. The first two pointers will
2564 be filled in later. Here we just leave space for them. */
2566 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2567 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2568 record_constant_1 (exp);
2569 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2572 /* Add a description of constant expression EXP
2573 to the object growing in `permanent_obstack'.
2574 No need to return its address; the caller will get that
2575 from the obstack when the object is complete. */
2577 static void
2578 record_constant_1 (exp)
2579 tree exp;
2581 register char *strp;
2582 register int len;
2583 register enum tree_code code = TREE_CODE (exp);
2585 obstack_1grow (&permanent_obstack, (unsigned int) code);
2587 switch (code)
2589 case INTEGER_CST:
2590 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2591 strp = (char *) &TREE_INT_CST_LOW (exp);
2592 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2593 break;
2595 case REAL_CST:
2596 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2597 strp = (char *) &TREE_REAL_CST (exp);
2598 len = sizeof TREE_REAL_CST (exp);
2599 break;
2601 case STRING_CST:
2602 if (flag_writable_strings)
2603 return;
2605 strp = TREE_STRING_POINTER (exp);
2606 len = TREE_STRING_LENGTH (exp);
2607 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2608 sizeof TREE_STRING_LENGTH (exp));
2609 break;
2611 case COMPLEX_CST:
2612 record_constant_1 (TREE_REALPART (exp));
2613 record_constant_1 (TREE_IMAGPART (exp));
2614 return;
2616 case CONSTRUCTOR:
2617 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2619 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2620 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2621 obstack_blank (&permanent_obstack, nbytes);
2622 get_set_constructor_bytes
2623 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2624 nbytes);
2625 return;
2627 else
2629 register tree link;
2630 int length = list_length (CONSTRUCTOR_ELTS (exp));
2631 tree type;
2633 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2635 /* For record constructors, insist that the types match.
2636 For arrays, just verify both constructors are for arrays. */
2637 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2638 type = TREE_TYPE (exp);
2639 else
2640 type = 0;
2641 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2643 /* For arrays, insist that the size in bytes match. */
2644 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2646 int size = int_size_in_bytes (TREE_TYPE (exp));
2647 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2650 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2652 if (TREE_VALUE (link))
2653 record_constant_1 (TREE_VALUE (link));
2654 else
2656 tree zero = 0;
2658 obstack_grow (&permanent_obstack,
2659 (char *) &zero, sizeof zero);
2663 return;
2665 case ADDR_EXPR:
2667 struct addr_const value;
2669 decode_addr_const (exp, &value);
2670 /* Record the offset. */
2671 obstack_grow (&permanent_obstack,
2672 (char *) &value.offset, sizeof value.offset);
2673 /* Record the symbol name. */
2674 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2675 strlen (XSTR (value.base, 0)) + 1);
2677 return;
2679 case PLUS_EXPR:
2680 case MINUS_EXPR:
2681 record_constant_1 (TREE_OPERAND (exp, 0));
2682 record_constant_1 (TREE_OPERAND (exp, 1));
2683 return;
2685 case NOP_EXPR:
2686 case CONVERT_EXPR:
2687 case NON_LVALUE_EXPR:
2688 record_constant_1 (TREE_OPERAND (exp, 0));
2689 return;
2691 default:
2692 abort ();
2695 /* Record constant contents. */
2696 obstack_grow (&permanent_obstack, strp, len);
2699 /* Record a list of constant expressions that were passed to
2700 output_constant_def but that could not be output right away. */
2702 struct deferred_constant
2704 struct deferred_constant *next;
2705 tree exp;
2706 int reloc;
2707 int labelno;
2710 static struct deferred_constant *deferred_constants;
2712 /* Nonzero means defer output of addressed subconstants
2713 (i.e., those for which output_constant_def is called.) */
2714 static int defer_addressed_constants_flag;
2716 /* Start deferring output of subconstants. */
2718 void
2719 defer_addressed_constants ()
2721 defer_addressed_constants_flag++;
2724 /* Stop deferring output of subconstants,
2725 and output now all those that have been deferred. */
2727 void
2728 output_deferred_addressed_constants ()
2730 struct deferred_constant *p, *next;
2732 defer_addressed_constants_flag--;
2734 if (defer_addressed_constants_flag > 0)
2735 return;
2737 for (p = deferred_constants; p; p = next)
2739 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2740 next = p->next;
2741 free (p);
2744 deferred_constants = 0;
2747 /* Make a copy of the whole tree structure for a constant.
2748 This handles the same types of nodes that compare_constant
2749 and record_constant handle. */
2751 static tree
2752 copy_constant (exp)
2753 tree exp;
2755 switch (TREE_CODE (exp))
2757 case ADDR_EXPR:
2758 /* For ADDR_EXPR, we do not want to copy the decl whose address
2759 is requested. We do want to copy constants though. */
2760 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2761 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2762 copy_constant (TREE_OPERAND (exp, 0)));
2763 else
2764 return copy_node (exp);
2766 case INTEGER_CST:
2767 case REAL_CST:
2768 case STRING_CST:
2769 return copy_node (exp);
2771 case COMPLEX_CST:
2772 return build_complex (copy_constant (TREE_REALPART (exp)),
2773 copy_constant (TREE_IMAGPART (exp)));
2775 case PLUS_EXPR:
2776 case MINUS_EXPR:
2777 return build (TREE_CODE (exp), TREE_TYPE (exp),
2778 copy_constant (TREE_OPERAND (exp, 0)),
2779 copy_constant (TREE_OPERAND (exp, 1)));
2781 case NOP_EXPR:
2782 case CONVERT_EXPR:
2783 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2784 copy_constant (TREE_OPERAND (exp, 0)));
2786 case CONSTRUCTOR:
2788 tree copy = copy_node (exp);
2789 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2790 tree tail;
2792 CONSTRUCTOR_ELTS (copy) = list;
2793 for (tail = list; tail; tail = TREE_CHAIN (tail))
2794 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2795 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2796 for (tail = list; tail; tail = TREE_CHAIN (tail))
2797 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2799 return copy;
2802 default:
2803 abort ();
2807 /* Return an rtx representing a reference to constant data in memory
2808 for the constant expression EXP.
2810 If assembler code for such a constant has already been output,
2811 return an rtx to refer to it.
2812 Otherwise, output such a constant in memory (or defer it for later)
2813 and generate an rtx for it.
2815 The TREE_CST_RTL of EXP is set up to point to that rtx.
2816 The const_hash_table records which constants already have label strings. */
2819 output_constant_def (exp)
2820 tree exp;
2822 register int hash;
2823 register struct constant_descriptor *desc;
2824 char label[256];
2825 char *found = 0;
2826 int reloc;
2827 register rtx def;
2829 if (TREE_CODE (exp) == INTEGER_CST)
2830 abort (); /* No TREE_CST_RTL slot in these. */
2832 if (TREE_CST_RTL (exp))
2833 return TREE_CST_RTL (exp);
2835 /* Make sure any other constants whose addresses appear in EXP
2836 are assigned label numbers. */
2838 reloc = output_addressed_constants (exp);
2840 /* Compute hash code of EXP. Search the descriptors for that hash code
2841 to see if any of them describes EXP. If yes, the descriptor records
2842 the label number already assigned. */
2844 hash = const_hash (exp) % MAX_HASH_TABLE;
2846 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2847 if (compare_constant (exp, desc))
2849 found = desc->label;
2850 break;
2853 if (found == 0)
2855 /* No constant equal to EXP is known to have been output.
2856 Make a constant descriptor to enter EXP in the hash table.
2857 Assign the label number and record it in the descriptor for
2858 future calls to this function to find. */
2860 /* Create a string containing the label name, in LABEL. */
2861 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2863 desc = record_constant (exp);
2864 desc->next = const_hash_table[hash];
2865 desc->label
2866 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2867 const_hash_table[hash] = desc;
2869 else
2871 /* Create a string containing the label name, in LABEL. */
2872 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2875 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2877 push_obstacks_nochange ();
2878 if (TREE_PERMANENT (exp))
2879 end_temporary_allocation ();
2881 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2883 TREE_CST_RTL (exp)
2884 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2885 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2886 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2887 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2889 pop_obstacks ();
2891 /* Optionally set flags or add text to the name to record information
2892 such as that it is a function name. If the name is changed, the macro
2893 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2894 #ifdef ENCODE_SECTION_INFO
2895 ENCODE_SECTION_INFO (exp);
2896 #endif
2898 /* If this is the first time we've seen this particular constant,
2899 output it (or defer its output for later). */
2900 if (found == 0)
2902 if (defer_addressed_constants_flag)
2904 struct deferred_constant *p;
2905 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2907 push_obstacks_nochange ();
2908 suspend_momentary ();
2909 p->exp = copy_constant (exp);
2910 pop_obstacks ();
2911 p->reloc = reloc;
2912 p->labelno = const_labelno++;
2913 p->next = deferred_constants;
2914 deferred_constants = p;
2916 else
2917 output_constant_def_contents (exp, reloc, const_labelno++);
2920 return TREE_CST_RTL (exp);
2923 /* Now output assembler code to define the label for EXP,
2924 and follow it with the data of EXP. */
2926 static void
2927 output_constant_def_contents (exp, reloc, labelno)
2928 tree exp;
2929 int reloc;
2930 int labelno;
2932 int align;
2934 if (IN_NAMED_SECTION (exp))
2935 named_section (exp, NULL);
2936 else
2938 /* First switch to text section, except for writable strings. */
2939 #ifdef SELECT_SECTION
2940 SELECT_SECTION (exp, reloc);
2941 #else
2942 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2943 || (flag_pic && reloc))
2944 data_section ();
2945 else
2946 readonly_data_section ();
2947 #endif
2950 /* Align the location counter as required by EXP's data type. */
2951 align = TYPE_ALIGN (TREE_TYPE (exp));
2952 #ifdef CONSTANT_ALIGNMENT
2953 align = CONSTANT_ALIGNMENT (exp, align);
2954 #endif
2956 if (align > BITS_PER_UNIT)
2958 if (!output_bytecode)
2960 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2962 else
2964 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2968 /* Output the label itself. */
2969 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2971 /* Output the value of EXP. */
2972 output_constant (exp,
2973 (TREE_CODE (exp) == STRING_CST
2974 ? TREE_STRING_LENGTH (exp)
2975 : int_size_in_bytes (TREE_TYPE (exp))));
2979 /* Similar hash facility for making memory-constants
2980 from constant rtl-expressions. It is used on RISC machines
2981 where immediate integer arguments and constant addresses are restricted
2982 so that such constants must be stored in memory.
2984 This pool of constants is reinitialized for each function
2985 so each function gets its own constants-pool that comes right before it.
2987 All structures allocated here are discarded when functions are saved for
2988 inlining, so they do not need to be allocated permanently. */
2990 #define MAX_RTX_HASH_TABLE 61
2991 static struct constant_descriptor **const_rtx_hash_table;
2993 /* Structure to represent sufficient information about a constant so that
2994 it can be output when the constant pool is output, so that function
2995 integration can be done, and to simplify handling on machines that reference
2996 constant pool as base+displacement. */
2998 struct pool_constant
3000 struct constant_descriptor *desc;
3001 struct pool_constant *next;
3002 enum machine_mode mode;
3003 rtx constant;
3004 int labelno;
3005 int align;
3006 int offset;
3009 /* Pointers to first and last constant in pool. */
3011 static struct pool_constant *first_pool, *last_pool;
3013 /* Current offset in constant pool (does not include any machine-specific
3014 header. */
3016 static int pool_offset;
3018 /* Structure used to maintain hash table mapping symbols used to their
3019 corresponding constants. */
3021 struct pool_sym
3023 char *label;
3024 struct pool_constant *pool;
3025 struct pool_sym *next;
3028 static struct pool_sym **const_rtx_sym_hash_table;
3030 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3031 The argument is XSTR (... , 0) */
3033 #define SYMHASH(LABEL) \
3034 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3036 /* Initialize constant pool hashing for next function. */
3038 void
3039 init_const_rtx_hash_table ()
3041 const_rtx_hash_table
3042 = ((struct constant_descriptor **)
3043 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
3044 const_rtx_sym_hash_table
3045 = ((struct pool_sym **)
3046 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
3047 bzero ((char *) const_rtx_hash_table,
3048 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
3049 bzero ((char *) const_rtx_sym_hash_table,
3050 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
3052 first_pool = last_pool = 0;
3053 pool_offset = 0;
3056 /* Save and restore status for a nested function. */
3058 void
3059 save_varasm_status (p)
3060 struct function *p;
3062 p->const_rtx_hash_table = const_rtx_hash_table;
3063 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
3064 p->first_pool = first_pool;
3065 p->last_pool = last_pool;
3066 p->pool_offset = pool_offset;
3069 void
3070 restore_varasm_status (p)
3071 struct function *p;
3073 const_rtx_hash_table = p->const_rtx_hash_table;
3074 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
3075 first_pool = p->first_pool;
3076 last_pool = p->last_pool;
3077 pool_offset = p->pool_offset;
3080 enum kind { RTX_DOUBLE, RTX_INT };
3082 struct rtx_const
3084 #ifdef ONLY_INT_FIELDS
3085 unsigned int kind : 16;
3086 unsigned int mode : 16;
3087 #else
3088 enum kind kind : 16;
3089 enum machine_mode mode : 16;
3090 #endif
3091 union {
3092 union real_extract du;
3093 struct addr_const addr;
3094 struct {HOST_WIDE_INT high, low;} di;
3095 } un;
3098 /* Express an rtx for a constant integer (perhaps symbolic)
3099 as the sum of a symbol or label plus an explicit integer.
3100 They are stored into VALUE. */
3102 static void
3103 decode_rtx_const (mode, x, value)
3104 enum machine_mode mode;
3105 rtx x;
3106 struct rtx_const *value;
3108 /* Clear the whole structure, including any gaps. */
3111 int *p = (int *) value;
3112 int *end = (int *) (value + 1);
3113 while (p < end)
3114 *p++ = 0;
3117 value->kind = RTX_INT; /* Most usual kind. */
3118 value->mode = mode;
3120 switch (GET_CODE (x))
3122 case CONST_DOUBLE:
3123 value->kind = RTX_DOUBLE;
3124 if (GET_MODE (x) != VOIDmode)
3126 value->mode = GET_MODE (x);
3127 bcopy ((char *) &CONST_DOUBLE_LOW (x),
3128 (char *) &value->un.du, sizeof value->un.du);
3130 else
3132 value->un.di.low = CONST_DOUBLE_LOW (x);
3133 value->un.di.high = CONST_DOUBLE_HIGH (x);
3135 break;
3137 case CONST_INT:
3138 value->un.addr.offset = INTVAL (x);
3139 break;
3141 case SYMBOL_REF:
3142 case LABEL_REF:
3143 case PC:
3144 value->un.addr.base = x;
3145 break;
3147 case CONST:
3148 x = XEXP (x, 0);
3149 if (GET_CODE (x) == PLUS)
3151 value->un.addr.base = XEXP (x, 0);
3152 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3153 abort ();
3154 value->un.addr.offset = INTVAL (XEXP (x, 1));
3156 else if (GET_CODE (x) == MINUS)
3158 value->un.addr.base = XEXP (x, 0);
3159 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3160 abort ();
3161 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3163 else
3164 abort ();
3165 break;
3167 default:
3168 abort ();
3171 if (value->kind == RTX_INT && value->un.addr.base != 0)
3172 switch (GET_CODE (value->un.addr.base))
3174 case SYMBOL_REF:
3175 case LABEL_REF:
3176 /* Use the string's address, not the SYMBOL_REF's address,
3177 for the sake of addresses of library routines.
3178 For a LABEL_REF, compare labels. */
3179 value->un.addr.base = XEXP (value->un.addr.base, 0);
3183 /* Given a MINUS expression, simplify it if both sides
3184 include the same symbol. */
3187 simplify_subtraction (x)
3188 rtx x;
3190 struct rtx_const val0, val1;
3192 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3193 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3195 if (val0.un.addr.base == val1.un.addr.base)
3196 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3197 return x;
3200 /* Compute a hash code for a constant RTL expression. */
3202 static int
3203 const_hash_rtx (mode, x)
3204 enum machine_mode mode;
3205 rtx x;
3207 register int hi, i;
3209 struct rtx_const value;
3210 decode_rtx_const (mode, x, &value);
3212 /* Compute hashing function */
3213 hi = 0;
3214 for (i = 0; i < sizeof value / sizeof (int); i++)
3215 hi += ((int *) &value)[i];
3217 hi &= (1 << HASHBITS) - 1;
3218 hi %= MAX_RTX_HASH_TABLE;
3219 return hi;
3222 /* Compare a constant rtl object X with a constant-descriptor DESC.
3223 Return 1 if DESC describes a constant with the same value as X. */
3225 static int
3226 compare_constant_rtx (mode, x, desc)
3227 enum machine_mode mode;
3228 rtx x;
3229 struct constant_descriptor *desc;
3231 register int *p = (int *) desc->contents;
3232 register int *strp;
3233 register int len;
3234 struct rtx_const value;
3236 decode_rtx_const (mode, x, &value);
3237 strp = (int *) &value;
3238 len = sizeof value / sizeof (int);
3240 /* Compare constant contents. */
3241 while (--len >= 0)
3242 if (*p++ != *strp++)
3243 return 0;
3245 return 1;
3248 /* Construct a constant descriptor for the rtl-expression X.
3249 It is up to the caller to enter the descriptor in the hash table. */
3251 static struct constant_descriptor *
3252 record_constant_rtx (mode, x)
3253 enum machine_mode mode;
3254 rtx x;
3256 struct constant_descriptor *ptr;
3257 char *label;
3258 struct rtx_const value;
3260 decode_rtx_const (mode, x, &value);
3262 /* Put these things in the saveable obstack so we can ensure it won't
3263 be freed if we are called from combine or some other phase that discards
3264 memory allocated from function_obstack (current_obstack). */
3265 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3266 obstack_grow (saveable_obstack, &label, sizeof label);
3268 /* Record constant contents. */
3269 obstack_grow (saveable_obstack, &value, sizeof value);
3271 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3274 /* Given a constant rtx X, make (or find) a memory constant for its value
3275 and return a MEM rtx to refer to it in memory. */
3278 force_const_mem (mode, x)
3279 enum machine_mode mode;
3280 rtx x;
3282 register int hash;
3283 register struct constant_descriptor *desc;
3284 char label[256];
3285 char *found = 0;
3286 rtx def;
3288 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3289 (this will always be true for floating CONST_DOUBLEs that have been
3290 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3291 use the previous copy. Otherwise, make a new one. Note that in
3292 the unlikely event that this same CONST_DOUBLE is used in two different
3293 modes in an alternating fashion, we will allocate a lot of different
3294 memory locations, but this should be extremely rare. */
3296 /* Don't use CONST_DOUBLE_MEM in a nested function.
3297 Nested functions have their own constant pools,
3298 so they can't share the same values in CONST_DOUBLE_MEM
3299 with the containing function. */
3300 if (outer_function_chain == 0)
3301 if (GET_CODE (x) == CONST_DOUBLE
3302 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3303 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3304 return CONST_DOUBLE_MEM (x);
3306 /* Compute hash code of X. Search the descriptors for that hash code
3307 to see if any of them describes X. If yes, the descriptor records
3308 the label number already assigned. */
3310 hash = const_hash_rtx (mode, x);
3312 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3313 if (compare_constant_rtx (mode, x, desc))
3315 found = desc->label;
3316 break;
3319 if (found == 0)
3321 register struct pool_constant *pool;
3322 register struct pool_sym *sym;
3323 int align;
3325 /* No constant equal to X is known to have been output.
3326 Make a constant descriptor to enter X in the hash table.
3327 Assign the label number and record it in the descriptor for
3328 future calls to this function to find. */
3330 desc = record_constant_rtx (mode, x);
3331 desc->next = const_rtx_hash_table[hash];
3332 const_rtx_hash_table[hash] = desc;
3334 /* Align the location counter as required by EXP's data type. */
3335 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3336 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3337 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3339 pool_offset += align - 1;
3340 pool_offset &= ~ (align - 1);
3342 /* If RTL is not being placed into the saveable obstack, make a
3343 copy of X that is in the saveable obstack in case we are being
3344 called from combine or some other phase that discards memory
3345 it allocates. We need only do this if it is a CONST, since
3346 no other RTX should be allocated in this situation. */
3347 if (rtl_obstack != saveable_obstack
3348 && GET_CODE (x) == CONST)
3350 push_obstacks_nochange ();
3351 rtl_in_saveable_obstack ();
3353 x = gen_rtx (CONST, GET_MODE (x),
3354 gen_rtx (PLUS, GET_MODE (x),
3355 XEXP (XEXP (x, 0), 0), XEXP (XEXP (x, 0), 1)));
3356 pop_obstacks ();
3359 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3361 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3362 pool->desc = desc;
3363 pool->constant = x;
3364 pool->mode = mode;
3365 pool->labelno = const_labelno;
3366 pool->align = align;
3367 pool->offset = pool_offset;
3368 pool->next = 0;
3370 if (last_pool == 0)
3371 first_pool = pool;
3372 else
3373 last_pool->next = pool;
3375 last_pool = pool;
3376 pool_offset += GET_MODE_SIZE (mode);
3378 /* Create a string containing the label name, in LABEL. */
3379 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3381 ++const_labelno;
3383 desc->label = found
3384 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3386 /* Add label to symbol hash table. */
3387 hash = SYMHASH (found);
3388 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3389 sym->label = found;
3390 sym->pool = pool;
3391 sym->next = const_rtx_sym_hash_table[hash];
3392 const_rtx_sym_hash_table[hash] = sym;
3395 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3397 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3399 RTX_UNCHANGING_P (def) = 1;
3400 /* Mark the symbol_ref as belonging to this constants pool. */
3401 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3402 current_function_uses_const_pool = 1;
3404 if (outer_function_chain == 0)
3405 if (GET_CODE (x) == CONST_DOUBLE)
3407 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3409 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3410 const_double_chain = x;
3412 CONST_DOUBLE_MEM (x) = def;
3415 return def;
3418 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3419 the corresponding pool_constant structure. */
3421 static struct pool_constant *
3422 find_pool_constant (addr)
3423 rtx addr;
3425 struct pool_sym *sym;
3426 char *label = XSTR (addr, 0);
3428 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3429 if (sym->label == label)
3430 return sym->pool;
3432 abort ();
3435 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3438 get_pool_constant (addr)
3439 rtx addr;
3441 return (find_pool_constant (addr))->constant;
3444 /* Similar, return the mode. */
3446 enum machine_mode
3447 get_pool_mode (addr)
3448 rtx addr;
3450 return (find_pool_constant (addr))->mode;
3453 /* Similar, return the offset in the constant pool. */
3456 get_pool_offset (addr)
3457 rtx addr;
3459 return (find_pool_constant (addr))->offset;
3462 /* Return the size of the constant pool. */
3465 get_pool_size ()
3467 return pool_offset;
3470 /* Write all the constants in the constant pool. */
3472 void
3473 output_constant_pool (fnname, fndecl)
3474 char *fnname;
3475 tree fndecl;
3477 struct pool_constant *pool;
3478 rtx x;
3479 union real_extract u;
3481 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3482 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3483 #endif
3485 for (pool = first_pool; pool; pool = pool->next)
3487 x = pool->constant;
3489 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3490 whose CODE_LABEL has been deleted. This can occur if a jump table
3491 is eliminated by optimization. If so, write a constant of zero
3492 instead. Note that this can also happen by turning the
3493 CODE_LABEL into a NOTE. */
3494 if (((GET_CODE (x) == LABEL_REF
3495 && (INSN_DELETED_P (XEXP (x, 0))
3496 || GET_CODE (XEXP (x, 0)) == NOTE)))
3497 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3498 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3499 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3500 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3501 x = const0_rtx;
3503 /* First switch to correct section. */
3504 #ifdef SELECT_RTX_SECTION
3505 SELECT_RTX_SECTION (pool->mode, x);
3506 #else
3507 readonly_data_section ();
3508 #endif
3510 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3511 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3512 pool->align, pool->labelno, done);
3513 #endif
3515 if (pool->align > 1)
3516 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3518 /* Output the label. */
3519 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3521 /* Output the value of the constant itself. */
3522 switch (GET_MODE_CLASS (pool->mode))
3524 case MODE_FLOAT:
3525 if (GET_CODE (x) != CONST_DOUBLE)
3526 abort ();
3528 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3529 assemble_real (u.d, pool->mode);
3530 break;
3532 case MODE_INT:
3533 case MODE_PARTIAL_INT:
3534 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3535 break;
3537 default:
3538 abort ();
3541 done: ;
3544 /* Done with this pool. */
3545 first_pool = last_pool = 0;
3548 /* Find all the constants whose addresses are referenced inside of EXP,
3549 and make sure assembler code with a label has been output for each one.
3550 Indicate whether an ADDR_EXPR has been encountered. */
3552 static int
3553 output_addressed_constants (exp)
3554 tree exp;
3556 int reloc = 0;
3558 switch (TREE_CODE (exp))
3560 case ADDR_EXPR:
3562 register tree constant = TREE_OPERAND (exp, 0);
3564 while (TREE_CODE (constant) == COMPONENT_REF)
3566 constant = TREE_OPERAND (constant, 0);
3569 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3570 || TREE_CODE (constant) == CONSTRUCTOR)
3571 /* No need to do anything here
3572 for addresses of variables or functions. */
3573 output_constant_def (constant);
3575 reloc = 1;
3576 break;
3578 case PLUS_EXPR:
3579 case MINUS_EXPR:
3580 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3581 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3582 break;
3584 case NOP_EXPR:
3585 case CONVERT_EXPR:
3586 case NON_LVALUE_EXPR:
3587 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3588 break;
3590 case CONSTRUCTOR:
3592 register tree link;
3593 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3594 if (TREE_VALUE (link) != 0)
3595 reloc |= output_addressed_constants (TREE_VALUE (link));
3597 break;
3599 case ERROR_MARK:
3600 break;
3602 return reloc;
3605 /* Output assembler code for constant EXP to FILE, with no label.
3606 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3607 Assumes output_addressed_constants has been done on EXP already.
3609 Generate exactly SIZE bytes of assembler data, padding at the end
3610 with zeros if necessary. SIZE must always be specified.
3612 SIZE is important for structure constructors,
3613 since trailing members may have been omitted from the constructor.
3614 It is also important for initialization of arrays from string constants
3615 since the full length of the string constant might not be wanted.
3616 It is also needed for initialization of unions, where the initializer's
3617 type is just one member, and that may not be as long as the union.
3619 There a case in which we would fail to output exactly SIZE bytes:
3620 for a structure constructor that wants to produce more than SIZE bytes.
3621 But such constructors will never be generated for any possible input. */
3623 void
3624 output_constant (exp, size)
3625 register tree exp;
3626 register int size;
3628 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3629 rtx x;
3631 if (size == 0)
3632 return;
3634 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3635 That way we get the constant (we hope) inside it. Also, strip off any
3636 NOP_EXPR that converts between two record, union, array, or set types. */
3637 while ((TREE_CODE (exp) == NOP_EXPR
3638 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3639 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
3640 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3641 exp = TREE_OPERAND (exp, 0);
3643 /* Allow a constructor with no elements for any data type.
3644 This means to fill the space with zeros. */
3645 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3647 if (output_bytecode)
3648 bc_emit_const_skip (size);
3649 else
3650 assemble_zeros (size);
3651 return;
3654 switch (code)
3656 case CHAR_TYPE:
3657 case BOOLEAN_TYPE:
3658 case INTEGER_TYPE:
3659 case ENUMERAL_TYPE:
3660 case POINTER_TYPE:
3661 case REFERENCE_TYPE:
3662 /* ??? What about (int)((float)(int)&foo + 4) */
3663 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3664 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3665 exp = TREE_OPERAND (exp, 0);
3667 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3668 EXPAND_INITIALIZER),
3669 size, 0))
3670 error ("initializer for integer value is too complicated");
3671 size = 0;
3672 break;
3674 case REAL_TYPE:
3675 if (TREE_CODE (exp) != REAL_CST)
3676 error ("initializer for floating value is not a floating constant");
3678 assemble_real (TREE_REAL_CST (exp),
3679 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3680 size = 0;
3681 break;
3683 case COMPLEX_TYPE:
3684 output_constant (TREE_REALPART (exp), size / 2);
3685 output_constant (TREE_IMAGPART (exp), size / 2);
3686 size -= (size / 2) * 2;
3687 break;
3689 case ARRAY_TYPE:
3690 if (TREE_CODE (exp) == CONSTRUCTOR)
3692 output_constructor (exp, size);
3693 return;
3695 else if (TREE_CODE (exp) == STRING_CST)
3697 int excess = 0;
3699 if (size > TREE_STRING_LENGTH (exp))
3701 excess = size - TREE_STRING_LENGTH (exp);
3702 size = TREE_STRING_LENGTH (exp);
3705 assemble_string (TREE_STRING_POINTER (exp), size);
3706 size = excess;
3708 else
3709 abort ();
3710 break;
3712 case RECORD_TYPE:
3713 case UNION_TYPE:
3714 if (TREE_CODE (exp) == CONSTRUCTOR)
3715 output_constructor (exp, size);
3716 else
3717 abort ();
3718 return;
3720 case SET_TYPE:
3721 if (TREE_CODE (exp) == INTEGER_CST)
3722 assemble_integer (expand_expr (exp, NULL_RTX,
3723 VOIDmode, EXPAND_INITIALIZER),
3724 size, 1);
3725 else if (TREE_CODE (exp) == CONSTRUCTOR)
3727 unsigned char *buffer = (unsigned char *) alloca (size);
3728 if (get_set_constructor_bytes (exp, buffer, size))
3729 abort ();
3730 assemble_string ((char *) buffer, size);
3732 else
3733 error ("unknown set constructor type");
3734 return;
3737 if (size > 0)
3738 assemble_zeros (size);
3741 /* Bytecode specific code to output assembler for integer. */
3743 static void
3744 bc_assemble_integer (exp, size)
3745 tree exp;
3746 int size;
3748 tree const_part;
3749 tree addr_part;
3750 tree tmp;
3752 /* FIXME: is this fold() business going to be as good as the
3753 expand_expr() using EXPAND_SUM above in the RTL case? I
3754 hate RMS.
3755 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3757 exp = fold (exp);
3759 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3760 exp = TREE_OPERAND (exp, 0);
3761 if (TREE_CODE (exp) == INTEGER_CST)
3763 const_part = exp;
3764 addr_part = 0;
3766 else if (TREE_CODE (exp) == PLUS_EXPR)
3768 const_part = TREE_OPERAND (exp, 0);
3769 while (TREE_CODE (const_part) == NOP_EXPR
3770 || TREE_CODE (const_part) == CONVERT_EXPR)
3771 const_part = TREE_OPERAND (const_part, 0);
3772 addr_part = TREE_OPERAND (exp, 1);
3773 while (TREE_CODE (addr_part) == NOP_EXPR
3774 || TREE_CODE (addr_part) == CONVERT_EXPR)
3775 addr_part = TREE_OPERAND (addr_part, 0);
3776 if (TREE_CODE (const_part) != INTEGER_CST)
3777 tmp = const_part, const_part = addr_part, addr_part = tmp;
3778 if (TREE_CODE (const_part) != INTEGER_CST
3779 || TREE_CODE (addr_part) != ADDR_EXPR)
3780 abort (); /* FIXME: we really haven't considered
3781 all the possible cases here. */
3783 else if (TREE_CODE (exp) == ADDR_EXPR)
3785 const_part = integer_zero_node;
3786 addr_part = exp;
3788 else
3789 abort (); /* FIXME: ditto previous. */
3791 if (addr_part == 0)
3793 if (size == 1)
3795 char c = TREE_INT_CST_LOW (const_part);
3796 bc_emit (&c, 1);
3797 size -= 1;
3799 else if (size == 2)
3801 short s = TREE_INT_CST_LOW (const_part);
3802 bc_emit ((char *) &s, 2);
3803 size -= 2;
3805 else if (size == 4)
3807 int i = TREE_INT_CST_LOW (const_part);
3808 bc_emit ((char *) &i, 4);
3809 size -= 4;
3811 else if (size == 8)
3813 if (WORDS_BIG_ENDIAN)
3815 int i = TREE_INT_CST_HIGH (const_part);
3816 bc_emit ((char *) &i, 4);
3817 i = TREE_INT_CST_LOW (const_part);
3818 bc_emit ((char *) &i, 4);
3820 else
3822 int i = TREE_INT_CST_LOW (const_part);
3823 bc_emit ((char *) &i, 4);
3824 i = TREE_INT_CST_HIGH (const_part);
3825 bc_emit ((char *) &i, 4);
3827 size -= 8;
3830 else
3831 if (size == 4
3832 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3833 bc_emit_labelref (IDENTIFIER_POINTER
3834 (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0))),
3835 TREE_INT_CST_LOW (const_part));
3836 else
3837 abort (); /* FIXME: there may be more cases. */
3840 /* Subroutine of output_constant, used for CONSTRUCTORs
3841 (aggregate constants).
3842 Generate at least SIZE bytes, padding if necessary. */
3844 static void
3845 output_constructor (exp, size)
3846 tree exp;
3847 int size;
3849 register tree link, field = 0;
3850 HOST_WIDE_INT min_index = 0;
3851 /* Number of bytes output or skipped so far.
3852 In other words, current position within the constructor. */
3853 int total_bytes = 0;
3854 /* Non-zero means BYTE contains part of a byte, to be output. */
3855 int byte_buffer_in_use = 0;
3856 register int byte;
3858 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3859 abort ();
3861 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3862 field = TYPE_FIELDS (TREE_TYPE (exp));
3864 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3865 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3866 min_index
3867 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3869 /* As LINK goes through the elements of the constant,
3870 FIELD goes through the structure fields, if the constant is a structure.
3871 if the constant is a union, then we override this,
3872 by getting the field from the TREE_LIST element.
3873 But the constant could also be an array. Then FIELD is zero. */
3874 for (link = CONSTRUCTOR_ELTS (exp);
3875 link;
3876 link = TREE_CHAIN (link),
3877 field = field ? TREE_CHAIN (field) : 0)
3879 tree val = TREE_VALUE (link);
3880 tree index = 0;
3882 /* the element in a union constructor specifies the proper field. */
3884 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3885 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3887 /* if available, use the type given by link */
3888 if (TREE_PURPOSE (link) != 0)
3889 field = TREE_PURPOSE (link);
3892 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3893 index = TREE_PURPOSE (link);
3895 /* Eliminate the marker that makes a cast not be an lvalue. */
3896 if (val != 0)
3897 STRIP_NOPS (val);
3899 if (field == 0 || !DECL_BIT_FIELD (field))
3901 /* An element that is not a bit-field. */
3903 register int fieldsize;
3904 /* Since this structure is static,
3905 we know the positions are constant. */
3906 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3907 / BITS_PER_UNIT)
3908 : 0);
3909 if (index != 0)
3910 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3911 / BITS_PER_UNIT
3912 * (TREE_INT_CST_LOW (index) - min_index));
3914 /* Output any buffered-up bit-fields preceding this element. */
3915 if (byte_buffer_in_use)
3917 ASM_OUTPUT_BYTE (asm_out_file, byte);
3918 total_bytes++;
3919 byte_buffer_in_use = 0;
3922 /* Advance to offset of this element.
3923 Note no alignment needed in an array, since that is guaranteed
3924 if each element has the proper size. */
3925 if ((field != 0 || index != 0) && bitpos != total_bytes)
3927 if (!output_bytecode)
3928 assemble_zeros (bitpos - total_bytes);
3929 else
3930 bc_emit_const_skip (bitpos - total_bytes);
3931 total_bytes = bitpos;
3934 /* Determine size this element should occupy. */
3935 if (field)
3937 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3938 abort ();
3939 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3941 /* This avoids overflow trouble. */
3942 tree size_tree = size_binop (CEIL_DIV_EXPR,
3943 DECL_SIZE (field),
3944 size_int (BITS_PER_UNIT));
3945 fieldsize = TREE_INT_CST_LOW (size_tree);
3947 else
3949 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3950 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3953 else
3954 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3956 /* Output the element's initial value. */
3957 if (val == 0)
3958 assemble_zeros (fieldsize);
3959 else
3960 output_constant (val, fieldsize);
3962 /* Count its size. */
3963 total_bytes += fieldsize;
3965 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3966 error ("invalid initial value for member `%s'",
3967 IDENTIFIER_POINTER (DECL_NAME (field)));
3968 else
3970 /* Element that is a bit-field. */
3972 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3973 int end_offset
3974 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3976 if (val == 0)
3977 val = integer_zero_node;
3979 /* If this field does not start in this (or, next) byte,
3980 skip some bytes. */
3981 if (next_offset / BITS_PER_UNIT != total_bytes)
3983 /* Output remnant of any bit field in previous bytes. */
3984 if (byte_buffer_in_use)
3986 ASM_OUTPUT_BYTE (asm_out_file, byte);
3987 total_bytes++;
3988 byte_buffer_in_use = 0;
3991 /* If still not at proper byte, advance to there. */
3992 if (next_offset / BITS_PER_UNIT != total_bytes)
3994 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3995 total_bytes = next_offset / BITS_PER_UNIT;
3999 if (! byte_buffer_in_use)
4000 byte = 0;
4002 /* We must split the element into pieces that fall within
4003 separate bytes, and combine each byte with previous or
4004 following bit-fields. */
4006 /* next_offset is the offset n fbits from the beginning of
4007 the structure to the next bit of this element to be processed.
4008 end_offset is the offset of the first bit past the end of
4009 this element. */
4010 while (next_offset < end_offset)
4012 int this_time;
4013 int shift;
4014 HOST_WIDE_INT value;
4015 int next_byte = next_offset / BITS_PER_UNIT;
4016 int next_bit = next_offset % BITS_PER_UNIT;
4018 /* Advance from byte to byte
4019 within this element when necessary. */
4020 while (next_byte != total_bytes)
4022 ASM_OUTPUT_BYTE (asm_out_file, byte);
4023 total_bytes++;
4024 byte = 0;
4027 /* Number of bits we can process at once
4028 (all part of the same byte). */
4029 this_time = MIN (end_offset - next_offset,
4030 BITS_PER_UNIT - next_bit);
4031 if (BYTES_BIG_ENDIAN)
4033 /* On big-endian machine, take the most significant bits
4034 first (of the bits that are significant)
4035 and put them into bytes from the most significant end. */
4036 shift = end_offset - next_offset - this_time;
4037 /* Don't try to take a bunch of bits that cross
4038 the word boundary in the INTEGER_CST. */
4039 if (shift < HOST_BITS_PER_WIDE_INT
4040 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4042 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4043 shift = HOST_BITS_PER_WIDE_INT;
4046 /* Now get the bits from the appropriate constant word. */
4047 if (shift < HOST_BITS_PER_WIDE_INT)
4049 value = TREE_INT_CST_LOW (val);
4051 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4053 value = TREE_INT_CST_HIGH (val);
4054 shift -= HOST_BITS_PER_WIDE_INT;
4056 else
4057 abort ();
4058 byte |= (((value >> shift)
4059 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4060 << (BITS_PER_UNIT - this_time - next_bit));
4062 else
4064 /* On little-endian machines,
4065 take first the least significant bits of the value
4066 and pack them starting at the least significant
4067 bits of the bytes. */
4068 shift = (next_offset
4069 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
4070 /* Don't try to take a bunch of bits that cross
4071 the word boundary in the INTEGER_CST. */
4072 if (shift < HOST_BITS_PER_WIDE_INT
4073 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4075 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
4076 shift = HOST_BITS_PER_WIDE_INT;
4079 /* Now get the bits from the appropriate constant word. */
4080 if (shift < HOST_BITS_PER_INT)
4081 value = TREE_INT_CST_LOW (val);
4082 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4084 value = TREE_INT_CST_HIGH (val);
4085 shift -= HOST_BITS_PER_WIDE_INT;
4087 else
4088 abort ();
4089 byte |= (((value >> shift)
4090 & (((HOST_WIDE_INT) 1 << this_time) - 1))
4091 << next_bit);
4093 next_offset += this_time;
4094 byte_buffer_in_use = 1;
4098 if (byte_buffer_in_use)
4100 ASM_OUTPUT_BYTE (asm_out_file, byte);
4101 total_bytes++;
4103 if (total_bytes < size)
4104 assemble_zeros (size - total_bytes);
4107 /* Output asm to handle ``#pragma weak'' */
4108 void
4109 handle_pragma_weak (what, name, value)
4110 enum pragma_state what;
4111 char *name, *value;
4113 #ifdef HANDLE_PRAGMA_WEAK
4114 if (what == ps_name || what == ps_value)
4116 struct weak_syms *weak =
4117 (struct weak_syms *)permalloc (sizeof (struct weak_syms));
4118 weak->next = weak_decls;
4119 weak->name = permalloc (strlen (name) + 1);
4120 strcpy (weak->name, name);
4122 if (what != ps_value)
4123 weak->value = NULL_PTR;
4125 else
4127 weak->value = permalloc (strlen (value) + 1);
4128 strcpy (weak->value, value);
4131 weak_decls = weak;
4133 else if (! (what == ps_done || what == ps_start))
4134 warning ("malformed `#pragma weak'");
4135 #endif /* HANDLE_PRAGMA_WEAK */
4138 /* Declare DECL to be a weak symbol. */
4140 void
4141 declare_weak (decl)
4142 tree decl;
4144 if (! TREE_PUBLIC (decl))
4145 error_with_decl (decl, "weak declaration of `%s' must be public");
4146 else if (TREE_ASM_WRITTEN (decl))
4147 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4148 else if (SUPPORTS_WEAK)
4149 DECL_WEAK (decl) = 1;
4152 /* Emit any pending weak declarations. */
4154 void
4155 weak_finish ()
4157 #ifdef HANDLE_PRAGMA_WEAK
4158 if (HANDLE_PRAGMA_WEAK)
4160 struct weak_syms *t;
4161 for (t = weak_decls; t; t = t->next)
4163 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4164 if (t->value)
4165 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4168 #endif
4171 void
4172 assemble_alias (decl, target)
4173 tree decl, target;
4175 #ifdef ASM_OUTPUT_DEF
4176 char *name;
4178 make_decl_rtl (decl, (char*)0, 1);
4179 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4181 /* Make name accessible from other files, if appropriate. */
4183 if (TREE_PUBLIC (decl))
4185 #ifdef ASM_WEAKEN_LABEL
4186 if (DECL_WEAK (decl))
4187 ASM_WEAKEN_LABEL (asm_out_file, name);
4188 else
4189 #endif
4190 if (output_bytecode)
4191 BC_GLOBALIZE_LABEL (asm_out_file, name);
4192 else
4193 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4196 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4197 TREE_ASM_WRITTEN (decl) = 1;
4198 #else
4199 warning ("alias definitions not supported in this configuration");
4200 #endif