Changes add TABs on either or both sides, covering start of line,
[gcc.git] / gcc / varasm.c
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997,
3 1998, 1999, 2000 Free Software Foundation, Inc.
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
21
22
23 /* This file handles generation of all the assembler code
24 *except* the instructions of a function.
25 This includes declarations of variables and their initial values.
26
27 We also output the assembler code for constants stored in memory
28 and are responsible for combining constants with the same value. */
29
30 #include "config.h"
31 #include "system.h"
32 #include <setjmp.h>
33 #include "rtl.h"
34 #include "tree.h"
35 #include "flags.h"
36 #include "function.h"
37 #include "expr.h"
38 #include "hard-reg-set.h"
39 #include "regs.h"
40 #include "defaults.h"
41 #include "output.h"
42 #include "real.h"
43 #include "toplev.h"
44 #include "dbxout.h"
45 #include "sdbout.h"
46 #include "obstack.h"
47 #include "c-pragma.h"
48 #include "ggc.h"
49 #include "tm_p.h"
50
51 #ifdef XCOFF_DEBUGGING_INFO
52 #include "xcoffout.h"
53 #endif
54
55 #ifndef TRAMPOLINE_ALIGNMENT
56 #define TRAMPOLINE_ALIGNMENT FUNCTION_BOUNDARY
57 #endif
58
59 #ifndef ASM_STABS_OP
60 #define ASM_STABS_OP "\t.stabs\t"
61 #endif
62
63 /* Define the prefix to use when check_memory_usage_flag is enable. */
64 #ifdef NO_DOLLAR_IN_LABEL
65 #ifdef NO_DOT_IN_LABEL
66 #define CHKR_PREFIX "chkr_prefix_"
67 #else /* !NO_DOT_IN_LABEL */
68 #define CHKR_PREFIX "chkr."
69 #endif
70 #else /* !NO_DOLLAR_IN_LABEL */
71 #define CHKR_PREFIX "chkr$"
72 #endif
73 #define CHKR_PREFIX_SIZE (sizeof (CHKR_PREFIX) - 1)
74
75 /* File in which assembler code is being written. */
76
77 extern FILE *asm_out_file;
78
79 /* The (assembler) name of the first globally-visible object output. */
80 const char *first_global_object_name;
81 const char *weak_global_object_name;
82
83 extern struct obstack *current_obstack;
84 extern struct obstack *saveable_obstack;
85 extern struct obstack *rtl_obstack;
86 extern struct obstack permanent_obstack;
87 #define obstack_chunk_alloc xmalloc
88
89 struct addr_const;
90 struct constant_descriptor;
91 struct rtx_const;
92 struct pool_constant;
93
94 #define MAX_RTX_HASH_TABLE 61
95
96 struct varasm_status
97 {
98 /* Hash facility for making memory-constants
99 from constant rtl-expressions. It is used on RISC machines
100 where immediate integer arguments and constant addresses are restricted
101 so that such constants must be stored in memory.
102
103 This pool of constants is reinitialized for each function
104 so each function gets its own constants-pool that comes right before
105 it. */
106 struct constant_descriptor **x_const_rtx_hash_table;
107 struct pool_sym **x_const_rtx_sym_hash_table;
108
109 /* Pointers to first and last constant in pool. */
110 struct pool_constant *x_first_pool, *x_last_pool;
111
112 /* Current offset in constant pool (does not include any machine-specific
113 header. */
114 int x_pool_offset;
115
116 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
117 They are chained through the CONST_DOUBLE_CHAIN.
118 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
119 In that case, CONST_DOUBLE_MEM is either a MEM,
120 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet. */
121 rtx x_const_double_chain;
122 };
123
124 #define const_rtx_hash_table (cfun->varasm->x_const_rtx_hash_table)
125 #define const_rtx_sym_hash_table (cfun->varasm->x_const_rtx_sym_hash_table)
126 #define first_pool (cfun->varasm->x_first_pool)
127 #define last_pool (cfun->varasm->x_last_pool)
128 #define pool_offset (cfun->varasm->x_pool_offset)
129 #define const_double_chain (cfun->varasm->x_const_double_chain)
130
131 /* Number for making the label on the next
132 constant that is stored in memory. */
133
134 int const_labelno;
135
136 /* Number for making the label on the next
137 static variable internal to a function. */
138
139 int var_labelno;
140
141 /* Carry information from ASM_DECLARE_OBJECT_NAME
142 to ASM_FINISH_DECLARE_OBJECT. */
143
144 int size_directive_output;
145
146 /* The last decl for which assemble_variable was called,
147 if it did ASM_DECLARE_OBJECT_NAME.
148 If the last call to assemble_variable didn't do that,
149 this holds 0. */
150
151 tree last_assemble_variable_decl;
152
153 static const char *strip_reg_name PARAMS ((const char *));
154 static int contains_pointers_p PARAMS ((tree));
155 static void decode_addr_const PARAMS ((tree, struct addr_const *));
156 static int const_hash PARAMS ((tree));
157 static int compare_constant PARAMS ((tree,
158 struct constant_descriptor *));
159 static const unsigned char *compare_constant_1 PARAMS ((tree, const unsigned char *));
160 static struct constant_descriptor *record_constant PARAMS ((tree));
161 static void record_constant_1 PARAMS ((tree));
162 static tree copy_constant PARAMS ((tree));
163 static void output_constant_def_contents PARAMS ((tree, int, int));
164 static void decode_rtx_const PARAMS ((enum machine_mode, rtx,
165 struct rtx_const *));
166 static int const_hash_rtx PARAMS ((enum machine_mode, rtx));
167 static int compare_constant_rtx PARAMS ((enum machine_mode, rtx,
168 struct constant_descriptor *));
169 static struct constant_descriptor *record_constant_rtx PARAMS ((enum machine_mode,
170 rtx));
171 static struct pool_constant *find_pool_constant PARAMS ((struct function *, rtx));
172 static void mark_constant_pool PARAMS ((void));
173 static void mark_constants PARAMS ((rtx));
174 static int output_addressed_constants PARAMS ((tree));
175 static void output_after_function_constants PARAMS ((void));
176 static void output_constructor PARAMS ((tree, int));
177 #ifdef ASM_WEAKEN_LABEL
178 static void remove_from_pending_weak_list PARAMS ((const char *));
179 #endif
180 #ifdef ASM_OUTPUT_BSS
181 static void asm_output_bss PARAMS ((FILE *, tree, const char *, int, int));
182 #endif
183 #ifdef BSS_SECTION_ASM_OP
184 #ifdef ASM_OUTPUT_ALIGNED_BSS
185 static void asm_output_aligned_bss PARAMS ((FILE *, tree, const char *,
186 int, int));
187 #endif
188 #endif /* BSS_SECTION_ASM_OP */
189 static void mark_pool_constant PARAMS ((struct pool_constant *));
190 static void mark_pool_sym_hash_table PARAMS ((struct pool_sym **));
191 static void mark_const_hash_entry PARAMS ((void *));
192 static void asm_emit_uninitialised PARAMS ((tree, const char*, int, int));
193 \f
194 static enum in_section { no_section, in_text, in_data, in_named
195 #ifdef BSS_SECTION_ASM_OP
196 , in_bss
197 #endif
198 #ifdef EH_FRAME_SECTION_ASM_OP
199 , in_eh_frame
200 #endif
201 #ifdef EXTRA_SECTIONS
202 , EXTRA_SECTIONS
203 #endif
204 } in_section = no_section;
205
206 /* Return a non-zero value if DECL has a section attribute. */
207 #ifndef IN_NAMED_SECTION
208 #define IN_NAMED_SECTION(DECL) \
209 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
210 && DECL_SECTION_NAME (DECL) != NULL_TREE)
211 #endif
212
213 /* Text of section name when in_section == in_named. */
214 static char *in_named_name;
215
216 /* Define functions like text_section for any extra sections. */
217 #ifdef EXTRA_SECTION_FUNCTIONS
218 EXTRA_SECTION_FUNCTIONS
219 #endif
220
221 /* Tell assembler to switch to text section. */
222
223 void
224 text_section ()
225 {
226 if (in_section != in_text)
227 {
228 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
229 in_section = in_text;
230 }
231 }
232
233 /* Tell assembler to switch to data section. */
234
235 void
236 data_section ()
237 {
238 if (in_section != in_data)
239 {
240 if (flag_shared_data)
241 {
242 #ifdef SHARED_SECTION_ASM_OP
243 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
244 #else
245 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
246 #endif
247 }
248 else
249 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
250
251 in_section = in_data;
252 }
253 }
254 /* Tell assembler to ALWAYS switch to data section, in case
255 it's not sure where it it. */
256
257 void
258 force_data_section ()
259 {
260 in_section = no_section;
261 data_section ();
262 }
263
264 /* Tell assembler to switch to read-only data section. This is normally
265 the text section. */
266
267 void
268 readonly_data_section ()
269 {
270 #ifdef READONLY_DATA_SECTION
271 READONLY_DATA_SECTION (); /* Note this can call data_section. */
272 #else
273 text_section ();
274 #endif
275 }
276
277 /* Determine if we're in the text section. */
278
279 int
280 in_text_section ()
281 {
282 return in_section == in_text;
283 }
284
285 /* Determine if we're in the data section. */
286
287 int
288 in_data_section ()
289 {
290 return in_section == in_data;
291 }
292
293 /* Tell assembler to change to section NAME for DECL.
294 If DECL is NULL, just switch to section NAME.
295 If NAME is NULL, get the name from DECL.
296 If RELOC is 1, the initializer for DECL contains relocs. */
297
298 void
299 named_section (decl, name, reloc)
300 tree decl;
301 const char *name;
302 int reloc ATTRIBUTE_UNUSED;
303 {
304 if (decl != NULL_TREE && !DECL_P (decl))
305 abort ();
306 if (name == NULL)
307 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
308
309 if (in_section != in_named || strcmp (name, in_named_name))
310 {
311 #ifdef ASM_OUTPUT_SECTION_NAME
312 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name, reloc);
313 #else
314 /* Section attributes are not supported if this macro isn't provided -
315 some host formats don't support them at all. The front-end should
316 already have flagged this as an error. */
317 abort ();
318 #endif
319
320 in_named_name = ggc_alloc_string (name, -1);
321 in_section = in_named;
322 }
323 }
324
325 #ifdef ASM_OUTPUT_SECTION_NAME
326 #ifndef UNIQUE_SECTION
327 #define UNIQUE_SECTION(DECL,RELOC) \
328 do { \
329 int len; \
330 const char *name; \
331 char *string; \
332 \
333 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL)); \
334 /* Strip off any encoding in name. */ \
335 STRIP_NAME_ENCODING (name, name); \
336 \
337 len = strlen (name) + 1; \
338 string = alloca (len + 1); \
339 sprintf (string, ".%s", name); \
340 \
341 DECL_SECTION_NAME (DECL) = build_string (len, string); \
342 } while (0)
343 #endif
344 #ifndef UNIQUE_SECTION_P
345 #define UNIQUE_SECTION_P(DECL) 0
346 #endif
347 #endif
348
349 #ifdef BSS_SECTION_ASM_OP
350
351 /* Tell the assembler to switch to the bss section. */
352
353 void
354 bss_section ()
355 {
356 if (in_section != in_bss)
357 {
358 #ifdef SHARED_BSS_SECTION_ASM_OP
359 if (flag_shared_data)
360 fprintf (asm_out_file, "%s\n", SHARED_BSS_SECTION_ASM_OP);
361 else
362 #endif
363 fprintf (asm_out_file, "%s\n", BSS_SECTION_ASM_OP);
364
365 in_section = in_bss;
366 }
367 }
368
369 #ifdef ASM_OUTPUT_BSS
370
371 /* Utility function for ASM_OUTPUT_BSS for targets to use if
372 they don't support alignments in .bss.
373 ??? It is believed that this function will work in most cases so such
374 support is localized here. */
375
376 static void
377 asm_output_bss (file, decl, name, size, rounded)
378 FILE *file;
379 tree decl ATTRIBUTE_UNUSED;
380 const char *name;
381 int size ATTRIBUTE_UNUSED, rounded;
382 {
383 ASM_GLOBALIZE_LABEL (file, name);
384 bss_section ();
385 #ifdef ASM_DECLARE_OBJECT_NAME
386 last_assemble_variable_decl = decl;
387 ASM_DECLARE_OBJECT_NAME (file, name, decl);
388 #else
389 /* Standard thing is just output label for the object. */
390 ASM_OUTPUT_LABEL (file, name);
391 #endif /* ASM_DECLARE_OBJECT_NAME */
392 ASM_OUTPUT_SKIP (file, rounded);
393 }
394
395 #endif
396
397 #ifdef ASM_OUTPUT_ALIGNED_BSS
398
399 /* Utility function for targets to use in implementing
400 ASM_OUTPUT_ALIGNED_BSS.
401 ??? It is believed that this function will work in most cases so such
402 support is localized here. */
403
404 static void
405 asm_output_aligned_bss (file, decl, name, size, align)
406 FILE *file;
407 tree decl;
408 const char *name;
409 int size, align;
410 {
411 ASM_GLOBALIZE_LABEL (file, name);
412 bss_section ();
413 ASM_OUTPUT_ALIGN (file, floor_log2 (align / BITS_PER_UNIT));
414 #ifdef ASM_DECLARE_OBJECT_NAME
415 last_assemble_variable_decl = decl;
416 ASM_DECLARE_OBJECT_NAME (file, name, decl);
417 #else
418 /* Standard thing is just output label for the object. */
419 ASM_OUTPUT_LABEL (file, name);
420 #endif /* ASM_DECLARE_OBJECT_NAME */
421 ASM_OUTPUT_SKIP (file, size ? size : 1);
422 }
423
424 #endif
425
426 #endif /* BSS_SECTION_ASM_OP */
427
428 #ifdef EH_FRAME_SECTION_ASM_OP
429 void
430 eh_frame_section ()
431 {
432 if (in_section != in_eh_frame)
433 {
434 fprintf (asm_out_file, "%s\n", EH_FRAME_SECTION_ASM_OP);
435 in_section = in_eh_frame;
436 }
437 }
438 #endif
439
440 /* Switch to the section for function DECL.
441
442 If DECL is NULL_TREE, switch to the text section.
443 ??? It's not clear that we will ever be passed NULL_TREE, but it's
444 safer to handle it. */
445
446 void
447 function_section (decl)
448 tree decl;
449 {
450 if (decl != NULL_TREE
451 && DECL_SECTION_NAME (decl) != NULL_TREE)
452 named_section (decl, (char *) 0, 0);
453 else
454 text_section ();
455 }
456
457 /* Switch to section for variable DECL.
458
459 RELOC is the `reloc' argument to SELECT_SECTION. */
460
461 void
462 variable_section (decl, reloc)
463 tree decl;
464 int reloc;
465 {
466 if (IN_NAMED_SECTION (decl))
467 named_section (decl, NULL, reloc);
468 else
469 {
470 /* C++ can have const variables that get initialized from constructors,
471 and thus can not be in a readonly section. We prevent this by
472 verifying that the initial value is constant for objects put in a
473 readonly section.
474
475 error_mark_node is used by the C front end to indicate that the
476 initializer has not been seen yet. In this case, we assume that
477 the initializer must be constant.
478
479 C++ uses error_mark_node for variables that have complicated
480 initializers, but these variables go in BSS so we won't be called
481 for them. */
482
483 #ifdef SELECT_SECTION
484 SELECT_SECTION (decl, reloc);
485 #else
486 if (DECL_READONLY_SECTION (decl, reloc))
487 readonly_data_section ();
488 else
489 data_section ();
490 #endif
491 }
492 }
493
494 /* Tell assembler to switch to the section for the exception handling
495 table. */
496
497 void
498 exception_section ()
499 {
500 #if defined (EXCEPTION_SECTION)
501 EXCEPTION_SECTION ();
502 #else
503 #ifdef ASM_OUTPUT_SECTION_NAME
504 named_section (NULL_TREE, ".gcc_except_table", 0);
505 #else
506 if (flag_pic)
507 data_section ();
508 else
509 readonly_data_section ();
510 #endif
511 #endif
512 }
513 \f
514 /* Create the rtl to represent a function, for a function definition.
515 DECL is a FUNCTION_DECL node which describes which function.
516 The rtl is stored into DECL. */
517
518 void
519 make_function_rtl (decl)
520 tree decl;
521 {
522 const char *name;
523 const char *new_name;
524
525 if (DECL_RTL (decl) != 0)
526 {
527 /* ??? Another way to do this would be to do what halfpic.c does
528 and maintain a hashed table of such critters. */
529 /* ??? Another way to do this would be to pass a flag bit to
530 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
531 /* Let the target reassign the RTL if it wants.
532 This is necessary, for example, when one machine specific
533 decl attribute overrides another. */
534 #ifdef REDO_SECTION_INFO_P
535 if (REDO_SECTION_INFO_P (decl))
536 ENCODE_SECTION_INFO (decl);
537 #endif
538 return;
539 }
540
541 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
542 new_name = name;
543
544 /* Rename a nested function to avoid conflicts, unless it's a member of
545 a local class, in which case the class name is already unique. */
546 if (decl_function_context (decl) != 0
547 && ! TYPE_P (DECL_CONTEXT (decl))
548 && DECL_INITIAL (decl) != 0
549 && DECL_RTL (decl) == 0)
550 {
551 char *label;
552 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
553 var_labelno++;
554 new_name = label;
555 }
556 /* When -fprefix-function-name is used, every function name is
557 prefixed. Even static functions are prefixed because they
558 could be declared latter. Note that a nested function name
559 is not prefixed. */
560 else if (flag_prefix_function_name)
561 {
562 size_t name_len = IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl));
563 char *pname;
564
565 pname = alloca (name_len + CHKR_PREFIX_SIZE + 1);
566 memcpy (pname, CHKR_PREFIX, CHKR_PREFIX_SIZE);
567 memcpy (pname + CHKR_PREFIX_SIZE, name, name_len + 1);
568 new_name = pname;
569 }
570
571 if (name != new_name)
572 {
573 DECL_ASSEMBLER_NAME (decl) = get_identifier (new_name);
574 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
575 }
576
577 DECL_RTL (decl)
578 = gen_rtx_MEM (DECL_MODE (decl),
579 gen_rtx_SYMBOL_REF (Pmode, name));
580
581 /* Optionally set flags or add text to the name to record
582 information such as that it is a function name. If the name
583 is changed, the macro ASM_OUTPUT_LABELREF will have to know
584 how to strip this information. */
585 #ifdef ENCODE_SECTION_INFO
586 ENCODE_SECTION_INFO (decl);
587 #endif
588 }
589
590
591 /* Given NAME, a putative register name, discard any customary prefixes. */
592
593 static const char *
594 strip_reg_name (name)
595 const char *name;
596 {
597 #ifdef REGISTER_PREFIX
598 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
599 name += strlen (REGISTER_PREFIX);
600 #endif
601 if (name[0] == '%' || name[0] == '#')
602 name++;
603 return name;
604 }
605 \f
606 /* Decode an `asm' spec for a declaration as a register name.
607 Return the register number, or -1 if nothing specified,
608 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
609 or -3 if ASMSPEC is `cc' and is not recognized,
610 or -4 if ASMSPEC is `memory' and is not recognized.
611 Accept an exact spelling or a decimal number.
612 Prefixes such as % are optional. */
613
614 int
615 decode_reg_name (asmspec)
616 const char *asmspec;
617 {
618 if (asmspec != 0)
619 {
620 int i;
621
622 /* Get rid of confusing prefixes. */
623 asmspec = strip_reg_name (asmspec);
624
625 /* Allow a decimal number as a "register name". */
626 for (i = strlen (asmspec) - 1; i >= 0; i--)
627 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
628 break;
629 if (asmspec[0] != 0 && i < 0)
630 {
631 i = atoi (asmspec);
632 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
633 return i;
634 else
635 return -2;
636 }
637
638 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
639 if (reg_names[i][0]
640 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
641 return i;
642
643 #ifdef ADDITIONAL_REGISTER_NAMES
644 {
645 static struct { const char *name; int number; } table[]
646 = ADDITIONAL_REGISTER_NAMES;
647
648 for (i = 0; i < (int) ARRAY_SIZE (table); i++)
649 if (! strcmp (asmspec, table[i].name))
650 return table[i].number;
651 }
652 #endif /* ADDITIONAL_REGISTER_NAMES */
653
654 if (!strcmp (asmspec, "memory"))
655 return -4;
656
657 if (!strcmp (asmspec, "cc"))
658 return -3;
659
660 return -2;
661 }
662
663 return -1;
664 }
665 \f
666 /* Create the DECL_RTL for a declaration for a static or external variable
667 or static or external function.
668 ASMSPEC, if not 0, is the string which the user specified
669 as the assembler symbol name.
670 TOP_LEVEL is nonzero if this is a file-scope variable.
671
672 This is never called for PARM_DECL nodes. */
673
674 void
675 make_decl_rtl (decl, asmspec, top_level)
676 tree decl;
677 const char *asmspec;
678 int top_level;
679 {
680 const char *name = 0;
681 const char *new_name = 0;
682 int reg_number;
683
684 /* For a duplicate declaration, we can be called twice on the
685 same DECL node. Don't discard the RTL already made. */
686 if (DECL_RTL (decl) != 0)
687 {
688 /* If the old RTL had the wrong mode, fix the mode. */
689 if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
690 {
691 rtx rtl = DECL_RTL (decl);
692 PUT_MODE (rtl, DECL_MODE (decl));
693 }
694
695 /* ??? Another way to do this would be to do what halfpic.c does
696 and maintain a hashed table of such critters. */
697 /* ??? Another way to do this would be to pass a flag bit to
698 ENCODE_SECTION_INFO saying whether this is a new decl or not. */
699 /* Let the target reassign the RTL if it wants.
700 This is necessary, for example, when one machine specific
701 decl attribute overrides another. */
702 #ifdef REDO_SECTION_INFO_P
703 if (REDO_SECTION_INFO_P (decl))
704 ENCODE_SECTION_INFO (decl);
705 #endif
706 return;
707 }
708
709 new_name = name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
710
711 reg_number = decode_reg_name (asmspec);
712 if (reg_number == -2)
713 {
714 /* ASMSPEC is given, and not the name of a register. Mark the
715 name with a star so assemble_name won't munge it. */
716 char *starred = alloca (strlen (asmspec) + 2);
717 starred[0] = '*';
718 strcpy (starred + 1, asmspec);
719 new_name = starred;
720 }
721
722 if (TREE_CODE (decl) != FUNCTION_DECL && DECL_REGISTER (decl))
723 {
724 /* First detect errors in declaring global registers. */
725 if (reg_number == -1)
726 error_with_decl (decl, "register name not specified for `%s'");
727 else if (reg_number < 0)
728 error_with_decl (decl, "invalid register name for `%s'");
729 else if (TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
730 error_with_decl (decl,
731 "data type of `%s' isn't suitable for a register");
732 else if (! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
733 error_with_decl (decl,
734 "register specified for `%s' isn't suitable for data type");
735 /* Now handle properly declared static register variables. */
736 else
737 {
738 int nregs;
739
740 if (DECL_INITIAL (decl) != 0 && top_level)
741 {
742 DECL_INITIAL (decl) = 0;
743 error ("global register variable has initial value");
744 }
745 if (TREE_THIS_VOLATILE (decl))
746 warning ("volatile register variables don't work as you might wish");
747
748 /* If the user specified one of the eliminables registers here,
749 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
750 confused with that register and be eliminated. Although this
751 usage is somewhat suspect, we nevertheless use the following
752 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
753
754 DECL_RTL (decl)
755 = gen_rtx_REG (DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
756 REGNO (DECL_RTL (decl)) = reg_number;
757 REG_USERVAR_P (DECL_RTL (decl)) = 1;
758
759 if (top_level)
760 {
761 /* Make this register global, so not usable for anything
762 else. */
763 #ifdef ASM_DECLARE_REGISTER_GLOBAL
764 ASM_DECLARE_REGISTER_GLOBAL (asm_out_file, decl, reg_number, name);
765 #endif
766 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
767 while (nregs > 0)
768 globalize_reg (reg_number + --nregs);
769 }
770
771 /* As a register variable, it has no section. */
772 return;
773 }
774 }
775
776 /* Now handle ordinary static variables and functions (in memory).
777 Also handle vars declared register invalidly. */
778
779 if (reg_number >= 0 || reg_number == -3)
780 error_with_decl (decl,
781 "register name given for non-register variable `%s'");
782
783 /* Specifying a section attribute on a variable forces it into a
784 non-.bss section, and thus it cannot be common. */
785 if (TREE_CODE (decl) == VAR_DECL
786 && DECL_SECTION_NAME (decl) != NULL_TREE
787 && DECL_INITIAL (decl) == NULL_TREE
788 && DECL_COMMON (decl))
789 DECL_COMMON (decl) = 0;
790
791 /* Can't use just the variable's own name for a variable
792 whose scope is less than the whole file, unless it's a member
793 of a local class (which will already be unambiguous).
794 Concatenate a distinguishing number. */
795 if (!top_level && !TREE_PUBLIC (decl)
796 && ! (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
797 && asmspec == 0)
798 {
799 char *label;
800 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
801 var_labelno++;
802 new_name = label;
803 }
804
805 /* When -fprefix-function-name is used, the functions
806 names are prefixed. Only nested function names are not
807 prefixed. */
808 else if (flag_prefix_function_name && TREE_CODE (decl) == FUNCTION_DECL)
809 {
810 size_t name_len = IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl));
811 char *pname;
812
813 pname = alloca (name_len + CHKR_PREFIX_SIZE + 1);
814 memcpy (pname, CHKR_PREFIX, CHKR_PREFIX_SIZE);
815 memcpy (pname + CHKR_PREFIX_SIZE, name, name_len + 1);
816 new_name = pname;
817 }
818
819 if (name != new_name)
820 {
821 DECL_ASSEMBLER_NAME (decl) = get_identifier (new_name);
822 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
823 }
824
825 /* If this variable is to be treated as volatile, show its
826 tree node has side effects. */
827 if ((flag_volatile_global && TREE_CODE (decl) == VAR_DECL
828 && TREE_PUBLIC (decl))
829 || ((flag_volatile_static && TREE_CODE (decl) == VAR_DECL
830 && (TREE_PUBLIC (decl) || TREE_STATIC (decl)))))
831 TREE_SIDE_EFFECTS (decl) = 1;
832
833 DECL_RTL (decl) = gen_rtx_MEM (DECL_MODE (decl),
834 gen_rtx_SYMBOL_REF (Pmode, name));
835 if (TREE_CODE (decl) != FUNCTION_DECL)
836 set_mem_attributes (DECL_RTL (decl), decl, 1);
837
838 /* Optionally set flags or add text to the name to record information
839 such as that it is a function name.
840 If the name is changed, the macro ASM_OUTPUT_LABELREF
841 will have to know how to strip this information. */
842 #ifdef ENCODE_SECTION_INFO
843 ENCODE_SECTION_INFO (decl);
844 #endif
845 }
846
847 /* Make the rtl for variable VAR be volatile.
848 Use this only for static variables. */
849
850 void
851 make_var_volatile (var)
852 tree var;
853 {
854 if (GET_CODE (DECL_RTL (var)) != MEM)
855 abort ();
856
857 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
858 }
859 \f
860 /* Output alignment directive to align for constant expression EXP. */
861
862 void
863 assemble_constant_align (exp)
864 tree exp;
865 {
866 int align;
867
868 /* Align the location counter as required by EXP's data type. */
869 align = TYPE_ALIGN (TREE_TYPE (exp));
870 #ifdef CONSTANT_ALIGNMENT
871 align = CONSTANT_ALIGNMENT (exp, align);
872 #endif
873
874 if (align > BITS_PER_UNIT)
875 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
876 }
877
878 /* Output a string of literal assembler code
879 for an `asm' keyword used between functions. */
880
881 void
882 assemble_asm (string)
883 tree string;
884 {
885 app_enable ();
886
887 if (TREE_CODE (string) == ADDR_EXPR)
888 string = TREE_OPERAND (string, 0);
889
890 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
891 }
892
893 #if 0 /* This should no longer be needed, because
894 flag_gnu_linker should be 0 on these systems,
895 which should prevent any output
896 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
897 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
898 #ifndef ASM_OUTPUT_CONSTRUCTOR
899 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
900 #endif
901 #ifndef ASM_OUTPUT_DESTRUCTOR
902 #define ASM_OUTPUT_DESTRUCTOR(file, name)
903 #endif
904 #endif
905 #endif /* 0 */
906
907 /* Record an element in the table of global destructors.
908 How this is done depends on what sort of assembler and linker
909 are in use.
910
911 NAME should be the name of a global function to be called
912 at exit time. This name is output using assemble_name. */
913
914 void
915 assemble_destructor (name)
916 const char *name;
917 {
918 #ifdef ASM_OUTPUT_DESTRUCTOR
919 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
920 #else
921 if (flag_gnu_linker)
922 {
923 /* Now tell GNU LD that this is part of the static destructor set. */
924 /* This code works for any machine provided you use GNU as/ld. */
925 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
926 assemble_name (asm_out_file, name);
927 fputc ('\n', asm_out_file);
928 }
929 #endif
930 }
931
932 /* Likewise for global constructors. */
933
934 void
935 assemble_constructor (name)
936 const char *name;
937 {
938 #ifdef ASM_OUTPUT_CONSTRUCTOR
939 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
940 #else
941 if (flag_gnu_linker)
942 {
943 /* Now tell GNU LD that this is part of the static constructor set. */
944 /* This code works for any machine provided you use GNU as/ld. */
945 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
946 assemble_name (asm_out_file, name);
947 fputc ('\n', asm_out_file);
948 }
949 #endif
950 }
951
952 /* Likewise for entries we want to record for garbage collection.
953 Garbage collection is still under development. */
954
955 void
956 assemble_gc_entry (name)
957 const char *name;
958 {
959 #ifdef ASM_OUTPUT_GC_ENTRY
960 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
961 #else
962 if (flag_gnu_linker)
963 {
964 /* Now tell GNU LD that this is part of the static constructor set. */
965 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
966 assemble_name (asm_out_file, name);
967 fputc ('\n', asm_out_file);
968 }
969 #endif
970 }
971 \f
972 /* CONSTANT_POOL_BEFORE_FUNCTION may be defined as an expression with
973 a non-zero value if the constant pool should be output before the
974 start of the function, or a zero value if the pool should output
975 after the end of the function. The default is to put it before the
976 start. */
977
978 #ifndef CONSTANT_POOL_BEFORE_FUNCTION
979 #define CONSTANT_POOL_BEFORE_FUNCTION 1
980 #endif
981
982 /* Output assembler code for the constant pool of a function and associated
983 with defining the name of the function. DECL describes the function.
984 NAME is the function's name. For the constant pool, we use the current
985 constant pool data. */
986
987 void
988 assemble_start_function (decl, fnname)
989 tree decl;
990 const char *fnname;
991 {
992 int align;
993
994 /* The following code does not need preprocessing in the assembler. */
995
996 app_disable ();
997
998 if (CONSTANT_POOL_BEFORE_FUNCTION)
999 output_constant_pool (fnname, decl);
1000
1001 #ifdef ASM_OUTPUT_SECTION_NAME
1002 /* If the function is to be put in its own section and it's not in a section
1003 already, indicate so. */
1004 if ((flag_function_sections
1005 && DECL_SECTION_NAME (decl) == NULL_TREE)
1006 || UNIQUE_SECTION_P (decl))
1007 UNIQUE_SECTION (decl, 0);
1008 #endif
1009
1010 function_section (decl);
1011
1012 /* Tell assembler to move to target machine's alignment for functions. */
1013 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1014 if (align > 0)
1015 ASM_OUTPUT_ALIGN (asm_out_file, align);
1016
1017 /* Handle a user-specified function alignment.
1018 Note that we still need to align to FUNCTION_BOUNDARY, as above,
1019 because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */
1020 if (align_functions_log > align)
1021 {
1022 #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN
1023 ASM_OUTPUT_MAX_SKIP_ALIGN (asm_out_file,
1024 align_functions_log, align_functions-1);
1025 #else
1026 ASM_OUTPUT_ALIGN (asm_out_file, align_functions_log);
1027 #endif
1028 }
1029
1030 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
1031 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
1032 #endif
1033
1034 #ifdef SDB_DEBUGGING_INFO
1035 /* Output SDB definition of the function. */
1036 if (write_symbols == SDB_DEBUG)
1037 sdbout_mark_begin_function ();
1038 #endif
1039
1040 #ifdef DBX_DEBUGGING_INFO
1041 /* Output DBX definition of the function. */
1042 if (write_symbols == DBX_DEBUG)
1043 dbxout_begin_function (decl);
1044 #endif
1045
1046 /* Make function name accessible from other files, if appropriate. */
1047
1048 if (TREE_PUBLIC (decl))
1049 {
1050 if (! first_global_object_name)
1051 {
1052 const char *p;
1053 char *name;
1054
1055 STRIP_NAME_ENCODING (p, fnname);
1056 name = permalloc (strlen (p) + 1);
1057 strcpy (name, p);
1058
1059 if (! DECL_WEAK (decl) && ! DECL_ONE_ONLY (decl))
1060 first_global_object_name = name;
1061 else
1062 weak_global_object_name = name;
1063 }
1064
1065 #ifdef ASM_WEAKEN_LABEL
1066 if (DECL_WEAK (decl))
1067 {
1068 ASM_WEAKEN_LABEL (asm_out_file, fnname);
1069 /* Remove this function from the pending weak list so that
1070 we do not emit multiple .weak directives for it. */
1071 remove_from_pending_weak_list
1072 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1073 }
1074 else
1075 #endif
1076 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
1077 }
1078
1079 /* Do any machine/system dependent processing of the function name */
1080 #ifdef ASM_DECLARE_FUNCTION_NAME
1081 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
1082 #else
1083 /* Standard thing is just output label for the function. */
1084 ASM_OUTPUT_LABEL (asm_out_file, fnname);
1085 #endif /* ASM_DECLARE_FUNCTION_NAME */
1086 }
1087
1088 /* Output assembler code associated with defining the size of the
1089 function. DECL describes the function. NAME is the function's name. */
1090
1091 void
1092 assemble_end_function (decl, fnname)
1093 tree decl;
1094 const char *fnname;
1095 {
1096 #ifdef ASM_DECLARE_FUNCTION_SIZE
1097 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
1098 #endif
1099 if (! CONSTANT_POOL_BEFORE_FUNCTION)
1100 {
1101 output_constant_pool (fnname, decl);
1102 function_section (decl); /* need to switch back */
1103 }
1104
1105 /* Output any constants which should appear after the function. */
1106 output_after_function_constants ();
1107 }
1108 \f
1109 /* Assemble code to leave SIZE bytes of zeros. */
1110
1111 void
1112 assemble_zeros (size)
1113 int size;
1114 {
1115 /* Do no output if -fsyntax-only. */
1116 if (flag_syntax_only)
1117 return;
1118
1119 #ifdef ASM_NO_SKIP_IN_TEXT
1120 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
1121 so we must output 0s explicitly in the text section. */
1122 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
1123 {
1124 int i;
1125
1126 for (i = 0; i < size - 20; i += 20)
1127 {
1128 #ifdef ASM_BYTE_OP
1129 fprintf (asm_out_file,
1130 "%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);
1131 #else
1132 fprintf (asm_out_file,
1133 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
1134 #endif
1135 }
1136 if (i < size)
1137 {
1138 #ifdef ASM_BYTE_OP
1139 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
1140 #else
1141 fprintf (asm_out_file, "\tbyte 0");
1142 #endif
1143 i++;
1144 for (; i < size; i++)
1145 fprintf (asm_out_file, ",0");
1146 fprintf (asm_out_file, "\n");
1147 }
1148 }
1149 else
1150 #endif
1151 if (size > 0)
1152 ASM_OUTPUT_SKIP (asm_out_file, size);
1153 }
1154
1155 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
1156
1157 void
1158 assemble_align (align)
1159 int align;
1160 {
1161 if (align > BITS_PER_UNIT)
1162 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1163 }
1164
1165 /* Assemble a string constant with the specified C string as contents. */
1166
1167 void
1168 assemble_string (p, size)
1169 const char *p;
1170 int size;
1171 {
1172 int pos = 0;
1173 int maximum = 2000;
1174
1175 /* If the string is very long, split it up. */
1176
1177 while (pos < size)
1178 {
1179 int thissize = size - pos;
1180 if (thissize > maximum)
1181 thissize = maximum;
1182
1183 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
1184
1185 pos += thissize;
1186 p += thissize;
1187 }
1188 }
1189
1190 \f
1191 #if defined ASM_OUTPUT_ALIGNED_DECL_LOCAL
1192 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1193 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1194 #else
1195 #if defined ASM_OUTPUT_ALIGNED_LOCAL
1196 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1197 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, DECL_ALIGN (decl))
1198 #else
1199 #define ASM_EMIT_LOCAL(decl, name, size, rounded) \
1200 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded)
1201 #endif
1202 #endif
1203
1204 #if defined ASM_OUTPUT_ALIGNED_BSS
1205 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1206 ASM_OUTPUT_ALIGNED_BSS (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1207 #else
1208 #if defined ASM_OUTPUT_BSS
1209 #define ASM_EMIT_BSS(decl, name, size, rounded) \
1210 ASM_OUTPUT_BSS (asm_out_file, decl, name, size, rounded)
1211 #else
1212 #undef ASM_EMIT_BSS
1213 #endif
1214 #endif
1215
1216 #if defined ASM_OUTPUT_ALIGNED_DECL_COMMON
1217 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1218 ASM_OUTPUT_ALIGNED_DECL_COMMON (asm_out_file, decl, name, size, DECL_ALIGN (decl))
1219 #else
1220 #if defined ASM_OUTPUT_ALIGNED_COMMON
1221 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1222 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size, DECL_ALIGN (decl))
1223 #else
1224 #define ASM_EMIT_COMMON(decl, name, size, rounded) \
1225 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded)
1226 #endif
1227 #endif
1228
1229 static void
1230 asm_emit_uninitialised (decl, name, size, rounded)
1231 tree decl;
1232 const char * name;
1233 int size ATTRIBUTE_UNUSED;
1234 int rounded ATTRIBUTE_UNUSED;
1235 {
1236 enum
1237 {
1238 asm_dest_common,
1239 asm_dest_bss,
1240 asm_dest_local
1241 }
1242 destination = asm_dest_local;
1243
1244 if (TREE_PUBLIC (decl))
1245 {
1246 #if defined ASM_EMIT_BSS
1247 if (! DECL_COMMON (decl))
1248 destination = asm_dest_bss;
1249 else
1250 #endif
1251 destination = asm_dest_common;
1252 }
1253
1254 if (flag_shared_data)
1255 {
1256 switch (destination)
1257 {
1258 #ifdef ASM_OUTPUT_SHARED_BSS
1259 case asm_dest_bss:
1260 ASM_OUTPUT_SHARED_BSS (asm_out_file, decl, name, size, rounded);
1261 return;
1262 #endif
1263 #ifdef ASM_OUTPUT_SHARED_COMMON
1264 case asm_dest_common:
1265 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1266 return;
1267 #endif
1268 #ifdef ASM_OUTPUT_SHARED_LOCAL
1269 case asm_dest_local:
1270 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1271 return;
1272 #endif
1273 default:
1274 break;
1275 }
1276 }
1277
1278 #ifdef ASM_OUTPUT_SECTION_NAME
1279 /* We already know that DECL_SECTION_NAME() == NULL. */
1280 if (flag_data_sections != 0 || UNIQUE_SECTION_P (decl))
1281 UNIQUE_SECTION (decl, 0);
1282 #endif
1283
1284 switch (destination)
1285 {
1286 #ifdef ASM_EMIT_BSS
1287 case asm_dest_bss:
1288 ASM_EMIT_BSS (decl, name, size, rounded);
1289 break;
1290 #endif
1291 case asm_dest_common:
1292 ASM_EMIT_COMMON (decl, name, size, rounded);
1293 break;
1294 case asm_dest_local:
1295 ASM_EMIT_LOCAL (decl, name, size, rounded);
1296 break;
1297 default:
1298 abort ();
1299 }
1300
1301 return;
1302 }
1303
1304 /* Assemble everything that is needed for a variable or function declaration.
1305 Not used for automatic variables, and not used for function definitions.
1306 Should not be called for variables of incomplete structure type.
1307
1308 TOP_LEVEL is nonzero if this variable has file scope.
1309 AT_END is nonzero if this is the special handling, at end of compilation,
1310 to define things that have had only tentative definitions.
1311 DONT_OUTPUT_DATA if nonzero means don't actually output the
1312 initial value (that will be done by the caller). */
1313
1314 void
1315 assemble_variable (decl, top_level, at_end, dont_output_data)
1316 tree decl;
1317 int top_level ATTRIBUTE_UNUSED;
1318 int at_end ATTRIBUTE_UNUSED;
1319 int dont_output_data;
1320 {
1321 register const char *name;
1322 unsigned int align;
1323 int reloc = 0;
1324 enum in_section saved_in_section;
1325
1326 last_assemble_variable_decl = 0;
1327
1328 if (GET_CODE (DECL_RTL (decl)) == REG)
1329 {
1330 /* Do output symbol info for global register variables, but do nothing
1331 else for them. */
1332
1333 if (TREE_ASM_WRITTEN (decl))
1334 return;
1335 TREE_ASM_WRITTEN (decl) = 1;
1336
1337 /* Do no output if -fsyntax-only. */
1338 if (flag_syntax_only)
1339 return;
1340
1341 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
1342 /* File-scope global variables are output here. */
1343 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
1344 && top_level)
1345 dbxout_symbol (decl, 0);
1346 #endif
1347 #ifdef SDB_DEBUGGING_INFO
1348 if (write_symbols == SDB_DEBUG && top_level
1349 /* Leave initialized global vars for end of compilation;
1350 see comment in compile_file. */
1351 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1352 sdbout_symbol (decl, 0);
1353 #endif
1354
1355 /* Don't output any DWARF debugging information for variables here.
1356 In the case of local variables, the information for them is output
1357 when we do our recursive traversal of the tree representation for
1358 the entire containing function. In the case of file-scope variables,
1359 we output information for all of them at the very end of compilation
1360 while we are doing our final traversal of the chain of file-scope
1361 declarations. */
1362
1363 return;
1364 }
1365
1366 /* Normally no need to say anything here for external references,
1367 since assemble_external is called by the language-specific code
1368 when a declaration is first seen. */
1369
1370 if (DECL_EXTERNAL (decl))
1371 return;
1372
1373 /* Output no assembler code for a function declaration.
1374 Only definitions of functions output anything. */
1375
1376 if (TREE_CODE (decl) == FUNCTION_DECL)
1377 return;
1378
1379 /* If type was incomplete when the variable was declared,
1380 see if it is complete now. */
1381
1382 if (DECL_SIZE (decl) == 0)
1383 layout_decl (decl, 0);
1384
1385 /* Still incomplete => don't allocate it; treat the tentative defn
1386 (which is what it must have been) as an `extern' reference. */
1387
1388 if (!dont_output_data && DECL_SIZE (decl) == 0)
1389 {
1390 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1391 DECL_SOURCE_LINE (decl),
1392 "storage size of `%s' isn't known",
1393 IDENTIFIER_POINTER (DECL_NAME (decl)));
1394 TREE_ASM_WRITTEN (decl) = 1;
1395 return;
1396 }
1397
1398 /* The first declaration of a variable that comes through this function
1399 decides whether it is global (in C, has external linkage)
1400 or local (in C, has internal linkage). So do nothing more
1401 if this function has already run. */
1402
1403 if (TREE_ASM_WRITTEN (decl))
1404 return;
1405
1406 TREE_ASM_WRITTEN (decl) = 1;
1407
1408 /* Do no output if -fsyntax-only. */
1409 if (flag_syntax_only)
1410 return;
1411
1412 app_disable ();
1413
1414 if (! dont_output_data
1415 && ! host_integerp (DECL_SIZE_UNIT (decl), 1))
1416 {
1417 error_with_decl (decl, "size of variable `%s' is too large");
1418 goto finish;
1419 }
1420
1421 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1422 if (TREE_PUBLIC (decl) && DECL_NAME (decl)
1423 && ! first_global_object_name
1424 && ! (DECL_COMMON (decl) && (DECL_INITIAL (decl) == 0
1425 || DECL_INITIAL (decl) == error_mark_node))
1426 && ! DECL_WEAK (decl)
1427 && ! DECL_ONE_ONLY (decl))
1428 {
1429 const char *p;
1430 char *xname;
1431
1432 STRIP_NAME_ENCODING (p, name);
1433 xname = permalloc (strlen (p) + 1);
1434 strcpy (xname, p);
1435 first_global_object_name = xname;
1436 }
1437
1438 /* Compute the alignment of this data. */
1439
1440 align = DECL_ALIGN (decl);
1441
1442 /* In the case for initialing an array whose length isn't specified,
1443 where we have not yet been able to do the layout,
1444 figure out the proper alignment now. */
1445 if (dont_output_data && DECL_SIZE (decl) == 0
1446 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1447 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1448
1449 /* Some object file formats have a maximum alignment which they support.
1450 In particular, a.out format supports a maximum alignment of 4. */
1451 #ifndef MAX_OFILE_ALIGNMENT
1452 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1453 #endif
1454 if (align > MAX_OFILE_ALIGNMENT)
1455 {
1456 warning_with_decl (decl,
1457 "alignment of `%s' is greater than maximum object file alignment. Using %d.",
1458 MAX_OFILE_ALIGNMENT/BITS_PER_UNIT);
1459 align = MAX_OFILE_ALIGNMENT;
1460 }
1461
1462 /* On some machines, it is good to increase alignment sometimes. */
1463 #ifdef DATA_ALIGNMENT
1464 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1465 #endif
1466 #ifdef CONSTANT_ALIGNMENT
1467 if (DECL_INITIAL (decl) != 0 && DECL_INITIAL (decl) != error_mark_node)
1468 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1469 #endif
1470
1471 /* Reset the alignment in case we have made it tighter, so we can benefit
1472 from it in get_pointer_alignment. */
1473 DECL_ALIGN (decl) = align;
1474
1475 /* Handle uninitialized definitions. */
1476
1477 if ((DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node)
1478 /* If the target can't output uninitialized but not common global data
1479 in .bss, then we have to use .data. */
1480 #if ! defined ASM_EMIT_BSS
1481 && DECL_COMMON (decl)
1482 #endif
1483 && DECL_SECTION_NAME (decl) == NULL_TREE
1484 && ! dont_output_data)
1485 {
1486 unsigned HOST_WIDE_INT size = tree_low_cst (DECL_SIZE_UNIT (decl), 1);
1487 unsigned HOST_WIDE_INT rounded = size;
1488
1489 /* Don't allocate zero bytes of common,
1490 since that means "undefined external" in the linker. */
1491 if (size == 0)
1492 rounded = 1;
1493
1494 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1495 so that each uninitialized object starts on such a boundary. */
1496 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1497 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1498 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1499
1500 /* Don't continue this line--convex cc version 4.1 would lose. */
1501 #if !defined(ASM_OUTPUT_ALIGNED_COMMON) && !defined(ASM_OUTPUT_ALIGNED_DECL_COMMON) && !defined(ASM_OUTPUT_ALIGNED_BSS)
1502 if ((unsigned HOST_WIDE_INT) DECL_ALIGN (decl) / BITS_PER_UNIT > rounded)
1503 warning_with_decl
1504 (decl, "requested alignment for %s is greater than implemented alignment of %d.",rounded);
1505 #endif
1506
1507 #ifdef DBX_DEBUGGING_INFO
1508 /* File-scope global variables are output here. */
1509 if (write_symbols == DBX_DEBUG && top_level)
1510 dbxout_symbol (decl, 0);
1511 #endif
1512 #ifdef SDB_DEBUGGING_INFO
1513 if (write_symbols == SDB_DEBUG && top_level
1514 /* Leave initialized global vars for end of compilation;
1515 see comment in compile_file. */
1516 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1517 sdbout_symbol (decl, 0);
1518 #endif
1519
1520 /* Don't output any DWARF debugging information for variables here.
1521 In the case of local variables, the information for them is output
1522 when we do our recursive traversal of the tree representation for
1523 the entire containing function. In the case of file-scope variables,
1524 we output information for all of them at the very end of compilation
1525 while we are doing our final traversal of the chain of file-scope
1526 declarations. */
1527
1528 #if 0 /* ??? We should either delete this or add a comment describing what
1529 it was intended to do and why we shouldn't delete it. */
1530 if (flag_shared_data)
1531 data_section ();
1532 #endif
1533 asm_emit_uninitialised (decl, name, size, rounded);
1534
1535 goto finish;
1536 }
1537
1538 /* Handle initialized definitions.
1539 Also handle uninitialized global definitions if -fno-common and the
1540 target doesn't support ASM_OUTPUT_BSS. */
1541
1542 /* First make the assembler name(s) global if appropriate. */
1543 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1544 {
1545 #ifdef ASM_WEAKEN_LABEL
1546 if (DECL_WEAK (decl))
1547 {
1548 ASM_WEAKEN_LABEL (asm_out_file, name);
1549 /* Remove this variable from the pending weak list so that
1550 we do not emit multiple .weak directives for it. */
1551 remove_from_pending_weak_list
1552 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
1553 }
1554 else
1555 #endif
1556 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1557 }
1558 #if 0
1559 for (d = equivalents; d; d = TREE_CHAIN (d))
1560 {
1561 tree e = TREE_VALUE (d);
1562 if (TREE_PUBLIC (e) && DECL_NAME (e))
1563 ASM_GLOBALIZE_LABEL (asm_out_file,
1564 XSTR (XEXP (DECL_RTL (e), 0), 0));
1565 }
1566 #endif
1567
1568 /* Output any data that we will need to use the address of. */
1569 if (DECL_INITIAL (decl) == error_mark_node)
1570 reloc = contains_pointers_p (TREE_TYPE (decl));
1571 else if (DECL_INITIAL (decl))
1572 reloc = output_addressed_constants (DECL_INITIAL (decl));
1573
1574 #ifdef ASM_OUTPUT_SECTION_NAME
1575 if ((flag_data_sections != 0 && DECL_SECTION_NAME (decl) == NULL_TREE)
1576 || UNIQUE_SECTION_P (decl))
1577 UNIQUE_SECTION (decl, reloc);
1578 #endif
1579
1580 /* Switch to the appropriate section. */
1581 variable_section (decl, reloc);
1582
1583 /* dbxout.c needs to know this. */
1584 if (in_text_section ())
1585 DECL_IN_TEXT_SECTION (decl) = 1;
1586
1587 /* Record current section so we can restore it if dbxout.c clobbers it. */
1588 saved_in_section = in_section;
1589
1590 /* Output the dbx info now that we have chosen the section. */
1591
1592 #ifdef DBX_DEBUGGING_INFO
1593 /* File-scope global variables are output here. */
1594 if (write_symbols == DBX_DEBUG && top_level)
1595 dbxout_symbol (decl, 0);
1596 #endif
1597 #ifdef SDB_DEBUGGING_INFO
1598 if (write_symbols == SDB_DEBUG && top_level
1599 /* Leave initialized global vars for end of compilation;
1600 see comment in compile_file. */
1601 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1602 sdbout_symbol (decl, 0);
1603 #endif
1604
1605 /* Don't output any DWARF debugging information for variables here.
1606 In the case of local variables, the information for them is output
1607 when we do our recursive traversal of the tree representation for
1608 the entire containing function. In the case of file-scope variables,
1609 we output information for all of them at the very end of compilation
1610 while we are doing our final traversal of the chain of file-scope
1611 declarations. */
1612
1613 /* If the debugging output changed sections, reselect the section
1614 that's supposed to be selected. */
1615 if (in_section != saved_in_section)
1616 variable_section (decl, reloc);
1617
1618 /* Output the alignment of this data. */
1619 if (align > BITS_PER_UNIT)
1620 ASM_OUTPUT_ALIGN (asm_out_file,
1621 floor_log2 (DECL_ALIGN (decl) / BITS_PER_UNIT));
1622
1623 /* Do any machine/system dependent processing of the object. */
1624 #ifdef ASM_DECLARE_OBJECT_NAME
1625 last_assemble_variable_decl = decl;
1626 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1627 #else
1628 /* Standard thing is just output label for the object. */
1629 ASM_OUTPUT_LABEL (asm_out_file, name);
1630 #endif /* ASM_DECLARE_OBJECT_NAME */
1631
1632 if (!dont_output_data)
1633 {
1634 if (DECL_INITIAL (decl))
1635 /* Output the actual data. */
1636 output_constant (DECL_INITIAL (decl),
1637 tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1638 else
1639 /* Leave space for it. */
1640 assemble_zeros (tree_low_cst (DECL_SIZE_UNIT (decl), 1));
1641 }
1642
1643 finish:
1644 #ifdef XCOFF_DEBUGGING_INFO
1645 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1646 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1647 and `aa' hasn't been output yet, the assembler generates a stab entry with
1648 a value of zero, in addition to creating an unnecessary external entry
1649 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1650
1651 /* File-scope global variables are output here. */
1652 if (write_symbols == XCOFF_DEBUG && top_level)
1653 {
1654 saved_in_section = in_section;
1655
1656 dbxout_symbol (decl, 0);
1657
1658 if (in_section != saved_in_section)
1659 variable_section (decl, reloc);
1660 }
1661 #else
1662 /* There must be a statement after a label. */
1663 ;
1664 #endif
1665 }
1666
1667 /* Return 1 if type TYPE contains any pointers. */
1668
1669 static int
1670 contains_pointers_p (type)
1671 tree type;
1672 {
1673 switch (TREE_CODE (type))
1674 {
1675 case POINTER_TYPE:
1676 case REFERENCE_TYPE:
1677 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1678 so I'll play safe and return 1. */
1679 case OFFSET_TYPE:
1680 return 1;
1681
1682 case RECORD_TYPE:
1683 case UNION_TYPE:
1684 case QUAL_UNION_TYPE:
1685 {
1686 tree fields;
1687 /* For a type that has fields, see if the fields have pointers. */
1688 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1689 if (TREE_CODE (fields) == FIELD_DECL
1690 && contains_pointers_p (TREE_TYPE (fields)))
1691 return 1;
1692 return 0;
1693 }
1694
1695 case ARRAY_TYPE:
1696 /* An array type contains pointers if its element type does. */
1697 return contains_pointers_p (TREE_TYPE (type));
1698
1699 default:
1700 return 0;
1701 }
1702 }
1703
1704 /* Output something to declare an external symbol to the assembler.
1705 (Most assemblers don't need this, so we normally output nothing.)
1706 Do nothing if DECL is not external. */
1707
1708 void
1709 assemble_external (decl)
1710 tree decl ATTRIBUTE_UNUSED;
1711 {
1712 #ifdef ASM_OUTPUT_EXTERNAL
1713 if (DECL_P (decl) && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1714 {
1715 rtx rtl = DECL_RTL (decl);
1716
1717 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1718 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1719 {
1720 /* Some systems do require some output. */
1721 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1722 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1723 }
1724 }
1725 #endif
1726 }
1727
1728 /* Similar, for calling a library function FUN. */
1729
1730 void
1731 assemble_external_libcall (fun)
1732 rtx fun ATTRIBUTE_UNUSED;
1733 {
1734 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1735 /* Declare library function name external when first used, if nec. */
1736 if (! SYMBOL_REF_USED (fun))
1737 {
1738 SYMBOL_REF_USED (fun) = 1;
1739 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1740 }
1741 #endif
1742 }
1743
1744 /* Declare the label NAME global. */
1745
1746 void
1747 assemble_global (name)
1748 const char *name;
1749 {
1750 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1751 }
1752
1753 /* Assemble a label named NAME. */
1754
1755 void
1756 assemble_label (name)
1757 const char *name;
1758 {
1759 ASM_OUTPUT_LABEL (asm_out_file, name);
1760 }
1761
1762 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1763 If NAME starts with a *, the rest of NAME is output verbatim.
1764 Otherwise NAME is transformed in an implementation-defined way
1765 (usually by the addition of an underscore).
1766 Many macros in the tm file are defined to call this function. */
1767
1768 void
1769 assemble_name (file, name)
1770 FILE *file;
1771 const char *name;
1772 {
1773 const char *real_name;
1774 tree id;
1775
1776 STRIP_NAME_ENCODING (real_name, name);
1777 if (flag_prefix_function_name
1778 && ! bcmp (real_name, CHKR_PREFIX, CHKR_PREFIX_SIZE))
1779 real_name = real_name + CHKR_PREFIX_SIZE;
1780
1781 id = maybe_get_identifier (real_name);
1782 if (id)
1783 TREE_SYMBOL_REFERENCED (id) = 1;
1784
1785 if (name[0] == '*')
1786 fputs (&name[1], file);
1787 else
1788 ASM_OUTPUT_LABELREF (file, name);
1789 }
1790
1791 /* Allocate SIZE bytes writable static space with a gensym name
1792 and return an RTX to refer to its address. */
1793
1794 rtx
1795 assemble_static_space (size)
1796 int size;
1797 {
1798 char name[12];
1799 char *namestring;
1800 rtx x;
1801
1802 #if 0
1803 if (flag_shared_data)
1804 data_section ();
1805 #endif
1806
1807 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1808 ++const_labelno;
1809 namestring = ggc_alloc_string (name, -1);
1810
1811 x = gen_rtx_SYMBOL_REF (Pmode, namestring);
1812
1813 #ifdef ASM_OUTPUT_ALIGNED_DECL_LOCAL
1814 ASM_OUTPUT_ALIGNED_DECL_LOCAL (asm_out_file, NULL_TREE, name, size,
1815 BIGGEST_ALIGNMENT);
1816 #else
1817 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1818 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1819 #else
1820 {
1821 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1822 so that each uninitialized object starts on such a boundary. */
1823 /* Variable `rounded' might or might not be used in ASM_OUTPUT_LOCAL. */
1824 int rounded ATTRIBUTE_UNUSED
1825 = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1826 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1827 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1828 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1829 }
1830 #endif
1831 #endif
1832 return x;
1833 }
1834
1835 /* Assemble the static constant template for function entry trampolines.
1836 This is done at most once per compilation.
1837 Returns an RTX for the address of the template. */
1838
1839 #ifdef TRAMPOLINE_TEMPLATE
1840 rtx
1841 assemble_trampoline_template ()
1842 {
1843 char label[256];
1844 char *name;
1845 int align;
1846
1847 /* By default, put trampoline templates in read-only data section. */
1848
1849 #ifdef TRAMPOLINE_SECTION
1850 TRAMPOLINE_SECTION ();
1851 #else
1852 readonly_data_section ();
1853 #endif
1854
1855 /* Write the assembler code to define one. */
1856 align = floor_log2 (TRAMPOLINE_ALIGNMENT / BITS_PER_UNIT);
1857 if (align > 0)
1858 ASM_OUTPUT_ALIGN (asm_out_file, align);
1859
1860 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1861 TRAMPOLINE_TEMPLATE (asm_out_file);
1862
1863 /* Record the rtl to refer to it. */
1864 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1865 name = ggc_alloc_string (label, -1);
1866 return gen_rtx_SYMBOL_REF (Pmode, name);
1867 }
1868 #endif
1869 \f
1870 /* Assemble the integer constant X into an object of SIZE bytes.
1871 X must be either a CONST_INT or CONST_DOUBLE.
1872
1873 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1874 non-zero, abort if we can't output the constant. */
1875
1876 int
1877 assemble_integer (x, size, force)
1878 rtx x;
1879 int size;
1880 int force;
1881 {
1882 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1883 ASM_OUTPUT... macros. */
1884
1885 switch (size)
1886 {
1887 #ifdef ASM_OUTPUT_CHAR
1888 case 1:
1889 ASM_OUTPUT_CHAR (asm_out_file, x);
1890 return 1;
1891 #endif
1892
1893 #ifdef ASM_OUTPUT_SHORT
1894 case 2:
1895 ASM_OUTPUT_SHORT (asm_out_file, x);
1896 return 1;
1897 #endif
1898
1899 #ifdef ASM_OUTPUT_INT
1900 case 4:
1901 ASM_OUTPUT_INT (asm_out_file, x);
1902 return 1;
1903 #endif
1904
1905 #ifdef ASM_OUTPUT_DOUBLE_INT
1906 case 8:
1907 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1908 return 1;
1909 #endif
1910
1911 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1912 case 16:
1913 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1914 return 1;
1915 #endif
1916 }
1917
1918 /* If we couldn't do it that way, there are two other possibilities: First,
1919 if the machine can output an explicit byte and this is a 1 byte constant,
1920 we can use ASM_OUTPUT_BYTE. */
1921
1922 #ifdef ASM_OUTPUT_BYTE
1923 if (size == 1 && GET_CODE (x) == CONST_INT)
1924 {
1925 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1926 return 1;
1927 }
1928 #endif
1929
1930 /* Finally, if SIZE is larger than a single word, try to output the constant
1931 one word at a time. */
1932
1933 if (size > UNITS_PER_WORD)
1934 {
1935 int i;
1936 enum machine_mode mode
1937 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1938 rtx word;
1939
1940 for (i = 0; i < size / UNITS_PER_WORD; i++)
1941 {
1942 word = operand_subword (x, i, 0, mode);
1943
1944 if (word == 0)
1945 break;
1946
1947 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1948 break;
1949 }
1950
1951 if (i == size / UNITS_PER_WORD)
1952 return 1;
1953 /* If we output at least one word and then could not finish,
1954 there is no valid way to continue. */
1955 if (i > 0)
1956 abort ();
1957 }
1958
1959 if (force)
1960 abort ();
1961
1962 return 0;
1963 }
1964 \f
1965 /* Assemble the floating-point constant D into an object of size MODE. */
1966
1967 void
1968 assemble_real (d, mode)
1969 REAL_VALUE_TYPE d;
1970 enum machine_mode mode;
1971 {
1972 jmp_buf output_constant_handler;
1973
1974 if (setjmp (output_constant_handler))
1975 {
1976 error ("floating point trap outputting a constant");
1977 #ifdef REAL_IS_NOT_DOUBLE
1978 bzero ((char *) &d, sizeof d);
1979 d = dconst0;
1980 #else
1981 d = 0;
1982 #endif
1983 }
1984
1985 set_float_handler (output_constant_handler);
1986
1987 switch (mode)
1988 {
1989 #ifdef ASM_OUTPUT_BYTE_FLOAT
1990 case QFmode:
1991 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1992 break;
1993 #endif
1994 #ifdef ASM_OUTPUT_SHORT_FLOAT
1995 case HFmode:
1996 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1997 break;
1998 #endif
1999 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
2000 case TQFmode:
2001 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
2002 break;
2003 #endif
2004 #ifdef ASM_OUTPUT_FLOAT
2005 case SFmode:
2006 ASM_OUTPUT_FLOAT (asm_out_file, d);
2007 break;
2008 #endif
2009
2010 #ifdef ASM_OUTPUT_DOUBLE
2011 case DFmode:
2012 ASM_OUTPUT_DOUBLE (asm_out_file, d);
2013 break;
2014 #endif
2015
2016 #ifdef ASM_OUTPUT_LONG_DOUBLE
2017 case XFmode:
2018 case TFmode:
2019 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
2020 break;
2021 #endif
2022
2023 default:
2024 abort ();
2025 }
2026
2027 set_float_handler (NULL_PTR);
2028 }
2029 \f
2030 /* Here we combine duplicate floating constants to make
2031 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
2032
2033 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
2034 For an integer, I0 is the low-order word and I1 is the high-order word.
2035 For a real number, I0 is the word with the low address
2036 and I1 is the word with the high address. */
2037
2038 rtx
2039 immed_double_const (i0, i1, mode)
2040 HOST_WIDE_INT i0, i1;
2041 enum machine_mode mode;
2042 {
2043 register rtx r;
2044
2045 if (GET_MODE_CLASS (mode) == MODE_INT
2046 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
2047 {
2048 /* We clear out all bits that don't belong in MODE, unless they and our
2049 sign bit are all one. So we get either a reasonable negative value
2050 or a reasonable unsigned value for this mode. */
2051 int width = GET_MODE_BITSIZE (mode);
2052 if (width < HOST_BITS_PER_WIDE_INT
2053 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
2054 != ((HOST_WIDE_INT) (-1) << (width - 1))))
2055 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
2056 else if (width == HOST_BITS_PER_WIDE_INT
2057 && ! (i1 == ~0 && i0 < 0))
2058 i1 = 0;
2059 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
2060 /* We cannot represent this value as a constant. */
2061 abort ();
2062
2063 /* If this would be an entire word for the target, but is not for
2064 the host, then sign-extend on the host so that the number will look
2065 the same way on the host that it would on the target.
2066
2067 For example, when building a 64 bit alpha hosted 32 bit sparc
2068 targeted compiler, then we want the 32 bit unsigned value -1 to be
2069 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
2070 The later confuses the sparc backend. */
2071
2072 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
2073 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
2074 i0 |= ((HOST_WIDE_INT) (-1) << width);
2075
2076 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
2077
2078 ??? Strictly speaking, this is wrong if we create a CONST_INT
2079 for a large unsigned constant with the size of MODE being
2080 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
2081 wider mode. In that case we will mis-interpret it as a negative
2082 number.
2083
2084 Unfortunately, the only alternative is to make a CONST_DOUBLE
2085 for any constant in any mode if it is an unsigned constant larger
2086 than the maximum signed integer in an int on the host. However,
2087 doing this will break everyone that always expects to see a CONST_INT
2088 for SImode and smaller.
2089
2090 We have always been making CONST_INTs in this case, so nothing new
2091 is being broken. */
2092
2093 if (width <= HOST_BITS_PER_WIDE_INT)
2094 i1 = (i0 < 0) ? ~(HOST_WIDE_INT) 0 : 0;
2095
2096 /* If this integer fits in one word, return a CONST_INT. */
2097 if ((i1 == 0 && i0 >= 0)
2098 || (i1 == ~0 && i0 < 0))
2099 return GEN_INT (i0);
2100
2101 /* We use VOIDmode for integers. */
2102 mode = VOIDmode;
2103 }
2104
2105 /* Search the chain for an existing CONST_DOUBLE with the right value.
2106 If one is found, return it. */
2107 if (cfun != 0)
2108 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2109 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
2110 && GET_MODE (r) == mode)
2111 return r;
2112
2113 /* No; make a new one and add it to the chain.
2114
2115 We may be called by an optimizer which may be discarding any memory
2116 allocated during its processing (such as combine and loop). However,
2117 we will be leaving this constant on the chain, so we cannot tolerate
2118 freed memory. So switch to saveable_obstack for this allocation
2119 and then switch back if we were in current_obstack. */
2120
2121 push_obstacks_nochange ();
2122 rtl_in_saveable_obstack ();
2123 r = gen_rtx_CONST_DOUBLE (mode, const0_rtx, i0, i1);
2124 pop_obstacks ();
2125
2126 /* Don't touch const_double_chain if not inside any function. */
2127 if (current_function_decl != 0)
2128 {
2129 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2130 const_double_chain = r;
2131 }
2132
2133 return r;
2134 }
2135
2136 /* Return a CONST_DOUBLE for a specified `double' value
2137 and machine mode. */
2138
2139 rtx
2140 immed_real_const_1 (d, mode)
2141 REAL_VALUE_TYPE d;
2142 enum machine_mode mode;
2143 {
2144 union real_extract u;
2145 register rtx r;
2146
2147 /* Get the desired `double' value as a sequence of ints
2148 since that is how they are stored in a CONST_DOUBLE. */
2149
2150 u.d = d;
2151
2152 /* Detect special cases. But be careful we don't use a CONST_DOUBLE
2153 that's from a parent function since it may be in its constant pool. */
2154 if (REAL_VALUES_IDENTICAL (dconst0, d)
2155 && (cfun == 0 || decl_function_context (current_function_decl) == 0))
2156 return CONST0_RTX (mode);
2157
2158 /* Check for NaN first, because some ports (specifically the i386) do not
2159 emit correct ieee-fp code by default, and thus will generate a core
2160 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
2161 does a floating point comparison. */
2162 else if ((! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
2163 && (cfun == 0
2164 || decl_function_context (current_function_decl) == 0))
2165 return CONST1_RTX (mode);
2166
2167 if (sizeof u == sizeof (HOST_WIDE_INT))
2168 return immed_double_const (u.i[0], 0, mode);
2169 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
2170 return immed_double_const (u.i[0], u.i[1], mode);
2171
2172 /* The rest of this function handles the case where
2173 a float value requires more than 2 ints of space.
2174 It will be deleted as dead code on machines that don't need it. */
2175
2176 /* Search the chain for an existing CONST_DOUBLE with the right value.
2177 If one is found, return it. */
2178 if (cfun != 0)
2179 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
2180 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
2181 && GET_MODE (r) == mode)
2182 return r;
2183
2184 /* No; make a new one and add it to the chain.
2185
2186 We may be called by an optimizer which may be discarding any memory
2187 allocated during its processing (such as combine and loop). However,
2188 we will be leaving this constant on the chain, so we cannot tolerate
2189 freed memory. So switch to saveable_obstack for this allocation
2190 and then switch back if we were in current_obstack. */
2191 push_obstacks_nochange ();
2192 rtl_in_saveable_obstack ();
2193 r = rtx_alloc (CONST_DOUBLE);
2194 pop_obstacks ();
2195 PUT_MODE (r, mode);
2196 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
2197
2198 /* If we aren't inside a function, don't put r on the
2199 const_double_chain. */
2200 if (current_function_decl != 0)
2201 {
2202 CONST_DOUBLE_CHAIN (r) = const_double_chain;
2203 const_double_chain = r;
2204 }
2205 else
2206 CONST_DOUBLE_CHAIN (r) = NULL_RTX;
2207
2208 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
2209 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
2210 is only through force_const_mem. */
2211
2212 CONST_DOUBLE_MEM (r) = const0_rtx;
2213
2214 return r;
2215 }
2216
2217 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
2218 which must be a REAL_CST tree node. */
2219
2220 rtx
2221 immed_real_const (exp)
2222 tree exp;
2223 {
2224 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2225 }
2226
2227 /* At the end of a function, forget the memory-constants
2228 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2229 Also clear out real_constant_chain and clear out all the chain-pointers. */
2230
2231 void
2232 clear_const_double_mem ()
2233 {
2234 register rtx r, next;
2235
2236 for (r = const_double_chain; r; r = next)
2237 {
2238 next = CONST_DOUBLE_CHAIN (r);
2239 CONST_DOUBLE_CHAIN (r) = 0;
2240 CONST_DOUBLE_MEM (r) = cc0_rtx;
2241 }
2242 const_double_chain = 0;
2243 }
2244 \f
2245 /* Given an expression EXP with a constant value,
2246 reduce it to the sum of an assembler symbol and an integer.
2247 Store them both in the structure *VALUE.
2248 Abort if EXP does not reduce. */
2249
2250 struct addr_const
2251 {
2252 rtx base;
2253 HOST_WIDE_INT offset;
2254 };
2255
2256 static void
2257 decode_addr_const (exp, value)
2258 tree exp;
2259 struct addr_const *value;
2260 {
2261 register tree target = TREE_OPERAND (exp, 0);
2262 register int offset = 0;
2263 register rtx x;
2264
2265 while (1)
2266 {
2267 if (TREE_CODE (target) == COMPONENT_REF
2268 && host_integerp (byte_position (TREE_OPERAND (target, 1)), 0))
2269
2270 {
2271 offset += int_byte_position (TREE_OPERAND (target, 1));
2272 target = TREE_OPERAND (target, 0);
2273 }
2274 else if (TREE_CODE (target) == ARRAY_REF)
2275 {
2276 offset += (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (target)), 1)
2277 * tree_low_cst (TREE_OPERAND (target, 1), 0));
2278 target = TREE_OPERAND (target, 0);
2279 }
2280 else
2281 break;
2282 }
2283
2284 switch (TREE_CODE (target))
2285 {
2286 case VAR_DECL:
2287 case FUNCTION_DECL:
2288 x = DECL_RTL (target);
2289 break;
2290
2291 case LABEL_DECL:
2292 x = gen_rtx_MEM (FUNCTION_MODE,
2293 gen_rtx_LABEL_REF (VOIDmode,
2294 label_rtx (TREE_OPERAND (exp, 0))));
2295 break;
2296
2297 case REAL_CST:
2298 case STRING_CST:
2299 case COMPLEX_CST:
2300 case CONSTRUCTOR:
2301 case INTEGER_CST:
2302 x = TREE_CST_RTL (target);
2303 break;
2304
2305 default:
2306 abort ();
2307 }
2308
2309 if (GET_CODE (x) != MEM)
2310 abort ();
2311 x = XEXP (x, 0);
2312
2313 value->base = x;
2314 value->offset = offset;
2315 }
2316 \f
2317 /* Uniquize all constants that appear in memory.
2318 Each constant in memory thus far output is recorded
2319 in `const_hash_table' with a `struct constant_descriptor'
2320 that contains a polish representation of the value of
2321 the constant.
2322
2323 We cannot store the trees in the hash table
2324 because the trees may be temporary. */
2325
2326 struct constant_descriptor
2327 {
2328 struct constant_descriptor *next;
2329 char *label;
2330 rtx rtl;
2331 unsigned char contents[1];
2332 };
2333
2334 #define HASHBITS 30
2335 #define MAX_HASH_TABLE 1009
2336 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2337
2338 /* Mark a const_hash_table descriptor for GC. */
2339
2340 static void
2341 mark_const_hash_entry (ptr)
2342 void *ptr;
2343 {
2344 struct constant_descriptor *desc = * (struct constant_descriptor **) ptr;
2345
2346 while (desc)
2347 {
2348 ggc_mark_string ((const char *)desc->label);
2349 ggc_mark_rtx (desc->rtl);
2350 desc = desc->next;
2351 }
2352 }
2353
2354 /* Compute a hash code for a constant expression. */
2355
2356 static int
2357 const_hash (exp)
2358 tree exp;
2359 {
2360 register const char *p;
2361 register int len, hi, i;
2362 register enum tree_code code = TREE_CODE (exp);
2363
2364 /* Either set P and LEN to the address and len of something to hash and
2365 exit the switch or return a value. */
2366
2367 switch (code)
2368 {
2369 case INTEGER_CST:
2370 p = (char *) &TREE_INT_CST (exp);
2371 len = sizeof TREE_INT_CST (exp);
2372 break;
2373
2374 case REAL_CST:
2375 p = (char *) &TREE_REAL_CST (exp);
2376 len = sizeof TREE_REAL_CST (exp);
2377 break;
2378
2379 case STRING_CST:
2380 p = TREE_STRING_POINTER (exp);
2381 len = TREE_STRING_LENGTH (exp);
2382 break;
2383
2384 case COMPLEX_CST:
2385 return (const_hash (TREE_REALPART (exp)) * 5
2386 + const_hash (TREE_IMAGPART (exp)));
2387
2388 case CONSTRUCTOR:
2389 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2390 {
2391 char *tmp;
2392
2393 len = int_size_in_bytes (TREE_TYPE (exp));
2394 tmp = (char *) alloca (len);
2395 get_set_constructor_bytes (exp, (unsigned char *) tmp, len);
2396 p = tmp;
2397 break;
2398 }
2399 else
2400 {
2401 register tree link;
2402
2403 /* For record type, include the type in the hashing.
2404 We do not do so for array types
2405 because (1) the sizes of the elements are sufficient
2406 and (2) distinct array types can have the same constructor.
2407 Instead, we include the array size because the constructor could
2408 be shorter. */
2409 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2410 hi = ((unsigned long) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2411 % MAX_HASH_TABLE;
2412 else
2413 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2414 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2415
2416 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2417 if (TREE_VALUE (link))
2418 hi
2419 = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2420
2421 return hi;
2422 }
2423
2424 case ADDR_EXPR:
2425 {
2426 struct addr_const value;
2427
2428 decode_addr_const (exp, &value);
2429 if (GET_CODE (value.base) == SYMBOL_REF)
2430 {
2431 /* Don't hash the address of the SYMBOL_REF;
2432 only use the offset and the symbol name. */
2433 hi = value.offset;
2434 p = XSTR (value.base, 0);
2435 for (i = 0; p[i] != 0; i++)
2436 hi = ((hi * 613) + (unsigned) (p[i]));
2437 }
2438 else if (GET_CODE (value.base) == LABEL_REF)
2439 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2440 else
2441 abort();
2442
2443 hi &= (1 << HASHBITS) - 1;
2444 hi %= MAX_HASH_TABLE;
2445 }
2446 return hi;
2447
2448 case PLUS_EXPR:
2449 case MINUS_EXPR:
2450 return (const_hash (TREE_OPERAND (exp, 0)) * 9
2451 + const_hash (TREE_OPERAND (exp, 1)));
2452
2453 case NOP_EXPR:
2454 case CONVERT_EXPR:
2455 case NON_LVALUE_EXPR:
2456 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2457
2458 default:
2459 /* A language specific constant. Just hash the code. */
2460 return code % MAX_HASH_TABLE;
2461 }
2462
2463 /* Compute hashing function */
2464 hi = len;
2465 for (i = 0; i < len; i++)
2466 hi = ((hi * 613) + (unsigned) (p[i]));
2467
2468 hi &= (1 << HASHBITS) - 1;
2469 hi %= MAX_HASH_TABLE;
2470 return hi;
2471 }
2472 \f
2473 /* Compare a constant expression EXP with a constant-descriptor DESC.
2474 Return 1 if DESC describes a constant with the same value as EXP. */
2475
2476 static int
2477 compare_constant (exp, desc)
2478 tree exp;
2479 struct constant_descriptor *desc;
2480 {
2481 return 0 != compare_constant_1 (exp, desc->contents);
2482 }
2483
2484 /* Compare constant expression EXP with a substring P of a constant descriptor.
2485 If they match, return a pointer to the end of the substring matched.
2486 If they do not match, return 0.
2487
2488 Since descriptors are written in polish prefix notation,
2489 this function can be used recursively to test one operand of EXP
2490 against a subdescriptor, and if it succeeds it returns the
2491 address of the subdescriptor for the next operand. */
2492
2493 static const unsigned char *
2494 compare_constant_1 (exp, p)
2495 tree exp;
2496 const unsigned char *p;
2497 {
2498 register const unsigned char *strp;
2499 register int len;
2500 register enum tree_code code = TREE_CODE (exp);
2501
2502 if (code != (enum tree_code) *p++)
2503 return 0;
2504
2505 /* Either set STRP, P and LEN to pointers and length to compare and exit the
2506 switch, or return the result of the comparison. */
2507
2508 switch (code)
2509 {
2510 case INTEGER_CST:
2511 /* Integer constants are the same only if the same width of type. */
2512 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2513 return 0;
2514
2515 strp = (unsigned char *) &TREE_INT_CST (exp);
2516 len = sizeof TREE_INT_CST (exp);
2517 break;
2518
2519 case REAL_CST:
2520 /* Real constants are the same only if the same width of type. */
2521 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2522 return 0;
2523
2524 strp = (unsigned char *) &TREE_REAL_CST (exp);
2525 len = sizeof TREE_REAL_CST (exp);
2526 break;
2527
2528 case STRING_CST:
2529 if (flag_writable_strings)
2530 return 0;
2531
2532 if ((enum machine_mode) *p++ != TYPE_MODE (TREE_TYPE (exp)))
2533 return 0;
2534
2535 strp = (unsigned char *)TREE_STRING_POINTER (exp);
2536 len = TREE_STRING_LENGTH (exp);
2537 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2538 sizeof TREE_STRING_LENGTH (exp)))
2539 return 0;
2540
2541 p += sizeof TREE_STRING_LENGTH (exp);
2542 break;
2543
2544 case COMPLEX_CST:
2545 p = compare_constant_1 (TREE_REALPART (exp), p);
2546 if (p == 0)
2547 return 0;
2548
2549 return compare_constant_1 (TREE_IMAGPART (exp), p);
2550
2551 case CONSTRUCTOR:
2552 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2553 {
2554 int xlen = len = int_size_in_bytes (TREE_TYPE (exp));
2555 unsigned char *tmp = (unsigned char *) alloca (len);
2556
2557 get_set_constructor_bytes (exp, tmp, len);
2558 strp = (unsigned char *) tmp;
2559 if (bcmp ((char *) &xlen, p, sizeof xlen))
2560 return 0;
2561
2562 p += sizeof xlen;
2563 break;
2564 }
2565 else
2566 {
2567 register tree link;
2568 int length = list_length (CONSTRUCTOR_ELTS (exp));
2569 tree type;
2570 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2571 int have_purpose = 0;
2572
2573 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2574 if (TREE_PURPOSE (link))
2575 have_purpose = 1;
2576
2577 if (bcmp ((char *) &length, p, sizeof length))
2578 return 0;
2579
2580 p += sizeof length;
2581
2582 /* For record constructors, insist that the types match.
2583 For arrays, just verify both constructors are for arrays.
2584 Then insist that either both or none have any TREE_PURPOSE
2585 values. */
2586 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2587 type = TREE_TYPE (exp);
2588 else
2589 type = 0;
2590
2591 if (bcmp ((char *) &type, p, sizeof type))
2592 return 0;
2593
2594 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2595 {
2596 if (bcmp ((char *) &mode, p, sizeof mode))
2597 return 0;
2598
2599 p += sizeof mode;
2600 }
2601
2602 p += sizeof type;
2603
2604 if (bcmp ((char *) &have_purpose, p, sizeof have_purpose))
2605 return 0;
2606
2607 p += sizeof have_purpose;
2608
2609 /* For arrays, insist that the size in bytes match. */
2610 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2611 {
2612 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2613
2614 if (bcmp ((char *) &size, p, sizeof size))
2615 return 0;
2616
2617 p += sizeof size;
2618 }
2619
2620 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2621 {
2622 if (TREE_VALUE (link))
2623 {
2624 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2625 return 0;
2626 }
2627 else
2628 {
2629 tree zero = 0;
2630
2631 if (bcmp ((char *) &zero, p, sizeof zero))
2632 return 0;
2633
2634 p += sizeof zero;
2635 }
2636
2637 if (TREE_PURPOSE (link)
2638 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2639 {
2640 if (bcmp ((char *) &TREE_PURPOSE (link), p,
2641 sizeof TREE_PURPOSE (link)))
2642 return 0;
2643
2644 p += sizeof TREE_PURPOSE (link);
2645 }
2646 else if (TREE_PURPOSE (link))
2647 {
2648 if ((p = compare_constant_1 (TREE_PURPOSE (link), p)) == 0)
2649 return 0;
2650 }
2651 else if (have_purpose)
2652 {
2653 int zero = 0;
2654
2655 if (bcmp ((char *) &zero, p, sizeof zero))
2656 return 0;
2657
2658 p += sizeof zero;
2659 }
2660 }
2661
2662 return p;
2663 }
2664
2665 case ADDR_EXPR:
2666 {
2667 struct addr_const value;
2668
2669 decode_addr_const (exp, &value);
2670 strp = (unsigned char *) &value.offset;
2671 len = sizeof value.offset;
2672 /* Compare the offset. */
2673 while (--len >= 0)
2674 if (*p++ != *strp++)
2675 return 0;
2676
2677 /* Compare symbol name. */
2678 strp = (unsigned char *) XSTR (value.base, 0);
2679 len = strlen ((char *) strp) + 1;
2680 }
2681 break;
2682
2683 case PLUS_EXPR:
2684 case MINUS_EXPR:
2685 case RANGE_EXPR:
2686 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2687 if (p == 0)
2688 return 0;
2689
2690 return compare_constant_1 (TREE_OPERAND (exp, 1), p);
2691
2692 case NOP_EXPR:
2693 case CONVERT_EXPR:
2694 case NON_LVALUE_EXPR:
2695 return compare_constant_1 (TREE_OPERAND (exp, 0), p);
2696
2697 default:
2698 if (lang_expand_constant)
2699 {
2700 exp = (*lang_expand_constant) (exp);
2701 return compare_constant_1 (exp, p);
2702 }
2703 return 0;
2704 }
2705
2706 /* Compare constant contents. */
2707 while (--len >= 0)
2708 if (*p++ != *strp++)
2709 return 0;
2710
2711 return p;
2712 }
2713 \f
2714 /* Construct a constant descriptor for the expression EXP.
2715 It is up to the caller to enter the descriptor in the hash table. */
2716
2717 static struct constant_descriptor *
2718 record_constant (exp)
2719 tree exp;
2720 {
2721 struct constant_descriptor *next = 0;
2722 char *label = 0;
2723 rtx rtl = 0;
2724
2725 /* Make a struct constant_descriptor. The first three pointers will
2726 be filled in later. Here we just leave space for them. */
2727
2728 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2729 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2730 obstack_grow (&permanent_obstack, (char *) &rtl, sizeof rtl);
2731 record_constant_1 (exp);
2732 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2733 }
2734
2735 /* Add a description of constant expression EXP
2736 to the object growing in `permanent_obstack'.
2737 No need to return its address; the caller will get that
2738 from the obstack when the object is complete. */
2739
2740 static void
2741 record_constant_1 (exp)
2742 tree exp;
2743 {
2744 register unsigned char *strp;
2745 register int len;
2746 register enum tree_code code = TREE_CODE (exp);
2747
2748 obstack_1grow (&permanent_obstack, (unsigned int) code);
2749
2750 switch (code)
2751 {
2752 case INTEGER_CST:
2753 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2754 strp = (unsigned char *) &TREE_INT_CST (exp);
2755 len = sizeof TREE_INT_CST (exp);
2756 break;
2757
2758 case REAL_CST:
2759 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2760 strp = (unsigned char *) &TREE_REAL_CST (exp);
2761 len = sizeof TREE_REAL_CST (exp);
2762 break;
2763
2764 case STRING_CST:
2765 if (flag_writable_strings)
2766 return;
2767
2768 obstack_1grow (&permanent_obstack, TYPE_MODE (TREE_TYPE (exp)));
2769 strp = (unsigned char *) TREE_STRING_POINTER (exp);
2770 len = TREE_STRING_LENGTH (exp);
2771 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2772 sizeof TREE_STRING_LENGTH (exp));
2773 break;
2774
2775 case COMPLEX_CST:
2776 record_constant_1 (TREE_REALPART (exp));
2777 record_constant_1 (TREE_IMAGPART (exp));
2778 return;
2779
2780 case CONSTRUCTOR:
2781 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2782 {
2783 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2784 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2785 obstack_blank (&permanent_obstack, nbytes);
2786 get_set_constructor_bytes
2787 (exp, (unsigned char *) permanent_obstack.next_free-nbytes,
2788 nbytes);
2789 return;
2790 }
2791 else
2792 {
2793 register tree link;
2794 int length = list_length (CONSTRUCTOR_ELTS (exp));
2795 enum machine_mode mode = TYPE_MODE (TREE_TYPE (exp));
2796 tree type;
2797 int have_purpose = 0;
2798
2799 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2800 if (TREE_PURPOSE (link))
2801 have_purpose = 1;
2802
2803 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2804
2805 /* For record constructors, insist that the types match.
2806 For arrays, just verify both constructors are for arrays
2807 of the same mode. Then insist that either both or none
2808 have any TREE_PURPOSE values. */
2809 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2810 type = TREE_TYPE (exp);
2811 else
2812 type = 0;
2813
2814 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2815 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2816 obstack_grow (&permanent_obstack, &mode, sizeof mode);
2817
2818 obstack_grow (&permanent_obstack, (char *) &have_purpose,
2819 sizeof have_purpose);
2820
2821 /* For arrays, insist that the size in bytes match. */
2822 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2823 {
2824 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (exp));
2825 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2826 }
2827
2828 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2829 {
2830 if (TREE_VALUE (link))
2831 record_constant_1 (TREE_VALUE (link));
2832 else
2833 {
2834 tree zero = 0;
2835
2836 obstack_grow (&permanent_obstack,
2837 (char *) &zero, sizeof zero);
2838 }
2839
2840 if (TREE_PURPOSE (link)
2841 && TREE_CODE (TREE_PURPOSE (link)) == FIELD_DECL)
2842 obstack_grow (&permanent_obstack,
2843 (char *) &TREE_PURPOSE (link),
2844 sizeof TREE_PURPOSE (link));
2845 else if (TREE_PURPOSE (link))
2846 record_constant_1 (TREE_PURPOSE (link));
2847 else if (have_purpose)
2848 {
2849 int zero = 0;
2850
2851 obstack_grow (&permanent_obstack,
2852 (char *) &zero, sizeof zero);
2853 }
2854 }
2855 }
2856 return;
2857
2858 case ADDR_EXPR:
2859 {
2860 struct addr_const value;
2861
2862 decode_addr_const (exp, &value);
2863 /* Record the offset. */
2864 obstack_grow (&permanent_obstack,
2865 (char *) &value.offset, sizeof value.offset);
2866
2867 switch (GET_CODE (value.base))
2868 {
2869 case SYMBOL_REF:
2870 /* Record the symbol name. */
2871 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2872 strlen (XSTR (value.base, 0)) + 1);
2873 break;
2874 case LABEL_REF:
2875 /* Record the address of the CODE_LABEL. It may not have
2876 been emitted yet, so it's UID may be zero. But pointer
2877 identity is good enough. */
2878 obstack_grow (&permanent_obstack, &XEXP (value.base, 0),
2879 sizeof (rtx));
2880 break;
2881 default:
2882 abort ();
2883 }
2884 }
2885 return;
2886
2887 case PLUS_EXPR:
2888 case MINUS_EXPR:
2889 case RANGE_EXPR:
2890 record_constant_1 (TREE_OPERAND (exp, 0));
2891 record_constant_1 (TREE_OPERAND (exp, 1));
2892 return;
2893
2894 case NOP_EXPR:
2895 case CONVERT_EXPR:
2896 case NON_LVALUE_EXPR:
2897 record_constant_1 (TREE_OPERAND (exp, 0));
2898 return;
2899
2900 default:
2901 if (lang_expand_constant)
2902 {
2903 exp = (*lang_expand_constant) (exp);
2904 record_constant_1 (exp);
2905 }
2906 return;
2907 }
2908
2909 /* Record constant contents. */
2910 obstack_grow (&permanent_obstack, strp, len);
2911 }
2912 \f
2913 /* Record a list of constant expressions that were passed to
2914 output_constant_def but that could not be output right away. */
2915
2916 struct deferred_constant
2917 {
2918 struct deferred_constant *next;
2919 tree exp;
2920 int reloc;
2921 int labelno;
2922 };
2923
2924 static struct deferred_constant *deferred_constants;
2925
2926 /* Another list of constants which should be output after the
2927 function. */
2928 static struct deferred_constant *after_function_constants;
2929
2930 /* Nonzero means defer output of addressed subconstants
2931 (i.e., those for which output_constant_def is called.) */
2932 static int defer_addressed_constants_flag;
2933
2934 /* Start deferring output of subconstants. */
2935
2936 void
2937 defer_addressed_constants ()
2938 {
2939 defer_addressed_constants_flag++;
2940 }
2941
2942 /* Stop deferring output of subconstants,
2943 and output now all those that have been deferred. */
2944
2945 void
2946 output_deferred_addressed_constants ()
2947 {
2948 struct deferred_constant *p, *next;
2949
2950 defer_addressed_constants_flag--;
2951
2952 if (defer_addressed_constants_flag > 0)
2953 return;
2954
2955 for (p = deferred_constants; p; p = next)
2956 {
2957 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2958 next = p->next;
2959 free (p);
2960 }
2961
2962 deferred_constants = 0;
2963 }
2964
2965 /* Output any constants which should appear after a function. */
2966
2967 static void
2968 output_after_function_constants ()
2969 {
2970 struct deferred_constant *p, *next;
2971
2972 for (p = after_function_constants; p; p = next)
2973 {
2974 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2975 next = p->next;
2976 free (p);
2977 }
2978
2979 after_function_constants = 0;
2980 }
2981
2982 /* Make a copy of the whole tree structure for a constant.
2983 This handles the same types of nodes that compare_constant
2984 and record_constant handle. */
2985
2986 static tree
2987 copy_constant (exp)
2988 tree exp;
2989 {
2990 switch (TREE_CODE (exp))
2991 {
2992 case ADDR_EXPR:
2993 /* For ADDR_EXPR, we do not want to copy the decl whose address
2994 is requested. We do want to copy constants though. */
2995 if (TREE_CODE_CLASS (TREE_CODE (TREE_OPERAND (exp, 0))) == 'c')
2996 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2997 copy_constant (TREE_OPERAND (exp, 0)));
2998 else
2999 return copy_node (exp);
3000
3001 case INTEGER_CST:
3002 case REAL_CST:
3003 case STRING_CST:
3004 return copy_node (exp);
3005
3006 case COMPLEX_CST:
3007 return build_complex (TREE_TYPE (exp),
3008 copy_constant (TREE_REALPART (exp)),
3009 copy_constant (TREE_IMAGPART (exp)));
3010
3011 case PLUS_EXPR:
3012 case MINUS_EXPR:
3013 return build (TREE_CODE (exp), TREE_TYPE (exp),
3014 copy_constant (TREE_OPERAND (exp, 0)),
3015 copy_constant (TREE_OPERAND (exp, 1)));
3016
3017 case NOP_EXPR:
3018 case CONVERT_EXPR:
3019 case NON_LVALUE_EXPR:
3020 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
3021 copy_constant (TREE_OPERAND (exp, 0)));
3022
3023 case CONSTRUCTOR:
3024 {
3025 tree copy = copy_node (exp);
3026 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
3027 tree tail;
3028
3029 CONSTRUCTOR_ELTS (copy) = list;
3030 for (tail = list; tail; tail = TREE_CHAIN (tail))
3031 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
3032 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
3033 for (tail = list; tail; tail = TREE_CHAIN (tail))
3034 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
3035
3036 return copy;
3037 }
3038
3039 default:
3040 abort ();
3041 }
3042 }
3043 \f
3044 /* Return an rtx representing a reference to constant data in memory
3045 for the constant expression EXP.
3046
3047 If assembler code for such a constant has already been output,
3048 return an rtx to refer to it.
3049 Otherwise, output such a constant in memory (or defer it for later)
3050 and generate an rtx for it.
3051
3052 The TREE_CST_RTL of EXP is set up to point to that rtx.
3053 The const_hash_table records which constants already have label strings. */
3054
3055 rtx
3056 output_constant_def (exp)
3057 tree exp;
3058 {
3059 register int hash;
3060 register struct constant_descriptor *desc;
3061 char label[256];
3062 int reloc;
3063 int found = 1;
3064
3065 if (TREE_CST_RTL (exp))
3066 return TREE_CST_RTL (exp);
3067
3068 /* Make sure any other constants whose addresses appear in EXP
3069 are assigned label numbers. */
3070
3071 reloc = output_addressed_constants (exp);
3072
3073 /* Compute hash code of EXP. Search the descriptors for that hash code
3074 to see if any of them describes EXP. If yes, the descriptor records
3075 the label number already assigned. */
3076
3077 hash = const_hash (exp) % MAX_HASH_TABLE;
3078
3079 for (desc = const_hash_table[hash]; desc; desc = desc->next)
3080 if (compare_constant (exp, desc))
3081 break;
3082
3083 if (desc == 0)
3084 {
3085 /* No constant equal to EXP is known to have been output.
3086 Make a constant descriptor to enter EXP in the hash table.
3087 Assign the label number and record it in the descriptor for
3088 future calls to this function to find. */
3089
3090 /* Create a string containing the label name, in LABEL. */
3091 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3092
3093 desc = record_constant (exp);
3094 desc->next = const_hash_table[hash];
3095 desc->label = ggc_alloc_string (label, -1);
3096 const_hash_table[hash] = desc;
3097
3098 /* We have a symbol name; construct the SYMBOL_REF and the MEM
3099 in the permanent obstack. We could also construct this in the
3100 obstack of EXP and put it into TREE_CST_RTL, but we have no way
3101 of knowing what obstack it is (e.g., it might be in a function
3102 obstack of a function we are nested inside). */
3103
3104 push_obstacks_nochange ();
3105 end_temporary_allocation ();
3106
3107 desc->rtl
3108 = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (exp)),
3109 gen_rtx_SYMBOL_REF (Pmode, desc->label));
3110
3111 set_mem_attributes (desc->rtl, exp, 1);
3112 pop_obstacks ();
3113
3114 found = 0;
3115 }
3116
3117 TREE_CST_RTL (exp) = desc->rtl;
3118
3119 /* Optionally set flags or add text to the name to record information
3120 such as that it is a function name. If the name is changed, the macro
3121 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
3122 #ifdef ENCODE_SECTION_INFO
3123 ENCODE_SECTION_INFO (exp);
3124 #endif
3125
3126 /* If this is the first time we've seen this particular constant,
3127 output it (or defer its output for later). */
3128 if (! found)
3129 {
3130 int after_function = 0;
3131
3132 #ifdef CONSTANT_AFTER_FUNCTION_P
3133 if (current_function_decl != 0
3134 && CONSTANT_AFTER_FUNCTION_P (exp))
3135 after_function = 1;
3136 #endif
3137
3138 if (defer_addressed_constants_flag || after_function)
3139 {
3140 struct deferred_constant *p;
3141 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
3142
3143 push_obstacks_nochange ();
3144 suspend_momentary ();
3145 p->exp = copy_constant (exp);
3146 pop_obstacks ();
3147 p->reloc = reloc;
3148 p->labelno = const_labelno++;
3149 if (after_function)
3150 {
3151 p->next = after_function_constants;
3152 after_function_constants = p;
3153 }
3154 else
3155 {
3156 p->next = deferred_constants;
3157 deferred_constants = p;
3158 }
3159 }
3160 else
3161 {
3162 /* Do no output if -fsyntax-only. */
3163 if (! flag_syntax_only)
3164 output_constant_def_contents (exp, reloc, const_labelno);
3165 ++const_labelno;
3166 }
3167 }
3168
3169 return TREE_CST_RTL (exp);
3170 }
3171
3172 /* Now output assembler code to define the label for EXP,
3173 and follow it with the data of EXP. */
3174
3175 static void
3176 output_constant_def_contents (exp, reloc, labelno)
3177 tree exp;
3178 int reloc;
3179 int labelno;
3180 {
3181 int align;
3182
3183 if (IN_NAMED_SECTION (exp))
3184 named_section (exp, NULL, reloc);
3185 else
3186 {
3187 /* First switch to text section, except for writable strings. */
3188 #ifdef SELECT_SECTION
3189 SELECT_SECTION (exp, reloc);
3190 #else
3191 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
3192 || (flag_pic && reloc))
3193 data_section ();
3194 else
3195 readonly_data_section ();
3196 #endif
3197 }
3198
3199 /* Align the location counter as required by EXP's data type. */
3200 align = TYPE_ALIGN (TREE_TYPE (exp));
3201 #ifdef CONSTANT_ALIGNMENT
3202 align = CONSTANT_ALIGNMENT (exp, align);
3203 #endif
3204
3205 if (align > BITS_PER_UNIT)
3206 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
3207
3208 /* Output the label itself. */
3209 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
3210
3211 /* Output the value of EXP. */
3212 output_constant (exp,
3213 (TREE_CODE (exp) == STRING_CST
3214 ? TREE_STRING_LENGTH (exp)
3215 : int_size_in_bytes (TREE_TYPE (exp))));
3216
3217 }
3218 \f
3219 /* Structure to represent sufficient information about a constant so that
3220 it can be output when the constant pool is output, so that function
3221 integration can be done, and to simplify handling on machines that reference
3222 constant pool as base+displacement. */
3223
3224 struct pool_constant
3225 {
3226 struct constant_descriptor *desc;
3227 struct pool_constant *next;
3228 enum machine_mode mode;
3229 rtx constant;
3230 int labelno;
3231 int align;
3232 int offset;
3233 int mark;
3234 };
3235
3236 /* Structure used to maintain hash table mapping symbols used to their
3237 corresponding constants. */
3238
3239 struct pool_sym
3240 {
3241 char *label;
3242 struct pool_constant *pool;
3243 struct pool_sym *next;
3244 };
3245
3246 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
3247 The argument is XSTR (... , 0) */
3248
3249 #define SYMHASH(LABEL) \
3250 ((((unsigned long) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
3251 \f
3252 /* Initialize constant pool hashing for a new function. */
3253
3254 void
3255 init_varasm_status (f)
3256 struct function *f;
3257 {
3258 struct varasm_status *p;
3259 p = (struct varasm_status *) xmalloc (sizeof (struct varasm_status));
3260 f->varasm = p;
3261 p->x_const_rtx_hash_table
3262 = ((struct constant_descriptor **)
3263 xmalloc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
3264 p->x_const_rtx_sym_hash_table
3265 = ((struct pool_sym **)
3266 xmalloc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
3267 bzero ((char *) p->x_const_rtx_hash_table,
3268 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
3269 bzero ((char *) p->x_const_rtx_sym_hash_table,
3270 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
3271
3272 p->x_first_pool = p->x_last_pool = 0;
3273 p->x_pool_offset = 0;
3274 p->x_const_double_chain = 0;
3275 }
3276
3277 /* Mark PC for GC. */
3278
3279 static void
3280 mark_pool_constant (pc)
3281 struct pool_constant *pc;
3282 {
3283 while (pc)
3284 {
3285 ggc_mark_rtx (pc->constant);
3286 pc = pc->next;
3287 }
3288 }
3289
3290 /* Mark PPS for GC. */
3291
3292 static void
3293 mark_pool_sym_hash_table (pps)
3294 struct pool_sym **pps;
3295 {
3296 struct pool_sym *ps;
3297 int i;
3298
3299 for (i = 0; i < MAX_RTX_HASH_TABLE; ++i)
3300 for (ps = pps[i]; ps ; ps = ps->next)
3301 ggc_mark_string (ps->label);
3302 }
3303
3304 /* Mark P for GC. */
3305
3306 void
3307 mark_varasm_status (p)
3308 struct varasm_status *p;
3309 {
3310 if (p == NULL)
3311 return;
3312
3313 mark_pool_constant (p->x_first_pool);
3314 mark_pool_sym_hash_table (p->x_const_rtx_sym_hash_table);
3315 ggc_mark_rtx (p->x_const_double_chain);
3316 }
3317
3318 /* Clear out all parts of the state in F that can safely be discarded
3319 after the function has been compiled, to let garbage collection
3320 reclaim the memory. */
3321
3322 void
3323 free_varasm_status (f)
3324 struct function *f;
3325 {
3326 struct varasm_status *p;
3327
3328 p = f->varasm;
3329 free (p->x_const_rtx_hash_table);
3330 free (p->x_const_rtx_sym_hash_table);
3331 free (p);
3332 f->varasm = NULL;
3333 }
3334 \f
3335 enum kind { RTX_DOUBLE, RTX_INT };
3336
3337 struct rtx_const
3338 {
3339 #ifdef ONLY_INT_FIELDS
3340 unsigned int kind : 16;
3341 unsigned int mode : 16;
3342 #else
3343 enum kind kind : 16;
3344 enum machine_mode mode : 16;
3345 #endif
3346 union {
3347 union real_extract du;
3348 struct addr_const addr;
3349 struct {HOST_WIDE_INT high, low;} di;
3350 } un;
3351 };
3352
3353 /* Express an rtx for a constant integer (perhaps symbolic)
3354 as the sum of a symbol or label plus an explicit integer.
3355 They are stored into VALUE. */
3356
3357 static void
3358 decode_rtx_const (mode, x, value)
3359 enum machine_mode mode;
3360 rtx x;
3361 struct rtx_const *value;
3362 {
3363 /* Clear the whole structure, including any gaps. */
3364
3365 {
3366 int *p = (int *) value;
3367 int *end = (int *) (value + 1);
3368 while (p < end)
3369 *p++ = 0;
3370 }
3371
3372 value->kind = RTX_INT; /* Most usual kind. */
3373 value->mode = mode;
3374
3375 switch (GET_CODE (x))
3376 {
3377 case CONST_DOUBLE:
3378 value->kind = RTX_DOUBLE;
3379 if (GET_MODE (x) != VOIDmode)
3380 {
3381 value->mode = GET_MODE (x);
3382 bcopy ((char *) &CONST_DOUBLE_LOW (x),
3383 (char *) &value->un.du, sizeof value->un.du);
3384 }
3385 else
3386 {
3387 value->un.di.low = CONST_DOUBLE_LOW (x);
3388 value->un.di.high = CONST_DOUBLE_HIGH (x);
3389 }
3390 break;
3391
3392 case CONST_INT:
3393 value->un.addr.offset = INTVAL (x);
3394 break;
3395
3396 case SYMBOL_REF:
3397 case LABEL_REF:
3398 case PC:
3399 value->un.addr.base = x;
3400 break;
3401
3402 case CONST:
3403 x = XEXP (x, 0);
3404 if (GET_CODE (x) == PLUS)
3405 {
3406 value->un.addr.base = XEXP (x, 0);
3407 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3408 abort ();
3409 value->un.addr.offset = INTVAL (XEXP (x, 1));
3410 }
3411 else if (GET_CODE (x) == MINUS)
3412 {
3413 value->un.addr.base = XEXP (x, 0);
3414 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
3415 abort ();
3416 value->un.addr.offset = - INTVAL (XEXP (x, 1));
3417 }
3418 else
3419 abort ();
3420 break;
3421
3422 default:
3423 abort ();
3424 }
3425
3426 if (value->kind == RTX_INT && value->un.addr.base != 0)
3427 switch (GET_CODE (value->un.addr.base))
3428 {
3429 case SYMBOL_REF:
3430 /* Use the string's address, not the SYMBOL_REF's address,
3431 for the sake of addresses of library routines. */
3432 value->un.addr.base = (rtx) XSTR (value->un.addr.base, 0);
3433 break;
3434
3435 case LABEL_REF:
3436 /* For a LABEL_REF, compare labels. */
3437 value->un.addr.base = XEXP (value->un.addr.base, 0);
3438
3439 default:
3440 break;
3441 }
3442 }
3443
3444 /* Given a MINUS expression, simplify it if both sides
3445 include the same symbol. */
3446
3447 rtx
3448 simplify_subtraction (x)
3449 rtx x;
3450 {
3451 struct rtx_const val0, val1;
3452
3453 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
3454 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
3455
3456 if (val0.un.addr.base == val1.un.addr.base)
3457 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
3458 return x;
3459 }
3460
3461 /* Compute a hash code for a constant RTL expression. */
3462
3463 static int
3464 const_hash_rtx (mode, x)
3465 enum machine_mode mode;
3466 rtx x;
3467 {
3468 register int hi;
3469 register size_t i;
3470
3471 struct rtx_const value;
3472 decode_rtx_const (mode, x, &value);
3473
3474 /* Compute hashing function */
3475 hi = 0;
3476 for (i = 0; i < sizeof value / sizeof (int); i++)
3477 hi += ((int *) &value)[i];
3478
3479 hi &= (1 << HASHBITS) - 1;
3480 hi %= MAX_RTX_HASH_TABLE;
3481 return hi;
3482 }
3483
3484 /* Compare a constant rtl object X with a constant-descriptor DESC.
3485 Return 1 if DESC describes a constant with the same value as X. */
3486
3487 static int
3488 compare_constant_rtx (mode, x, desc)
3489 enum machine_mode mode;
3490 rtx x;
3491 struct constant_descriptor *desc;
3492 {
3493 register int *p = (int *) desc->contents;
3494 register int *strp;
3495 register int len;
3496 struct rtx_const value;
3497
3498 decode_rtx_const (mode, x, &value);
3499 strp = (int *) &value;
3500 len = sizeof value / sizeof (int);
3501
3502 /* Compare constant contents. */
3503 while (--len >= 0)
3504 if (*p++ != *strp++)
3505 return 0;
3506
3507 return 1;
3508 }
3509
3510 /* Construct a constant descriptor for the rtl-expression X.
3511 It is up to the caller to enter the descriptor in the hash table. */
3512
3513 static struct constant_descriptor *
3514 record_constant_rtx (mode, x)
3515 enum machine_mode mode;
3516 rtx x;
3517 {
3518 struct constant_descriptor *ptr;
3519 char *label;
3520 rtx rtl;
3521 struct rtx_const value;
3522
3523 decode_rtx_const (mode, x, &value);
3524
3525 /* Put these things in the saveable obstack so we can ensure it won't
3526 be freed if we are called from combine or some other phase that discards
3527 memory allocated from function_obstack (current_obstack). */
3528 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3529 obstack_grow (saveable_obstack, &label, sizeof label);
3530 obstack_grow (saveable_obstack, &rtl, sizeof rtl);
3531
3532 /* Record constant contents. */
3533 obstack_grow (saveable_obstack, &value, sizeof value);
3534
3535 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3536 }
3537 \f
3538 /* Given a constant rtx X, make (or find) a memory constant for its value
3539 and return a MEM rtx to refer to it in memory. */
3540
3541 rtx
3542 force_const_mem (mode, x)
3543 enum machine_mode mode;
3544 rtx x;
3545 {
3546 register int hash;
3547 register struct constant_descriptor *desc;
3548 char label[256];
3549 char *found = 0;
3550 rtx def;
3551
3552 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3553 (this will always be true for floating CONST_DOUBLEs that have been
3554 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3555 use the previous copy. Otherwise, make a new one. Note that in
3556 the unlikely event that this same CONST_DOUBLE is used in two different
3557 modes in an alternating fashion, we will allocate a lot of different
3558 memory locations, but this should be extremely rare. */
3559
3560 if (GET_CODE (x) == CONST_DOUBLE
3561 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3562 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3563 return CONST_DOUBLE_MEM (x);
3564
3565 /* Compute hash code of X. Search the descriptors for that hash code
3566 to see if any of them describes X. If yes, the descriptor records
3567 the label number already assigned. */
3568
3569 hash = const_hash_rtx (mode, x);
3570
3571 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3572 if (compare_constant_rtx (mode, x, desc))
3573 {
3574 found = desc->label;
3575 break;
3576 }
3577
3578 if (found == 0)
3579 {
3580 register struct pool_constant *pool;
3581 register struct pool_sym *sym;
3582 int align;
3583
3584 /* No constant equal to X is known to have been output.
3585 Make a constant descriptor to enter X in the hash table.
3586 Assign the label number and record it in the descriptor for
3587 future calls to this function to find. */
3588
3589 desc = record_constant_rtx (mode, x);
3590 desc->next = const_rtx_hash_table[hash];
3591 const_rtx_hash_table[hash] = desc;
3592
3593 /* Align the location counter as required by EXP's data type. */
3594 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3595 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3596 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3597 #ifdef CONSTANT_ALIGNMENT
3598 align = CONSTANT_ALIGNMENT (make_tree (type_for_mode (mode, 0), x),
3599 align * BITS_PER_UNIT) / BITS_PER_UNIT;
3600 #endif
3601
3602 pool_offset += align - 1;
3603 pool_offset &= ~ (align - 1);
3604
3605 /* If RTL is not being placed into the saveable obstack, make a
3606 copy of X that is in the saveable obstack in case we are
3607 being called from combine or some other phase that discards
3608 memory it allocates. We used to only do this if it is a
3609 CONST; however, reload can allocate a CONST_INT when
3610 eliminating registers. */
3611 if (rtl_obstack != saveable_obstack
3612 && (GET_CODE (x) == CONST || GET_CODE (x) == CONST_INT))
3613 {
3614 push_obstacks_nochange ();
3615 rtl_in_saveable_obstack ();
3616
3617 if (GET_CODE (x) == CONST)
3618 x = gen_rtx_CONST (GET_MODE (x),
3619 gen_rtx_PLUS (GET_MODE (x),
3620 XEXP (XEXP (x, 0), 0),
3621 XEXP (XEXP (x, 0), 1)));
3622 else
3623 x = GEN_INT (INTVAL (x));
3624
3625 pop_obstacks ();
3626 }
3627
3628 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3629
3630 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3631 pool->desc = desc;
3632 pool->constant = x;
3633 pool->mode = mode;
3634 pool->labelno = const_labelno;
3635 pool->align = align;
3636 pool->offset = pool_offset;
3637 pool->mark = 1;
3638 pool->next = 0;
3639
3640 if (last_pool == 0)
3641 first_pool = pool;
3642 else
3643 last_pool->next = pool;
3644
3645 last_pool = pool;
3646 pool_offset += GET_MODE_SIZE (mode);
3647
3648 /* Create a string containing the label name, in LABEL. */
3649 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3650
3651 ++const_labelno;
3652
3653 desc->label = found = ggc_alloc_string (label, -1);
3654
3655 /* Add label to symbol hash table. */
3656 hash = SYMHASH (found);
3657 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3658 sym->label = found;
3659 sym->pool = pool;
3660 sym->next = const_rtx_sym_hash_table[hash];
3661 const_rtx_sym_hash_table[hash] = sym;
3662 }
3663
3664 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3665
3666 def = gen_rtx_MEM (mode, gen_rtx_SYMBOL_REF (Pmode, found));
3667 set_mem_attributes (def, type_for_mode (mode, 0), 1);
3668 RTX_UNCHANGING_P (def) = 1;
3669
3670 /* Mark the symbol_ref as belonging to this constants pool. */
3671 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3672 current_function_uses_const_pool = 1;
3673
3674 if (GET_CODE (x) == CONST_DOUBLE)
3675 {
3676 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3677 {
3678 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3679 const_double_chain = x;
3680 }
3681 CONST_DOUBLE_MEM (x) = def;
3682 }
3683
3684 return def;
3685 }
3686 \f
3687 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3688 the corresponding pool_constant structure. */
3689
3690 static struct pool_constant *
3691 find_pool_constant (f, addr)
3692 struct function *f;
3693 rtx addr;
3694 {
3695 struct pool_sym *sym;
3696 const char *label = XSTR (addr, 0);
3697
3698 for (sym = f->varasm->x_const_rtx_sym_hash_table[SYMHASH (label)]; sym;
3699 sym = sym->next)
3700 if (sym->label == label)
3701 return sym->pool;
3702
3703 abort ();
3704 }
3705
3706 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3707
3708 rtx
3709 get_pool_constant (addr)
3710 rtx addr;
3711 {
3712 return (find_pool_constant (cfun, addr))->constant;
3713 }
3714
3715 /* Likewise, but for the constant pool of a specific function. */
3716
3717 rtx
3718 get_pool_constant_for_function (f, addr)
3719 struct function *f;
3720 rtx addr;
3721 {
3722 return (find_pool_constant (f, addr))->constant;
3723 }
3724
3725 /* Similar, return the mode. */
3726
3727 enum machine_mode
3728 get_pool_mode (addr)
3729 rtx addr;
3730 {
3731 return (find_pool_constant (cfun, addr))->mode;
3732 }
3733
3734 enum machine_mode
3735 get_pool_mode_for_function (f, addr)
3736 struct function *f;
3737 rtx addr;
3738 {
3739 return (find_pool_constant (f, addr))->mode;
3740 }
3741
3742 /* Similar, return the offset in the constant pool. */
3743
3744 int
3745 get_pool_offset (addr)
3746 rtx addr;
3747 {
3748 return (find_pool_constant (cfun, addr))->offset;
3749 }
3750
3751 /* Return the size of the constant pool. */
3752
3753 int
3754 get_pool_size ()
3755 {
3756 return pool_offset;
3757 }
3758 \f
3759 /* Write all the constants in the constant pool. */
3760
3761 void
3762 output_constant_pool (fnname, fndecl)
3763 const char *fnname ATTRIBUTE_UNUSED;
3764 tree fndecl ATTRIBUTE_UNUSED;
3765 {
3766 struct pool_constant *pool;
3767 rtx x;
3768 union real_extract u;
3769
3770 /* It is possible for gcc to call force_const_mem and then to later
3771 discard the instructions which refer to the constant. In such a
3772 case we do not need to output the constant. */
3773 mark_constant_pool ();
3774
3775 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3776 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3777 #endif
3778
3779 for (pool = first_pool; pool; pool = pool->next)
3780 {
3781 rtx tmp;
3782
3783 x = pool->constant;
3784
3785 if (! pool->mark)
3786 continue;
3787
3788 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3789 whose CODE_LABEL has been deleted. This can occur if a jump table
3790 is eliminated by optimization. If so, write a constant of zero
3791 instead. Note that this can also happen by turning the
3792 CODE_LABEL into a NOTE. */
3793 /* ??? This seems completely and utterly wrong. Certainly it's
3794 not true for NOTE_INSN_DELETED_LABEL, but I disbelieve proper
3795 functioning even with INSN_DELETED_P and friends. */
3796
3797 tmp = x;
3798 switch (GET_CODE (x))
3799 {
3800 case CONST:
3801 if (GET_CODE (XEXP (x, 0)) != PLUS
3802 || GET_CODE (XEXP (XEXP (x, 0), 0)) != LABEL_REF)
3803 break;
3804 tmp = XEXP (XEXP (x, 0), 0);
3805 /* FALLTHRU */
3806
3807 case LABEL_REF:
3808 tmp = XEXP (x, 0);
3809 if (INSN_DELETED_P (tmp)
3810 || (GET_CODE (tmp) == NOTE
3811 && NOTE_LINE_NUMBER (tmp) == NOTE_INSN_DELETED))
3812 {
3813 abort ();
3814 x = const0_rtx;
3815 }
3816 break;
3817
3818 default:
3819 break;
3820 }
3821
3822 /* First switch to correct section. */
3823 #ifdef SELECT_RTX_SECTION
3824 SELECT_RTX_SECTION (pool->mode, x);
3825 #else
3826 readonly_data_section ();
3827 #endif
3828
3829 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3830 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3831 pool->align, pool->labelno, done);
3832 #endif
3833
3834 if (pool->align > 1)
3835 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (pool->align));
3836
3837 /* Output the label. */
3838 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3839
3840 /* Output the value of the constant itself. */
3841 switch (GET_MODE_CLASS (pool->mode))
3842 {
3843 case MODE_FLOAT:
3844 if (GET_CODE (x) != CONST_DOUBLE)
3845 abort ();
3846
3847 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3848 assemble_real (u.d, pool->mode);
3849 break;
3850
3851 case MODE_INT:
3852 case MODE_PARTIAL_INT:
3853 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3854 break;
3855
3856 default:
3857 abort ();
3858 }
3859
3860 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3861 done: ;
3862 #endif
3863
3864 }
3865
3866 #ifdef ASM_OUTPUT_POOL_EPILOGUE
3867 ASM_OUTPUT_POOL_EPILOGUE (asm_out_file, fnname, fndecl, pool_offset);
3868 #endif
3869
3870 /* Done with this pool. */
3871 first_pool = last_pool = 0;
3872 }
3873
3874 /* Look through the instructions for this function, and mark all the
3875 entries in the constant pool which are actually being used. */
3876
3877 static void
3878 mark_constant_pool ()
3879 {
3880 register rtx insn;
3881 struct pool_constant *pool;
3882
3883 if (first_pool == 0)
3884 return;
3885
3886 for (pool = first_pool; pool; pool = pool->next)
3887 pool->mark = 0;
3888
3889 for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
3890 if (INSN_P (insn))
3891 mark_constants (PATTERN (insn));
3892
3893 for (insn = current_function_epilogue_delay_list;
3894 insn;
3895 insn = XEXP (insn, 1))
3896 if (INSN_P (insn))
3897 mark_constants (PATTERN (insn));
3898
3899 /* It's possible that the only reference to a symbol is in a symbol
3900 that's in the constant pool. This happens in Fortran under some
3901 situations. (When the constant contains the address of another
3902 constant, and only the first is used directly in an insn.)
3903 This is potentially suboptimal if there's ever a possibility of
3904 backwards (in pool order) 2'd level references. However, it's
3905 not clear that 2'd level references can happen. */
3906 for (pool = first_pool; pool; pool = pool->next)
3907 {
3908 struct pool_sym *sym;
3909 const char *label;
3910
3911 /* skip unmarked entries; no insn refers to them. */
3912 if (!pool->mark)
3913 continue;
3914
3915 /* Skip everything except SYMBOL_REFs. */
3916 if (GET_CODE (pool->constant) != SYMBOL_REF)
3917 continue;
3918 label = XSTR (pool->constant, 0);
3919
3920 /* Be sure the symbol's value is marked. */
3921 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym;
3922 sym = sym->next)
3923 if (sym->label == label)
3924 sym->pool->mark = 1;
3925 /* If we didn't find it, there's something truly wrong here, but it
3926 will be announced by the assembler. */
3927 }
3928 }
3929
3930 static void
3931 mark_constants (x)
3932 register rtx x;
3933 {
3934 register int i;
3935 register const char *format_ptr;
3936
3937 if (x == 0)
3938 return;
3939
3940 if (GET_CODE (x) == SYMBOL_REF)
3941 {
3942 if (CONSTANT_POOL_ADDRESS_P (x))
3943 find_pool_constant (cfun, x)->mark = 1;
3944 return;
3945 }
3946 /* Never search inside a CONST_DOUBLE, because CONST_DOUBLE_MEM may be
3947 a MEM, but does not constitute a use of that MEM. */
3948 else if (GET_CODE (x) == CONST_DOUBLE)
3949 return;
3950
3951 /* Insns may appear inside a SEQUENCE. Only check the patterns of
3952 insns, not any notes that may be attached. We don't want to mark
3953 a constant just because it happens to appear in a REG_EQUIV note. */
3954 if (INSN_P (x))
3955 {
3956 mark_constants (PATTERN (x));
3957 return;
3958 }
3959
3960 format_ptr = GET_RTX_FORMAT (GET_CODE (x));
3961
3962 for (i = 0; i < GET_RTX_LENGTH (GET_CODE (x)); i++)
3963 {
3964 switch (*format_ptr++)
3965 {
3966 case 'e':
3967 mark_constants (XEXP (x, i));
3968 break;
3969
3970 case 'E':
3971 if (XVEC (x, i) != 0)
3972 {
3973 register int j;
3974
3975 for (j = 0; j < XVECLEN (x, i); j++)
3976 mark_constants (XVECEXP (x, i, j));
3977 }
3978 break;
3979
3980 case 'S':
3981 case 's':
3982 case '0':
3983 case 'i':
3984 case 'w':
3985 case 'n':
3986 case 'u':
3987 break;
3988
3989 default:
3990 abort ();
3991 }
3992 }
3993 }
3994 \f
3995 /* Find all the constants whose addresses are referenced inside of EXP,
3996 and make sure assembler code with a label has been output for each one.
3997 Indicate whether an ADDR_EXPR has been encountered. */
3998
3999 static int
4000 output_addressed_constants (exp)
4001 tree exp;
4002 {
4003 int reloc = 0;
4004
4005 switch (TREE_CODE (exp))
4006 {
4007 case ADDR_EXPR:
4008 {
4009 register tree constant = TREE_OPERAND (exp, 0);
4010
4011 while (TREE_CODE (constant) == COMPONENT_REF)
4012 {
4013 constant = TREE_OPERAND (constant, 0);
4014 }
4015
4016 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
4017 || TREE_CODE (constant) == CONSTRUCTOR)
4018 /* No need to do anything here
4019 for addresses of variables or functions. */
4020 output_constant_def (constant);
4021 }
4022 reloc = 1;
4023 break;
4024
4025 case PLUS_EXPR:
4026 case MINUS_EXPR:
4027 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4028 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
4029 break;
4030
4031 case NOP_EXPR:
4032 case CONVERT_EXPR:
4033 case NON_LVALUE_EXPR:
4034 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
4035 break;
4036
4037 case CONSTRUCTOR:
4038 {
4039 register tree link;
4040 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
4041 if (TREE_VALUE (link) != 0)
4042 reloc |= output_addressed_constants (TREE_VALUE (link));
4043 }
4044 break;
4045
4046 default:
4047 break;
4048 }
4049 return reloc;
4050 }
4051 \f
4052 /* Return nonzero if VALUE is a valid constant-valued expression
4053 for use in initializing a static variable; one that can be an
4054 element of a "constant" initializer.
4055
4056 Return null_pointer_node if the value is absolute;
4057 if it is relocatable, return the variable that determines the relocation.
4058 We assume that VALUE has been folded as much as possible;
4059 therefore, we do not need to check for such things as
4060 arithmetic-combinations of integers. */
4061
4062 tree
4063 initializer_constant_valid_p (value, endtype)
4064 tree value;
4065 tree endtype;
4066 {
4067 /* Give the front-end a chance to convert VALUE to something that
4068 looks more like a constant to the back-end. */
4069 if (lang_expand_constant)
4070 value = (*lang_expand_constant) (value);
4071
4072 switch (TREE_CODE (value))
4073 {
4074 case CONSTRUCTOR:
4075 if ((TREE_CODE (TREE_TYPE (value)) == UNION_TYPE
4076 || TREE_CODE (TREE_TYPE (value)) == RECORD_TYPE)
4077 && TREE_CONSTANT (value)
4078 && CONSTRUCTOR_ELTS (value))
4079 return
4080 initializer_constant_valid_p (TREE_VALUE (CONSTRUCTOR_ELTS (value)),
4081 endtype);
4082
4083 return TREE_STATIC (value) ? null_pointer_node : 0;
4084
4085 case INTEGER_CST:
4086 case REAL_CST:
4087 case STRING_CST:
4088 case COMPLEX_CST:
4089 return null_pointer_node;
4090
4091 case ADDR_EXPR:
4092 return staticp (TREE_OPERAND (value, 0)) ? TREE_OPERAND (value, 0) : 0;
4093
4094 case NON_LVALUE_EXPR:
4095 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4096
4097 case CONVERT_EXPR:
4098 case NOP_EXPR:
4099 /* Allow conversions between pointer types. */
4100 if (POINTER_TYPE_P (TREE_TYPE (value))
4101 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4102 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4103
4104 /* Allow conversions between real types. */
4105 if (FLOAT_TYPE_P (TREE_TYPE (value))
4106 && FLOAT_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4107 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4108
4109 /* Allow length-preserving conversions between integer types. */
4110 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4111 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4112 && (TYPE_PRECISION (TREE_TYPE (value))
4113 == TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4114 return initializer_constant_valid_p (TREE_OPERAND (value, 0), endtype);
4115
4116 /* Allow conversions between other integer types only if
4117 explicit value. */
4118 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4119 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4120 {
4121 tree inner = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4122 endtype);
4123 if (inner == null_pointer_node)
4124 return null_pointer_node;
4125 break;
4126 }
4127
4128 /* Allow (int) &foo provided int is as wide as a pointer. */
4129 if (INTEGRAL_TYPE_P (TREE_TYPE (value))
4130 && POINTER_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0)))
4131 && (TYPE_PRECISION (TREE_TYPE (value))
4132 >= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0)))))
4133 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4134 endtype);
4135
4136 /* Likewise conversions from int to pointers, but also allow
4137 conversions from 0. */
4138 if (POINTER_TYPE_P (TREE_TYPE (value))
4139 && INTEGRAL_TYPE_P (TREE_TYPE (TREE_OPERAND (value, 0))))
4140 {
4141 if (integer_zerop (TREE_OPERAND (value, 0)))
4142 return null_pointer_node;
4143 else if (TYPE_PRECISION (TREE_TYPE (value))
4144 <= TYPE_PRECISION (TREE_TYPE (TREE_OPERAND (value, 0))))
4145 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4146 endtype);
4147 }
4148
4149 /* Allow conversions to union types if the value inside is okay. */
4150 if (TREE_CODE (TREE_TYPE (value)) == UNION_TYPE)
4151 return initializer_constant_valid_p (TREE_OPERAND (value, 0),
4152 endtype);
4153 break;
4154
4155 case PLUS_EXPR:
4156 if (! INTEGRAL_TYPE_P (endtype)
4157 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4158 {
4159 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4160 endtype);
4161 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4162 endtype);
4163 /* If either term is absolute, use the other terms relocation. */
4164 if (valid0 == null_pointer_node)
4165 return valid1;
4166 if (valid1 == null_pointer_node)
4167 return valid0;
4168 }
4169 break;
4170
4171 case MINUS_EXPR:
4172 if (! INTEGRAL_TYPE_P (endtype)
4173 || TYPE_PRECISION (endtype) >= POINTER_SIZE)
4174 {
4175 tree valid0 = initializer_constant_valid_p (TREE_OPERAND (value, 0),
4176 endtype);
4177 tree valid1 = initializer_constant_valid_p (TREE_OPERAND (value, 1),
4178 endtype);
4179 /* Win if second argument is absolute. */
4180 if (valid1 == null_pointer_node)
4181 return valid0;
4182 /* Win if both arguments have the same relocation.
4183 Then the value is absolute. */
4184 if (valid0 == valid1 && valid0 != 0)
4185 return null_pointer_node;
4186 }
4187
4188 /* Support differences between labels. */
4189 if (INTEGRAL_TYPE_P (endtype))
4190 {
4191 tree op0, op1;
4192 op0 = TREE_OPERAND (value, 0);
4193 op1 = TREE_OPERAND (value, 1);
4194 STRIP_NOPS (op0);
4195 STRIP_NOPS (op1);
4196
4197 if (TREE_CODE (op0) == ADDR_EXPR
4198 && TREE_CODE (TREE_OPERAND (op0, 0)) == LABEL_DECL
4199 && TREE_CODE (op1) == ADDR_EXPR
4200 && TREE_CODE (TREE_OPERAND (op1, 0)) == LABEL_DECL)
4201 return null_pointer_node;
4202 }
4203 break;
4204
4205 default:
4206 break;
4207 }
4208
4209 return 0;
4210 }
4211 \f
4212 /* Output assembler code for constant EXP to FILE, with no label.
4213 This includes the pseudo-op such as ".int" or ".byte", and a newline.
4214 Assumes output_addressed_constants has been done on EXP already.
4215
4216 Generate exactly SIZE bytes of assembler data, padding at the end
4217 with zeros if necessary. SIZE must always be specified.
4218
4219 SIZE is important for structure constructors,
4220 since trailing members may have been omitted from the constructor.
4221 It is also important for initialization of arrays from string constants
4222 since the full length of the string constant might not be wanted.
4223 It is also needed for initialization of unions, where the initializer's
4224 type is just one member, and that may not be as long as the union.
4225
4226 There a case in which we would fail to output exactly SIZE bytes:
4227 for a structure constructor that wants to produce more than SIZE bytes.
4228 But such constructors will never be generated for any possible input. */
4229
4230 void
4231 output_constant (exp, size)
4232 register tree exp;
4233 register int size;
4234 {
4235 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
4236
4237 /* Some front-ends use constants other than the standard
4238 language-indepdent varieties, but which may still be output
4239 directly. Give the front-end a chance to convert EXP to a
4240 language-independent representation. */
4241 if (lang_expand_constant)
4242 exp = (*lang_expand_constant) (exp);
4243
4244 if (size == 0 || flag_syntax_only)
4245 return;
4246
4247 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
4248 That way we get the constant (we hope) inside it. Also, strip off any
4249 NOP_EXPR that converts between two record, union, array, or set types
4250 or a CONVERT_EXPR that converts to a union TYPE. */
4251 while ((TREE_CODE (exp) == NOP_EXPR
4252 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
4253 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
4254 || (TREE_CODE (exp) == CONVERT_EXPR
4255 && code == UNION_TYPE)
4256 || TREE_CODE (exp) == NON_LVALUE_EXPR)
4257 {
4258 exp = TREE_OPERAND (exp, 0);
4259 code = TREE_CODE (TREE_TYPE (exp));
4260 }
4261
4262 /* Allow a constructor with no elements for any data type.
4263 This means to fill the space with zeros. */
4264 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
4265 {
4266 assemble_zeros (size);
4267 return;
4268 }
4269
4270 switch (code)
4271 {
4272 case CHAR_TYPE:
4273 case BOOLEAN_TYPE:
4274 case INTEGER_TYPE:
4275 case ENUMERAL_TYPE:
4276 case POINTER_TYPE:
4277 case REFERENCE_TYPE:
4278 /* ??? What about (int)((float)(int)&foo + 4) */
4279 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
4280 || TREE_CODE (exp) == NON_LVALUE_EXPR)
4281 exp = TREE_OPERAND (exp, 0);
4282
4283 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
4284 EXPAND_INITIALIZER),
4285 size, 0))
4286 error ("initializer for integer value is too complicated");
4287 size = 0;
4288 break;
4289
4290 case REAL_TYPE:
4291 if (TREE_CODE (exp) != REAL_CST)
4292 error ("initializer for floating value is not a floating constant");
4293
4294 assemble_real (TREE_REAL_CST (exp),
4295 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
4296 size = 0;
4297 break;
4298
4299 case COMPLEX_TYPE:
4300 output_constant (TREE_REALPART (exp), size / 2);
4301 output_constant (TREE_IMAGPART (exp), size / 2);
4302 size -= (size / 2) * 2;
4303 break;
4304
4305 case ARRAY_TYPE:
4306 if (TREE_CODE (exp) == CONSTRUCTOR)
4307 {
4308 output_constructor (exp, size);
4309 return;
4310 }
4311 else if (TREE_CODE (exp) == STRING_CST)
4312 {
4313 int excess = 0;
4314
4315 if (size > TREE_STRING_LENGTH (exp))
4316 {
4317 excess = size - TREE_STRING_LENGTH (exp);
4318 size = TREE_STRING_LENGTH (exp);
4319 }
4320
4321 assemble_string (TREE_STRING_POINTER (exp), size);
4322 size = excess;
4323 }
4324 else
4325 abort ();
4326 break;
4327
4328 case RECORD_TYPE:
4329 case UNION_TYPE:
4330 if (TREE_CODE (exp) == CONSTRUCTOR)
4331 output_constructor (exp, size);
4332 else
4333 abort ();
4334 return;
4335
4336 case SET_TYPE:
4337 if (TREE_CODE (exp) == INTEGER_CST)
4338 assemble_integer (expand_expr (exp, NULL_RTX,
4339 VOIDmode, EXPAND_INITIALIZER),
4340 size, 1);
4341 else if (TREE_CODE (exp) == CONSTRUCTOR)
4342 {
4343 unsigned char *buffer = (unsigned char *) alloca (size);
4344 if (get_set_constructor_bytes (exp, buffer, size))
4345 abort ();
4346 assemble_string ((char *) buffer, size);
4347 }
4348 else
4349 error ("unknown set constructor type");
4350 return;
4351
4352 default:
4353 break; /* ??? */
4354 }
4355
4356 if (size > 0)
4357 assemble_zeros (size);
4358 }
4359
4360 \f
4361 /* Subroutine of output_constant, used for CONSTRUCTORs
4362 (aggregate constants).
4363 Generate at least SIZE bytes, padding if necessary. */
4364
4365 static void
4366 output_constructor (exp, size)
4367 tree exp;
4368 int size;
4369 {
4370 tree type = TREE_TYPE (exp);
4371 register tree link, field = 0;
4372 tree min_index = 0;
4373 /* Number of bytes output or skipped so far.
4374 In other words, current position within the constructor. */
4375 HOST_WIDE_INT total_bytes = 0;
4376 /* Non-zero means BYTE contains part of a byte, to be output. */
4377 int byte_buffer_in_use = 0;
4378 register int byte = 0;
4379
4380 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
4381 abort ();
4382
4383 if (TREE_CODE (type) == RECORD_TYPE)
4384 field = TYPE_FIELDS (type);
4385
4386 if (TREE_CODE (type) == ARRAY_TYPE
4387 && TYPE_DOMAIN (type) != 0)
4388 min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
4389
4390 /* As LINK goes through the elements of the constant,
4391 FIELD goes through the structure fields, if the constant is a structure.
4392 if the constant is a union, then we override this,
4393 by getting the field from the TREE_LIST element.
4394 But the constant could also be an array. Then FIELD is zero.
4395
4396 There is always a maximum of one element in the chain LINK for unions
4397 (even if the initializer in a source program incorrectly contains
4398 more one). */
4399 for (link = CONSTRUCTOR_ELTS (exp);
4400 link;
4401 link = TREE_CHAIN (link),
4402 field = field ? TREE_CHAIN (field) : 0)
4403 {
4404 tree val = TREE_VALUE (link);
4405 tree index = 0;
4406
4407 /* The element in a union constructor specifies the proper field
4408 or index. */
4409 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
4410 || TREE_CODE (type) == QUAL_UNION_TYPE)
4411 && TREE_PURPOSE (link) != 0)
4412 field = TREE_PURPOSE (link);
4413
4414 else if (TREE_CODE (type) == ARRAY_TYPE)
4415 index = TREE_PURPOSE (link);
4416
4417 /* Eliminate the marker that makes a cast not be an lvalue. */
4418 if (val != 0)
4419 STRIP_NOPS (val);
4420
4421 if (index && TREE_CODE (index) == RANGE_EXPR)
4422 {
4423 register int fieldsize
4424 = int_size_in_bytes (TREE_TYPE (type));
4425 HOST_WIDE_INT lo_index = tree_low_cst (TREE_OPERAND (index, 0), 0);
4426 HOST_WIDE_INT hi_index = tree_low_cst (TREE_OPERAND (index, 1), 0);
4427 HOST_WIDE_INT index;
4428
4429 for (index = lo_index; index <= hi_index; index++)
4430 {
4431 /* Output the element's initial value. */
4432 if (val == 0)
4433 assemble_zeros (fieldsize);
4434 else
4435 output_constant (val, fieldsize);
4436
4437 /* Count its size. */
4438 total_bytes += fieldsize;
4439 }
4440 }
4441 else if (field == 0 || !DECL_BIT_FIELD (field))
4442 {
4443 /* An element that is not a bit-field. */
4444
4445 register int fieldsize;
4446 /* Since this structure is static,
4447 we know the positions are constant. */
4448 HOST_WIDE_INT pos = field ? int_byte_position (field) : 0;
4449
4450 if (index != 0)
4451 pos = (tree_low_cst (TYPE_SIZE_UNIT (TREE_TYPE (val)), 1)
4452 * (tree_low_cst (index, 0) - tree_low_cst (min_index, 0)));
4453
4454 /* Output any buffered-up bit-fields preceding this element. */
4455 if (byte_buffer_in_use)
4456 {
4457 ASM_OUTPUT_BYTE (asm_out_file, byte);
4458 total_bytes++;
4459 byte_buffer_in_use = 0;
4460 }
4461
4462 /* Advance to offset of this element.
4463 Note no alignment needed in an array, since that is guaranteed
4464 if each element has the proper size. */
4465 if ((field != 0 || index != 0) && pos != total_bytes)
4466 {
4467 assemble_zeros (pos - total_bytes);
4468 total_bytes = pos;
4469 }
4470
4471 else if (field != 0 && DECL_PACKED (field))
4472 /* Some assemblers automaticallly align a datum according to its
4473 size if no align directive is specified. The datum, however,
4474 may be declared with 'packed' attribute, so we have to disable
4475 such a feature. */
4476 ASM_OUTPUT_ALIGN (asm_out_file, 0);
4477
4478 /* Determine size this element should occupy. */
4479 if (field)
4480 fieldsize = tree_low_cst (DECL_SIZE_UNIT (field), 1);
4481 else
4482 fieldsize = int_size_in_bytes (TREE_TYPE (type));
4483
4484 /* Output the element's initial value. */
4485 if (val == 0)
4486 assemble_zeros (fieldsize);
4487 else
4488 output_constant (val, fieldsize);
4489
4490 /* Count its size. */
4491 total_bytes += fieldsize;
4492 }
4493 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
4494 error ("invalid initial value for member `%s'",
4495 IDENTIFIER_POINTER (DECL_NAME (field)));
4496 else
4497 {
4498 /* Element that is a bit-field. */
4499
4500 HOST_WIDE_INT next_offset = int_bit_position (field);
4501 HOST_WIDE_INT end_offset
4502 = (next_offset + tree_low_cst (DECL_SIZE (field), 1));
4503
4504 if (val == 0)
4505 val = integer_zero_node;
4506
4507 /* If this field does not start in this (or, next) byte,
4508 skip some bytes. */
4509 if (next_offset / BITS_PER_UNIT != total_bytes)
4510 {
4511 /* Output remnant of any bit field in previous bytes. */
4512 if (byte_buffer_in_use)
4513 {
4514 ASM_OUTPUT_BYTE (asm_out_file, byte);
4515 total_bytes++;
4516 byte_buffer_in_use = 0;
4517 }
4518
4519 /* If still not at proper byte, advance to there. */
4520 if (next_offset / BITS_PER_UNIT != total_bytes)
4521 {
4522 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
4523 total_bytes = next_offset / BITS_PER_UNIT;
4524 }
4525 }
4526
4527 if (! byte_buffer_in_use)
4528 byte = 0;
4529
4530 /* We must split the element into pieces that fall within
4531 separate bytes, and combine each byte with previous or
4532 following bit-fields. */
4533
4534 /* next_offset is the offset n fbits from the beginning of
4535 the structure to the next bit of this element to be processed.
4536 end_offset is the offset of the first bit past the end of
4537 this element. */
4538 while (next_offset < end_offset)
4539 {
4540 int this_time;
4541 int shift;
4542 HOST_WIDE_INT value;
4543 HOST_WIDE_INT next_byte = next_offset / BITS_PER_UNIT;
4544 HOST_WIDE_INT next_bit = next_offset % BITS_PER_UNIT;
4545
4546 /* Advance from byte to byte
4547 within this element when necessary. */
4548 while (next_byte != total_bytes)
4549 {
4550 ASM_OUTPUT_BYTE (asm_out_file, byte);
4551 total_bytes++;
4552 byte = 0;
4553 }
4554
4555 /* Number of bits we can process at once
4556 (all part of the same byte). */
4557 this_time = MIN (end_offset - next_offset,
4558 BITS_PER_UNIT - next_bit);
4559 if (BYTES_BIG_ENDIAN)
4560 {
4561 /* On big-endian machine, take the most significant bits
4562 first (of the bits that are significant)
4563 and put them into bytes from the most significant end. */
4564 shift = end_offset - next_offset - this_time;
4565
4566 /* Don't try to take a bunch of bits that cross
4567 the word boundary in the INTEGER_CST. We can
4568 only select bits from the LOW or HIGH part
4569 not from both. */
4570 if (shift < HOST_BITS_PER_WIDE_INT
4571 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4572 {
4573 this_time = shift + this_time - HOST_BITS_PER_WIDE_INT;
4574 shift = HOST_BITS_PER_WIDE_INT;
4575 }
4576
4577 /* Now get the bits from the appropriate constant word. */
4578 if (shift < HOST_BITS_PER_WIDE_INT)
4579 value = TREE_INT_CST_LOW (val);
4580 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4581 {
4582 value = TREE_INT_CST_HIGH (val);
4583 shift -= HOST_BITS_PER_WIDE_INT;
4584 }
4585 else
4586 abort ();
4587
4588 /* Get the result. This works only when:
4589 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4590 byte |= (((value >> shift)
4591 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4592 << (BITS_PER_UNIT - this_time - next_bit));
4593 }
4594 else
4595 {
4596 /* On little-endian machines,
4597 take first the least significant bits of the value
4598 and pack them starting at the least significant
4599 bits of the bytes. */
4600 shift = next_offset - int_bit_position (field);
4601
4602 /* Don't try to take a bunch of bits that cross
4603 the word boundary in the INTEGER_CST. We can
4604 only select bits from the LOW or HIGH part
4605 not from both. */
4606 if (shift < HOST_BITS_PER_WIDE_INT
4607 && shift + this_time > HOST_BITS_PER_WIDE_INT)
4608 this_time = (HOST_BITS_PER_WIDE_INT - shift);
4609
4610 /* Now get the bits from the appropriate constant word. */
4611 if (shift < HOST_BITS_PER_WIDE_INT)
4612 value = TREE_INT_CST_LOW (val);
4613 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
4614 {
4615 value = TREE_INT_CST_HIGH (val);
4616 shift -= HOST_BITS_PER_WIDE_INT;
4617 }
4618 else
4619 abort ();
4620
4621 /* Get the result. This works only when:
4622 1 <= this_time <= HOST_BITS_PER_WIDE_INT. */
4623 byte |= (((value >> shift)
4624 & (((HOST_WIDE_INT) 2 << (this_time - 1)) - 1))
4625 << next_bit);
4626 }
4627
4628 next_offset += this_time;
4629 byte_buffer_in_use = 1;
4630 }
4631 }
4632 }
4633
4634 if (byte_buffer_in_use)
4635 {
4636 ASM_OUTPUT_BYTE (asm_out_file, byte);
4637 total_bytes++;
4638 }
4639
4640 if (total_bytes < size)
4641 assemble_zeros (size - total_bytes);
4642 }
4643
4644 #ifdef HANDLE_PRAGMA_WEAK
4645 /* Add function NAME to the weak symbols list. VALUE is a weak alias
4646 associatd with NAME. */
4647
4648 int
4649 add_weak (name, value)
4650 const char *name;
4651 const char *value;
4652 {
4653 struct weak_syms *weak;
4654
4655 weak = (struct weak_syms *) permalloc (sizeof (struct weak_syms));
4656
4657 if (weak == NULL)
4658 return 0;
4659
4660 weak->next = weak_decls;
4661 weak->name = name;
4662 weak->value = value;
4663 weak_decls = weak;
4664
4665 return 1;
4666 }
4667 #endif /* HANDLE_PRAGMA_WEAK */
4668
4669 /* Declare DECL to be a weak symbol. */
4670
4671 void
4672 declare_weak (decl)
4673 tree decl;
4674 {
4675 if (! TREE_PUBLIC (decl))
4676 error_with_decl (decl, "weak declaration of `%s' must be public");
4677 else if (TREE_ASM_WRITTEN (decl))
4678 error_with_decl (decl, "weak declaration of `%s' must precede definition");
4679 else if (SUPPORTS_WEAK)
4680 DECL_WEAK (decl) = 1;
4681 #ifdef HANDLE_PRAGMA_WEAK
4682 add_weak (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)), NULL);
4683 #endif
4684 }
4685
4686 /* Emit any pending weak declarations. */
4687
4688 #ifdef HANDLE_PRAGMA_WEAK
4689 struct weak_syms * weak_decls;
4690 #endif
4691
4692 void
4693 weak_finish ()
4694 {
4695 #ifdef HANDLE_PRAGMA_WEAK
4696 if (HANDLE_PRAGMA_WEAK)
4697 {
4698 struct weak_syms *t;
4699 for (t = weak_decls; t; t = t->next)
4700 {
4701 if (t->name)
4702 {
4703 ASM_WEAKEN_LABEL (asm_out_file, t->name);
4704 if (t->value)
4705 ASM_OUTPUT_DEF (asm_out_file, t->name, t->value);
4706 }
4707 }
4708 }
4709 #endif
4710 }
4711
4712 /* Remove NAME from the pending list of weak symbols. This prevents
4713 the compiler from emitting multiple .weak directives which confuses
4714 some assemblers. */
4715 #ifdef ASM_WEAKEN_LABEL
4716 static void
4717 remove_from_pending_weak_list (name)
4718 const char *name ATTRIBUTE_UNUSED;
4719 {
4720 #ifdef HANDLE_PRAGMA_WEAK
4721 if (HANDLE_PRAGMA_WEAK)
4722 {
4723 struct weak_syms *t;
4724 for (t = weak_decls; t; t = t->next)
4725 {
4726 if (t->name && strcmp (name, t->name) == 0)
4727 t->name = NULL;
4728 }
4729 }
4730 #endif
4731 }
4732 #endif
4733
4734 void
4735 assemble_alias (decl, target)
4736 tree decl, target ATTRIBUTE_UNUSED;
4737 {
4738 const char *name;
4739
4740 make_decl_rtl (decl, (char *) 0, 1);
4741 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
4742
4743 #ifdef ASM_OUTPUT_DEF
4744 /* Make name accessible from other files, if appropriate. */
4745
4746 if (TREE_PUBLIC (decl))
4747 {
4748 #ifdef ASM_WEAKEN_LABEL
4749 if (DECL_WEAK (decl))
4750 {
4751 ASM_WEAKEN_LABEL (asm_out_file, name);
4752 /* Remove this function from the pending weak list so that
4753 we do not emit multiple .weak directives for it. */
4754 remove_from_pending_weak_list
4755 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
4756 }
4757 else
4758 #endif
4759 ASM_GLOBALIZE_LABEL (asm_out_file, name);
4760 }
4761
4762 #ifdef ASM_OUTPUT_DEF_FROM_DECLS
4763 ASM_OUTPUT_DEF_FROM_DECLS (asm_out_file, decl, target);
4764 #else
4765 ASM_OUTPUT_DEF (asm_out_file, name, IDENTIFIER_POINTER (target));
4766 #endif
4767 TREE_ASM_WRITTEN (decl) = 1;
4768 #else
4769 #ifdef ASM_OUTPUT_WEAK_ALIAS
4770 if (! DECL_WEAK (decl))
4771 warning ("only weak aliases are supported in this configuration");
4772
4773 ASM_OUTPUT_WEAK_ALIAS (asm_out_file, name, IDENTIFIER_POINTER (target));
4774 TREE_ASM_WRITTEN (decl) = 1;
4775 #else
4776 warning ("alias definitions not supported in this configuration; ignored");
4777 #endif
4778 #endif
4779 }
4780
4781 /* This determines whether or not we support link-once semantics. */
4782 #ifndef SUPPORTS_ONE_ONLY
4783 #ifdef MAKE_DECL_ONE_ONLY
4784 #define SUPPORTS_ONE_ONLY 1
4785 #else
4786 #define SUPPORTS_ONE_ONLY 0
4787 #endif
4788 #endif
4789
4790 /* Returns 1 if the target configuration supports defining public symbols
4791 so that one of them will be chosen at link time instead of generating a
4792 multiply-defined symbol error, whether through the use of weak symbols or
4793 a target-specific mechanism for having duplicates discarded. */
4794
4795 int
4796 supports_one_only ()
4797 {
4798 if (SUPPORTS_ONE_ONLY)
4799 return 1;
4800 return SUPPORTS_WEAK;
4801 }
4802
4803 /* Set up DECL as a public symbol that can be defined in multiple
4804 translation units without generating a linker error. */
4805
4806 void
4807 make_decl_one_only (decl)
4808 tree decl;
4809 {
4810 if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
4811 abort ();
4812
4813 TREE_PUBLIC (decl) = 1;
4814
4815 if (TREE_CODE (decl) == VAR_DECL
4816 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
4817 DECL_COMMON (decl) = 1;
4818 else if (SUPPORTS_ONE_ONLY)
4819 {
4820 #ifdef MAKE_DECL_ONE_ONLY
4821 MAKE_DECL_ONE_ONLY (decl);
4822 #endif
4823 DECL_ONE_ONLY (decl) = 1;
4824 }
4825 else if (SUPPORTS_WEAK)
4826 DECL_WEAK (decl) = 1;
4827 else
4828 abort ();
4829 }
4830
4831 void
4832 init_varasm_once ()
4833 {
4834 ggc_add_root (const_hash_table, MAX_HASH_TABLE, sizeof const_hash_table[0],
4835 mark_const_hash_entry);
4836 ggc_add_string_root (&in_named_name, 1);
4837 }
4838
4839 /* Extra support for EH values. */
4840 void
4841 assemble_eh_label (name)
4842 const char *name;
4843 {
4844 #ifdef ASM_OUTPUT_EH_LABEL
4845 ASM_OUTPUT_EH_LABEL (asm_out_file, name);
4846 #else
4847 assemble_label (name);
4848 #endif
4849 }
4850
4851 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
4852
4853 void
4854 assemble_eh_align (align)
4855 int align;
4856 {
4857 #ifdef ASM_OUTPUT_EH_ALIGN
4858 if (align > BITS_PER_UNIT)
4859 ASM_OUTPUT_EH_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
4860 #else
4861 assemble_align (align);
4862 #endif
4863 }
4864
4865
4866 /* On some platforms, we may want to specify a special mechansim to
4867 output EH data when generating with a function.. */
4868 int
4869 assemble_eh_integer (x, size, force)
4870 rtx x;
4871 int size;
4872 int force;
4873 {
4874
4875 switch (size)
4876 {
4877 #ifdef ASM_OUTPUT_EH_CHAR
4878 case 1:
4879 ASM_OUTPUT_EH_CHAR (asm_out_file, x);
4880 return 1;
4881 #endif
4882
4883 #ifdef ASM_OUTPUT_EH_SHORT
4884 case 2:
4885 ASM_OUTPUT_EH_SHORT (asm_out_file, x);
4886 return 1;
4887 #endif
4888
4889 #ifdef ASM_OUTPUT_EH_INT
4890 case 4:
4891 ASM_OUTPUT_EH_INT (asm_out_file, x);
4892 return 1;
4893 #endif
4894
4895 #ifdef ASM_OUTPUT_EH_DOUBLE_INT
4896 case 8:
4897 ASM_OUTPUT_EH_DOUBLE_INT (asm_out_file, x);
4898 return 1;
4899 #endif
4900
4901 default:
4902 break;
4903 }
4904 return (assemble_integer (x, size, force));
4905 }
4906
4907
4908