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