]> gcc.gnu.org Git - gcc.git/blob - gcc/varasm.c
c08f46e61ec4b57acfa2258cc0eda032e0e87c11
[gcc.git] / gcc / varasm.c
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92, 93, 1994 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 "function.h"
36 #include "expr.h"
37 #include "hard-reg-set.h"
38 #include "regs.h"
39 #include "defaults.h"
40 #include "real.h"
41 #include "bytecode.h"
42
43 #include "obstack.h"
44
45 #ifdef XCOFF_DEBUGGING_INFO
46 #include "xcoffout.h"
47 #endif
48
49 #include <ctype.h>
50
51 #ifndef ASM_STABS_OP
52 #define ASM_STABS_OP ".stabs"
53 #endif
54
55 /* This macro gets just the user-specified name
56 out of the string in a SYMBOL_REF. On most machines,
57 we discard the * if any and that's all. */
58 #ifndef STRIP_NAME_ENCODING
59 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
60 (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
61 #endif
62
63 /* File in which assembler code is being written. */
64
65 extern FILE *asm_out_file;
66
67 /* The (assembler) name of the first globally-visible object output. */
68 char *first_global_object_name;
69
70 extern struct obstack *current_obstack;
71 extern struct obstack *saveable_obstack;
72 extern struct obstack permanent_obstack;
73 #define obstack_chunk_alloc xmalloc
74
75 /* Number for making the label on the next
76 constant that is stored in memory. */
77
78 int const_labelno;
79
80 /* Number for making the label on the next
81 static variable internal to a function. */
82
83 int var_labelno;
84
85 /* Carry information from ASM_DECLARE_OBJECT_NAME
86 to ASM_FINISH_DECLARE_OBJECT. */
87
88 int size_directive_output;
89
90 /* The last decl for which assemble_variable was called,
91 if it did ASM_DECLARE_OBJECT_NAME.
92 If the last call to assemble_variable didn't do that,
93 this holds 0. */
94
95 tree last_assemble_variable_decl;
96
97 /* Nonzero if at least one function definition has been seen. */
98 static int function_defined;
99
100 extern FILE *asm_out_file;
101
102 static char *compare_constant_1 ();
103 static void record_constant_1 ();
104 static void output_constant_def_contents ();
105 static int contains_pointers_p ();
106 static void bc_output_ascii ();
107
108 void output_constant_pool ();
109 void assemble_name ();
110 int output_addressed_constants ();
111 void output_constant ();
112 void output_constructor ();
113 void output_byte_asm ();
114 void text_section ();
115 void readonly_data_section ();
116 void data_section ();
117 void named_section ();
118 static void bc_assemble_integer ();
119 \f
120 #ifdef EXTRA_SECTIONS
121 static enum in_section {no_section, in_text, in_data, in_named, EXTRA_SECTIONS} in_section
122 = no_section;
123 #else
124 static enum in_section {no_section, in_text, in_data, in_named} in_section
125 = no_section;
126 #endif
127
128 /* Return a non-zero value if DECL has a section attribute. */
129 #define IN_NAMED_SECTION(DECL) \
130 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
131 && DECL_SECTION_NAME (DECL) != NULL_TREE)
132
133 /* Text of section name when in_section == in_named. */
134 static char *in_named_name;
135
136 /* Define functions like text_section for any extra sections. */
137 #ifdef EXTRA_SECTION_FUNCTIONS
138 EXTRA_SECTION_FUNCTIONS
139 #endif
140
141 /* Tell assembler to switch to text section. */
142
143 void
144 text_section ()
145 {
146 if (in_section != in_text)
147 {
148 if (output_bytecode)
149 bc_text ();
150 else
151 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
152
153 in_section = in_text;
154 }
155 }
156
157 /* Tell assembler to switch to data section. */
158
159 void
160 data_section ()
161 {
162 if (in_section != in_data)
163 {
164 if (output_bytecode)
165 bc_data ();
166 else
167 {
168 if (flag_shared_data)
169 {
170 #ifdef SHARED_SECTION_ASM_OP
171 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
172 #else
173 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
174 #endif
175 }
176 else
177 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
178 }
179
180 in_section = in_data;
181 }
182 }
183
184 /* Tell assembler to switch to read-only data section. This is normally
185 the text section. */
186
187 void
188 readonly_data_section ()
189 {
190 #ifdef READONLY_DATA_SECTION
191 READONLY_DATA_SECTION (); /* Note this can call data_section. */
192 #else
193 text_section ();
194 #endif
195 }
196
197 /* Determine if we're in the text section. */
198
199 int
200 in_text_section ()
201 {
202 return in_section == in_text;
203 }
204
205 /* Tell assembler to change to named section. */
206
207 void
208 named_section (name)
209 char *name;
210 {
211 if (in_section != in_named || strcmp (name, in_named_name))
212 {
213 in_named_name = name;
214 in_section = in_named;
215
216 #ifdef ASM_OUTPUT_SECTION_NAME
217 ASM_OUTPUT_SECTION_NAME (asm_out_file, name);
218 #else
219 /* Section attributes are not supported if this macro isn't provided -
220 some host formats don't support them at all. The front-end should
221 already have flagged this as an error. */
222 abort ();
223 #endif
224 }
225 }
226 \f
227 /* Create the rtl to represent a function, for a function definition.
228 DECL is a FUNCTION_DECL node which describes which function.
229 The rtl is stored into DECL. */
230
231 void
232 make_function_rtl (decl)
233 tree decl;
234 {
235 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
236
237 if (output_bytecode)
238 {
239 if (DECL_RTL (decl) == 0)
240 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
241
242 /* Record that at least one function has been defined. */
243 function_defined = 1;
244 return;
245 }
246
247 /* Rename a nested function to avoid conflicts. */
248 if (decl_function_context (decl) != 0
249 && DECL_INITIAL (decl) != 0
250 && DECL_RTL (decl) == 0)
251 {
252 char *label;
253
254 name = IDENTIFIER_POINTER (DECL_NAME (decl));
255 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
256 name = obstack_copy0 (saveable_obstack, label, strlen (label));
257 var_labelno++;
258 }
259
260 if (DECL_RTL (decl) == 0)
261 {
262 DECL_RTL (decl)
263 = gen_rtx (MEM, DECL_MODE (decl),
264 gen_rtx (SYMBOL_REF, Pmode, name));
265
266 /* Optionally set flags or add text to the name to record information
267 such as that it is a function name. If the name is changed, the macro
268 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
269 #ifdef ENCODE_SECTION_INFO
270 ENCODE_SECTION_INFO (decl);
271 #endif
272 }
273
274 /* Record at least one function has been defined. */
275 function_defined = 1;
276 }
277
278 /* Create the DECL_RTL for a declaration for a static or external
279 variable or static or external function.
280 ASMSPEC, if not 0, is the string which the user specified
281 as the assembler symbol name.
282 TOP_LEVEL is nonzero if this is a file-scope variable.
283 This is never called for PARM_DECLs. */
284 void
285 bc_make_decl_rtl (decl, asmspec, top_level)
286 tree decl;
287 char *asmspec;
288 int top_level;
289 {
290 register char *name = TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl));
291
292 if (DECL_RTL (decl) == 0)
293 {
294 /* Print an error message for register variables. */
295 if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
296 error ("function declared `register'");
297 else if (DECL_REGISTER (decl))
298 error ("global register variables not supported in the interpreter");
299
300 /* Handle ordinary static variables and functions. */
301 if (DECL_RTL (decl) == 0)
302 {
303 /* Can't use just the variable's own name for a variable
304 whose scope is less than the whole file.
305 Concatenate a distinguishing number. */
306 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
307 {
308 char *label;
309
310 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
311 name = obstack_copy0 (saveable_obstack, label, strlen (label));
312 var_labelno++;
313 }
314
315 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
316 }
317 }
318 }
319
320 /* Given NAME, a putative register name, discard any customary prefixes. */
321
322 static char *
323 strip_reg_name (name)
324 char *name;
325 {
326 #ifdef REGISTER_PREFIX
327 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
328 name += strlen (REGISTER_PREFIX);
329 #endif
330 if (name[0] == '%' || name[0] == '#')
331 name++;
332 return name;
333 }
334 \f
335 /* Decode an `asm' spec for a declaration as a register name.
336 Return the register number, or -1 if nothing specified,
337 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
338 or -3 if ASMSPEC is `cc' and is not recognized,
339 or -4 if ASMSPEC is `memory' and is not recognized.
340 Accept an exact spelling or a decimal number.
341 Prefixes such as % are optional. */
342
343 int
344 decode_reg_name (asmspec)
345 char *asmspec;
346 {
347 if (asmspec != 0)
348 {
349 int i;
350
351 /* Get rid of confusing prefixes. */
352 asmspec = strip_reg_name (asmspec);
353
354 /* Allow a decimal number as a "register name". */
355 for (i = strlen (asmspec) - 1; i >= 0; i--)
356 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
357 break;
358 if (asmspec[0] != 0 && i < 0)
359 {
360 i = atoi (asmspec);
361 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
362 return i;
363 else
364 return -2;
365 }
366
367 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
368 if (reg_names[i][0]
369 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
370 return i;
371
372 #ifdef ADDITIONAL_REGISTER_NAMES
373 {
374 static struct { char *name; int number; } table[]
375 = ADDITIONAL_REGISTER_NAMES;
376
377 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
378 if (! strcmp (asmspec, table[i].name))
379 return table[i].number;
380 }
381 #endif /* ADDITIONAL_REGISTER_NAMES */
382
383 if (!strcmp (asmspec, "memory"))
384 return -4;
385
386 if (!strcmp (asmspec, "cc"))
387 return -3;
388
389 return -2;
390 }
391
392 return -1;
393 }
394 \f
395 /* Create the DECL_RTL for a declaration for a static or external variable
396 or static or external function.
397 ASMSPEC, if not 0, is the string which the user specified
398 as the assembler symbol name.
399 TOP_LEVEL is nonzero if this is a file-scope variable.
400
401 This is never called for PARM_DECL nodes. */
402
403 void
404 make_decl_rtl (decl, asmspec, top_level)
405 tree decl;
406 char *asmspec;
407 int top_level;
408 {
409 register char *name = 0;
410 int reg_number;
411
412 if (output_bytecode)
413 {
414 bc_make_decl_rtl (decl, asmspec, top_level);
415 return;
416 }
417
418 reg_number = decode_reg_name (asmspec);
419
420 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
421 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
422
423 if (reg_number == -2)
424 {
425 /* ASMSPEC is given, and not the name of a register. */
426 name = (char *) obstack_alloc (saveable_obstack,
427 strlen (asmspec) + 2);
428 name[0] = '*';
429 strcpy (&name[1], asmspec);
430 }
431
432 /* For a duplicate declaration, we can be called twice on the
433 same DECL node. Don't discard the RTL already made. */
434 if (DECL_RTL (decl) == 0)
435 {
436 DECL_RTL (decl) = 0;
437
438 /* First detect errors in declaring global registers. */
439 if (DECL_REGISTER (decl) && reg_number == -1)
440 error_with_decl (decl,
441 "register name not specified for `%s'");
442 else if (DECL_REGISTER (decl) && reg_number < 0)
443 error_with_decl (decl,
444 "invalid register name for `%s'");
445 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
446 error_with_decl (decl,
447 "register name given for non-register variable `%s'");
448 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
449 error ("function declared `register'");
450 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
451 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
452 else if (DECL_REGISTER (decl)
453 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
454 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
455 /* Now handle properly declared static register variables. */
456 else if (DECL_REGISTER (decl))
457 {
458 int nregs;
459 #if 0 /* yylex should print the warning for this */
460 if (pedantic)
461 pedwarn ("ANSI C forbids global register variables");
462 #endif
463 if (DECL_INITIAL (decl) != 0 && top_level)
464 {
465 DECL_INITIAL (decl) = 0;
466 error ("global register variable has initial value");
467 }
468 if (fixed_regs[reg_number] == 0
469 && function_defined && top_level)
470 error ("global register variable follows a function definition");
471 if (TREE_THIS_VOLATILE (decl))
472 warning ("volatile register variables don't work as you might wish");
473
474 /* If the user specified one of the eliminables registers here,
475 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
476 confused with that register and be eliminated. Although this
477 usage is somewhat suspect, we nevertheless use the following
478 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
479
480 DECL_RTL (decl)
481 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
482 REGNO (DECL_RTL (decl)) = reg_number;
483 REG_USERVAR_P (DECL_RTL (decl)) = 1;
484
485 if (top_level)
486 {
487 /* Make this register global, so not usable for anything
488 else. */
489 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
490 while (nregs > 0)
491 globalize_reg (reg_number + --nregs);
492 }
493 }
494 /* Specifying a section attribute on an uninitialized variable does not
495 (and cannot) cause it to be put in the given section. The linker
496 can only put initialized objects in specific sections, everything
497 else goes in bss for the linker to sort out later (otherwise the
498 linker would give a duplicate definition error for each compilation
499 unit that behaved thusly). So warn the user. */
500 else if (TREE_CODE (decl) == VAR_DECL
501 && DECL_SECTION_NAME (decl) != NULL_TREE
502 && DECL_INITIAL (decl) == NULL_TREE)
503 {
504 warning_with_decl (decl,
505 "section attribute ignored for uninitialized variable `%s'");
506 }
507
508 /* Now handle ordinary static variables and functions (in memory).
509 Also handle vars declared register invalidly. */
510 if (DECL_RTL (decl) == 0)
511 {
512 /* Can't use just the variable's own name for a variable
513 whose scope is less than the whole file.
514 Concatenate a distinguishing number. */
515 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
516 {
517 char *label;
518
519 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
520 name = obstack_copy0 (saveable_obstack, label, strlen (label));
521 var_labelno++;
522 }
523
524 if (name == 0)
525 abort ();
526
527 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
528 gen_rtx (SYMBOL_REF, Pmode, name));
529
530 /* If this variable is to be treated as volatile, show its
531 tree node has side effects. If it has side effects, either
532 because of this test or from TREE_THIS_VOLATILE also
533 being set, show the MEM is volatile. */
534 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
535 && TREE_PUBLIC (decl))
536 TREE_SIDE_EFFECTS (decl) = 1;
537 if (TREE_SIDE_EFFECTS (decl))
538 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
539
540 if (TREE_READONLY (decl))
541 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
542 MEM_IN_STRUCT_P (DECL_RTL (decl))
543 = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
544 || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
545 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE
546 || TREE_CODE (TREE_TYPE (decl)) == QUAL_UNION_TYPE);
547
548 /* Optionally set flags or add text to the name to record information
549 such as that it is a function name.
550 If the name is changed, the macro ASM_OUTPUT_LABELREF
551 will have to know how to strip this information. */
552 #ifdef ENCODE_SECTION_INFO
553 ENCODE_SECTION_INFO (decl);
554 #endif
555 }
556 }
557 /* If the old RTL had the wrong mode, fix the mode. */
558 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
559 {
560 rtx rtl = DECL_RTL (decl);
561 PUT_MODE (rtl, DECL_MODE (decl));
562 }
563 }
564
565 /* Make the rtl for variable VAR be volatile.
566 Use this only for static variables. */
567
568 void
569 make_var_volatile (var)
570 tree var;
571 {
572 if (GET_CODE (DECL_RTL (var)) != MEM)
573 abort ();
574
575 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
576 }
577 \f
578 /* Output alignment directive to align for constant expression EXP. */
579
580 void
581 assemble_constant_align (exp)
582 tree exp;
583 {
584 int align;
585
586 /* Align the location counter as required by EXP's data type. */
587 align = TYPE_ALIGN (TREE_TYPE (exp));
588 #ifdef CONSTANT_ALIGNMENT
589 align = CONSTANT_ALIGNMENT (exp, align);
590 #endif
591
592 if (align > BITS_PER_UNIT)
593 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
594 }
595
596 /* Output a string of literal assembler code
597 for an `asm' keyword used between functions. */
598
599 void
600 assemble_asm (string)
601 tree string;
602 {
603 if (output_bytecode)
604 {
605 error ("asm statements not allowed in interpreter");
606 return;
607 }
608
609 app_enable ();
610
611 if (TREE_CODE (string) == ADDR_EXPR)
612 string = TREE_OPERAND (string, 0);
613
614 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
615 }
616
617 #if 0 /* This should no longer be needed, because
618 flag_gnu_linker should be 0 on these systems,
619 which should prevent any output
620 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
621 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
622 #ifndef ASM_OUTPUT_CONSTRUCTOR
623 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
624 #endif
625 #ifndef ASM_OUTPUT_DESTRUCTOR
626 #define ASM_OUTPUT_DESTRUCTOR(file, name)
627 #endif
628 #endif
629 #endif /* 0 */
630
631 /* Record an element in the table of global destructors.
632 How this is done depends on what sort of assembler and linker
633 are in use.
634
635 NAME should be the name of a global function to be called
636 at exit time. This name is output using assemble_name. */
637
638 void
639 assemble_destructor (name)
640 char *name;
641 {
642 #ifdef ASM_OUTPUT_DESTRUCTOR
643 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
644 #else
645 if (flag_gnu_linker)
646 {
647 /* Now tell GNU LD that this is part of the static destructor set. */
648 /* This code works for any machine provided you use GNU as/ld. */
649 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
650 assemble_name (asm_out_file, name);
651 fputc ('\n', asm_out_file);
652 }
653 #endif
654 }
655
656 /* Likewise for global constructors. */
657
658 void
659 assemble_constructor (name)
660 char *name;
661 {
662 #ifdef ASM_OUTPUT_CONSTRUCTOR
663 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
664 #else
665 if (flag_gnu_linker)
666 {
667 /* Now tell GNU LD that this is part of the static constructor set. */
668 /* This code works for any machine provided you use GNU as/ld. */
669 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
670 assemble_name (asm_out_file, name);
671 fputc ('\n', asm_out_file);
672 }
673 #endif
674 }
675
676 /* Likewise for entries we want to record for garbage collection.
677 Garbage collection is still under development. */
678
679 void
680 assemble_gc_entry (name)
681 char *name;
682 {
683 #ifdef ASM_OUTPUT_GC_ENTRY
684 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
685 #else
686 if (flag_gnu_linker)
687 {
688 /* Now tell GNU LD that this is part of the static constructor set. */
689 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
690 assemble_name (asm_out_file, name);
691 fputc ('\n', asm_out_file);
692 }
693 #endif
694 }
695 \f
696 /* Output assembler code for the constant pool of a function and associated
697 with defining the name of the function. DECL describes the function.
698 NAME is the function's name. For the constant pool, we use the current
699 constant pool data. */
700
701 void
702 assemble_start_function (decl, fnname)
703 tree decl;
704 char *fnname;
705 {
706 int align;
707
708 /* The following code does not need preprocessing in the assembler. */
709
710 app_disable ();
711
712 output_constant_pool (fnname, decl);
713
714 if (IN_NAMED_SECTION (decl))
715 named_section (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)));
716 else
717 text_section ();
718
719 /* Tell assembler to move to target machine's alignment for functions. */
720 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
721 if (align > 0)
722 {
723 if (output_bytecode)
724 BC_OUTPUT_ALIGN (asm_out_file, align);
725 else
726 ASM_OUTPUT_ALIGN (asm_out_file, align);
727 }
728
729 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
730 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
731 #endif
732
733 #ifdef SDB_DEBUGGING_INFO
734 /* Output SDB definition of the function. */
735 if (write_symbols == SDB_DEBUG)
736 sdbout_mark_begin_function ();
737 #endif
738
739 #ifdef DBX_DEBUGGING_INFO
740 /* Output DBX definition of the function. */
741 if (write_symbols == DBX_DEBUG)
742 dbxout_begin_function (decl);
743 #endif
744
745 /* Make function name accessible from other files, if appropriate. */
746
747 if (TREE_PUBLIC (decl))
748 {
749 if (!first_global_object_name)
750 STRIP_NAME_ENCODING (first_global_object_name, fnname);
751 if (output_bytecode)
752 BC_GLOBALIZE_LABEL (asm_out_file, fnname);
753 else
754 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
755 }
756
757 /* Do any machine/system dependent processing of the function name */
758 #ifdef ASM_DECLARE_FUNCTION_NAME
759 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
760 #else
761 /* Standard thing is just output label for the function. */
762 if (output_bytecode)
763 BC_OUTPUT_LABEL (asm_out_file, fnname);
764 else
765 ASM_OUTPUT_LABEL (asm_out_file, fnname);
766 #endif /* ASM_DECLARE_FUNCTION_NAME */
767 }
768
769 /* Output assembler code associated with defining the size of the
770 function. DECL describes the function. NAME is the function's name. */
771
772 void
773 assemble_end_function (decl, fnname)
774 tree decl;
775 char *fnname;
776 {
777 #ifdef ASM_DECLARE_FUNCTION_SIZE
778 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
779 #endif
780 }
781 \f
782 /* Assemble code to leave SIZE bytes of zeros. */
783
784 void
785 assemble_zeros (size)
786 int size;
787 {
788 if (output_bytecode)
789 {
790 bc_emit_const_skip (size);
791 return;
792 }
793
794 #ifdef ASM_NO_SKIP_IN_TEXT
795 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
796 so we must output 0s explicitly in the text section. */
797 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
798 {
799 int i;
800
801 for (i = 0; i < size - 20; i += 20)
802 {
803 #ifdef ASM_BYTE_OP
804 fprintf (asm_out_file,
805 "%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);
806 #else
807 fprintf (asm_out_file,
808 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
809 #endif
810 }
811 if (i < size)
812 {
813 #ifdef ASM_BYTE_OP
814 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
815 #else
816 fprintf (asm_out_file, "\tbyte 0");
817 #endif
818 i++;
819 for (; i < size; i++)
820 fprintf (asm_out_file, ",0");
821 fprintf (asm_out_file, "\n");
822 }
823 }
824 else
825 #endif
826 if (size > 0)
827 {
828 if (output_bytecode)
829 BC_OUTPUT_SKIP (asm_out_file, size);
830 else
831 ASM_OUTPUT_SKIP (asm_out_file, size);
832 }
833 }
834
835 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
836
837 void
838 assemble_align (align)
839 int align;
840 {
841 if (align > BITS_PER_UNIT)
842 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
843 }
844
845 /* Assemble a string constant with the specified C string as contents. */
846
847 void
848 assemble_string (p, size)
849 char *p;
850 int size;
851 {
852 register int i;
853 int pos = 0;
854 int maximum = 2000;
855
856 if (output_bytecode)
857 {
858 bc_emit (p, size);
859 return;
860 }
861
862 /* If the string is very long, split it up. */
863
864 while (pos < size)
865 {
866 int thissize = size - pos;
867 if (thissize > maximum)
868 thissize = maximum;
869
870 if (output_bytecode)
871 bc_output_ascii (asm_out_file, p, thissize);
872 else
873 {
874 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
875 }
876
877 pos += thissize;
878 p += thissize;
879 }
880 }
881
882 static void
883 bc_output_ascii (file, p, size)
884 FILE *file;
885 char *p;
886 int size;
887 {
888 BC_OUTPUT_ASCII (file, p, size);
889 }
890 \f
891 /* Assemble everything that is needed for a variable or function declaration.
892 Not used for automatic variables, and not used for function definitions.
893 Should not be called for variables of incomplete structure type.
894
895 TOP_LEVEL is nonzero if this variable has file scope.
896 AT_END is nonzero if this is the special handling, at end of compilation,
897 to define things that have had only tentative definitions.
898 DONT_OUTPUT_DATA if nonzero means don't actually output the
899 initial value (that will be done by the caller). */
900
901 void
902 assemble_variable (decl, top_level, at_end, dont_output_data)
903 tree decl;
904 int top_level;
905 int at_end;
906 {
907 register char *name;
908 int align;
909 tree size_tree;
910 int reloc = 0;
911 enum in_section saved_in_section;
912
913 last_assemble_variable_decl = 0;
914
915 if (output_bytecode)
916 return;
917
918 if (GET_CODE (DECL_RTL (decl)) == REG)
919 {
920 /* Do output symbol info for global register variables, but do nothing
921 else for them. */
922
923 if (TREE_ASM_WRITTEN (decl))
924 return;
925 TREE_ASM_WRITTEN (decl) = 1;
926
927 if (!output_bytecode)
928 {
929 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
930 /* File-scope global variables are output here. */
931 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
932 && top_level)
933 dbxout_symbol (decl, 0);
934 #endif
935 #ifdef SDB_DEBUGGING_INFO
936 if (write_symbols == SDB_DEBUG && top_level
937 /* Leave initialized global vars for end of compilation;
938 see comment in compile_file. */
939 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
940 sdbout_symbol (decl, 0);
941 #endif
942 }
943
944 /* Don't output any DWARF debugging information for variables here.
945 In the case of local variables, the information for them is output
946 when we do our recursive traversal of the tree representation for
947 the entire containing function. In the case of file-scope variables,
948 we output information for all of them at the very end of compilation
949 while we are doing our final traversal of the chain of file-scope
950 declarations. */
951
952 return;
953 }
954
955 /* Normally no need to say anything here for external references,
956 since assemble_external is called by the langauge-specific code
957 when a declaration is first seen. */
958
959 if (DECL_EXTERNAL (decl))
960 return;
961
962 /* Output no assembler code for a function declaration.
963 Only definitions of functions output anything. */
964
965 if (TREE_CODE (decl) == FUNCTION_DECL)
966 return;
967
968 /* If type was incomplete when the variable was declared,
969 see if it is complete now. */
970
971 if (DECL_SIZE (decl) == 0)
972 layout_decl (decl, 0);
973
974 /* Still incomplete => don't allocate it; treat the tentative defn
975 (which is what it must have been) as an `extern' reference. */
976
977 if (!dont_output_data && DECL_SIZE (decl) == 0)
978 {
979 error_with_file_and_line (DECL_SOURCE_FILE (decl),
980 DECL_SOURCE_LINE (decl),
981 "storage size of `%s' isn't known",
982 IDENTIFIER_POINTER (DECL_NAME (decl)));
983 return;
984 }
985
986 /* The first declaration of a variable that comes through this function
987 decides whether it is global (in C, has external linkage)
988 or local (in C, has internal linkage). So do nothing more
989 if this function has already run. */
990
991 if (TREE_ASM_WRITTEN (decl))
992 return;
993
994 TREE_ASM_WRITTEN (decl) = 1;
995
996 /* If storage size is erroneously variable, just continue.
997 Error message was already made. */
998
999 if (DECL_SIZE (decl))
1000 {
1001 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1002 goto finish;
1003
1004 app_disable ();
1005
1006 /* This is better than explicit arithmetic, since it avoids overflow. */
1007 size_tree = size_binop (CEIL_DIV_EXPR,
1008 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1009
1010 if (TREE_INT_CST_HIGH (size_tree) != 0)
1011 {
1012 error_with_decl (decl, "size of variable `%s' is too large");
1013 goto finish;
1014 }
1015 }
1016
1017 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1018
1019 /* Handle uninitialized definitions. */
1020
1021 /* ANSI specifies that a tentative definition which is not merged with
1022 a non-tentative definition behaves exactly like a definition with an
1023 initializer equal to zero. (Section 3.7.2)
1024 -fno-common gives strict ANSI behavior. Usually you don't want it.
1025 This matters only for variables with external linkage. */
1026 if ((! flag_no_common || ! TREE_PUBLIC (decl))
1027 && DECL_COMMON (decl)
1028 && ! dont_output_data
1029 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
1030 {
1031 int size = TREE_INT_CST_LOW (size_tree);
1032 int rounded = size;
1033
1034 if (TREE_INT_CST_HIGH (size_tree) != 0)
1035 error_with_decl (decl, "size of variable `%s' is too large");
1036 /* Don't allocate zero bytes of common,
1037 since that means "undefined external" in the linker. */
1038 if (size == 0) rounded = 1;
1039 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1040 so that each uninitialized object starts on such a boundary. */
1041 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1042 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1043 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1044
1045 #ifdef DBX_DEBUGGING_INFO
1046 /* File-scope global variables are output here. */
1047 if (write_symbols == DBX_DEBUG && top_level)
1048 dbxout_symbol (decl, 0);
1049 #endif
1050 #ifdef SDB_DEBUGGING_INFO
1051 if (write_symbols == SDB_DEBUG && top_level
1052 /* Leave initialized global vars for end of compilation;
1053 see comment in compile_file. */
1054 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1055 sdbout_symbol (decl, 0);
1056 #endif
1057
1058 /* Don't output any DWARF debugging information for variables here.
1059 In the case of local variables, the information for them is output
1060 when we do our recursive traversal of the tree representation for
1061 the entire containing function. In the case of file-scope variables,
1062 we output information for all of them at the very end of compilation
1063 while we are doing our final traversal of the chain of file-scope
1064 declarations. */
1065
1066 #if 0
1067 if (flag_shared_data)
1068 data_section ();
1069 #endif
1070 if (TREE_PUBLIC (decl))
1071 {
1072 #ifdef ASM_OUTPUT_SHARED_COMMON
1073 if (flag_shared_data)
1074 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1075 else
1076 #endif
1077 if (output_bytecode)
1078 {
1079 BC_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1080 }
1081 else
1082 {
1083 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1084 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1085 DECL_ALIGN (decl));
1086 #else
1087 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1088 #endif
1089 }
1090 }
1091 else
1092 {
1093 #ifdef ASM_OUTPUT_SHARED_LOCAL
1094 if (flag_shared_data)
1095 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1096 else
1097 #endif
1098 if (output_bytecode)
1099 {
1100 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1101 }
1102 else
1103 {
1104 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1105 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1106 DECL_ALIGN (decl));
1107 #else
1108 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1109 #endif
1110 }
1111 }
1112 goto finish;
1113 }
1114
1115 /* Handle initialized definitions. */
1116
1117 /* First make the assembler name(s) global if appropriate. */
1118 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1119 {
1120 if (!first_global_object_name)
1121 STRIP_NAME_ENCODING(first_global_object_name, name);
1122 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1123 }
1124 #if 0
1125 for (d = equivalents; d; d = TREE_CHAIN (d))
1126 {
1127 tree e = TREE_VALUE (d);
1128 if (TREE_PUBLIC (e) && DECL_NAME (e))
1129 ASM_GLOBALIZE_LABEL (asm_out_file,
1130 XSTR (XEXP (DECL_RTL (e), 0), 0));
1131 }
1132 #endif
1133
1134 /* Output any data that we will need to use the address of. */
1135 if (DECL_INITIAL (decl) == error_mark_node)
1136 reloc = contains_pointers_p (TREE_TYPE (decl));
1137 else if (DECL_INITIAL (decl))
1138 reloc = output_addressed_constants (DECL_INITIAL (decl));
1139
1140 /* Switch to the proper section for this data. */
1141 if (IN_NAMED_SECTION (decl))
1142 named_section (TREE_STRING_POINTER (DECL_SECTION_NAME (decl)));
1143 else
1144 {
1145 /* C++ can have const variables that get initialized from constructors,
1146 and thus can not be in a readonly section. We prevent this by
1147 verifying that the initial value is constant for objects put in a
1148 readonly section.
1149
1150 error_mark_node is used by the C front end to indicate that the
1151 initializer has not been seen yet. In this case, we assume that
1152 the initializer must be constant. */
1153 #ifdef SELECT_SECTION
1154 SELECT_SECTION (decl, reloc);
1155 #else
1156 if (TREE_READONLY (decl)
1157 && ! TREE_THIS_VOLATILE (decl)
1158 && DECL_INITIAL (decl)
1159 && (DECL_INITIAL (decl) == error_mark_node
1160 || TREE_CONSTANT (DECL_INITIAL (decl)))
1161 && ! (flag_pic && reloc))
1162 readonly_data_section ();
1163 else
1164 data_section ();
1165 #endif
1166 }
1167
1168 /* dbxout.c needs to know this. */
1169 if (in_text_section ())
1170 DECL_IN_TEXT_SECTION (decl) = 1;
1171
1172 /* Record current section so we can restore it if dbxout.c clobbers it. */
1173 saved_in_section = in_section;
1174
1175 /* Output the dbx info now that we have chosen the section. */
1176
1177 #ifdef DBX_DEBUGGING_INFO
1178 /* File-scope global variables are output here. */
1179 if (write_symbols == DBX_DEBUG && top_level)
1180 dbxout_symbol (decl, 0);
1181 #endif
1182 #ifdef SDB_DEBUGGING_INFO
1183 if (write_symbols == SDB_DEBUG && top_level
1184 /* Leave initialized global vars for end of compilation;
1185 see comment in compile_file. */
1186 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1187 sdbout_symbol (decl, 0);
1188 #endif
1189
1190 /* Don't output any DWARF debugging information for variables here.
1191 In the case of local variables, the information for them is output
1192 when we do our recursive traversal of the tree representation for
1193 the entire containing function. In the case of file-scope variables,
1194 we output information for all of them at the very end of compilation
1195 while we are doing our final traversal of the chain of file-scope
1196 declarations. */
1197
1198 /* If the debugging output changed sections, reselect the section
1199 that's supposed to be selected. */
1200 if (in_section != saved_in_section)
1201 {
1202 /* Switch to the proper section for this data. */
1203 #ifdef SELECT_SECTION
1204 SELECT_SECTION (decl, reloc);
1205 #else
1206 if (TREE_READONLY (decl)
1207 && ! TREE_THIS_VOLATILE (decl)
1208 && DECL_INITIAL (decl)
1209 && (DECL_INITIAL (decl) == error_mark_node
1210 || TREE_CONSTANT (DECL_INITIAL (decl)))
1211 && ! (flag_pic && reloc))
1212 readonly_data_section ();
1213 else
1214 data_section ();
1215 #endif
1216 }
1217
1218 /* Compute and output the alignment of this data. */
1219
1220 align = DECL_ALIGN (decl);
1221 /* In the case for initialing an array whose length isn't specified,
1222 where we have not yet been able to do the layout,
1223 figure out the proper alignment now. */
1224 if (dont_output_data && DECL_SIZE (decl) == 0
1225 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1226 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1227
1228 /* Some object file formats have a maximum alignment which they support.
1229 In particular, a.out format supports a maximum alignment of 4. */
1230 #ifndef MAX_OFILE_ALIGNMENT
1231 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1232 #endif
1233 if (align > MAX_OFILE_ALIGNMENT)
1234 {
1235 warning_with_decl (decl,
1236 "alignment of `%s' is greater than maximum object file alignment");
1237 align = MAX_OFILE_ALIGNMENT;
1238 }
1239 #ifdef DATA_ALIGNMENT
1240 /* On some machines, it is good to increase alignment sometimes. */
1241 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1242 #endif
1243 #ifdef CONSTANT_ALIGNMENT
1244 if (DECL_INITIAL (decl))
1245 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1246 #endif
1247
1248 /* Reset the alignment in case we have made it tighter, so we can benefit
1249 from it in get_pointer_alignment. */
1250 DECL_ALIGN (decl) = align;
1251
1252 if (align > BITS_PER_UNIT)
1253 {
1254 if (output_bytecode)
1255 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1256 else
1257 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1258 }
1259
1260 /* Do any machine/system dependent processing of the object. */
1261 #ifdef ASM_DECLARE_OBJECT_NAME
1262 last_assemble_variable_decl = decl;
1263 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1264 #else
1265 /* Standard thing is just output label for the object. */
1266 if (output_bytecode)
1267 BC_OUTPUT_LABEL (asm_out_file, name);
1268 else
1269 ASM_OUTPUT_LABEL (asm_out_file, name);
1270 #endif /* ASM_DECLARE_OBJECT_NAME */
1271
1272 if (!dont_output_data)
1273 {
1274 if (DECL_INITIAL (decl))
1275 /* Output the actual data. */
1276 output_constant (DECL_INITIAL (decl),
1277 int_size_in_bytes (TREE_TYPE (decl)));
1278 else
1279 /* Leave space for it. */
1280 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1281 }
1282
1283 finish:
1284 #ifdef XCOFF_DEBUGGING_INFO
1285 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1286 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1287 and `aa' hasn't been output yet, the assembler generates a stab entry with
1288 a value of zero, in addition to creating an unnecessary external entry
1289 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1290
1291 /* File-scope global variables are output here. */
1292 if (write_symbols == XCOFF_DEBUG && top_level)
1293 {
1294 saved_in_section = in_section;
1295
1296 dbxout_symbol (decl, 0);
1297
1298 if (in_section != saved_in_section)
1299 {
1300 /* Switch to the proper section for this data. */
1301 #ifdef SELECT_SECTION
1302 SELECT_SECTION (decl, reloc);
1303 #else
1304 if (TREE_READONLY (decl)
1305 && ! TREE_THIS_VOLATILE (decl)
1306 && DECL_INITIAL (decl)
1307 && (DECL_INITIAL (decl) == error_mark_node
1308 || TREE_CONSTANT (DECL_INITIAL (decl)))
1309 && ! (flag_pic && reloc))
1310 readonly_data_section ();
1311 else
1312 data_section ();
1313 #endif
1314 }
1315 }
1316 #else
1317 /* There must be a statement after a label. */
1318 ;
1319 #endif
1320 }
1321
1322 /* Return 1 if type TYPE contains any pointers. */
1323
1324 static int
1325 contains_pointers_p (type)
1326 tree type;
1327 {
1328 switch (TREE_CODE (type))
1329 {
1330 case POINTER_TYPE:
1331 case REFERENCE_TYPE:
1332 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1333 so I'll play safe and return 1. */
1334 case OFFSET_TYPE:
1335 return 1;
1336
1337 case RECORD_TYPE:
1338 case UNION_TYPE:
1339 case QUAL_UNION_TYPE:
1340 {
1341 tree fields;
1342 /* For a type that has fields, see if the fields have pointers. */
1343 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1344 if (TREE_CODE (fields) == FIELD_DECL
1345 && contains_pointers_p (TREE_TYPE (fields)))
1346 return 1;
1347 return 0;
1348 }
1349
1350 case ARRAY_TYPE:
1351 /* An array type contains pointers if its element type does. */
1352 return contains_pointers_p (TREE_TYPE (type));
1353
1354 default:
1355 return 0;
1356 }
1357 }
1358
1359 /* Output text storage for constructor CONSTR. Returns rtx of
1360 storage. */
1361
1362 rtx
1363 bc_output_constructor (constr)
1364 tree constr;
1365 {
1366 int i;
1367
1368 /* Must always be a literal; non-literal constructors are handled
1369 differently. */
1370
1371 if (!TREE_CONSTANT (constr))
1372 abort ();
1373
1374 /* Always const */
1375 text_section ();
1376
1377 /* Align */
1378 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1379 if (i > 0)
1380 BC_OUTPUT_ALIGN (asm_out_file, i);
1381
1382 /* Output data */
1383 output_constant (constr, int_size_in_bytes (TREE_TYPE (constr)));
1384 }
1385
1386
1387 /* Create storage for constructor CONSTR. */
1388
1389 void
1390 bc_output_data_constructor (constr)
1391 tree constr;
1392 {
1393 int i;
1394
1395 /* Put in data section */
1396 data_section ();
1397
1398 /* Align */
1399 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1400 if (i > 0)
1401 BC_OUTPUT_ALIGN (asm_out_file, i);
1402
1403 /* The constructor is filled in at runtime. */
1404 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1405 }
1406
1407
1408 /* Output something to declare an external symbol to the assembler.
1409 (Most assemblers don't need this, so we normally output nothing.)
1410 Do nothing if DECL is not external. */
1411
1412 void
1413 assemble_external (decl)
1414 tree decl;
1415 {
1416 if (output_bytecode)
1417 return;
1418
1419 #ifdef ASM_OUTPUT_EXTERNAL
1420 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1421 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1422 {
1423 rtx rtl = DECL_RTL (decl);
1424
1425 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1426 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1427 {
1428 /* Some systems do require some output. */
1429 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1430 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1431 }
1432 }
1433 #endif
1434 }
1435
1436 /* Similar, for calling a library function FUN. */
1437
1438 void
1439 assemble_external_libcall (fun)
1440 rtx fun;
1441 {
1442 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1443 if (!output_bytecode)
1444 {
1445 /* Declare library function name external when first used, if nec. */
1446 if (! SYMBOL_REF_USED (fun))
1447 {
1448 SYMBOL_REF_USED (fun) = 1;
1449 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1450 }
1451 }
1452 #endif
1453 }
1454
1455 /* Declare the label NAME global. */
1456
1457 void
1458 assemble_global (name)
1459 char *name;
1460 {
1461 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1462 }
1463
1464 /* Assemble a label named NAME. */
1465
1466 void
1467 assemble_label (name)
1468 char *name;
1469 {
1470 if (output_bytecode)
1471 BC_OUTPUT_LABEL (asm_out_file, name);
1472 else
1473 ASM_OUTPUT_LABEL (asm_out_file, name);
1474 }
1475
1476 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1477 If NAME starts with a *, the rest of NAME is output verbatim.
1478 Otherwise NAME is transformed in an implementation-defined way
1479 (usually by the addition of an underscore).
1480 Many macros in the tm file are defined to call this function. */
1481
1482 void
1483 assemble_name (file, name)
1484 FILE *file;
1485 char *name;
1486 {
1487 if (name[0] == '*')
1488 {
1489 if (output_bytecode)
1490 bc_emit_labelref (name);
1491 else
1492 fputs (&name[1], file);
1493 }
1494 else
1495 {
1496 if (output_bytecode)
1497 BC_OUTPUT_LABELREF (file, name);
1498 else
1499 ASM_OUTPUT_LABELREF (file, name);
1500 }
1501 }
1502
1503 /* Allocate SIZE bytes writable static space with a gensym name
1504 and return an RTX to refer to its address. */
1505
1506 rtx
1507 assemble_static_space (size)
1508 int size;
1509 {
1510 char name[12];
1511 char *namestring;
1512 rtx x;
1513 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1514 so that each uninitialized object starts on such a boundary. */
1515 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1516 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1517 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1518
1519 #if 0
1520 if (flag_shared_data)
1521 data_section ();
1522 #endif
1523
1524 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1525 ++const_labelno;
1526
1527 namestring = (char *) obstack_alloc (saveable_obstack,
1528 strlen (name) + 2);
1529 strcpy (namestring, name);
1530
1531 if (output_bytecode)
1532 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1533 else
1534 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1535
1536 if (output_bytecode)
1537 {
1538 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1539 }
1540 else
1541 {
1542 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1543 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1544 #else
1545 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1546 #endif
1547 }
1548 return x;
1549 }
1550
1551 /* Assemble the static constant template for function entry trampolines.
1552 This is done at most once per compilation.
1553 Returns an RTX for the address of the template. */
1554
1555 rtx
1556 assemble_trampoline_template ()
1557 {
1558 char label[256];
1559 char *name;
1560 int align;
1561
1562 /* Shouldn't get here */
1563 if (output_bytecode)
1564 abort ();
1565
1566 /* By default, put trampoline templates in read-only data section. */
1567
1568 #ifdef TRAMPOLINE_SECTION
1569 TRAMPOLINE_SECTION ();
1570 #else
1571 readonly_data_section ();
1572 #endif
1573
1574 /* Write the assembler code to define one. */
1575 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1576 if (align > 0)
1577 ASM_OUTPUT_ALIGN (asm_out_file, align);
1578
1579 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1580 TRAMPOLINE_TEMPLATE (asm_out_file);
1581
1582 /* Record the rtl to refer to it. */
1583 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1584 name
1585 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1586 return gen_rtx (SYMBOL_REF, Pmode, name);
1587 }
1588 \f
1589 /* Assemble the integer constant X into an object of SIZE bytes.
1590 X must be either a CONST_INT or CONST_DOUBLE.
1591
1592 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1593 non-zero, abort if we can't output the constant. */
1594
1595 int
1596 assemble_integer (x, size, force)
1597 rtx x;
1598 int size;
1599 int force;
1600 {
1601 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1602 ASM_OUTPUT... macros. */
1603
1604 switch (size)
1605 {
1606 #ifdef ASM_OUTPUT_CHAR
1607 case 1:
1608 ASM_OUTPUT_CHAR (asm_out_file, x);
1609 return 1;
1610 #endif
1611
1612 #ifdef ASM_OUTPUT_SHORT
1613 case 2:
1614 ASM_OUTPUT_SHORT (asm_out_file, x);
1615 return 1;
1616 #endif
1617
1618 #ifdef ASM_OUTPUT_INT
1619 case 4:
1620 ASM_OUTPUT_INT (asm_out_file, x);
1621 return 1;
1622 #endif
1623
1624 #ifdef ASM_OUTPUT_DOUBLE_INT
1625 case 8:
1626 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1627 return 1;
1628 #endif
1629
1630 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1631 case 16:
1632 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1633 return 1;
1634 #endif
1635 }
1636
1637 /* If we couldn't do it that way, there are two other possibilities: First,
1638 if the machine can output an explicit byte and this is a 1 byte constant,
1639 we can use ASM_OUTPUT_BYTE. */
1640
1641 #ifdef ASM_OUTPUT_BYTE
1642 if (size == 1 && GET_CODE (x) == CONST_INT)
1643 {
1644 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1645 return 1;
1646 }
1647 #endif
1648
1649 /* Finally, if SIZE is larger than a single word, try to output the constant
1650 one word at a time. */
1651
1652 if (size > UNITS_PER_WORD)
1653 {
1654 int i;
1655 enum machine_mode mode
1656 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1657 rtx word;
1658
1659 for (i = 0; i < size / UNITS_PER_WORD; i++)
1660 {
1661 word = operand_subword (x, i, 0, mode);
1662
1663 if (word == 0)
1664 break;
1665
1666 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1667 break;
1668 }
1669
1670 if (i == size / UNITS_PER_WORD)
1671 return 1;
1672 /* If we output at least one word and then could not finish,
1673 there is no valid way to continue. */
1674 if (i > 0)
1675 abort ();
1676 }
1677
1678 if (force)
1679 abort ();
1680
1681 return 0;
1682 }
1683 \f
1684 /* Assemble the floating-point constant D into an object of size MODE. */
1685
1686 void
1687 assemble_real (d, mode)
1688 REAL_VALUE_TYPE d;
1689 enum machine_mode mode;
1690 {
1691 jmp_buf output_constant_handler;
1692
1693 if (setjmp (output_constant_handler))
1694 {
1695 error ("floating point trap outputting a constant");
1696 #ifdef REAL_IS_NOT_DOUBLE
1697 bzero (&d, sizeof d);
1698 d = dconst0;
1699 #else
1700 d = 0;
1701 #endif
1702 }
1703
1704 set_float_handler (output_constant_handler);
1705
1706 switch (mode)
1707 {
1708 #ifdef ASM_OUTPUT_BYTE_FLOAT
1709 case QFmode:
1710 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1711 break;
1712 #endif
1713 #ifdef ASM_OUTPUT_SHORT_FLOAT
1714 case HFmode:
1715 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1716 break;
1717 #endif
1718 #ifdef ASM_OUTPUT_FLOAT
1719 case SFmode:
1720 ASM_OUTPUT_FLOAT (asm_out_file, d);
1721 break;
1722 #endif
1723
1724 #ifdef ASM_OUTPUT_DOUBLE
1725 case DFmode:
1726 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1727 break;
1728 #endif
1729
1730 #ifdef ASM_OUTPUT_LONG_DOUBLE
1731 case XFmode:
1732 case TFmode:
1733 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1734 break;
1735 #endif
1736
1737 default:
1738 abort ();
1739 }
1740
1741 set_float_handler (NULL_PTR);
1742 }
1743 \f
1744 /* Here we combine duplicate floating constants to make
1745 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1746
1747 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1748 They are chained through the CONST_DOUBLE_CHAIN.
1749 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1750 In that case, CONST_DOUBLE_MEM is either a MEM,
1751 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1752
1753 (CONST_DOUBLE_MEM is used only for top-level functions.
1754 See force_const_mem for explanation.) */
1755
1756 static rtx const_double_chain;
1757
1758 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1759 For an integer, I0 is the low-order word and I1 is the high-order word.
1760 For a real number, I0 is the word with the low address
1761 and I1 is the word with the high address. */
1762
1763 rtx
1764 immed_double_const (i0, i1, mode)
1765 HOST_WIDE_INT i0, i1;
1766 enum machine_mode mode;
1767 {
1768 register rtx r;
1769 int in_current_obstack;
1770
1771 if (GET_MODE_CLASS (mode) == MODE_INT
1772 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1773 {
1774 /* We clear out all bits that don't belong in MODE, unless they and our
1775 sign bit are all one. So we get either a reasonable negative value
1776 or a reasonable unsigned value for this mode. */
1777 int width = GET_MODE_BITSIZE (mode);
1778 if (width < HOST_BITS_PER_WIDE_INT
1779 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1780 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1781 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1782 else if (width == HOST_BITS_PER_WIDE_INT
1783 && ! (i1 == ~0 && i0 < 0))
1784 i1 = 0;
1785 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1786 /* We cannot represent this value as a constant. */
1787 abort ();
1788
1789 /* If this would be an entire word for the target, but is not for
1790 the host, then sign-extend on the host so that the number will look
1791 the same way on the host that it would on the target.
1792
1793 For example, when building a 64 bit alpha hosted 32 bit sparc
1794 targeted compiler, then we want the 32 bit unsigned value -1 to be
1795 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1796 The later confuses the sparc backend. */
1797
1798 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1799 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1800 i0 |= ((HOST_WIDE_INT) (-1) << width);
1801
1802 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1803
1804 ??? Strictly speaking, this is wrong if we create a CONST_INT
1805 for a large unsigned constant with the size of MODE being
1806 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1807 wider mode. In that case we will mis-interpret it as a negative
1808 number.
1809
1810 Unfortunately, the only alternative is to make a CONST_DOUBLE
1811 for any constant in any mode if it is an unsigned constant larger
1812 than the maximum signed integer in an int on the host. However,
1813 doing this will break everyone that always expects to see a CONST_INT
1814 for SImode and smaller.
1815
1816 We have always been making CONST_INTs in this case, so nothing new
1817 is being broken. */
1818
1819 if (width <= HOST_BITS_PER_WIDE_INT)
1820 i1 = (i0 < 0) ? ~0 : 0;
1821
1822 /* If this integer fits in one word, return a CONST_INT. */
1823 if ((i1 == 0 && i0 >= 0)
1824 || (i1 == ~0 && i0 < 0))
1825 return GEN_INT (i0);
1826
1827 /* We use VOIDmode for integers. */
1828 mode = VOIDmode;
1829 }
1830
1831 /* Search the chain for an existing CONST_DOUBLE with the right value.
1832 If one is found, return it. */
1833
1834 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1835 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1836 && GET_MODE (r) == mode)
1837 return r;
1838
1839 /* No; make a new one and add it to the chain.
1840
1841 We may be called by an optimizer which may be discarding any memory
1842 allocated during its processing (such as combine and loop). However,
1843 we will be leaving this constant on the chain, so we cannot tolerate
1844 freed memory. So switch to saveable_obstack for this allocation
1845 and then switch back if we were in current_obstack. */
1846
1847 push_obstacks_nochange ();
1848 rtl_in_saveable_obstack ();
1849 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1850 pop_obstacks ();
1851
1852 /* Don't touch const_double_chain in nested function; see force_const_mem.
1853 Also, don't touch it if not inside any function. */
1854 if (outer_function_chain == 0 && current_function_decl != 0)
1855 {
1856 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1857 const_double_chain = r;
1858 }
1859
1860 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1861 Actual use of mem-slot is only through force_const_mem. */
1862
1863 CONST_DOUBLE_MEM (r) = const0_rtx;
1864
1865 return r;
1866 }
1867
1868 /* Return a CONST_DOUBLE for a specified `double' value
1869 and machine mode. */
1870
1871 rtx
1872 immed_real_const_1 (d, mode)
1873 REAL_VALUE_TYPE d;
1874 enum machine_mode mode;
1875 {
1876 union real_extract u;
1877 register rtx r;
1878 int in_current_obstack;
1879
1880 /* Get the desired `double' value as a sequence of ints
1881 since that is how they are stored in a CONST_DOUBLE. */
1882
1883 u.d = d;
1884
1885 /* Detect special cases. */
1886
1887 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1888 if (!bcmp (&dconst0, &d, sizeof d))
1889 return CONST0_RTX (mode);
1890 /* Check for NaN first, because some ports (specifically the i386) do not
1891 emit correct ieee-fp code by default, and thus will generate a core
1892 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1893 does a floating point comparison. */
1894 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1895 return CONST1_RTX (mode);
1896
1897 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1898 return immed_double_const (u.i[0], u.i[1], mode);
1899
1900 /* The rest of this function handles the case where
1901 a float value requires more than 2 ints of space.
1902 It will be deleted as dead code on machines that don't need it. */
1903
1904 /* Search the chain for an existing CONST_DOUBLE with the right value.
1905 If one is found, return it. */
1906
1907 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1908 if (! bcmp (&CONST_DOUBLE_LOW (r), &u, sizeof u)
1909 && GET_MODE (r) == mode)
1910 return r;
1911
1912 /* No; make a new one and add it to the chain.
1913
1914 We may be called by an optimizer which may be discarding any memory
1915 allocated during its processing (such as combine and loop). However,
1916 we will be leaving this constant on the chain, so we cannot tolerate
1917 freed memory. So switch to saveable_obstack for this allocation
1918 and then switch back if we were in current_obstack. */
1919
1920 push_obstacks_nochange ();
1921 rtl_in_saveable_obstack ();
1922 r = rtx_alloc (CONST_DOUBLE);
1923 PUT_MODE (r, mode);
1924 bcopy (&u, &CONST_DOUBLE_LOW (r), sizeof u);
1925 pop_obstacks ();
1926
1927 /* Don't touch const_double_chain in nested function; see force_const_mem.
1928 Also, don't touch it if not inside any function. */
1929 if (outer_function_chain == 0 && current_function_decl != 0)
1930 {
1931 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1932 const_double_chain = r;
1933 }
1934
1935 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1936 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1937 is only through force_const_mem. */
1938
1939 CONST_DOUBLE_MEM (r) = const0_rtx;
1940
1941 return r;
1942 }
1943
1944 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1945 which must be a REAL_CST tree node. */
1946
1947 rtx
1948 immed_real_const (exp)
1949 tree exp;
1950 {
1951 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1952 }
1953
1954 /* At the end of a function, forget the memory-constants
1955 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1956 Also clear out real_constant_chain and clear out all the chain-pointers. */
1957
1958 void
1959 clear_const_double_mem ()
1960 {
1961 register rtx r, next;
1962
1963 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1964 See force_const_mem for explanation. */
1965 if (outer_function_chain != 0)
1966 return;
1967
1968 for (r = const_double_chain; r; r = next)
1969 {
1970 next = CONST_DOUBLE_CHAIN (r);
1971 CONST_DOUBLE_CHAIN (r) = 0;
1972 CONST_DOUBLE_MEM (r) = cc0_rtx;
1973 }
1974 const_double_chain = 0;
1975 }
1976 \f
1977 /* Given an expression EXP with a constant value,
1978 reduce it to the sum of an assembler symbol and an integer.
1979 Store them both in the structure *VALUE.
1980 Abort if EXP does not reduce. */
1981
1982 struct addr_const
1983 {
1984 rtx base;
1985 HOST_WIDE_INT offset;
1986 };
1987
1988 static void
1989 decode_addr_const (exp, value)
1990 tree exp;
1991 struct addr_const *value;
1992 {
1993 register tree target = TREE_OPERAND (exp, 0);
1994 register int offset = 0;
1995 register rtx x;
1996
1997 while (1)
1998 {
1999 if (TREE_CODE (target) == COMPONENT_REF
2000 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2001 == INTEGER_CST))
2002 {
2003 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2004 target = TREE_OPERAND (target, 0);
2005 }
2006 else if (TREE_CODE (target) == ARRAY_REF)
2007 {
2008 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2009 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2010 abort ();
2011 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2012 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2013 / BITS_PER_UNIT);
2014 target = TREE_OPERAND (target, 0);
2015 }
2016 else
2017 break;
2018 }
2019
2020 switch (TREE_CODE (target))
2021 {
2022 case VAR_DECL:
2023 case FUNCTION_DECL:
2024 x = DECL_RTL (target);
2025 break;
2026
2027 case LABEL_DECL:
2028 if (output_bytecode)
2029 /* FIXME: this may not be correct, check it */
2030 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
2031 else
2032 x = gen_rtx (MEM, FUNCTION_MODE,
2033 gen_rtx (LABEL_REF, VOIDmode,
2034 label_rtx (TREE_OPERAND (exp, 0))));
2035 break;
2036
2037 case REAL_CST:
2038 case STRING_CST:
2039 case COMPLEX_CST:
2040 case CONSTRUCTOR:
2041 x = TREE_CST_RTL (target);
2042 break;
2043
2044 default:
2045 abort ();
2046 }
2047
2048 if (!output_bytecode)
2049 {
2050 if (GET_CODE (x) != MEM)
2051 abort ();
2052 x = XEXP (x, 0);
2053 }
2054
2055 value->base = x;
2056 value->offset = offset;
2057 }
2058 \f
2059 /* Uniquize all constants that appear in memory.
2060 Each constant in memory thus far output is recorded
2061 in `const_hash_table' with a `struct constant_descriptor'
2062 that contains a polish representation of the value of
2063 the constant.
2064
2065 We cannot store the trees in the hash table
2066 because the trees may be temporary. */
2067
2068 struct constant_descriptor
2069 {
2070 struct constant_descriptor *next;
2071 char *label;
2072 char contents[1];
2073 };
2074
2075 #define HASHBITS 30
2076 #define MAX_HASH_TABLE 1009
2077 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2078
2079 /* Compute a hash code for a constant expression. */
2080
2081 int
2082 const_hash (exp)
2083 tree exp;
2084 {
2085 register char *p;
2086 register int len, hi, i;
2087 register enum tree_code code = TREE_CODE (exp);
2088
2089 if (code == INTEGER_CST)
2090 {
2091 p = (char *) &TREE_INT_CST_LOW (exp);
2092 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2093 }
2094 else if (code == REAL_CST)
2095 {
2096 p = (char *) &TREE_REAL_CST (exp);
2097 len = sizeof TREE_REAL_CST (exp);
2098 }
2099 else if (code == STRING_CST)
2100 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2101 else if (code == COMPLEX_CST)
2102 return const_hash (TREE_REALPART (exp)) * 5
2103 + const_hash (TREE_IMAGPART (exp));
2104 else if (code == CONSTRUCTOR)
2105 {
2106 register tree link;
2107
2108 /* For record type, include the type in the hashing.
2109 We do not do so for array types
2110 because (1) the sizes of the elements are sufficient
2111 and (2) distinct array types can have the same constructor.
2112 Instead, we include the array size because the constructor could
2113 be shorter. */
2114 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2115 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2116 % MAX_HASH_TABLE;
2117 else
2118 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2119 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2120
2121 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2122 if (TREE_VALUE (link))
2123 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2124
2125 return hi;
2126 }
2127 else if (code == ADDR_EXPR)
2128 {
2129 struct addr_const value;
2130 decode_addr_const (exp, &value);
2131 if (GET_CODE (value.base) == SYMBOL_REF)
2132 {
2133 /* Don't hash the address of the SYMBOL_REF;
2134 only use the offset and the symbol name. */
2135 hi = value.offset;
2136 p = XSTR (value.base, 0);
2137 for (i = 0; p[i] != 0; i++)
2138 hi = ((hi * 613) + (unsigned)(p[i]));
2139 }
2140 else if (GET_CODE (value.base) == LABEL_REF)
2141 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2142
2143 hi &= (1 << HASHBITS) - 1;
2144 hi %= MAX_HASH_TABLE;
2145 return hi;
2146 }
2147 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2148 return const_hash (TREE_OPERAND (exp, 0)) * 9
2149 + const_hash (TREE_OPERAND (exp, 1));
2150 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2151 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2152
2153 /* Compute hashing function */
2154 hi = len;
2155 for (i = 0; i < len; i++)
2156 hi = ((hi * 613) + (unsigned)(p[i]));
2157
2158 hi &= (1 << HASHBITS) - 1;
2159 hi %= MAX_HASH_TABLE;
2160 return hi;
2161 }
2162 \f
2163 /* Compare a constant expression EXP with a constant-descriptor DESC.
2164 Return 1 if DESC describes a constant with the same value as EXP. */
2165
2166 static int
2167 compare_constant (exp, desc)
2168 tree exp;
2169 struct constant_descriptor *desc;
2170 {
2171 return 0 != compare_constant_1 (exp, desc->contents);
2172 }
2173
2174 /* Compare constant expression EXP with a substring P of a constant descriptor.
2175 If they match, return a pointer to the end of the substring matched.
2176 If they do not match, return 0.
2177
2178 Since descriptors are written in polish prefix notation,
2179 this function can be used recursively to test one operand of EXP
2180 against a subdescriptor, and if it succeeds it returns the
2181 address of the subdescriptor for the next operand. */
2182
2183 static char *
2184 compare_constant_1 (exp, p)
2185 tree exp;
2186 char *p;
2187 {
2188 register char *strp;
2189 register int len;
2190 register enum tree_code code = TREE_CODE (exp);
2191
2192 if (code != (enum tree_code) *p++)
2193 return 0;
2194
2195 if (code == INTEGER_CST)
2196 {
2197 /* Integer constants are the same only if the same width of type. */
2198 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2199 return 0;
2200 strp = (char *) &TREE_INT_CST_LOW (exp);
2201 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2202 }
2203 else if (code == REAL_CST)
2204 {
2205 /* Real constants are the same only if the same width of type. */
2206 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2207 return 0;
2208 strp = (char *) &TREE_REAL_CST (exp);
2209 len = sizeof TREE_REAL_CST (exp);
2210 }
2211 else if (code == STRING_CST)
2212 {
2213 if (flag_writable_strings)
2214 return 0;
2215 strp = TREE_STRING_POINTER (exp);
2216 len = TREE_STRING_LENGTH (exp);
2217 if (bcmp (&TREE_STRING_LENGTH (exp), p,
2218 sizeof TREE_STRING_LENGTH (exp)))
2219 return 0;
2220 p += sizeof TREE_STRING_LENGTH (exp);
2221 }
2222 else if (code == COMPLEX_CST)
2223 {
2224 p = compare_constant_1 (TREE_REALPART (exp), p);
2225 if (p == 0) return 0;
2226 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2227 return p;
2228 }
2229 else if (code == CONSTRUCTOR)
2230 {
2231 register tree link;
2232 int length = list_length (CONSTRUCTOR_ELTS (exp));
2233 tree type;
2234
2235 if (bcmp (&length, p, sizeof length))
2236 return 0;
2237 p += sizeof length;
2238
2239 /* For record constructors, insist that the types match.
2240 For arrays, just verify both constructors are for arrays. */
2241 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2242 type = TREE_TYPE (exp);
2243 else
2244 type = 0;
2245 if (bcmp (&type, p, sizeof type))
2246 return 0;
2247 p += sizeof type;
2248
2249 /* For arrays, insist that the size in bytes match. */
2250 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2251 {
2252 int size = int_size_in_bytes (TREE_TYPE (exp));
2253 if (bcmp (&size, p, sizeof size))
2254 return 0;
2255 p += sizeof size;
2256 }
2257
2258 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2259 {
2260 if (TREE_VALUE (link))
2261 {
2262 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2263 return 0;
2264 }
2265 else
2266 {
2267 tree zero = 0;
2268
2269 if (bcmp (&zero, p, sizeof zero))
2270 return 0;
2271 p += sizeof zero;
2272 }
2273 }
2274
2275 return p;
2276 }
2277 else if (code == ADDR_EXPR)
2278 {
2279 struct addr_const value;
2280 decode_addr_const (exp, &value);
2281 strp = (char *) &value.offset;
2282 len = sizeof value.offset;
2283 /* Compare the offset. */
2284 while (--len >= 0)
2285 if (*p++ != *strp++)
2286 return 0;
2287 /* Compare symbol name. */
2288 strp = XSTR (value.base, 0);
2289 len = strlen (strp) + 1;
2290 }
2291 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2292 {
2293 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2294 if (p == 0) return 0;
2295 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2296 return p;
2297 }
2298 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2299 {
2300 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2301 return p;
2302 }
2303
2304 /* Compare constant contents. */
2305 while (--len >= 0)
2306 if (*p++ != *strp++)
2307 return 0;
2308
2309 return p;
2310 }
2311 \f
2312 /* Construct a constant descriptor for the expression EXP.
2313 It is up to the caller to enter the descriptor in the hash table. */
2314
2315 static struct constant_descriptor *
2316 record_constant (exp)
2317 tree exp;
2318 {
2319 struct constant_descriptor *next = 0;
2320 char *label = 0;
2321
2322 /* Make a struct constant_descriptor. The first two pointers will
2323 be filled in later. Here we just leave space for them. */
2324
2325 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2326 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2327 record_constant_1 (exp);
2328 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2329 }
2330
2331 /* Add a description of constant expression EXP
2332 to the object growing in `permanent_obstack'.
2333 No need to return its address; the caller will get that
2334 from the obstack when the object is complete. */
2335
2336 static void
2337 record_constant_1 (exp)
2338 tree exp;
2339 {
2340 register char *strp;
2341 register int len;
2342 register enum tree_code code = TREE_CODE (exp);
2343
2344 obstack_1grow (&permanent_obstack, (unsigned int) code);
2345
2346 if (code == INTEGER_CST)
2347 {
2348 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2349 strp = (char *) &TREE_INT_CST_LOW (exp);
2350 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2351 }
2352 else if (code == REAL_CST)
2353 {
2354 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2355 strp = (char *) &TREE_REAL_CST (exp);
2356 len = sizeof TREE_REAL_CST (exp);
2357 }
2358 else if (code == STRING_CST)
2359 {
2360 if (flag_writable_strings)
2361 return;
2362 strp = TREE_STRING_POINTER (exp);
2363 len = TREE_STRING_LENGTH (exp);
2364 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2365 sizeof TREE_STRING_LENGTH (exp));
2366 }
2367 else if (code == COMPLEX_CST)
2368 {
2369 record_constant_1 (TREE_REALPART (exp));
2370 record_constant_1 (TREE_IMAGPART (exp));
2371 return;
2372 }
2373 else if (code == CONSTRUCTOR)
2374 {
2375 register tree link;
2376 int length = list_length (CONSTRUCTOR_ELTS (exp));
2377 tree type;
2378
2379 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2380
2381 /* For record constructors, insist that the types match.
2382 For arrays, just verify both constructors are for arrays. */
2383 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2384 type = TREE_TYPE (exp);
2385 else
2386 type = 0;
2387 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2388
2389 /* For arrays, insist that the size in bytes match. */
2390 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2391 {
2392 int size = int_size_in_bytes (TREE_TYPE (exp));
2393 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2394 }
2395
2396 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2397 {
2398 if (TREE_VALUE (link))
2399 record_constant_1 (TREE_VALUE (link));
2400 else
2401 {
2402 tree zero = 0;
2403
2404 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
2405 }
2406 }
2407
2408 return;
2409 }
2410 else if (code == ADDR_EXPR)
2411 {
2412 struct addr_const value;
2413 decode_addr_const (exp, &value);
2414 /* Record the offset. */
2415 obstack_grow (&permanent_obstack,
2416 (char *) &value.offset, sizeof value.offset);
2417 /* Record the symbol name. */
2418 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2419 strlen (XSTR (value.base, 0)) + 1);
2420 return;
2421 }
2422 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2423 {
2424 record_constant_1 (TREE_OPERAND (exp, 0));
2425 record_constant_1 (TREE_OPERAND (exp, 1));
2426 return;
2427 }
2428 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2429 {
2430 record_constant_1 (TREE_OPERAND (exp, 0));
2431 return;
2432 }
2433
2434 /* Record constant contents. */
2435 obstack_grow (&permanent_obstack, strp, len);
2436 }
2437 \f
2438 /* Record a list of constant expressions that were passed to
2439 output_constant_def but that could not be output right away. */
2440
2441 struct deferred_constant
2442 {
2443 struct deferred_constant *next;
2444 tree exp;
2445 int reloc;
2446 int labelno;
2447 };
2448
2449 static struct deferred_constant *deferred_constants;
2450
2451 /* Nonzero means defer output of addressed subconstants
2452 (i.e., those for which output_constant_def is called.) */
2453 static int defer_addressed_constants_flag;
2454
2455 /* Start deferring output of subconstants. */
2456
2457 void
2458 defer_addressed_constants ()
2459 {
2460 defer_addressed_constants_flag++;
2461 }
2462
2463 /* Stop deferring output of subconstants,
2464 and output now all those that have been deferred. */
2465
2466 void
2467 output_deferred_addressed_constants ()
2468 {
2469 struct deferred_constant *p, *next;
2470
2471 defer_addressed_constants_flag--;
2472
2473 if (defer_addressed_constants_flag > 0)
2474 return;
2475
2476 for (p = deferred_constants; p; p = next)
2477 {
2478 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2479 next = p->next;
2480 free (p);
2481 }
2482
2483 deferred_constants = 0;
2484 }
2485
2486 /* Make a copy of the whole tree structure for a constant.
2487 This handles the same types of nodes that compare_constant
2488 and record_constant handle. */
2489
2490 static tree
2491 copy_constant (exp)
2492 tree exp;
2493 {
2494 switch (TREE_CODE (exp))
2495 {
2496 case INTEGER_CST:
2497 case REAL_CST:
2498 case STRING_CST:
2499 case ADDR_EXPR:
2500 /* For ADDR_EXPR, we do not want to copy the decl
2501 whose address is requested. */
2502 return copy_node (exp);
2503
2504 case COMPLEX_CST:
2505 return build_complex (copy_constant (TREE_REALPART (exp)),
2506 copy_constant (TREE_IMAGPART (exp)));
2507
2508 case PLUS_EXPR:
2509 case MINUS_EXPR:
2510 return build (TREE_CODE (exp), TREE_TYPE (exp),
2511 copy_constant (TREE_OPERAND (exp, 0)),
2512 copy_constant (TREE_OPERAND (exp, 1)));
2513
2514 case NOP_EXPR:
2515 case CONVERT_EXPR:
2516 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2517 copy_constant (TREE_OPERAND (exp, 0)));
2518
2519 case CONSTRUCTOR:
2520 {
2521 tree copy = copy_node (exp);
2522 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2523 tree tail;
2524
2525 CONSTRUCTOR_ELTS (exp) = list;
2526 for (tail = list; tail; tail = TREE_CHAIN (tail))
2527 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2528
2529 return copy;
2530 }
2531
2532 default:
2533 abort ();
2534 }
2535 }
2536 \f
2537 /* Return an rtx representing a reference to constant data in memory
2538 for the constant expression EXP.
2539
2540 If assembler code for such a constant has already been output,
2541 return an rtx to refer to it.
2542 Otherwise, output such a constant in memory (or defer it for later)
2543 and generate an rtx for it.
2544
2545 The TREE_CST_RTL of EXP is set up to point to that rtx.
2546 The const_hash_table records which constants already have label strings. */
2547
2548 rtx
2549 output_constant_def (exp)
2550 tree exp;
2551 {
2552 register int hash;
2553 register struct constant_descriptor *desc;
2554 char label[256];
2555 char *found = 0;
2556 int reloc;
2557 register rtx def;
2558
2559 if (TREE_CODE (exp) == INTEGER_CST)
2560 abort (); /* No TREE_CST_RTL slot in these. */
2561
2562 if (TREE_CST_RTL (exp))
2563 return TREE_CST_RTL (exp);
2564
2565 /* Make sure any other constants whose addresses appear in EXP
2566 are assigned label numbers. */
2567
2568 reloc = output_addressed_constants (exp);
2569
2570 /* Compute hash code of EXP. Search the descriptors for that hash code
2571 to see if any of them describes EXP. If yes, the descriptor records
2572 the label number already assigned. */
2573
2574 hash = const_hash (exp) % MAX_HASH_TABLE;
2575
2576 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2577 if (compare_constant (exp, desc))
2578 {
2579 found = desc->label;
2580 break;
2581 }
2582
2583 if (found == 0)
2584 {
2585 /* No constant equal to EXP is known to have been output.
2586 Make a constant descriptor to enter EXP in the hash table.
2587 Assign the label number and record it in the descriptor for
2588 future calls to this function to find. */
2589
2590 /* Create a string containing the label name, in LABEL. */
2591 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2592
2593 desc = record_constant (exp);
2594 desc->next = const_hash_table[hash];
2595 desc->label
2596 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2597 const_hash_table[hash] = desc;
2598 }
2599 else
2600 {
2601 /* Create a string containing the label name, in LABEL. */
2602 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2603 }
2604
2605 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2606
2607 push_obstacks_nochange ();
2608 if (TREE_PERMANENT (exp))
2609 end_temporary_allocation ();
2610
2611 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2612
2613 TREE_CST_RTL (exp)
2614 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2615 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2616 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
2617 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2618 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2619
2620 pop_obstacks ();
2621
2622 /* Optionally set flags or add text to the name to record information
2623 such as that it is a function name. If the name is changed, the macro
2624 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2625 #ifdef ENCODE_SECTION_INFO
2626 ENCODE_SECTION_INFO (exp);
2627 #endif
2628
2629 /* If this is the first time we've seen this particular constant,
2630 output it (or defer its output for later). */
2631 if (found == 0)
2632 {
2633 if (defer_addressed_constants_flag)
2634 {
2635 struct deferred_constant *p;
2636 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2637
2638 push_obstacks_nochange ();
2639 suspend_momentary ();
2640 p->exp = copy_constant (exp);
2641 pop_obstacks ();
2642 p->reloc = reloc;
2643 p->labelno = const_labelno++;
2644 p->next = deferred_constants;
2645 deferred_constants = p;
2646 }
2647 else
2648 output_constant_def_contents (exp, reloc, const_labelno++);
2649 }
2650
2651 return TREE_CST_RTL (exp);
2652 }
2653
2654 /* Now output assembler code to define the label for EXP,
2655 and follow it with the data of EXP. */
2656
2657 static void
2658 output_constant_def_contents (exp, reloc, labelno)
2659 tree exp;
2660 int reloc;
2661 int labelno;
2662 {
2663 int align;
2664
2665 if (IN_NAMED_SECTION (exp))
2666 named_section (TREE_STRING_POINTER (DECL_SECTION_NAME (exp)));
2667 else
2668 {
2669 /* First switch to text section, except for writable strings. */
2670 #ifdef SELECT_SECTION
2671 SELECT_SECTION (exp, reloc);
2672 #else
2673 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2674 || (flag_pic && reloc))
2675 data_section ();
2676 else
2677 readonly_data_section ();
2678 #endif
2679 }
2680
2681 /* Align the location counter as required by EXP's data type. */
2682 align = TYPE_ALIGN (TREE_TYPE (exp));
2683 #ifdef CONSTANT_ALIGNMENT
2684 align = CONSTANT_ALIGNMENT (exp, align);
2685 #endif
2686
2687 if (align > BITS_PER_UNIT)
2688 {
2689 if (!output_bytecode)
2690 {
2691 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2692 }
2693 else
2694 {
2695 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2696 }
2697 }
2698
2699 /* Output the label itself. */
2700 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2701
2702 /* Output the value of EXP. */
2703 output_constant (exp,
2704 (TREE_CODE (exp) == STRING_CST
2705 ? TREE_STRING_LENGTH (exp)
2706 : int_size_in_bytes (TREE_TYPE (exp))));
2707
2708 }
2709 \f
2710 /* Similar hash facility for making memory-constants
2711 from constant rtl-expressions. It is used on RISC machines
2712 where immediate integer arguments and constant addresses are restricted
2713 so that such constants must be stored in memory.
2714
2715 This pool of constants is reinitialized for each function
2716 so each function gets its own constants-pool that comes right before it.
2717
2718 All structures allocated here are discarded when functions are saved for
2719 inlining, so they do not need to be allocated permanently. */
2720
2721 #define MAX_RTX_HASH_TABLE 61
2722 static struct constant_descriptor **const_rtx_hash_table;
2723
2724 /* Structure to represent sufficient information about a constant so that
2725 it can be output when the constant pool is output, so that function
2726 integration can be done, and to simplify handling on machines that reference
2727 constant pool as base+displacement. */
2728
2729 struct pool_constant
2730 {
2731 struct constant_descriptor *desc;
2732 struct pool_constant *next;
2733 enum machine_mode mode;
2734 rtx constant;
2735 int labelno;
2736 int align;
2737 int offset;
2738 };
2739
2740 /* Pointers to first and last constant in pool. */
2741
2742 static struct pool_constant *first_pool, *last_pool;
2743
2744 /* Current offset in constant pool (does not include any machine-specific
2745 header. */
2746
2747 static int pool_offset;
2748
2749 /* Structure used to maintain hash table mapping symbols used to their
2750 corresponding constants. */
2751
2752 struct pool_sym
2753 {
2754 char *label;
2755 struct pool_constant *pool;
2756 struct pool_sym *next;
2757 };
2758
2759 static struct pool_sym **const_rtx_sym_hash_table;
2760
2761 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2762 The argument is XSTR (... , 0) */
2763
2764 #define SYMHASH(LABEL) \
2765 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2766 \f
2767 /* Initialize constant pool hashing for next function. */
2768
2769 void
2770 init_const_rtx_hash_table ()
2771 {
2772 const_rtx_hash_table
2773 = ((struct constant_descriptor **)
2774 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2775 const_rtx_sym_hash_table
2776 = ((struct pool_sym **)
2777 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2778 bzero (const_rtx_hash_table,
2779 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2780 bzero (const_rtx_sym_hash_table,
2781 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2782
2783 first_pool = last_pool = 0;
2784 pool_offset = 0;
2785 }
2786
2787 /* Save and restore it for a nested function. */
2788
2789 void
2790 save_varasm_status (p)
2791 struct function *p;
2792 {
2793 p->const_rtx_hash_table = const_rtx_hash_table;
2794 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2795 p->first_pool = first_pool;
2796 p->last_pool = last_pool;
2797 p->pool_offset = pool_offset;
2798 }
2799
2800 void
2801 restore_varasm_status (p)
2802 struct function *p;
2803 {
2804 const_rtx_hash_table = p->const_rtx_hash_table;
2805 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2806 first_pool = p->first_pool;
2807 last_pool = p->last_pool;
2808 pool_offset = p->pool_offset;
2809 }
2810 \f
2811 enum kind { RTX_DOUBLE, RTX_INT };
2812
2813 struct rtx_const
2814 {
2815 #ifdef ONLY_INT_FIELDS
2816 unsigned int kind : 16;
2817 unsigned int mode : 16;
2818 #else
2819 enum kind kind : 16;
2820 enum machine_mode mode : 16;
2821 #endif
2822 union {
2823 union real_extract du;
2824 struct addr_const addr;
2825 } un;
2826 };
2827
2828 /* Express an rtx for a constant integer (perhaps symbolic)
2829 as the sum of a symbol or label plus an explicit integer.
2830 They are stored into VALUE. */
2831
2832 static void
2833 decode_rtx_const (mode, x, value)
2834 enum machine_mode mode;
2835 rtx x;
2836 struct rtx_const *value;
2837 {
2838 /* Clear the whole structure, including any gaps. */
2839
2840 {
2841 int *p = (int *) value;
2842 int *end = (int *) (value + 1);
2843 while (p < end)
2844 *p++ = 0;
2845 }
2846
2847 value->kind = RTX_INT; /* Most usual kind. */
2848 value->mode = mode;
2849
2850 switch (GET_CODE (x))
2851 {
2852 case CONST_DOUBLE:
2853 value->kind = RTX_DOUBLE;
2854 if (GET_MODE (x) != VOIDmode)
2855 value->mode = GET_MODE (x);
2856 bcopy (&CONST_DOUBLE_LOW (x), &value->un.du, sizeof value->un.du);
2857 break;
2858
2859 case CONST_INT:
2860 value->un.addr.offset = INTVAL (x);
2861 break;
2862
2863 case SYMBOL_REF:
2864 case LABEL_REF:
2865 case PC:
2866 value->un.addr.base = x;
2867 break;
2868
2869 case CONST:
2870 x = XEXP (x, 0);
2871 if (GET_CODE (x) == PLUS)
2872 {
2873 value->un.addr.base = XEXP (x, 0);
2874 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2875 abort ();
2876 value->un.addr.offset = INTVAL (XEXP (x, 1));
2877 }
2878 else if (GET_CODE (x) == MINUS)
2879 {
2880 value->un.addr.base = XEXP (x, 0);
2881 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2882 abort ();
2883 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2884 }
2885 else
2886 abort ();
2887 break;
2888
2889 default:
2890 abort ();
2891 }
2892
2893 if (value->kind == RTX_INT && value->un.addr.base != 0)
2894 switch (GET_CODE (value->un.addr.base))
2895 {
2896 case SYMBOL_REF:
2897 case LABEL_REF:
2898 /* Use the string's address, not the SYMBOL_REF's address,
2899 for the sake of addresses of library routines.
2900 For a LABEL_REF, compare labels. */
2901 value->un.addr.base = XEXP (value->un.addr.base, 0);
2902 }
2903 }
2904
2905 /* Given a MINUS expression, simplify it if both sides
2906 include the same symbol. */
2907
2908 rtx
2909 simplify_subtraction (x)
2910 rtx x;
2911 {
2912 struct rtx_const val0, val1;
2913
2914 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2915 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2916
2917 if (val0.un.addr.base == val1.un.addr.base)
2918 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2919 return x;
2920 }
2921
2922 /* Compute a hash code for a constant RTL expression. */
2923
2924 int
2925 const_hash_rtx (mode, x)
2926 enum machine_mode mode;
2927 rtx x;
2928 {
2929 register int hi, i;
2930
2931 struct rtx_const value;
2932 decode_rtx_const (mode, x, &value);
2933
2934 /* Compute hashing function */
2935 hi = 0;
2936 for (i = 0; i < sizeof value / sizeof (int); i++)
2937 hi += ((int *) &value)[i];
2938
2939 hi &= (1 << HASHBITS) - 1;
2940 hi %= MAX_RTX_HASH_TABLE;
2941 return hi;
2942 }
2943
2944 /* Compare a constant rtl object X with a constant-descriptor DESC.
2945 Return 1 if DESC describes a constant with the same value as X. */
2946
2947 static int
2948 compare_constant_rtx (mode, x, desc)
2949 enum machine_mode mode;
2950 rtx x;
2951 struct constant_descriptor *desc;
2952 {
2953 register int *p = (int *) desc->contents;
2954 register int *strp;
2955 register int len;
2956 struct rtx_const value;
2957
2958 decode_rtx_const (mode, x, &value);
2959 strp = (int *) &value;
2960 len = sizeof value / sizeof (int);
2961
2962 /* Compare constant contents. */
2963 while (--len >= 0)
2964 if (*p++ != *strp++)
2965 return 0;
2966
2967 return 1;
2968 }
2969
2970 /* Construct a constant descriptor for the rtl-expression X.
2971 It is up to the caller to enter the descriptor in the hash table. */
2972
2973 static struct constant_descriptor *
2974 record_constant_rtx (mode, x)
2975 enum machine_mode mode;
2976 rtx x;
2977 {
2978 struct constant_descriptor *ptr;
2979 char *label;
2980 struct rtx_const value;
2981
2982 decode_rtx_const (mode, x, &value);
2983
2984 obstack_grow (current_obstack, &ptr, sizeof ptr);
2985 obstack_grow (current_obstack, &label, sizeof label);
2986
2987 /* Record constant contents. */
2988 obstack_grow (current_obstack, &value, sizeof value);
2989
2990 return (struct constant_descriptor *) obstack_finish (current_obstack);
2991 }
2992 \f
2993 /* Given a constant rtx X, make (or find) a memory constant for its value
2994 and return a MEM rtx to refer to it in memory. */
2995
2996 rtx
2997 force_const_mem (mode, x)
2998 enum machine_mode mode;
2999 rtx x;
3000 {
3001 register int hash;
3002 register struct constant_descriptor *desc;
3003 char label[256];
3004 char *found = 0;
3005 rtx def;
3006
3007 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3008 (this will always be true for floating CONST_DOUBLEs that have been
3009 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3010 use the previous copy. Otherwise, make a new one. Note that in
3011 the unlikely event that this same CONST_DOUBLE is used in two different
3012 modes in an alternating fashion, we will allocate a lot of different
3013 memory locations, but this should be extremely rare. */
3014
3015 /* Don't use CONST_DOUBLE_MEM in a nested function.
3016 Nested functions have their own constant pools,
3017 so they can't share the same values in CONST_DOUBLE_MEM
3018 with the containing function. */
3019 if (outer_function_chain == 0)
3020 if (GET_CODE (x) == CONST_DOUBLE
3021 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3022 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3023 return CONST_DOUBLE_MEM (x);
3024
3025 /* Compute hash code of X. Search the descriptors for that hash code
3026 to see if any of them describes X. If yes, the descriptor records
3027 the label number already assigned. */
3028
3029 hash = const_hash_rtx (mode, x);
3030
3031 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3032 if (compare_constant_rtx (mode, x, desc))
3033 {
3034 found = desc->label;
3035 break;
3036 }
3037
3038 if (found == 0)
3039 {
3040 register struct pool_constant *pool;
3041 register struct pool_sym *sym;
3042 int align;
3043
3044 /* No constant equal to X is known to have been output.
3045 Make a constant descriptor to enter X in the hash table.
3046 Assign the label number and record it in the descriptor for
3047 future calls to this function to find. */
3048
3049 desc = record_constant_rtx (mode, x);
3050 desc->next = const_rtx_hash_table[hash];
3051 const_rtx_hash_table[hash] = desc;
3052
3053 /* Align the location counter as required by EXP's data type. */
3054 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3055 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3056 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3057
3058 pool_offset += align - 1;
3059 pool_offset &= ~ (align - 1);
3060
3061 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3062
3063 pool = (struct pool_constant *) oballoc (sizeof (struct pool_constant));
3064 pool->desc = desc;
3065 pool->constant = x;
3066 pool->mode = mode;
3067 pool->labelno = const_labelno;
3068 pool->align = align;
3069 pool->offset = pool_offset;
3070 pool->next = 0;
3071
3072 if (last_pool == 0)
3073 first_pool = pool;
3074 else
3075 last_pool->next = pool;
3076
3077 last_pool = pool;
3078 pool_offset += GET_MODE_SIZE (mode);
3079
3080 /* Create a string containing the label name, in LABEL. */
3081 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3082
3083 ++const_labelno;
3084
3085 desc->label = found
3086 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3087
3088 /* Add label to symbol hash table. */
3089 hash = SYMHASH (found);
3090 sym = (struct pool_sym *) oballoc (sizeof (struct pool_sym));
3091 sym->label = found;
3092 sym->pool = pool;
3093 sym->next = const_rtx_sym_hash_table[hash];
3094 const_rtx_sym_hash_table[hash] = sym;
3095 }
3096
3097 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3098
3099 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3100
3101 RTX_UNCHANGING_P (def) = 1;
3102 /* Mark the symbol_ref as belonging to this constants pool. */
3103 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3104 current_function_uses_const_pool = 1;
3105
3106 if (outer_function_chain == 0)
3107 if (GET_CODE (x) == CONST_DOUBLE)
3108 {
3109 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3110 {
3111 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3112 const_double_chain = x;
3113 }
3114 CONST_DOUBLE_MEM (x) = def;
3115 }
3116
3117 return def;
3118 }
3119 \f
3120 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3121 the corresponding pool_constant structure. */
3122
3123 static struct pool_constant *
3124 find_pool_constant (addr)
3125 rtx addr;
3126 {
3127 struct pool_sym *sym;
3128 char *label = XSTR (addr, 0);
3129
3130 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3131 if (sym->label == label)
3132 return sym->pool;
3133
3134 abort ();
3135 }
3136
3137 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3138
3139 rtx
3140 get_pool_constant (addr)
3141 rtx addr;
3142 {
3143 return (find_pool_constant (addr))->constant;
3144 }
3145
3146 /* Similar, return the mode. */
3147
3148 enum machine_mode
3149 get_pool_mode (addr)
3150 rtx addr;
3151 {
3152 return (find_pool_constant (addr))->mode;
3153 }
3154
3155 /* Similar, return the offset in the constant pool. */
3156
3157 int
3158 get_pool_offset (addr)
3159 rtx addr;
3160 {
3161 return (find_pool_constant (addr))->offset;
3162 }
3163
3164 /* Return the size of the constant pool. */
3165
3166 int
3167 get_pool_size ()
3168 {
3169 return pool_offset;
3170 }
3171 \f
3172 /* Write all the constants in the constant pool. */
3173
3174 void
3175 output_constant_pool (fnname, fndecl)
3176 char *fnname;
3177 tree fndecl;
3178 {
3179 struct pool_constant *pool;
3180 rtx x;
3181 union real_extract u;
3182
3183 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3184 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3185 #endif
3186
3187 for (pool = first_pool; pool; pool = pool->next)
3188 {
3189 x = pool->constant;
3190
3191 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3192 whose CODE_LABEL has been deleted. This can occur if a jump table
3193 is eliminated by optimization. If so, write a constant of zero
3194 instead. Note that this can also happen by turning the
3195 CODE_LABEL into a NOTE. */
3196 if (((GET_CODE (x) == LABEL_REF
3197 && (INSN_DELETED_P (XEXP (x, 0))
3198 || GET_CODE (XEXP (x, 0)) == NOTE)))
3199 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3200 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3201 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3202 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3203 x = const0_rtx;
3204
3205 /* First switch to correct section. */
3206 #ifdef SELECT_RTX_SECTION
3207 SELECT_RTX_SECTION (pool->mode, x);
3208 #else
3209 readonly_data_section ();
3210 #endif
3211
3212 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3213 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3214 pool->align, pool->labelno, done);
3215 #endif
3216
3217 if (pool->align > 1)
3218 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3219
3220 /* Output the label. */
3221 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3222
3223 /* Output the value of the constant itself. */
3224 switch (GET_MODE_CLASS (pool->mode))
3225 {
3226 case MODE_FLOAT:
3227 if (GET_CODE (x) != CONST_DOUBLE)
3228 abort ();
3229
3230 bcopy (&CONST_DOUBLE_LOW (x), &u, sizeof u);
3231 assemble_real (u.d, pool->mode);
3232 break;
3233
3234 case MODE_INT:
3235 case MODE_PARTIAL_INT:
3236 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3237 break;
3238
3239 default:
3240 abort ();
3241 }
3242
3243 done: ;
3244 }
3245
3246 /* Done with this pool. */
3247 first_pool = last_pool = 0;
3248 }
3249 \f
3250 /* Find all the constants whose addresses are referenced inside of EXP,
3251 and make sure assembler code with a label has been output for each one.
3252 Indicate whether an ADDR_EXPR has been encountered. */
3253
3254 int
3255 output_addressed_constants (exp)
3256 tree exp;
3257 {
3258 int reloc = 0;
3259
3260 switch (TREE_CODE (exp))
3261 {
3262 case ADDR_EXPR:
3263 {
3264 register tree constant = TREE_OPERAND (exp, 0);
3265
3266 while (TREE_CODE (constant) == COMPONENT_REF)
3267 {
3268 constant = TREE_OPERAND (constant, 0);
3269 }
3270
3271 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3272 || TREE_CODE (constant) == CONSTRUCTOR)
3273 /* No need to do anything here
3274 for addresses of variables or functions. */
3275 output_constant_def (constant);
3276 }
3277 reloc = 1;
3278 break;
3279
3280 case PLUS_EXPR:
3281 case MINUS_EXPR:
3282 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3283 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3284 break;
3285
3286 case NOP_EXPR:
3287 case CONVERT_EXPR:
3288 case NON_LVALUE_EXPR:
3289 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3290 break;
3291
3292 case CONSTRUCTOR:
3293 {
3294 register tree link;
3295 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3296 if (TREE_VALUE (link) != 0)
3297 reloc |= output_addressed_constants (TREE_VALUE (link));
3298 }
3299 break;
3300
3301 case ERROR_MARK:
3302 break;
3303 }
3304 return reloc;
3305 }
3306
3307
3308 /* Output assembler for byte constant */
3309 void
3310 output_byte_asm (byte)
3311 int byte;
3312 {
3313 if (output_bytecode)
3314 bc_emit_const ((char *) &byte, sizeof (char));
3315 #ifdef ASM_OUTPUT_BYTE
3316 else
3317 {
3318 ASM_OUTPUT_BYTE (asm_out_file, byte);
3319 }
3320 #endif
3321 }
3322 \f
3323 /* Output assembler code for constant EXP to FILE, with no label.
3324 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3325 Assumes output_addressed_constants has been done on EXP already.
3326
3327 Generate exactly SIZE bytes of assembler data, padding at the end
3328 with zeros if necessary. SIZE must always be specified.
3329
3330 SIZE is important for structure constructors,
3331 since trailing members may have been omitted from the constructor.
3332 It is also important for initialization of arrays from string constants
3333 since the full length of the string constant might not be wanted.
3334 It is also needed for initialization of unions, where the initializer's
3335 type is just one member, and that may not be as long as the union.
3336
3337 There a case in which we would fail to output exactly SIZE bytes:
3338 for a structure constructor that wants to produce more than SIZE bytes.
3339 But such constructors will never be generated for any possible input. */
3340
3341 void
3342 output_constant (exp, size)
3343 register tree exp;
3344 register int size;
3345 {
3346 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3347 rtx x;
3348
3349 if (size == 0)
3350 return;
3351
3352 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3353 That way we get the constant (we hope) inside it. Also, strip
3354 off any NOP_EXPR that converts between two record or union types. */
3355 while ((TREE_CODE (exp) == NOP_EXPR
3356 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3357 || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3358 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
3359 || TREE_CODE (TREE_TYPE (exp)) == QUAL_UNION_TYPE))
3360 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3361 exp = TREE_OPERAND (exp, 0);
3362
3363 /* Allow a constructor with no elements for any data type.
3364 This means to fill the space with zeros. */
3365 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3366 {
3367 if (output_bytecode)
3368 bc_emit_const_skip (size);
3369 else
3370 assemble_zeros (size);
3371 return;
3372 }
3373
3374 switch (code)
3375 {
3376 case CHAR_TYPE:
3377 case BOOLEAN_TYPE:
3378 case INTEGER_TYPE:
3379 case ENUMERAL_TYPE:
3380 case POINTER_TYPE:
3381 case REFERENCE_TYPE:
3382 /* ??? What about (int)((float)(int)&foo + 4) */
3383 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3384 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3385 exp = TREE_OPERAND (exp, 0);
3386
3387 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3388 EXPAND_INITIALIZER),
3389 size, 0))
3390 error ("initializer for integer value is too complicated");
3391 size = 0;
3392 break;
3393
3394 case REAL_TYPE:
3395 if (TREE_CODE (exp) != REAL_CST)
3396 error ("initializer for floating value is not a floating constant");
3397
3398 assemble_real (TREE_REAL_CST (exp),
3399 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3400 size = 0;
3401 break;
3402
3403 case COMPLEX_TYPE:
3404 output_constant (TREE_REALPART (exp), size / 2);
3405 output_constant (TREE_IMAGPART (exp), size / 2);
3406 size -= (size / 2) * 2;
3407 break;
3408
3409 case ARRAY_TYPE:
3410 if (TREE_CODE (exp) == CONSTRUCTOR)
3411 {
3412 output_constructor (exp, size);
3413 return;
3414 }
3415 else if (TREE_CODE (exp) == STRING_CST)
3416 {
3417 int excess = 0;
3418
3419 if (size > TREE_STRING_LENGTH (exp))
3420 {
3421 excess = size - TREE_STRING_LENGTH (exp);
3422 size = TREE_STRING_LENGTH (exp);
3423 }
3424
3425 assemble_string (TREE_STRING_POINTER (exp), size);
3426 size = excess;
3427 }
3428 else
3429 abort ();
3430 break;
3431
3432 case RECORD_TYPE:
3433 case UNION_TYPE:
3434 if (TREE_CODE (exp) == CONSTRUCTOR)
3435 output_constructor (exp, size);
3436 else
3437 abort ();
3438 return;
3439 }
3440
3441 if (size > 0)
3442 assemble_zeros (size);
3443 }
3444
3445
3446 /* Bytecode specific code to output assembler for integer. */
3447 static void
3448 bc_assemble_integer (exp, size)
3449 tree exp;
3450 int size;
3451 {
3452 tree const_part;
3453 tree addr_part;
3454 tree tmp;
3455
3456 /* FIXME: is this fold() business going to be as good as the
3457 expand_expr() using EXPAND_SUM above in the RTL case? I
3458 hate RMS.
3459 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3460
3461 exp = fold (exp);
3462
3463 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3464 exp = TREE_OPERAND (exp, 0);
3465 if (TREE_CODE (exp) == INTEGER_CST)
3466 {
3467 const_part = exp;
3468 addr_part = 0;
3469 }
3470 else if (TREE_CODE (exp) == PLUS_EXPR)
3471 {
3472 const_part = TREE_OPERAND (exp, 0);
3473 while (TREE_CODE (const_part) == NOP_EXPR
3474 || TREE_CODE (const_part) == CONVERT_EXPR)
3475 const_part = TREE_OPERAND (const_part, 0);
3476 addr_part = TREE_OPERAND (exp, 1);
3477 while (TREE_CODE (addr_part) == NOP_EXPR
3478 || TREE_CODE (addr_part) == CONVERT_EXPR)
3479 addr_part = TREE_OPERAND (addr_part, 0);
3480 if (TREE_CODE (const_part) != INTEGER_CST)
3481 tmp = const_part, const_part = addr_part, addr_part = tmp;
3482 if (TREE_CODE (const_part) != INTEGER_CST
3483 || TREE_CODE (addr_part) != ADDR_EXPR)
3484 abort (); /* FIXME: we really haven't considered
3485 all the possible cases here. */
3486 }
3487 else if (TREE_CODE (exp) == ADDR_EXPR)
3488 {
3489 const_part = integer_zero_node;
3490 addr_part = exp;
3491 }
3492 else
3493 abort (); /* FIXME: ditto previous. */
3494
3495 if (addr_part == 0)
3496 {
3497 if (size == 1)
3498 {
3499 char c = TREE_INT_CST_LOW (const_part);
3500 bc_emit (&c, 1);
3501 size -= 1;
3502 }
3503 else if (size == 2)
3504 {
3505 short s = TREE_INT_CST_LOW (const_part);
3506 bc_emit ((char *) &s, 2);
3507 size -= 2;
3508 }
3509 else if (size == 4)
3510 {
3511 int i = TREE_INT_CST_LOW (const_part);
3512 bc_emit ((char *) &i, 4);
3513 size -= 4;
3514 }
3515 else if (size == 8)
3516 {
3517 #if WORDS_BIG_ENDIAN
3518 int i = TREE_INT_CST_HIGH (const_part);
3519 bc_emit ((char *) &i, 4);
3520 i = TREE_INT_CST_LOW (const_part);
3521 bc_emit ((char *) &i, 4);
3522 #else
3523 int i = TREE_INT_CST_LOW (const_part);
3524 bc_emit ((char *) &i, 4);
3525 i = TREE_INT_CST_HIGH (const_part);
3526 bc_emit ((char *) &i, 4);
3527 #endif
3528 size -= 8;
3529 }
3530 }
3531 else
3532 if (size == 4
3533 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3534 bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3535 TREE_INT_CST_LOW (const_part));
3536 else
3537 abort (); /* FIXME: there may be more cases. */
3538 }
3539 \f
3540 /* Subroutine of output_constant, used for CONSTRUCTORs
3541 (aggregate constants).
3542 Generate at least SIZE bytes, padding if necessary. */
3543
3544 void
3545 output_constructor (exp, size)
3546 tree exp;
3547 int size;
3548 {
3549 register tree link, field = 0;
3550 HOST_WIDE_INT min_index = 0;
3551 /* Number of bytes output or skipped so far.
3552 In other words, current position within the constructor. */
3553 int total_bytes = 0;
3554 /* Non-zero means BYTE contains part of a byte, to be output. */
3555 int byte_buffer_in_use = 0;
3556 register int byte;
3557
3558 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3559 abort ();
3560
3561 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3562 field = TYPE_FIELDS (TREE_TYPE (exp));
3563
3564 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3565 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3566 min_index
3567 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3568
3569 /* As LINK goes through the elements of the constant,
3570 FIELD goes through the structure fields, if the constant is a structure.
3571 if the constant is a union, then we override this,
3572 by getting the field from the TREE_LIST element.
3573 But the constant could also be an array. Then FIELD is zero. */
3574 for (link = CONSTRUCTOR_ELTS (exp);
3575 link;
3576 link = TREE_CHAIN (link),
3577 field = field ? TREE_CHAIN (field) : 0)
3578 {
3579 tree val = TREE_VALUE (link);
3580 tree index = 0;
3581
3582 /* the element in a union constructor specifies the proper field. */
3583
3584 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3585 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3586 {
3587 /* if available, use the type given by link */
3588 if (TREE_PURPOSE (link) != 0)
3589 field = TREE_PURPOSE (link);
3590 }
3591
3592 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3593 index = TREE_PURPOSE (link);
3594
3595 /* Eliminate the marker that makes a cast not be an lvalue. */
3596 if (val != 0)
3597 STRIP_NOPS (val);
3598
3599 if (field == 0 || !DECL_BIT_FIELD (field))
3600 {
3601 /* An element that is not a bit-field. */
3602
3603 register int fieldsize;
3604 /* Since this structure is static,
3605 we know the positions are constant. */
3606 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3607 / BITS_PER_UNIT)
3608 : 0);
3609 if (index != 0)
3610 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3611 / BITS_PER_UNIT
3612 * (TREE_INT_CST_LOW (index) - min_index));
3613
3614 /* Output any buffered-up bit-fields preceding this element. */
3615 if (byte_buffer_in_use)
3616 {
3617 ASM_OUTPUT_BYTE (asm_out_file, byte);
3618 total_bytes++;
3619 byte_buffer_in_use = 0;
3620 }
3621
3622 /* Advance to offset of this element.
3623 Note no alignment needed in an array, since that is guaranteed
3624 if each element has the proper size. */
3625 if ((field != 0 || index != 0) && bitpos != total_bytes)
3626 {
3627 if (!output_bytecode)
3628 assemble_zeros (bitpos - total_bytes);
3629 else
3630 bc_emit_const_skip (bitpos - total_bytes);
3631 total_bytes = bitpos;
3632 }
3633
3634 /* Determine size this element should occupy. */
3635 if (field)
3636 {
3637 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3638 abort ();
3639 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3640 {
3641 /* This avoids overflow trouble. */
3642 tree size_tree = size_binop (CEIL_DIV_EXPR,
3643 DECL_SIZE (field),
3644 size_int (BITS_PER_UNIT));
3645 fieldsize = TREE_INT_CST_LOW (size_tree);
3646 }
3647 else
3648 {
3649 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3650 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3651 }
3652 }
3653 else
3654 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3655
3656 /* Output the element's initial value. */
3657 if (val == 0)
3658 assemble_zeros (fieldsize);
3659 else
3660 output_constant (val, fieldsize);
3661
3662 /* Count its size. */
3663 total_bytes += fieldsize;
3664 }
3665 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3666 error ("invalid initial value for member `%s'",
3667 IDENTIFIER_POINTER (DECL_NAME (field)));
3668 else
3669 {
3670 /* Element that is a bit-field. */
3671
3672 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3673 int end_offset
3674 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3675
3676 if (val == 0)
3677 val = integer_zero_node;
3678
3679 /* If this field does not start in this (or, next) byte,
3680 skip some bytes. */
3681 if (next_offset / BITS_PER_UNIT != total_bytes)
3682 {
3683 /* Output remnant of any bit field in previous bytes. */
3684 if (byte_buffer_in_use)
3685 {
3686 ASM_OUTPUT_BYTE (asm_out_file, byte);
3687 total_bytes++;
3688 byte_buffer_in_use = 0;
3689 }
3690
3691 /* If still not at proper byte, advance to there. */
3692 if (next_offset / BITS_PER_UNIT != total_bytes)
3693 {
3694 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3695 total_bytes = next_offset / BITS_PER_UNIT;
3696 }
3697 }
3698
3699 if (! byte_buffer_in_use)
3700 byte = 0;
3701
3702 /* We must split the element into pieces that fall within
3703 separate bytes, and combine each byte with previous or
3704 following bit-fields. */
3705
3706 /* next_offset is the offset n fbits from the beginning of
3707 the structure to the next bit of this element to be processed.
3708 end_offset is the offset of the first bit past the end of
3709 this element. */
3710 while (next_offset < end_offset)
3711 {
3712 int this_time;
3713 int shift, value;
3714 int next_byte = next_offset / BITS_PER_UNIT;
3715 int next_bit = next_offset % BITS_PER_UNIT;
3716
3717 /* Advance from byte to byte
3718 within this element when necessary. */
3719 while (next_byte != total_bytes)
3720 {
3721 ASM_OUTPUT_BYTE (asm_out_file, byte);
3722 total_bytes++;
3723 byte = 0;
3724 }
3725
3726 /* Number of bits we can process at once
3727 (all part of the same byte). */
3728 this_time = MIN (end_offset - next_offset,
3729 BITS_PER_UNIT - next_bit);
3730 #if BYTES_BIG_ENDIAN
3731 /* On big-endian machine, take the most significant bits
3732 first (of the bits that are significant)
3733 and put them into bytes from the most significant end. */
3734 shift = end_offset - next_offset - this_time;
3735 /* Don't try to take a bunch of bits that cross
3736 the word boundary in the INTEGER_CST. */
3737 if (shift < HOST_BITS_PER_WIDE_INT
3738 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3739 {
3740 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3741 shift = HOST_BITS_PER_WIDE_INT;
3742 }
3743
3744 /* Now get the bits from the appropriate constant word. */
3745 if (shift < HOST_BITS_PER_WIDE_INT)
3746 {
3747 value = TREE_INT_CST_LOW (val);
3748 }
3749 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3750 {
3751 value = TREE_INT_CST_HIGH (val);
3752 shift -= HOST_BITS_PER_WIDE_INT;
3753 }
3754 else
3755 abort ();
3756 byte |= (((value >> shift)
3757 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3758 << (BITS_PER_UNIT - this_time - next_bit));
3759 #else
3760 /* On little-endian machines,
3761 take first the least significant bits of the value
3762 and pack them starting at the least significant
3763 bits of the bytes. */
3764 shift = (next_offset
3765 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3766 /* Don't try to take a bunch of bits that cross
3767 the word boundary in the INTEGER_CST. */
3768 if (shift < HOST_BITS_PER_WIDE_INT
3769 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3770 {
3771 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3772 shift = HOST_BITS_PER_WIDE_INT;
3773 }
3774
3775 /* Now get the bits from the appropriate constant word. */
3776 if (shift < HOST_BITS_PER_INT)
3777 value = TREE_INT_CST_LOW (val);
3778 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3779 {
3780 value = TREE_INT_CST_HIGH (val);
3781 shift -= HOST_BITS_PER_WIDE_INT;
3782 }
3783 else
3784 abort ();
3785 byte |= ((value >> shift)
3786 & (((HOST_WIDE_INT) 1 << this_time) - 1)) << next_bit;
3787 #endif
3788 next_offset += this_time;
3789 byte_buffer_in_use = 1;
3790 }
3791 }
3792 }
3793 if (byte_buffer_in_use)
3794 {
3795 ASM_OUTPUT_BYTE (asm_out_file, byte);
3796 total_bytes++;
3797 }
3798 if (total_bytes < size)
3799 assemble_zeros (size - total_bytes);
3800 }
3801
3802
3803 #ifdef HANDLE_SYSV_PRAGMA
3804
3805 /* Support #pragma weak by default if WEAK_ASM_OP and ASM_OUTPUT_DEF
3806 are defined. */
3807 #if defined (WEAK_ASM_OP) && defined (ASM_OUTPUT_DEF)
3808
3809 /* See c-pragma.c for an identical definition. */
3810 enum pragma_state
3811 {
3812 ps_start,
3813 ps_done,
3814 ps_bad,
3815 ps_weak,
3816 ps_name,
3817 ps_equals,
3818 ps_value,
3819 ps_pack,
3820 ps_left,
3821 ps_align,
3822 ps_right
3823 };
3824
3825 /* Output asm to handle ``#pragma weak'' */
3826 void
3827 handle_pragma_weak (what, asm_out_file, name, value)
3828 enum pragma_state what;
3829 FILE *asm_out_file;
3830 char *name, *value;
3831 {
3832 if (what == ps_name || what == ps_value)
3833 {
3834 fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
3835
3836 if (output_bytecode)
3837 BC_OUTPUT_LABELREF (asm_out_file, name);
3838 else
3839 ASM_OUTPUT_LABELREF (asm_out_file, name);
3840
3841 fputc ('\n', asm_out_file);
3842 if (what == ps_value)
3843 ASM_OUTPUT_DEF (asm_out_file, name, value);
3844 }
3845 else if (! (what == ps_done || what == ps_start))
3846 warning ("malformed `#pragma weak'");
3847 }
3848
3849 #endif /* HANDLE_PRAGMA_WEAK or (WEAK_ASM_OP and SET_ASM_OP) */
3850
3851 #endif /* WEAK_ASM_OP && ASM_OUTPUT_DEF */
This page took 0.228395 seconds and 4 git commands to generate.