(store_constructor, ARRAY_TYPE): Use code for non-integer INDEX for
[official-gcc.git] / gcc / varasm.c
bloba89de1a541e360a1ead4de1aeacbf3d2a9dfac70
1 /* Output variables, constants and external declarations, for GNU compiler.
2 Copyright (C) 1987, 88, 89, 92, 93, 1994 Free Software Foundation, Inc.
4 This file is part of GNU CC.
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.
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.
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. */
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.
25 We also output the assembler code for constants stored in memory
26 and are responsible for combining constants with the same value. */
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 "output.h"
38 #include "hard-reg-set.h"
39 #include "regs.h"
40 #include "defaults.h"
41 #include "real.h"
42 #include "bytecode.h"
44 #include "obstack.h"
46 #ifdef XCOFF_DEBUGGING_INFO
47 #include "xcoffout.h"
48 #endif
50 #include <ctype.h>
52 #ifndef ASM_STABS_OP
53 #define ASM_STABS_OP ".stabs"
54 #endif
56 /* This macro gets just the user-specified name
57 out of the string in a SYMBOL_REF. On most machines,
58 we discard the * if any and that's all. */
59 #ifndef STRIP_NAME_ENCODING
60 #define STRIP_NAME_ENCODING(VAR,SYMBOL_NAME) \
61 (VAR) = ((SYMBOL_NAME) + ((SYMBOL_NAME)[0] == '*'))
62 #endif
64 /* File in which assembler code is being written. */
66 extern FILE *asm_out_file;
68 /* The (assembler) name of the first globally-visible object output. */
69 char *first_global_object_name;
71 extern struct obstack *current_obstack;
72 extern struct obstack *saveable_obstack;
73 extern struct obstack *rtl_obstack;
74 extern struct obstack permanent_obstack;
75 #define obstack_chunk_alloc xmalloc
77 /* Number for making the label on the next
78 constant that is stored in memory. */
80 int const_labelno;
82 /* Number for making the label on the next
83 static variable internal to a function. */
85 int var_labelno;
87 /* Carry information from ASM_DECLARE_OBJECT_NAME
88 to ASM_FINISH_DECLARE_OBJECT. */
90 int size_directive_output;
92 /* The last decl for which assemble_variable was called,
93 if it did ASM_DECLARE_OBJECT_NAME.
94 If the last call to assemble_variable didn't do that,
95 this holds 0. */
97 tree last_assemble_variable_decl;
99 /* Nonzero if at least one function definition has been seen. */
100 static int function_defined;
102 struct addr_const;
103 struct constant_descriptor;
104 struct rtx_const;
105 struct pool_constant;
107 static void bc_make_decl_rtl PROTO((tree, char *, int));
108 static char *strip_reg_name PROTO((char *));
109 static void bc_output_ascii PROTO((FILE *, char *, int));
110 static int contains_pointers_p PROTO((tree));
111 static void decode_addr_const PROTO((tree, struct addr_const *));
112 static int const_hash PROTO((tree));
113 static int compare_constant PROTO((tree,
114 struct constant_descriptor *));
115 static char *compare_constant_1 PROTO((tree, char *));
116 static struct constant_descriptor *record_constant PROTO((tree));
117 static void record_constant_1 PROTO((tree));
118 static tree copy_constant PROTO((tree));
119 static void output_constant_def_contents PROTO((tree, int, int));
120 static void decode_rtx_const PROTO((enum machine_mode, rtx,
121 struct rtx_const *));
122 static int const_hash_rtx PROTO((enum machine_mode, rtx));
123 static int compare_constant_rtx PROTO((enum machine_mode, rtx,
124 struct constant_descriptor *));
125 static struct constant_descriptor *record_constant_rtx PROTO((enum machine_mode,
126 rtx));
127 static struct pool_constant *find_pool_constant PROTO((rtx));
128 static int output_addressed_constants PROTO((tree));
129 static void bc_assemble_integer PROTO((tree, int));
130 static void output_constructor PROTO((tree, int));
132 #ifdef EXTRA_SECTIONS
133 static enum in_section {no_section, in_text, in_data, in_named, EXTRA_SECTIONS} in_section
134 = no_section;
135 #else
136 static enum in_section {no_section, in_text, in_data, in_named} in_section
137 = no_section;
138 #endif
140 /* Return a non-zero value if DECL has a section attribute. */
141 #define IN_NAMED_SECTION(DECL) \
142 ((TREE_CODE (DECL) == FUNCTION_DECL || TREE_CODE (DECL) == VAR_DECL) \
143 && DECL_SECTION_NAME (DECL) != NULL_TREE)
145 /* Text of section name when in_section == in_named. */
146 static char *in_named_name;
148 /* Define functions like text_section for any extra sections. */
149 #ifdef EXTRA_SECTION_FUNCTIONS
150 EXTRA_SECTION_FUNCTIONS
151 #endif
153 /* Tell assembler to switch to text section. */
155 void
156 text_section ()
158 if (in_section != in_text)
160 if (output_bytecode)
161 bc_text ();
162 else
163 fprintf (asm_out_file, "%s\n", TEXT_SECTION_ASM_OP);
165 in_section = in_text;
169 /* Tell assembler to switch to data section. */
171 void
172 data_section ()
174 if (in_section != in_data)
176 if (output_bytecode)
177 bc_data ();
178 else
180 if (flag_shared_data)
182 #ifdef SHARED_SECTION_ASM_OP
183 fprintf (asm_out_file, "%s\n", SHARED_SECTION_ASM_OP);
184 #else
185 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
186 #endif
188 else
189 fprintf (asm_out_file, "%s\n", DATA_SECTION_ASM_OP);
192 in_section = in_data;
196 /* Tell assembler to switch to read-only data section. This is normally
197 the text section. */
199 void
200 readonly_data_section ()
202 #ifdef READONLY_DATA_SECTION
203 READONLY_DATA_SECTION (); /* Note this can call data_section. */
204 #else
205 text_section ();
206 #endif
209 /* Determine if we're in the text section. */
212 in_text_section ()
214 return in_section == in_text;
217 /* Tell assembler to change to section NAME for DECL.
218 If DECL is NULL, just switch to section NAME.
219 If NAME is NULL, get the name from DECL. */
221 void
222 named_section (decl, name)
223 tree decl;
224 char *name;
226 if (decl != NULL_TREE
227 && (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL))
228 abort ();
229 if (name == NULL)
230 name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
232 if (in_section != in_named || strcmp (name, in_named_name))
234 in_named_name = name;
235 in_section = in_named;
237 #ifdef ASM_OUTPUT_SECTION_NAME
238 ASM_OUTPUT_SECTION_NAME (asm_out_file, decl, name);
239 #else
240 /* Section attributes are not supported if this macro isn't provided -
241 some host formats don't support them at all. The front-end should
242 already have flagged this as an error. */
243 abort ();
244 #endif
248 /* Create the rtl to represent a function, for a function definition.
249 DECL is a FUNCTION_DECL node which describes which function.
250 The rtl is stored into DECL. */
252 void
253 make_function_rtl (decl)
254 tree decl;
256 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
258 if (output_bytecode)
260 if (DECL_RTL (decl) == 0)
261 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
263 /* Record that at least one function has been defined. */
264 function_defined = 1;
265 return;
268 /* Rename a nested function to avoid conflicts. */
269 if (decl_function_context (decl) != 0
270 && DECL_INITIAL (decl) != 0
271 && DECL_RTL (decl) == 0)
273 char *label;
275 name = IDENTIFIER_POINTER (DECL_NAME (decl));
276 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
277 name = obstack_copy0 (saveable_obstack, label, strlen (label));
278 var_labelno++;
281 if (DECL_RTL (decl) == 0)
283 DECL_RTL (decl)
284 = gen_rtx (MEM, DECL_MODE (decl),
285 gen_rtx (SYMBOL_REF, Pmode, name));
287 /* Optionally set flags or add text to the name to record information
288 such as that it is a function name. If the name is changed, the macro
289 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
290 #ifdef ENCODE_SECTION_INFO
291 ENCODE_SECTION_INFO (decl);
292 #endif
295 /* Record at least one function has been defined. */
296 function_defined = 1;
299 /* Create the DECL_RTL for a declaration for a static or external
300 variable or static or external function.
301 ASMSPEC, if not 0, is the string which the user specified
302 as the assembler symbol name.
303 TOP_LEVEL is nonzero if this is a file-scope variable.
304 This is never called for PARM_DECLs. */
306 static void
307 bc_make_decl_rtl (decl, asmspec, top_level)
308 tree decl;
309 char *asmspec;
310 int top_level;
312 register char *name = TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl));
314 if (DECL_RTL (decl) == 0)
316 /* Print an error message for register variables. */
317 if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
318 error ("function declared `register'");
319 else if (DECL_REGISTER (decl))
320 error ("global register variables not supported in the interpreter");
322 /* Handle ordinary static variables and functions. */
323 if (DECL_RTL (decl) == 0)
325 /* Can't use just the variable's own name for a variable
326 whose scope is less than the whole file.
327 Concatenate a distinguishing number. */
328 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
330 char *label;
332 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
333 name = obstack_copy0 (saveable_obstack, label, strlen (label));
334 var_labelno++;
337 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
342 /* Given NAME, a putative register name, discard any customary prefixes. */
344 static char *
345 strip_reg_name (name)
346 char *name;
348 #ifdef REGISTER_PREFIX
349 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
350 name += strlen (REGISTER_PREFIX);
351 #endif
352 if (name[0] == '%' || name[0] == '#')
353 name++;
354 return name;
357 /* Decode an `asm' spec for a declaration as a register name.
358 Return the register number, or -1 if nothing specified,
359 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
360 or -3 if ASMSPEC is `cc' and is not recognized,
361 or -4 if ASMSPEC is `memory' and is not recognized.
362 Accept an exact spelling or a decimal number.
363 Prefixes such as % are optional. */
366 decode_reg_name (asmspec)
367 char *asmspec;
369 if (asmspec != 0)
371 int i;
373 /* Get rid of confusing prefixes. */
374 asmspec = strip_reg_name (asmspec);
376 /* Allow a decimal number as a "register name". */
377 for (i = strlen (asmspec) - 1; i >= 0; i--)
378 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
379 break;
380 if (asmspec[0] != 0 && i < 0)
382 i = atoi (asmspec);
383 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
384 return i;
385 else
386 return -2;
389 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
390 if (reg_names[i][0]
391 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
392 return i;
394 #ifdef ADDITIONAL_REGISTER_NAMES
396 static struct { char *name; int number; } table[]
397 = ADDITIONAL_REGISTER_NAMES;
399 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
400 if (! strcmp (asmspec, table[i].name))
401 return table[i].number;
403 #endif /* ADDITIONAL_REGISTER_NAMES */
405 if (!strcmp (asmspec, "memory"))
406 return -4;
408 if (!strcmp (asmspec, "cc"))
409 return -3;
411 return -2;
414 return -1;
417 /* Create the DECL_RTL for a declaration for a static or external variable
418 or static or external function.
419 ASMSPEC, if not 0, is the string which the user specified
420 as the assembler symbol name.
421 TOP_LEVEL is nonzero if this is a file-scope variable.
423 This is never called for PARM_DECL nodes. */
425 void
426 make_decl_rtl (decl, asmspec, top_level)
427 tree decl;
428 char *asmspec;
429 int top_level;
431 register char *name = 0;
432 int reg_number;
434 if (output_bytecode)
436 bc_make_decl_rtl (decl, asmspec, top_level);
437 return;
440 reg_number = decode_reg_name (asmspec);
442 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
443 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
445 if (reg_number == -2)
447 /* ASMSPEC is given, and not the name of a register. */
448 name = (char *) obstack_alloc (saveable_obstack,
449 strlen (asmspec) + 2);
450 name[0] = '*';
451 strcpy (&name[1], asmspec);
454 /* For a duplicate declaration, we can be called twice on the
455 same DECL node. Don't discard the RTL already made. */
456 if (DECL_RTL (decl) == 0)
458 DECL_RTL (decl) = 0;
460 /* First detect errors in declaring global registers. */
461 if (DECL_REGISTER (decl) && reg_number == -1)
462 error_with_decl (decl,
463 "register name not specified for `%s'");
464 else if (DECL_REGISTER (decl) && reg_number < 0)
465 error_with_decl (decl,
466 "invalid register name for `%s'");
467 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
468 error_with_decl (decl,
469 "register name given for non-register variable `%s'");
470 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
471 error ("function declared `register'");
472 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
473 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
474 else if (DECL_REGISTER (decl)
475 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
476 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
477 /* Now handle properly declared static register variables. */
478 else if (DECL_REGISTER (decl))
480 int nregs;
481 #if 0 /* yylex should print the warning for this */
482 if (pedantic)
483 pedwarn ("ANSI C forbids global register variables");
484 #endif
485 if (DECL_INITIAL (decl) != 0 && top_level)
487 DECL_INITIAL (decl) = 0;
488 error ("global register variable has initial value");
490 if (fixed_regs[reg_number] == 0
491 && function_defined && top_level)
492 error ("global register variable follows a function definition");
493 if (TREE_THIS_VOLATILE (decl))
494 warning ("volatile register variables don't work as you might wish");
496 /* If the user specified one of the eliminables registers here,
497 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
498 confused with that register and be eliminated. Although this
499 usage is somewhat suspect, we nevertheless use the following
500 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
502 DECL_RTL (decl)
503 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
504 REGNO (DECL_RTL (decl)) = reg_number;
505 REG_USERVAR_P (DECL_RTL (decl)) = 1;
507 if (top_level)
509 /* Make this register global, so not usable for anything
510 else. */
511 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
512 while (nregs > 0)
513 globalize_reg (reg_number + --nregs);
516 /* Specifying a section attribute on an uninitialized variable does not
517 (and cannot) cause it to be put in the given section. The linker
518 can only put initialized objects in specific sections, everything
519 else goes in bss for the linker to sort out later (otherwise the
520 linker would give a duplicate definition error for each compilation
521 unit that behaved thusly). So warn the user. */
522 else if (TREE_CODE (decl) == VAR_DECL
523 && DECL_SECTION_NAME (decl) != NULL_TREE
524 && DECL_INITIAL (decl) == NULL_TREE)
526 warning_with_decl (decl,
527 "section attribute ignored for uninitialized variable `%s'");
528 /* Remove the section name so subsequent declarations won't see it.
529 We are ignoring it, remember. */
530 DECL_SECTION_NAME (decl) = NULL_TREE;
533 /* Now handle ordinary static variables and functions (in memory).
534 Also handle vars declared register invalidly. */
535 if (DECL_RTL (decl) == 0)
537 /* Can't use just the variable's own name for a variable
538 whose scope is less than the whole file.
539 Concatenate a distinguishing number. */
540 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
542 char *label;
544 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
545 name = obstack_copy0 (saveable_obstack, label, strlen (label));
546 var_labelno++;
549 if (name == 0)
550 abort ();
552 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
553 gen_rtx (SYMBOL_REF, Pmode, name));
555 /* If this variable is to be treated as volatile, show its
556 tree node has side effects. If it has side effects, either
557 because of this test or from TREE_THIS_VOLATILE also
558 being set, show the MEM is volatile. */
559 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
560 && TREE_PUBLIC (decl))
561 TREE_SIDE_EFFECTS (decl) = 1;
562 if (TREE_SIDE_EFFECTS (decl))
563 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
565 if (TREE_READONLY (decl))
566 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
567 MEM_IN_STRUCT_P (DECL_RTL (decl))
568 = AGGREGATE_TYPE_P (TREE_TYPE (decl));
570 /* Optionally set flags or add text to the name to record information
571 such as that it is a function name.
572 If the name is changed, the macro ASM_OUTPUT_LABELREF
573 will have to know how to strip this information. */
574 #ifdef ENCODE_SECTION_INFO
575 ENCODE_SECTION_INFO (decl);
576 #endif
579 /* If the old RTL had the wrong mode, fix the mode. */
580 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
582 rtx rtl = DECL_RTL (decl);
583 PUT_MODE (rtl, DECL_MODE (decl));
587 /* Make the rtl for variable VAR be volatile.
588 Use this only for static variables. */
590 void
591 make_var_volatile (var)
592 tree var;
594 if (GET_CODE (DECL_RTL (var)) != MEM)
595 abort ();
597 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
600 /* Output alignment directive to align for constant expression EXP. */
602 void
603 assemble_constant_align (exp)
604 tree exp;
606 int align;
608 /* Align the location counter as required by EXP's data type. */
609 align = TYPE_ALIGN (TREE_TYPE (exp));
610 #ifdef CONSTANT_ALIGNMENT
611 align = CONSTANT_ALIGNMENT (exp, align);
612 #endif
614 if (align > BITS_PER_UNIT)
615 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
618 /* Output a string of literal assembler code
619 for an `asm' keyword used between functions. */
621 void
622 assemble_asm (string)
623 tree string;
625 if (output_bytecode)
627 error ("asm statements not allowed in interpreter");
628 return;
631 app_enable ();
633 if (TREE_CODE (string) == ADDR_EXPR)
634 string = TREE_OPERAND (string, 0);
636 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
639 #if 0 /* This should no longer be needed, because
640 flag_gnu_linker should be 0 on these systems,
641 which should prevent any output
642 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
643 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
644 #ifndef ASM_OUTPUT_CONSTRUCTOR
645 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
646 #endif
647 #ifndef ASM_OUTPUT_DESTRUCTOR
648 #define ASM_OUTPUT_DESTRUCTOR(file, name)
649 #endif
650 #endif
651 #endif /* 0 */
653 /* Record an element in the table of global destructors.
654 How this is done depends on what sort of assembler and linker
655 are in use.
657 NAME should be the name of a global function to be called
658 at exit time. This name is output using assemble_name. */
660 void
661 assemble_destructor (name)
662 char *name;
664 #ifdef ASM_OUTPUT_DESTRUCTOR
665 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
666 #else
667 if (flag_gnu_linker)
669 /* Now tell GNU LD that this is part of the static destructor set. */
670 /* This code works for any machine provided you use GNU as/ld. */
671 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
672 assemble_name (asm_out_file, name);
673 fputc ('\n', asm_out_file);
675 #endif
678 /* Likewise for global constructors. */
680 void
681 assemble_constructor (name)
682 char *name;
684 #ifdef ASM_OUTPUT_CONSTRUCTOR
685 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
686 #else
687 if (flag_gnu_linker)
689 /* Now tell GNU LD that this is part of the static constructor set. */
690 /* This code works for any machine provided you use GNU as/ld. */
691 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
692 assemble_name (asm_out_file, name);
693 fputc ('\n', asm_out_file);
695 #endif
698 /* Likewise for entries we want to record for garbage collection.
699 Garbage collection is still under development. */
701 void
702 assemble_gc_entry (name)
703 char *name;
705 #ifdef ASM_OUTPUT_GC_ENTRY
706 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
707 #else
708 if (flag_gnu_linker)
710 /* Now tell GNU LD that this is part of the static constructor set. */
711 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
712 assemble_name (asm_out_file, name);
713 fputc ('\n', asm_out_file);
715 #endif
718 /* Output assembler code for the constant pool of a function and associated
719 with defining the name of the function. DECL describes the function.
720 NAME is the function's name. For the constant pool, we use the current
721 constant pool data. */
723 void
724 assemble_start_function (decl, fnname)
725 tree decl;
726 char *fnname;
728 int align;
730 /* The following code does not need preprocessing in the assembler. */
732 app_disable ();
734 output_constant_pool (fnname, decl);
736 if (IN_NAMED_SECTION (decl))
737 named_section (decl, NULL);
738 else
739 text_section ();
741 /* Tell assembler to move to target machine's alignment for functions. */
742 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
743 if (align > 0)
745 if (output_bytecode)
746 BC_OUTPUT_ALIGN (asm_out_file, align);
747 else
748 ASM_OUTPUT_ALIGN (asm_out_file, align);
751 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
752 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
753 #endif
755 #ifdef SDB_DEBUGGING_INFO
756 /* Output SDB definition of the function. */
757 if (write_symbols == SDB_DEBUG)
758 sdbout_mark_begin_function ();
759 #endif
761 #ifdef DBX_DEBUGGING_INFO
762 /* Output DBX definition of the function. */
763 if (write_symbols == DBX_DEBUG)
764 dbxout_begin_function (decl);
765 #endif
767 /* Make function name accessible from other files, if appropriate. */
769 if (TREE_PUBLIC (decl))
771 if (!first_global_object_name)
772 STRIP_NAME_ENCODING (first_global_object_name, fnname);
773 if (output_bytecode)
774 BC_GLOBALIZE_LABEL (asm_out_file, fnname);
775 else
776 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
779 /* Do any machine/system dependent processing of the function name */
780 #ifdef ASM_DECLARE_FUNCTION_NAME
781 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
782 #else
783 /* Standard thing is just output label for the function. */
784 if (output_bytecode)
785 BC_OUTPUT_LABEL (asm_out_file, fnname);
786 else
787 ASM_OUTPUT_LABEL (asm_out_file, fnname);
788 #endif /* ASM_DECLARE_FUNCTION_NAME */
791 /* Output assembler code associated with defining the size of the
792 function. DECL describes the function. NAME is the function's name. */
794 void
795 assemble_end_function (decl, fnname)
796 tree decl;
797 char *fnname;
799 #ifdef ASM_DECLARE_FUNCTION_SIZE
800 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
801 #endif
804 /* Assemble code to leave SIZE bytes of zeros. */
806 void
807 assemble_zeros (size)
808 int size;
810 if (output_bytecode)
812 bc_emit_const_skip (size);
813 return;
816 #ifdef ASM_NO_SKIP_IN_TEXT
817 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
818 so we must output 0s explicitly in the text section. */
819 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
821 int i;
823 for (i = 0; i < size - 20; i += 20)
825 #ifdef ASM_BYTE_OP
826 fprintf (asm_out_file,
827 "%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);
828 #else
829 fprintf (asm_out_file,
830 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
831 #endif
833 if (i < size)
835 #ifdef ASM_BYTE_OP
836 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
837 #else
838 fprintf (asm_out_file, "\tbyte 0");
839 #endif
840 i++;
841 for (; i < size; i++)
842 fprintf (asm_out_file, ",0");
843 fprintf (asm_out_file, "\n");
846 else
847 #endif
848 if (size > 0)
850 if (output_bytecode)
851 BC_OUTPUT_SKIP (asm_out_file, size);
852 else
853 ASM_OUTPUT_SKIP (asm_out_file, size);
857 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
859 void
860 assemble_align (align)
861 int align;
863 if (align > BITS_PER_UNIT)
864 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
867 /* Assemble a string constant with the specified C string as contents. */
869 void
870 assemble_string (p, size)
871 char *p;
872 int size;
874 register int i;
875 int pos = 0;
876 int maximum = 2000;
878 if (output_bytecode)
880 bc_emit (p, size);
881 return;
884 /* If the string is very long, split it up. */
886 while (pos < size)
888 int thissize = size - pos;
889 if (thissize > maximum)
890 thissize = maximum;
892 if (output_bytecode)
893 bc_output_ascii (asm_out_file, p, thissize);
894 else
896 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
899 pos += thissize;
900 p += thissize;
904 static void
905 bc_output_ascii (file, p, size)
906 FILE *file;
907 char *p;
908 int size;
910 BC_OUTPUT_ASCII (file, p, size);
913 /* Assemble everything that is needed for a variable or function declaration.
914 Not used for automatic variables, and not used for function definitions.
915 Should not be called for variables of incomplete structure type.
917 TOP_LEVEL is nonzero if this variable has file scope.
918 AT_END is nonzero if this is the special handling, at end of compilation,
919 to define things that have had only tentative definitions.
920 DONT_OUTPUT_DATA if nonzero means don't actually output the
921 initial value (that will be done by the caller). */
923 void
924 assemble_variable (decl, top_level, at_end, dont_output_data)
925 tree decl;
926 int top_level;
927 int at_end;
928 int dont_output_data;
930 register char *name;
931 int align;
932 tree size_tree;
933 int reloc = 0;
934 enum in_section saved_in_section;
936 last_assemble_variable_decl = 0;
938 if (output_bytecode)
939 return;
941 if (GET_CODE (DECL_RTL (decl)) == REG)
943 /* Do output symbol info for global register variables, but do nothing
944 else for them. */
946 if (TREE_ASM_WRITTEN (decl))
947 return;
948 TREE_ASM_WRITTEN (decl) = 1;
950 if (!output_bytecode)
952 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
953 /* File-scope global variables are output here. */
954 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
955 && top_level)
956 dbxout_symbol (decl, 0);
957 #endif
958 #ifdef SDB_DEBUGGING_INFO
959 if (write_symbols == SDB_DEBUG && top_level
960 /* Leave initialized global vars for end of compilation;
961 see comment in compile_file. */
962 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
963 sdbout_symbol (decl, 0);
964 #endif
967 /* Don't output any DWARF debugging information for variables here.
968 In the case of local variables, the information for them is output
969 when we do our recursive traversal of the tree representation for
970 the entire containing function. In the case of file-scope variables,
971 we output information for all of them at the very end of compilation
972 while we are doing our final traversal of the chain of file-scope
973 declarations. */
975 return;
978 /* Normally no need to say anything here for external references,
979 since assemble_external is called by the langauge-specific code
980 when a declaration is first seen. */
982 if (DECL_EXTERNAL (decl))
983 return;
985 /* Output no assembler code for a function declaration.
986 Only definitions of functions output anything. */
988 if (TREE_CODE (decl) == FUNCTION_DECL)
989 return;
991 /* If type was incomplete when the variable was declared,
992 see if it is complete now. */
994 if (DECL_SIZE (decl) == 0)
995 layout_decl (decl, 0);
997 /* Still incomplete => don't allocate it; treat the tentative defn
998 (which is what it must have been) as an `extern' reference. */
1000 if (!dont_output_data && DECL_SIZE (decl) == 0)
1002 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1003 DECL_SOURCE_LINE (decl),
1004 "storage size of `%s' isn't known",
1005 IDENTIFIER_POINTER (DECL_NAME (decl)));
1006 TREE_ASM_WRITTEN (decl) = 1;
1007 return;
1010 /* The first declaration of a variable that comes through this function
1011 decides whether it is global (in C, has external linkage)
1012 or local (in C, has internal linkage). So do nothing more
1013 if this function has already run. */
1015 if (TREE_ASM_WRITTEN (decl))
1016 return;
1018 TREE_ASM_WRITTEN (decl) = 1;
1020 /* If storage size is erroneously variable, just continue.
1021 Error message was already made. */
1023 if (DECL_SIZE (decl))
1025 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1026 goto finish;
1028 app_disable ();
1030 /* This is better than explicit arithmetic, since it avoids overflow. */
1031 size_tree = size_binop (CEIL_DIV_EXPR,
1032 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1034 if (TREE_INT_CST_HIGH (size_tree) != 0)
1036 error_with_decl (decl, "size of variable `%s' is too large");
1037 goto finish;
1041 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1043 /* Handle uninitialized definitions. */
1045 /* ANSI specifies that a tentative definition which is not merged with
1046 a non-tentative definition behaves exactly like a definition with an
1047 initializer equal to zero. (Section 3.7.2)
1048 -fno-common gives strict ANSI behavior. Usually you don't want it.
1049 This matters only for variables with external linkage. */
1050 if ((! flag_no_common || ! TREE_PUBLIC (decl))
1051 && DECL_COMMON (decl)
1052 && ! dont_output_data
1053 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
1055 int size = TREE_INT_CST_LOW (size_tree);
1056 int rounded = size;
1058 if (TREE_INT_CST_HIGH (size_tree) != 0)
1059 error_with_decl (decl, "size of variable `%s' is too large");
1060 /* Don't allocate zero bytes of common,
1061 since that means "undefined external" in the linker. */
1062 if (size == 0) rounded = 1;
1063 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1064 so that each uninitialized object starts on such a boundary. */
1065 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1066 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1067 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1069 #ifdef DBX_DEBUGGING_INFO
1070 /* File-scope global variables are output here. */
1071 if (write_symbols == DBX_DEBUG && top_level)
1072 dbxout_symbol (decl, 0);
1073 #endif
1074 #ifdef SDB_DEBUGGING_INFO
1075 if (write_symbols == SDB_DEBUG && top_level
1076 /* Leave initialized global vars for end of compilation;
1077 see comment in compile_file. */
1078 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1079 sdbout_symbol (decl, 0);
1080 #endif
1082 /* Don't output any DWARF debugging information for variables here.
1083 In the case of local variables, the information for them is output
1084 when we do our recursive traversal of the tree representation for
1085 the entire containing function. In the case of file-scope variables,
1086 we output information for all of them at the very end of compilation
1087 while we are doing our final traversal of the chain of file-scope
1088 declarations. */
1090 #if 0
1091 if (flag_shared_data)
1092 data_section ();
1093 #endif
1094 if (TREE_PUBLIC (decl))
1096 #ifdef ASM_OUTPUT_SHARED_COMMON
1097 if (flag_shared_data)
1098 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1099 else
1100 #endif
1101 if (output_bytecode)
1103 BC_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1105 else
1107 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1108 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1109 DECL_ALIGN (decl));
1110 #else
1111 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1112 #endif
1115 else
1117 #ifdef ASM_OUTPUT_SHARED_LOCAL
1118 if (flag_shared_data)
1119 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1120 else
1121 #endif
1122 if (output_bytecode)
1124 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1126 else
1128 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1129 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1130 DECL_ALIGN (decl));
1131 #else
1132 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1133 #endif
1136 goto finish;
1139 /* Handle initialized definitions. */
1141 /* First make the assembler name(s) global if appropriate. */
1142 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1144 if (!first_global_object_name)
1145 STRIP_NAME_ENCODING(first_global_object_name, name);
1146 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1148 #if 0
1149 for (d = equivalents; d; d = TREE_CHAIN (d))
1151 tree e = TREE_VALUE (d);
1152 if (TREE_PUBLIC (e) && DECL_NAME (e))
1153 ASM_GLOBALIZE_LABEL (asm_out_file,
1154 XSTR (XEXP (DECL_RTL (e), 0), 0));
1156 #endif
1158 /* Output any data that we will need to use the address of. */
1159 if (DECL_INITIAL (decl) == error_mark_node)
1160 reloc = contains_pointers_p (TREE_TYPE (decl));
1161 else if (DECL_INITIAL (decl))
1162 reloc = output_addressed_constants (DECL_INITIAL (decl));
1164 /* Switch to the proper section for this data. */
1165 if (IN_NAMED_SECTION (decl))
1166 named_section (decl, NULL);
1167 else
1169 /* C++ can have const variables that get initialized from constructors,
1170 and thus can not be in a readonly section. We prevent this by
1171 verifying that the initial value is constant for objects put in a
1172 readonly section.
1174 error_mark_node is used by the C front end to indicate that the
1175 initializer has not been seen yet. In this case, we assume that
1176 the initializer must be constant. */
1177 #ifdef SELECT_SECTION
1178 SELECT_SECTION (decl, reloc);
1179 #else
1180 if (TREE_READONLY (decl)
1181 && ! TREE_THIS_VOLATILE (decl)
1182 && DECL_INITIAL (decl)
1183 && (DECL_INITIAL (decl) == error_mark_node
1184 || TREE_CONSTANT (DECL_INITIAL (decl)))
1185 && ! (flag_pic && reloc))
1186 readonly_data_section ();
1187 else
1188 data_section ();
1189 #endif
1192 /* dbxout.c needs to know this. */
1193 if (in_text_section ())
1194 DECL_IN_TEXT_SECTION (decl) = 1;
1196 /* Record current section so we can restore it if dbxout.c clobbers it. */
1197 saved_in_section = in_section;
1199 /* Output the dbx info now that we have chosen the section. */
1201 #ifdef DBX_DEBUGGING_INFO
1202 /* File-scope global variables are output here. */
1203 if (write_symbols == DBX_DEBUG && top_level)
1204 dbxout_symbol (decl, 0);
1205 #endif
1206 #ifdef SDB_DEBUGGING_INFO
1207 if (write_symbols == SDB_DEBUG && top_level
1208 /* Leave initialized global vars for end of compilation;
1209 see comment in compile_file. */
1210 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1211 sdbout_symbol (decl, 0);
1212 #endif
1214 /* Don't output any DWARF debugging information for variables here.
1215 In the case of local variables, the information for them is output
1216 when we do our recursive traversal of the tree representation for
1217 the entire containing function. In the case of file-scope variables,
1218 we output information for all of them at the very end of compilation
1219 while we are doing our final traversal of the chain of file-scope
1220 declarations. */
1222 /* If the debugging output changed sections, reselect the section
1223 that's supposed to be selected. */
1224 if (in_section != saved_in_section)
1226 /* Switch to the proper section for this data. */
1227 #ifdef SELECT_SECTION
1228 SELECT_SECTION (decl, reloc);
1229 #else
1230 if (TREE_READONLY (decl)
1231 && ! TREE_THIS_VOLATILE (decl)
1232 && DECL_INITIAL (decl)
1233 && (DECL_INITIAL (decl) == error_mark_node
1234 || TREE_CONSTANT (DECL_INITIAL (decl)))
1235 && ! (flag_pic && reloc))
1236 readonly_data_section ();
1237 else
1238 data_section ();
1239 #endif
1242 /* Compute and output the alignment of this data. */
1244 align = DECL_ALIGN (decl);
1245 /* In the case for initialing an array whose length isn't specified,
1246 where we have not yet been able to do the layout,
1247 figure out the proper alignment now. */
1248 if (dont_output_data && DECL_SIZE (decl) == 0
1249 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1250 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1252 /* Some object file formats have a maximum alignment which they support.
1253 In particular, a.out format supports a maximum alignment of 4. */
1254 #ifndef MAX_OFILE_ALIGNMENT
1255 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1256 #endif
1257 if (align > MAX_OFILE_ALIGNMENT)
1259 warning_with_decl (decl,
1260 "alignment of `%s' is greater than maximum object file alignment");
1261 align = MAX_OFILE_ALIGNMENT;
1263 #ifdef DATA_ALIGNMENT
1264 /* On some machines, it is good to increase alignment sometimes. */
1265 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1266 #endif
1267 #ifdef CONSTANT_ALIGNMENT
1268 if (DECL_INITIAL (decl))
1269 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1270 #endif
1272 /* Reset the alignment in case we have made it tighter, so we can benefit
1273 from it in get_pointer_alignment. */
1274 DECL_ALIGN (decl) = align;
1276 if (align > BITS_PER_UNIT)
1278 if (output_bytecode)
1279 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1280 else
1281 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1284 /* Do any machine/system dependent processing of the object. */
1285 #ifdef ASM_DECLARE_OBJECT_NAME
1286 last_assemble_variable_decl = decl;
1287 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1288 #else
1289 /* Standard thing is just output label for the object. */
1290 if (output_bytecode)
1291 BC_OUTPUT_LABEL (asm_out_file, name);
1292 else
1293 ASM_OUTPUT_LABEL (asm_out_file, name);
1294 #endif /* ASM_DECLARE_OBJECT_NAME */
1296 if (!dont_output_data)
1298 if (DECL_INITIAL (decl))
1299 /* Output the actual data. */
1300 output_constant (DECL_INITIAL (decl),
1301 int_size_in_bytes (TREE_TYPE (decl)));
1302 else
1303 /* Leave space for it. */
1304 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1307 finish:
1308 #ifdef XCOFF_DEBUGGING_INFO
1309 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1310 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1311 and `aa' hasn't been output yet, the assembler generates a stab entry with
1312 a value of zero, in addition to creating an unnecessary external entry
1313 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1315 /* File-scope global variables are output here. */
1316 if (write_symbols == XCOFF_DEBUG && top_level)
1318 saved_in_section = in_section;
1320 dbxout_symbol (decl, 0);
1322 if (in_section != saved_in_section)
1324 /* Switch to the proper section for this data. */
1325 #ifdef SELECT_SECTION
1326 SELECT_SECTION (decl, reloc);
1327 #else
1328 if (TREE_READONLY (decl)
1329 && ! TREE_THIS_VOLATILE (decl)
1330 && DECL_INITIAL (decl)
1331 && (DECL_INITIAL (decl) == error_mark_node
1332 || TREE_CONSTANT (DECL_INITIAL (decl)))
1333 && ! (flag_pic && reloc))
1334 readonly_data_section ();
1335 else
1336 data_section ();
1337 #endif
1340 #else
1341 /* There must be a statement after a label. */
1343 #endif
1346 /* Return 1 if type TYPE contains any pointers. */
1348 static int
1349 contains_pointers_p (type)
1350 tree type;
1352 switch (TREE_CODE (type))
1354 case POINTER_TYPE:
1355 case REFERENCE_TYPE:
1356 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1357 so I'll play safe and return 1. */
1358 case OFFSET_TYPE:
1359 return 1;
1361 case RECORD_TYPE:
1362 case UNION_TYPE:
1363 case QUAL_UNION_TYPE:
1365 tree fields;
1366 /* For a type that has fields, see if the fields have pointers. */
1367 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1368 if (TREE_CODE (fields) == FIELD_DECL
1369 && contains_pointers_p (TREE_TYPE (fields)))
1370 return 1;
1371 return 0;
1374 case ARRAY_TYPE:
1375 /* An array type contains pointers if its element type does. */
1376 return contains_pointers_p (TREE_TYPE (type));
1378 default:
1379 return 0;
1383 /* Output text storage for constructor CONSTR. */
1385 void
1386 bc_output_constructor (constr, size)
1387 tree constr;
1388 int size;
1390 int i;
1392 /* Must always be a literal; non-literal constructors are handled
1393 differently. */
1395 if (!TREE_CONSTANT (constr))
1396 abort ();
1398 /* Always const */
1399 text_section ();
1401 /* Align */
1402 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++)
1405 if (i > 0)
1406 BC_OUTPUT_ALIGN (asm_out_file, i);
1408 /* Output data */
1409 output_constant (constr, size);
1412 /* Create storage for constructor CONSTR. */
1414 void
1415 bc_output_data_constructor (constr)
1416 tree constr;
1418 int i;
1420 /* Put in data section */
1421 data_section ();
1423 /* Align */
1424 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1425 if (i > 0)
1426 BC_OUTPUT_ALIGN (asm_out_file, i);
1428 /* The constructor is filled in at runtime. */
1429 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1432 /* Output something to declare an external symbol to the assembler.
1433 (Most assemblers don't need this, so we normally output nothing.)
1434 Do nothing if DECL is not external. */
1436 void
1437 assemble_external (decl)
1438 tree decl;
1440 if (output_bytecode)
1441 return;
1443 #ifdef ASM_OUTPUT_EXTERNAL
1444 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1445 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1447 rtx rtl = DECL_RTL (decl);
1449 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1450 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1452 /* Some systems do require some output. */
1453 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1454 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1457 #endif
1460 /* Similar, for calling a library function FUN. */
1462 void
1463 assemble_external_libcall (fun)
1464 rtx fun;
1466 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1467 if (!output_bytecode)
1469 /* Declare library function name external when first used, if nec. */
1470 if (! SYMBOL_REF_USED (fun))
1472 SYMBOL_REF_USED (fun) = 1;
1473 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1476 #endif
1479 /* Declare the label NAME global. */
1481 void
1482 assemble_global (name)
1483 char *name;
1485 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1488 /* Assemble a label named NAME. */
1490 void
1491 assemble_label (name)
1492 char *name;
1494 if (output_bytecode)
1495 BC_OUTPUT_LABEL (asm_out_file, name);
1496 else
1497 ASM_OUTPUT_LABEL (asm_out_file, name);
1500 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1501 If NAME starts with a *, the rest of NAME is output verbatim.
1502 Otherwise NAME is transformed in an implementation-defined way
1503 (usually by the addition of an underscore).
1504 Many macros in the tm file are defined to call this function. */
1506 void
1507 assemble_name (file, name)
1508 FILE *file;
1509 char *name;
1511 char *real_name;
1513 STRIP_NAME_ENCODING (real_name, name);
1514 TREE_SYMBOL_REFERENCED (get_identifier (real_name)) = 1;
1516 if (name[0] == '*')
1518 if (output_bytecode)
1519 bc_emit_labelref (name);
1520 else
1521 fputs (&name[1], file);
1523 else
1525 if (output_bytecode)
1526 BC_OUTPUT_LABELREF (file, name);
1527 else
1528 ASM_OUTPUT_LABELREF (file, name);
1532 /* Allocate SIZE bytes writable static space with a gensym name
1533 and return an RTX to refer to its address. */
1536 assemble_static_space (size)
1537 int size;
1539 char name[12];
1540 char *namestring;
1541 rtx x;
1542 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1543 so that each uninitialized object starts on such a boundary. */
1544 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1545 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1546 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1548 #if 0
1549 if (flag_shared_data)
1550 data_section ();
1551 #endif
1553 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1554 ++const_labelno;
1556 namestring = (char *) obstack_alloc (saveable_obstack,
1557 strlen (name) + 2);
1558 strcpy (namestring, name);
1560 if (output_bytecode)
1561 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1562 else
1563 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1565 if (output_bytecode)
1567 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1569 else
1571 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1572 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1573 #else
1574 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1575 #endif
1577 return x;
1580 /* Assemble the static constant template for function entry trampolines.
1581 This is done at most once per compilation.
1582 Returns an RTX for the address of the template. */
1585 assemble_trampoline_template ()
1587 char label[256];
1588 char *name;
1589 int align;
1591 /* Shouldn't get here */
1592 if (output_bytecode)
1593 abort ();
1595 /* By default, put trampoline templates in read-only data section. */
1597 #ifdef TRAMPOLINE_SECTION
1598 TRAMPOLINE_SECTION ();
1599 #else
1600 readonly_data_section ();
1601 #endif
1603 /* Write the assembler code to define one. */
1604 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1605 if (align > 0)
1606 ASM_OUTPUT_ALIGN (asm_out_file, align);
1608 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1609 TRAMPOLINE_TEMPLATE (asm_out_file);
1611 /* Record the rtl to refer to it. */
1612 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1613 name
1614 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1615 return gen_rtx (SYMBOL_REF, Pmode, name);
1618 /* Assemble the integer constant X into an object of SIZE bytes.
1619 X must be either a CONST_INT or CONST_DOUBLE.
1621 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1622 non-zero, abort if we can't output the constant. */
1625 assemble_integer (x, size, force)
1626 rtx x;
1627 int size;
1628 int force;
1630 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1631 ASM_OUTPUT... macros. */
1633 switch (size)
1635 #ifdef ASM_OUTPUT_CHAR
1636 case 1:
1637 ASM_OUTPUT_CHAR (asm_out_file, x);
1638 return 1;
1639 #endif
1641 #ifdef ASM_OUTPUT_SHORT
1642 case 2:
1643 ASM_OUTPUT_SHORT (asm_out_file, x);
1644 return 1;
1645 #endif
1647 #ifdef ASM_OUTPUT_INT
1648 case 4:
1649 ASM_OUTPUT_INT (asm_out_file, x);
1650 return 1;
1651 #endif
1653 #ifdef ASM_OUTPUT_DOUBLE_INT
1654 case 8:
1655 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1656 return 1;
1657 #endif
1659 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1660 case 16:
1661 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1662 return 1;
1663 #endif
1666 /* If we couldn't do it that way, there are two other possibilities: First,
1667 if the machine can output an explicit byte and this is a 1 byte constant,
1668 we can use ASM_OUTPUT_BYTE. */
1670 #ifdef ASM_OUTPUT_BYTE
1671 if (size == 1 && GET_CODE (x) == CONST_INT)
1673 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1674 return 1;
1676 #endif
1678 /* Finally, if SIZE is larger than a single word, try to output the constant
1679 one word at a time. */
1681 if (size > UNITS_PER_WORD)
1683 int i;
1684 enum machine_mode mode
1685 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1686 rtx word;
1688 for (i = 0; i < size / UNITS_PER_WORD; i++)
1690 word = operand_subword (x, i, 0, mode);
1692 if (word == 0)
1693 break;
1695 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1696 break;
1699 if (i == size / UNITS_PER_WORD)
1700 return 1;
1701 /* If we output at least one word and then could not finish,
1702 there is no valid way to continue. */
1703 if (i > 0)
1704 abort ();
1707 if (force)
1708 abort ();
1710 return 0;
1713 /* Assemble the floating-point constant D into an object of size MODE. */
1715 void
1716 assemble_real (d, mode)
1717 REAL_VALUE_TYPE d;
1718 enum machine_mode mode;
1720 jmp_buf output_constant_handler;
1722 if (setjmp (output_constant_handler))
1724 error ("floating point trap outputting a constant");
1725 #ifdef REAL_IS_NOT_DOUBLE
1726 bzero ((char *) &d, sizeof d);
1727 d = dconst0;
1728 #else
1729 d = 0;
1730 #endif
1733 set_float_handler (output_constant_handler);
1735 switch (mode)
1737 #ifdef ASM_OUTPUT_BYTE_FLOAT
1738 case QFmode:
1739 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1740 break;
1741 #endif
1742 #ifdef ASM_OUTPUT_SHORT_FLOAT
1743 case HFmode:
1744 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1745 break;
1746 #endif
1747 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1748 case TQFmode:
1749 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1750 break;
1751 #endif
1752 #ifdef ASM_OUTPUT_FLOAT
1753 case SFmode:
1754 ASM_OUTPUT_FLOAT (asm_out_file, d);
1755 break;
1756 #endif
1758 #ifdef ASM_OUTPUT_DOUBLE
1759 case DFmode:
1760 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1761 break;
1762 #endif
1764 #ifdef ASM_OUTPUT_LONG_DOUBLE
1765 case XFmode:
1766 case TFmode:
1767 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1768 break;
1769 #endif
1771 default:
1772 abort ();
1775 set_float_handler (NULL_PTR);
1778 /* Here we combine duplicate floating constants to make
1779 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1781 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1782 They are chained through the CONST_DOUBLE_CHAIN.
1783 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1784 In that case, CONST_DOUBLE_MEM is either a MEM,
1785 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1787 (CONST_DOUBLE_MEM is used only for top-level functions.
1788 See force_const_mem for explanation.) */
1790 static rtx const_double_chain;
1792 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1793 For an integer, I0 is the low-order word and I1 is the high-order word.
1794 For a real number, I0 is the word with the low address
1795 and I1 is the word with the high address. */
1798 immed_double_const (i0, i1, mode)
1799 HOST_WIDE_INT i0, i1;
1800 enum machine_mode mode;
1802 register rtx r;
1803 int in_current_obstack;
1805 if (GET_MODE_CLASS (mode) == MODE_INT
1806 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1808 /* We clear out all bits that don't belong in MODE, unless they and our
1809 sign bit are all one. So we get either a reasonable negative value
1810 or a reasonable unsigned value for this mode. */
1811 int width = GET_MODE_BITSIZE (mode);
1812 if (width < HOST_BITS_PER_WIDE_INT
1813 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1814 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1815 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1816 else if (width == HOST_BITS_PER_WIDE_INT
1817 && ! (i1 == ~0 && i0 < 0))
1818 i1 = 0;
1819 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1820 /* We cannot represent this value as a constant. */
1821 abort ();
1823 /* If this would be an entire word for the target, but is not for
1824 the host, then sign-extend on the host so that the number will look
1825 the same way on the host that it would on the target.
1827 For example, when building a 64 bit alpha hosted 32 bit sparc
1828 targeted compiler, then we want the 32 bit unsigned value -1 to be
1829 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1830 The later confuses the sparc backend. */
1832 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1833 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1834 i0 |= ((HOST_WIDE_INT) (-1) << width);
1836 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1838 ??? Strictly speaking, this is wrong if we create a CONST_INT
1839 for a large unsigned constant with the size of MODE being
1840 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1841 wider mode. In that case we will mis-interpret it as a negative
1842 number.
1844 Unfortunately, the only alternative is to make a CONST_DOUBLE
1845 for any constant in any mode if it is an unsigned constant larger
1846 than the maximum signed integer in an int on the host. However,
1847 doing this will break everyone that always expects to see a CONST_INT
1848 for SImode and smaller.
1850 We have always been making CONST_INTs in this case, so nothing new
1851 is being broken. */
1853 if (width <= HOST_BITS_PER_WIDE_INT)
1854 i1 = (i0 < 0) ? ~0 : 0;
1856 /* If this integer fits in one word, return a CONST_INT. */
1857 if ((i1 == 0 && i0 >= 0)
1858 || (i1 == ~0 && i0 < 0))
1859 return GEN_INT (i0);
1861 /* We use VOIDmode for integers. */
1862 mode = VOIDmode;
1865 /* Search the chain for an existing CONST_DOUBLE with the right value.
1866 If one is found, return it. */
1868 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1869 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1870 && GET_MODE (r) == mode)
1871 return r;
1873 /* No; make a new one and add it to the chain.
1875 We may be called by an optimizer which may be discarding any memory
1876 allocated during its processing (such as combine and loop). However,
1877 we will be leaving this constant on the chain, so we cannot tolerate
1878 freed memory. So switch to saveable_obstack for this allocation
1879 and then switch back if we were in current_obstack. */
1881 push_obstacks_nochange ();
1882 rtl_in_saveable_obstack ();
1883 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1884 pop_obstacks ();
1886 /* Don't touch const_double_chain in nested function; see force_const_mem.
1887 Also, don't touch it if not inside any function. */
1888 if (outer_function_chain == 0 && current_function_decl != 0)
1890 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1891 const_double_chain = r;
1894 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1895 Actual use of mem-slot is only through force_const_mem. */
1897 CONST_DOUBLE_MEM (r) = const0_rtx;
1899 return r;
1902 /* Return a CONST_DOUBLE for a specified `double' value
1903 and machine mode. */
1906 immed_real_const_1 (d, mode)
1907 REAL_VALUE_TYPE d;
1908 enum machine_mode mode;
1910 union real_extract u;
1911 register rtx r;
1912 int in_current_obstack;
1914 /* Get the desired `double' value as a sequence of ints
1915 since that is how they are stored in a CONST_DOUBLE. */
1917 u.d = d;
1919 /* Detect special cases. */
1921 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1922 if (!bcmp ((char *) &dconst0, (char *) &d, sizeof d))
1923 return CONST0_RTX (mode);
1924 /* Check for NaN first, because some ports (specifically the i386) do not
1925 emit correct ieee-fp code by default, and thus will generate a core
1926 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1927 does a floating point comparison. */
1928 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1929 return CONST1_RTX (mode);
1931 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1932 return immed_double_const (u.i[0], u.i[1], mode);
1934 /* The rest of this function handles the case where
1935 a float value requires more than 2 ints of space.
1936 It will be deleted as dead code on machines that don't need it. */
1938 /* Search the chain for an existing CONST_DOUBLE with the right value.
1939 If one is found, return it. */
1941 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1942 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
1943 && GET_MODE (r) == mode)
1944 return r;
1946 /* No; make a new one and add it to the chain.
1948 We may be called by an optimizer which may be discarding any memory
1949 allocated during its processing (such as combine and loop). However,
1950 we will be leaving this constant on the chain, so we cannot tolerate
1951 freed memory. So switch to saveable_obstack for this allocation
1952 and then switch back if we were in current_obstack. */
1954 push_obstacks_nochange ();
1955 rtl_in_saveable_obstack ();
1956 r = rtx_alloc (CONST_DOUBLE);
1957 PUT_MODE (r, mode);
1958 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
1959 pop_obstacks ();
1961 /* Don't touch const_double_chain in nested function; see force_const_mem.
1962 Also, don't touch it if not inside any function. */
1963 if (outer_function_chain == 0 && current_function_decl != 0)
1965 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1966 const_double_chain = r;
1969 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1970 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1971 is only through force_const_mem. */
1973 CONST_DOUBLE_MEM (r) = const0_rtx;
1975 return r;
1978 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1979 which must be a REAL_CST tree node. */
1982 immed_real_const (exp)
1983 tree exp;
1985 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
1988 /* At the end of a function, forget the memory-constants
1989 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
1990 Also clear out real_constant_chain and clear out all the chain-pointers. */
1992 void
1993 clear_const_double_mem ()
1995 register rtx r, next;
1997 /* Don't touch CONST_DOUBLE_MEM for nested functions.
1998 See force_const_mem for explanation. */
1999 if (outer_function_chain != 0)
2000 return;
2002 for (r = const_double_chain; r; r = next)
2004 next = CONST_DOUBLE_CHAIN (r);
2005 CONST_DOUBLE_CHAIN (r) = 0;
2006 CONST_DOUBLE_MEM (r) = cc0_rtx;
2008 const_double_chain = 0;
2011 /* Given an expression EXP with a constant value,
2012 reduce it to the sum of an assembler symbol and an integer.
2013 Store them both in the structure *VALUE.
2014 Abort if EXP does not reduce. */
2016 struct addr_const
2018 rtx base;
2019 HOST_WIDE_INT offset;
2022 static void
2023 decode_addr_const (exp, value)
2024 tree exp;
2025 struct addr_const *value;
2027 register tree target = TREE_OPERAND (exp, 0);
2028 register int offset = 0;
2029 register rtx x;
2031 while (1)
2033 if (TREE_CODE (target) == COMPONENT_REF
2034 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2035 == INTEGER_CST))
2037 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2038 target = TREE_OPERAND (target, 0);
2040 else if (TREE_CODE (target) == ARRAY_REF)
2042 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2043 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2044 abort ();
2045 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2046 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2047 / BITS_PER_UNIT);
2048 target = TREE_OPERAND (target, 0);
2050 else
2051 break;
2054 switch (TREE_CODE (target))
2056 case VAR_DECL:
2057 case FUNCTION_DECL:
2058 x = DECL_RTL (target);
2059 break;
2061 case LABEL_DECL:
2062 if (output_bytecode)
2063 /* FIXME: this may not be correct, check it */
2064 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
2065 else
2066 x = gen_rtx (MEM, FUNCTION_MODE,
2067 gen_rtx (LABEL_REF, VOIDmode,
2068 label_rtx (TREE_OPERAND (exp, 0))));
2069 break;
2071 case REAL_CST:
2072 case STRING_CST:
2073 case COMPLEX_CST:
2074 case CONSTRUCTOR:
2075 x = TREE_CST_RTL (target);
2076 break;
2078 default:
2079 abort ();
2082 if (!output_bytecode)
2084 if (GET_CODE (x) != MEM)
2085 abort ();
2086 x = XEXP (x, 0);
2089 value->base = x;
2090 value->offset = offset;
2093 /* Uniquize all constants that appear in memory.
2094 Each constant in memory thus far output is recorded
2095 in `const_hash_table' with a `struct constant_descriptor'
2096 that contains a polish representation of the value of
2097 the constant.
2099 We cannot store the trees in the hash table
2100 because the trees may be temporary. */
2102 struct constant_descriptor
2104 struct constant_descriptor *next;
2105 char *label;
2106 char contents[1];
2109 #define HASHBITS 30
2110 #define MAX_HASH_TABLE 1009
2111 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2113 /* Compute a hash code for a constant expression. */
2115 static int
2116 const_hash (exp)
2117 tree exp;
2119 register char *p;
2120 register int len, hi, i;
2121 register enum tree_code code = TREE_CODE (exp);
2123 if (code == INTEGER_CST)
2125 p = (char *) &TREE_INT_CST_LOW (exp);
2126 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2128 else if (code == REAL_CST)
2130 p = (char *) &TREE_REAL_CST (exp);
2131 len = sizeof TREE_REAL_CST (exp);
2133 else if (code == STRING_CST)
2134 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2135 else if (code == COMPLEX_CST)
2136 return const_hash (TREE_REALPART (exp)) * 5
2137 + const_hash (TREE_IMAGPART (exp));
2138 else if (code == CONSTRUCTOR)
2140 register tree link;
2142 /* For record type, include the type in the hashing.
2143 We do not do so for array types
2144 because (1) the sizes of the elements are sufficient
2145 and (2) distinct array types can have the same constructor.
2146 Instead, we include the array size because the constructor could
2147 be shorter. */
2148 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2149 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2150 % MAX_HASH_TABLE;
2151 else
2152 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2153 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2155 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2156 if (TREE_VALUE (link))
2157 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2159 return hi;
2161 else if (code == ADDR_EXPR)
2163 struct addr_const value;
2164 decode_addr_const (exp, &value);
2165 if (GET_CODE (value.base) == SYMBOL_REF)
2167 /* Don't hash the address of the SYMBOL_REF;
2168 only use the offset and the symbol name. */
2169 hi = value.offset;
2170 p = XSTR (value.base, 0);
2171 for (i = 0; p[i] != 0; i++)
2172 hi = ((hi * 613) + (unsigned)(p[i]));
2174 else if (GET_CODE (value.base) == LABEL_REF)
2175 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2177 hi &= (1 << HASHBITS) - 1;
2178 hi %= MAX_HASH_TABLE;
2179 return hi;
2181 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2182 return const_hash (TREE_OPERAND (exp, 0)) * 9
2183 + const_hash (TREE_OPERAND (exp, 1));
2184 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2185 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2187 /* Compute hashing function */
2188 hi = len;
2189 for (i = 0; i < len; i++)
2190 hi = ((hi * 613) + (unsigned)(p[i]));
2192 hi &= (1 << HASHBITS) - 1;
2193 hi %= MAX_HASH_TABLE;
2194 return hi;
2197 /* Compare a constant expression EXP with a constant-descriptor DESC.
2198 Return 1 if DESC describes a constant with the same value as EXP. */
2200 static int
2201 compare_constant (exp, desc)
2202 tree exp;
2203 struct constant_descriptor *desc;
2205 return 0 != compare_constant_1 (exp, desc->contents);
2208 /* Compare constant expression EXP with a substring P of a constant descriptor.
2209 If they match, return a pointer to the end of the substring matched.
2210 If they do not match, return 0.
2212 Since descriptors are written in polish prefix notation,
2213 this function can be used recursively to test one operand of EXP
2214 against a subdescriptor, and if it succeeds it returns the
2215 address of the subdescriptor for the next operand. */
2217 static char *
2218 compare_constant_1 (exp, p)
2219 tree exp;
2220 char *p;
2222 register char *strp;
2223 register int len;
2224 register enum tree_code code = TREE_CODE (exp);
2226 if (code != (enum tree_code) *p++)
2227 return 0;
2229 if (code == INTEGER_CST)
2231 /* Integer constants are the same only if the same width of type. */
2232 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2233 return 0;
2234 strp = (char *) &TREE_INT_CST_LOW (exp);
2235 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2237 else if (code == REAL_CST)
2239 /* Real constants are the same only if the same width of type. */
2240 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2241 return 0;
2242 strp = (char *) &TREE_REAL_CST (exp);
2243 len = sizeof TREE_REAL_CST (exp);
2245 else if (code == STRING_CST)
2247 if (flag_writable_strings)
2248 return 0;
2249 strp = TREE_STRING_POINTER (exp);
2250 len = TREE_STRING_LENGTH (exp);
2251 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2252 sizeof TREE_STRING_LENGTH (exp)))
2253 return 0;
2254 p += sizeof TREE_STRING_LENGTH (exp);
2256 else if (code == COMPLEX_CST)
2258 p = compare_constant_1 (TREE_REALPART (exp), p);
2259 if (p == 0) return 0;
2260 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2261 return p;
2263 else if (code == CONSTRUCTOR)
2265 register tree link;
2266 int length = list_length (CONSTRUCTOR_ELTS (exp));
2267 tree type;
2269 if (bcmp ((char *) &length, p, sizeof length))
2270 return 0;
2271 p += sizeof length;
2273 /* For record constructors, insist that the types match.
2274 For arrays, just verify both constructors are for arrays. */
2275 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2276 type = TREE_TYPE (exp);
2277 else
2278 type = 0;
2279 if (bcmp ((char *) &type, p, sizeof type))
2280 return 0;
2281 p += sizeof type;
2283 /* For arrays, insist that the size in bytes match. */
2284 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2286 int size = int_size_in_bytes (TREE_TYPE (exp));
2287 if (bcmp ((char *) &size, p, sizeof size))
2288 return 0;
2289 p += sizeof size;
2292 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2294 if (TREE_VALUE (link))
2296 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2297 return 0;
2299 else
2301 tree zero = 0;
2303 if (bcmp ((char *) &zero, p, sizeof zero))
2304 return 0;
2305 p += sizeof zero;
2309 return p;
2311 else if (code == ADDR_EXPR)
2313 struct addr_const value;
2314 decode_addr_const (exp, &value);
2315 strp = (char *) &value.offset;
2316 len = sizeof value.offset;
2317 /* Compare the offset. */
2318 while (--len >= 0)
2319 if (*p++ != *strp++)
2320 return 0;
2321 /* Compare symbol name. */
2322 strp = XSTR (value.base, 0);
2323 len = strlen (strp) + 1;
2325 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2327 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2328 if (p == 0) return 0;
2329 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2330 return p;
2332 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2334 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2335 return p;
2338 /* Compare constant contents. */
2339 while (--len >= 0)
2340 if (*p++ != *strp++)
2341 return 0;
2343 return p;
2346 /* Construct a constant descriptor for the expression EXP.
2347 It is up to the caller to enter the descriptor in the hash table. */
2349 static struct constant_descriptor *
2350 record_constant (exp)
2351 tree exp;
2353 struct constant_descriptor *next = 0;
2354 char *label = 0;
2356 /* Make a struct constant_descriptor. The first two pointers will
2357 be filled in later. Here we just leave space for them. */
2359 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2360 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2361 record_constant_1 (exp);
2362 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2365 /* Add a description of constant expression EXP
2366 to the object growing in `permanent_obstack'.
2367 No need to return its address; the caller will get that
2368 from the obstack when the object is complete. */
2370 static void
2371 record_constant_1 (exp)
2372 tree exp;
2374 register char *strp;
2375 register int len;
2376 register enum tree_code code = TREE_CODE (exp);
2378 obstack_1grow (&permanent_obstack, (unsigned int) code);
2380 if (code == INTEGER_CST)
2382 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2383 strp = (char *) &TREE_INT_CST_LOW (exp);
2384 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2386 else if (code == REAL_CST)
2388 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2389 strp = (char *) &TREE_REAL_CST (exp);
2390 len = sizeof TREE_REAL_CST (exp);
2392 else if (code == STRING_CST)
2394 if (flag_writable_strings)
2395 return;
2396 strp = TREE_STRING_POINTER (exp);
2397 len = TREE_STRING_LENGTH (exp);
2398 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2399 sizeof TREE_STRING_LENGTH (exp));
2401 else if (code == COMPLEX_CST)
2403 record_constant_1 (TREE_REALPART (exp));
2404 record_constant_1 (TREE_IMAGPART (exp));
2405 return;
2407 else if (code == CONSTRUCTOR)
2409 register tree link;
2410 int length = list_length (CONSTRUCTOR_ELTS (exp));
2411 tree type;
2413 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2415 /* For record constructors, insist that the types match.
2416 For arrays, just verify both constructors are for arrays. */
2417 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2418 type = TREE_TYPE (exp);
2419 else
2420 type = 0;
2421 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2423 /* For arrays, insist that the size in bytes match. */
2424 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2426 int size = int_size_in_bytes (TREE_TYPE (exp));
2427 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2430 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2432 if (TREE_VALUE (link))
2433 record_constant_1 (TREE_VALUE (link));
2434 else
2436 tree zero = 0;
2438 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
2442 return;
2444 else if (code == ADDR_EXPR)
2446 struct addr_const value;
2447 decode_addr_const (exp, &value);
2448 /* Record the offset. */
2449 obstack_grow (&permanent_obstack,
2450 (char *) &value.offset, sizeof value.offset);
2451 /* Record the symbol name. */
2452 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2453 strlen (XSTR (value.base, 0)) + 1);
2454 return;
2456 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2458 record_constant_1 (TREE_OPERAND (exp, 0));
2459 record_constant_1 (TREE_OPERAND (exp, 1));
2460 return;
2462 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2464 record_constant_1 (TREE_OPERAND (exp, 0));
2465 return;
2468 /* Record constant contents. */
2469 obstack_grow (&permanent_obstack, strp, len);
2472 /* Record a list of constant expressions that were passed to
2473 output_constant_def but that could not be output right away. */
2475 struct deferred_constant
2477 struct deferred_constant *next;
2478 tree exp;
2479 int reloc;
2480 int labelno;
2483 static struct deferred_constant *deferred_constants;
2485 /* Nonzero means defer output of addressed subconstants
2486 (i.e., those for which output_constant_def is called.) */
2487 static int defer_addressed_constants_flag;
2489 /* Start deferring output of subconstants. */
2491 void
2492 defer_addressed_constants ()
2494 defer_addressed_constants_flag++;
2497 /* Stop deferring output of subconstants,
2498 and output now all those that have been deferred. */
2500 void
2501 output_deferred_addressed_constants ()
2503 struct deferred_constant *p, *next;
2505 defer_addressed_constants_flag--;
2507 if (defer_addressed_constants_flag > 0)
2508 return;
2510 for (p = deferred_constants; p; p = next)
2512 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2513 next = p->next;
2514 free (p);
2517 deferred_constants = 0;
2520 /* Make a copy of the whole tree structure for a constant.
2521 This handles the same types of nodes that compare_constant
2522 and record_constant handle. */
2524 static tree
2525 copy_constant (exp)
2526 tree exp;
2528 switch (TREE_CODE (exp))
2530 case INTEGER_CST:
2531 case REAL_CST:
2532 case STRING_CST:
2533 case ADDR_EXPR:
2534 /* For ADDR_EXPR, we do not want to copy the decl
2535 whose address is requested. */
2536 return copy_node (exp);
2538 case COMPLEX_CST:
2539 return build_complex (copy_constant (TREE_REALPART (exp)),
2540 copy_constant (TREE_IMAGPART (exp)));
2542 case PLUS_EXPR:
2543 case MINUS_EXPR:
2544 return build (TREE_CODE (exp), TREE_TYPE (exp),
2545 copy_constant (TREE_OPERAND (exp, 0)),
2546 copy_constant (TREE_OPERAND (exp, 1)));
2548 case NOP_EXPR:
2549 case CONVERT_EXPR:
2550 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2551 copy_constant (TREE_OPERAND (exp, 0)));
2553 case CONSTRUCTOR:
2555 tree copy = copy_node (exp);
2556 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2557 tree tail;
2559 CONSTRUCTOR_ELTS (copy) = list;
2560 for (tail = list; tail; tail = TREE_CHAIN (tail))
2561 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2563 return copy;
2566 default:
2567 abort ();
2571 /* Return an rtx representing a reference to constant data in memory
2572 for the constant expression EXP.
2574 If assembler code for such a constant has already been output,
2575 return an rtx to refer to it.
2576 Otherwise, output such a constant in memory (or defer it for later)
2577 and generate an rtx for it.
2579 The TREE_CST_RTL of EXP is set up to point to that rtx.
2580 The const_hash_table records which constants already have label strings. */
2583 output_constant_def (exp)
2584 tree exp;
2586 register int hash;
2587 register struct constant_descriptor *desc;
2588 char label[256];
2589 char *found = 0;
2590 int reloc;
2591 register rtx def;
2593 if (TREE_CODE (exp) == INTEGER_CST)
2594 abort (); /* No TREE_CST_RTL slot in these. */
2596 if (TREE_CST_RTL (exp))
2597 return TREE_CST_RTL (exp);
2599 /* Make sure any other constants whose addresses appear in EXP
2600 are assigned label numbers. */
2602 reloc = output_addressed_constants (exp);
2604 /* Compute hash code of EXP. Search the descriptors for that hash code
2605 to see if any of them describes EXP. If yes, the descriptor records
2606 the label number already assigned. */
2608 hash = const_hash (exp) % MAX_HASH_TABLE;
2610 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2611 if (compare_constant (exp, desc))
2613 found = desc->label;
2614 break;
2617 if (found == 0)
2619 /* No constant equal to EXP is known to have been output.
2620 Make a constant descriptor to enter EXP in the hash table.
2621 Assign the label number and record it in the descriptor for
2622 future calls to this function to find. */
2624 /* Create a string containing the label name, in LABEL. */
2625 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2627 desc = record_constant (exp);
2628 desc->next = const_hash_table[hash];
2629 desc->label
2630 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2631 const_hash_table[hash] = desc;
2633 else
2635 /* Create a string containing the label name, in LABEL. */
2636 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2639 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2641 push_obstacks_nochange ();
2642 if (TREE_PERMANENT (exp))
2643 end_temporary_allocation ();
2645 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2647 TREE_CST_RTL (exp)
2648 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2649 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2650 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2651 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2653 pop_obstacks ();
2655 /* Optionally set flags or add text to the name to record information
2656 such as that it is a function name. If the name is changed, the macro
2657 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2658 #ifdef ENCODE_SECTION_INFO
2659 ENCODE_SECTION_INFO (exp);
2660 #endif
2662 /* If this is the first time we've seen this particular constant,
2663 output it (or defer its output for later). */
2664 if (found == 0)
2666 if (defer_addressed_constants_flag)
2668 struct deferred_constant *p;
2669 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2671 push_obstacks_nochange ();
2672 suspend_momentary ();
2673 p->exp = copy_constant (exp);
2674 pop_obstacks ();
2675 p->reloc = reloc;
2676 p->labelno = const_labelno++;
2677 p->next = deferred_constants;
2678 deferred_constants = p;
2680 else
2681 output_constant_def_contents (exp, reloc, const_labelno++);
2684 return TREE_CST_RTL (exp);
2687 /* Now output assembler code to define the label for EXP,
2688 and follow it with the data of EXP. */
2690 static void
2691 output_constant_def_contents (exp, reloc, labelno)
2692 tree exp;
2693 int reloc;
2694 int labelno;
2696 int align;
2698 if (IN_NAMED_SECTION (exp))
2699 named_section (exp, NULL);
2700 else
2702 /* First switch to text section, except for writable strings. */
2703 #ifdef SELECT_SECTION
2704 SELECT_SECTION (exp, reloc);
2705 #else
2706 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2707 || (flag_pic && reloc))
2708 data_section ();
2709 else
2710 readonly_data_section ();
2711 #endif
2714 /* Align the location counter as required by EXP's data type. */
2715 align = TYPE_ALIGN (TREE_TYPE (exp));
2716 #ifdef CONSTANT_ALIGNMENT
2717 align = CONSTANT_ALIGNMENT (exp, align);
2718 #endif
2720 if (align > BITS_PER_UNIT)
2722 if (!output_bytecode)
2724 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2726 else
2728 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2732 /* Output the label itself. */
2733 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2735 /* Output the value of EXP. */
2736 output_constant (exp,
2737 (TREE_CODE (exp) == STRING_CST
2738 ? TREE_STRING_LENGTH (exp)
2739 : int_size_in_bytes (TREE_TYPE (exp))));
2743 /* Similar hash facility for making memory-constants
2744 from constant rtl-expressions. It is used on RISC machines
2745 where immediate integer arguments and constant addresses are restricted
2746 so that such constants must be stored in memory.
2748 This pool of constants is reinitialized for each function
2749 so each function gets its own constants-pool that comes right before it.
2751 All structures allocated here are discarded when functions are saved for
2752 inlining, so they do not need to be allocated permanently. */
2754 #define MAX_RTX_HASH_TABLE 61
2755 static struct constant_descriptor **const_rtx_hash_table;
2757 /* Structure to represent sufficient information about a constant so that
2758 it can be output when the constant pool is output, so that function
2759 integration can be done, and to simplify handling on machines that reference
2760 constant pool as base+displacement. */
2762 struct pool_constant
2764 struct constant_descriptor *desc;
2765 struct pool_constant *next;
2766 enum machine_mode mode;
2767 rtx constant;
2768 int labelno;
2769 int align;
2770 int offset;
2773 /* Pointers to first and last constant in pool. */
2775 static struct pool_constant *first_pool, *last_pool;
2777 /* Current offset in constant pool (does not include any machine-specific
2778 header. */
2780 static int pool_offset;
2782 /* Structure used to maintain hash table mapping symbols used to their
2783 corresponding constants. */
2785 struct pool_sym
2787 char *label;
2788 struct pool_constant *pool;
2789 struct pool_sym *next;
2792 static struct pool_sym **const_rtx_sym_hash_table;
2794 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2795 The argument is XSTR (... , 0) */
2797 #define SYMHASH(LABEL) \
2798 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2800 /* Initialize constant pool hashing for next function. */
2802 void
2803 init_const_rtx_hash_table ()
2805 const_rtx_hash_table
2806 = ((struct constant_descriptor **)
2807 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2808 const_rtx_sym_hash_table
2809 = ((struct pool_sym **)
2810 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2811 bzero ((char *) const_rtx_hash_table,
2812 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2813 bzero ((char *) const_rtx_sym_hash_table,
2814 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2816 first_pool = last_pool = 0;
2817 pool_offset = 0;
2820 /* Save and restore status for a nested function. */
2822 void
2823 save_varasm_status (p)
2824 struct function *p;
2826 p->const_rtx_hash_table = const_rtx_hash_table;
2827 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2828 p->first_pool = first_pool;
2829 p->last_pool = last_pool;
2830 p->pool_offset = pool_offset;
2833 void
2834 restore_varasm_status (p)
2835 struct function *p;
2837 const_rtx_hash_table = p->const_rtx_hash_table;
2838 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2839 first_pool = p->first_pool;
2840 last_pool = p->last_pool;
2841 pool_offset = p->pool_offset;
2844 enum kind { RTX_DOUBLE, RTX_INT };
2846 struct rtx_const
2848 #ifdef ONLY_INT_FIELDS
2849 unsigned int kind : 16;
2850 unsigned int mode : 16;
2851 #else
2852 enum kind kind : 16;
2853 enum machine_mode mode : 16;
2854 #endif
2855 union {
2856 union real_extract du;
2857 struct addr_const addr;
2858 } un;
2861 /* Express an rtx for a constant integer (perhaps symbolic)
2862 as the sum of a symbol or label plus an explicit integer.
2863 They are stored into VALUE. */
2865 static void
2866 decode_rtx_const (mode, x, value)
2867 enum machine_mode mode;
2868 rtx x;
2869 struct rtx_const *value;
2871 /* Clear the whole structure, including any gaps. */
2874 int *p = (int *) value;
2875 int *end = (int *) (value + 1);
2876 while (p < end)
2877 *p++ = 0;
2880 value->kind = RTX_INT; /* Most usual kind. */
2881 value->mode = mode;
2883 switch (GET_CODE (x))
2885 case CONST_DOUBLE:
2886 value->kind = RTX_DOUBLE;
2887 if (GET_MODE (x) != VOIDmode)
2888 value->mode = GET_MODE (x);
2889 bcopy ((char *) &CONST_DOUBLE_LOW (x),
2890 (char *) &value->un.du, sizeof value->un.du);
2891 break;
2893 case CONST_INT:
2894 value->un.addr.offset = INTVAL (x);
2895 break;
2897 case SYMBOL_REF:
2898 case LABEL_REF:
2899 case PC:
2900 value->un.addr.base = x;
2901 break;
2903 case CONST:
2904 x = XEXP (x, 0);
2905 if (GET_CODE (x) == PLUS)
2907 value->un.addr.base = XEXP (x, 0);
2908 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2909 abort ();
2910 value->un.addr.offset = INTVAL (XEXP (x, 1));
2912 else if (GET_CODE (x) == MINUS)
2914 value->un.addr.base = XEXP (x, 0);
2915 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2916 abort ();
2917 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2919 else
2920 abort ();
2921 break;
2923 default:
2924 abort ();
2927 if (value->kind == RTX_INT && value->un.addr.base != 0)
2928 switch (GET_CODE (value->un.addr.base))
2930 case SYMBOL_REF:
2931 case LABEL_REF:
2932 /* Use the string's address, not the SYMBOL_REF's address,
2933 for the sake of addresses of library routines.
2934 For a LABEL_REF, compare labels. */
2935 value->un.addr.base = XEXP (value->un.addr.base, 0);
2939 /* Given a MINUS expression, simplify it if both sides
2940 include the same symbol. */
2943 simplify_subtraction (x)
2944 rtx x;
2946 struct rtx_const val0, val1;
2948 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2949 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2951 if (val0.un.addr.base == val1.un.addr.base)
2952 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2953 return x;
2956 /* Compute a hash code for a constant RTL expression. */
2958 static int
2959 const_hash_rtx (mode, x)
2960 enum machine_mode mode;
2961 rtx x;
2963 register int hi, i;
2965 struct rtx_const value;
2966 decode_rtx_const (mode, x, &value);
2968 /* Compute hashing function */
2969 hi = 0;
2970 for (i = 0; i < sizeof value / sizeof (int); i++)
2971 hi += ((int *) &value)[i];
2973 hi &= (1 << HASHBITS) - 1;
2974 hi %= MAX_RTX_HASH_TABLE;
2975 return hi;
2978 /* Compare a constant rtl object X with a constant-descriptor DESC.
2979 Return 1 if DESC describes a constant with the same value as X. */
2981 static int
2982 compare_constant_rtx (mode, x, desc)
2983 enum machine_mode mode;
2984 rtx x;
2985 struct constant_descriptor *desc;
2987 register int *p = (int *) desc->contents;
2988 register int *strp;
2989 register int len;
2990 struct rtx_const value;
2992 decode_rtx_const (mode, x, &value);
2993 strp = (int *) &value;
2994 len = sizeof value / sizeof (int);
2996 /* Compare constant contents. */
2997 while (--len >= 0)
2998 if (*p++ != *strp++)
2999 return 0;
3001 return 1;
3004 /* Construct a constant descriptor for the rtl-expression X.
3005 It is up to the caller to enter the descriptor in the hash table. */
3007 static struct constant_descriptor *
3008 record_constant_rtx (mode, x)
3009 enum machine_mode mode;
3010 rtx x;
3012 struct constant_descriptor *ptr;
3013 char *label;
3014 struct rtx_const value;
3016 decode_rtx_const (mode, x, &value);
3018 /* Put these things in the saveable obstack so we can ensure it won't
3019 be freed if we are called from combine or some other phase that discards
3020 memory allocated from function_obstack (current_obstack). */
3021 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3022 obstack_grow (saveable_obstack, &label, sizeof label);
3024 /* Record constant contents. */
3025 obstack_grow (saveable_obstack, &value, sizeof value);
3027 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3030 /* Given a constant rtx X, make (or find) a memory constant for its value
3031 and return a MEM rtx to refer to it in memory. */
3034 force_const_mem (mode, x)
3035 enum machine_mode mode;
3036 rtx x;
3038 register int hash;
3039 register struct constant_descriptor *desc;
3040 char label[256];
3041 char *found = 0;
3042 rtx def;
3044 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3045 (this will always be true for floating CONST_DOUBLEs that have been
3046 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3047 use the previous copy. Otherwise, make a new one. Note that in
3048 the unlikely event that this same CONST_DOUBLE is used in two different
3049 modes in an alternating fashion, we will allocate a lot of different
3050 memory locations, but this should be extremely rare. */
3052 /* Don't use CONST_DOUBLE_MEM in a nested function.
3053 Nested functions have their own constant pools,
3054 so they can't share the same values in CONST_DOUBLE_MEM
3055 with the containing function. */
3056 if (outer_function_chain == 0)
3057 if (GET_CODE (x) == CONST_DOUBLE
3058 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3059 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3060 return CONST_DOUBLE_MEM (x);
3062 /* Compute hash code of X. Search the descriptors for that hash code
3063 to see if any of them describes X. If yes, the descriptor records
3064 the label number already assigned. */
3066 hash = const_hash_rtx (mode, x);
3068 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3069 if (compare_constant_rtx (mode, x, desc))
3071 found = desc->label;
3072 break;
3075 if (found == 0)
3077 register struct pool_constant *pool;
3078 register struct pool_sym *sym;
3079 int align;
3081 /* No constant equal to X is known to have been output.
3082 Make a constant descriptor to enter X in the hash table.
3083 Assign the label number and record it in the descriptor for
3084 future calls to this function to find. */
3086 desc = record_constant_rtx (mode, x);
3087 desc->next = const_rtx_hash_table[hash];
3088 const_rtx_hash_table[hash] = desc;
3090 /* Align the location counter as required by EXP's data type. */
3091 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3092 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3093 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3095 pool_offset += align - 1;
3096 pool_offset &= ~ (align - 1);
3098 /* If RTL is not being placed into the saveable obstack, make a
3099 copy of X that is in the saveable obstack in case we are being
3100 called from combine or some other phase that discards memory
3101 it allocates. We need only do this if it is a CONST, since
3102 no other RTX should be allocated in this situation. */
3103 if (rtl_obstack != saveable_obstack
3104 && GET_CODE (x) == CONST)
3106 push_obstacks_nochange ();
3107 rtl_in_saveable_obstack ();
3109 x = gen_rtx (CONST, GET_MODE (x),
3110 gen_rtx (PLUS, GET_MODE (x),
3111 XEXP (XEXP (x, 0), 0), XEXP (XEXP (x, 0), 1)));
3112 pop_obstacks ();
3115 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3117 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3118 pool->desc = desc;
3119 pool->constant = x;
3120 pool->mode = mode;
3121 pool->labelno = const_labelno;
3122 pool->align = align;
3123 pool->offset = pool_offset;
3124 pool->next = 0;
3126 if (last_pool == 0)
3127 first_pool = pool;
3128 else
3129 last_pool->next = pool;
3131 last_pool = pool;
3132 pool_offset += GET_MODE_SIZE (mode);
3134 /* Create a string containing the label name, in LABEL. */
3135 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3137 ++const_labelno;
3139 desc->label = found
3140 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3142 /* Add label to symbol hash table. */
3143 hash = SYMHASH (found);
3144 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3145 sym->label = found;
3146 sym->pool = pool;
3147 sym->next = const_rtx_sym_hash_table[hash];
3148 const_rtx_sym_hash_table[hash] = sym;
3151 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3153 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3155 RTX_UNCHANGING_P (def) = 1;
3156 /* Mark the symbol_ref as belonging to this constants pool. */
3157 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3158 current_function_uses_const_pool = 1;
3160 if (outer_function_chain == 0)
3161 if (GET_CODE (x) == CONST_DOUBLE)
3163 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3165 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3166 const_double_chain = x;
3168 CONST_DOUBLE_MEM (x) = def;
3171 return def;
3174 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3175 the corresponding pool_constant structure. */
3177 static struct pool_constant *
3178 find_pool_constant (addr)
3179 rtx addr;
3181 struct pool_sym *sym;
3182 char *label = XSTR (addr, 0);
3184 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3185 if (sym->label == label)
3186 return sym->pool;
3188 abort ();
3191 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3194 get_pool_constant (addr)
3195 rtx addr;
3197 return (find_pool_constant (addr))->constant;
3200 /* Similar, return the mode. */
3202 enum machine_mode
3203 get_pool_mode (addr)
3204 rtx addr;
3206 return (find_pool_constant (addr))->mode;
3209 /* Similar, return the offset in the constant pool. */
3212 get_pool_offset (addr)
3213 rtx addr;
3215 return (find_pool_constant (addr))->offset;
3218 /* Return the size of the constant pool. */
3221 get_pool_size ()
3223 return pool_offset;
3226 /* Write all the constants in the constant pool. */
3228 void
3229 output_constant_pool (fnname, fndecl)
3230 char *fnname;
3231 tree fndecl;
3233 struct pool_constant *pool;
3234 rtx x;
3235 union real_extract u;
3237 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3238 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3239 #endif
3241 for (pool = first_pool; pool; pool = pool->next)
3243 x = pool->constant;
3245 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3246 whose CODE_LABEL has been deleted. This can occur if a jump table
3247 is eliminated by optimization. If so, write a constant of zero
3248 instead. Note that this can also happen by turning the
3249 CODE_LABEL into a NOTE. */
3250 if (((GET_CODE (x) == LABEL_REF
3251 && (INSN_DELETED_P (XEXP (x, 0))
3252 || GET_CODE (XEXP (x, 0)) == NOTE)))
3253 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3254 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3255 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3256 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3257 x = const0_rtx;
3259 /* First switch to correct section. */
3260 #ifdef SELECT_RTX_SECTION
3261 SELECT_RTX_SECTION (pool->mode, x);
3262 #else
3263 readonly_data_section ();
3264 #endif
3266 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3267 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3268 pool->align, pool->labelno, done);
3269 #endif
3271 if (pool->align > 1)
3272 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3274 /* Output the label. */
3275 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3277 /* Output the value of the constant itself. */
3278 switch (GET_MODE_CLASS (pool->mode))
3280 case MODE_FLOAT:
3281 if (GET_CODE (x) != CONST_DOUBLE)
3282 abort ();
3284 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3285 assemble_real (u.d, pool->mode);
3286 break;
3288 case MODE_INT:
3289 case MODE_PARTIAL_INT:
3290 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3291 break;
3293 default:
3294 abort ();
3297 done: ;
3300 /* Done with this pool. */
3301 first_pool = last_pool = 0;
3304 /* Find all the constants whose addresses are referenced inside of EXP,
3305 and make sure assembler code with a label has been output for each one.
3306 Indicate whether an ADDR_EXPR has been encountered. */
3308 static int
3309 output_addressed_constants (exp)
3310 tree exp;
3312 int reloc = 0;
3314 switch (TREE_CODE (exp))
3316 case ADDR_EXPR:
3318 register tree constant = TREE_OPERAND (exp, 0);
3320 while (TREE_CODE (constant) == COMPONENT_REF)
3322 constant = TREE_OPERAND (constant, 0);
3325 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3326 || TREE_CODE (constant) == CONSTRUCTOR)
3327 /* No need to do anything here
3328 for addresses of variables or functions. */
3329 output_constant_def (constant);
3331 reloc = 1;
3332 break;
3334 case PLUS_EXPR:
3335 case MINUS_EXPR:
3336 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3337 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3338 break;
3340 case NOP_EXPR:
3341 case CONVERT_EXPR:
3342 case NON_LVALUE_EXPR:
3343 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3344 break;
3346 case CONSTRUCTOR:
3348 register tree link;
3349 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3350 if (TREE_VALUE (link) != 0)
3351 reloc |= output_addressed_constants (TREE_VALUE (link));
3353 break;
3355 case ERROR_MARK:
3356 break;
3358 return reloc;
3361 /* Output assembler code for constant EXP to FILE, with no label.
3362 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3363 Assumes output_addressed_constants has been done on EXP already.
3365 Generate exactly SIZE bytes of assembler data, padding at the end
3366 with zeros if necessary. SIZE must always be specified.
3368 SIZE is important for structure constructors,
3369 since trailing members may have been omitted from the constructor.
3370 It is also important for initialization of arrays from string constants
3371 since the full length of the string constant might not be wanted.
3372 It is also needed for initialization of unions, where the initializer's
3373 type is just one member, and that may not be as long as the union.
3375 There a case in which we would fail to output exactly SIZE bytes:
3376 for a structure constructor that wants to produce more than SIZE bytes.
3377 But such constructors will never be generated for any possible input. */
3379 void
3380 output_constant (exp, size)
3381 register tree exp;
3382 register int size;
3384 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3385 rtx x;
3387 if (size == 0)
3388 return;
3390 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3391 That way we get the constant (we hope) inside it. Also, strip off any
3392 NOP_EXPR that converts between two record, union, or array types. */
3393 while ((TREE_CODE (exp) == NOP_EXPR
3394 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3395 || TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3396 || TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3397 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE
3398 || TREE_CODE (TREE_TYPE (exp)) == QUAL_UNION_TYPE))
3399 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3400 exp = TREE_OPERAND (exp, 0);
3402 /* Allow a constructor with no elements for any data type.
3403 This means to fill the space with zeros. */
3404 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3406 if (output_bytecode)
3407 bc_emit_const_skip (size);
3408 else
3409 assemble_zeros (size);
3410 return;
3413 switch (code)
3415 case CHAR_TYPE:
3416 case BOOLEAN_TYPE:
3417 case INTEGER_TYPE:
3418 case ENUMERAL_TYPE:
3419 case POINTER_TYPE:
3420 case REFERENCE_TYPE:
3421 /* ??? What about (int)((float)(int)&foo + 4) */
3422 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3423 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3424 exp = TREE_OPERAND (exp, 0);
3426 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3427 EXPAND_INITIALIZER),
3428 size, 0))
3429 error ("initializer for integer value is too complicated");
3430 size = 0;
3431 break;
3433 case REAL_TYPE:
3434 if (TREE_CODE (exp) != REAL_CST)
3435 error ("initializer for floating value is not a floating constant");
3437 assemble_real (TREE_REAL_CST (exp),
3438 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3439 size = 0;
3440 break;
3442 case COMPLEX_TYPE:
3443 output_constant (TREE_REALPART (exp), size / 2);
3444 output_constant (TREE_IMAGPART (exp), size / 2);
3445 size -= (size / 2) * 2;
3446 break;
3448 case ARRAY_TYPE:
3449 if (TREE_CODE (exp) == CONSTRUCTOR)
3451 output_constructor (exp, size);
3452 return;
3454 else if (TREE_CODE (exp) == STRING_CST)
3456 int excess = 0;
3458 if (size > TREE_STRING_LENGTH (exp))
3460 excess = size - TREE_STRING_LENGTH (exp);
3461 size = TREE_STRING_LENGTH (exp);
3464 assemble_string (TREE_STRING_POINTER (exp), size);
3465 size = excess;
3467 else
3468 abort ();
3469 break;
3471 case RECORD_TYPE:
3472 case UNION_TYPE:
3473 if (TREE_CODE (exp) == CONSTRUCTOR)
3474 output_constructor (exp, size);
3475 else
3476 abort ();
3477 return;
3480 if (size > 0)
3481 assemble_zeros (size);
3484 /* Bytecode specific code to output assembler for integer. */
3486 static void
3487 bc_assemble_integer (exp, size)
3488 tree exp;
3489 int size;
3491 tree const_part;
3492 tree addr_part;
3493 tree tmp;
3495 /* FIXME: is this fold() business going to be as good as the
3496 expand_expr() using EXPAND_SUM above in the RTL case? I
3497 hate RMS.
3498 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3500 exp = fold (exp);
3502 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3503 exp = TREE_OPERAND (exp, 0);
3504 if (TREE_CODE (exp) == INTEGER_CST)
3506 const_part = exp;
3507 addr_part = 0;
3509 else if (TREE_CODE (exp) == PLUS_EXPR)
3511 const_part = TREE_OPERAND (exp, 0);
3512 while (TREE_CODE (const_part) == NOP_EXPR
3513 || TREE_CODE (const_part) == CONVERT_EXPR)
3514 const_part = TREE_OPERAND (const_part, 0);
3515 addr_part = TREE_OPERAND (exp, 1);
3516 while (TREE_CODE (addr_part) == NOP_EXPR
3517 || TREE_CODE (addr_part) == CONVERT_EXPR)
3518 addr_part = TREE_OPERAND (addr_part, 0);
3519 if (TREE_CODE (const_part) != INTEGER_CST)
3520 tmp = const_part, const_part = addr_part, addr_part = tmp;
3521 if (TREE_CODE (const_part) != INTEGER_CST
3522 || TREE_CODE (addr_part) != ADDR_EXPR)
3523 abort (); /* FIXME: we really haven't considered
3524 all the possible cases here. */
3526 else if (TREE_CODE (exp) == ADDR_EXPR)
3528 const_part = integer_zero_node;
3529 addr_part = exp;
3531 else
3532 abort (); /* FIXME: ditto previous. */
3534 if (addr_part == 0)
3536 if (size == 1)
3538 char c = TREE_INT_CST_LOW (const_part);
3539 bc_emit (&c, 1);
3540 size -= 1;
3542 else if (size == 2)
3544 short s = TREE_INT_CST_LOW (const_part);
3545 bc_emit ((char *) &s, 2);
3546 size -= 2;
3548 else if (size == 4)
3550 int i = TREE_INT_CST_LOW (const_part);
3551 bc_emit ((char *) &i, 4);
3552 size -= 4;
3554 else if (size == 8)
3556 if (WORDS_BIG_ENDIAN)
3558 int i = TREE_INT_CST_HIGH (const_part);
3559 bc_emit ((char *) &i, 4);
3560 i = TREE_INT_CST_LOW (const_part);
3561 bc_emit ((char *) &i, 4);
3563 else
3565 int i = TREE_INT_CST_LOW (const_part);
3566 bc_emit ((char *) &i, 4);
3567 i = TREE_INT_CST_HIGH (const_part);
3568 bc_emit ((char *) &i, 4);
3570 size -= 8;
3573 else
3574 if (size == 4
3575 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3576 bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3577 TREE_INT_CST_LOW (const_part));
3578 else
3579 abort (); /* FIXME: there may be more cases. */
3582 /* Subroutine of output_constant, used for CONSTRUCTORs
3583 (aggregate constants).
3584 Generate at least SIZE bytes, padding if necessary. */
3586 static void
3587 output_constructor (exp, size)
3588 tree exp;
3589 int size;
3591 register tree link, field = 0;
3592 HOST_WIDE_INT min_index = 0;
3593 /* Number of bytes output or skipped so far.
3594 In other words, current position within the constructor. */
3595 int total_bytes = 0;
3596 /* Non-zero means BYTE contains part of a byte, to be output. */
3597 int byte_buffer_in_use = 0;
3598 register int byte;
3600 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3601 abort ();
3603 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3604 field = TYPE_FIELDS (TREE_TYPE (exp));
3606 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3607 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3608 min_index
3609 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3611 /* As LINK goes through the elements of the constant,
3612 FIELD goes through the structure fields, if the constant is a structure.
3613 if the constant is a union, then we override this,
3614 by getting the field from the TREE_LIST element.
3615 But the constant could also be an array. Then FIELD is zero. */
3616 for (link = CONSTRUCTOR_ELTS (exp);
3617 link;
3618 link = TREE_CHAIN (link),
3619 field = field ? TREE_CHAIN (field) : 0)
3621 tree val = TREE_VALUE (link);
3622 tree index = 0;
3624 /* the element in a union constructor specifies the proper field. */
3626 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3627 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3629 /* if available, use the type given by link */
3630 if (TREE_PURPOSE (link) != 0)
3631 field = TREE_PURPOSE (link);
3634 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3635 index = TREE_PURPOSE (link);
3637 /* Eliminate the marker that makes a cast not be an lvalue. */
3638 if (val != 0)
3639 STRIP_NOPS (val);
3641 if (field == 0 || !DECL_BIT_FIELD (field))
3643 /* An element that is not a bit-field. */
3645 register int fieldsize;
3646 /* Since this structure is static,
3647 we know the positions are constant. */
3648 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3649 / BITS_PER_UNIT)
3650 : 0);
3651 if (index != 0)
3652 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3653 / BITS_PER_UNIT
3654 * (TREE_INT_CST_LOW (index) - min_index));
3656 /* Output any buffered-up bit-fields preceding this element. */
3657 if (byte_buffer_in_use)
3659 ASM_OUTPUT_BYTE (asm_out_file, byte);
3660 total_bytes++;
3661 byte_buffer_in_use = 0;
3664 /* Advance to offset of this element.
3665 Note no alignment needed in an array, since that is guaranteed
3666 if each element has the proper size. */
3667 if ((field != 0 || index != 0) && bitpos != total_bytes)
3669 if (!output_bytecode)
3670 assemble_zeros (bitpos - total_bytes);
3671 else
3672 bc_emit_const_skip (bitpos - total_bytes);
3673 total_bytes = bitpos;
3676 /* Determine size this element should occupy. */
3677 if (field)
3679 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3680 abort ();
3681 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3683 /* This avoids overflow trouble. */
3684 tree size_tree = size_binop (CEIL_DIV_EXPR,
3685 DECL_SIZE (field),
3686 size_int (BITS_PER_UNIT));
3687 fieldsize = TREE_INT_CST_LOW (size_tree);
3689 else
3691 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3692 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3695 else
3696 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3698 /* Output the element's initial value. */
3699 if (val == 0)
3700 assemble_zeros (fieldsize);
3701 else
3702 output_constant (val, fieldsize);
3704 /* Count its size. */
3705 total_bytes += fieldsize;
3707 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3708 error ("invalid initial value for member `%s'",
3709 IDENTIFIER_POINTER (DECL_NAME (field)));
3710 else
3712 /* Element that is a bit-field. */
3714 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3715 int end_offset
3716 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3718 if (val == 0)
3719 val = integer_zero_node;
3721 /* If this field does not start in this (or, next) byte,
3722 skip some bytes. */
3723 if (next_offset / BITS_PER_UNIT != total_bytes)
3725 /* Output remnant of any bit field in previous bytes. */
3726 if (byte_buffer_in_use)
3728 ASM_OUTPUT_BYTE (asm_out_file, byte);
3729 total_bytes++;
3730 byte_buffer_in_use = 0;
3733 /* If still not at proper byte, advance to there. */
3734 if (next_offset / BITS_PER_UNIT != total_bytes)
3736 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3737 total_bytes = next_offset / BITS_PER_UNIT;
3741 if (! byte_buffer_in_use)
3742 byte = 0;
3744 /* We must split the element into pieces that fall within
3745 separate bytes, and combine each byte with previous or
3746 following bit-fields. */
3748 /* next_offset is the offset n fbits from the beginning of
3749 the structure to the next bit of this element to be processed.
3750 end_offset is the offset of the first bit past the end of
3751 this element. */
3752 while (next_offset < end_offset)
3754 int this_time;
3755 int shift;
3756 HOST_WIDE_INT value;
3757 int next_byte = next_offset / BITS_PER_UNIT;
3758 int next_bit = next_offset % BITS_PER_UNIT;
3760 /* Advance from byte to byte
3761 within this element when necessary. */
3762 while (next_byte != total_bytes)
3764 ASM_OUTPUT_BYTE (asm_out_file, byte);
3765 total_bytes++;
3766 byte = 0;
3769 /* Number of bits we can process at once
3770 (all part of the same byte). */
3771 this_time = MIN (end_offset - next_offset,
3772 BITS_PER_UNIT - next_bit);
3773 if (BYTES_BIG_ENDIAN)
3775 /* On big-endian machine, take the most significant bits
3776 first (of the bits that are significant)
3777 and put them into bytes from the most significant end. */
3778 shift = end_offset - next_offset - this_time;
3779 /* Don't try to take a bunch of bits that cross
3780 the word boundary in the INTEGER_CST. */
3781 if (shift < HOST_BITS_PER_WIDE_INT
3782 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3784 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3785 shift = HOST_BITS_PER_WIDE_INT;
3788 /* Now get the bits from the appropriate constant word. */
3789 if (shift < HOST_BITS_PER_WIDE_INT)
3791 value = TREE_INT_CST_LOW (val);
3793 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3795 value = TREE_INT_CST_HIGH (val);
3796 shift -= HOST_BITS_PER_WIDE_INT;
3798 else
3799 abort ();
3800 byte |= (((value >> shift)
3801 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3802 << (BITS_PER_UNIT - this_time - next_bit));
3804 else
3806 /* On little-endian machines,
3807 take first the least significant bits of the value
3808 and pack them starting at the least significant
3809 bits of the bytes. */
3810 shift = (next_offset
3811 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3812 /* Don't try to take a bunch of bits that cross
3813 the word boundary in the INTEGER_CST. */
3814 if (shift < HOST_BITS_PER_WIDE_INT
3815 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3817 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3818 shift = HOST_BITS_PER_WIDE_INT;
3821 /* Now get the bits from the appropriate constant word. */
3822 if (shift < HOST_BITS_PER_INT)
3823 value = TREE_INT_CST_LOW (val);
3824 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3826 value = TREE_INT_CST_HIGH (val);
3827 shift -= HOST_BITS_PER_WIDE_INT;
3829 else
3830 abort ();
3831 byte |= (((value >> shift)
3832 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3833 << next_bit);
3835 next_offset += this_time;
3836 byte_buffer_in_use = 1;
3840 if (byte_buffer_in_use)
3842 ASM_OUTPUT_BYTE (asm_out_file, byte);
3843 total_bytes++;
3845 if (total_bytes < size)
3846 assemble_zeros (size - total_bytes);
3850 #ifdef HANDLE_SYSV_PRAGMA
3852 /* Support #pragma weak by default if WEAK_ASM_OP and ASM_OUTPUT_DEF
3853 are defined. */
3854 #if defined (WEAK_ASM_OP) && defined (ASM_OUTPUT_DEF)
3856 /* See c-pragma.c for an identical definition. */
3857 enum pragma_state
3859 ps_start,
3860 ps_done,
3861 ps_bad,
3862 ps_weak,
3863 ps_name,
3864 ps_equals,
3865 ps_value,
3866 ps_pack,
3867 ps_left,
3868 ps_align,
3869 ps_right
3872 /* Output asm to handle ``#pragma weak'' */
3873 void
3874 handle_pragma_weak (what, asm_out_file, name, value)
3875 enum pragma_state what;
3876 FILE *asm_out_file;
3877 char *name, *value;
3879 if (what == ps_name || what == ps_value)
3881 fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
3883 if (output_bytecode)
3884 BC_OUTPUT_LABELREF (asm_out_file, name);
3885 else
3886 ASM_OUTPUT_LABELREF (asm_out_file, name);
3888 fputc ('\n', asm_out_file);
3889 if (what == ps_value)
3890 ASM_OUTPUT_DEF (asm_out_file, name, value);
3892 else if (! (what == ps_done || what == ps_start))
3893 warning ("malformed `#pragma weak'");
3896 #endif /* HANDLE_PRAGMA_WEAK or (WEAK_ASM_OP and SET_ASM_OP) */
3898 #endif /* WEAK_ASM_OP && ASM_OUTPUT_DEF */