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