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