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