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