]> gcc.gnu.org Git - gcc.git/blame - gcc/varasm.c
(STARTFILE_SPEC): -static is added to ld if
[gcc.git] / gcc / varasm.c
CommitLineData
79e68feb
RS
1/* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 1988, 1989, 1992 Free Software Foundation, Inc.
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
21/* This file handles generation of all the assembler code
22 *except* the instructions of a function.
23 This includes declarations of variables and their initial values.
24
25 We also output the assembler code for constants stored in memory
26 and are responsible for combining constants with the same value. */
27
28#include <stdio.h>
29#include <setjmp.h>
30/* #include <stab.h> */
31#include "config.h"
32#include "rtl.h"
33#include "tree.h"
34#include "flags.h"
57632c51 35#include "function.h"
79e68feb
RS
36#include "expr.h"
37#include "hard-reg-set.h"
38#include "regs.h"
9a631e8e 39#include "defaults.h"
24b09b50 40#include "real.h"
79e68feb
RS
41
42#include "obstack.h"
43
b4ac57ab 44#ifdef XCOFF_DEBUGGING_INFO
f246a305 45#include "xcoffout.h"
b4ac57ab
RS
46#endif
47
79e68feb
RS
48#ifndef ASM_STABS_OP
49#define ASM_STABS_OP ".stabs"
50#endif
51
561e6650
RS
52/* This macro gets just the user-specified name
53 out of the string in a SYMBOL_REF. On most machines,
54 we discard the * if any and that's all. */
55#ifndef STRIP_NAME_ENCODING
56#define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
57 (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
58#endif
59
79e68feb
RS
60/* File in which assembler code is being written. */
61
62extern FILE *asm_out_file;
63
64/* The (assembler) name of the first globally-visible object output. */
65char *first_global_object_name;
66
67extern struct obstack *current_obstack;
68extern struct obstack *saveable_obstack;
69extern struct obstack permanent_obstack;
70#define obstack_chunk_alloc xmalloc
79e68feb
RS
71
72/* Number for making the label on the next
73 constant that is stored in memory. */
74
75int const_labelno;
76
77/* Number for making the label on the next
78 static variable internal to a function. */
79
80int var_labelno;
81
82/* Nonzero if at least one function definition has been seen. */
83static int function_defined;
84
85extern FILE *asm_out_file;
86
87static char *compare_constant_1 ();
88static void record_constant_1 ();
89void output_constant_pool ();
90void assemble_name ();
91int output_addressed_constants ();
92void output_constant ();
93void output_constructor ();
11435a40
TW
94void text_section ();
95void readonly_data_section ();
f246a305 96void data_section ();
79e68feb
RS
97\f
98#ifdef EXTRA_SECTIONS
99static enum in_section {no_section, in_text, in_data, EXTRA_SECTIONS} in_section
100 = no_section;
101#else
102static enum in_section {no_section, in_text, in_data} in_section
103 = no_section;
104#endif
105
106/* Define functions like text_section for any extra sections. */
107#ifdef EXTRA_SECTION_FUNCTIONS
108EXTRA_SECTION_FUNCTIONS
109#endif
110
111/* Tell assembler to switch to text section. */
112
113void
114text_section ()
115{
116 if (in_section != in_text)
117 {
118 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
119 in_section = in_text;
120 }
121}
122
79e68feb
RS
123/* Tell assembler to switch to data section. */
124
125void
126data_section ()
127{
128 if (in_section != in_data)
129 {
130 if (flag_shared_data)
131 {
132#ifdef SHARED_SECTION_ASM_OP
133 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
134#else
135 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
136#endif
137 }
138 else
139 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
140
141 in_section = in_data;
142 }
143}
144
7c6d68c8
RS
145/* Tell assembler to switch to read-only data section. This is normally
146 the text section. */
147
148void
149readonly_data_section ()
150{
151#ifdef READONLY_DATA_SECTION
152 READONLY_DATA_SECTION (); /* Note this can call data_section. */
153#else
154 text_section ();
155#endif
156}
157
79e68feb
RS
158/* Determine if we're in the text section. */
159
160int
161in_text_section ()
162{
163 return in_section == in_text;
164}
165\f
166/* Create the rtl to represent a function, for a function definition.
167 DECL is a FUNCTION_DECL node which describes which function.
168 The rtl is stored into DECL. */
169
170void
171make_function_rtl (decl)
172 tree decl;
173{
174 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
175
176 /* Rename a nested function to avoid conflicts. */
177 if (decl_function_context (decl) != 0
178 && DECL_INITIAL (decl) != 0
179 && DECL_RTL (decl) == 0)
180 {
181 char *label;
182
183 name = IDENTIFIER_POINTER (DECL_NAME (decl));
184 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
185 name = obstack_copy0 (saveable_obstack, label, strlen (label));
186 var_labelno++;
187 }
188
189 if (DECL_RTL (decl) == 0)
190 {
191 DECL_RTL (decl)
192 = gen_rtx (MEM, DECL_MODE (decl),
193 gen_rtx (SYMBOL_REF, Pmode, name));
194
195 /* Optionally set flags or add text to the name to record information
196 such as that it is a function name. If the name is changed, the macro
197 ASM_OUTPUT_LABELREF will have to know how to strip this information.
198 And if it finds a * at the beginning after doing so, it must handle
199 that too. */
200#ifdef ENCODE_SECTION_INFO
201 ENCODE_SECTION_INFO (decl);
202#endif
203 }
204
205 /* Record at least one function has been defined. */
206 function_defined = 1;
207}
208
b4ac57ab
RS
209/* Given NAME, a putative register name, discard any customary prefixes. */
210
211static char *
212strip_reg_name (name)
213 char *name;
214{
215#ifdef REGISTER_PREFIX
216 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
217 name += strlen (REGISTER_PREFIX);
218#endif
219 if (name[0] == '%' || name[0] == '#')
220 name++;
221 return name;
222}
dcfedcd0 223\f
79e68feb
RS
224/* Decode an `asm' spec for a declaration as a register name.
225 Return the register number, or -1 if nothing specified,
c09e6498
RS
226 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
227 or -3 if ASMSPEC is `cc' and is not recognized,
228 or -4 if ASMSPEC is `memory' and is not recognized.
dcfedcd0
RK
229 Accept an exact spelling or a decimal number.
230 Prefixes such as % are optional. */
79e68feb
RS
231
232int
233decode_reg_name (asmspec)
234 char *asmspec;
235{
236 if (asmspec != 0)
237 {
238 int i;
239
b4ac57ab
RS
240 /* Get rid of confusing prefixes. */
241 asmspec = strip_reg_name (asmspec);
242
fff9e713
MT
243 /* Allow a decimal number as a "register name". */
244 for (i = strlen (asmspec) - 1; i >= 0; i--)
245 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
246 break;
247 if (asmspec[0] != 0 && i < 0)
248 {
249 i = atoi (asmspec);
250 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
251 return i;
252 else
253 return -2;
254 }
255
79e68feb 256 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
b4ac57ab
RS
257 if (reg_names[i][0]
258 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
79e68feb
RS
259 return i;
260
79e68feb
RS
261#ifdef ADDITIONAL_REGISTER_NAMES
262 {
263 static struct { char *name; int number; } table[]
264 = ADDITIONAL_REGISTER_NAMES;
265
266 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
267 if (! strcmp (asmspec, table[i].name))
268 return table[i].number;
79e68feb
RS
269 }
270#endif /* ADDITIONAL_REGISTER_NAMES */
271
c09e6498
RS
272 if (!strcmp (asmspec, "memory"))
273 return -4;
274
dcfedcd0
RK
275 if (!strcmp (asmspec, "cc"))
276 return -3;
277
79e68feb
RS
278 return -2;
279 }
280
281 return -1;
282}
283\f
284/* Create the DECL_RTL for a declaration for a static or external variable
285 or static or external function.
286 ASMSPEC, if not 0, is the string which the user specified
287 as the assembler symbol name.
288 TOP_LEVEL is nonzero if this is a file-scope variable.
289
290 This is never called for PARM_DECL nodes. */
291
292void
293make_decl_rtl (decl, asmspec, top_level)
294 tree decl;
295 char *asmspec;
296 int top_level;
297{
298 register char *name;
299 int reg_number = decode_reg_name (asmspec);
300
301 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
302 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
303
304 if (reg_number == -2)
305 {
306 /* ASMSPEC is given, and not the name of a register. */
307 name = (char *) obstack_alloc (saveable_obstack,
308 strlen (asmspec) + 2);
309 name[0] = '*';
310 strcpy (&name[1], asmspec);
311 }
312
313 /* For a duplicate declaration, we can be called twice on the
314 same DECL node. Don't alter the RTL already made
315 unless the old mode is wrong (which can happen when
316 the previous rtl was made when the type was incomplete). */
317 if (DECL_RTL (decl) == 0
318 || GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
319 {
320 DECL_RTL (decl) = 0;
321
322 /* First detect errors in declaring global registers. */
44fe2e80 323 if (DECL_REGISTER (decl) && reg_number == -1)
79e68feb
RS
324 error_with_decl (decl,
325 "register name not specified for `%s'");
44fe2e80 326 else if (DECL_REGISTER (decl) && reg_number < 0)
79e68feb
RS
327 error_with_decl (decl,
328 "invalid register name for `%s'");
44fe2e80 329 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
79e68feb
RS
330 error_with_decl (decl,
331 "register name given for non-register variable `%s'");
44fe2e80 332 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
79e68feb 333 error ("function declared `register'");
44fe2e80 334 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
79e68feb
RS
335 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
336 /* Now handle properly declared static register variables. */
44fe2e80 337 else if (DECL_REGISTER (decl))
79e68feb
RS
338 {
339 int nregs;
340#if 0 /* yylex should print the warning for this */
341 if (pedantic)
342 pedwarn ("ANSI C forbids global register variables");
343#endif
344 if (DECL_INITIAL (decl) != 0 && top_level)
345 {
346 DECL_INITIAL (decl) = 0;
347 error ("global register variable has initial value");
348 }
349 if (fixed_regs[reg_number] == 0
350 && function_defined && top_level)
351 error ("global register variable follows a function definition");
352 if (TREE_THIS_VOLATILE (decl))
353 warning ("volatile register variables don't work as you might wish");
354 DECL_RTL (decl) = gen_rtx (REG, DECL_MODE (decl), reg_number);
355 REG_USERVAR_P (DECL_RTL (decl)) = 1;
356
357 if (top_level)
358 {
359 /* Make this register fixed, so not usable for anything else. */
360 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
361 while (nregs > 0)
362 global_regs[reg_number + --nregs] = 1;
363 init_reg_sets_1 ();
364 }
365 }
366
367 /* Now handle ordinary static variables and functions (in memory).
368 Also handle vars declared register invalidly. */
369 if (DECL_RTL (decl) == 0)
370 {
371 /* Can't use just the variable's own name for a variable
372 whose scope is less than the whole file.
373 Concatenate a distinguishing number. */
44fe2e80 374 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
79e68feb
RS
375 {
376 char *label;
377
378 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
379 name = obstack_copy0 (saveable_obstack, label, strlen (label));
380 var_labelno++;
381 }
382
383 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
384 gen_rtx (SYMBOL_REF, Pmode, name));
385 if (TREE_THIS_VOLATILE (decl))
386 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
387 if (TREE_READONLY (decl))
388 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
389 MEM_IN_STRUCT_P (DECL_RTL (decl))
390 = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
391 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
392 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
393
394 /* Optionally set flags or add text to the name to record information
395 such as that it is a function name.
396 If the name is changed, the macro ASM_OUTPUT_LABELREF
397 will have to know how to strip this information.
398 And if it finds a * at the beginning after doing so,
399 it must handle that too. */
400#ifdef ENCODE_SECTION_INFO
401 ENCODE_SECTION_INFO (decl);
402#endif
403 }
404 }
405}
4724d87a
RS
406
407/* Make the rtl for variable VAR be volatile.
408 Use this only for static variables. */
409
410make_var_volatile (var)
411 tree var;
412{
413 if (GET_CODE (DECL_RTL (var)) != MEM)
414 abort ();
415
416 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
417}
79e68feb
RS
418\f
419/* Output a string of literal assembler code
420 for an `asm' keyword used between functions. */
421
422void
423assemble_asm (string)
424 tree string;
425{
426 app_enable ();
427
428 if (TREE_CODE (string) == ADDR_EXPR)
429 string = TREE_OPERAND (string, 0);
430
431 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
432}
433
9bb2e4fe
RS
434#if 0 /* This should no longer be needed, because
435 flag_gnu_linker should be 0 on these systems,
436 which should prevent any output
437 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
79e68feb
RS
438#if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
439#ifndef ASM_OUTPUT_CONSTRUCTOR
440#define ASM_OUTPUT_CONSTRUCTOR(file, name)
441#endif
442#ifndef ASM_OUTPUT_DESTRUCTOR
443#define ASM_OUTPUT_DESTRUCTOR(file, name)
444#endif
445#endif
9bb2e4fe 446#endif /* 0 */
79e68feb
RS
447
448/* Record an element in the table of global destructors.
449 How this is done depends on what sort of assembler and linker
450 are in use.
451
452 NAME should be the name of a global function to be called
453 at exit time. This name is output using assemble_name. */
454
455void
456assemble_destructor (name)
457 char *name;
458{
459#ifdef ASM_OUTPUT_DESTRUCTOR
460 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
461#else
462 if (flag_gnu_linker)
463 {
464 /* Now tell GNU LD that this is part of the static destructor set. */
465 /* This code works for any machine provided you use GNU as/ld. */
466 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
467 assemble_name (asm_out_file, name);
468 fputc ('\n', asm_out_file);
469 }
470#endif
471}
472
473/* Likewise for global constructors. */
474
475void
476assemble_constructor (name)
477 char *name;
478{
479#ifdef ASM_OUTPUT_CONSTRUCTOR
480 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
481#else
482 if (flag_gnu_linker)
483 {
484 /* Now tell GNU LD that this is part of the static constructor set. */
485 /* This code works for any machine provided you use GNU as/ld. */
486 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
487 assemble_name (asm_out_file, name);
488 fputc ('\n', asm_out_file);
489 }
490#endif
491}
492
493/* Likewise for entries we want to record for garbage collection.
494 Garbage collection is still under development. */
495
496void
497assemble_gc_entry (name)
498 char *name;
499{
500#ifdef ASM_OUTPUT_GC_ENTRY
501 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
502#else
503 if (flag_gnu_linker)
504 {
505 /* Now tell GNU LD that this is part of the static constructor set. */
506 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
507 assemble_name (asm_out_file, name);
508 fputc ('\n', asm_out_file);
509 }
510#endif
511}
512\f
513/* Output assembler code for the constant pool of a function and associated
514 with defining the name of the function. DECL describes the function.
515 NAME is the function's name. For the constant pool, we use the current
516 constant pool data. */
517
518void
519assemble_start_function (decl, fnname)
520 tree decl;
521 char *fnname;
522{
523 int align;
524
525 /* The following code does not need preprocessing in the assembler. */
526
527 app_disable ();
528
529 output_constant_pool (fnname, decl);
530
531 text_section ();
532
533
534 /* Tell assembler to move to target machine's alignment for functions. */
535 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
536 if (align > 0)
537 ASM_OUTPUT_ALIGN (asm_out_file, align);
538
539#ifdef ASM_OUTPUT_FUNCTION_PREFIX
540 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
541#endif
542
543#ifdef SDB_DEBUGGING_INFO
544 /* Output SDB definition of the function. */
545 if (write_symbols == SDB_DEBUG)
546 sdbout_mark_begin_function ();
547#endif
548
549#ifdef DBX_DEBUGGING_INFO
e5c90c23 550 /* Output DBX definition of the function. */
79e68feb 551 if (write_symbols == DBX_DEBUG)
e5c90c23 552 dbxout_begin_function (decl);
79e68feb
RS
553#endif
554
555 /* Make function name accessible from other files, if appropriate. */
556
557 if (TREE_PUBLIC (decl))
558 {
559 if (!first_global_object_name)
561e6650 560 STRIP_NAME_ENCODING (first_global_object_name, fnname);
79e68feb
RS
561 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
562 }
563
564 /* Do any machine/system dependent processing of the function name */
565#ifdef ASM_DECLARE_FUNCTION_NAME
566 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
567#else
568 /* Standard thing is just output label for the function. */
569 ASM_OUTPUT_LABEL (asm_out_file, fnname);
570#endif /* ASM_DECLARE_FUNCTION_NAME */
571}
572
573/* Output assembler code associated with defining the size of the
574 function. DECL describes the function. NAME is the function's name. */
575
576void
577assemble_end_function (decl, fnname)
578 tree decl;
579 char *fnname;
580{
581#ifdef ASM_DECLARE_FUNCTION_SIZE
582 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
583#endif
584}
585\f
586/* Assemble code to leave SIZE bytes of zeros. */
587
588void
589assemble_zeros (size)
590 int size;
591{
592#ifdef ASM_NO_SKIP_IN_TEXT
593 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
594 so we must output 0s explicitly in the text section. */
595 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
596 {
597 int i;
598
599 for (i = 0; i < size - 20; i += 20)
600 {
601#ifdef ASM_BYTE_OP
602 fprintf (asm_out_file,
603 "%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);
604#else
605 fprintf (asm_out_file,
606 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
607#endif
608 }
609 if (i < size)
610 {
611#ifdef ASM_BYTE_OP
612 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
613#else
614 fprintf (asm_out_file, "\tbyte 0");
615#endif
616 i++;
617 for (; i < size; i++)
618 fprintf (asm_out_file, ",0");
619 fprintf (asm_out_file, "\n");
620 }
621 }
622 else
623#endif
624 ASM_OUTPUT_SKIP (asm_out_file, size);
625}
626
627/* Assemble a string constant with the specified C string as contents. */
628
629void
630assemble_string (p, size)
631 unsigned char *p;
632 int size;
633{
634 register int i;
635 int pos = 0;
636 int maximum = 2000;
637
638 /* If the string is very long, split it up. */
639
640 while (pos < size)
641 {
642 int thissize = size - pos;
643 if (thissize > maximum)
644 thissize = maximum;
645
79e68feb 646 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
79e68feb
RS
647
648 pos += thissize;
649 p += thissize;
650 }
651}
652\f
653/* Assemble everything that is needed for a variable or function declaration.
654 Not used for automatic variables, and not used for function definitions.
655 Should not be called for variables of incomplete structure type.
656
657 TOP_LEVEL is nonzero if this variable has file scope.
658 AT_END is nonzero if this is the special handling, at end of compilation,
659 to define things that have had only tentative definitions. */
660
661void
662assemble_variable (decl, top_level, at_end)
663 tree decl;
664 int top_level;
665 int at_end;
666{
667 register char *name;
668 int align;
669 tree size_tree;
670 int reloc = 0;
671
672 if (GET_CODE (DECL_RTL (decl)) == REG)
673 {
674 /* Do output symbol info for global register variables, but do nothing
675 else for them. */
676
677 if (TREE_ASM_WRITTEN (decl))
678 return;
679 TREE_ASM_WRITTEN (decl) = 1;
680
b4ac57ab 681#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
79e68feb 682 /* File-scope global variables are output here. */
b4ac57ab
RS
683 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
684 && top_level)
79e68feb
RS
685 dbxout_symbol (decl, 0);
686#endif
687#ifdef SDB_DEBUGGING_INFO
688 if (write_symbols == SDB_DEBUG && top_level
689 /* Leave initialized global vars for end of compilation;
690 see comment in compile_file. */
691 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
692 sdbout_symbol (decl, 0);
693#endif
694
695 /* Don't output any DWARF debugging information for variables here.
696 In the case of local variables, the information for them is output
697 when we do our recursive traversal of the tree representation for
698 the entire containing function. In the case of file-scope variables,
699 we output information for all of them at the very end of compilation
700 while we are doing our final traversal of the chain of file-scope
701 declarations. */
702
703 return;
704 }
705
706 /* Normally no need to say anything for external references,
707 since assembler considers all undefined symbols external. */
708
44fe2e80 709 if (DECL_EXTERNAL (decl))
79e68feb
RS
710 return;
711
712 /* Output no assembler code for a function declaration.
713 Only definitions of functions output anything. */
714
715 if (TREE_CODE (decl) == FUNCTION_DECL)
716 return;
717
718 /* If type was incomplete when the variable was declared,
719 see if it is complete now. */
720
721 if (DECL_SIZE (decl) == 0)
722 layout_decl (decl, 0);
723
724 /* Still incomplete => don't allocate it; treat the tentative defn
725 (which is what it must have been) as an `extern' reference. */
726
727 if (DECL_SIZE (decl) == 0)
728 {
729 error_with_file_and_line (DECL_SOURCE_FILE (decl),
730 DECL_SOURCE_LINE (decl),
ea80ee44 731 "storage size of `%s' isn't known",
79e68feb
RS
732 IDENTIFIER_POINTER (DECL_NAME (decl)));
733 return;
734 }
735
736 /* The first declaration of a variable that comes through this function
737 decides whether it is global (in C, has external linkage)
738 or local (in C, has internal linkage). So do nothing more
739 if this function has already run. */
740
741 if (TREE_ASM_WRITTEN (decl))
742 return;
743
744 TREE_ASM_WRITTEN (decl) = 1;
745
746#ifdef DBX_DEBUGGING_INFO
747 /* File-scope global variables are output here. */
748 if (write_symbols == DBX_DEBUG && top_level)
749 dbxout_symbol (decl, 0);
750#endif
751#ifdef SDB_DEBUGGING_INFO
752 if (write_symbols == SDB_DEBUG && top_level
753 /* Leave initialized global vars for end of compilation;
754 see comment in compile_file. */
755 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
756 sdbout_symbol (decl, 0);
757#endif
758
759 /* Don't output any DWARF debugging information for variables here.
760 In the case of local variables, the information for them is output
761 when we do our recursive traversal of the tree representation for
762 the entire containing function. In the case of file-scope variables,
763 we output information for all of them at the very end of compilation
764 while we are doing our final traversal of the chain of file-scope
765 declarations. */
766
767 /* If storage size is erroneously variable, just continue.
768 Error message was already made. */
769
770 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
b4ac57ab 771 goto finish;
79e68feb
RS
772
773 app_disable ();
774
775 /* This is better than explicit arithmetic, since it avoids overflow. */
776 size_tree = size_binop (CEIL_DIV_EXPR,
777 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
778
779 if (TREE_INT_CST_HIGH (size_tree) != 0)
780 {
781 error_with_decl (decl, "size of variable `%s' is too large");
b4ac57ab 782 goto finish;
79e68feb
RS
783 }
784
785 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
786
787 /* Handle uninitialized definitions. */
788
789 /* ANSI specifies that a tentative definition which is not merged with
790 a non-tentative definition behaves exactly like a definition with an
791 initializer equal to zero. (Section 3.7.2)
792 -fno-common gives strict ANSI behavior. Usually you don't want it. */
793 if (! flag_no_common
794 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
795 {
796 int size = TREE_INT_CST_LOW (size_tree);
797 int rounded = size;
798
799 if (TREE_INT_CST_HIGH (size_tree) != 0)
800 error_with_decl (decl, "size of variable `%s' is too large");
801 /* Don't allocate zero bytes of common,
802 since that means "undefined external" in the linker. */
803 if (size == 0) rounded = 1;
804 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
805 so that each uninitialized object starts on such a boundary. */
806 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
807 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
808 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
809#if 0
810 if (flag_shared_data)
811 data_section ();
812#endif
813 if (TREE_PUBLIC (decl))
814 {
815#ifdef ASM_OUTPUT_SHARED_COMMON
816 if (flag_shared_data)
817 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
818 else
819#endif
820#ifdef ASM_OUTPUT_ALIGNED_COMMON
821 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
822 DECL_ALIGN (decl));
823#else
824 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
825#endif
826 }
827 else
828 {
829#ifdef ASM_OUTPUT_SHARED_LOCAL
830 if (flag_shared_data)
831 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
832 else
833#endif
834#ifdef ASM_OUTPUT_ALIGNED_LOCAL
835 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
836 DECL_ALIGN (decl));
837#else
838 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
839#endif
840 }
b4ac57ab 841 goto finish;
79e68feb
RS
842 }
843
844 /* Handle initialized definitions. */
845
846 /* First make the assembler name(s) global if appropriate. */
847 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
848 {
849 if (!first_global_object_name)
561e6650 850 STRIP_NAME_ENCODING(first_global_object_name, name);
79e68feb
RS
851 ASM_GLOBALIZE_LABEL (asm_out_file, name);
852 }
853#if 0
854 for (d = equivalents; d; d = TREE_CHAIN (d))
855 {
856 tree e = TREE_VALUE (d);
857 if (TREE_PUBLIC (e) && DECL_NAME (e))
858 ASM_GLOBALIZE_LABEL (asm_out_file,
859 XSTR (XEXP (DECL_RTL (e), 0), 0));
860 }
861#endif
862
863 /* Output any data that we will need to use the address of. */
864 if (DECL_INITIAL (decl))
865 reloc = output_addressed_constants (DECL_INITIAL (decl));
866
867 /* Switch to the proper section for this data. */
868#ifdef SELECT_SECTION
869 SELECT_SECTION (decl, reloc);
870#else
871 if (TREE_READONLY (decl)
872 && ! TREE_THIS_VOLATILE (decl)
873 && ! (flag_pic && reloc))
874 readonly_data_section ();
875 else
876 data_section ();
877#endif
878
879 /* Compute and output the alignment of this data. */
880
881 align = DECL_ALIGN (decl);
882 /* Some object file formats have a maximum alignment which they support.
883 In particular, a.out format supports a maximum alignment of 4. */
884#ifndef MAX_OFILE_ALIGNMENT
885#define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
886#endif
887 if (align > MAX_OFILE_ALIGNMENT)
888 {
889 warning_with_decl (decl,
890 "alignment of `%s' is greater than maximum object file alignment");
891 align = MAX_OFILE_ALIGNMENT;
892 }
893#ifdef DATA_ALIGNMENT
894 /* On some machines, it is good to increase alignment sometimes. */
895 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
896#endif
897#ifdef CONSTANT_ALIGNMENT
898 if (DECL_INITIAL (decl))
899 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
900#endif
901
902 /* Reset the alignment in case we have made it tighter, so we can benefit
903 from it in get_pointer_alignment. */
904 DECL_ALIGN (decl) = align;
905
906 if (align > BITS_PER_UNIT)
907 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
908
909 /* Do any machine/system dependent processing of the object. */
910#ifdef ASM_DECLARE_OBJECT_NAME
911 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
912#else
913 /* Standard thing is just output label for the object. */
914 ASM_OUTPUT_LABEL (asm_out_file, name);
915#endif /* ASM_DECLARE_OBJECT_NAME */
916
917#if 0
918 for (d = equivalents; d; d = TREE_CHAIN (d))
919 {
920 tree e = TREE_VALUE (d);
921 ASM_OUTPUT_LABEL (asm_out_file, XSTR (XEXP (DECL_RTL (e), 0), 0));
922 }
923#endif
924
925 if (DECL_INITIAL (decl))
926 /* Output the actual data. */
927 output_constant (DECL_INITIAL (decl),
928 int_size_in_bytes (TREE_TYPE (decl)));
929 else
930 /* Leave space for it. */
931 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
b4ac57ab
RS
932
933 finish:
934#ifdef XCOFF_DEBUGGING_INFO
935 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
936 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
937 and `aa' hasn't been output yet, the assembler generates a stab entry with
938 a value of zero, in addition to creating an unnecessary external entry
6dc42e49 939 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
b4ac57ab
RS
940
941 /* File-scope global variables are output here. */
942 if (write_symbols == XCOFF_DEBUG && top_level)
943 dbxout_symbol (decl, 0);
944#else
945 /* There must be a statement after a label. */
946 ;
947#endif
79e68feb
RS
948}
949
950/* Output something to declare an external symbol to the assembler.
fff9e713
MT
951 (Most assemblers don't need this, so we normally output nothing.)
952 Do nothing if DECL is not external. */
79e68feb
RS
953
954void
955assemble_external (decl)
956 tree decl;
957{
79e68feb 958#ifdef ASM_OUTPUT_EXTERNAL
fff9e713 959 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
44fe2e80 960 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
79e68feb 961 {
fff9e713
MT
962 rtx rtl = DECL_RTL (decl);
963
964 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
965 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
966 {
967 /* Some systems do require some output. */
968 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
969 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
970 }
79e68feb
RS
971 }
972#endif
973}
974
975/* Similar, for calling a library function FUN. */
976
977void
978assemble_external_libcall (fun)
979 rtx fun;
980{
981#ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
982 /* Declare library function name external when first used, if nec. */
983 if (! SYMBOL_REF_USED (fun))
984 {
985 SYMBOL_REF_USED (fun) = 1;
986 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
987 }
988#endif
989}
990
991/* Declare the label NAME global. */
992
993void
994assemble_global (name)
995 char *name;
996{
997 ASM_GLOBALIZE_LABEL (asm_out_file, name);
998}
999
1000/* Assemble a label named NAME. */
1001
1002void
1003assemble_label (name)
1004 char *name;
1005{
1006 ASM_OUTPUT_LABEL (asm_out_file, name);
1007}
1008
1009/* Output to FILE a reference to the assembler name of a C-level name NAME.
1010 If NAME starts with a *, the rest of NAME is output verbatim.
1011 Otherwise NAME is transformed in an implementation-defined way
1012 (usually by the addition of an underscore).
1013 Many macros in the tm file are defined to call this function. */
1014
1015void
1016assemble_name (file, name)
1017 FILE *file;
1018 char *name;
1019{
1020 if (name[0] == '*')
1021 fputs (&name[1], file);
1022 else
1023 ASM_OUTPUT_LABELREF (file, name);
1024}
1025
1026/* Allocate SIZE bytes writable static space with a gensym name
1027 and return an RTX to refer to its address. */
1028
1029rtx
1030assemble_static_space (size)
1031 int size;
1032{
1033 char name[12];
1034 char *namestring;
1035 rtx x;
1036 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1037 so that each uninitialized object starts on such a boundary. */
1038 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1039 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1040 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1041
1042#if 0
1043 if (flag_shared_data)
1044 data_section ();
1045#endif
1046
1047 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1048 ++const_labelno;
1049
1050 namestring = (char *) obstack_alloc (saveable_obstack,
1051 strlen (name) + 2);
1052 strcpy (namestring, name);
1053
1054 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1055#ifdef ASM_OUTPUT_ALIGNED_LOCAL
1056 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1057#else
1058 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1059#endif
1060 return x;
1061}
1062
1063/* Assemble the static constant template for function entry trampolines.
1064 This is done at most once per compilation.
1065 Returns an RTX for the address of the template. */
1066
1067rtx
1068assemble_trampoline_template ()
1069{
1070 char label[256];
1071 char *name;
1072 int align;
1073
1074 /* Write the assembler code to define one. */
1075 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1076 if (align > 0)
1077 ASM_OUTPUT_ALIGN (asm_out_file, align);
1078
1079 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1080 TRAMPOLINE_TEMPLATE (asm_out_file);
1081
1082 /* Record the rtl to refer to it. */
1083 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1084 name
1085 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1086 return gen_rtx (SYMBOL_REF, Pmode, name);
1087}
1088\f
1089/* Assemble the integer constant X into an object of SIZE bytes.
1090 X must be either a CONST_INT or CONST_DOUBLE.
1091
1092 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1093 non-zero, abort if we can't output the constant. */
1094
1095int
1096assemble_integer (x, size, force)
1097 rtx x;
1098 int size;
1099 int force;
1100{
1101 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1102 ASM_OUTPUT... macros. */
1103
1104 switch (size)
1105 {
1106#ifdef ASM_OUTPUT_CHAR
1107 case 1:
1108 ASM_OUTPUT_CHAR (asm_out_file, x);
1109 return 1;
1110#endif
1111
1112#ifdef ASM_OUTPUT_SHORT
1113 case 2:
1114 ASM_OUTPUT_SHORT (asm_out_file, x);
1115 return 1;
1116#endif
1117
1118#ifdef ASM_OUTPUT_INT
1119 case 4:
1120 ASM_OUTPUT_INT (asm_out_file, x);
1121 return 1;
1122#endif
1123
1124#ifdef ASM_OUTPUT_DOUBLE_INT
1125 case 8:
1126 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1127 return 1;
1128#endif
1129
1130#ifdef ASM_OUTPUT_QUADRUPLE_INT
1131 case 16:
1132 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1133 return 1;
1134#endif
1135 }
1136
1137 /* If we couldn't do it that way, there are two other possibilities: First,
1138 if the machine can output an explicit byte and this is a 1 byte constant,
1139 we can use ASM_OUTPUT_BYTE. */
1140
1141#ifdef ASM_OUTPUT_BYTE
1142 if (size == 1 && GET_CODE (x) == CONST_INT)
1143 {
1144 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1145 return 1;
1146 }
1147#endif
1148
1149 /* Finally, if SIZE is larger than a single word, try to output the constant
1150 one word at a time. */
1151
1152 if (size > UNITS_PER_WORD)
1153 {
1154 int i;
1155 enum machine_mode mode
1156 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1157 rtx word;
1158
1159 for (i = 0; i < size / UNITS_PER_WORD; i++)
1160 {
1161 word = operand_subword (x, i, 0, mode);
1162
1163 if (word == 0)
1164 break;
1165
fff9e713
MT
1166 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1167 break;
79e68feb
RS
1168 }
1169
1170 if (i == size / UNITS_PER_WORD)
1171 return 1;
fff9e713
MT
1172 /* If we output at least one word and then could not finish,
1173 there is no valid way to continue. */
1174 if (i > 0)
1175 abort ();
79e68feb
RS
1176 }
1177
1178 if (force)
1179 abort ();
1180
1181 return 0;
1182}
1183\f
1184/* Assemble the floating-point constant D into an object of size MODE. */
1185
1186void
1187assemble_real (d, mode)
1188 REAL_VALUE_TYPE d;
1189 enum machine_mode mode;
1190{
1191 jmp_buf output_constant_handler;
1192
1193 if (setjmp (output_constant_handler))
1194 {
1195 error ("floating point trap outputting a constant");
1196#ifdef REAL_IS_NOT_DOUBLE
1197 bzero (&d, sizeof d);
1198 d = dconst0;
1199#else
1200 d = 0;
1201#endif
1202 }
1203
1204 set_float_handler (output_constant_handler);
1205
1206 switch (mode)
1207 {
1208#ifdef ASM_OUTPUT_FLOAT
1209 case SFmode:
1210 ASM_OUTPUT_FLOAT (asm_out_file, d);
1211 break;
1212#endif
1213
1214#ifdef ASM_OUTPUT_DOUBLE
1215 case DFmode:
1216 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1217 break;
1218#endif
1219
1220#ifdef ASM_OUTPUT_LONG_DOUBLE
1221 case TFmode:
1222 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1223 break;
1224#endif
1225
1226 default:
1227 abort ();
1228 }
1229
37366632 1230 set_float_handler (NULL_PTR);
79e68feb
RS
1231}
1232\f
1233/* Here we combine duplicate floating constants to make
1234 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1235
1236/* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1237 They are chained through the CONST_DOUBLE_CHAIN.
1238 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1239 In that case, CONST_DOUBLE_MEM is either a MEM,
57632c51
RS
1240 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1241
1242 (CONST_DOUBLE_MEM is used only for top-level functions.
1243 See force_const_mem for explanation.) */
79e68feb
RS
1244
1245static rtx const_double_chain;
1246
1247/* Return a CONST_DOUBLE for a value specified as a pair of ints.
1248 For an integer, I0 is the low-order word and I1 is the high-order word.
1249 For a real number, I0 is the word with the low address
1250 and I1 is the word with the high address. */
1251
1252rtx
1253immed_double_const (i0, i1, mode)
37366632 1254 HOST_WIDE_INT i0, i1;
79e68feb
RS
1255 enum machine_mode mode;
1256{
1257 register rtx r;
1258 int in_current_obstack;
1259
1260 if (GET_MODE_CLASS (mode) == MODE_INT)
1261 {
1262 /* We clear out all bits that don't belong in MODE, unless they and our
1263 sign bit are all one. So we get either a reasonable negative value
1264 or a reasonable unsigned value for this mode. */
1265 int width = GET_MODE_BITSIZE (mode);
37366632
RK
1266 if (width < HOST_BITS_PER_WIDE_INT
1267 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1268 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1269 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1270 else if (width == HOST_BITS_PER_WIDE_INT
79e68feb
RS
1271 && ! (i1 == ~0 && i0 < 0))
1272 i1 = 0;
37366632 1273 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
79e68feb
RS
1274 /* We cannot represent this value as a constant. */
1275 abort ();
1276
37366632 1277 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
79e68feb
RS
1278
1279 ??? Strictly speaking, this is wrong if we create a CONST_INT
1280 for a large unsigned constant with the size of MODE being
37366632
RK
1281 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1282 wider mode. In that case we will mis-interpret it as a negative
1283 number.
79e68feb
RS
1284
1285 Unfortunately, the only alternative is to make a CONST_DOUBLE
1286 for any constant in any mode if it is an unsigned constant larger
1287 than the maximum signed integer in an int on the host. However,
1288 doing this will break everyone that always expects to see a CONST_INT
1289 for SImode and smaller.
1290
1291 We have always been making CONST_INTs in this case, so nothing new
1292 is being broken. */
1293
37366632 1294 if (width <= HOST_BITS_PER_WIDE_INT)
79e68feb
RS
1295 i1 = (i0 < 0) ? ~0 : 0;
1296
1297 /* If this integer fits in one word, return a CONST_INT. */
1298 if ((i1 == 0 && i0 >= 0)
1299 || (i1 == ~0 && i0 < 0))
37366632 1300 return GEN_INT (i0);
79e68feb
RS
1301
1302 /* We use VOIDmode for integers. */
1303 mode = VOIDmode;
1304 }
1305
1306 /* Search the chain for an existing CONST_DOUBLE with the right value.
1307 If one is found, return it. */
1308
1309 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1310 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1311 && GET_MODE (r) == mode)
1312 return r;
1313
1314 /* No; make a new one and add it to the chain.
1315
1316 We may be called by an optimizer which may be discarding any memory
1317 allocated during its processing (such as combine and loop). However,
1318 we will be leaving this constant on the chain, so we cannot tolerate
1319 freed memory. So switch to saveable_obstack for this allocation
1320 and then switch back if we were in current_obstack. */
1321
1322 in_current_obstack = rtl_in_saveable_obstack ();
1323 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1324 if (in_current_obstack)
1325 rtl_in_current_obstack ();
1326
1327 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1328 const_double_chain = r;
1329
1330 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1331 Actual use of mem-slot is only through force_const_mem. */
1332
1333 CONST_DOUBLE_MEM (r) = const0_rtx;
1334
1335 return r;
1336}
1337
1338/* Return a CONST_DOUBLE for a specified `double' value
1339 and machine mode. */
1340
1341rtx
1342immed_real_const_1 (d, mode)
1343 REAL_VALUE_TYPE d;
1344 enum machine_mode mode;
1345{
1346 union real_extract u;
1347 register rtx r;
1348 int in_current_obstack;
1349
1350 /* Get the desired `double' value as a sequence of ints
1351 since that is how they are stored in a CONST_DOUBLE. */
1352
1353 u.d = d;
1354
1355 /* Detect special cases. */
1356
f246a305
RS
1357 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1358 if (!bcmp (&dconst0, &d, sizeof d))
79e68feb
RS
1359 return CONST0_RTX (mode);
1360 else if (REAL_VALUES_EQUAL (dconst1, d))
1361 return CONST1_RTX (mode);
1362
37366632 1363 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
79e68feb
RS
1364 return immed_double_const (u.i[0], u.i[1], mode);
1365
1366 /* The rest of this function handles the case where
1367 a float value requires more than 2 ints of space.
1368 It will be deleted as dead code on machines that don't need it. */
1369
1370 /* Search the chain for an existing CONST_DOUBLE with the right value.
1371 If one is found, return it. */
1372
1373 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1374 if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
1375 && GET_MODE (r) == mode)
1376 return r;
1377
1378 /* No; make a new one and add it to the chain.
1379
1380 We may be called by an optimizer which may be discarding any memory
1381 allocated during its processing (such as combine and loop). However,
1382 we will be leaving this constant on the chain, so we cannot tolerate
1383 freed memory. So switch to saveable_obstack for this allocation
1384 and then switch back if we were in current_obstack. */
1385
1386 in_current_obstack = rtl_in_saveable_obstack ();
1387 r = rtx_alloc (CONST_DOUBLE);
1388 PUT_MODE (r, mode);
1389 bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
1390 if (in_current_obstack)
1391 rtl_in_current_obstack ();
1392
1393 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1394 const_double_chain = r;
1395
1396 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1397 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1398 is only through force_const_mem. */
1399
1400 CONST_DOUBLE_MEM (r) = const0_rtx;
1401
1402 return r;
1403}
1404
1405/* Return a CONST_DOUBLE rtx for a value specified by EXP,
1406 which must be a REAL_CST tree node. */
1407
1408rtx
1409immed_real_const (exp)
1410 tree exp;
1411{
1412 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1413}
1414
1415/* At the end of a function, forget the memory-constants
1416 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1417 Also clear out real_constant_chain and clear out all the chain-pointers. */
1418
1419void
1420clear_const_double_mem ()
1421{
1422 register rtx r, next;
1423
57632c51
RS
1424 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1425 See force_const_mem for explanation. */
1426 if (outer_function_chain != 0)
1427 return;
1428
79e68feb
RS
1429 for (r = const_double_chain; r; r = next)
1430 {
1431 next = CONST_DOUBLE_CHAIN (r);
1432 CONST_DOUBLE_CHAIN (r) = 0;
1433 CONST_DOUBLE_MEM (r) = cc0_rtx;
1434 }
1435 const_double_chain = 0;
1436}
1437\f
1438/* Given an expression EXP with a constant value,
1439 reduce it to the sum of an assembler symbol and an integer.
1440 Store them both in the structure *VALUE.
1441 Abort if EXP does not reduce. */
1442
1443struct addr_const
1444{
1445 rtx base;
fb351073 1446 HOST_WIDE_INT offset;
79e68feb
RS
1447};
1448
1449static void
1450decode_addr_const (exp, value)
1451 tree exp;
1452 struct addr_const *value;
1453{
1454 register tree target = TREE_OPERAND (exp, 0);
1455 register int offset = 0;
1456 register rtx x;
1457
1458 while (1)
1459 {
1460 if (TREE_CODE (target) == COMPONENT_REF
1461 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
1462 == INTEGER_CST))
1463 {
1464 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
1465 target = TREE_OPERAND (target, 0);
1466 }
1467 else if (TREE_CODE (target) == ARRAY_REF)
1468 {
1469 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
1470 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
1471 abort ();
1472 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
1473 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
1474 / BITS_PER_UNIT);
1475 target = TREE_OPERAND (target, 0);
1476 }
1477 else
1478 break;
1479 }
1480
1481 switch (TREE_CODE (target))
1482 {
1483 case VAR_DECL:
1484 case FUNCTION_DECL:
1485 x = DECL_RTL (target);
1486 break;
1487
1488 case LABEL_DECL:
1489 x = gen_rtx (MEM, FUNCTION_MODE,
1490 gen_rtx (LABEL_REF, VOIDmode,
1491 label_rtx (TREE_OPERAND (exp, 0))));
1492 break;
1493
1494 case REAL_CST:
1495 case STRING_CST:
1496 case COMPLEX_CST:
1497 case CONSTRUCTOR:
1498 x = TREE_CST_RTL (target);
1499 break;
1500
1501 default:
1502 abort ();
1503 }
1504
1505 if (GET_CODE (x) != MEM)
1506 abort ();
1507 x = XEXP (x, 0);
1508
1509 value->base = x;
1510 value->offset = offset;
1511}
1512\f
1513/* Uniquize all constants that appear in memory.
1514 Each constant in memory thus far output is recorded
1515 in `const_hash_table' with a `struct constant_descriptor'
1516 that contains a polish representation of the value of
1517 the constant.
1518
1519 We cannot store the trees in the hash table
1520 because the trees may be temporary. */
1521
1522struct constant_descriptor
1523{
1524 struct constant_descriptor *next;
1525 char *label;
1526 char contents[1];
1527};
1528
1529#define HASHBITS 30
1530#define MAX_HASH_TABLE 1009
1531static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
1532
1533/* Compute a hash code for a constant expression. */
1534
1535int
1536const_hash (exp)
1537 tree exp;
1538{
1539 register char *p;
1540 register int len, hi, i;
1541 register enum tree_code code = TREE_CODE (exp);
1542
1543 if (code == INTEGER_CST)
1544 {
1545 p = (char *) &TREE_INT_CST_LOW (exp);
1546 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1547 }
1548 else if (code == REAL_CST)
1549 {
1550 p = (char *) &TREE_REAL_CST (exp);
1551 len = sizeof TREE_REAL_CST (exp);
1552 }
1553 else if (code == STRING_CST)
1554 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
1555 else if (code == COMPLEX_CST)
1556 return const_hash (TREE_REALPART (exp)) * 5
1557 + const_hash (TREE_IMAGPART (exp));
1558 else if (code == CONSTRUCTOR)
1559 {
1560 register tree link;
1561
1562 /* For record type, include the type in the hashing.
1563 We do not do so for array types
1564 because (1) the sizes of the elements are sufficient
eb528802
RS
1565 and (2) distinct array types can have the same constructor.
1566 Instead, we include the array size because the constructor could
1567 be shorter. */
79e68feb 1568 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
fb351073
RK
1569 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
1570 % MAX_HASH_TABLE;
79e68feb 1571 else
eb528802
RS
1572 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
1573 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
79e68feb
RS
1574
1575 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
77fa0940
RK
1576 if (TREE_VALUE (link))
1577 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
79e68feb
RS
1578
1579 return hi;
1580 }
1581 else if (code == ADDR_EXPR)
1582 {
1583 struct addr_const value;
1584 decode_addr_const (exp, &value);
1585 if (GET_CODE (value.base) == SYMBOL_REF)
1586 {
1587 /* Don't hash the address of the SYMBOL_REF;
1588 only use the offset and the symbol name. */
1589 hi = value.offset;
1590 p = XSTR (value.base, 0);
1591 for (i = 0; p[i] != 0; i++)
1592 hi = ((hi * 613) + (unsigned)(p[i]));
1593 }
1594 else if (GET_CODE (value.base) == LABEL_REF)
1595 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
1596
1597 hi &= (1 << HASHBITS) - 1;
1598 hi %= MAX_HASH_TABLE;
1599 return hi;
1600 }
1601 else if (code == PLUS_EXPR || code == MINUS_EXPR)
1602 return const_hash (TREE_OPERAND (exp, 0)) * 9
1603 + const_hash (TREE_OPERAND (exp, 1));
1604 else if (code == NOP_EXPR || code == CONVERT_EXPR)
1605 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
1606
1607 /* Compute hashing function */
1608 hi = len;
1609 for (i = 0; i < len; i++)
1610 hi = ((hi * 613) + (unsigned)(p[i]));
1611
1612 hi &= (1 << HASHBITS) - 1;
1613 hi %= MAX_HASH_TABLE;
1614 return hi;
1615}
1616\f
1617/* Compare a constant expression EXP with a constant-descriptor DESC.
1618 Return 1 if DESC describes a constant with the same value as EXP. */
1619
1620static int
1621compare_constant (exp, desc)
1622 tree exp;
1623 struct constant_descriptor *desc;
1624{
1625 return 0 != compare_constant_1 (exp, desc->contents);
1626}
1627
1628/* Compare constant expression EXP with a substring P of a constant descriptor.
1629 If they match, return a pointer to the end of the substring matched.
1630 If they do not match, return 0.
1631
1632 Since descriptors are written in polish prefix notation,
1633 this function can be used recursively to test one operand of EXP
1634 against a subdescriptor, and if it succeeds it returns the
1635 address of the subdescriptor for the next operand. */
1636
1637static char *
1638compare_constant_1 (exp, p)
1639 tree exp;
1640 char *p;
1641{
1642 register char *strp;
1643 register int len;
1644 register enum tree_code code = TREE_CODE (exp);
1645
1646 if (code != (enum tree_code) *p++)
1647 return 0;
1648
1649 if (code == INTEGER_CST)
1650 {
1651 /* Integer constants are the same only if the same width of type. */
1652 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
1653 return 0;
1654 strp = (char *) &TREE_INT_CST_LOW (exp);
1655 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1656 }
1657 else if (code == REAL_CST)
1658 {
1659 /* Real constants are the same only if the same width of type. */
1660 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
1661 return 0;
1662 strp = (char *) &TREE_REAL_CST (exp);
1663 len = sizeof TREE_REAL_CST (exp);
1664 }
1665 else if (code == STRING_CST)
1666 {
1667 if (flag_writable_strings)
1668 return 0;
1669 strp = TREE_STRING_POINTER (exp);
1670 len = TREE_STRING_LENGTH (exp);
1671 if (bcmp (&TREE_STRING_LENGTH (exp), p,
1672 sizeof TREE_STRING_LENGTH (exp)))
1673 return 0;
1674 p += sizeof TREE_STRING_LENGTH (exp);
1675 }
1676 else if (code == COMPLEX_CST)
1677 {
1678 p = compare_constant_1 (TREE_REALPART (exp), p);
1679 if (p == 0) return 0;
1680 p = compare_constant_1 (TREE_IMAGPART (exp), p);
1681 return p;
1682 }
1683 else if (code == CONSTRUCTOR)
1684 {
1685 register tree link;
1686 int length = list_length (CONSTRUCTOR_ELTS (exp));
1687 tree type;
1688
1689 if (bcmp (&length, p, sizeof length))
1690 return 0;
1691 p += sizeof length;
1692
1693 /* For record constructors, insist that the types match.
1694 For arrays, just verify both constructors are for arrays. */
1695 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1696 type = TREE_TYPE (exp);
1697 else
1698 type = 0;
1699 if (bcmp (&type, p, sizeof type))
1700 return 0;
1701 p += sizeof type;
1702
eb528802
RS
1703 /* For arrays, insist that the size in bytes match. */
1704 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
1705 {
1706 int size = int_size_in_bytes (TREE_TYPE (exp));
1707 if (bcmp (&size, p, sizeof size))
1708 return 0;
1709 p += sizeof size;
1710 }
1711
79e68feb 1712 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
77fa0940
RK
1713 {
1714 if (TREE_VALUE (link))
1715 {
1716 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
1717 return 0;
1718 }
1719 else
1720 {
1721 tree zero = 0;
1722
1723 if (bcmp (&zero, p, sizeof zero))
1724 return 0;
1725 p += sizeof zero;
1726 }
1727 }
1728
79e68feb
RS
1729 return p;
1730 }
1731 else if (code == ADDR_EXPR)
1732 {
1733 struct addr_const value;
1734 decode_addr_const (exp, &value);
1735 strp = (char *) &value.offset;
1736 len = sizeof value.offset;
1737 /* Compare the offset. */
1738 while (--len >= 0)
1739 if (*p++ != *strp++)
1740 return 0;
1741 /* Compare symbol name. */
1742 strp = XSTR (value.base, 0);
1743 len = strlen (strp) + 1;
1744 }
1745 else if (code == PLUS_EXPR || code == MINUS_EXPR)
1746 {
1747 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
1748 if (p == 0) return 0;
1749 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
1750 return p;
1751 }
1752 else if (code == NOP_EXPR || code == CONVERT_EXPR)
1753 {
1754 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
1755 return p;
1756 }
1757
1758 /* Compare constant contents. */
1759 while (--len >= 0)
1760 if (*p++ != *strp++)
1761 return 0;
1762
1763 return p;
1764}
1765\f
1766/* Construct a constant descriptor for the expression EXP.
1767 It is up to the caller to enter the descriptor in the hash table. */
1768
1769static struct constant_descriptor *
1770record_constant (exp)
1771 tree exp;
1772{
1773 struct constant_descriptor *ptr = 0;
1774 int buf;
1775
1776 obstack_grow (&permanent_obstack, &ptr, sizeof ptr);
1777 obstack_grow (&permanent_obstack, &buf, sizeof buf);
1778 record_constant_1 (exp);
1779 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
1780}
1781
1782/* Add a description of constant expression EXP
1783 to the object growing in `permanent_obstack'.
1784 No need to return its address; the caller will get that
1785 from the obstack when the object is complete. */
1786
1787static void
1788record_constant_1 (exp)
1789 tree exp;
1790{
1791 register char *strp;
1792 register int len;
1793 register enum tree_code code = TREE_CODE (exp);
1794
1795 obstack_1grow (&permanent_obstack, (unsigned int) code);
1796
1797 if (code == INTEGER_CST)
1798 {
1799 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
1800 strp = (char *) &TREE_INT_CST_LOW (exp);
1801 len = 2 * sizeof TREE_INT_CST_LOW (exp);
1802 }
1803 else if (code == REAL_CST)
1804 {
1805 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
1806 strp = (char *) &TREE_REAL_CST (exp);
1807 len = sizeof TREE_REAL_CST (exp);
1808 }
1809 else if (code == STRING_CST)
1810 {
1811 if (flag_writable_strings)
1812 return;
1813 strp = TREE_STRING_POINTER (exp);
1814 len = TREE_STRING_LENGTH (exp);
1815 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
1816 sizeof TREE_STRING_LENGTH (exp));
1817 }
1818 else if (code == COMPLEX_CST)
1819 {
1820 record_constant_1 (TREE_REALPART (exp));
1821 record_constant_1 (TREE_IMAGPART (exp));
1822 return;
1823 }
1824 else if (code == CONSTRUCTOR)
1825 {
1826 register tree link;
1827 int length = list_length (CONSTRUCTOR_ELTS (exp));
1828 tree type;
1829
1830 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
1831
1832 /* For record constructors, insist that the types match.
1833 For arrays, just verify both constructors are for arrays. */
1834 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
1835 type = TREE_TYPE (exp);
1836 else
1837 type = 0;
1838 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
1839
eb528802
RS
1840 /* For arrays, insist that the size in bytes match. */
1841 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
1842 {
1843 int size = int_size_in_bytes (TREE_TYPE (exp));
1844 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
1845 }
1846
79e68feb 1847 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
77fa0940
RK
1848 {
1849 if (TREE_VALUE (link))
1850 record_constant_1 (TREE_VALUE (link));
1851 else
1852 {
1853 tree zero = 0;
1854
1855 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
1856 }
1857 }
1858
79e68feb
RS
1859 return;
1860 }
1861 else if (code == ADDR_EXPR)
1862 {
1863 struct addr_const value;
1864 decode_addr_const (exp, &value);
1865 /* Record the offset. */
1866 obstack_grow (&permanent_obstack,
1867 (char *) &value.offset, sizeof value.offset);
1868 /* Record the symbol name. */
1869 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
1870 strlen (XSTR (value.base, 0)) + 1);
1871 return;
1872 }
1873 else if (code == PLUS_EXPR || code == MINUS_EXPR)
1874 {
1875 record_constant_1 (TREE_OPERAND (exp, 0));
1876 record_constant_1 (TREE_OPERAND (exp, 1));
1877 return;
1878 }
1879 else if (code == NOP_EXPR || code == CONVERT_EXPR)
1880 {
1881 record_constant_1 (TREE_OPERAND (exp, 0));
1882 return;
1883 }
1884
1885 /* Record constant contents. */
1886 obstack_grow (&permanent_obstack, strp, len);
1887}
1888\f
1889/* Return an rtx representing a reference to constant data in memory
1890 for the constant expression EXP.
1891 If assembler code for such a constant has already been output,
1892 return an rtx to refer to it.
1893 Otherwise, output such a constant in memory and generate
1894 an rtx for it. The TREE_CST_RTL of EXP is set up to point to that rtx.
1895 The const_hash_table records which constants already have label strings. */
1896
1897rtx
1898output_constant_def (exp)
1899 tree exp;
1900{
1901 register int hash, align;
1902 register struct constant_descriptor *desc;
1903 char label[256];
1904 char *found = 0;
1905 int reloc;
1906 register rtx def;
1907
1908 if (TREE_CODE (exp) == INTEGER_CST)
1909 abort (); /* No TREE_CST_RTL slot in these. */
1910
1911 if (TREE_CST_RTL (exp))
1912 return TREE_CST_RTL (exp);
1913
1914 /* Make sure any other constants whose addresses appear in EXP
1915 are assigned label numbers. */
1916
1917 reloc = output_addressed_constants (exp);
1918
1919 /* Compute hash code of EXP. Search the descriptors for that hash code
1920 to see if any of them describes EXP. If yes, the descriptor records
1921 the label number already assigned. */
1922
1923 hash = const_hash (exp) % MAX_HASH_TABLE;
1924
1925 for (desc = const_hash_table[hash]; desc; desc = desc->next)
1926 if (compare_constant (exp, desc))
1927 {
1928 found = desc->label;
1929 break;
1930 }
1931
1932 if (found == 0)
1933 {
1934 /* No constant equal to EXP is known to have been output.
1935 Make a constant descriptor to enter EXP in the hash table.
1936 Assign the label number and record it in the descriptor for
1937 future calls to this function to find. */
1938
1939 /* Create a string containing the label name, in LABEL. */
1940 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
1941
1942 desc = record_constant (exp);
1943 desc->next = const_hash_table[hash];
1944 desc->label
1945 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1946 const_hash_table[hash] = desc;
1947 }
1948
1949 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
1950
1951 push_obstacks_nochange ();
1952 if (TREE_PERMANENT (exp))
1953 end_temporary_allocation ();
1954
1955 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
1956
1957 TREE_CST_RTL (exp)
1958 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
1959 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
dd43f13d
RS
1960 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
1961 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
1962 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
79e68feb
RS
1963
1964 pop_obstacks ();
1965
1966 /* Optionally set flags or add text to the name to record information
1967 such as that it is a function name. If the name is changed, the macro
1968 ASM_OUTPUT_LABELREF will have to know how to strip this information.
1969 And if it finds a * at the beginning after doing so, it must handle
1970 that too. */
1971#ifdef ENCODE_SECTION_INFO
1972 ENCODE_SECTION_INFO (exp);
1973#endif
1974
1975 if (found == 0)
1976 {
1977 /* Now output assembler code to define that label
1978 and follow it with the data of EXP. */
1979
1980 /* First switch to text section, except for writable strings. */
1981#ifdef SELECT_SECTION
1982 SELECT_SECTION (exp, reloc);
1983#else
1984 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
1985 || (flag_pic && reloc))
1986 data_section ();
1987 else
1988 readonly_data_section ();
1989#endif
1990
1991 /* Align the location counter as required by EXP's data type. */
1992 align = TYPE_ALIGN (TREE_TYPE (exp));
1993#ifdef CONSTANT_ALIGNMENT
1994 align = CONSTANT_ALIGNMENT (exp, align);
1995#endif
1996
1997 if (align > BITS_PER_UNIT)
1998 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1999
2000 /* Output the label itself. */
2001 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", const_labelno);
2002
2003 /* Output the value of EXP. */
2004 output_constant (exp,
2005 (TREE_CODE (exp) == STRING_CST
2006 ? TREE_STRING_LENGTH (exp)
2007 : int_size_in_bytes (TREE_TYPE (exp))));
2008
2009 ++const_labelno;
2010 }
2011
2012 return TREE_CST_RTL (exp);
2013}
2014\f
2015/* Similar hash facility for making memory-constants
2016 from constant rtl-expressions. It is used on RISC machines
2017 where immediate integer arguments and constant addresses are restricted
2018 so that such constants must be stored in memory.
2019
2020 This pool of constants is reinitialized for each function
2021 so each function gets its own constants-pool that comes right before it.
2022
2023 All structures allocated here are discarded when functions are saved for
2024 inlining, so they do not need to be allocated permanently. */
2025
2026#define MAX_RTX_HASH_TABLE 61
57632c51 2027static struct constant_descriptor **const_rtx_hash_table;
79e68feb
RS
2028
2029/* Structure to represent sufficient information about a constant so that
2030 it can be output when the constant pool is output, so that function
2031 integration can be done, and to simplify handling on machines that reference
2032 constant pool as base+displacement. */
2033
2034struct pool_constant
2035{
2036 struct constant_descriptor *desc;
2037 struct pool_constant *next;
2038 enum machine_mode mode;
2039 rtx constant;
2040 int labelno;
2041 int align;
2042 int offset;
2043};
2044
2045/* Pointers to first and last constant in pool. */
2046
2047static struct pool_constant *first_pool, *last_pool;
2048
2049/* Current offset in constant pool (does not include any machine-specific
2050 header. */
2051
2052static int pool_offset;
2053
2054/* Structure used to maintain hash table mapping symbols used to their
2055 corresponding constants. */
2056
2057struct pool_sym
2058{
2059 char *label;
2060 struct pool_constant *pool;
2061 struct pool_sym *next;
2062};
2063
57632c51 2064static struct pool_sym **const_rtx_sym_hash_table;
79e68feb
RS
2065
2066/* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2067 The argument is XSTR (... , 0) */
2068
2069#define SYMHASH(LABEL) \
fb351073 2070 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
79e68feb
RS
2071\f
2072/* Initialize constant pool hashing for next function. */
2073
2074void
2075init_const_rtx_hash_table ()
2076{
57632c51
RS
2077 const_rtx_hash_table
2078 = ((struct constant_descriptor **)
2079 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2080 const_rtx_sym_hash_table
2081 = ((struct pool_sym **)
2082 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2083 bzero (const_rtx_hash_table,
2084 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2085 bzero (const_rtx_sym_hash_table,
2086 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
79e68feb
RS
2087
2088 first_pool = last_pool = 0;
2089 pool_offset = 0;
2090}
2091
57632c51
RS
2092/* Save and restore it for a nested function. */
2093
2094void
2095save_varasm_status (p)
2096 struct function *p;
2097{
2098 p->const_rtx_hash_table = const_rtx_hash_table;
2099 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2100 p->first_pool = first_pool;
2101 p->last_pool = last_pool;
2102 p->pool_offset = pool_offset;
2103}
2104
2105void
2106restore_varasm_status (p)
2107 struct function *p;
2108{
2109 const_rtx_hash_table = p->const_rtx_hash_table;
2110 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2111 first_pool = p->first_pool;
2112 last_pool = p->last_pool;
2113 pool_offset = p->pool_offset;
2114}
2115\f
79e68feb
RS
2116enum kind { RTX_DOUBLE, RTX_INT };
2117
2118struct rtx_const
2119{
2120#ifdef ONLY_INT_FIELDS
2121 unsigned int kind : 16;
2122 unsigned int mode : 16;
2123#else
2124 enum kind kind : 16;
2125 enum machine_mode mode : 16;
2126#endif
2127 union {
2128 union real_extract du;
2129 struct addr_const addr;
2130 } un;
2131};
2132
2133/* Express an rtx for a constant integer (perhaps symbolic)
2134 as the sum of a symbol or label plus an explicit integer.
2135 They are stored into VALUE. */
2136
2137static void
2138decode_rtx_const (mode, x, value)
2139 enum machine_mode mode;
2140 rtx x;
2141 struct rtx_const *value;
2142{
2143 /* Clear the whole structure, including any gaps. */
2144
2145 {
2146 int *p = (int *) value;
2147 int *end = (int *) (value + 1);
2148 while (p < end)
2149 *p++ = 0;
2150 }
2151
2152 value->kind = RTX_INT; /* Most usual kind. */
2153 value->mode = mode;
2154
2155 switch (GET_CODE (x))
2156 {
2157 case CONST_DOUBLE:
2158 value->kind = RTX_DOUBLE;
2159 value->mode = GET_MODE (x);
2160 bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
2161 break;
2162
2163 case CONST_INT:
2164 value->un.addr.offset = INTVAL (x);
2165 break;
2166
2167 case SYMBOL_REF:
2168 case LABEL_REF:
3d037392 2169 case PC:
79e68feb
RS
2170 value->un.addr.base = x;
2171 break;
2172
2173 case CONST:
2174 x = XEXP (x, 0);
2175 if (GET_CODE (x) == PLUS)
2176 {
2177 value->un.addr.base = XEXP (x, 0);
2178 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2179 abort ();
2180 value->un.addr.offset = INTVAL (XEXP (x, 1));
2181 }
2182 else if (GET_CODE (x) == MINUS)
2183 {
2184 value->un.addr.base = XEXP (x, 0);
2185 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2186 abort ();
2187 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2188 }
2189 else
2190 abort ();
2191 break;
2192
2193 default:
2194 abort ();
2195 }
2196
2197 if (value->kind == RTX_INT && value->un.addr.base != 0)
2198 switch (GET_CODE (value->un.addr.base))
2199 {
2200 case SYMBOL_REF:
2201 case LABEL_REF:
2202 /* Use the string's address, not the SYMBOL_REF's address,
2203 for the sake of addresses of library routines.
2204 For a LABEL_REF, compare labels. */
2205 value->un.addr.base = XEXP (value->un.addr.base, 0);
2206 }
2207}
2208
57632c51
RS
2209/* Given a MINUS expression, simplify it if both sides
2210 include the same symbol. */
2211
2212rtx
2213simplify_subtraction (x)
2214 rtx x;
2215{
2216 struct rtx_const val0, val1;
2217
2218 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2219 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2220
2221 if (val0.un.addr.base == val1.un.addr.base)
2222 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2223 return x;
2224}
2225
79e68feb
RS
2226/* Compute a hash code for a constant RTL expression. */
2227
2228int
2229const_hash_rtx (mode, x)
2230 enum machine_mode mode;
2231 rtx x;
2232{
2233 register int hi, i;
2234
2235 struct rtx_const value;
2236 decode_rtx_const (mode, x, &value);
2237
2238 /* Compute hashing function */
2239 hi = 0;
2240 for (i = 0; i < sizeof value / sizeof (int); i++)
2241 hi += ((int *) &value)[i];
2242
2243 hi &= (1 << HASHBITS) - 1;
2244 hi %= MAX_RTX_HASH_TABLE;
2245 return hi;
2246}
2247
2248/* Compare a constant rtl object X with a constant-descriptor DESC.
2249 Return 1 if DESC describes a constant with the same value as X. */
2250
2251static int
2252compare_constant_rtx (mode, x, desc)
2253 enum machine_mode mode;
2254 rtx x;
2255 struct constant_descriptor *desc;
2256{
2257 register int *p = (int *) desc->contents;
2258 register int *strp;
2259 register int len;
2260 struct rtx_const value;
2261
2262 decode_rtx_const (mode, x, &value);
2263 strp = (int *) &value;
2264 len = sizeof value / sizeof (int);
2265
2266 /* Compare constant contents. */
2267 while (--len >= 0)
2268 if (*p++ != *strp++)
2269 return 0;
2270
2271 return 1;
2272}
2273
2274/* Construct a constant descriptor for the rtl-expression X.
2275 It is up to the caller to enter the descriptor in the hash table. */
2276
2277static struct constant_descriptor *
2278record_constant_rtx (mode, x)
2279 enum machine_mode mode;
2280 rtx x;
2281{
2282 struct constant_descriptor *ptr;
2283 char *label;
2284 struct rtx_const value;
2285
2286 decode_rtx_const (mode, x, &value);
2287
2288 obstack_grow (current_obstack, &ptr, sizeof ptr);
2289 obstack_grow (current_obstack, &label, sizeof label);
2290
2291 /* Record constant contents. */
2292 obstack_grow (current_obstack, &value, sizeof value);
2293
2294 return (struct constant_descriptor *) obstack_finish (current_obstack);
2295}
2296\f
2297/* Given a constant rtx X, make (or find) a memory constant for its value
2298 and return a MEM rtx to refer to it in memory. */
2299
2300rtx
2301force_const_mem (mode, x)
2302 enum machine_mode mode;
2303 rtx x;
2304{
2305 register int hash;
2306 register struct constant_descriptor *desc;
2307 char label[256];
2308 char *found = 0;
2309 rtx def;
2310
2311 /* If we want this CONST_DOUBLE in the same mode as it is in memory
2312 (this will always be true for floating CONST_DOUBLEs that have been
2313 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
2314 use the previous copy. Otherwise, make a new one. Note that in
2315 the unlikely event that this same CONST_DOUBLE is used in two different
2316 modes in an alternating fashion, we will allocate a lot of different
2317 memory locations, but this should be extremely rare. */
2318
57632c51
RS
2319 /* Don't use CONST_DOUBLE_MEM in a nested function.
2320 Nested functions have their own constant pools,
2321 so they can't share the same values in CONST_DOUBLE_MEM
2322 with the containing function. */
2323 if (outer_function_chain == 0)
2324 if (GET_CODE (x) == CONST_DOUBLE
2325 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
2326 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
2327 return CONST_DOUBLE_MEM (x);
79e68feb
RS
2328
2329 /* Compute hash code of X. Search the descriptors for that hash code
2330 to see if any of them describes X. If yes, the descriptor records
2331 the label number already assigned. */
2332
2333 hash = const_hash_rtx (mode, x);
2334
2335 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
2336 if (compare_constant_rtx (mode, x, desc))
2337 {
2338 found = desc->label;
2339 break;
2340 }
2341
2342 if (found == 0)
2343 {
2344 register struct pool_constant *pool;
2345 register struct pool_sym *sym;
2346 int align;
2347
2348 /* No constant equal to X is known to have been output.
2349 Make a constant descriptor to enter X in the hash table.
2350 Assign the label number and record it in the descriptor for
2351 future calls to this function to find. */
2352
2353 desc = record_constant_rtx (mode, x);
2354 desc->next = const_rtx_hash_table[hash];
2355 const_rtx_hash_table[hash] = desc;
2356
2357 /* Align the location counter as required by EXP's data type. */
2358 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
2359 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
2360 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
2361
2362 pool_offset += align - 1;
2363 pool_offset &= ~ (align - 1);
2364
2365 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
2366
2367 pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
2368 pool->desc = desc;
2369 pool->constant = x;
2370 pool->mode = mode;
2371 pool->labelno = const_labelno;
2372 pool->align = align;
2373 pool->offset = pool_offset;
2374 pool->next = 0;
2375
2376 if (last_pool == 0)
2377 first_pool = pool;
2378 else
2379 last_pool->next = pool;
2380
2381 last_pool = pool;
2382 pool_offset += GET_MODE_SIZE (mode);
2383
2384 /* Create a string containing the label name, in LABEL. */
2385 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2386
2387 ++const_labelno;
2388
2389 desc->label = found
2390 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
2391
2392 /* Add label to symbol hash table. */
2393 hash = SYMHASH (found);
2394 sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
2395 sym->label = found;
2396 sym->pool = pool;
2397 sym->next = const_rtx_sym_hash_table[hash];
2398 const_rtx_sym_hash_table[hash] = sym;
2399 }
2400
2401 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2402
2403 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
2404
2405 RTX_UNCHANGING_P (def) = 1;
2406 /* Mark the symbol_ref as belonging to this constants pool. */
2407 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
2408 current_function_uses_const_pool = 1;
2409
57632c51
RS
2410 if (outer_function_chain == 0)
2411 if (GET_CODE (x) == CONST_DOUBLE)
2412 {
2413 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
2414 {
2415 CONST_DOUBLE_CHAIN (x) = const_double_chain;
2416 const_double_chain = x;
2417 }
2418 CONST_DOUBLE_MEM (x) = def;
2419 }
79e68feb
RS
2420
2421 return def;
2422}
2423\f
2424/* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
2425 the corresponding pool_constant structure. */
2426
2427static struct pool_constant *
2428find_pool_constant (addr)
2429 rtx addr;
2430{
2431 struct pool_sym *sym;
2432 char *label = XSTR (addr, 0);
2433
2434 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
2435 if (sym->label == label)
2436 return sym->pool;
2437
2438 abort ();
2439}
2440
2441/* Given a constant pool SYMBOL_REF, return the corresponding constant. */
2442
2443rtx
2444get_pool_constant (addr)
2445 rtx addr;
2446{
2447 return (find_pool_constant (addr))->constant;
2448}
2449
2450/* Similar, return the mode. */
2451
2452enum machine_mode
2453get_pool_mode (addr)
2454 rtx addr;
2455{
2456 return (find_pool_constant (addr))->mode;
2457}
2458
2459/* Similar, return the offset in the constant pool. */
2460
2461int
2462get_pool_offset (addr)
2463 rtx addr;
2464{
2465 return (find_pool_constant (addr))->offset;
2466}
2467
2468/* Return the size of the constant pool. */
2469
2470int
2471get_pool_size ()
2472{
2473 return pool_offset;
2474}
2475\f
2476/* Write all the constants in the constant pool. */
2477
2478void
2479output_constant_pool (fnname, fndecl)
2480 char *fnname;
2481 tree fndecl;
2482{
2483 struct pool_constant *pool;
2484 rtx x;
2485 union real_extract u;
2486
2487#ifdef ASM_OUTPUT_POOL_PROLOGUE
2488 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
2489#endif
2490
2491 for (pool = first_pool; pool; pool = pool->next)
2492 {
2493 x = pool->constant;
2494
2495 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
2496 whose CODE_LABEL has been deleted. This can occur if a jump table
2497 is eliminated by optimization. If so, write a constant of zero
7b2b3f1f
RK
2498 instead. Note that this can also happen by turning the
2499 CODE_LABEL into a NOTE. */
2500 if (((GET_CODE (x) == LABEL_REF
2501 && (INSN_DELETED_P (XEXP (x, 0))
2502 || GET_CODE (XEXP (x, 0)) == NOTE)))
79e68feb
RS
2503 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
2504 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
7b2b3f1f
RK
2505 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
2506 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
79e68feb
RS
2507 x = const0_rtx;
2508
2509 /* First switch to correct section. */
2510#ifdef SELECT_RTX_SECTION
2511 SELECT_RTX_SECTION (pool->mode, x);
2512#else
2513 readonly_data_section ();
2514#endif
2515
2516#ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
2517 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
2518 pool->align, pool->labelno, done);
2519#endif
2520
2521 if (pool->align > 1)
2522 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
2523
2524 /* Output the label. */
2525 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
2526
2527 /* Output the value of the constant itself. */
2528 switch (GET_MODE_CLASS (pool->mode))
2529 {
2530 case MODE_FLOAT:
2531 if (GET_CODE (x) != CONST_DOUBLE)
2532 abort ();
2533
2534 bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
2535 assemble_real (u.d, pool->mode);
2536 break;
2537
2538 case MODE_INT:
2539 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
2540 break;
2541
2542 default:
2543 abort ();
2544 }
2545
2546 done: ;
2547 }
2548
2549 /* Done with this pool. */
2550 first_pool = last_pool = 0;
2551}
2552\f
2553/* Find all the constants whose addresses are referenced inside of EXP,
2554 and make sure assembler code with a label has been output for each one.
2555 Indicate whether an ADDR_EXPR has been encountered. */
2556
2557int
2558output_addressed_constants (exp)
2559 tree exp;
2560{
2561 int reloc = 0;
2562
2563 switch (TREE_CODE (exp))
2564 {
2565 case ADDR_EXPR:
2566 {
2567 register tree constant = TREE_OPERAND (exp, 0);
2568
2569 while (TREE_CODE (constant) == COMPONENT_REF)
2570 {
2571 constant = TREE_OPERAND (constant, 0);
2572 }
2573
2574 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
2575 || TREE_CODE (constant) == CONSTRUCTOR)
2576 /* No need to do anything here
2577 for addresses of variables or functions. */
2578 output_constant_def (constant);
2579 }
2580 reloc = 1;
2581 break;
2582
2583 case PLUS_EXPR:
2584 case MINUS_EXPR:
2585 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
2586 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
2587 break;
2588
2589 case NOP_EXPR:
2590 case CONVERT_EXPR:
37a52112 2591 case NON_LVALUE_EXPR:
79e68feb
RS
2592 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
2593 break;
2594
2595 case CONSTRUCTOR:
2596 {
2597 register tree link;
2598 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2599 if (TREE_VALUE (link) != 0)
2600 reloc |= output_addressed_constants (TREE_VALUE (link));
2601 }
2602 break;
2603
2604 case ERROR_MARK:
2605 break;
2606 }
2607 return reloc;
2608}
2609\f
2610/* Output assembler code for constant EXP to FILE, with no label.
2611 This includes the pseudo-op such as ".int" or ".byte", and a newline.
2612 Assumes output_addressed_constants has been done on EXP already.
2613
2614 Generate exactly SIZE bytes of assembler data, padding at the end
2615 with zeros if necessary. SIZE must always be specified.
2616
2617 SIZE is important for structure constructors,
2618 since trailing members may have been omitted from the constructor.
2619 It is also important for initialization of arrays from string constants
2620 since the full length of the string constant might not be wanted.
2621 It is also needed for initialization of unions, where the initializer's
2622 type is just one member, and that may not be as long as the union.
2623
2624 There a case in which we would fail to output exactly SIZE bytes:
2625 for a structure constructor that wants to produce more than SIZE bytes.
2626 But such constructors will never be generated for any possible input. */
2627
2628void
2629output_constant (exp, size)
2630 register tree exp;
2631 register int size;
2632{
2633 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
2634 rtx x;
2635
2636 if (size == 0)
2637 return;
2638
fff9e713
MT
2639 /* Allow a constructor with no elements for any data type.
2640 This means to fill the space with zeros. */
77fa0940 2641 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
fff9e713
MT
2642 {
2643 assemble_zeros (size);
2644 return;
2645 }
2646
79e68feb
RS
2647 /* Eliminate the NOP_EXPR that makes a cast not be an lvalue.
2648 That way we get the constant (we hope) inside it. */
2649 if (TREE_CODE (exp) == NOP_EXPR
2650 && TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0)))
2651 exp = TREE_OPERAND (exp, 0);
2652
2653 switch (code)
2654 {
2655 case INTEGER_TYPE:
2656 case ENUMERAL_TYPE:
2657 case POINTER_TYPE:
2658 case REFERENCE_TYPE:
2659 /* ??? What about (int)((float)(int)&foo + 4) */
2660 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
2661 || TREE_CODE (exp) == NON_LVALUE_EXPR)
2662 exp = TREE_OPERAND (exp, 0);
2663
37366632 2664 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
79e68feb
RS
2665 EXPAND_INITIALIZER),
2666 size, 0))
2667 error ("initializer for integer value is too complicated");
2668 size = 0;
2669 break;
2670
2671 case REAL_TYPE:
2672 if (TREE_CODE (exp) != REAL_CST)
2673 error ("initializer for floating value is not a floating constant");
2674
2675 assemble_real (TREE_REAL_CST (exp),
2676 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
2677 size = 0;
2678 break;
2679
2680 case COMPLEX_TYPE:
2681 output_constant (TREE_REALPART (exp), size / 2);
2682 output_constant (TREE_IMAGPART (exp), size / 2);
2683 size -= (size / 2) * 2;
2684 break;
2685
2686 case ARRAY_TYPE:
2687 if (TREE_CODE (exp) == CONSTRUCTOR)
2688 {
2689 output_constructor (exp, size);
2690 return;
2691 }
2692 else if (TREE_CODE (exp) == STRING_CST)
2693 {
2694 int excess = 0;
2695
2696 if (size > TREE_STRING_LENGTH (exp))
2697 {
2698 excess = size - TREE_STRING_LENGTH (exp);
2699 size = TREE_STRING_LENGTH (exp);
2700 }
2701
2702 assemble_string (TREE_STRING_POINTER (exp), size);
2703 size = excess;
2704 }
2705 else
2706 abort ();
2707 break;
2708
2709 case RECORD_TYPE:
2710 case UNION_TYPE:
2711 if (TREE_CODE (exp) == CONSTRUCTOR)
2712 output_constructor (exp, size);
2713 else
2714 abort ();
2715 return;
2716 }
2717
2718 if (size > 0)
2719 assemble_zeros (size);
2720}
2721\f
2722/* Subroutine of output_constant, used for CONSTRUCTORs
2723 (aggregate constants).
2724 Generate at least SIZE bytes, padding if necessary. */
2725
2726void
2727output_constructor (exp, size)
2728 tree exp;
2729 int size;
2730{
2731 register tree link, field = 0;
2732 /* Number of bytes output or skipped so far.
2733 In other words, current position within the constructor. */
2734 int total_bytes = 0;
2735 /* Non-zero means BYTE contains part of a byte, to be output. */
2736 int byte_buffer_in_use = 0;
2737 register int byte;
2738
37366632 2739 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
79e68feb
RS
2740 abort ();
2741
2742 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2743 field = TYPE_FIELDS (TREE_TYPE (exp));
2744
2745 /* As LINK goes through the elements of the constant,
2746 FIELD goes through the structure fields, if the constant is a structure.
2747 if the constant is a union, then we override this,
2748 by getting the field from the TREE_LIST element.
2749 But the constant could also be an array. Then FIELD is zero. */
2750 for (link = CONSTRUCTOR_ELTS (exp);
2751 link;
2752 link = TREE_CHAIN (link),
2753 field = field ? TREE_CHAIN (field) : 0)
2754 {
2755 tree val = TREE_VALUE (link);
2756 /* the element in a union constructor specifies the proper field. */
2757 if (TREE_PURPOSE (link) != 0)
2758 field = TREE_PURPOSE (link);
2759
2760 /* Eliminate the marker that makes a cast not be an lvalue. */
d964285c
CH
2761 if (val != 0)
2762 STRIP_NOPS (val);
79e68feb
RS
2763
2764 if (field == 0 || !DECL_BIT_FIELD (field))
2765 {
2766 register int fieldsize;
2767 /* Since this structure is static,
2768 we know the positions are constant. */
2769 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
2770 / BITS_PER_UNIT)
2771 : 0);
2772
2773 /* An element that is not a bit-field.
2774 Output any buffered-up bit-fields preceding it. */
2775 if (byte_buffer_in_use)
2776 {
2777 ASM_OUTPUT_BYTE (asm_out_file, byte);
2778 total_bytes++;
2779 byte_buffer_in_use = 0;
2780 }
2781
2782 /* Advance to offset of this element.
2783 Note no alignment needed in an array, since that is guaranteed
2784 if each element has the proper size. */
2785 if (field != 0 && bitpos != total_bytes)
2786 {
2787 assemble_zeros (bitpos - total_bytes);
2788 total_bytes = bitpos;
2789 }
2790
2791 /* Determine size this element should occupy. */
2792 if (field)
2793 {
2794 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
2795 abort ();
2796 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
2797 {
2798 /* This avoids overflow trouble. */
2799 tree size_tree = size_binop (CEIL_DIV_EXPR,
2800 DECL_SIZE (field),
2801 size_int (BITS_PER_UNIT));
2802 fieldsize = TREE_INT_CST_LOW (size_tree);
2803 }
2804 else
2805 {
2806 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
2807 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
2808 }
2809 }
2810 else
2811 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
2812
2813 /* Output the element's initial value. */
2814 if (val == 0)
2815 assemble_zeros (fieldsize);
2816 else
2817 output_constant (val, fieldsize);
2818
2819 /* Count its size. */
2820 total_bytes += fieldsize;
2821 }
2822 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
2823 error ("invalid initial value for member `%s'",
2824 IDENTIFIER_POINTER (DECL_NAME (field)));
2825 else
2826 {
2827 /* Element that is a bit-field. */
2828
2829 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
2830 int end_offset
2831 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
2832
2833 if (val == 0)
2834 val = integer_zero_node;
2835
2836 /* If this field does not start in this (or, next) byte,
2837 skip some bytes. */
2838 if (next_offset / BITS_PER_UNIT != total_bytes)
2839 {
2840 /* Output remnant of any bit field in previous bytes. */
2841 if (byte_buffer_in_use)
2842 {
2843 ASM_OUTPUT_BYTE (asm_out_file, byte);
2844 total_bytes++;
2845 byte_buffer_in_use = 0;
2846 }
2847
2848 /* If still not at proper byte, advance to there. */
2849 if (next_offset / BITS_PER_UNIT != total_bytes)
2850 {
2851 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
2852 total_bytes = next_offset / BITS_PER_UNIT;
2853 }
2854 }
2855
2856 if (! byte_buffer_in_use)
2857 byte = 0;
2858
2859 /* We must split the element into pieces that fall within
2860 separate bytes, and combine each byte with previous or
2861 following bit-fields. */
2862
b4ac57ab 2863 /* next_offset is the offset n fbits from the beginning of
79e68feb
RS
2864 the structure to the next bit of this element to be processed.
2865 end_offset is the offset of the first bit past the end of
2866 this element. */
2867 while (next_offset < end_offset)
2868 {
2869 int this_time;
2870 int shift, value;
2871 int next_byte = next_offset / BITS_PER_UNIT;
2872 int next_bit = next_offset % BITS_PER_UNIT;
2873
2874 /* Advance from byte to byte
2875 within this element when necessary. */
2876 while (next_byte != total_bytes)
2877 {
2878 ASM_OUTPUT_BYTE (asm_out_file, byte);
2879 total_bytes++;
2880 byte = 0;
2881 }
2882
2883 /* Number of bits we can process at once
2884 (all part of the same byte). */
2885 this_time = MIN (end_offset - next_offset,
2886 BITS_PER_UNIT - next_bit);
2887#if BYTES_BIG_ENDIAN
2888 /* On big-endian machine, take the most significant bits
2889 first (of the bits that are significant)
2890 and put them into bytes from the most significant end. */
2891 shift = end_offset - next_offset - this_time;
2892 /* Don't try to take a bunch of bits that cross
2893 the word boundary in the INTEGER_CST. */
37366632
RK
2894 if (shift < HOST_BITS_PER_WIDE_INT
2895 && shift + this_time > HOST_BITS_PER_WIDE_INT)
79e68feb 2896 {
37366632
RK
2897 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
2898 shift = HOST_BITS_PER_WIDE_INT;
79e68feb
RS
2899 }
2900
2901 /* Now get the bits from the appropriate constant word. */
37366632 2902 if (shift < HOST_BITS_PER_WIDE_INT)
79e68feb
RS
2903 {
2904 value = TREE_INT_CST_LOW (val);
2905 }
37366632 2906 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
79e68feb
RS
2907 {
2908 value = TREE_INT_CST_HIGH (val);
37366632 2909 shift -= HOST_BITS_PER_WIDE_INT;
79e68feb
RS
2910 }
2911 else
2912 abort ();
37366632
RK
2913 byte |= (((value >> shift)
2914 & (((HOST_WIDE_INT) 1 << this_time) - 1))
79e68feb
RS
2915 << (BITS_PER_UNIT - this_time - next_bit));
2916#else
2917 /* On little-endian machines,
2918 take first the least significant bits of the value
2919 and pack them starting at the least significant
2920 bits of the bytes. */
2921 shift = (next_offset
2922 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
2923 /* Don't try to take a bunch of bits that cross
2924 the word boundary in the INTEGER_CST. */
37366632
RK
2925 if (shift < HOST_BITS_PER_WIDE_INT
2926 && shift + this_time > HOST_BITS_PER_WIDE_INT)
79e68feb 2927 {
37366632
RK
2928 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
2929 shift = HOST_BITS_PER_WIDE_INT;
79e68feb
RS
2930 }
2931
2932 /* Now get the bits from the appropriate constant word. */
2933 if (shift < HOST_BITS_PER_INT)
2934 value = TREE_INT_CST_LOW (val);
37366632 2935 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
79e68feb
RS
2936 {
2937 value = TREE_INT_CST_HIGH (val);
37366632 2938 shift -= HOST_BITS_PER_WIDE_INT;
79e68feb
RS
2939 }
2940 else
2941 abort ();
37366632
RK
2942 byte |= ((value >> shift)
2943 & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
79e68feb
RS
2944#endif
2945 next_offset += this_time;
2946 byte_buffer_in_use = 1;
2947 }
2948 }
2949 }
2950 if (byte_buffer_in_use)
2951 {
2952 ASM_OUTPUT_BYTE (asm_out_file, byte);
2953 total_bytes++;
2954 }
2955 if (total_bytes < size)
2956 assemble_zeros (size - total_bytes);
2957}
This page took 0.358991 seconds and 5 git commands to generate.