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