]> gcc.gnu.org Git - gcc.git/blame - gcc/varasm.c
(expand_call, emit_library_call{,_value}, store_one_arg): Use
[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'");
506 }
79e68feb
RS
507
508 /* Now handle ordinary static variables and functions (in memory).
509 Also handle vars declared register invalidly. */
510 if (DECL_RTL (decl) == 0)
511 {
512 /* Can't use just the variable's own name for a variable
513 whose scope is less than the whole file.
514 Concatenate a distinguishing number. */
44fe2e80 515 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
79e68feb
RS
516 {
517 char *label;
518
519 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
520 name = obstack_copy0 (saveable_obstack, label, strlen (label));
521 var_labelno++;
522 }
523
0a5152d0
RK
524 if (name == 0)
525 abort ();
526
79e68feb
RS
527 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
528 gen_rtx (SYMBOL_REF, Pmode, name));
3771b9b2
RK
529
530 /* If this variable is to be treated as volatile, show its
531 tree node has side effects. If it has side effects, either
532 because of this test or from TREE_THIS_VOLATILE also
533 being set, show the MEM is volatile. */
534 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
535 && TREE_PUBLIC (decl))
536 TREE_SIDE_EFFECTS (decl) = 1;
537 if (TREE_SIDE_EFFECTS (decl))
79e68feb 538 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
3771b9b2 539
79e68feb
RS
540 if (TREE_READONLY (decl))
541 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
542 MEM_IN_STRUCT_P (DECL_RTL (decl))
543 = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
544 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
c1b98a95
RK
545 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
546 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE);
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))
1344 if (contains_pointers_p (TREE_TYPE (fields)))
1345 return 1;
1346 return 0;
1347 }
1348
1349 case ARRAY_TYPE:
1350 /* An array type contains pointers if its element type does. */
1351 return contains_pointers_p (TREE_TYPE (type));
1352
1353 default:
1354 return 0;
1355 }
1356}
1357
ca695ac9
JB
1358/* Output text storage for constructor CONSTR. Returns rtx of
1359 storage. */
1360
1361rtx
1362bc_output_constructor (constr)
1363 tree constr;
1364{
1365 int i;
1366
1367 /* Must always be a literal; non-literal constructors are handled
1368 differently. */
1369
1370 if (!TREE_CONSTANT (constr))
1371 abort ();
1372
1373 /* Always const */
1374 text_section ();
1375
1376 /* Align */
1377 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1378 if (i > 0)
1379 BC_OUTPUT_ALIGN (asm_out_file, i);
1380
1381 /* Output data */
1382 output_constant (constr, int_size_in_bytes (TREE_TYPE (constr)));
1383}
1384
1385
1386/* Create storage for constructor CONSTR. */
1387
1388void
1389bc_output_data_constructor (constr)
1390 tree constr;
1391{
1392 int i;
1393
1394 /* Put in data section */
1395 data_section ();
1396
1397 /* Align */
1398 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1399 if (i > 0)
1400 BC_OUTPUT_ALIGN (asm_out_file, i);
1401
1402 /* The constructor is filled in at runtime. */
1403 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1404}
1405
1406
79e68feb 1407/* Output something to declare an external symbol to the assembler.
fff9e713
MT
1408 (Most assemblers don't need this, so we normally output nothing.)
1409 Do nothing if DECL is not external. */
79e68feb
RS
1410
1411void
1412assemble_external (decl)
1413 tree decl;
1414{
ca695ac9
JB
1415 if (output_bytecode)
1416 return;
1417
79e68feb 1418#ifdef ASM_OUTPUT_EXTERNAL
fff9e713 1419 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
44fe2e80 1420 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
79e68feb 1421 {
fff9e713
MT
1422 rtx rtl = DECL_RTL (decl);
1423
1424 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1425 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1426 {
1427 /* Some systems do require some output. */
1428 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1429 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1430 }
79e68feb
RS
1431 }
1432#endif
1433}
1434
1435/* Similar, for calling a library function FUN. */
1436
1437void
1438assemble_external_libcall (fun)
1439 rtx fun;
1440{
1441#ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
ca695ac9 1442 if (!output_bytecode)
79e68feb 1443 {
ca695ac9
JB
1444 /* Declare library function name external when first used, if nec. */
1445 if (! SYMBOL_REF_USED (fun))
1446 {
1447 SYMBOL_REF_USED (fun) = 1;
1448 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1449 }
79e68feb
RS
1450 }
1451#endif
1452}
1453
1454/* Declare the label NAME global. */
1455
1456void
1457assemble_global (name)
1458 char *name;
1459{
1460 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1461}
1462
1463/* Assemble a label named NAME. */
1464
1465void
1466assemble_label (name)
1467 char *name;
1468{
ca695ac9
JB
1469 if (output_bytecode)
1470 BC_OUTPUT_LABEL (asm_out_file, name);
1471 else
1472 ASM_OUTPUT_LABEL (asm_out_file, name);
79e68feb
RS
1473}
1474
1475/* Output to FILE a reference to the assembler name of a C-level name NAME.
1476 If NAME starts with a *, the rest of NAME is output verbatim.
1477 Otherwise NAME is transformed in an implementation-defined way
1478 (usually by the addition of an underscore).
1479 Many macros in the tm file are defined to call this function. */
1480
1481void
1482assemble_name (file, name)
1483 FILE *file;
1484 char *name;
1485{
1486 if (name[0] == '*')
ca695ac9
JB
1487 {
1488 if (output_bytecode)
1489 bc_emit_labelref (name);
1490 else
1491 fputs (&name[1], file);
1492 }
79e68feb 1493 else
ca695ac9
JB
1494 {
1495 if (output_bytecode)
1496 BC_OUTPUT_LABELREF (file, name);
1497 else
1498 ASM_OUTPUT_LABELREF (file, name);
1499 }
79e68feb
RS
1500}
1501
1502/* Allocate SIZE bytes writable static space with a gensym name
1503 and return an RTX to refer to its address. */
1504
1505rtx
1506assemble_static_space (size)
1507 int size;
1508{
1509 char name[12];
1510 char *namestring;
1511 rtx x;
1512 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1513 so that each uninitialized object starts on such a boundary. */
1514 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1515 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1516 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1517
1518#if 0
1519 if (flag_shared_data)
1520 data_section ();
1521#endif
1522
1523 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1524 ++const_labelno;
1525
1526 namestring = (char *) obstack_alloc (saveable_obstack,
1527 strlen (name) + 2);
1528 strcpy (namestring, name);
1529
ca695ac9
JB
1530 if (output_bytecode)
1531 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1532 else
1533 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1534
1535 if (output_bytecode)
69249c1b
RS
1536 {
1537 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1538 }
ca695ac9
JB
1539 else
1540 {
79e68feb 1541#ifdef ASM_OUTPUT_ALIGNED_LOCAL
ca695ac9 1542 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
79e68feb 1543#else
ca695ac9 1544 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
79e68feb 1545#endif
ca695ac9 1546 }
79e68feb
RS
1547 return x;
1548}
1549
1550/* Assemble the static constant template for function entry trampolines.
1551 This is done at most once per compilation.
1552 Returns an RTX for the address of the template. */
1553
1554rtx
1555assemble_trampoline_template ()
1556{
1557 char label[256];
1558 char *name;
1559 int align;
1560
ca695ac9
JB
1561 /* Shouldn't get here */
1562 if (output_bytecode)
1563 abort ();
1564
37552631 1565 /* By default, put trampoline templates in read-only data section. */
f49acdb4 1566
37552631
RS
1567#ifdef TRAMPOLINE_SECTION
1568 TRAMPOLINE_SECTION ();
1569#else
c8c29f85 1570 readonly_data_section ();
37552631 1571#endif
f49acdb4 1572
79e68feb
RS
1573 /* Write the assembler code to define one. */
1574 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1575 if (align > 0)
1576 ASM_OUTPUT_ALIGN (asm_out_file, align);
1577
1578 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1579 TRAMPOLINE_TEMPLATE (asm_out_file);
1580
1581 /* Record the rtl to refer to it. */
1582 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1583 name
1584 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1585 return gen_rtx (SYMBOL_REF, Pmode, name);
1586}
1587\f
1588/* Assemble the integer constant X into an object of SIZE bytes.
1589 X must be either a CONST_INT or CONST_DOUBLE.
1590
1591 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1592 non-zero, abort if we can't output the constant. */
1593
1594int
1595assemble_integer (x, size, force)
1596 rtx x;
1597 int size;
1598 int force;
1599{
1600 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1601 ASM_OUTPUT... macros. */
1602
1603 switch (size)
1604 {
1605#ifdef ASM_OUTPUT_CHAR
1606 case 1:
1607 ASM_OUTPUT_CHAR (asm_out_file, x);
1608 return 1;
1609#endif
1610
1611#ifdef ASM_OUTPUT_SHORT
1612 case 2:
1613 ASM_OUTPUT_SHORT (asm_out_file, x);
1614 return 1;
1615#endif
1616
1617#ifdef ASM_OUTPUT_INT
1618 case 4:
1619 ASM_OUTPUT_INT (asm_out_file, x);
1620 return 1;
1621#endif
1622
1623#ifdef ASM_OUTPUT_DOUBLE_INT
1624 case 8:
1625 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1626 return 1;
1627#endif
1628
1629#ifdef ASM_OUTPUT_QUADRUPLE_INT
1630 case 16:
1631 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1632 return 1;
1633#endif
1634 }
1635
1636 /* If we couldn't do it that way, there are two other possibilities: First,
1637 if the machine can output an explicit byte and this is a 1 byte constant,
1638 we can use ASM_OUTPUT_BYTE. */
1639
1640#ifdef ASM_OUTPUT_BYTE
1641 if (size == 1 && GET_CODE (x) == CONST_INT)
1642 {
1643 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1644 return 1;
1645 }
1646#endif
1647
1648 /* Finally, if SIZE is larger than a single word, try to output the constant
1649 one word at a time. */
1650
1651 if (size > UNITS_PER_WORD)
1652 {
1653 int i;
1654 enum machine_mode mode
1655 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1656 rtx word;
1657
1658 for (i = 0; i < size / UNITS_PER_WORD; i++)
1659 {
1660 word = operand_subword (x, i, 0, mode);
1661
1662 if (word == 0)
1663 break;
1664
fff9e713
MT
1665 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1666 break;
79e68feb
RS
1667 }
1668
1669 if (i == size / UNITS_PER_WORD)
1670 return 1;
fff9e713
MT
1671 /* If we output at least one word and then could not finish,
1672 there is no valid way to continue. */
1673 if (i > 0)
1674 abort ();
79e68feb
RS
1675 }
1676
1677 if (force)
1678 abort ();
1679
1680 return 0;
1681}
1682\f
1683/* Assemble the floating-point constant D into an object of size MODE. */
1684
1685void
1686assemble_real (d, mode)
1687 REAL_VALUE_TYPE d;
1688 enum machine_mode mode;
1689{
1690 jmp_buf output_constant_handler;
1691
1692 if (setjmp (output_constant_handler))
1693 {
1694 error ("floating point trap outputting a constant");
1695#ifdef REAL_IS_NOT_DOUBLE
1696 bzero (&d, sizeof d);
1697 d = dconst0;
1698#else
1699 d = 0;
1700#endif
1701 }
1702
1703 set_float_handler (output_constant_handler);
1704
1705 switch (mode)
1706 {
b7526ea5
RS
1707#ifdef ASM_OUTPUT_BYTE_FLOAT
1708 case QFmode:
1709 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1710 break;
1711#endif
1712#ifdef ASM_OUTPUT_SHORT_FLOAT
1713 case HFmode:
1714 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1715 break;
1716#endif
79e68feb
RS
1717#ifdef ASM_OUTPUT_FLOAT
1718 case SFmode:
1719 ASM_OUTPUT_FLOAT (asm_out_file, d);
1720 break;
1721#endif
1722
1723#ifdef ASM_OUTPUT_DOUBLE
1724 case DFmode:
1725 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1726 break;
1727#endif
1728
1729#ifdef ASM_OUTPUT_LONG_DOUBLE
2c7ff63c 1730 case XFmode:
79e68feb
RS
1731 case TFmode:
1732 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1733 break;
1734#endif
1735
1736 default:
1737 abort ();
1738 }
1739
37366632 1740 set_float_handler (NULL_PTR);
79e68feb
RS
1741}
1742\f
1743/* Here we combine duplicate floating constants to make
1744 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1745
1746/* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1747 They are chained through the CONST_DOUBLE_CHAIN.
1748 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1749 In that case, CONST_DOUBLE_MEM is either a MEM,
57632c51
RS
1750 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1751
1752 (CONST_DOUBLE_MEM is used only for top-level functions.
1753 See force_const_mem for explanation.) */
79e68feb
RS
1754
1755static rtx const_double_chain;
1756
4db92e9a 1757/* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
79e68feb
RS
1758 For an integer, I0 is the low-order word and I1 is the high-order word.
1759 For a real number, I0 is the word with the low address
1760 and I1 is the word with the high address. */
1761
1762rtx
1763immed_double_const (i0, i1, mode)
37366632 1764 HOST_WIDE_INT i0, i1;
79e68feb
RS
1765 enum machine_mode mode;
1766{
1767 register rtx r;
1768 int in_current_obstack;
1769
ab8ab9d0
SC
1770 if (GET_MODE_CLASS (mode) == MODE_INT
1771 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
79e68feb
RS
1772 {
1773 /* We clear out all bits that don't belong in MODE, unless they and our
1774 sign bit are all one. So we get either a reasonable negative value
1775 or a reasonable unsigned value for this mode. */
1776 int width = GET_MODE_BITSIZE (mode);
37366632
RK
1777 if (width < HOST_BITS_PER_WIDE_INT
1778 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1779 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1780 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1781 else if (width == HOST_BITS_PER_WIDE_INT
79e68feb
RS
1782 && ! (i1 == ~0 && i0 < 0))
1783 i1 = 0;
37366632 1784 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
79e68feb
RS
1785 /* We cannot represent this value as a constant. */
1786 abort ();
1787
37366632 1788 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
79e68feb
RS
1789
1790 ??? Strictly speaking, this is wrong if we create a CONST_INT
1791 for a large unsigned constant with the size of MODE being
37366632
RK
1792 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1793 wider mode. In that case we will mis-interpret it as a negative
1794 number.
79e68feb
RS
1795
1796 Unfortunately, the only alternative is to make a CONST_DOUBLE
1797 for any constant in any mode if it is an unsigned constant larger
1798 than the maximum signed integer in an int on the host. However,
1799 doing this will break everyone that always expects to see a CONST_INT
1800 for SImode and smaller.
1801
1802 We have always been making CONST_INTs in this case, so nothing new
1803 is being broken. */
1804
37366632 1805 if (width <= HOST_BITS_PER_WIDE_INT)
79e68feb
RS
1806 i1 = (i0 < 0) ? ~0 : 0;
1807
1808 /* If this integer fits in one word, return a CONST_INT. */
1809 if ((i1 == 0 && i0 >= 0)
1810 || (i1 == ~0 && i0 < 0))
37366632 1811 return GEN_INT (i0);
79e68feb
RS
1812
1813 /* We use VOIDmode for integers. */
1814 mode = VOIDmode;
1815 }
1816
1817 /* Search the chain for an existing CONST_DOUBLE with the right value.
1818 If one is found, return it. */
1819
1820 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1821 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1822 && GET_MODE (r) == mode)
1823 return r;
1824
1825 /* No; make a new one and add it to the chain.
1826
1827 We may be called by an optimizer which may be discarding any memory
1828 allocated during its processing (such as combine and loop). However,
1829 we will be leaving this constant on the chain, so we cannot tolerate
1830 freed memory. So switch to saveable_obstack for this allocation
1831 and then switch back if we were in current_obstack. */
1832
2260924f
JW
1833 push_obstacks_nochange ();
1834 rtl_in_saveable_obstack ();
79e68feb 1835 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
2260924f 1836 pop_obstacks ();
79e68feb 1837
179bb78c
JW
1838 /* Don't touch const_double_chain in nested function; see force_const_mem.
1839 Also, don't touch it if not inside any function. */
1840 if (outer_function_chain == 0 && current_function_decl != 0)
5145eda8
RS
1841 {
1842 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1843 const_double_chain = r;
1844 }
79e68feb
RS
1845
1846 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1847 Actual use of mem-slot is only through force_const_mem. */
1848
1849 CONST_DOUBLE_MEM (r) = const0_rtx;
1850
1851 return r;
1852}
1853
1854/* Return a CONST_DOUBLE for a specified `double' value
1855 and machine mode. */
1856
1857rtx
1858immed_real_const_1 (d, mode)
1859 REAL_VALUE_TYPE d;
1860 enum machine_mode mode;
1861{
1862 union real_extract u;
1863 register rtx r;
1864 int in_current_obstack;
1865
1866 /* Get the desired `double' value as a sequence of ints
1867 since that is how they are stored in a CONST_DOUBLE. */
1868
1869 u.d = d;
1870
1871 /* Detect special cases. */
1872
f246a305
RS
1873 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1874 if (!bcmp (&dconst0, &d, sizeof d))
79e68feb 1875 return CONST0_RTX (mode);
12194c38
RS
1876 /* Check for NaN first, because some ports (specifically the i386) do not
1877 emit correct ieee-fp code by default, and thus will generate a core
1878 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1879 does a floating point comparison. */
1880 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
79e68feb
RS
1881 return CONST1_RTX (mode);
1882
37366632 1883 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
79e68feb
RS
1884 return immed_double_const (u.i[0], u.i[1], mode);
1885
1886 /* The rest of this function handles the case where
1887 a float value requires more than 2 ints of space.
1888 It will be deleted as dead code on machines that don't need it. */
1889
1890 /* Search the chain for an existing CONST_DOUBLE with the right value.
1891 If one is found, return it. */
1892
1893 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1894 if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
1895 && GET_MODE (r) == mode)
1896 return r;
1897
1898 /* No; make a new one and add it to the chain.
1899
1900 We may be called by an optimizer which may be discarding any memory
1901 allocated during its processing (such as combine and loop). However,
1902 we will be leaving this constant on the chain, so we cannot tolerate
1903 freed memory. So switch to saveable_obstack for this allocation
1904 and then switch back if we were in current_obstack. */
1905
2260924f
JW
1906 push_obstacks_nochange ();
1907 rtl_in_saveable_obstack ();
79e68feb
RS
1908 r = rtx_alloc (CONST_DOUBLE);
1909 PUT_MODE (r, mode);
1910 bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
2260924f 1911 pop_obstacks ();
79e68feb 1912
179bb78c
JW
1913 /* Don't touch const_double_chain in nested function; see force_const_mem.
1914 Also, don't touch it if not inside any function. */
1915 if (outer_function_chain == 0 && current_function_decl != 0)
5145eda8
RS
1916 {
1917 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1918 const_double_chain = r;
1919 }
79e68feb
RS
1920
1921 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1922 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1923 is only through force_const_mem. */
1924
1925 CONST_DOUBLE_MEM (r) = const0_rtx;
1926
1927 return r;
1928}
1929
1930/* Return a CONST_DOUBLE rtx for a value specified by EXP,
1931 which must be a REAL_CST tree node. */
1932
1933rtx
1934immed_real_const (exp)
1935 tree exp;
1936{
1937 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1938}
1939
1940/* At the end of a function, forget the memory-constants
1941 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1942 Also clear out real_constant_chain and clear out all the chain-pointers. */
1943
1944void
1945clear_const_double_mem ()
1946{
1947 register rtx r, next;
1948
57632c51
RS
1949 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1950 See force_const_mem for explanation. */
1951 if (outer_function_chain != 0)
1952 return;
1953
79e68feb
RS
1954 for (r = const_double_chain; r; r = next)
1955 {
1956 next = CONST_DOUBLE_CHAIN (r);
1957 CONST_DOUBLE_CHAIN (r) = 0;
1958 CONST_DOUBLE_MEM (r) = cc0_rtx;
1959 }
1960 const_double_chain = 0;
1961}
1962\f
1963/* Given an expression EXP with a constant value,
1964 reduce it to the sum of an assembler symbol and an integer.
1965 Store them both in the structure *VALUE.
1966 Abort if EXP does not reduce. */
1967
1968struct addr_const
1969{
1970 rtx base;
fb351073 1971 HOST_WIDE_INT offset;
79e68feb
RS
1972};
1973
1974static void
1975decode_addr_const (exp, value)
1976 tree exp;
1977 struct addr_const *value;
1978{
1979 register tree target = TREE_OPERAND (exp, 0);
1980 register int offset = 0;
1981 register rtx x;
1982
1983 while (1)
1984 {
1985 if (TREE_CODE (target) == COMPONENT_REF
1986 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
1987 == INTEGER_CST))
1988 {
1989 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
1990 target = TREE_OPERAND (target, 0);
1991 }
1992 else if (TREE_CODE (target) == ARRAY_REF)
1993 {
1994 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
1995 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
1996 abort ();
1997 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
1998 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
1999 / BITS_PER_UNIT);
2000 target = TREE_OPERAND (target, 0);
2001 }
2002 else
2003 break;
2004 }
2005
2006 switch (TREE_CODE (target))
2007 {
2008 case VAR_DECL:
2009 case FUNCTION_DECL:
2010 x = DECL_RTL (target);
2011 break;
2012
2013 case LABEL_DECL:
ca695ac9
JB
2014 if (output_bytecode)
2015 /* FIXME: this may not be correct, check it */
2016 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
2017 else
2018 x = gen_rtx (MEM, FUNCTION_MODE,
2019 gen_rtx (LABEL_REF, VOIDmode,
2020 label_rtx (TREE_OPERAND (exp, 0))));
79e68feb
RS
2021 break;
2022
2023 case REAL_CST:
2024 case STRING_CST:
2025 case COMPLEX_CST:
2026 case CONSTRUCTOR:
2027 x = TREE_CST_RTL (target);
2028 break;
2029
2030 default:
2031 abort ();
2032 }
2033
ca695ac9
JB
2034 if (!output_bytecode)
2035 {
2036 if (GET_CODE (x) != MEM)
2037 abort ();
2038 x = XEXP (x, 0);
2039 }
79e68feb
RS
2040
2041 value->base = x;
2042 value->offset = offset;
2043}
2044\f
2045/* Uniquize all constants that appear in memory.
2046 Each constant in memory thus far output is recorded
2047 in `const_hash_table' with a `struct constant_descriptor'
2048 that contains a polish representation of the value of
2049 the constant.
2050
2051 We cannot store the trees in the hash table
2052 because the trees may be temporary. */
2053
2054struct constant_descriptor
2055{
2056 struct constant_descriptor *next;
2057 char *label;
2058 char contents[1];
2059};
2060
2061#define HASHBITS 30
2062#define MAX_HASH_TABLE 1009
2063static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2064
2065/* Compute a hash code for a constant expression. */
2066
2067int
2068const_hash (exp)
2069 tree exp;
2070{
2071 register char *p;
2072 register int len, hi, i;
2073 register enum tree_code code = TREE_CODE (exp);
2074
2075 if (code == INTEGER_CST)
2076 {
2077 p = (char *) &TREE_INT_CST_LOW (exp);
2078 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2079 }
2080 else if (code == REAL_CST)
2081 {
2082 p = (char *) &TREE_REAL_CST (exp);
2083 len = sizeof TREE_REAL_CST (exp);
2084 }
2085 else if (code == STRING_CST)
2086 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2087 else if (code == COMPLEX_CST)
2088 return const_hash (TREE_REALPART (exp)) * 5
2089 + const_hash (TREE_IMAGPART (exp));
2090 else if (code == CONSTRUCTOR)
2091 {
2092 register tree link;
2093
2094 /* For record type, include the type in the hashing.
2095 We do not do so for array types
2096 because (1) the sizes of the elements are sufficient
eb528802
RS
2097 and (2) distinct array types can have the same constructor.
2098 Instead, we include the array size because the constructor could
2099 be shorter. */
79e68feb 2100 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
fb351073
RK
2101 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2102 % MAX_HASH_TABLE;
79e68feb 2103 else
eb528802
RS
2104 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2105 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
79e68feb
RS
2106
2107 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
77fa0940
RK
2108 if (TREE_VALUE (link))
2109 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
79e68feb
RS
2110
2111 return hi;
2112 }
2113 else if (code == ADDR_EXPR)
2114 {
2115 struct addr_const value;
2116 decode_addr_const (exp, &value);
2117 if (GET_CODE (value.base) == SYMBOL_REF)
2118 {
2119 /* Don't hash the address of the SYMBOL_REF;
2120 only use the offset and the symbol name. */
2121 hi = value.offset;
2122 p = XSTR (value.base, 0);
2123 for (i = 0; p[i] != 0; i++)
2124 hi = ((hi * 613) + (unsigned)(p[i]));
2125 }
2126 else if (GET_CODE (value.base) == LABEL_REF)
2127 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2128
2129 hi &= (1 << HASHBITS) - 1;
2130 hi %= MAX_HASH_TABLE;
2131 return hi;
2132 }
2133 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2134 return const_hash (TREE_OPERAND (exp, 0)) * 9
2135 + const_hash (TREE_OPERAND (exp, 1));
2136 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2137 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2138
2139 /* Compute hashing function */
2140 hi = len;
2141 for (i = 0; i < len; i++)
2142 hi = ((hi * 613) + (unsigned)(p[i]));
2143
2144 hi &= (1 << HASHBITS) - 1;
2145 hi %= MAX_HASH_TABLE;
2146 return hi;
2147}
2148\f
2149/* Compare a constant expression EXP with a constant-descriptor DESC.
2150 Return 1 if DESC describes a constant with the same value as EXP. */
2151
2152static int
2153compare_constant (exp, desc)
2154 tree exp;
2155 struct constant_descriptor *desc;
2156{
2157 return 0 != compare_constant_1 (exp, desc->contents);
2158}
2159
2160/* Compare constant expression EXP with a substring P of a constant descriptor.
2161 If they match, return a pointer to the end of the substring matched.
2162 If they do not match, return 0.
2163
2164 Since descriptors are written in polish prefix notation,
2165 this function can be used recursively to test one operand of EXP
2166 against a subdescriptor, and if it succeeds it returns the
2167 address of the subdescriptor for the next operand. */
2168
2169static char *
2170compare_constant_1 (exp, p)
2171 tree exp;
2172 char *p;
2173{
2174 register char *strp;
2175 register int len;
2176 register enum tree_code code = TREE_CODE (exp);
2177
2178 if (code != (enum tree_code) *p++)
2179 return 0;
2180
2181 if (code == INTEGER_CST)
2182 {
2183 /* Integer constants are the same only if the same width of type. */
2184 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2185 return 0;
2186 strp = (char *) &TREE_INT_CST_LOW (exp);
2187 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2188 }
2189 else if (code == REAL_CST)
2190 {
2191 /* Real constants are the same only if the same width of type. */
2192 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2193 return 0;
2194 strp = (char *) &TREE_REAL_CST (exp);
2195 len = sizeof TREE_REAL_CST (exp);
2196 }
2197 else if (code == STRING_CST)
2198 {
2199 if (flag_writable_strings)
2200 return 0;
2201 strp = TREE_STRING_POINTER (exp);
2202 len = TREE_STRING_LENGTH (exp);
2203 if (bcmp (&TREE_STRING_LENGTH (exp), p,
2204 sizeof TREE_STRING_LENGTH (exp)))
2205 return 0;
2206 p += sizeof TREE_STRING_LENGTH (exp);
2207 }
2208 else if (code == COMPLEX_CST)
2209 {
2210 p = compare_constant_1 (TREE_REALPART (exp), p);
2211 if (p == 0) return 0;
2212 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2213 return p;
2214 }
2215 else if (code == CONSTRUCTOR)
2216 {
2217 register tree link;
2218 int length = list_length (CONSTRUCTOR_ELTS (exp));
2219 tree type;
2220
2221 if (bcmp (&length, p, sizeof length))
2222 return 0;
2223 p += sizeof length;
2224
2225 /* For record constructors, insist that the types match.
2226 For arrays, just verify both constructors are for arrays. */
2227 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2228 type = TREE_TYPE (exp);
2229 else
2230 type = 0;
2231 if (bcmp (&type, p, sizeof type))
2232 return 0;
2233 p += sizeof type;
2234
eb528802
RS
2235 /* For arrays, insist that the size in bytes match. */
2236 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2237 {
2238 int size = int_size_in_bytes (TREE_TYPE (exp));
2239 if (bcmp (&size, p, sizeof size))
2240 return 0;
2241 p += sizeof size;
2242 }
2243
79e68feb 2244 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
77fa0940
RK
2245 {
2246 if (TREE_VALUE (link))
2247 {
2248 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2249 return 0;
2250 }
2251 else
2252 {
2253 tree zero = 0;
2254
2255 if (bcmp (&zero, p, sizeof zero))
2256 return 0;
2257 p += sizeof zero;
2258 }
2259 }
2260
79e68feb
RS
2261 return p;
2262 }
2263 else if (code == ADDR_EXPR)
2264 {
2265 struct addr_const value;
2266 decode_addr_const (exp, &value);
2267 strp = (char *) &value.offset;
2268 len = sizeof value.offset;
2269 /* Compare the offset. */
2270 while (--len >= 0)
2271 if (*p++ != *strp++)
2272 return 0;
2273 /* Compare symbol name. */
2274 strp = XSTR (value.base, 0);
2275 len = strlen (strp) + 1;
2276 }
2277 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2278 {
2279 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2280 if (p == 0) return 0;
2281 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2282 return p;
2283 }
2284 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2285 {
2286 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2287 return p;
2288 }
2289
2290 /* Compare constant contents. */
2291 while (--len >= 0)
2292 if (*p++ != *strp++)
2293 return 0;
2294
2295 return p;
2296}
2297\f
2298/* Construct a constant descriptor for the expression EXP.
2299 It is up to the caller to enter the descriptor in the hash table. */
2300
2301static struct constant_descriptor *
2302record_constant (exp)
2303 tree exp;
2304{
387e854a
RK
2305 struct constant_descriptor *next = 0;
2306 char *label = 0;
79e68feb 2307
387e854a
RK
2308 /* Make a struct constant_descriptor. The first two pointers will
2309 be filled in later. Here we just leave space for them. */
2310
2311 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2312 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
79e68feb
RS
2313 record_constant_1 (exp);
2314 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2315}
2316
2317/* Add a description of constant expression EXP
2318 to the object growing in `permanent_obstack'.
2319 No need to return its address; the caller will get that
2320 from the obstack when the object is complete. */
2321
2322static void
2323record_constant_1 (exp)
2324 tree exp;
2325{
2326 register char *strp;
2327 register int len;
2328 register enum tree_code code = TREE_CODE (exp);
2329
2330 obstack_1grow (&permanent_obstack, (unsigned int) code);
2331
2332 if (code == INTEGER_CST)
2333 {
2334 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2335 strp = (char *) &TREE_INT_CST_LOW (exp);
2336 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2337 }
2338 else if (code == REAL_CST)
2339 {
2340 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2341 strp = (char *) &TREE_REAL_CST (exp);
2342 len = sizeof TREE_REAL_CST (exp);
2343 }
2344 else if (code == STRING_CST)
2345 {
2346 if (flag_writable_strings)
2347 return;
2348 strp = TREE_STRING_POINTER (exp);
2349 len = TREE_STRING_LENGTH (exp);
2350 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2351 sizeof TREE_STRING_LENGTH (exp));
2352 }
2353 else if (code == COMPLEX_CST)
2354 {
2355 record_constant_1 (TREE_REALPART (exp));
2356 record_constant_1 (TREE_IMAGPART (exp));
2357 return;
2358 }
2359 else if (code == CONSTRUCTOR)
2360 {
2361 register tree link;
2362 int length = list_length (CONSTRUCTOR_ELTS (exp));
2363 tree type;
2364
2365 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2366
2367 /* For record constructors, insist that the types match.
2368 For arrays, just verify both constructors are for arrays. */
2369 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2370 type = TREE_TYPE (exp);
2371 else
2372 type = 0;
2373 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2374
eb528802
RS
2375 /* For arrays, insist that the size in bytes match. */
2376 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2377 {
2378 int size = int_size_in_bytes (TREE_TYPE (exp));
2379 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2380 }
2381
79e68feb 2382 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
77fa0940
RK
2383 {
2384 if (TREE_VALUE (link))
2385 record_constant_1 (TREE_VALUE (link));
2386 else
2387 {
2388 tree zero = 0;
2389
2390 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
2391 }
2392 }
2393
79e68feb
RS
2394 return;
2395 }
2396 else if (code == ADDR_EXPR)
2397 {
2398 struct addr_const value;
2399 decode_addr_const (exp, &value);
2400 /* Record the offset. */
2401 obstack_grow (&permanent_obstack,
2402 (char *) &value.offset, sizeof value.offset);
2403 /* Record the symbol name. */
2404 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2405 strlen (XSTR (value.base, 0)) + 1);
2406 return;
2407 }
2408 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2409 {
2410 record_constant_1 (TREE_OPERAND (exp, 0));
2411 record_constant_1 (TREE_OPERAND (exp, 1));
2412 return;
2413 }
2414 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2415 {
2416 record_constant_1 (TREE_OPERAND (exp, 0));
2417 return;
2418 }
2419
2420 /* Record constant contents. */
2421 obstack_grow (&permanent_obstack, strp, len);
2422}
2423\f
ff8f4401
RS
2424/* Record a list of constant expressions that were passed to
2425 output_constant_def but that could not be output right away. */
2426
2427struct deferred_constant
2428{
2429 struct deferred_constant *next;
2430 tree exp;
2431 int reloc;
2432 int labelno;
2433};
2434
2435static struct deferred_constant *deferred_constants;
2436
2437/* Nonzero means defer output of addressed subconstants
2438 (i.e., those for which output_constant_def is called.) */
2439static int defer_addressed_constants_flag;
2440
2441/* Start deferring output of subconstants. */
2442
2443void
2444defer_addressed_constants ()
2445{
2446 defer_addressed_constants_flag++;
2447}
2448
2449/* Stop deferring output of subconstants,
2450 and output now all those that have been deferred. */
2451
2452void
2453output_deferred_addressed_constants ()
2454{
2455 struct deferred_constant *p, *next;
2456
2457 defer_addressed_constants_flag--;
2458
2459 if (defer_addressed_constants_flag > 0)
2460 return;
2461
2462 for (p = deferred_constants; p; p = next)
2463 {
2464 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2465 next = p->next;
2466 free (p);
2467 }
2468
2469 deferred_constants = 0;
2470}
d12516f1
RS
2471
2472/* Make a copy of the whole tree structure for a constant.
2473 This handles the same types of nodes that compare_constant
2474 and record_constant handle. */
2475
2476static tree
2477copy_constant (exp)
2478 tree exp;
2479{
2480 switch (TREE_CODE (exp))
2481 {
2482 case INTEGER_CST:
2483 case REAL_CST:
2484 case STRING_CST:
2485 case ADDR_EXPR:
2486 /* For ADDR_EXPR, we do not want to copy the decl
2487 whose address is requested. */
2488 return copy_node (exp);
2489
2490 case COMPLEX_CST:
2491 return build_complex (copy_constant (TREE_REALPART (exp)),
2492 copy_constant (TREE_IMAGPART (exp)));
2493
2494 case PLUS_EXPR:
2495 case MINUS_EXPR:
2496 return build (TREE_CODE (exp), TREE_TYPE (exp),
2497 copy_constant (TREE_OPERAND (exp, 0)),
2498 copy_constant (TREE_OPERAND (exp, 1)));
2499
2500 case NOP_EXPR:
2501 case CONVERT_EXPR:
2502 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2503 copy_constant (TREE_OPERAND (exp, 0)));
2504
2505 case CONSTRUCTOR:
2506 {
2507 tree copy = copy_node (exp);
2508 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2509 tree tail;
2510
2511 CONSTRUCTOR_ELTS (exp) = list;
2512 for (tail = list; tail; tail = TREE_CHAIN (tail))
2513 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2514
2515 return copy;
2516 }
2517
2518 default:
2519 abort ();
2520 }
2521}
ff8f4401 2522\f
79e68feb
RS
2523/* Return an rtx representing a reference to constant data in memory
2524 for the constant expression EXP.
ff8f4401 2525
79e68feb
RS
2526 If assembler code for such a constant has already been output,
2527 return an rtx to refer to it.
ff8f4401
RS
2528 Otherwise, output such a constant in memory (or defer it for later)
2529 and generate an rtx for it.
2530
2531 The TREE_CST_RTL of EXP is set up to point to that rtx.
79e68feb
RS
2532 The const_hash_table records which constants already have label strings. */
2533
2534rtx
2535output_constant_def (exp)
2536 tree exp;
2537{
ff8f4401 2538 register int hash;
79e68feb
RS
2539 register struct constant_descriptor *desc;
2540 char label[256];
2541 char *found = 0;
2542 int reloc;
2543 register rtx def;
2544
2545 if (TREE_CODE (exp) == INTEGER_CST)
2546 abort (); /* No TREE_CST_RTL slot in these. */
2547
2548 if (TREE_CST_RTL (exp))
2549 return TREE_CST_RTL (exp);
2550
2551 /* Make sure any other constants whose addresses appear in EXP
2552 are assigned label numbers. */
2553
2554 reloc = output_addressed_constants (exp);
2555
2556 /* Compute hash code of EXP. Search the descriptors for that hash code
2557 to see if any of them describes EXP. If yes, the descriptor records
2558 the label number already assigned. */
2559
00f07fb9 2560 hash = const_hash (exp) % MAX_HASH_TABLE;
ca695ac9 2561
00f07fb9
RK
2562 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2563 if (compare_constant (exp, desc))
2564 {
2565 found = desc->label;
2566 break;
2567 }
ca695ac9 2568
00f07fb9
RK
2569 if (found == 0)
2570 {
2571 /* No constant equal to EXP is known to have been output.
2572 Make a constant descriptor to enter EXP in the hash table.
2573 Assign the label number and record it in the descriptor for
2574 future calls to this function to find. */
ca695ac9 2575
00f07fb9
RK
2576 /* Create a string containing the label name, in LABEL. */
2577 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2578
2579 desc = record_constant (exp);
2580 desc->next = const_hash_table[hash];
2581 desc->label
2582 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2583 const_hash_table[hash] = desc;
2584 }
2585 else
2586 {
2587 /* Create a string containing the label name, in LABEL. */
2588 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
79e68feb 2589 }
ca695ac9 2590
79e68feb
RS
2591 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2592
2593 push_obstacks_nochange ();
2594 if (TREE_PERMANENT (exp))
2595 end_temporary_allocation ();
2596
00f07fb9 2597 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
ca695ac9 2598
00f07fb9
RK
2599 TREE_CST_RTL (exp)
2600 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2601 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2602 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
2603 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2604 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2605
79e68feb
RS
2606 pop_obstacks ();
2607
2608 /* Optionally set flags or add text to the name to record information
2609 such as that it is a function name. If the name is changed, the macro
8a425a05 2610 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
79e68feb
RS
2611#ifdef ENCODE_SECTION_INFO
2612 ENCODE_SECTION_INFO (exp);
2613#endif
2614
ff8f4401
RS
2615 /* If this is the first time we've seen this particular constant,
2616 output it (or defer its output for later). */
79e68feb
RS
2617 if (found == 0)
2618 {
ff8f4401
RS
2619 if (defer_addressed_constants_flag)
2620 {
2621 struct deferred_constant *p;
2622 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2623
ff8f4401
RS
2624 push_obstacks_nochange ();
2625 suspend_momentary ();
d12516f1 2626 p->exp = copy_constant (exp);
ff8f4401
RS
2627 pop_obstacks ();
2628 p->reloc = reloc;
2629 p->labelno = const_labelno++;
2630 p->next = deferred_constants;
2631 deferred_constants = p;
2632 }
2633 else
2634 output_constant_def_contents (exp, reloc, const_labelno++);
2635 }
2636
2637 return TREE_CST_RTL (exp);
2638}
2639
2640/* Now output assembler code to define the label for EXP,
2641 and follow it with the data of EXP. */
79e68feb 2642
ff8f4401
RS
2643static void
2644output_constant_def_contents (exp, reloc, labelno)
2645 tree exp;
2646 int reloc;
2647 int labelno;
2648{
2649 int align;
2650
8a425a05
DE
2651 if (IN_NAMED_SECTION (exp))
2652 named_section (TREE_STRING_POINTER (DECL_SECTION_NAME (exp)));
2653 else
2654 {
2655 /* First switch to text section, except for writable strings. */
79e68feb 2656#ifdef SELECT_SECTION
8a425a05 2657 SELECT_SECTION (exp, reloc);
79e68feb 2658#else
8a425a05
DE
2659 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2660 || (flag_pic && reloc))
2661 data_section ();
2662 else
2663 readonly_data_section ();
79e68feb 2664#endif
8a425a05 2665 }
79e68feb 2666
ff8f4401
RS
2667 /* Align the location counter as required by EXP's data type. */
2668 align = TYPE_ALIGN (TREE_TYPE (exp));
79e68feb 2669#ifdef CONSTANT_ALIGNMENT
ff8f4401 2670 align = CONSTANT_ALIGNMENT (exp, align);
79e68feb
RS
2671#endif
2672
ff8f4401 2673 if (align > BITS_PER_UNIT)
ca695ac9
JB
2674 {
2675 if (!output_bytecode)
c02bd5d9
JB
2676 {
2677 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2678 }
ca695ac9 2679 else
c02bd5d9
JB
2680 {
2681 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2682 }
ca695ac9 2683 }
79e68feb 2684
ff8f4401
RS
2685 /* Output the label itself. */
2686 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
79e68feb 2687
ff8f4401
RS
2688 /* Output the value of EXP. */
2689 output_constant (exp,
2690 (TREE_CODE (exp) == STRING_CST
2691 ? TREE_STRING_LENGTH (exp)
2692 : int_size_in_bytes (TREE_TYPE (exp))));
79e68feb 2693
79e68feb
RS
2694}
2695\f
2696/* Similar hash facility for making memory-constants
2697 from constant rtl-expressions. It is used on RISC machines
2698 where immediate integer arguments and constant addresses are restricted
2699 so that such constants must be stored in memory.
2700
2701 This pool of constants is reinitialized for each function
2702 so each function gets its own constants-pool that comes right before it.
2703
2704 All structures allocated here are discarded when functions are saved for
2705 inlining, so they do not need to be allocated permanently. */
2706
2707#define MAX_RTX_HASH_TABLE 61
57632c51 2708static struct constant_descriptor **const_rtx_hash_table;
79e68feb
RS
2709
2710/* Structure to represent sufficient information about a constant so that
2711 it can be output when the constant pool is output, so that function
2712 integration can be done, and to simplify handling on machines that reference
2713 constant pool as base+displacement. */
2714
2715struct pool_constant
2716{
2717 struct constant_descriptor *desc;
2718 struct pool_constant *next;
2719 enum machine_mode mode;
2720 rtx constant;
2721 int labelno;
2722 int align;
2723 int offset;
2724};
2725
2726/* Pointers to first and last constant in pool. */
2727
2728static struct pool_constant *first_pool, *last_pool;
2729
2730/* Current offset in constant pool (does not include any machine-specific
2731 header. */
2732
2733static int pool_offset;
2734
2735/* Structure used to maintain hash table mapping symbols used to their
2736 corresponding constants. */
2737
2738struct pool_sym
2739{
2740 char *label;
2741 struct pool_constant *pool;
2742 struct pool_sym *next;
2743};
2744
57632c51 2745static struct pool_sym **const_rtx_sym_hash_table;
79e68feb
RS
2746
2747/* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2748 The argument is XSTR (... , 0) */
2749
2750#define SYMHASH(LABEL) \
fb351073 2751 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
79e68feb
RS
2752\f
2753/* Initialize constant pool hashing for next function. */
2754
2755void
2756init_const_rtx_hash_table ()
2757{
57632c51
RS
2758 const_rtx_hash_table
2759 = ((struct constant_descriptor **)
2760 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2761 const_rtx_sym_hash_table
2762 = ((struct pool_sym **)
2763 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2764 bzero (const_rtx_hash_table,
2765 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2766 bzero (const_rtx_sym_hash_table,
2767 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
79e68feb
RS
2768
2769 first_pool = last_pool = 0;
2770 pool_offset = 0;
2771}
2772
57632c51
RS
2773/* Save and restore it for a nested function. */
2774
2775void
2776save_varasm_status (p)
2777 struct function *p;
2778{
2779 p->const_rtx_hash_table = const_rtx_hash_table;
2780 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2781 p->first_pool = first_pool;
2782 p->last_pool = last_pool;
2783 p->pool_offset = pool_offset;
2784}
2785
2786void
2787restore_varasm_status (p)
2788 struct function *p;
2789{
2790 const_rtx_hash_table = p->const_rtx_hash_table;
2791 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2792 first_pool = p->first_pool;
2793 last_pool = p->last_pool;
2794 pool_offset = p->pool_offset;
2795}
2796\f
79e68feb
RS
2797enum kind { RTX_DOUBLE, RTX_INT };
2798
2799struct rtx_const
2800{
2801#ifdef ONLY_INT_FIELDS
2802 unsigned int kind : 16;
2803 unsigned int mode : 16;
2804#else
2805 enum kind kind : 16;
2806 enum machine_mode mode : 16;
2807#endif
2808 union {
2809 union real_extract du;
2810 struct addr_const addr;
2811 } un;
2812};
2813
2814/* Express an rtx for a constant integer (perhaps symbolic)
2815 as the sum of a symbol or label plus an explicit integer.
2816 They are stored into VALUE. */
2817
2818static void
2819decode_rtx_const (mode, x, value)
2820 enum machine_mode mode;
2821 rtx x;
2822 struct rtx_const *value;
2823{
2824 /* Clear the whole structure, including any gaps. */
2825
2826 {
2827 int *p = (int *) value;
2828 int *end = (int *) (value + 1);
2829 while (p < end)
2830 *p++ = 0;
2831 }
2832
2833 value->kind = RTX_INT; /* Most usual kind. */
2834 value->mode = mode;
2835
2836 switch (GET_CODE (x))
2837 {
2838 case CONST_DOUBLE:
2839 value->kind = RTX_DOUBLE;
56e2d435
RK
2840 if (GET_MODE (x) != VOIDmode)
2841 value->mode = GET_MODE (x);
79e68feb
RS
2842 bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
2843 break;
2844
2845 case CONST_INT:
2846 value->un.addr.offset = INTVAL (x);
2847 break;
2848
2849 case SYMBOL_REF:
2850 case LABEL_REF:
3d037392 2851 case PC:
79e68feb
RS
2852 value->un.addr.base = x;
2853 break;
2854
2855 case CONST:
2856 x = XEXP (x, 0);
2857 if (GET_CODE (x) == PLUS)
2858 {
2859 value->un.addr.base = XEXP (x, 0);
2860 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2861 abort ();
2862 value->un.addr.offset = INTVAL (XEXP (x, 1));
2863 }
2864 else if (GET_CODE (x) == MINUS)
2865 {
2866 value->un.addr.base = XEXP (x, 0);
2867 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2868 abort ();
2869 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2870 }
2871 else
2872 abort ();
2873 break;
2874
2875 default:
2876 abort ();
2877 }
2878
2879 if (value->kind == RTX_INT && value->un.addr.base != 0)
2880 switch (GET_CODE (value->un.addr.base))
2881 {
2882 case SYMBOL_REF:
2883 case LABEL_REF:
2884 /* Use the string's address, not the SYMBOL_REF's address,
2885 for the sake of addresses of library routines.
2886 For a LABEL_REF, compare labels. */
2887 value->un.addr.base = XEXP (value->un.addr.base, 0);
2888 }
2889}
2890
57632c51
RS
2891/* Given a MINUS expression, simplify it if both sides
2892 include the same symbol. */
2893
2894rtx
2895simplify_subtraction (x)
2896 rtx x;
2897{
2898 struct rtx_const val0, val1;
2899
2900 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2901 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2902
2903 if (val0.un.addr.base == val1.un.addr.base)
2904 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2905 return x;
2906}
2907
79e68feb
RS
2908/* Compute a hash code for a constant RTL expression. */
2909
2910int
2911const_hash_rtx (mode, x)
2912 enum machine_mode mode;
2913 rtx x;
2914{
2915 register int hi, i;
2916
2917 struct rtx_const value;
2918 decode_rtx_const (mode, x, &value);
2919
2920 /* Compute hashing function */
2921 hi = 0;
2922 for (i = 0; i < sizeof value / sizeof (int); i++)
2923 hi += ((int *) &value)[i];
2924
2925 hi &= (1 << HASHBITS) - 1;
2926 hi %= MAX_RTX_HASH_TABLE;
2927 return hi;
2928}
2929
2930/* Compare a constant rtl object X with a constant-descriptor DESC.
2931 Return 1 if DESC describes a constant with the same value as X. */
2932
2933static int
2934compare_constant_rtx (mode, x, desc)
2935 enum machine_mode mode;
2936 rtx x;
2937 struct constant_descriptor *desc;
2938{
2939 register int *p = (int *) desc->contents;
2940 register int *strp;
2941 register int len;
2942 struct rtx_const value;
2943
2944 decode_rtx_const (mode, x, &value);
2945 strp = (int *) &value;
2946 len = sizeof value / sizeof (int);
2947
2948 /* Compare constant contents. */
2949 while (--len >= 0)
2950 if (*p++ != *strp++)
2951 return 0;
2952
2953 return 1;
2954}
2955
2956/* Construct a constant descriptor for the rtl-expression X.
2957 It is up to the caller to enter the descriptor in the hash table. */
2958
2959static struct constant_descriptor *
2960record_constant_rtx (mode, x)
2961 enum machine_mode mode;
2962 rtx x;
2963{
2964 struct constant_descriptor *ptr;
2965 char *label;
2966 struct rtx_const value;
2967
2968 decode_rtx_const (mode, x, &value);
2969
2970 obstack_grow (current_obstack, &ptr, sizeof ptr);
2971 obstack_grow (current_obstack, &label, sizeof label);
2972
2973 /* Record constant contents. */
2974 obstack_grow (current_obstack, &value, sizeof value);
2975
2976 return (struct constant_descriptor *) obstack_finish (current_obstack);
2977}
2978\f
2979/* Given a constant rtx X, make (or find) a memory constant for its value
2980 and return a MEM rtx to refer to it in memory. */
2981
2982rtx
2983force_const_mem (mode, x)
2984 enum machine_mode mode;
2985 rtx x;
2986{
2987 register int hash;
2988 register struct constant_descriptor *desc;
2989 char label[256];
2990 char *found = 0;
2991 rtx def;
2992
2993 /* If we want this CONST_DOUBLE in the same mode as it is in memory
2994 (this will always be true for floating CONST_DOUBLEs that have been
2995 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
2996 use the previous copy. Otherwise, make a new one. Note that in
2997 the unlikely event that this same CONST_DOUBLE is used in two different
2998 modes in an alternating fashion, we will allocate a lot of different
2999 memory locations, but this should be extremely rare. */
3000
57632c51
RS
3001 /* Don't use CONST_DOUBLE_MEM in a nested function.
3002 Nested functions have their own constant pools,
3003 so they can't share the same values in CONST_DOUBLE_MEM
3004 with the containing function. */
3005 if (outer_function_chain == 0)
3006 if (GET_CODE (x) == CONST_DOUBLE
3007 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3008 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3009 return CONST_DOUBLE_MEM (x);
79e68feb
RS
3010
3011 /* Compute hash code of X. Search the descriptors for that hash code
3012 to see if any of them describes X. If yes, the descriptor records
3013 the label number already assigned. */
3014
3015 hash = const_hash_rtx (mode, x);
3016
3017 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3018 if (compare_constant_rtx (mode, x, desc))
3019 {
3020 found = desc->label;
3021 break;
3022 }
3023
3024 if (found == 0)
3025 {
3026 register struct pool_constant *pool;
3027 register struct pool_sym *sym;
3028 int align;
3029
3030 /* No constant equal to X is known to have been output.
3031 Make a constant descriptor to enter X in the hash table.
3032 Assign the label number and record it in the descriptor for
3033 future calls to this function to find. */
3034
3035 desc = record_constant_rtx (mode, x);
3036 desc->next = const_rtx_hash_table[hash];
3037 const_rtx_hash_table[hash] = desc;
3038
3039 /* Align the location counter as required by EXP's data type. */
3040 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3041 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3042 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3043
3044 pool_offset += align - 1;
3045 pool_offset &= ~ (align - 1);
3046
3047 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3048
3049 pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
3050 pool->desc = desc;
3051 pool->constant = x;
3052 pool->mode = mode;
3053 pool->labelno = const_labelno;
3054 pool->align = align;
3055 pool->offset = pool_offset;
3056 pool->next = 0;
3057
3058 if (last_pool == 0)
3059 first_pool = pool;
3060 else
3061 last_pool->next = pool;
3062
3063 last_pool = pool;
3064 pool_offset += GET_MODE_SIZE (mode);
3065
3066 /* Create a string containing the label name, in LABEL. */
3067 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3068
3069 ++const_labelno;
3070
3071 desc->label = found
3072 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3073
3074 /* Add label to symbol hash table. */
3075 hash = SYMHASH (found);
3076 sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
3077 sym->label = found;
3078 sym->pool = pool;
3079 sym->next = const_rtx_sym_hash_table[hash];
3080 const_rtx_sym_hash_table[hash] = sym;
3081 }
3082
3083 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3084
3085 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3086
3087 RTX_UNCHANGING_P (def) = 1;
3088 /* Mark the symbol_ref as belonging to this constants pool. */
3089 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3090 current_function_uses_const_pool = 1;
3091
57632c51
RS
3092 if (outer_function_chain == 0)
3093 if (GET_CODE (x) == CONST_DOUBLE)
3094 {
3095 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3096 {
3097 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3098 const_double_chain = x;
3099 }
3100 CONST_DOUBLE_MEM (x) = def;
3101 }
79e68feb
RS
3102
3103 return def;
3104}
3105\f
3106/* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3107 the corresponding pool_constant structure. */
3108
3109static struct pool_constant *
3110find_pool_constant (addr)
3111 rtx addr;
3112{
3113 struct pool_sym *sym;
3114 char *label = XSTR (addr, 0);
3115
3116 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3117 if (sym->label == label)
3118 return sym->pool;
3119
3120 abort ();
3121}
3122
3123/* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3124
3125rtx
3126get_pool_constant (addr)
3127 rtx addr;
3128{
3129 return (find_pool_constant (addr))->constant;
3130}
3131
3132/* Similar, return the mode. */
3133
3134enum machine_mode
3135get_pool_mode (addr)
3136 rtx addr;
3137{
3138 return (find_pool_constant (addr))->mode;
3139}
3140
3141/* Similar, return the offset in the constant pool. */
3142
3143int
3144get_pool_offset (addr)
3145 rtx addr;
3146{
3147 return (find_pool_constant (addr))->offset;
3148}
3149
3150/* Return the size of the constant pool. */
3151
3152int
3153get_pool_size ()
3154{
3155 return pool_offset;
3156}
3157\f
3158/* Write all the constants in the constant pool. */
3159
3160void
3161output_constant_pool (fnname, fndecl)
3162 char *fnname;
3163 tree fndecl;
3164{
3165 struct pool_constant *pool;
3166 rtx x;
3167 union real_extract u;
3168
3169#ifdef ASM_OUTPUT_POOL_PROLOGUE
3170 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3171#endif
3172
3173 for (pool = first_pool; pool; pool = pool->next)
3174 {
3175 x = pool->constant;
3176
3177 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3178 whose CODE_LABEL has been deleted. This can occur if a jump table
3179 is eliminated by optimization. If so, write a constant of zero
7b2b3f1f
RK
3180 instead. Note that this can also happen by turning the
3181 CODE_LABEL into a NOTE. */
3182 if (((GET_CODE (x) == LABEL_REF
3183 && (INSN_DELETED_P (XEXP (x, 0))
3184 || GET_CODE (XEXP (x, 0)) == NOTE)))
79e68feb
RS
3185 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3186 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
7b2b3f1f
RK
3187 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3188 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
79e68feb
RS
3189 x = const0_rtx;
3190
3191 /* First switch to correct section. */
3192#ifdef SELECT_RTX_SECTION
3193 SELECT_RTX_SECTION (pool->mode, x);
3194#else
3195 readonly_data_section ();
3196#endif
3197
3198#ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3199 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3200 pool->align, pool->labelno, done);
3201#endif
3202
3203 if (pool->align > 1)
3204 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3205
3206 /* Output the label. */
3207 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3208
3209 /* Output the value of the constant itself. */
3210 switch (GET_MODE_CLASS (pool->mode))
3211 {
3212 case MODE_FLOAT:
3213 if (GET_CODE (x) != CONST_DOUBLE)
3214 abort ();
3215
3216 bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
3217 assemble_real (u.d, pool->mode);
3218 break;
3219
3220 case MODE_INT:
ab8ab9d0 3221 case MODE_PARTIAL_INT:
79e68feb
RS
3222 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3223 break;
3224
3225 default:
3226 abort ();
3227 }
3228
3229 done: ;
3230 }
3231
3232 /* Done with this pool. */
3233 first_pool = last_pool = 0;
3234}
3235\f
3236/* Find all the constants whose addresses are referenced inside of EXP,
3237 and make sure assembler code with a label has been output for each one.
3238 Indicate whether an ADDR_EXPR has been encountered. */
3239
3240int
3241output_addressed_constants (exp)
3242 tree exp;
3243{
3244 int reloc = 0;
3245
3246 switch (TREE_CODE (exp))
3247 {
3248 case ADDR_EXPR:
3249 {
3250 register tree constant = TREE_OPERAND (exp, 0);
3251
3252 while (TREE_CODE (constant) == COMPONENT_REF)
3253 {
3254 constant = TREE_OPERAND (constant, 0);
3255 }
3256
3257 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3258 || TREE_CODE (constant) == CONSTRUCTOR)
3259 /* No need to do anything here
3260 for addresses of variables or functions. */
3261 output_constant_def (constant);
3262 }
3263 reloc = 1;
3264 break;
3265
3266 case PLUS_EXPR:
3267 case MINUS_EXPR:
3268 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3269 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3270 break;
3271
3272 case NOP_EXPR:
3273 case CONVERT_EXPR:
37a52112 3274 case NON_LVALUE_EXPR:
79e68feb
RS
3275 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3276 break;
3277
3278 case CONSTRUCTOR:
3279 {
3280 register tree link;
3281 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3282 if (TREE_VALUE (link) != 0)
3283 reloc |= output_addressed_constants (TREE_VALUE (link));
3284 }
3285 break;
3286
3287 case ERROR_MARK:
3288 break;
3289 }
3290 return reloc;
3291}
ca695ac9
JB
3292
3293
3294/* Output assembler for byte constant */
3295void
3296output_byte_asm (byte)
3297 int byte;
3298{
3299 if (output_bytecode)
3300 bc_emit_const ((char *) &byte, sizeof (char));
3301#ifdef ASM_OUTPUT_BYTE
3302 else
3303 {
3304 ASM_OUTPUT_BYTE (asm_out_file, byte);
3305 }
3306#endif
3307}
79e68feb
RS
3308\f
3309/* Output assembler code for constant EXP to FILE, with no label.
3310 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3311 Assumes output_addressed_constants has been done on EXP already.
3312
3313 Generate exactly SIZE bytes of assembler data, padding at the end
3314 with zeros if necessary. SIZE must always be specified.
3315
3316 SIZE is important for structure constructors,
3317 since trailing members may have been omitted from the constructor.
3318 It is also important for initialization of arrays from string constants
3319 since the full length of the string constant might not be wanted.
3320 It is also needed for initialization of unions, where the initializer's
3321 type is just one member, and that may not be as long as the union.
3322
3323 There a case in which we would fail to output exactly SIZE bytes:
3324 for a structure constructor that wants to produce more than SIZE bytes.
3325 But such constructors will never be generated for any possible input. */
3326
3327void
3328output_constant (exp, size)
3329 register tree exp;
3330 register int size;
3331{
3332 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3333 rtx x;
3334
3335 if (size == 0)
3336 return;
3337
be1ad04c
RK
3338 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3339 That way we get the constant (we hope) inside it. Also, strip
3340 off any NOP_EXPR that converts between two record or union types. */
3341 while ((TREE_CODE (exp) == NOP_EXPR
3342 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3343 || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3344 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
3345 || TREE_CODE (TREE_TYPE (exp)) == QUAL_UNION_TYPE))
3346 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3347 exp = TREE_OPERAND (exp, 0);
3348
fff9e713
MT
3349 /* Allow a constructor with no elements for any data type.
3350 This means to fill the space with zeros. */
77fa0940 3351 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
fff9e713 3352 {
ca695ac9
JB
3353 if (output_bytecode)
3354 bc_emit_const_skip (size);
3355 else
3356 assemble_zeros (size);
fff9e713
MT
3357 return;
3358 }
3359
79e68feb
RS
3360 switch (code)
3361 {
644ea577
RS
3362 case CHAR_TYPE:
3363 case BOOLEAN_TYPE:
79e68feb
RS
3364 case INTEGER_TYPE:
3365 case ENUMERAL_TYPE:
3366 case POINTER_TYPE:
3367 case REFERENCE_TYPE:
3368 /* ??? What about (int)((float)(int)&foo + 4) */
3369 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3370 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3371 exp = TREE_OPERAND (exp, 0);
3372
37366632 3373 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
79e68feb
RS
3374 EXPAND_INITIALIZER),
3375 size, 0))
3376 error ("initializer for integer value is too complicated");
3377 size = 0;
3378 break;
3379
3380 case REAL_TYPE:
3381 if (TREE_CODE (exp) != REAL_CST)
3382 error ("initializer for floating value is not a floating constant");
3383
3384 assemble_real (TREE_REAL_CST (exp),
3385 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3386 size = 0;
3387 break;
3388
3389 case COMPLEX_TYPE:
3390 output_constant (TREE_REALPART (exp), size / 2);
3391 output_constant (TREE_IMAGPART (exp), size / 2);
3392 size -= (size / 2) * 2;
3393 break;
3394
3395 case ARRAY_TYPE:
3396 if (TREE_CODE (exp) == CONSTRUCTOR)
3397 {
3398 output_constructor (exp, size);
3399 return;
3400 }
3401 else if (TREE_CODE (exp) == STRING_CST)
3402 {
3403 int excess = 0;
3404
3405 if (size > TREE_STRING_LENGTH (exp))
3406 {
3407 excess = size - TREE_STRING_LENGTH (exp);
3408 size = TREE_STRING_LENGTH (exp);
3409 }
3410
3411 assemble_string (TREE_STRING_POINTER (exp), size);
3412 size = excess;
3413 }
3414 else
3415 abort ();
3416 break;
3417
3418 case RECORD_TYPE:
3419 case UNION_TYPE:
3420 if (TREE_CODE (exp) == CONSTRUCTOR)
3421 output_constructor (exp, size);
3422 else
3423 abort ();
3424 return;
3425 }
3426
3427 if (size > 0)
3428 assemble_zeros (size);
3429}
ca695ac9
JB
3430
3431
3432/* Bytecode specific code to output assembler for integer. */
6e828044 3433static void
ca695ac9
JB
3434bc_assemble_integer (exp, size)
3435 tree exp;
3436 int size;
3437{
3438 tree const_part;
3439 tree addr_part;
3440 tree tmp;
3441
3442 /* FIXME: is this fold() business going to be as good as the
3443 expand_expr() using EXPAND_SUM above in the RTL case? I
3444 hate RMS.
3445 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3446
3447 exp = fold (exp);
3448
3449 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3450 exp = TREE_OPERAND (exp, 0);
3451 if (TREE_CODE (exp) == INTEGER_CST)
3452 {
3453 const_part = exp;
3454 addr_part = 0;
3455 }
3456 else if (TREE_CODE (exp) == PLUS_EXPR)
3457 {
3458 const_part = TREE_OPERAND (exp, 0);
3459 while (TREE_CODE (const_part) == NOP_EXPR
3460 || TREE_CODE (const_part) == CONVERT_EXPR)
3461 const_part = TREE_OPERAND (const_part, 0);
3462 addr_part = TREE_OPERAND (exp, 1);
3463 while (TREE_CODE (addr_part) == NOP_EXPR
3464 || TREE_CODE (addr_part) == CONVERT_EXPR)
3465 addr_part = TREE_OPERAND (addr_part, 0);
3466 if (TREE_CODE (const_part) != INTEGER_CST)
3467 tmp = const_part, const_part = addr_part, addr_part = tmp;
3468 if (TREE_CODE (const_part) != INTEGER_CST
3469 || TREE_CODE (addr_part) != ADDR_EXPR)
3470 abort (); /* FIXME: we really haven't considered
3471 all the possible cases here. */
3472 }
3473 else if (TREE_CODE (exp) == ADDR_EXPR)
3474 {
3475 const_part = integer_zero_node;
3476 addr_part = exp;
3477 }
3478 else
3479 abort (); /* FIXME: ditto previous. */
3480
3481 if (addr_part == 0)
3482 {
3483 if (size == 1)
3484 {
3485 char c = TREE_INT_CST_LOW (const_part);
3486 bc_emit (&c, 1);
3487 size -= 1;
3488 }
3489 else if (size == 2)
3490 {
3491 short s = TREE_INT_CST_LOW (const_part);
3492 bc_emit ((char *) &s, 2);
3493 size -= 2;
3494 }
3495 else if (size == 4)
3496 {
3497 int i = TREE_INT_CST_LOW (const_part);
3498 bc_emit ((char *) &i, 4);
3499 size -= 4;
3500 }
3501 else if (size == 8)
3502 {
3503#if WORDS_BIG_ENDIAN
3504 int i = TREE_INT_CST_HIGH (const_part);
3505 bc_emit ((char *) &i, 4);
3506 i = TREE_INT_CST_LOW (const_part);
3507 bc_emit ((char *) &i, 4);
3508#else
3509 int i = TREE_INT_CST_LOW (const_part);
3510 bc_emit ((char *) &i, 4);
3511 i = TREE_INT_CST_HIGH (const_part);
3512 bc_emit ((char *) &i, 4);
3513#endif
3514 size -= 8;
3515 }
3516 }
3517 else
3518 if (size == 4
3519 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3520 bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3521 TREE_INT_CST_LOW (const_part));
3522 else
3523 abort (); /* FIXME: there may be more cases. */
3524}
79e68feb
RS
3525\f
3526/* Subroutine of output_constant, used for CONSTRUCTORs
3527 (aggregate constants).
3528 Generate at least SIZE bytes, padding if necessary. */
3529
3530void
3531output_constructor (exp, size)
3532 tree exp;
3533 int size;
3534{
3535 register tree link, field = 0;
13b457e7 3536 HOST_WIDE_INT min_index = 0;
79e68feb
RS
3537 /* Number of bytes output or skipped so far.
3538 In other words, current position within the constructor. */
3539 int total_bytes = 0;
3540 /* Non-zero means BYTE contains part of a byte, to be output. */
3541 int byte_buffer_in_use = 0;
3542 register int byte;
3543
37366632 3544 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
79e68feb
RS
3545 abort ();
3546
3547 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3548 field = TYPE_FIELDS (TREE_TYPE (exp));
3549
d12516f1
RS
3550 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3551 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
13b457e7
RK
3552 min_index
3553 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3554
79e68feb
RS
3555 /* As LINK goes through the elements of the constant,
3556 FIELD goes through the structure fields, if the constant is a structure.
3557 if the constant is a union, then we override this,
3558 by getting the field from the TREE_LIST element.
3559 But the constant could also be an array. Then FIELD is zero. */
3560 for (link = CONSTRUCTOR_ELTS (exp);
3561 link;
3562 link = TREE_CHAIN (link),
3563 field = field ? TREE_CHAIN (field) : 0)
3564 {
3565 tree val = TREE_VALUE (link);
3181cbfd
RS
3566 tree index = 0;
3567
79e68feb 3568 /* the element in a union constructor specifies the proper field. */
3181cbfd
RS
3569
3570 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3571 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
1108dc3d
KKT
3572 {
3573 /* if available, use the type given by link */
3574 if (TREE_PURPOSE (link) != 0)
3575 field = TREE_PURPOSE (link);
3576 }
79e68feb 3577
3181cbfd
RS
3578 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3579 index = TREE_PURPOSE (link);
3580
79e68feb 3581 /* Eliminate the marker that makes a cast not be an lvalue. */
d964285c
CH
3582 if (val != 0)
3583 STRIP_NOPS (val);
79e68feb
RS
3584
3585 if (field == 0 || !DECL_BIT_FIELD (field))
3586 {
3181cbfd
RS
3587 /* An element that is not a bit-field. */
3588
79e68feb
RS
3589 register int fieldsize;
3590 /* Since this structure is static,
3591 we know the positions are constant. */
3592 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3593 / BITS_PER_UNIT)
3594 : 0);
3181cbfd
RS
3595 if (index != 0)
3596 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3597 / BITS_PER_UNIT
13b457e7 3598 * (TREE_INT_CST_LOW (index) - min_index));
79e68feb 3599
3181cbfd 3600 /* Output any buffered-up bit-fields preceding this element. */
79e68feb
RS
3601 if (byte_buffer_in_use)
3602 {
3603 ASM_OUTPUT_BYTE (asm_out_file, byte);
3604 total_bytes++;
3605 byte_buffer_in_use = 0;
3606 }
3607
3608 /* Advance to offset of this element.
3609 Note no alignment needed in an array, since that is guaranteed
3610 if each element has the proper size. */
3181cbfd 3611 if ((field != 0 || index != 0) && bitpos != total_bytes)
79e68feb 3612 {
ca695ac9
JB
3613 if (!output_bytecode)
3614 assemble_zeros (bitpos - total_bytes);
3615 else
3616 bc_emit_const_skip (bitpos - total_bytes);
79e68feb
RS
3617 total_bytes = bitpos;
3618 }
3619
3620 /* Determine size this element should occupy. */
3621 if (field)
3622 {
3623 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3624 abort ();
3625 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3626 {
3627 /* This avoids overflow trouble. */
3628 tree size_tree = size_binop (CEIL_DIV_EXPR,
3629 DECL_SIZE (field),
3630 size_int (BITS_PER_UNIT));
3631 fieldsize = TREE_INT_CST_LOW (size_tree);
3632 }
3633 else
3634 {
3635 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3636 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3637 }
3638 }
3639 else
3640 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3641
3642 /* Output the element's initial value. */
3643 if (val == 0)
3644 assemble_zeros (fieldsize);
3645 else
3646 output_constant (val, fieldsize);
3647
3648 /* Count its size. */
3649 total_bytes += fieldsize;
3650 }
3651 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3652 error ("invalid initial value for member `%s'",
3653 IDENTIFIER_POINTER (DECL_NAME (field)));
3654 else
3655 {
3656 /* Element that is a bit-field. */
3657
3658 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3659 int end_offset
3660 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3661
3662 if (val == 0)
3663 val = integer_zero_node;
3664
3665 /* If this field does not start in this (or, next) byte,
3666 skip some bytes. */
3667 if (next_offset / BITS_PER_UNIT != total_bytes)
3668 {
3669 /* Output remnant of any bit field in previous bytes. */
3670 if (byte_buffer_in_use)
3671 {
3672 ASM_OUTPUT_BYTE (asm_out_file, byte);
3673 total_bytes++;
3674 byte_buffer_in_use = 0;
3675 }
3676
3677 /* If still not at proper byte, advance to there. */
3678 if (next_offset / BITS_PER_UNIT != total_bytes)
3679 {
3680 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3681 total_bytes = next_offset / BITS_PER_UNIT;
3682 }
3683 }
3684
3685 if (! byte_buffer_in_use)
3686 byte = 0;
3687
3688 /* We must split the element into pieces that fall within
3689 separate bytes, and combine each byte with previous or
3690 following bit-fields. */
3691
b4ac57ab 3692 /* next_offset is the offset n fbits from the beginning of
79e68feb
RS
3693 the structure to the next bit of this element to be processed.
3694 end_offset is the offset of the first bit past the end of
3695 this element. */
3696 while (next_offset < end_offset)
3697 {
3698 int this_time;
3699 int shift, value;
3700 int next_byte = next_offset / BITS_PER_UNIT;
3701 int next_bit = next_offset % BITS_PER_UNIT;
3702
3703 /* Advance from byte to byte
3704 within this element when necessary. */
3705 while (next_byte != total_bytes)
3706 {
3707 ASM_OUTPUT_BYTE (asm_out_file, byte);
3708 total_bytes++;
3709 byte = 0;
3710 }
3711
3712 /* Number of bits we can process at once
3713 (all part of the same byte). */
3714 this_time = MIN (end_offset - next_offset,
3715 BITS_PER_UNIT - next_bit);
3716#if BYTES_BIG_ENDIAN
3717 /* On big-endian machine, take the most significant bits
3718 first (of the bits that are significant)
3719 and put them into bytes from the most significant end. */
3720 shift = end_offset - next_offset - this_time;
3721 /* Don't try to take a bunch of bits that cross
3722 the word boundary in the INTEGER_CST. */
37366632
RK
3723 if (shift < HOST_BITS_PER_WIDE_INT
3724 && shift + this_time > HOST_BITS_PER_WIDE_INT)
79e68feb 3725 {
37366632
RK
3726 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3727 shift = HOST_BITS_PER_WIDE_INT;
79e68feb
RS
3728 }
3729
3730 /* Now get the bits from the appropriate constant word. */
37366632 3731 if (shift < HOST_BITS_PER_WIDE_INT)
79e68feb
RS
3732 {
3733 value = TREE_INT_CST_LOW (val);
3734 }
37366632 3735 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
79e68feb
RS
3736 {
3737 value = TREE_INT_CST_HIGH (val);
37366632 3738 shift -= HOST_BITS_PER_WIDE_INT;
79e68feb
RS
3739 }
3740 else
3741 abort ();
37366632
RK
3742 byte |= (((value >> shift)
3743 & (((HOST_WIDE_INT) 1 << this_time) - 1))
79e68feb
RS
3744 << (BITS_PER_UNIT - this_time - next_bit));
3745#else
3746 /* On little-endian machines,
3747 take first the least significant bits of the value
3748 and pack them starting at the least significant
3749 bits of the bytes. */
3750 shift = (next_offset
3751 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3752 /* Don't try to take a bunch of bits that cross
3753 the word boundary in the INTEGER_CST. */
37366632
RK
3754 if (shift < HOST_BITS_PER_WIDE_INT
3755 && shift + this_time > HOST_BITS_PER_WIDE_INT)
79e68feb 3756 {
37366632
RK
3757 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3758 shift = HOST_BITS_PER_WIDE_INT;
79e68feb
RS
3759 }
3760
3761 /* Now get the bits from the appropriate constant word. */
3762 if (shift < HOST_BITS_PER_INT)
3763 value = TREE_INT_CST_LOW (val);
37366632 3764 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
79e68feb
RS
3765 {
3766 value = TREE_INT_CST_HIGH (val);
37366632 3767 shift -= HOST_BITS_PER_WIDE_INT;
79e68feb
RS
3768 }
3769 else
3770 abort ();
37366632
RK
3771 byte |= ((value >> shift)
3772 & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
79e68feb
RS
3773#endif
3774 next_offset += this_time;
3775 byte_buffer_in_use = 1;
3776 }
3777 }
3778 }
3779 if (byte_buffer_in_use)
3780 {
3781 ASM_OUTPUT_BYTE (asm_out_file, byte);
3782 total_bytes++;
3783 }
3784 if (total_bytes < size)
3785 assemble_zeros (size - total_bytes);
3786}
ca695ac9
JB
3787
3788
c02bd5d9
JB
3789#ifdef HANDLE_SYSV_PRAGMA
3790
879a4a9a
JW
3791/* Support #pragma weak by default if WEAK_ASM_OP and ASM_OUTPUT_DEF
3792 are defined. */
3793#if defined (WEAK_ASM_OP) && defined (ASM_OUTPUT_DEF)
da9f42b1 3794
b7560989
RS
3795/* See c-pragma.c for an identical definition. */
3796enum pragma_state
3797{
3798 ps_start,
3799 ps_done,
3800 ps_bad,
3801 ps_weak,
3802 ps_name,
3803 ps_equals,
3804 ps_value,
3805 ps_pack,
3806 ps_left,
3807 ps_align,
3808 ps_right
3809};
3810
ca695ac9
JB
3811/* Output asm to handle ``#pragma weak'' */
3812void
3813handle_pragma_weak (what, asm_out_file, name, value)
3814 enum pragma_state what;
3815 FILE *asm_out_file;
3816 char *name, *value;
3817{
3818 if (what == ps_name || what == ps_value)
3819 {
3820 fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
3821
3822 if (output_bytecode)
3823 BC_OUTPUT_LABELREF (asm_out_file, name);
3824 else
3825 ASM_OUTPUT_LABELREF (asm_out_file, name);
3826
3827 fputc ('\n', asm_out_file);
3828 if (what == ps_value)
879a4a9a 3829 ASM_OUTPUT_DEF (asm_out_file, name, value);
ca695ac9
JB
3830 }
3831 else if (! (what == ps_done || what == ps_start))
3832 warning ("malformed `#pragma weak'");
3833}
c02bd5d9 3834
da9f42b1
RS
3835#endif /* HANDLE_PRAGMA_WEAK or (WEAK_ASM_OP and SET_ASM_OP) */
3836
879a4a9a 3837#endif /* WEAK_ASM_OP && ASM_OUTPUT_DEF */
This page took 0.659175 seconds and 5 git commands to generate.