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