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