Initial revision
[official-gcc.git] / gcc / varasm.c
blob74c8d57f40b34032e09745c54ae7ee2869eb5ca7
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 /* Switch to the section for function DECL.
250 If DECL is NULL_TREE, switch to the text section.
251 ??? It's not clear that we will ever be passed NULL_TREE, but it's
252 safer to handle it. */
254 void
255 function_section (decl)
256 tree decl;
258 if (decl != NULL_TREE
259 && DECL_SECTION_NAME (decl) != NULL_TREE)
260 named_section (decl, (char *) 0);
261 else
262 text_section ();
265 /* Create the rtl to represent a function, for a function definition.
266 DECL is a FUNCTION_DECL node which describes which function.
267 The rtl is stored into DECL. */
269 void
270 make_function_rtl (decl)
271 tree decl;
273 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
275 if (output_bytecode)
277 if (DECL_RTL (decl) == 0)
278 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
280 /* Record that at least one function has been defined. */
281 function_defined = 1;
282 return;
285 /* Rename a nested function to avoid conflicts. */
286 if (decl_function_context (decl) != 0
287 && DECL_INITIAL (decl) != 0
288 && DECL_RTL (decl) == 0)
290 char *label;
292 name = IDENTIFIER_POINTER (DECL_NAME (decl));
293 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
294 name = obstack_copy0 (saveable_obstack, label, strlen (label));
295 var_labelno++;
298 if (DECL_RTL (decl) == 0)
300 DECL_RTL (decl)
301 = gen_rtx (MEM, DECL_MODE (decl),
302 gen_rtx (SYMBOL_REF, Pmode, name));
304 /* Optionally set flags or add text to the name to record information
305 such as that it is a function name. If the name is changed, the macro
306 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
307 #ifdef ENCODE_SECTION_INFO
308 ENCODE_SECTION_INFO (decl);
309 #endif
312 /* Record at least one function has been defined. */
313 function_defined = 1;
316 /* Create the DECL_RTL for a declaration for a static or external
317 variable or static or external function.
318 ASMSPEC, if not 0, is the string which the user specified
319 as the assembler symbol name.
320 TOP_LEVEL is nonzero if this is a file-scope variable.
321 This is never called for PARM_DECLs. */
323 static void
324 bc_make_decl_rtl (decl, asmspec, top_level)
325 tree decl;
326 char *asmspec;
327 int top_level;
329 register char *name = TREE_STRING_POINTER (DECL_ASSEMBLER_NAME (decl));
331 if (DECL_RTL (decl) == 0)
333 /* Print an error message for register variables. */
334 if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
335 error ("function declared `register'");
336 else if (DECL_REGISTER (decl))
337 error ("global register variables not supported in the interpreter");
339 /* Handle ordinary static variables and functions. */
340 if (DECL_RTL (decl) == 0)
342 /* Can't use just the variable's own name for a variable
343 whose scope is less than the whole file.
344 Concatenate a distinguishing number. */
345 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
347 char *label;
349 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
350 name = obstack_copy0 (saveable_obstack, label, strlen (label));
351 var_labelno++;
354 DECL_RTL (decl) = bc_gen_rtx (name, 0, (struct bc_label *) 0);
359 /* Given NAME, a putative register name, discard any customary prefixes. */
361 static char *
362 strip_reg_name (name)
363 char *name;
365 #ifdef REGISTER_PREFIX
366 if (!strncmp (name, REGISTER_PREFIX, strlen (REGISTER_PREFIX)))
367 name += strlen (REGISTER_PREFIX);
368 #endif
369 if (name[0] == '%' || name[0] == '#')
370 name++;
371 return name;
374 /* Decode an `asm' spec for a declaration as a register name.
375 Return the register number, or -1 if nothing specified,
376 or -2 if the ASMSPEC is not `cc' or `memory' and is not recognized,
377 or -3 if ASMSPEC is `cc' and is not recognized,
378 or -4 if ASMSPEC is `memory' and is not recognized.
379 Accept an exact spelling or a decimal number.
380 Prefixes such as % are optional. */
383 decode_reg_name (asmspec)
384 char *asmspec;
386 if (asmspec != 0)
388 int i;
390 /* Get rid of confusing prefixes. */
391 asmspec = strip_reg_name (asmspec);
393 /* Allow a decimal number as a "register name". */
394 for (i = strlen (asmspec) - 1; i >= 0; i--)
395 if (! (asmspec[i] >= '0' && asmspec[i] <= '9'))
396 break;
397 if (asmspec[0] != 0 && i < 0)
399 i = atoi (asmspec);
400 if (i < FIRST_PSEUDO_REGISTER && i >= 0)
401 return i;
402 else
403 return -2;
406 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
407 if (reg_names[i][0]
408 && ! strcmp (asmspec, strip_reg_name (reg_names[i])))
409 return i;
411 #ifdef ADDITIONAL_REGISTER_NAMES
413 static struct { char *name; int number; } table[]
414 = ADDITIONAL_REGISTER_NAMES;
416 for (i = 0; i < sizeof (table) / sizeof (table[0]); i++)
417 if (! strcmp (asmspec, table[i].name))
418 return table[i].number;
420 #endif /* ADDITIONAL_REGISTER_NAMES */
422 if (!strcmp (asmspec, "memory"))
423 return -4;
425 if (!strcmp (asmspec, "cc"))
426 return -3;
428 return -2;
431 return -1;
434 /* Create the DECL_RTL for a declaration for a static or external variable
435 or static or external function.
436 ASMSPEC, if not 0, is the string which the user specified
437 as the assembler symbol name.
438 TOP_LEVEL is nonzero if this is a file-scope variable.
440 This is never called for PARM_DECL nodes. */
442 void
443 make_decl_rtl (decl, asmspec, top_level)
444 tree decl;
445 char *asmspec;
446 int top_level;
448 register char *name = 0;
449 int reg_number;
451 if (output_bytecode)
453 bc_make_decl_rtl (decl, asmspec, top_level);
454 return;
457 reg_number = decode_reg_name (asmspec);
459 if (DECL_ASSEMBLER_NAME (decl) != NULL_TREE)
460 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
462 if (reg_number == -2)
464 /* ASMSPEC is given, and not the name of a register. */
465 name = (char *) obstack_alloc (saveable_obstack,
466 strlen (asmspec) + 2);
467 name[0] = '*';
468 strcpy (&name[1], asmspec);
471 /* For a duplicate declaration, we can be called twice on the
472 same DECL node. Don't discard the RTL already made. */
473 if (DECL_RTL (decl) == 0)
475 DECL_RTL (decl) = 0;
477 /* First detect errors in declaring global registers. */
478 if (DECL_REGISTER (decl) && reg_number == -1)
479 error_with_decl (decl,
480 "register name not specified for `%s'");
481 else if (DECL_REGISTER (decl) && reg_number < 0)
482 error_with_decl (decl,
483 "invalid register name for `%s'");
484 else if ((reg_number >= 0 || reg_number == -3) && ! DECL_REGISTER (decl))
485 error_with_decl (decl,
486 "register name given for non-register variable `%s'");
487 else if (DECL_REGISTER (decl) && TREE_CODE (decl) == FUNCTION_DECL)
488 error ("function declared `register'");
489 else if (DECL_REGISTER (decl) && TYPE_MODE (TREE_TYPE (decl)) == BLKmode)
490 error_with_decl (decl, "data type of `%s' isn't suitable for a register");
491 else if (DECL_REGISTER (decl)
492 && ! HARD_REGNO_MODE_OK (reg_number, TYPE_MODE (TREE_TYPE (decl))))
493 error_with_decl (decl, "register number for `%s' isn't suitable for the data type");
494 /* Now handle properly declared static register variables. */
495 else if (DECL_REGISTER (decl))
497 int nregs;
498 #if 0 /* yylex should print the warning for this */
499 if (pedantic)
500 pedwarn ("ANSI C forbids global register variables");
501 #endif
502 if (DECL_INITIAL (decl) != 0 && top_level)
504 DECL_INITIAL (decl) = 0;
505 error ("global register variable has initial value");
507 if (fixed_regs[reg_number] == 0
508 && function_defined && top_level)
509 error ("global register variable follows a function definition");
510 if (TREE_THIS_VOLATILE (decl))
511 warning ("volatile register variables don't work as you might wish");
513 /* If the user specified one of the eliminables registers here,
514 e.g., FRAME_POINTER_REGNUM, we don't want to get this variable
515 confused with that register and be eliminated. Although this
516 usage is somewhat suspect, we nevertheless use the following
517 kludge to avoid setting DECL_RTL to frame_pointer_rtx. */
519 DECL_RTL (decl)
520 = gen_rtx (REG, DECL_MODE (decl), FIRST_PSEUDO_REGISTER);
521 REGNO (DECL_RTL (decl)) = reg_number;
522 REG_USERVAR_P (DECL_RTL (decl)) = 1;
524 if (top_level)
526 /* Make this register global, so not usable for anything
527 else. */
528 nregs = HARD_REGNO_NREGS (reg_number, DECL_MODE (decl));
529 while (nregs > 0)
530 globalize_reg (reg_number + --nregs);
533 /* Specifying a section attribute on an uninitialized variable does not
534 (and cannot) cause it to be put in the given section. The linker
535 can only put initialized objects in specific sections, everything
536 else goes in bss for the linker to sort out later (otherwise the
537 linker would give a duplicate definition error for each compilation
538 unit that behaved thusly). So warn the user. */
539 else if (TREE_CODE (decl) == VAR_DECL
540 && DECL_SECTION_NAME (decl) != NULL_TREE
541 && DECL_INITIAL (decl) == NULL_TREE)
543 warning_with_decl (decl,
544 "section attribute ignored for uninitialized variable `%s'");
545 /* Remove the section name so subsequent declarations won't see it.
546 We are ignoring it, remember. */
547 DECL_SECTION_NAME (decl) = NULL_TREE;
550 /* Now handle ordinary static variables and functions (in memory).
551 Also handle vars declared register invalidly. */
552 if (DECL_RTL (decl) == 0)
554 /* Can't use just the variable's own name for a variable
555 whose scope is less than the whole file.
556 Concatenate a distinguishing number. */
557 if (!top_level && !DECL_EXTERNAL (decl) && asmspec == 0)
559 char *label;
561 ASM_FORMAT_PRIVATE_NAME (label, name, var_labelno);
562 name = obstack_copy0 (saveable_obstack, label, strlen (label));
563 var_labelno++;
566 if (name == 0)
567 abort ();
569 DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl),
570 gen_rtx (SYMBOL_REF, Pmode, name));
572 /* If this variable is to be treated as volatile, show its
573 tree node has side effects. If it has side effects, either
574 because of this test or from TREE_THIS_VOLATILE also
575 being set, show the MEM is volatile. */
576 if (flag_volatile_global && TREE_CODE (decl) == VAR_DECL
577 && TREE_PUBLIC (decl))
578 TREE_SIDE_EFFECTS (decl) = 1;
579 if (TREE_SIDE_EFFECTS (decl))
580 MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
582 if (TREE_READONLY (decl))
583 RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
584 MEM_IN_STRUCT_P (DECL_RTL (decl))
585 = AGGREGATE_TYPE_P (TREE_TYPE (decl));
587 /* Optionally set flags or add text to the name to record information
588 such as that it is a function name.
589 If the name is changed, the macro ASM_OUTPUT_LABELREF
590 will have to know how to strip this information. */
591 #ifdef ENCODE_SECTION_INFO
592 ENCODE_SECTION_INFO (decl);
593 #endif
596 /* If the old RTL had the wrong mode, fix the mode. */
597 else if (GET_MODE (DECL_RTL (decl)) != DECL_MODE (decl))
599 rtx rtl = DECL_RTL (decl);
600 PUT_MODE (rtl, DECL_MODE (decl));
604 /* Make the rtl for variable VAR be volatile.
605 Use this only for static variables. */
607 void
608 make_var_volatile (var)
609 tree var;
611 if (GET_CODE (DECL_RTL (var)) != MEM)
612 abort ();
614 MEM_VOLATILE_P (DECL_RTL (var)) = 1;
617 /* Output alignment directive to align for constant expression EXP. */
619 void
620 assemble_constant_align (exp)
621 tree exp;
623 int align;
625 /* Align the location counter as required by EXP's data type. */
626 align = TYPE_ALIGN (TREE_TYPE (exp));
627 #ifdef CONSTANT_ALIGNMENT
628 align = CONSTANT_ALIGNMENT (exp, align);
629 #endif
631 if (align > BITS_PER_UNIT)
632 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
635 /* Output a string of literal assembler code
636 for an `asm' keyword used between functions. */
638 void
639 assemble_asm (string)
640 tree string;
642 if (output_bytecode)
644 error ("asm statements not allowed in interpreter");
645 return;
648 app_enable ();
650 if (TREE_CODE (string) == ADDR_EXPR)
651 string = TREE_OPERAND (string, 0);
653 fprintf (asm_out_file, "\t%s\n", TREE_STRING_POINTER (string));
656 #if 0 /* This should no longer be needed, because
657 flag_gnu_linker should be 0 on these systems,
658 which should prevent any output
659 if ASM_OUTPUT_CONSTRUCTOR and ASM_OUTPUT_DESTRUCTOR are absent. */
660 #if !(defined(DBX_DEBUGGING_INFO) && !defined(FASCIST_ASSEMBLER))
661 #ifndef ASM_OUTPUT_CONSTRUCTOR
662 #define ASM_OUTPUT_CONSTRUCTOR(file, name)
663 #endif
664 #ifndef ASM_OUTPUT_DESTRUCTOR
665 #define ASM_OUTPUT_DESTRUCTOR(file, name)
666 #endif
667 #endif
668 #endif /* 0 */
670 /* Record an element in the table of global destructors.
671 How this is done depends on what sort of assembler and linker
672 are in use.
674 NAME should be the name of a global function to be called
675 at exit time. This name is output using assemble_name. */
677 void
678 assemble_destructor (name)
679 char *name;
681 #ifdef ASM_OUTPUT_DESTRUCTOR
682 ASM_OUTPUT_DESTRUCTOR (asm_out_file, name);
683 #else
684 if (flag_gnu_linker)
686 /* Now tell GNU LD that this is part of the static destructor set. */
687 /* This code works for any machine provided you use GNU as/ld. */
688 fprintf (asm_out_file, "%s \"___DTOR_LIST__\",22,0,0,", ASM_STABS_OP);
689 assemble_name (asm_out_file, name);
690 fputc ('\n', asm_out_file);
692 #endif
695 /* Likewise for global constructors. */
697 void
698 assemble_constructor (name)
699 char *name;
701 #ifdef ASM_OUTPUT_CONSTRUCTOR
702 ASM_OUTPUT_CONSTRUCTOR (asm_out_file, name);
703 #else
704 if (flag_gnu_linker)
706 /* Now tell GNU LD that this is part of the static constructor set. */
707 /* This code works for any machine provided you use GNU as/ld. */
708 fprintf (asm_out_file, "%s \"___CTOR_LIST__\",22,0,0,", ASM_STABS_OP);
709 assemble_name (asm_out_file, name);
710 fputc ('\n', asm_out_file);
712 #endif
715 /* Likewise for entries we want to record for garbage collection.
716 Garbage collection is still under development. */
718 void
719 assemble_gc_entry (name)
720 char *name;
722 #ifdef ASM_OUTPUT_GC_ENTRY
723 ASM_OUTPUT_GC_ENTRY (asm_out_file, name);
724 #else
725 if (flag_gnu_linker)
727 /* Now tell GNU LD that this is part of the static constructor set. */
728 fprintf (asm_out_file, "%s \"___PTR_LIST__\",22,0,0,", ASM_STABS_OP);
729 assemble_name (asm_out_file, name);
730 fputc ('\n', asm_out_file);
732 #endif
735 /* Output assembler code for the constant pool of a function and associated
736 with defining the name of the function. DECL describes the function.
737 NAME is the function's name. For the constant pool, we use the current
738 constant pool data. */
740 void
741 assemble_start_function (decl, fnname)
742 tree decl;
743 char *fnname;
745 int align;
747 /* The following code does not need preprocessing in the assembler. */
749 app_disable ();
751 output_constant_pool (fnname, decl);
753 function_section (decl);
755 /* Tell assembler to move to target machine's alignment for functions. */
756 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
757 if (align > 0)
759 if (output_bytecode)
760 BC_OUTPUT_ALIGN (asm_out_file, align);
761 else
762 ASM_OUTPUT_ALIGN (asm_out_file, align);
765 #ifdef ASM_OUTPUT_FUNCTION_PREFIX
766 ASM_OUTPUT_FUNCTION_PREFIX (asm_out_file, fnname);
767 #endif
769 #ifdef SDB_DEBUGGING_INFO
770 /* Output SDB definition of the function. */
771 if (write_symbols == SDB_DEBUG)
772 sdbout_mark_begin_function ();
773 #endif
775 #ifdef DBX_DEBUGGING_INFO
776 /* Output DBX definition of the function. */
777 if (write_symbols == DBX_DEBUG)
778 dbxout_begin_function (decl);
779 #endif
781 /* Make function name accessible from other files, if appropriate. */
783 if (TREE_PUBLIC (decl))
785 if (!first_global_object_name)
786 STRIP_NAME_ENCODING (first_global_object_name, fnname);
787 if (output_bytecode)
788 BC_GLOBALIZE_LABEL (asm_out_file, fnname);
789 else
790 ASM_GLOBALIZE_LABEL (asm_out_file, fnname);
793 /* Do any machine/system dependent processing of the function name */
794 #ifdef ASM_DECLARE_FUNCTION_NAME
795 ASM_DECLARE_FUNCTION_NAME (asm_out_file, fnname, current_function_decl);
796 #else
797 /* Standard thing is just output label for the function. */
798 if (output_bytecode)
799 BC_OUTPUT_LABEL (asm_out_file, fnname);
800 else
801 ASM_OUTPUT_LABEL (asm_out_file, fnname);
802 #endif /* ASM_DECLARE_FUNCTION_NAME */
805 /* Output assembler code associated with defining the size of the
806 function. DECL describes the function. NAME is the function's name. */
808 void
809 assemble_end_function (decl, fnname)
810 tree decl;
811 char *fnname;
813 #ifdef ASM_DECLARE_FUNCTION_SIZE
814 ASM_DECLARE_FUNCTION_SIZE (asm_out_file, fnname, decl);
815 #endif
818 /* Assemble code to leave SIZE bytes of zeros. */
820 void
821 assemble_zeros (size)
822 int size;
824 if (output_bytecode)
826 bc_emit_const_skip (size);
827 return;
830 #ifdef ASM_NO_SKIP_IN_TEXT
831 /* The `space' pseudo in the text section outputs nop insns rather than 0s,
832 so we must output 0s explicitly in the text section. */
833 if (ASM_NO_SKIP_IN_TEXT && in_text_section ())
835 int i;
837 for (i = 0; i < size - 20; i += 20)
839 #ifdef ASM_BYTE_OP
840 fprintf (asm_out_file,
841 "%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);
842 #else
843 fprintf (asm_out_file,
844 "\tbyte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n");
845 #endif
847 if (i < size)
849 #ifdef ASM_BYTE_OP
850 fprintf (asm_out_file, "%s 0", ASM_BYTE_OP);
851 #else
852 fprintf (asm_out_file, "\tbyte 0");
853 #endif
854 i++;
855 for (; i < size; i++)
856 fprintf (asm_out_file, ",0");
857 fprintf (asm_out_file, "\n");
860 else
861 #endif
862 if (size > 0)
864 if (output_bytecode)
865 BC_OUTPUT_SKIP (asm_out_file, size);
866 else
867 ASM_OUTPUT_SKIP (asm_out_file, size);
871 /* Assemble an alignment pseudo op for an ALIGN-bit boundary. */
873 void
874 assemble_align (align)
875 int align;
877 if (align > BITS_PER_UNIT)
878 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
881 /* Assemble a string constant with the specified C string as contents. */
883 void
884 assemble_string (p, size)
885 char *p;
886 int size;
888 register int i;
889 int pos = 0;
890 int maximum = 2000;
892 if (output_bytecode)
894 bc_emit (p, size);
895 return;
898 /* If the string is very long, split it up. */
900 while (pos < size)
902 int thissize = size - pos;
903 if (thissize > maximum)
904 thissize = maximum;
906 if (output_bytecode)
907 bc_output_ascii (asm_out_file, p, thissize);
908 else
910 ASM_OUTPUT_ASCII (asm_out_file, p, thissize);
913 pos += thissize;
914 p += thissize;
918 static void
919 bc_output_ascii (file, p, size)
920 FILE *file;
921 char *p;
922 int size;
924 BC_OUTPUT_ASCII (file, p, size);
927 /* Assemble everything that is needed for a variable or function declaration.
928 Not used for automatic variables, and not used for function definitions.
929 Should not be called for variables of incomplete structure type.
931 TOP_LEVEL is nonzero if this variable has file scope.
932 AT_END is nonzero if this is the special handling, at end of compilation,
933 to define things that have had only tentative definitions.
934 DONT_OUTPUT_DATA if nonzero means don't actually output the
935 initial value (that will be done by the caller). */
937 void
938 assemble_variable (decl, top_level, at_end, dont_output_data)
939 tree decl;
940 int top_level;
941 int at_end;
942 int dont_output_data;
944 register char *name;
945 int align;
946 tree size_tree;
947 int reloc = 0;
948 enum in_section saved_in_section;
950 last_assemble_variable_decl = 0;
952 if (output_bytecode)
953 return;
955 if (GET_CODE (DECL_RTL (decl)) == REG)
957 /* Do output symbol info for global register variables, but do nothing
958 else for them. */
960 if (TREE_ASM_WRITTEN (decl))
961 return;
962 TREE_ASM_WRITTEN (decl) = 1;
964 if (!output_bytecode)
966 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
967 /* File-scope global variables are output here. */
968 if ((write_symbols == DBX_DEBUG || write_symbols == XCOFF_DEBUG)
969 && top_level)
970 dbxout_symbol (decl, 0);
971 #endif
972 #ifdef SDB_DEBUGGING_INFO
973 if (write_symbols == SDB_DEBUG && top_level
974 /* Leave initialized global vars for end of compilation;
975 see comment in compile_file. */
976 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
977 sdbout_symbol (decl, 0);
978 #endif
981 /* Don't output any DWARF debugging information for variables here.
982 In the case of local variables, the information for them is output
983 when we do our recursive traversal of the tree representation for
984 the entire containing function. In the case of file-scope variables,
985 we output information for all of them at the very end of compilation
986 while we are doing our final traversal of the chain of file-scope
987 declarations. */
989 return;
992 /* Normally no need to say anything here for external references,
993 since assemble_external is called by the langauge-specific code
994 when a declaration is first seen. */
996 if (DECL_EXTERNAL (decl))
997 return;
999 /* Output no assembler code for a function declaration.
1000 Only definitions of functions output anything. */
1002 if (TREE_CODE (decl) == FUNCTION_DECL)
1003 return;
1005 /* If type was incomplete when the variable was declared,
1006 see if it is complete now. */
1008 if (DECL_SIZE (decl) == 0)
1009 layout_decl (decl, 0);
1011 /* Still incomplete => don't allocate it; treat the tentative defn
1012 (which is what it must have been) as an `extern' reference. */
1014 if (!dont_output_data && DECL_SIZE (decl) == 0)
1016 error_with_file_and_line (DECL_SOURCE_FILE (decl),
1017 DECL_SOURCE_LINE (decl),
1018 "storage size of `%s' isn't known",
1019 IDENTIFIER_POINTER (DECL_NAME (decl)));
1020 TREE_ASM_WRITTEN (decl) = 1;
1021 return;
1024 /* The first declaration of a variable that comes through this function
1025 decides whether it is global (in C, has external linkage)
1026 or local (in C, has internal linkage). So do nothing more
1027 if this function has already run. */
1029 if (TREE_ASM_WRITTEN (decl))
1030 return;
1032 TREE_ASM_WRITTEN (decl) = 1;
1034 /* If storage size is erroneously variable, just continue.
1035 Error message was already made. */
1037 if (DECL_SIZE (decl))
1039 if (TREE_CODE (DECL_SIZE (decl)) != INTEGER_CST)
1040 goto finish;
1042 app_disable ();
1044 /* This is better than explicit arithmetic, since it avoids overflow. */
1045 size_tree = size_binop (CEIL_DIV_EXPR,
1046 DECL_SIZE (decl), size_int (BITS_PER_UNIT));
1048 if (TREE_INT_CST_HIGH (size_tree) != 0)
1050 error_with_decl (decl, "size of variable `%s' is too large");
1051 goto finish;
1055 name = XSTR (XEXP (DECL_RTL (decl), 0), 0);
1057 /* Handle uninitialized definitions. */
1059 /* ANSI specifies that a tentative definition which is not merged with
1060 a non-tentative definition behaves exactly like a definition with an
1061 initializer equal to zero. (Section 3.7.2)
1062 -fno-common gives strict ANSI behavior. Usually you don't want it.
1063 This matters only for variables with external linkage. */
1064 if ((! flag_no_common || ! TREE_PUBLIC (decl))
1065 && DECL_COMMON (decl)
1066 && ! dont_output_data
1067 && (DECL_INITIAL (decl) == 0 || DECL_INITIAL (decl) == error_mark_node))
1069 int size = TREE_INT_CST_LOW (size_tree);
1070 int rounded = size;
1072 if (TREE_INT_CST_HIGH (size_tree) != 0)
1073 error_with_decl (decl, "size of variable `%s' is too large");
1074 /* Don't allocate zero bytes of common,
1075 since that means "undefined external" in the linker. */
1076 if (size == 0) rounded = 1;
1077 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1078 so that each uninitialized object starts on such a boundary. */
1079 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;
1080 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1081 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1083 #ifdef DBX_DEBUGGING_INFO
1084 /* File-scope global variables are output here. */
1085 if (write_symbols == DBX_DEBUG && top_level)
1086 dbxout_symbol (decl, 0);
1087 #endif
1088 #ifdef SDB_DEBUGGING_INFO
1089 if (write_symbols == SDB_DEBUG && top_level
1090 /* Leave initialized global vars for end of compilation;
1091 see comment in compile_file. */
1092 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1093 sdbout_symbol (decl, 0);
1094 #endif
1096 /* Don't output any DWARF debugging information for variables here.
1097 In the case of local variables, the information for them is output
1098 when we do our recursive traversal of the tree representation for
1099 the entire containing function. In the case of file-scope variables,
1100 we output information for all of them at the very end of compilation
1101 while we are doing our final traversal of the chain of file-scope
1102 declarations. */
1104 #if 0
1105 if (flag_shared_data)
1106 data_section ();
1107 #endif
1108 if (TREE_PUBLIC (decl))
1110 #ifdef ASM_OUTPUT_SHARED_COMMON
1111 if (flag_shared_data)
1112 ASM_OUTPUT_SHARED_COMMON (asm_out_file, name, size, rounded);
1113 else
1114 #endif
1115 if (output_bytecode)
1117 BC_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1119 else
1121 #ifdef ASM_OUTPUT_ALIGNED_COMMON
1122 ASM_OUTPUT_ALIGNED_COMMON (asm_out_file, name, size,
1123 DECL_ALIGN (decl));
1124 #else
1125 ASM_OUTPUT_COMMON (asm_out_file, name, size, rounded);
1126 #endif
1129 else
1131 #ifdef ASM_OUTPUT_SHARED_LOCAL
1132 if (flag_shared_data)
1133 ASM_OUTPUT_SHARED_LOCAL (asm_out_file, name, size, rounded);
1134 else
1135 #endif
1136 if (output_bytecode)
1138 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1140 else
1142 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1143 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size,
1144 DECL_ALIGN (decl));
1145 #else
1146 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1147 #endif
1150 goto finish;
1153 /* Handle initialized definitions. */
1155 /* First make the assembler name(s) global if appropriate. */
1156 if (TREE_PUBLIC (decl) && DECL_NAME (decl))
1158 if (!first_global_object_name)
1159 STRIP_NAME_ENCODING(first_global_object_name, name);
1160 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1162 #if 0
1163 for (d = equivalents; d; d = TREE_CHAIN (d))
1165 tree e = TREE_VALUE (d);
1166 if (TREE_PUBLIC (e) && DECL_NAME (e))
1167 ASM_GLOBALIZE_LABEL (asm_out_file,
1168 XSTR (XEXP (DECL_RTL (e), 0), 0));
1170 #endif
1172 /* Output any data that we will need to use the address of. */
1173 if (DECL_INITIAL (decl) == error_mark_node)
1174 reloc = contains_pointers_p (TREE_TYPE (decl));
1175 else if (DECL_INITIAL (decl))
1176 reloc = output_addressed_constants (DECL_INITIAL (decl));
1178 /* Switch to the proper section for this data. */
1179 if (IN_NAMED_SECTION (decl))
1180 named_section (decl, NULL);
1181 else
1183 /* C++ can have const variables that get initialized from constructors,
1184 and thus can not be in a readonly section. We prevent this by
1185 verifying that the initial value is constant for objects put in a
1186 readonly section.
1188 error_mark_node is used by the C front end to indicate that the
1189 initializer has not been seen yet. In this case, we assume that
1190 the initializer must be constant. */
1191 #ifdef SELECT_SECTION
1192 SELECT_SECTION (decl, reloc);
1193 #else
1194 if (TREE_READONLY (decl)
1195 && ! TREE_THIS_VOLATILE (decl)
1196 && DECL_INITIAL (decl)
1197 && (DECL_INITIAL (decl) == error_mark_node
1198 || TREE_CONSTANT (DECL_INITIAL (decl)))
1199 && ! (flag_pic && reloc))
1200 readonly_data_section ();
1201 else
1202 data_section ();
1203 #endif
1206 /* dbxout.c needs to know this. */
1207 if (in_text_section ())
1208 DECL_IN_TEXT_SECTION (decl) = 1;
1210 /* Record current section so we can restore it if dbxout.c clobbers it. */
1211 saved_in_section = in_section;
1213 /* Output the dbx info now that we have chosen the section. */
1215 #ifdef DBX_DEBUGGING_INFO
1216 /* File-scope global variables are output here. */
1217 if (write_symbols == DBX_DEBUG && top_level)
1218 dbxout_symbol (decl, 0);
1219 #endif
1220 #ifdef SDB_DEBUGGING_INFO
1221 if (write_symbols == SDB_DEBUG && top_level
1222 /* Leave initialized global vars for end of compilation;
1223 see comment in compile_file. */
1224 && (TREE_PUBLIC (decl) == 0 || DECL_INITIAL (decl) == 0))
1225 sdbout_symbol (decl, 0);
1226 #endif
1228 /* Don't output any DWARF debugging information for variables here.
1229 In the case of local variables, the information for them is output
1230 when we do our recursive traversal of the tree representation for
1231 the entire containing function. In the case of file-scope variables,
1232 we output information for all of them at the very end of compilation
1233 while we are doing our final traversal of the chain of file-scope
1234 declarations. */
1236 /* If the debugging output changed sections, reselect the section
1237 that's supposed to be selected. */
1238 if (in_section != saved_in_section)
1240 /* Switch to the proper section for this data. */
1241 #ifdef SELECT_SECTION
1242 SELECT_SECTION (decl, reloc);
1243 #else
1244 if (TREE_READONLY (decl)
1245 && ! TREE_THIS_VOLATILE (decl)
1246 && DECL_INITIAL (decl)
1247 && (DECL_INITIAL (decl) == error_mark_node
1248 || TREE_CONSTANT (DECL_INITIAL (decl)))
1249 && ! (flag_pic && reloc))
1250 readonly_data_section ();
1251 else
1252 data_section ();
1253 #endif
1256 /* Compute and output the alignment of this data. */
1258 align = DECL_ALIGN (decl);
1259 /* In the case for initialing an array whose length isn't specified,
1260 where we have not yet been able to do the layout,
1261 figure out the proper alignment now. */
1262 if (dont_output_data && DECL_SIZE (decl) == 0
1263 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE)
1264 align = MAX (align, TYPE_ALIGN (TREE_TYPE (TREE_TYPE (decl))));
1266 /* Some object file formats have a maximum alignment which they support.
1267 In particular, a.out format supports a maximum alignment of 4. */
1268 #ifndef MAX_OFILE_ALIGNMENT
1269 #define MAX_OFILE_ALIGNMENT BIGGEST_ALIGNMENT
1270 #endif
1271 if (align > MAX_OFILE_ALIGNMENT)
1273 warning_with_decl (decl,
1274 "alignment of `%s' is greater than maximum object file alignment");
1275 align = MAX_OFILE_ALIGNMENT;
1277 #ifdef DATA_ALIGNMENT
1278 /* On some machines, it is good to increase alignment sometimes. */
1279 align = DATA_ALIGNMENT (TREE_TYPE (decl), align);
1280 #endif
1281 #ifdef CONSTANT_ALIGNMENT
1282 if (DECL_INITIAL (decl))
1283 align = CONSTANT_ALIGNMENT (DECL_INITIAL (decl), align);
1284 #endif
1286 /* Reset the alignment in case we have made it tighter, so we can benefit
1287 from it in get_pointer_alignment. */
1288 DECL_ALIGN (decl) = align;
1290 if (align > BITS_PER_UNIT)
1292 if (output_bytecode)
1293 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1294 else
1295 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
1298 /* Do any machine/system dependent processing of the object. */
1299 #ifdef ASM_DECLARE_OBJECT_NAME
1300 last_assemble_variable_decl = decl;
1301 ASM_DECLARE_OBJECT_NAME (asm_out_file, name, decl);
1302 #else
1303 /* Standard thing is just output label for the object. */
1304 if (output_bytecode)
1305 BC_OUTPUT_LABEL (asm_out_file, name);
1306 else
1307 ASM_OUTPUT_LABEL (asm_out_file, name);
1308 #endif /* ASM_DECLARE_OBJECT_NAME */
1310 if (!dont_output_data)
1312 if (DECL_INITIAL (decl))
1313 /* Output the actual data. */
1314 output_constant (DECL_INITIAL (decl),
1315 int_size_in_bytes (TREE_TYPE (decl)));
1316 else
1317 /* Leave space for it. */
1318 assemble_zeros (int_size_in_bytes (TREE_TYPE (decl)));
1321 finish:
1322 #ifdef XCOFF_DEBUGGING_INFO
1323 /* Unfortunately, the IBM assembler cannot handle stabx before the actual
1324 declaration. When something like ".stabx "aa:S-2",aa,133,0" is emitted
1325 and `aa' hasn't been output yet, the assembler generates a stab entry with
1326 a value of zero, in addition to creating an unnecessary external entry
1327 for `aa'. Hence, we must postpone dbxout_symbol to here at the end. */
1329 /* File-scope global variables are output here. */
1330 if (write_symbols == XCOFF_DEBUG && top_level)
1332 saved_in_section = in_section;
1334 dbxout_symbol (decl, 0);
1336 if (in_section != saved_in_section)
1338 /* Switch to the proper section for this data. */
1339 #ifdef SELECT_SECTION
1340 SELECT_SECTION (decl, reloc);
1341 #else
1342 if (TREE_READONLY (decl)
1343 && ! TREE_THIS_VOLATILE (decl)
1344 && DECL_INITIAL (decl)
1345 && (DECL_INITIAL (decl) == error_mark_node
1346 || TREE_CONSTANT (DECL_INITIAL (decl)))
1347 && ! (flag_pic && reloc))
1348 readonly_data_section ();
1349 else
1350 data_section ();
1351 #endif
1354 #else
1355 /* There must be a statement after a label. */
1357 #endif
1360 /* Return 1 if type TYPE contains any pointers. */
1362 static int
1363 contains_pointers_p (type)
1364 tree type;
1366 switch (TREE_CODE (type))
1368 case POINTER_TYPE:
1369 case REFERENCE_TYPE:
1370 /* I'm not sure whether OFFSET_TYPE needs this treatment,
1371 so I'll play safe and return 1. */
1372 case OFFSET_TYPE:
1373 return 1;
1375 case RECORD_TYPE:
1376 case UNION_TYPE:
1377 case QUAL_UNION_TYPE:
1379 tree fields;
1380 /* For a type that has fields, see if the fields have pointers. */
1381 for (fields = TYPE_FIELDS (type); fields; fields = TREE_CHAIN (fields))
1382 if (TREE_CODE (fields) == FIELD_DECL
1383 && contains_pointers_p (TREE_TYPE (fields)))
1384 return 1;
1385 return 0;
1388 case ARRAY_TYPE:
1389 /* An array type contains pointers if its element type does. */
1390 return contains_pointers_p (TREE_TYPE (type));
1392 default:
1393 return 0;
1397 /* Output text storage for constructor CONSTR. */
1399 void
1400 bc_output_constructor (constr, size)
1401 tree constr;
1402 int size;
1404 int i;
1406 /* Must always be a literal; non-literal constructors are handled
1407 differently. */
1409 if (!TREE_CONSTANT (constr))
1410 abort ();
1412 /* Always const */
1413 text_section ();
1415 /* Align */
1416 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++)
1419 if (i > 0)
1420 BC_OUTPUT_ALIGN (asm_out_file, i);
1422 /* Output data */
1423 output_constant (constr, size);
1426 /* Create storage for constructor CONSTR. */
1428 void
1429 bc_output_data_constructor (constr)
1430 tree constr;
1432 int i;
1434 /* Put in data section */
1435 data_section ();
1437 /* Align */
1438 for (i = 0; TYPE_ALIGN (constr) >= BITS_PER_UNIT << (i + 1); i++);
1439 if (i > 0)
1440 BC_OUTPUT_ALIGN (asm_out_file, i);
1442 /* The constructor is filled in at runtime. */
1443 BC_OUTPUT_SKIP (asm_out_file, int_size_in_bytes (TREE_TYPE (constr)));
1446 /* Output something to declare an external symbol to the assembler.
1447 (Most assemblers don't need this, so we normally output nothing.)
1448 Do nothing if DECL is not external. */
1450 void
1451 assemble_external (decl)
1452 tree decl;
1454 if (output_bytecode)
1455 return;
1457 #ifdef ASM_OUTPUT_EXTERNAL
1458 if (TREE_CODE_CLASS (TREE_CODE (decl)) == 'd'
1459 && DECL_EXTERNAL (decl) && TREE_PUBLIC (decl))
1461 rtx rtl = DECL_RTL (decl);
1463 if (GET_CODE (rtl) == MEM && GET_CODE (XEXP (rtl, 0)) == SYMBOL_REF
1464 && ! SYMBOL_REF_USED (XEXP (rtl, 0)))
1466 /* Some systems do require some output. */
1467 SYMBOL_REF_USED (XEXP (rtl, 0)) = 1;
1468 ASM_OUTPUT_EXTERNAL (asm_out_file, decl, XSTR (XEXP (rtl, 0), 0));
1471 #endif
1474 /* Similar, for calling a library function FUN. */
1476 void
1477 assemble_external_libcall (fun)
1478 rtx fun;
1480 #ifdef ASM_OUTPUT_EXTERNAL_LIBCALL
1481 if (!output_bytecode)
1483 /* Declare library function name external when first used, if nec. */
1484 if (! SYMBOL_REF_USED (fun))
1486 SYMBOL_REF_USED (fun) = 1;
1487 ASM_OUTPUT_EXTERNAL_LIBCALL (asm_out_file, fun);
1490 #endif
1493 /* Declare the label NAME global. */
1495 void
1496 assemble_global (name)
1497 char *name;
1499 ASM_GLOBALIZE_LABEL (asm_out_file, name);
1502 /* Assemble a label named NAME. */
1504 void
1505 assemble_label (name)
1506 char *name;
1508 if (output_bytecode)
1509 BC_OUTPUT_LABEL (asm_out_file, name);
1510 else
1511 ASM_OUTPUT_LABEL (asm_out_file, name);
1514 /* Output to FILE a reference to the assembler name of a C-level name NAME.
1515 If NAME starts with a *, the rest of NAME is output verbatim.
1516 Otherwise NAME is transformed in an implementation-defined way
1517 (usually by the addition of an underscore).
1518 Many macros in the tm file are defined to call this function. */
1520 void
1521 assemble_name (file, name)
1522 FILE *file;
1523 char *name;
1525 char *real_name;
1527 STRIP_NAME_ENCODING (real_name, name);
1528 TREE_SYMBOL_REFERENCED (get_identifier (real_name)) = 1;
1530 if (name[0] == '*')
1532 if (output_bytecode)
1533 bc_emit_labelref (name);
1534 else
1535 fputs (&name[1], file);
1537 else
1539 if (output_bytecode)
1540 BC_OUTPUT_LABELREF (file, name);
1541 else
1542 ASM_OUTPUT_LABELREF (file, name);
1546 /* Allocate SIZE bytes writable static space with a gensym name
1547 and return an RTX to refer to its address. */
1550 assemble_static_space (size)
1551 int size;
1553 char name[12];
1554 char *namestring;
1555 rtx x;
1556 /* Round size up to multiple of BIGGEST_ALIGNMENT bits
1557 so that each uninitialized object starts on such a boundary. */
1558 int rounded = ((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
1559 / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)
1560 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
1562 #if 0
1563 if (flag_shared_data)
1564 data_section ();
1565 #endif
1567 ASM_GENERATE_INTERNAL_LABEL (name, "LF", const_labelno);
1568 ++const_labelno;
1570 namestring = (char *) obstack_alloc (saveable_obstack,
1571 strlen (name) + 2);
1572 strcpy (namestring, name);
1574 if (output_bytecode)
1575 x = bc_gen_rtx (namestring, 0, (struct bc_label *) 0);
1576 else
1577 x = gen_rtx (SYMBOL_REF, Pmode, namestring);
1579 if (output_bytecode)
1581 BC_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1583 else
1585 #ifdef ASM_OUTPUT_ALIGNED_LOCAL
1586 ASM_OUTPUT_ALIGNED_LOCAL (asm_out_file, name, size, BIGGEST_ALIGNMENT);
1587 #else
1588 ASM_OUTPUT_LOCAL (asm_out_file, name, size, rounded);
1589 #endif
1591 return x;
1594 /* Assemble the static constant template for function entry trampolines.
1595 This is done at most once per compilation.
1596 Returns an RTX for the address of the template. */
1599 assemble_trampoline_template ()
1601 char label[256];
1602 char *name;
1603 int align;
1605 /* Shouldn't get here */
1606 if (output_bytecode)
1607 abort ();
1609 /* By default, put trampoline templates in read-only data section. */
1611 #ifdef TRAMPOLINE_SECTION
1612 TRAMPOLINE_SECTION ();
1613 #else
1614 readonly_data_section ();
1615 #endif
1617 /* Write the assembler code to define one. */
1618 align = floor_log2 (FUNCTION_BOUNDARY / BITS_PER_UNIT);
1619 if (align > 0)
1620 ASM_OUTPUT_ALIGN (asm_out_file, align);
1622 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LTRAMP", 0);
1623 TRAMPOLINE_TEMPLATE (asm_out_file);
1625 /* Record the rtl to refer to it. */
1626 ASM_GENERATE_INTERNAL_LABEL (label, "LTRAMP", 0);
1627 name
1628 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
1629 return gen_rtx (SYMBOL_REF, Pmode, name);
1632 /* Assemble the integer constant X into an object of SIZE bytes.
1633 X must be either a CONST_INT or CONST_DOUBLE.
1635 Return 1 if we were able to output the constant, otherwise 0. If FORCE is
1636 non-zero, abort if we can't output the constant. */
1639 assemble_integer (x, size, force)
1640 rtx x;
1641 int size;
1642 int force;
1644 /* First try to use the standard 1, 2, 4, 8, and 16 byte
1645 ASM_OUTPUT... macros. */
1647 switch (size)
1649 #ifdef ASM_OUTPUT_CHAR
1650 case 1:
1651 ASM_OUTPUT_CHAR (asm_out_file, x);
1652 return 1;
1653 #endif
1655 #ifdef ASM_OUTPUT_SHORT
1656 case 2:
1657 ASM_OUTPUT_SHORT (asm_out_file, x);
1658 return 1;
1659 #endif
1661 #ifdef ASM_OUTPUT_INT
1662 case 4:
1663 ASM_OUTPUT_INT (asm_out_file, x);
1664 return 1;
1665 #endif
1667 #ifdef ASM_OUTPUT_DOUBLE_INT
1668 case 8:
1669 ASM_OUTPUT_DOUBLE_INT (asm_out_file, x);
1670 return 1;
1671 #endif
1673 #ifdef ASM_OUTPUT_QUADRUPLE_INT
1674 case 16:
1675 ASM_OUTPUT_QUADRUPLE_INT (asm_out_file, x);
1676 return 1;
1677 #endif
1680 /* If we couldn't do it that way, there are two other possibilities: First,
1681 if the machine can output an explicit byte and this is a 1 byte constant,
1682 we can use ASM_OUTPUT_BYTE. */
1684 #ifdef ASM_OUTPUT_BYTE
1685 if (size == 1 && GET_CODE (x) == CONST_INT)
1687 ASM_OUTPUT_BYTE (asm_out_file, INTVAL (x));
1688 return 1;
1690 #endif
1692 /* Finally, if SIZE is larger than a single word, try to output the constant
1693 one word at a time. */
1695 if (size > UNITS_PER_WORD)
1697 int i;
1698 enum machine_mode mode
1699 = mode_for_size (size * BITS_PER_UNIT, MODE_INT, 0);
1700 rtx word;
1702 for (i = 0; i < size / UNITS_PER_WORD; i++)
1704 word = operand_subword (x, i, 0, mode);
1706 if (word == 0)
1707 break;
1709 if (! assemble_integer (word, UNITS_PER_WORD, 0))
1710 break;
1713 if (i == size / UNITS_PER_WORD)
1714 return 1;
1715 /* If we output at least one word and then could not finish,
1716 there is no valid way to continue. */
1717 if (i > 0)
1718 abort ();
1721 if (force)
1722 abort ();
1724 return 0;
1727 /* Assemble the floating-point constant D into an object of size MODE. */
1729 void
1730 assemble_real (d, mode)
1731 REAL_VALUE_TYPE d;
1732 enum machine_mode mode;
1734 jmp_buf output_constant_handler;
1736 if (setjmp (output_constant_handler))
1738 error ("floating point trap outputting a constant");
1739 #ifdef REAL_IS_NOT_DOUBLE
1740 bzero ((char *) &d, sizeof d);
1741 d = dconst0;
1742 #else
1743 d = 0;
1744 #endif
1747 set_float_handler (output_constant_handler);
1749 switch (mode)
1751 #ifdef ASM_OUTPUT_BYTE_FLOAT
1752 case QFmode:
1753 ASM_OUTPUT_BYTE_FLOAT (asm_out_file, d);
1754 break;
1755 #endif
1756 #ifdef ASM_OUTPUT_SHORT_FLOAT
1757 case HFmode:
1758 ASM_OUTPUT_SHORT_FLOAT (asm_out_file, d);
1759 break;
1760 #endif
1761 #ifdef ASM_OUTPUT_THREE_QUARTER_FLOAT
1762 case TQFmode:
1763 ASM_OUTPUT_THREE_QUARTER_FLOAT (asm_out_file, d);
1764 break;
1765 #endif
1766 #ifdef ASM_OUTPUT_FLOAT
1767 case SFmode:
1768 ASM_OUTPUT_FLOAT (asm_out_file, d);
1769 break;
1770 #endif
1772 #ifdef ASM_OUTPUT_DOUBLE
1773 case DFmode:
1774 ASM_OUTPUT_DOUBLE (asm_out_file, d);
1775 break;
1776 #endif
1778 #ifdef ASM_OUTPUT_LONG_DOUBLE
1779 case XFmode:
1780 case TFmode:
1781 ASM_OUTPUT_LONG_DOUBLE (asm_out_file, d);
1782 break;
1783 #endif
1785 default:
1786 abort ();
1789 set_float_handler (NULL_PTR);
1792 /* Here we combine duplicate floating constants to make
1793 CONST_DOUBLE rtx's, and force those out to memory when necessary. */
1795 /* Chain of all CONST_DOUBLE rtx's constructed for the current function.
1796 They are chained through the CONST_DOUBLE_CHAIN.
1797 A CONST_DOUBLE rtx has CONST_DOUBLE_MEM != cc0_rtx iff it is on this chain.
1798 In that case, CONST_DOUBLE_MEM is either a MEM,
1799 or const0_rtx if no MEM has been made for this CONST_DOUBLE yet.
1801 (CONST_DOUBLE_MEM is used only for top-level functions.
1802 See force_const_mem for explanation.) */
1804 static rtx const_double_chain;
1806 /* Return a CONST_DOUBLE or CONST_INT for a value specified as a pair of ints.
1807 For an integer, I0 is the low-order word and I1 is the high-order word.
1808 For a real number, I0 is the word with the low address
1809 and I1 is the word with the high address. */
1812 immed_double_const (i0, i1, mode)
1813 HOST_WIDE_INT i0, i1;
1814 enum machine_mode mode;
1816 register rtx r;
1817 int in_current_obstack;
1819 if (GET_MODE_CLASS (mode) == MODE_INT
1820 || GET_MODE_CLASS (mode) == MODE_PARTIAL_INT)
1822 /* We clear out all bits that don't belong in MODE, unless they and our
1823 sign bit are all one. So we get either a reasonable negative value
1824 or a reasonable unsigned value for this mode. */
1825 int width = GET_MODE_BITSIZE (mode);
1826 if (width < HOST_BITS_PER_WIDE_INT
1827 && ((i0 & ((HOST_WIDE_INT) (-1) << (width - 1)))
1828 != ((HOST_WIDE_INT) (-1) << (width - 1))))
1829 i0 &= ((HOST_WIDE_INT) 1 << width) - 1, i1 = 0;
1830 else if (width == HOST_BITS_PER_WIDE_INT
1831 && ! (i1 == ~0 && i0 < 0))
1832 i1 = 0;
1833 else if (width > 2 * HOST_BITS_PER_WIDE_INT)
1834 /* We cannot represent this value as a constant. */
1835 abort ();
1837 /* If this would be an entire word for the target, but is not for
1838 the host, then sign-extend on the host so that the number will look
1839 the same way on the host that it would on the target.
1841 For example, when building a 64 bit alpha hosted 32 bit sparc
1842 targeted compiler, then we want the 32 bit unsigned value -1 to be
1843 represented as a 64 bit value -1, and not as 0x00000000ffffffff.
1844 The later confuses the sparc backend. */
1846 if (BITS_PER_WORD < HOST_BITS_PER_WIDE_INT && BITS_PER_WORD == width
1847 && (i0 & ((HOST_WIDE_INT) 1 << (width - 1))))
1848 i0 |= ((HOST_WIDE_INT) (-1) << width);
1850 /* If MODE fits within HOST_BITS_PER_WIDE_INT, always use a CONST_INT.
1852 ??? Strictly speaking, this is wrong if we create a CONST_INT
1853 for a large unsigned constant with the size of MODE being
1854 HOST_BITS_PER_WIDE_INT and later try to interpret that constant in a
1855 wider mode. In that case we will mis-interpret it as a negative
1856 number.
1858 Unfortunately, the only alternative is to make a CONST_DOUBLE
1859 for any constant in any mode if it is an unsigned constant larger
1860 than the maximum signed integer in an int on the host. However,
1861 doing this will break everyone that always expects to see a CONST_INT
1862 for SImode and smaller.
1864 We have always been making CONST_INTs in this case, so nothing new
1865 is being broken. */
1867 if (width <= HOST_BITS_PER_WIDE_INT)
1868 i1 = (i0 < 0) ? ~0 : 0;
1870 /* If this integer fits in one word, return a CONST_INT. */
1871 if ((i1 == 0 && i0 >= 0)
1872 || (i1 == ~0 && i0 < 0))
1873 return GEN_INT (i0);
1875 /* We use VOIDmode for integers. */
1876 mode = VOIDmode;
1879 /* Search the chain for an existing CONST_DOUBLE with the right value.
1880 If one is found, return it. */
1882 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1883 if (CONST_DOUBLE_LOW (r) == i0 && CONST_DOUBLE_HIGH (r) == i1
1884 && GET_MODE (r) == mode)
1885 return r;
1887 /* No; make a new one and add it to the chain.
1889 We may be called by an optimizer which may be discarding any memory
1890 allocated during its processing (such as combine and loop). However,
1891 we will be leaving this constant on the chain, so we cannot tolerate
1892 freed memory. So switch to saveable_obstack for this allocation
1893 and then switch back if we were in current_obstack. */
1895 push_obstacks_nochange ();
1896 rtl_in_saveable_obstack ();
1897 r = gen_rtx (CONST_DOUBLE, mode, 0, i0, i1);
1898 pop_obstacks ();
1900 /* Don't touch const_double_chain in nested function; see force_const_mem.
1901 Also, don't touch it if not inside any function. */
1902 if (outer_function_chain == 0 && current_function_decl != 0)
1904 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1905 const_double_chain = r;
1908 /* Store const0_rtx in mem-slot since this CONST_DOUBLE is on the chain.
1909 Actual use of mem-slot is only through force_const_mem. */
1911 CONST_DOUBLE_MEM (r) = const0_rtx;
1913 return r;
1916 /* Return a CONST_DOUBLE for a specified `double' value
1917 and machine mode. */
1920 immed_real_const_1 (d, mode)
1921 REAL_VALUE_TYPE d;
1922 enum machine_mode mode;
1924 union real_extract u;
1925 register rtx r;
1926 int in_current_obstack;
1928 /* Get the desired `double' value as a sequence of ints
1929 since that is how they are stored in a CONST_DOUBLE. */
1931 u.d = d;
1933 /* Detect special cases. */
1935 /* Avoid REAL_VALUES_EQUAL here in order to distinguish minus zero. */
1936 if (!bcmp ((char *) &dconst0, (char *) &d, sizeof d))
1937 return CONST0_RTX (mode);
1938 /* Check for NaN first, because some ports (specifically the i386) do not
1939 emit correct ieee-fp code by default, and thus will generate a core
1940 dump here if we pass a NaN to REAL_VALUES_EQUAL and if REAL_VALUES_EQUAL
1941 does a floating point comparison. */
1942 else if (! REAL_VALUE_ISNAN (d) && REAL_VALUES_EQUAL (dconst1, d))
1943 return CONST1_RTX (mode);
1945 if (sizeof u == 2 * sizeof (HOST_WIDE_INT))
1946 return immed_double_const (u.i[0], u.i[1], mode);
1948 /* The rest of this function handles the case where
1949 a float value requires more than 2 ints of space.
1950 It will be deleted as dead code on machines that don't need it. */
1952 /* Search the chain for an existing CONST_DOUBLE with the right value.
1953 If one is found, return it. */
1955 for (r = const_double_chain; r; r = CONST_DOUBLE_CHAIN (r))
1956 if (! bcmp ((char *) &CONST_DOUBLE_LOW (r), (char *) &u, sizeof u)
1957 && GET_MODE (r) == mode)
1958 return r;
1960 /* No; make a new one and add it to the chain.
1962 We may be called by an optimizer which may be discarding any memory
1963 allocated during its processing (such as combine and loop). However,
1964 we will be leaving this constant on the chain, so we cannot tolerate
1965 freed memory. So switch to saveable_obstack for this allocation
1966 and then switch back if we were in current_obstack. */
1968 push_obstacks_nochange ();
1969 rtl_in_saveable_obstack ();
1970 r = rtx_alloc (CONST_DOUBLE);
1971 PUT_MODE (r, mode);
1972 bcopy ((char *) &u, (char *) &CONST_DOUBLE_LOW (r), sizeof u);
1973 pop_obstacks ();
1975 /* Don't touch const_double_chain in nested function; see force_const_mem.
1976 Also, don't touch it if not inside any function. */
1977 if (outer_function_chain == 0 && current_function_decl != 0)
1979 CONST_DOUBLE_CHAIN (r) = const_double_chain;
1980 const_double_chain = r;
1983 /* Store const0_rtx in CONST_DOUBLE_MEM since this CONST_DOUBLE is on the
1984 chain, but has not been allocated memory. Actual use of CONST_DOUBLE_MEM
1985 is only through force_const_mem. */
1987 CONST_DOUBLE_MEM (r) = const0_rtx;
1989 return r;
1992 /* Return a CONST_DOUBLE rtx for a value specified by EXP,
1993 which must be a REAL_CST tree node. */
1996 immed_real_const (exp)
1997 tree exp;
1999 return immed_real_const_1 (TREE_REAL_CST (exp), TYPE_MODE (TREE_TYPE (exp)));
2002 /* At the end of a function, forget the memory-constants
2003 previously made for CONST_DOUBLEs. Mark them as not on real_constant_chain.
2004 Also clear out real_constant_chain and clear out all the chain-pointers. */
2006 void
2007 clear_const_double_mem ()
2009 register rtx r, next;
2011 /* Don't touch CONST_DOUBLE_MEM for nested functions.
2012 See force_const_mem for explanation. */
2013 if (outer_function_chain != 0)
2014 return;
2016 for (r = const_double_chain; r; r = next)
2018 next = CONST_DOUBLE_CHAIN (r);
2019 CONST_DOUBLE_CHAIN (r) = 0;
2020 CONST_DOUBLE_MEM (r) = cc0_rtx;
2022 const_double_chain = 0;
2025 /* Given an expression EXP with a constant value,
2026 reduce it to the sum of an assembler symbol and an integer.
2027 Store them both in the structure *VALUE.
2028 Abort if EXP does not reduce. */
2030 struct addr_const
2032 rtx base;
2033 HOST_WIDE_INT offset;
2036 static void
2037 decode_addr_const (exp, value)
2038 tree exp;
2039 struct addr_const *value;
2041 register tree target = TREE_OPERAND (exp, 0);
2042 register int offset = 0;
2043 register rtx x;
2045 while (1)
2047 if (TREE_CODE (target) == COMPONENT_REF
2048 && (TREE_CODE (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1)))
2049 == INTEGER_CST))
2051 offset += TREE_INT_CST_LOW (DECL_FIELD_BITPOS (TREE_OPERAND (target, 1))) / BITS_PER_UNIT;
2052 target = TREE_OPERAND (target, 0);
2054 else if (TREE_CODE (target) == ARRAY_REF)
2056 if (TREE_CODE (TREE_OPERAND (target, 1)) != INTEGER_CST
2057 || TREE_CODE (TYPE_SIZE (TREE_TYPE (target))) != INTEGER_CST)
2058 abort ();
2059 offset += ((TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (target)))
2060 * TREE_INT_CST_LOW (TREE_OPERAND (target, 1)))
2061 / BITS_PER_UNIT);
2062 target = TREE_OPERAND (target, 0);
2064 else
2065 break;
2068 switch (TREE_CODE (target))
2070 case VAR_DECL:
2071 case FUNCTION_DECL:
2072 x = DECL_RTL (target);
2073 break;
2075 case LABEL_DECL:
2076 if (output_bytecode)
2077 /* FIXME: this may not be correct, check it */
2078 x = bc_gen_rtx (TREE_STRING_POINTER (target), 0, (struct bc_label *) 0);
2079 else
2080 x = gen_rtx (MEM, FUNCTION_MODE,
2081 gen_rtx (LABEL_REF, VOIDmode,
2082 label_rtx (TREE_OPERAND (exp, 0))));
2083 break;
2085 case REAL_CST:
2086 case STRING_CST:
2087 case COMPLEX_CST:
2088 case CONSTRUCTOR:
2089 x = TREE_CST_RTL (target);
2090 break;
2092 default:
2093 abort ();
2096 if (!output_bytecode)
2098 if (GET_CODE (x) != MEM)
2099 abort ();
2100 x = XEXP (x, 0);
2103 value->base = x;
2104 value->offset = offset;
2107 /* Uniquize all constants that appear in memory.
2108 Each constant in memory thus far output is recorded
2109 in `const_hash_table' with a `struct constant_descriptor'
2110 that contains a polish representation of the value of
2111 the constant.
2113 We cannot store the trees in the hash table
2114 because the trees may be temporary. */
2116 struct constant_descriptor
2118 struct constant_descriptor *next;
2119 char *label;
2120 char contents[1];
2123 #define HASHBITS 30
2124 #define MAX_HASH_TABLE 1009
2125 static struct constant_descriptor *const_hash_table[MAX_HASH_TABLE];
2127 /* Compute a hash code for a constant expression. */
2129 static int
2130 const_hash (exp)
2131 tree exp;
2133 register char *p;
2134 register int len, hi, i;
2135 register enum tree_code code = TREE_CODE (exp);
2137 if (code == INTEGER_CST)
2139 p = (char *) &TREE_INT_CST_LOW (exp);
2140 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2142 else if (code == REAL_CST)
2144 p = (char *) &TREE_REAL_CST (exp);
2145 len = sizeof TREE_REAL_CST (exp);
2147 else if (code == STRING_CST)
2148 p = TREE_STRING_POINTER (exp), len = TREE_STRING_LENGTH (exp);
2149 else if (code == COMPLEX_CST)
2150 return const_hash (TREE_REALPART (exp)) * 5
2151 + const_hash (TREE_IMAGPART (exp));
2152 else if (code == CONSTRUCTOR && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2154 len = int_size_in_bytes (TREE_TYPE (exp));
2155 p = (char*) alloca (len);
2156 get_set_constructor_bytes (exp, (unsigned char *) p, len);
2158 else if (code == CONSTRUCTOR)
2160 register tree link;
2162 /* For record type, include the type in the hashing.
2163 We do not do so for array types
2164 because (1) the sizes of the elements are sufficient
2165 and (2) distinct array types can have the same constructor.
2166 Instead, we include the array size because the constructor could
2167 be shorter. */
2168 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2169 hi = ((HOST_WIDE_INT) TREE_TYPE (exp) & ((1 << HASHBITS) - 1))
2170 % MAX_HASH_TABLE;
2171 else
2172 hi = ((5 + int_size_in_bytes (TREE_TYPE (exp)))
2173 & ((1 << HASHBITS) - 1)) % MAX_HASH_TABLE;
2175 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2176 if (TREE_VALUE (link))
2177 hi = (hi * 603 + const_hash (TREE_VALUE (link))) % MAX_HASH_TABLE;
2179 return hi;
2181 else if (code == ADDR_EXPR)
2183 struct addr_const value;
2184 decode_addr_const (exp, &value);
2185 if (GET_CODE (value.base) == SYMBOL_REF)
2187 /* Don't hash the address of the SYMBOL_REF;
2188 only use the offset and the symbol name. */
2189 hi = value.offset;
2190 p = XSTR (value.base, 0);
2191 for (i = 0; p[i] != 0; i++)
2192 hi = ((hi * 613) + (unsigned)(p[i]));
2194 else if (GET_CODE (value.base) == LABEL_REF)
2195 hi = value.offset + CODE_LABEL_NUMBER (XEXP (value.base, 0)) * 13;
2197 hi &= (1 << HASHBITS) - 1;
2198 hi %= MAX_HASH_TABLE;
2199 return hi;
2201 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2202 return const_hash (TREE_OPERAND (exp, 0)) * 9
2203 + const_hash (TREE_OPERAND (exp, 1));
2204 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2205 return const_hash (TREE_OPERAND (exp, 0)) * 7 + 2;
2207 /* Compute hashing function */
2208 hi = len;
2209 for (i = 0; i < len; i++)
2210 hi = ((hi * 613) + (unsigned)(p[i]));
2212 hi &= (1 << HASHBITS) - 1;
2213 hi %= MAX_HASH_TABLE;
2214 return hi;
2217 /* Compare a constant expression EXP with a constant-descriptor DESC.
2218 Return 1 if DESC describes a constant with the same value as EXP. */
2220 static int
2221 compare_constant (exp, desc)
2222 tree exp;
2223 struct constant_descriptor *desc;
2225 return 0 != compare_constant_1 (exp, desc->contents);
2228 /* Compare constant expression EXP with a substring P of a constant descriptor.
2229 If they match, return a pointer to the end of the substring matched.
2230 If they do not match, return 0.
2232 Since descriptors are written in polish prefix notation,
2233 this function can be used recursively to test one operand of EXP
2234 against a subdescriptor, and if it succeeds it returns the
2235 address of the subdescriptor for the next operand. */
2237 static char *
2238 compare_constant_1 (exp, p)
2239 tree exp;
2240 char *p;
2242 register char *strp;
2243 register int len;
2244 register enum tree_code code = TREE_CODE (exp);
2246 if (code != (enum tree_code) *p++)
2247 return 0;
2249 if (code == INTEGER_CST)
2251 /* Integer constants are the same only if the same width of type. */
2252 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2253 return 0;
2254 strp = (char *) &TREE_INT_CST_LOW (exp);
2255 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2257 else if (code == REAL_CST)
2259 /* Real constants are the same only if the same width of type. */
2260 if (*p++ != TYPE_PRECISION (TREE_TYPE (exp)))
2261 return 0;
2262 strp = (char *) &TREE_REAL_CST (exp);
2263 len = sizeof TREE_REAL_CST (exp);
2265 else if (code == STRING_CST)
2267 if (flag_writable_strings)
2268 return 0;
2269 strp = TREE_STRING_POINTER (exp);
2270 len = TREE_STRING_LENGTH (exp);
2271 if (bcmp ((char *) &TREE_STRING_LENGTH (exp), p,
2272 sizeof TREE_STRING_LENGTH (exp)))
2273 return 0;
2274 p += sizeof TREE_STRING_LENGTH (exp);
2276 else if (code == COMPLEX_CST)
2278 p = compare_constant_1 (TREE_REALPART (exp), p);
2279 if (p == 0) return 0;
2280 p = compare_constant_1 (TREE_IMAGPART (exp), p);
2281 return p;
2283 else if (code == CONSTRUCTOR && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2285 len = int_size_in_bytes (TREE_TYPE (exp));
2286 strp = (char*) alloca (len);
2287 get_set_constructor_bytes (exp, (unsigned char *) strp, len);
2289 else if (code == CONSTRUCTOR)
2291 register tree link;
2292 int length = list_length (CONSTRUCTOR_ELTS (exp));
2293 tree type;
2295 if (bcmp ((char *) &length, p, sizeof length))
2296 return 0;
2297 p += sizeof length;
2299 /* For record constructors, insist that the types match.
2300 For arrays, just verify both constructors are for arrays. */
2301 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2302 type = TREE_TYPE (exp);
2303 else
2304 type = 0;
2305 if (bcmp ((char *) &type, p, sizeof type))
2306 return 0;
2307 p += sizeof type;
2309 /* For arrays, insist that the size in bytes match. */
2310 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2312 int size = int_size_in_bytes (TREE_TYPE (exp));
2313 if (bcmp ((char *) &size, p, sizeof size))
2314 return 0;
2315 p += sizeof size;
2318 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2320 if (TREE_VALUE (link))
2322 if ((p = compare_constant_1 (TREE_VALUE (link), p)) == 0)
2323 return 0;
2325 else
2327 tree zero = 0;
2329 if (bcmp ((char *) &zero, p, sizeof zero))
2330 return 0;
2331 p += sizeof zero;
2335 return p;
2337 else if (code == ADDR_EXPR)
2339 struct addr_const value;
2340 decode_addr_const (exp, &value);
2341 strp = (char *) &value.offset;
2342 len = sizeof value.offset;
2343 /* Compare the offset. */
2344 while (--len >= 0)
2345 if (*p++ != *strp++)
2346 return 0;
2347 /* Compare symbol name. */
2348 strp = XSTR (value.base, 0);
2349 len = strlen (strp) + 1;
2351 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2353 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2354 if (p == 0) return 0;
2355 p = compare_constant_1 (TREE_OPERAND (exp, 1), p);
2356 return p;
2358 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2360 p = compare_constant_1 (TREE_OPERAND (exp, 0), p);
2361 return p;
2364 /* Compare constant contents. */
2365 while (--len >= 0)
2366 if (*p++ != *strp++)
2367 return 0;
2369 return p;
2372 /* Construct a constant descriptor for the expression EXP.
2373 It is up to the caller to enter the descriptor in the hash table. */
2375 static struct constant_descriptor *
2376 record_constant (exp)
2377 tree exp;
2379 struct constant_descriptor *next = 0;
2380 char *label = 0;
2382 /* Make a struct constant_descriptor. The first two pointers will
2383 be filled in later. Here we just leave space for them. */
2385 obstack_grow (&permanent_obstack, (char *) &next, sizeof next);
2386 obstack_grow (&permanent_obstack, (char *) &label, sizeof label);
2387 record_constant_1 (exp);
2388 return (struct constant_descriptor *) obstack_finish (&permanent_obstack);
2391 /* Add a description of constant expression EXP
2392 to the object growing in `permanent_obstack'.
2393 No need to return its address; the caller will get that
2394 from the obstack when the object is complete. */
2396 static void
2397 record_constant_1 (exp)
2398 tree exp;
2400 register char *strp;
2401 register int len;
2402 register enum tree_code code = TREE_CODE (exp);
2404 obstack_1grow (&permanent_obstack, (unsigned int) code);
2406 if (code == INTEGER_CST)
2408 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2409 strp = (char *) &TREE_INT_CST_LOW (exp);
2410 len = 2 * sizeof TREE_INT_CST_LOW (exp);
2412 else if (code == REAL_CST)
2414 obstack_1grow (&permanent_obstack, TYPE_PRECISION (TREE_TYPE (exp)));
2415 strp = (char *) &TREE_REAL_CST (exp);
2416 len = sizeof TREE_REAL_CST (exp);
2418 else if (code == STRING_CST)
2420 if (flag_writable_strings)
2421 return;
2422 strp = TREE_STRING_POINTER (exp);
2423 len = TREE_STRING_LENGTH (exp);
2424 obstack_grow (&permanent_obstack, (char *) &TREE_STRING_LENGTH (exp),
2425 sizeof TREE_STRING_LENGTH (exp));
2427 else if (code == COMPLEX_CST)
2429 record_constant_1 (TREE_REALPART (exp));
2430 record_constant_1 (TREE_IMAGPART (exp));
2431 return;
2433 else if (code == CONSTRUCTOR && TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2435 int nbytes = int_size_in_bytes (TREE_TYPE (exp));
2436 obstack_grow (&permanent_obstack, &nbytes, sizeof (nbytes));
2437 obstack_blank (&permanent_obstack, nbytes);
2438 get_set_constructor_bytes (exp,
2439 (unsigned char *) permanent_obstack.next_free,
2440 nbytes);
2441 return;
2443 else if (code == CONSTRUCTOR)
2445 register tree link;
2446 int length = list_length (CONSTRUCTOR_ELTS (exp));
2447 tree type;
2449 obstack_grow (&permanent_obstack, (char *) &length, sizeof length);
2451 /* For record constructors, insist that the types match.
2452 For arrays, just verify both constructors are for arrays. */
2453 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
2454 type = TREE_TYPE (exp);
2455 else
2456 type = 0;
2457 obstack_grow (&permanent_obstack, (char *) &type, sizeof type);
2459 /* For arrays, insist that the size in bytes match. */
2460 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
2462 int size = int_size_in_bytes (TREE_TYPE (exp));
2463 obstack_grow (&permanent_obstack, (char *) &size, sizeof size);
2466 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
2468 if (TREE_VALUE (link))
2469 record_constant_1 (TREE_VALUE (link));
2470 else
2472 tree zero = 0;
2474 obstack_grow (&permanent_obstack, (char *) &zero, sizeof zero);
2478 return;
2480 else if (code == ADDR_EXPR)
2482 struct addr_const value;
2483 decode_addr_const (exp, &value);
2484 /* Record the offset. */
2485 obstack_grow (&permanent_obstack,
2486 (char *) &value.offset, sizeof value.offset);
2487 /* Record the symbol name. */
2488 obstack_grow (&permanent_obstack, XSTR (value.base, 0),
2489 strlen (XSTR (value.base, 0)) + 1);
2490 return;
2492 else if (code == PLUS_EXPR || code == MINUS_EXPR)
2494 record_constant_1 (TREE_OPERAND (exp, 0));
2495 record_constant_1 (TREE_OPERAND (exp, 1));
2496 return;
2498 else if (code == NOP_EXPR || code == CONVERT_EXPR)
2500 record_constant_1 (TREE_OPERAND (exp, 0));
2501 return;
2504 /* Record constant contents. */
2505 obstack_grow (&permanent_obstack, strp, len);
2508 /* Record a list of constant expressions that were passed to
2509 output_constant_def but that could not be output right away. */
2511 struct deferred_constant
2513 struct deferred_constant *next;
2514 tree exp;
2515 int reloc;
2516 int labelno;
2519 static struct deferred_constant *deferred_constants;
2521 /* Nonzero means defer output of addressed subconstants
2522 (i.e., those for which output_constant_def is called.) */
2523 static int defer_addressed_constants_flag;
2525 /* Start deferring output of subconstants. */
2527 void
2528 defer_addressed_constants ()
2530 defer_addressed_constants_flag++;
2533 /* Stop deferring output of subconstants,
2534 and output now all those that have been deferred. */
2536 void
2537 output_deferred_addressed_constants ()
2539 struct deferred_constant *p, *next;
2541 defer_addressed_constants_flag--;
2543 if (defer_addressed_constants_flag > 0)
2544 return;
2546 for (p = deferred_constants; p; p = next)
2548 output_constant_def_contents (p->exp, p->reloc, p->labelno);
2549 next = p->next;
2550 free (p);
2553 deferred_constants = 0;
2556 /* Make a copy of the whole tree structure for a constant.
2557 This handles the same types of nodes that compare_constant
2558 and record_constant handle. */
2560 static tree
2561 copy_constant (exp)
2562 tree exp;
2564 switch (TREE_CODE (exp))
2566 case INTEGER_CST:
2567 case REAL_CST:
2568 case STRING_CST:
2569 case ADDR_EXPR:
2570 /* For ADDR_EXPR, we do not want to copy the decl
2571 whose address is requested. */
2572 return copy_node (exp);
2574 case COMPLEX_CST:
2575 return build_complex (copy_constant (TREE_REALPART (exp)),
2576 copy_constant (TREE_IMAGPART (exp)));
2578 case PLUS_EXPR:
2579 case MINUS_EXPR:
2580 return build (TREE_CODE (exp), TREE_TYPE (exp),
2581 copy_constant (TREE_OPERAND (exp, 0)),
2582 copy_constant (TREE_OPERAND (exp, 1)));
2584 case NOP_EXPR:
2585 case CONVERT_EXPR:
2586 return build1 (TREE_CODE (exp), TREE_TYPE (exp),
2587 copy_constant (TREE_OPERAND (exp, 0)));
2589 case CONSTRUCTOR:
2591 tree copy = copy_node (exp);
2592 tree list = copy_list (CONSTRUCTOR_ELTS (exp));
2593 tree tail;
2595 CONSTRUCTOR_ELTS (copy) = list;
2596 for (tail = list; tail; tail = TREE_CHAIN (tail))
2597 TREE_VALUE (tail) = copy_constant (TREE_VALUE (tail));
2598 if (TREE_CODE (TREE_TYPE (exp)) == SET_TYPE)
2599 for (tail = list; tail; tail = TREE_CHAIN (tail))
2600 TREE_PURPOSE (tail) = copy_constant (TREE_PURPOSE (tail));
2602 return copy;
2605 default:
2606 abort ();
2610 /* Return an rtx representing a reference to constant data in memory
2611 for the constant expression EXP.
2613 If assembler code for such a constant has already been output,
2614 return an rtx to refer to it.
2615 Otherwise, output such a constant in memory (or defer it for later)
2616 and generate an rtx for it.
2618 The TREE_CST_RTL of EXP is set up to point to that rtx.
2619 The const_hash_table records which constants already have label strings. */
2622 output_constant_def (exp)
2623 tree exp;
2625 register int hash;
2626 register struct constant_descriptor *desc;
2627 char label[256];
2628 char *found = 0;
2629 int reloc;
2630 register rtx def;
2632 if (TREE_CODE (exp) == INTEGER_CST)
2633 abort (); /* No TREE_CST_RTL slot in these. */
2635 if (TREE_CST_RTL (exp))
2636 return TREE_CST_RTL (exp);
2638 /* Make sure any other constants whose addresses appear in EXP
2639 are assigned label numbers. */
2641 reloc = output_addressed_constants (exp);
2643 /* Compute hash code of EXP. Search the descriptors for that hash code
2644 to see if any of them describes EXP. If yes, the descriptor records
2645 the label number already assigned. */
2647 hash = const_hash (exp) % MAX_HASH_TABLE;
2649 for (desc = const_hash_table[hash]; desc; desc = desc->next)
2650 if (compare_constant (exp, desc))
2652 found = desc->label;
2653 break;
2656 if (found == 0)
2658 /* No constant equal to EXP is known to have been output.
2659 Make a constant descriptor to enter EXP in the hash table.
2660 Assign the label number and record it in the descriptor for
2661 future calls to this function to find. */
2663 /* Create a string containing the label name, in LABEL. */
2664 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2666 desc = record_constant (exp);
2667 desc->next = const_hash_table[hash];
2668 desc->label
2669 = (char *) obstack_copy0 (&permanent_obstack, label, strlen (label));
2670 const_hash_table[hash] = desc;
2672 else
2674 /* Create a string containing the label name, in LABEL. */
2675 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
2678 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
2680 push_obstacks_nochange ();
2681 if (TREE_PERMANENT (exp))
2682 end_temporary_allocation ();
2684 def = gen_rtx (SYMBOL_REF, Pmode, desc->label);
2686 TREE_CST_RTL (exp)
2687 = gen_rtx (MEM, TYPE_MODE (TREE_TYPE (exp)), def);
2688 RTX_UNCHANGING_P (TREE_CST_RTL (exp)) = 1;
2689 if (AGGREGATE_TYPE_P (TREE_TYPE (exp)))
2690 MEM_IN_STRUCT_P (TREE_CST_RTL (exp)) = 1;
2692 pop_obstacks ();
2694 /* Optionally set flags or add text to the name to record information
2695 such as that it is a function name. If the name is changed, the macro
2696 ASM_OUTPUT_LABELREF will have to know how to strip this information. */
2697 #ifdef ENCODE_SECTION_INFO
2698 ENCODE_SECTION_INFO (exp);
2699 #endif
2701 /* If this is the first time we've seen this particular constant,
2702 output it (or defer its output for later). */
2703 if (found == 0)
2705 if (defer_addressed_constants_flag)
2707 struct deferred_constant *p;
2708 p = (struct deferred_constant *) xmalloc (sizeof (struct deferred_constant));
2710 push_obstacks_nochange ();
2711 suspend_momentary ();
2712 p->exp = copy_constant (exp);
2713 pop_obstacks ();
2714 p->reloc = reloc;
2715 p->labelno = const_labelno++;
2716 p->next = deferred_constants;
2717 deferred_constants = p;
2719 else
2720 output_constant_def_contents (exp, reloc, const_labelno++);
2723 return TREE_CST_RTL (exp);
2726 /* Now output assembler code to define the label for EXP,
2727 and follow it with the data of EXP. */
2729 static void
2730 output_constant_def_contents (exp, reloc, labelno)
2731 tree exp;
2732 int reloc;
2733 int labelno;
2735 int align;
2737 if (IN_NAMED_SECTION (exp))
2738 named_section (exp, NULL);
2739 else
2741 /* First switch to text section, except for writable strings. */
2742 #ifdef SELECT_SECTION
2743 SELECT_SECTION (exp, reloc);
2744 #else
2745 if (((TREE_CODE (exp) == STRING_CST) && flag_writable_strings)
2746 || (flag_pic && reloc))
2747 data_section ();
2748 else
2749 readonly_data_section ();
2750 #endif
2753 /* Align the location counter as required by EXP's data type. */
2754 align = TYPE_ALIGN (TREE_TYPE (exp));
2755 #ifdef CONSTANT_ALIGNMENT
2756 align = CONSTANT_ALIGNMENT (exp, align);
2757 #endif
2759 if (align > BITS_PER_UNIT)
2761 if (!output_bytecode)
2763 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2765 else
2767 BC_OUTPUT_ALIGN (asm_out_file, floor_log2 (align / BITS_PER_UNIT));
2771 /* Output the label itself. */
2772 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", labelno);
2774 /* Output the value of EXP. */
2775 output_constant (exp,
2776 (TREE_CODE (exp) == STRING_CST
2777 ? TREE_STRING_LENGTH (exp)
2778 : int_size_in_bytes (TREE_TYPE (exp))));
2782 /* Similar hash facility for making memory-constants
2783 from constant rtl-expressions. It is used on RISC machines
2784 where immediate integer arguments and constant addresses are restricted
2785 so that such constants must be stored in memory.
2787 This pool of constants is reinitialized for each function
2788 so each function gets its own constants-pool that comes right before it.
2790 All structures allocated here are discarded when functions are saved for
2791 inlining, so they do not need to be allocated permanently. */
2793 #define MAX_RTX_HASH_TABLE 61
2794 static struct constant_descriptor **const_rtx_hash_table;
2796 /* Structure to represent sufficient information about a constant so that
2797 it can be output when the constant pool is output, so that function
2798 integration can be done, and to simplify handling on machines that reference
2799 constant pool as base+displacement. */
2801 struct pool_constant
2803 struct constant_descriptor *desc;
2804 struct pool_constant *next;
2805 enum machine_mode mode;
2806 rtx constant;
2807 int labelno;
2808 int align;
2809 int offset;
2812 /* Pointers to first and last constant in pool. */
2814 static struct pool_constant *first_pool, *last_pool;
2816 /* Current offset in constant pool (does not include any machine-specific
2817 header. */
2819 static int pool_offset;
2821 /* Structure used to maintain hash table mapping symbols used to their
2822 corresponding constants. */
2824 struct pool_sym
2826 char *label;
2827 struct pool_constant *pool;
2828 struct pool_sym *next;
2831 static struct pool_sym **const_rtx_sym_hash_table;
2833 /* Hash code for a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true.
2834 The argument is XSTR (... , 0) */
2836 #define SYMHASH(LABEL) \
2837 ((((HOST_WIDE_INT) (LABEL)) & ((1 << HASHBITS) - 1)) % MAX_RTX_HASH_TABLE)
2839 /* Initialize constant pool hashing for next function. */
2841 void
2842 init_const_rtx_hash_table ()
2844 const_rtx_hash_table
2845 = ((struct constant_descriptor **)
2846 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *)));
2847 const_rtx_sym_hash_table
2848 = ((struct pool_sym **)
2849 oballoc (MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *)));
2850 bzero ((char *) const_rtx_hash_table,
2851 MAX_RTX_HASH_TABLE * sizeof (struct constant_descriptor *));
2852 bzero ((char *) const_rtx_sym_hash_table,
2853 MAX_RTX_HASH_TABLE * sizeof (struct pool_sym *));
2855 first_pool = last_pool = 0;
2856 pool_offset = 0;
2859 /* Save and restore status for a nested function. */
2861 void
2862 save_varasm_status (p)
2863 struct function *p;
2865 p->const_rtx_hash_table = const_rtx_hash_table;
2866 p->const_rtx_sym_hash_table = const_rtx_sym_hash_table;
2867 p->first_pool = first_pool;
2868 p->last_pool = last_pool;
2869 p->pool_offset = pool_offset;
2872 void
2873 restore_varasm_status (p)
2874 struct function *p;
2876 const_rtx_hash_table = p->const_rtx_hash_table;
2877 const_rtx_sym_hash_table = p->const_rtx_sym_hash_table;
2878 first_pool = p->first_pool;
2879 last_pool = p->last_pool;
2880 pool_offset = p->pool_offset;
2883 enum kind { RTX_DOUBLE, RTX_INT };
2885 struct rtx_const
2887 #ifdef ONLY_INT_FIELDS
2888 unsigned int kind : 16;
2889 unsigned int mode : 16;
2890 #else
2891 enum kind kind : 16;
2892 enum machine_mode mode : 16;
2893 #endif
2894 union {
2895 union real_extract du;
2896 struct addr_const addr;
2897 } un;
2900 /* Express an rtx for a constant integer (perhaps symbolic)
2901 as the sum of a symbol or label plus an explicit integer.
2902 They are stored into VALUE. */
2904 static void
2905 decode_rtx_const (mode, x, value)
2906 enum machine_mode mode;
2907 rtx x;
2908 struct rtx_const *value;
2910 /* Clear the whole structure, including any gaps. */
2913 int *p = (int *) value;
2914 int *end = (int *) (value + 1);
2915 while (p < end)
2916 *p++ = 0;
2919 value->kind = RTX_INT; /* Most usual kind. */
2920 value->mode = mode;
2922 switch (GET_CODE (x))
2924 case CONST_DOUBLE:
2925 value->kind = RTX_DOUBLE;
2926 if (GET_MODE (x) != VOIDmode)
2927 value->mode = GET_MODE (x);
2928 bcopy ((char *) &CONST_DOUBLE_LOW (x),
2929 (char *) &value->un.du, sizeof value->un.du);
2930 break;
2932 case CONST_INT:
2933 value->un.addr.offset = INTVAL (x);
2934 break;
2936 case SYMBOL_REF:
2937 case LABEL_REF:
2938 case PC:
2939 value->un.addr.base = x;
2940 break;
2942 case CONST:
2943 x = XEXP (x, 0);
2944 if (GET_CODE (x) == PLUS)
2946 value->un.addr.base = XEXP (x, 0);
2947 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2948 abort ();
2949 value->un.addr.offset = INTVAL (XEXP (x, 1));
2951 else if (GET_CODE (x) == MINUS)
2953 value->un.addr.base = XEXP (x, 0);
2954 if (GET_CODE (XEXP (x, 1)) != CONST_INT)
2955 abort ();
2956 value->un.addr.offset = - INTVAL (XEXP (x, 1));
2958 else
2959 abort ();
2960 break;
2962 default:
2963 abort ();
2966 if (value->kind == RTX_INT && value->un.addr.base != 0)
2967 switch (GET_CODE (value->un.addr.base))
2969 case SYMBOL_REF:
2970 case LABEL_REF:
2971 /* Use the string's address, not the SYMBOL_REF's address,
2972 for the sake of addresses of library routines.
2973 For a LABEL_REF, compare labels. */
2974 value->un.addr.base = XEXP (value->un.addr.base, 0);
2978 /* Given a MINUS expression, simplify it if both sides
2979 include the same symbol. */
2982 simplify_subtraction (x)
2983 rtx x;
2985 struct rtx_const val0, val1;
2987 decode_rtx_const (GET_MODE (x), XEXP (x, 0), &val0);
2988 decode_rtx_const (GET_MODE (x), XEXP (x, 1), &val1);
2990 if (val0.un.addr.base == val1.un.addr.base)
2991 return GEN_INT (val0.un.addr.offset - val1.un.addr.offset);
2992 return x;
2995 /* Compute a hash code for a constant RTL expression. */
2997 static int
2998 const_hash_rtx (mode, x)
2999 enum machine_mode mode;
3000 rtx x;
3002 register int hi, i;
3004 struct rtx_const value;
3005 decode_rtx_const (mode, x, &value);
3007 /* Compute hashing function */
3008 hi = 0;
3009 for (i = 0; i < sizeof value / sizeof (int); i++)
3010 hi += ((int *) &value)[i];
3012 hi &= (1 << HASHBITS) - 1;
3013 hi %= MAX_RTX_HASH_TABLE;
3014 return hi;
3017 /* Compare a constant rtl object X with a constant-descriptor DESC.
3018 Return 1 if DESC describes a constant with the same value as X. */
3020 static int
3021 compare_constant_rtx (mode, x, desc)
3022 enum machine_mode mode;
3023 rtx x;
3024 struct constant_descriptor *desc;
3026 register int *p = (int *) desc->contents;
3027 register int *strp;
3028 register int len;
3029 struct rtx_const value;
3031 decode_rtx_const (mode, x, &value);
3032 strp = (int *) &value;
3033 len = sizeof value / sizeof (int);
3035 /* Compare constant contents. */
3036 while (--len >= 0)
3037 if (*p++ != *strp++)
3038 return 0;
3040 return 1;
3043 /* Construct a constant descriptor for the rtl-expression X.
3044 It is up to the caller to enter the descriptor in the hash table. */
3046 static struct constant_descriptor *
3047 record_constant_rtx (mode, x)
3048 enum machine_mode mode;
3049 rtx x;
3051 struct constant_descriptor *ptr;
3052 char *label;
3053 struct rtx_const value;
3055 decode_rtx_const (mode, x, &value);
3057 /* Put these things in the saveable obstack so we can ensure it won't
3058 be freed if we are called from combine or some other phase that discards
3059 memory allocated from function_obstack (current_obstack). */
3060 obstack_grow (saveable_obstack, &ptr, sizeof ptr);
3061 obstack_grow (saveable_obstack, &label, sizeof label);
3063 /* Record constant contents. */
3064 obstack_grow (saveable_obstack, &value, sizeof value);
3066 return (struct constant_descriptor *) obstack_finish (saveable_obstack);
3069 /* Given a constant rtx X, make (or find) a memory constant for its value
3070 and return a MEM rtx to refer to it in memory. */
3073 force_const_mem (mode, x)
3074 enum machine_mode mode;
3075 rtx x;
3077 register int hash;
3078 register struct constant_descriptor *desc;
3079 char label[256];
3080 char *found = 0;
3081 rtx def;
3083 /* If we want this CONST_DOUBLE in the same mode as it is in memory
3084 (this will always be true for floating CONST_DOUBLEs that have been
3085 placed in memory, but not for VOIDmode (integer) CONST_DOUBLEs),
3086 use the previous copy. Otherwise, make a new one. Note that in
3087 the unlikely event that this same CONST_DOUBLE is used in two different
3088 modes in an alternating fashion, we will allocate a lot of different
3089 memory locations, but this should be extremely rare. */
3091 /* Don't use CONST_DOUBLE_MEM in a nested function.
3092 Nested functions have their own constant pools,
3093 so they can't share the same values in CONST_DOUBLE_MEM
3094 with the containing function. */
3095 if (outer_function_chain == 0)
3096 if (GET_CODE (x) == CONST_DOUBLE
3097 && GET_CODE (CONST_DOUBLE_MEM (x)) == MEM
3098 && GET_MODE (CONST_DOUBLE_MEM (x)) == mode)
3099 return CONST_DOUBLE_MEM (x);
3101 /* Compute hash code of X. Search the descriptors for that hash code
3102 to see if any of them describes X. If yes, the descriptor records
3103 the label number already assigned. */
3105 hash = const_hash_rtx (mode, x);
3107 for (desc = const_rtx_hash_table[hash]; desc; desc = desc->next)
3108 if (compare_constant_rtx (mode, x, desc))
3110 found = desc->label;
3111 break;
3114 if (found == 0)
3116 register struct pool_constant *pool;
3117 register struct pool_sym *sym;
3118 int align;
3120 /* No constant equal to X is known to have been output.
3121 Make a constant descriptor to enter X in the hash table.
3122 Assign the label number and record it in the descriptor for
3123 future calls to this function to find. */
3125 desc = record_constant_rtx (mode, x);
3126 desc->next = const_rtx_hash_table[hash];
3127 const_rtx_hash_table[hash] = desc;
3129 /* Align the location counter as required by EXP's data type. */
3130 align = (mode == VOIDmode) ? UNITS_PER_WORD : GET_MODE_SIZE (mode);
3131 if (align > BIGGEST_ALIGNMENT / BITS_PER_UNIT)
3132 align = BIGGEST_ALIGNMENT / BITS_PER_UNIT;
3134 pool_offset += align - 1;
3135 pool_offset &= ~ (align - 1);
3137 /* If RTL is not being placed into the saveable obstack, make a
3138 copy of X that is in the saveable obstack in case we are being
3139 called from combine or some other phase that discards memory
3140 it allocates. We need only do this if it is a CONST, since
3141 no other RTX should be allocated in this situation. */
3142 if (rtl_obstack != saveable_obstack
3143 && GET_CODE (x) == CONST)
3145 push_obstacks_nochange ();
3146 rtl_in_saveable_obstack ();
3148 x = gen_rtx (CONST, GET_MODE (x),
3149 gen_rtx (PLUS, GET_MODE (x),
3150 XEXP (XEXP (x, 0), 0), XEXP (XEXP (x, 0), 1)));
3151 pop_obstacks ();
3154 /* Allocate a pool constant descriptor, fill it in, and chain it in. */
3156 pool = (struct pool_constant *) savealloc (sizeof (struct pool_constant));
3157 pool->desc = desc;
3158 pool->constant = x;
3159 pool->mode = mode;
3160 pool->labelno = const_labelno;
3161 pool->align = align;
3162 pool->offset = pool_offset;
3163 pool->next = 0;
3165 if (last_pool == 0)
3166 first_pool = pool;
3167 else
3168 last_pool->next = pool;
3170 last_pool = pool;
3171 pool_offset += GET_MODE_SIZE (mode);
3173 /* Create a string containing the label name, in LABEL. */
3174 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno);
3176 ++const_labelno;
3178 desc->label = found
3179 = (char *) obstack_copy0 (saveable_obstack, label, strlen (label));
3181 /* Add label to symbol hash table. */
3182 hash = SYMHASH (found);
3183 sym = (struct pool_sym *) savealloc (sizeof (struct pool_sym));
3184 sym->label = found;
3185 sym->pool = pool;
3186 sym->next = const_rtx_sym_hash_table[hash];
3187 const_rtx_sym_hash_table[hash] = sym;
3190 /* We have a symbol name; construct the SYMBOL_REF and the MEM. */
3192 def = gen_rtx (MEM, mode, gen_rtx (SYMBOL_REF, Pmode, found));
3194 RTX_UNCHANGING_P (def) = 1;
3195 /* Mark the symbol_ref as belonging to this constants pool. */
3196 CONSTANT_POOL_ADDRESS_P (XEXP (def, 0)) = 1;
3197 current_function_uses_const_pool = 1;
3199 if (outer_function_chain == 0)
3200 if (GET_CODE (x) == CONST_DOUBLE)
3202 if (CONST_DOUBLE_MEM (x) == cc0_rtx)
3204 CONST_DOUBLE_CHAIN (x) = const_double_chain;
3205 const_double_chain = x;
3207 CONST_DOUBLE_MEM (x) = def;
3210 return def;
3213 /* Given a SYMBOL_REF with CONSTANT_POOL_ADDRESS_P true, return a pointer to
3214 the corresponding pool_constant structure. */
3216 static struct pool_constant *
3217 find_pool_constant (addr)
3218 rtx addr;
3220 struct pool_sym *sym;
3221 char *label = XSTR (addr, 0);
3223 for (sym = const_rtx_sym_hash_table[SYMHASH (label)]; sym; sym = sym->next)
3224 if (sym->label == label)
3225 return sym->pool;
3227 abort ();
3230 /* Given a constant pool SYMBOL_REF, return the corresponding constant. */
3233 get_pool_constant (addr)
3234 rtx addr;
3236 return (find_pool_constant (addr))->constant;
3239 /* Similar, return the mode. */
3241 enum machine_mode
3242 get_pool_mode (addr)
3243 rtx addr;
3245 return (find_pool_constant (addr))->mode;
3248 /* Similar, return the offset in the constant pool. */
3251 get_pool_offset (addr)
3252 rtx addr;
3254 return (find_pool_constant (addr))->offset;
3257 /* Return the size of the constant pool. */
3260 get_pool_size ()
3262 return pool_offset;
3265 /* Write all the constants in the constant pool. */
3267 void
3268 output_constant_pool (fnname, fndecl)
3269 char *fnname;
3270 tree fndecl;
3272 struct pool_constant *pool;
3273 rtx x;
3274 union real_extract u;
3276 #ifdef ASM_OUTPUT_POOL_PROLOGUE
3277 ASM_OUTPUT_POOL_PROLOGUE (asm_out_file, fnname, fndecl, pool_offset);
3278 #endif
3280 for (pool = first_pool; pool; pool = pool->next)
3282 x = pool->constant;
3284 /* See if X is a LABEL_REF (or a CONST referring to a LABEL_REF)
3285 whose CODE_LABEL has been deleted. This can occur if a jump table
3286 is eliminated by optimization. If so, write a constant of zero
3287 instead. Note that this can also happen by turning the
3288 CODE_LABEL into a NOTE. */
3289 if (((GET_CODE (x) == LABEL_REF
3290 && (INSN_DELETED_P (XEXP (x, 0))
3291 || GET_CODE (XEXP (x, 0)) == NOTE)))
3292 || (GET_CODE (x) == CONST && GET_CODE (XEXP (x, 0)) == PLUS
3293 && GET_CODE (XEXP (XEXP (x, 0), 0)) == LABEL_REF
3294 && (INSN_DELETED_P (XEXP (XEXP (XEXP (x, 0), 0), 0))
3295 || GET_CODE (XEXP (XEXP (XEXP (x, 0), 0), 0)) == NOTE)))
3296 x = const0_rtx;
3298 /* First switch to correct section. */
3299 #ifdef SELECT_RTX_SECTION
3300 SELECT_RTX_SECTION (pool->mode, x);
3301 #else
3302 readonly_data_section ();
3303 #endif
3305 #ifdef ASM_OUTPUT_SPECIAL_POOL_ENTRY
3306 ASM_OUTPUT_SPECIAL_POOL_ENTRY (asm_out_file, x, pool->mode,
3307 pool->align, pool->labelno, done);
3308 #endif
3310 if (pool->align > 1)
3311 ASM_OUTPUT_ALIGN (asm_out_file, exact_log2 (pool->align));
3313 /* Output the label. */
3314 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, "LC", pool->labelno);
3316 /* Output the value of the constant itself. */
3317 switch (GET_MODE_CLASS (pool->mode))
3319 case MODE_FLOAT:
3320 if (GET_CODE (x) != CONST_DOUBLE)
3321 abort ();
3323 bcopy ((char *) &CONST_DOUBLE_LOW (x), (char *) &u, sizeof u);
3324 assemble_real (u.d, pool->mode);
3325 break;
3327 case MODE_INT:
3328 case MODE_PARTIAL_INT:
3329 assemble_integer (x, GET_MODE_SIZE (pool->mode), 1);
3330 break;
3332 default:
3333 abort ();
3336 done: ;
3339 /* Done with this pool. */
3340 first_pool = last_pool = 0;
3343 /* Find all the constants whose addresses are referenced inside of EXP,
3344 and make sure assembler code with a label has been output for each one.
3345 Indicate whether an ADDR_EXPR has been encountered. */
3347 static int
3348 output_addressed_constants (exp)
3349 tree exp;
3351 int reloc = 0;
3353 switch (TREE_CODE (exp))
3355 case ADDR_EXPR:
3357 register tree constant = TREE_OPERAND (exp, 0);
3359 while (TREE_CODE (constant) == COMPONENT_REF)
3361 constant = TREE_OPERAND (constant, 0);
3364 if (TREE_CODE_CLASS (TREE_CODE (constant)) == 'c'
3365 || TREE_CODE (constant) == CONSTRUCTOR)
3366 /* No need to do anything here
3367 for addresses of variables or functions. */
3368 output_constant_def (constant);
3370 reloc = 1;
3371 break;
3373 case PLUS_EXPR:
3374 case MINUS_EXPR:
3375 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3376 reloc |= output_addressed_constants (TREE_OPERAND (exp, 1));
3377 break;
3379 case NOP_EXPR:
3380 case CONVERT_EXPR:
3381 case NON_LVALUE_EXPR:
3382 reloc = output_addressed_constants (TREE_OPERAND (exp, 0));
3383 break;
3385 case CONSTRUCTOR:
3387 register tree link;
3388 for (link = CONSTRUCTOR_ELTS (exp); link; link = TREE_CHAIN (link))
3389 if (TREE_VALUE (link) != 0)
3390 reloc |= output_addressed_constants (TREE_VALUE (link));
3392 break;
3394 case ERROR_MARK:
3395 break;
3397 return reloc;
3400 /* Output assembler code for constant EXP to FILE, with no label.
3401 This includes the pseudo-op such as ".int" or ".byte", and a newline.
3402 Assumes output_addressed_constants has been done on EXP already.
3404 Generate exactly SIZE bytes of assembler data, padding at the end
3405 with zeros if necessary. SIZE must always be specified.
3407 SIZE is important for structure constructors,
3408 since trailing members may have been omitted from the constructor.
3409 It is also important for initialization of arrays from string constants
3410 since the full length of the string constant might not be wanted.
3411 It is also needed for initialization of unions, where the initializer's
3412 type is just one member, and that may not be as long as the union.
3414 There a case in which we would fail to output exactly SIZE bytes:
3415 for a structure constructor that wants to produce more than SIZE bytes.
3416 But such constructors will never be generated for any possible input. */
3418 void
3419 output_constant (exp, size)
3420 register tree exp;
3421 register int size;
3423 register enum tree_code code = TREE_CODE (TREE_TYPE (exp));
3424 rtx x;
3426 if (size == 0)
3427 return;
3429 /* Eliminate the NON_LVALUE_EXPR_EXPR that makes a cast not be an lvalue.
3430 That way we get the constant (we hope) inside it. Also, strip off any
3431 NOP_EXPR that converts between two record, union, array, or set types. */
3432 while ((TREE_CODE (exp) == NOP_EXPR
3433 && (TREE_TYPE (exp) == TREE_TYPE (TREE_OPERAND (exp, 0))
3434 || AGGREGATE_TYPE_P (TREE_TYPE (exp))))
3435 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3436 exp = TREE_OPERAND (exp, 0);
3438 /* Allow a constructor with no elements for any data type.
3439 This means to fill the space with zeros. */
3440 if (TREE_CODE (exp) == CONSTRUCTOR && CONSTRUCTOR_ELTS (exp) == 0)
3442 if (output_bytecode)
3443 bc_emit_const_skip (size);
3444 else
3445 assemble_zeros (size);
3446 return;
3449 switch (code)
3451 case CHAR_TYPE:
3452 case BOOLEAN_TYPE:
3453 case INTEGER_TYPE:
3454 case ENUMERAL_TYPE:
3455 case POINTER_TYPE:
3456 case REFERENCE_TYPE:
3457 /* ??? What about (int)((float)(int)&foo + 4) */
3458 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR
3459 || TREE_CODE (exp) == NON_LVALUE_EXPR)
3460 exp = TREE_OPERAND (exp, 0);
3462 if (! assemble_integer (expand_expr (exp, NULL_RTX, VOIDmode,
3463 EXPAND_INITIALIZER),
3464 size, 0))
3465 error ("initializer for integer value is too complicated");
3466 size = 0;
3467 break;
3469 case REAL_TYPE:
3470 if (TREE_CODE (exp) != REAL_CST)
3471 error ("initializer for floating value is not a floating constant");
3473 assemble_real (TREE_REAL_CST (exp),
3474 mode_for_size (size * BITS_PER_UNIT, MODE_FLOAT, 0));
3475 size = 0;
3476 break;
3478 case COMPLEX_TYPE:
3479 output_constant (TREE_REALPART (exp), size / 2);
3480 output_constant (TREE_IMAGPART (exp), size / 2);
3481 size -= (size / 2) * 2;
3482 break;
3484 case ARRAY_TYPE:
3485 if (TREE_CODE (exp) == CONSTRUCTOR)
3487 output_constructor (exp, size);
3488 return;
3490 else if (TREE_CODE (exp) == STRING_CST)
3492 int excess = 0;
3494 if (size > TREE_STRING_LENGTH (exp))
3496 excess = size - TREE_STRING_LENGTH (exp);
3497 size = TREE_STRING_LENGTH (exp);
3500 assemble_string (TREE_STRING_POINTER (exp), size);
3501 size = excess;
3503 else
3504 abort ();
3505 break;
3507 case RECORD_TYPE:
3508 case UNION_TYPE:
3509 if (TREE_CODE (exp) == CONSTRUCTOR)
3510 output_constructor (exp, size);
3511 else
3512 abort ();
3513 return;
3515 case SET_TYPE:
3516 if (TREE_CODE (exp) == INTEGER_CST)
3517 assemble_integer (expand_expr (exp, NULL_RTX,
3518 VOIDmode, EXPAND_INITIALIZER),
3519 size, 1);
3520 else if (TREE_CODE (exp) == CONSTRUCTOR)
3522 unsigned char *buffer = (unsigned char *) alloca (size);
3523 if (get_set_constructor_bytes (exp, buffer, size))
3524 abort ();
3525 assemble_string (buffer, size);
3527 else
3528 error ("unknown set constructor type");
3529 return;
3532 if (size > 0)
3533 assemble_zeros (size);
3536 /* Bytecode specific code to output assembler for integer. */
3538 static void
3539 bc_assemble_integer (exp, size)
3540 tree exp;
3541 int size;
3543 tree const_part;
3544 tree addr_part;
3545 tree tmp;
3547 /* FIXME: is this fold() business going to be as good as the
3548 expand_expr() using EXPAND_SUM above in the RTL case? I
3549 hate RMS.
3550 FIXME: Copied as is from BC-GCC1; may need work. Don't hate. -bson */
3552 exp = fold (exp);
3554 while (TREE_CODE (exp) == NOP_EXPR || TREE_CODE (exp) == CONVERT_EXPR)
3555 exp = TREE_OPERAND (exp, 0);
3556 if (TREE_CODE (exp) == INTEGER_CST)
3558 const_part = exp;
3559 addr_part = 0;
3561 else if (TREE_CODE (exp) == PLUS_EXPR)
3563 const_part = TREE_OPERAND (exp, 0);
3564 while (TREE_CODE (const_part) == NOP_EXPR
3565 || TREE_CODE (const_part) == CONVERT_EXPR)
3566 const_part = TREE_OPERAND (const_part, 0);
3567 addr_part = TREE_OPERAND (exp, 1);
3568 while (TREE_CODE (addr_part) == NOP_EXPR
3569 || TREE_CODE (addr_part) == CONVERT_EXPR)
3570 addr_part = TREE_OPERAND (addr_part, 0);
3571 if (TREE_CODE (const_part) != INTEGER_CST)
3572 tmp = const_part, const_part = addr_part, addr_part = tmp;
3573 if (TREE_CODE (const_part) != INTEGER_CST
3574 || TREE_CODE (addr_part) != ADDR_EXPR)
3575 abort (); /* FIXME: we really haven't considered
3576 all the possible cases here. */
3578 else if (TREE_CODE (exp) == ADDR_EXPR)
3580 const_part = integer_zero_node;
3581 addr_part = exp;
3583 else
3584 abort (); /* FIXME: ditto previous. */
3586 if (addr_part == 0)
3588 if (size == 1)
3590 char c = TREE_INT_CST_LOW (const_part);
3591 bc_emit (&c, 1);
3592 size -= 1;
3594 else if (size == 2)
3596 short s = TREE_INT_CST_LOW (const_part);
3597 bc_emit ((char *) &s, 2);
3598 size -= 2;
3600 else if (size == 4)
3602 int i = TREE_INT_CST_LOW (const_part);
3603 bc_emit ((char *) &i, 4);
3604 size -= 4;
3606 else if (size == 8)
3608 if (WORDS_BIG_ENDIAN)
3610 int i = TREE_INT_CST_HIGH (const_part);
3611 bc_emit ((char *) &i, 4);
3612 i = TREE_INT_CST_LOW (const_part);
3613 bc_emit ((char *) &i, 4);
3615 else
3617 int i = TREE_INT_CST_LOW (const_part);
3618 bc_emit ((char *) &i, 4);
3619 i = TREE_INT_CST_HIGH (const_part);
3620 bc_emit ((char *) &i, 4);
3622 size -= 8;
3625 else
3626 if (size == 4
3627 && TREE_CODE (TREE_OPERAND (addr_part, 0)) == VAR_DECL)
3628 bc_emit_labelref (DECL_ASSEMBLER_NAME (TREE_OPERAND (addr_part, 0)),
3629 TREE_INT_CST_LOW (const_part));
3630 else
3631 abort (); /* FIXME: there may be more cases. */
3634 /* Subroutine of output_constant, used for CONSTRUCTORs
3635 (aggregate constants).
3636 Generate at least SIZE bytes, padding if necessary. */
3638 static void
3639 output_constructor (exp, size)
3640 tree exp;
3641 int size;
3643 register tree link, field = 0;
3644 HOST_WIDE_INT min_index = 0;
3645 /* Number of bytes output or skipped so far.
3646 In other words, current position within the constructor. */
3647 int total_bytes = 0;
3648 /* Non-zero means BYTE contains part of a byte, to be output. */
3649 int byte_buffer_in_use = 0;
3650 register int byte;
3652 if (HOST_BITS_PER_WIDE_INT < BITS_PER_UNIT)
3653 abort ();
3655 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE)
3656 field = TYPE_FIELDS (TREE_TYPE (exp));
3658 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE
3659 && TYPE_DOMAIN (TREE_TYPE (exp)) != 0)
3660 min_index
3661 = TREE_INT_CST_LOW (TYPE_MIN_VALUE (TYPE_DOMAIN (TREE_TYPE (exp))));
3663 /* As LINK goes through the elements of the constant,
3664 FIELD goes through the structure fields, if the constant is a structure.
3665 if the constant is a union, then we override this,
3666 by getting the field from the TREE_LIST element.
3667 But the constant could also be an array. Then FIELD is zero. */
3668 for (link = CONSTRUCTOR_ELTS (exp);
3669 link;
3670 link = TREE_CHAIN (link),
3671 field = field ? TREE_CHAIN (field) : 0)
3673 tree val = TREE_VALUE (link);
3674 tree index = 0;
3676 /* the element in a union constructor specifies the proper field. */
3678 if (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
3679 || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE)
3681 /* if available, use the type given by link */
3682 if (TREE_PURPOSE (link) != 0)
3683 field = TREE_PURPOSE (link);
3686 if (TREE_CODE (TREE_TYPE (exp)) == ARRAY_TYPE)
3687 index = TREE_PURPOSE (link);
3689 /* Eliminate the marker that makes a cast not be an lvalue. */
3690 if (val != 0)
3691 STRIP_NOPS (val);
3693 if (field == 0 || !DECL_BIT_FIELD (field))
3695 /* An element that is not a bit-field. */
3697 register int fieldsize;
3698 /* Since this structure is static,
3699 we know the positions are constant. */
3700 int bitpos = (field ? (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field))
3701 / BITS_PER_UNIT)
3702 : 0);
3703 if (index != 0)
3704 bitpos = (TREE_INT_CST_LOW (TYPE_SIZE (TREE_TYPE (val)))
3705 / BITS_PER_UNIT
3706 * (TREE_INT_CST_LOW (index) - min_index));
3708 /* Output any buffered-up bit-fields preceding this element. */
3709 if (byte_buffer_in_use)
3711 ASM_OUTPUT_BYTE (asm_out_file, byte);
3712 total_bytes++;
3713 byte_buffer_in_use = 0;
3716 /* Advance to offset of this element.
3717 Note no alignment needed in an array, since that is guaranteed
3718 if each element has the proper size. */
3719 if ((field != 0 || index != 0) && bitpos != total_bytes)
3721 if (!output_bytecode)
3722 assemble_zeros (bitpos - total_bytes);
3723 else
3724 bc_emit_const_skip (bitpos - total_bytes);
3725 total_bytes = bitpos;
3728 /* Determine size this element should occupy. */
3729 if (field)
3731 if (TREE_CODE (DECL_SIZE (field)) != INTEGER_CST)
3732 abort ();
3733 if (TREE_INT_CST_LOW (DECL_SIZE (field)) > 100000)
3735 /* This avoids overflow trouble. */
3736 tree size_tree = size_binop (CEIL_DIV_EXPR,
3737 DECL_SIZE (field),
3738 size_int (BITS_PER_UNIT));
3739 fieldsize = TREE_INT_CST_LOW (size_tree);
3741 else
3743 fieldsize = TREE_INT_CST_LOW (DECL_SIZE (field));
3744 fieldsize = (fieldsize + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
3747 else
3748 fieldsize = int_size_in_bytes (TREE_TYPE (TREE_TYPE (exp)));
3750 /* Output the element's initial value. */
3751 if (val == 0)
3752 assemble_zeros (fieldsize);
3753 else
3754 output_constant (val, fieldsize);
3756 /* Count its size. */
3757 total_bytes += fieldsize;
3759 else if (val != 0 && TREE_CODE (val) != INTEGER_CST)
3760 error ("invalid initial value for member `%s'",
3761 IDENTIFIER_POINTER (DECL_NAME (field)));
3762 else
3764 /* Element that is a bit-field. */
3766 int next_offset = TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field));
3767 int end_offset
3768 = (next_offset + TREE_INT_CST_LOW (DECL_SIZE (field)));
3770 if (val == 0)
3771 val = integer_zero_node;
3773 /* If this field does not start in this (or, next) byte,
3774 skip some bytes. */
3775 if (next_offset / BITS_PER_UNIT != total_bytes)
3777 /* Output remnant of any bit field in previous bytes. */
3778 if (byte_buffer_in_use)
3780 ASM_OUTPUT_BYTE (asm_out_file, byte);
3781 total_bytes++;
3782 byte_buffer_in_use = 0;
3785 /* If still not at proper byte, advance to there. */
3786 if (next_offset / BITS_PER_UNIT != total_bytes)
3788 assemble_zeros (next_offset / BITS_PER_UNIT - total_bytes);
3789 total_bytes = next_offset / BITS_PER_UNIT;
3793 if (! byte_buffer_in_use)
3794 byte = 0;
3796 /* We must split the element into pieces that fall within
3797 separate bytes, and combine each byte with previous or
3798 following bit-fields. */
3800 /* next_offset is the offset n fbits from the beginning of
3801 the structure to the next bit of this element to be processed.
3802 end_offset is the offset of the first bit past the end of
3803 this element. */
3804 while (next_offset < end_offset)
3806 int this_time;
3807 int shift;
3808 HOST_WIDE_INT value;
3809 int next_byte = next_offset / BITS_PER_UNIT;
3810 int next_bit = next_offset % BITS_PER_UNIT;
3812 /* Advance from byte to byte
3813 within this element when necessary. */
3814 while (next_byte != total_bytes)
3816 ASM_OUTPUT_BYTE (asm_out_file, byte);
3817 total_bytes++;
3818 byte = 0;
3821 /* Number of bits we can process at once
3822 (all part of the same byte). */
3823 this_time = MIN (end_offset - next_offset,
3824 BITS_PER_UNIT - next_bit);
3825 if (BYTES_BIG_ENDIAN)
3827 /* On big-endian machine, take the most significant bits
3828 first (of the bits that are significant)
3829 and put them into bytes from the most significant end. */
3830 shift = end_offset - next_offset - this_time;
3831 /* Don't try to take a bunch of bits that cross
3832 the word boundary in the INTEGER_CST. */
3833 if (shift < HOST_BITS_PER_WIDE_INT
3834 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3836 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3837 shift = HOST_BITS_PER_WIDE_INT;
3840 /* Now get the bits from the appropriate constant word. */
3841 if (shift < HOST_BITS_PER_WIDE_INT)
3843 value = TREE_INT_CST_LOW (val);
3845 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3847 value = TREE_INT_CST_HIGH (val);
3848 shift -= HOST_BITS_PER_WIDE_INT;
3850 else
3851 abort ();
3852 byte |= (((value >> shift)
3853 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3854 << (BITS_PER_UNIT - this_time - next_bit));
3856 else
3858 /* On little-endian machines,
3859 take first the least significant bits of the value
3860 and pack them starting at the least significant
3861 bits of the bytes. */
3862 shift = (next_offset
3863 - TREE_INT_CST_LOW (DECL_FIELD_BITPOS (field)));
3864 /* Don't try to take a bunch of bits that cross
3865 the word boundary in the INTEGER_CST. */
3866 if (shift < HOST_BITS_PER_WIDE_INT
3867 && shift + this_time > HOST_BITS_PER_WIDE_INT)
3869 this_time -= (HOST_BITS_PER_WIDE_INT - shift);
3870 shift = HOST_BITS_PER_WIDE_INT;
3873 /* Now get the bits from the appropriate constant word. */
3874 if (shift < HOST_BITS_PER_INT)
3875 value = TREE_INT_CST_LOW (val);
3876 else if (shift < 2 * HOST_BITS_PER_WIDE_INT)
3878 value = TREE_INT_CST_HIGH (val);
3879 shift -= HOST_BITS_PER_WIDE_INT;
3881 else
3882 abort ();
3883 byte |= (((value >> shift)
3884 & (((HOST_WIDE_INT) 1 << this_time) - 1))
3885 << next_bit);
3887 next_offset += this_time;
3888 byte_buffer_in_use = 1;
3892 if (byte_buffer_in_use)
3894 ASM_OUTPUT_BYTE (asm_out_file, byte);
3895 total_bytes++;
3897 if (total_bytes < size)
3898 assemble_zeros (size - total_bytes);
3902 #ifdef HANDLE_SYSV_PRAGMA
3904 /* Support #pragma weak by default if WEAK_ASM_OP and ASM_OUTPUT_DEF
3905 are defined. */
3906 #if defined (WEAK_ASM_OP) && defined (ASM_OUTPUT_DEF)
3908 /* See c-pragma.c for an identical definition. */
3909 enum pragma_state
3911 ps_start,
3912 ps_done,
3913 ps_bad,
3914 ps_weak,
3915 ps_name,
3916 ps_equals,
3917 ps_value,
3918 ps_pack,
3919 ps_left,
3920 ps_align,
3921 ps_right
3924 /* Output asm to handle ``#pragma weak'' */
3925 void
3926 handle_pragma_weak (what, asm_out_file, name, value)
3927 enum pragma_state what;
3928 FILE *asm_out_file;
3929 char *name, *value;
3931 if (what == ps_name || what == ps_value)
3933 fprintf (asm_out_file, "\t%s\t", WEAK_ASM_OP);
3935 if (output_bytecode)
3936 BC_OUTPUT_LABELREF (asm_out_file, name);
3937 else
3938 ASM_OUTPUT_LABELREF (asm_out_file, name);
3940 fputc ('\n', asm_out_file);
3941 if (what == ps_value)
3942 ASM_OUTPUT_DEF (asm_out_file, name, value);
3944 else if (! (what == ps_done || what == ps_start))
3945 warning ("malformed `#pragma weak'");
3948 #endif /* HANDLE_PRAGMA_WEAK or (WEAK_ASM_OP and SET_ASM_OP) */
3950 #endif /* WEAK_ASM_OP && ASM_OUTPUT_DEF */