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