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