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