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