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