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