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