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