Add an UNSPEC_PROLOGUE_USE to prevent the link register from being considered dead.
[official-gcc.git] / gcc / ada / misc.c
bloba8293e709fb5e85270edc6e4b7f5ffbd84c888e6
1 /****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * M I S C *
6 * *
7 * C Implementation File *
8 * *
9 * *
10 * Copyright (C) 1992-2002 Free Software Foundation, Inc. *
11 * *
12 * GNAT is free software; you can redistribute it and/or modify it under *
13 * terms of the GNU General Public License as published by the Free Soft- *
14 * ware Foundation; either version 2, or (at your option) any later ver- *
15 * sion. GNAT is distributed in the hope that it will be useful, but WITH- *
16 * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
17 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
18 * for more details. You should have received a copy of the GNU General *
19 * Public License distributed with GNAT; see file COPYING. If not, write *
20 * to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, *
21 * MA 02111-1307, USA. *
22 * *
23 * As a special exception, if you link this file with other files to *
24 * produce an executable, this file does not by itself cause the resulting *
25 * executable to be covered by the GNU General Public License. This except- *
26 * ion does not however invalidate any other reasons why the executable *
27 * file might be covered by the GNU Public License. *
28 * *
29 * GNAT was originally developed by the GNAT team at New York University. *
30 * Extensive contributions were provided by Ada Core Technologies Inc. *
31 * *
32 ****************************************************************************/
34 /* This file contains parts of the compiler that are required for interfacing
35 with GCC but otherwise do nothing and parts of Gigi that need to know
36 about RTL. */
38 #include "config.h"
39 #include "system.h"
40 #include "coretypes.h"
41 #include "tm.h"
42 #include "tree.h"
43 #include "rtl.h"
44 #include "errors.h"
45 #include "diagnostic.h"
46 #include "expr.h"
47 #include "libfuncs.h"
48 #include "ggc.h"
49 #include "flags.h"
50 #include "debug.h"
51 #include "insn-codes.h"
52 #include "insn-flags.h"
53 #include "insn-config.h"
54 #include "optabs.h"
55 #include "recog.h"
56 #include "toplev.h"
57 #include "output.h"
58 #include "except.h"
59 #include "tm_p.h"
60 #include "langhooks.h"
61 #include "langhooks-def.h"
63 #include "ada.h"
64 #include "types.h"
65 #include "atree.h"
66 #include "elists.h"
67 #include "namet.h"
68 #include "nlists.h"
69 #include "stringt.h"
70 #include "uintp.h"
71 #include "fe.h"
72 #include "sinfo.h"
73 #include "einfo.h"
74 #include "ada-tree.h"
75 #include "gigi.h"
76 #include "adadecode.h"
78 extern FILE *asm_out_file;
79 extern int save_argc;
80 extern char **save_argv;
82 static const char *gnat_init PARAMS ((const char *));
83 static void gnat_init_options PARAMS ((void));
84 static int gnat_decode_option PARAMS ((int, char **));
85 static HOST_WIDE_INT gnat_get_alias_set PARAMS ((tree));
86 static void gnat_print_decl PARAMS ((FILE *, tree, int));
87 static void gnat_print_type PARAMS ((FILE *, tree, int));
88 static const char *gnat_printable_name PARAMS ((tree, int));
89 static tree gnat_eh_runtime_type PARAMS ((tree));
90 static int gnat_eh_type_covers PARAMS ((tree, tree));
91 static void gnat_parse_file PARAMS ((int));
92 static rtx gnat_expand_expr PARAMS ((tree, rtx, enum machine_mode,
93 int));
95 /* Structure giving our language-specific hooks. */
97 #undef LANG_HOOKS_NAME
98 #define LANG_HOOKS_NAME "GNU Ada"
99 #undef LANG_HOOKS_IDENTIFIER_SIZE
100 #define LANG_HOOKS_IDENTIFIER_SIZE sizeof (struct tree_identifier)
101 #undef LANG_HOOKS_INIT
102 #define LANG_HOOKS_INIT gnat_init
103 #undef LANG_HOOKS_INIT_OPTIONS
104 #define LANG_HOOKS_INIT_OPTIONS gnat_init_options
105 #undef LANG_HOOKS_DECODE_OPTION
106 #define LANG_HOOKS_DECODE_OPTION gnat_decode_option
107 #undef LANG_HOOKS_PARSE_FILE
108 #define LANG_HOOKS_PARSE_FILE gnat_parse_file
109 #undef LANG_HOOKS_HONOR_READONLY
110 #define LANG_HOOKS_HONOR_READONLY 1
111 #undef LANG_HOOKS_FINISH_INCOMPLETE_DECL
112 #define LANG_HOOKS_FINISH_INCOMPLETE_DECL gnat_finish_incomplete_decl
113 #undef LANG_HOOKS_GET_ALIAS_SET
114 #define LANG_HOOKS_GET_ALIAS_SET gnat_get_alias_set
115 #undef LANG_HOOKS_EXPAND_EXPR
116 #define LANG_HOOKS_EXPAND_EXPR gnat_expand_expr
117 #undef LANG_HOOKS_MARK_ADDRESSABLE
118 #define LANG_HOOKS_MARK_ADDRESSABLE gnat_mark_addressable
119 #undef LANG_HOOKS_TRUTHVALUE_CONVERSION
120 #define LANG_HOOKS_TRUTHVALUE_CONVERSION gnat_truthvalue_conversion
121 #undef LANG_HOOKS_PRINT_DECL
122 #define LANG_HOOKS_PRINT_DECL gnat_print_decl
123 #undef LANG_HOOKS_PRINT_TYPE
124 #define LANG_HOOKS_PRINT_TYPE gnat_print_type
125 #undef LANG_HOOKS_DECL_PRINTABLE_NAME
126 #define LANG_HOOKS_DECL_PRINTABLE_NAME gnat_printable_name
127 #undef LANG_HOOKS_TYPE_FOR_MODE
128 #define LANG_HOOKS_TYPE_FOR_MODE gnat_type_for_mode
129 #undef LANG_HOOKS_TYPE_FOR_SIZE
130 #define LANG_HOOKS_TYPE_FOR_SIZE gnat_type_for_size
131 #undef LANG_HOOKS_SIGNED_TYPE
132 #define LANG_HOOKS_SIGNED_TYPE gnat_signed_type
133 #undef LANG_HOOKS_UNSIGNED_TYPE
134 #define LANG_HOOKS_UNSIGNED_TYPE gnat_unsigned_type
135 #undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE
136 #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE gnat_signed_or_unsigned_type
138 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
140 /* Tables describing GCC tree codes used only by GNAT.
142 Table indexed by tree code giving a string containing a character
143 classifying the tree code. Possibilities are
144 t, d, s, c, r, <, 1 and 2. See cp-tree.def for details. */
146 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
148 const char tree_code_type[] = {
149 #include "tree.def"
150 'x',
151 #include "ada-tree.def"
153 #undef DEFTREECODE
155 /* Table indexed by tree code giving number of expression
156 operands beyond the fixed part of the node structure.
157 Not used for types or decls. */
159 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
161 const unsigned char tree_code_length[] = {
162 #include "tree.def"
164 #include "ada-tree.def"
166 #undef DEFTREECODE
168 /* Names of tree components.
169 Used for printing out the tree and error messages. */
170 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
172 const char *const tree_code_name[] = {
173 #include "tree.def"
174 "@@dummy",
175 #include "ada-tree.def"
177 #undef DEFTREECODE
179 /* gnat standard argc argv */
181 extern int gnat_argc;
182 extern char **gnat_argv;
184 static void internal_error_function PARAMS ((const char *, va_list *));
185 static void gnat_adjust_rli PARAMS ((record_layout_info));
187 /* Declare functions we use as part of startup. */
188 extern void __gnat_initialize PARAMS((void));
189 extern void adainit PARAMS((void));
190 extern void _ada_gnat1drv PARAMS((void));
192 /* The parser for the language. For us, we process the GNAT tree. */
194 static void
195 gnat_parse_file (set_yydebug)
196 int set_yydebug ATTRIBUTE_UNUSED;
198 /* call the target specific initializations */
199 __gnat_initialize();
201 /* Call the front-end elaboration procedures */
202 adainit ();
204 immediate_size_expand = 1;
206 /* Call the front end */
207 _ada_gnat1drv ();
210 /* Decode all the language specific options that cannot be decoded by GCC.
211 The option decoding phase of GCC calls this routine on the flags that
212 it cannot decode. This routine returns the number of consecutive arguments
213 from ARGV that it successfully decoded; 0 indicates failure. */
215 static int
216 gnat_decode_option (argc, argv)
217 int argc ATTRIBUTE_UNUSED;
218 char **argv;
220 char *p = argv[0];
221 int i;
223 if (!strncmp (p, "-I", 2))
225 /* We might get -I foo or -Ifoo. Canonicalize to the latter. */
226 if (p[2] == '\0')
228 char *q;
230 if (argv[1] == 0)
231 return 0;
233 q = xmalloc (sizeof("-I") + strlen (argv[1]));
234 strcpy (q, "-I");
235 strcat (q, argv[1]);
237 gnat_argv[gnat_argc] = q;
238 gnat_argc ++;
239 return 2; /* consumed argument */
241 else
243 gnat_argv[gnat_argc] = p;
244 gnat_argc ++;
245 return 1;
249 else if (!strncmp (p, "-gant", 5))
251 char *q = xstrdup (p);
253 warning ("`-gnat' misspelled as `-gant'");
254 q[2] = 'n', q[3] = 'a';
255 p = q;
256 return 1;
259 else if (!strncmp (p, "-gnat", 5))
261 /* Recopy the switches without the 'gnat' prefix */
263 gnat_argv[gnat_argc] = (char *) xmalloc (strlen (p) - 3);
264 gnat_argv[gnat_argc][0] = '-';
265 strcpy (gnat_argv[gnat_argc] + 1, p + 5);
266 gnat_argc ++;
267 if (p[5] == 'O')
268 for (i = 1; i < save_argc - 1; i++)
269 if (!strncmp (save_argv[i], "-gnatO", 6))
270 if (save_argv[++i][0] != '-')
272 /* Preserve output filename as GCC doesn't save it for GNAT. */
273 gnat_argv[gnat_argc] = save_argv[i];
274 gnat_argc++;
275 break;
278 return 1;
281 /* Handle the --RTS switch. The real option we get is -fRTS. This
282 modification is done by the driver program. */
283 if (!strncmp (p, "-fRTS", 5))
285 gnat_argv[gnat_argc] = p;
286 gnat_argc ++;
287 return 1;
290 /* Ignore -W flags since people may want to use the same flags for all
291 languages. */
292 else if (p[0] == '-' && p[1] == 'W' && p[2] != 0)
293 return 1;
295 return 0;
298 /* Initialize for option processing. */
300 static void
301 gnat_init_options ()
303 /* Initialize gnat_argv with save_argv size */
304 gnat_argv = (char **) xmalloc ((save_argc + 1) * sizeof (gnat_argv[0]));
305 gnat_argv[0] = save_argv[0]; /* name of the command */
306 gnat_argc = 1;
309 /* Here is the function to handle the compiler error processing in GCC. */
311 static void
312 internal_error_function (msgid, ap)
313 const char *msgid;
314 va_list *ap;
316 char buffer[1000]; /* Assume this is big enough. */
317 char *p;
318 String_Template temp;
319 Fat_Pointer fp;
321 vsprintf (buffer, msgid, *ap);
323 /* Go up to the first newline. */
324 for (p = buffer; *p != 0; p++)
325 if (*p == '\n')
327 *p = '\0';
328 break;
331 temp.Low_Bound = 1, temp.High_Bound = strlen (buffer);
332 fp.Array = buffer, fp.Bounds = &temp;
334 Current_Error_Node = error_gnat_node;
335 Compiler_Abort (fp, -1);
338 /* Perform all the initialization steps that are language-specific. */
340 static const char *
341 gnat_init (filename)
342 const char *filename;
344 /* Performs whatever initialization steps needed by the language-dependent
345 lexical analyzer.
347 Define the additional tree codes here. This isn't the best place to put
348 it, but it's where g++ does it. */
350 gnat_init_decl_processing ();
352 /* Add the input filename as the last argument. */
353 gnat_argv[gnat_argc] = (char *) filename;
354 gnat_argc++;
355 gnat_argv[gnat_argc] = 0;
357 global_dc->internal_error = &internal_error_function;
359 /* Show that REFERENCE_TYPEs are internal and should be Pmode. */
360 internal_reference_types ();
362 set_lang_adjust_rli (gnat_adjust_rli);
364 if (filename == 0)
365 filename = "";
367 return filename;
370 /* If we are using the GCC mechanism for to process exception handling, we
371 have to register the personality routine for Ada and to initialize
372 various language dependent hooks. */
374 void
375 gnat_init_gcc_eh ()
377 /* We shouldn't do anything if the No_Exceptions_Handler pragma is set,
378 though. This could for instance lead to the emission of tables with
379 references to symbols (such as the Ada eh personality routine) within
380 libraries we won't link against. */
381 if (No_Exception_Handlers_Set ())
382 return;
384 eh_personality_libfunc = init_one_libfunc ("__gnat_eh_personality");
385 lang_eh_type_covers = gnat_eh_type_covers;
386 lang_eh_runtime_type = gnat_eh_runtime_type;
387 flag_exceptions = 1;
389 init_eh ();
390 #ifdef DWARF2_UNWIND_INFO
391 if (dwarf2out_do_frame ())
392 dwarf2out_frame_init ();
393 #endif
396 /* Hooks for print-tree.c: */
398 static void
399 gnat_print_decl (file, node, indent)
400 FILE *file;
401 tree node;
402 int indent;
404 switch (TREE_CODE (node))
406 case CONST_DECL:
407 print_node (file, "const_corresponding_var",
408 DECL_CONST_CORRESPONDING_VAR (node), indent + 4);
409 break;
411 case FIELD_DECL:
412 print_node (file, "original field", DECL_ORIGINAL_FIELD (node),
413 indent + 4);
414 break;
416 default:
417 break;
421 static void
422 gnat_print_type (file, node, indent)
423 FILE *file;
424 tree node;
425 int indent;
427 switch (TREE_CODE (node))
429 case FUNCTION_TYPE:
430 print_node (file, "ci_co_list", TYPE_CI_CO_LIST (node), indent + 4);
431 break;
433 case ENUMERAL_TYPE:
434 print_node (file, "RM size", TYPE_RM_SIZE_ENUM (node), indent + 4);
435 break;
437 case INTEGER_TYPE:
438 if (TYPE_MODULAR_P (node))
439 print_node (file, "modulus", TYPE_MODULUS (node), indent + 4);
440 else if (TYPE_HAS_ACTUAL_BOUNDS_P (node))
441 print_node (file, "actual bounds", TYPE_ACTUAL_BOUNDS (node),
442 indent + 4);
443 else if (TYPE_VAX_FLOATING_POINT_P (node))
445 else
446 print_node (file, "index type", TYPE_INDEX_TYPE (node), indent + 4);
448 print_node (file, "RM size", TYPE_RM_SIZE_INT (node), indent + 4);
449 break;
451 case ARRAY_TYPE:
452 print_node (file,"actual bounds", TYPE_ACTUAL_BOUNDS (node), indent + 4);
453 break;
455 case RECORD_TYPE:
456 if (TYPE_IS_FAT_POINTER_P (node) || TYPE_CONTAINS_TEMPLATE_P (node))
457 print_node (file, "unconstrained array",
458 TYPE_UNCONSTRAINED_ARRAY (node), indent + 4);
459 else
460 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
461 break;
463 case UNION_TYPE:
464 case QUAL_UNION_TYPE:
465 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
466 break;
468 default:
469 break;
473 static const char *
474 gnat_printable_name (decl, verbosity)
475 tree decl;
476 int verbosity ATTRIBUTE_UNUSED;
478 const char *coded_name = IDENTIFIER_POINTER (DECL_NAME (decl));
479 char *ada_name = (char *) ggc_alloc (strlen (coded_name) * 2 + 60);
481 __gnat_decode (coded_name, ada_name, 0);
483 return (const char *) ada_name;
486 /* Expands GNAT-specific GCC tree nodes. The only ones we support
487 here are TRANSFORM_EXPR, ALLOCATE_EXPR, USE_EXPR and NULL_EXPR. */
489 static rtx
490 gnat_expand_expr (exp, target, tmode, modifier)
491 tree exp;
492 rtx target;
493 enum machine_mode tmode;
494 int modifier; /* Actually an enum expand_modifier. */
496 tree type = TREE_TYPE (exp);
497 tree new;
498 rtx result;
500 /* Update EXP to be the new expression to expand. */
502 switch (TREE_CODE (exp))
504 case TRANSFORM_EXPR:
505 gnat_to_code (TREE_COMPLEXITY (exp));
506 return const0_rtx;
507 break;
509 case NULL_EXPR:
510 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
512 /* We aren't going to be doing anything with this memory, but allocate
513 it anyway. If it's variable size, make a bogus address. */
514 if (! host_integerp (TYPE_SIZE_UNIT (type), 1))
515 result = gen_rtx_MEM (BLKmode, virtual_stack_vars_rtx);
516 else
517 result = assign_temp (type, 0, TREE_ADDRESSABLE (exp), 1);
519 return result;
521 case ALLOCATE_EXPR:
522 return
523 allocate_dynamic_stack_space
524 (expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, TYPE_MODE (sizetype),
525 EXPAND_NORMAL),
526 NULL_RTX, tree_low_cst (TREE_OPERAND (exp, 1), 1));
528 case USE_EXPR:
529 if (target != const0_rtx)
530 gigi_abort (203);
532 /* First write a volatile ASM_INPUT to prevent anything from being
533 moved. */
534 result = gen_rtx_ASM_INPUT (VOIDmode, "");
535 MEM_VOLATILE_P (result) = 1;
536 emit_insn (result);
538 result = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode,
539 modifier);
540 emit_insn (gen_rtx_USE (VOIDmode, result));
541 return target;
543 case GNAT_NOP_EXPR:
544 return expand_expr (build1 (NOP_EXPR, type, TREE_OPERAND (exp, 0)),
545 target, tmode, modifier);
547 case UNCONSTRAINED_ARRAY_REF:
548 /* If we are evaluating just for side-effects, just evaluate our
549 operand. Otherwise, abort since this code should never appear
550 in a tree to be evaluated (objects aren't unconstrained). */
551 if (target == const0_rtx || TREE_CODE (type) == VOID_TYPE)
552 return expand_expr (TREE_OPERAND (exp, 0), const0_rtx,
553 VOIDmode, modifier);
555 /* ... fall through ... */
557 default:
558 gigi_abort (201);
561 return expand_expr (new, target, tmode, modifier);
564 /* Adjusts the RLI used to layout a record after all the fields have been
565 added. We only handle the packed case and cause it to use the alignment
566 that will pad the record at the end. */
568 static void
569 gnat_adjust_rli (rli)
570 record_layout_info rli;
572 unsigned int record_align = rli->unpadded_align;
573 tree field;
575 /* If any fields have variable size, we need to force the record to be at
576 least as aligned as the alignment of that type. */
577 for (field = TYPE_FIELDS (rli->t); field; field = TREE_CHAIN (field))
578 if (TREE_CODE (DECL_SIZE_UNIT (field)) != INTEGER_CST)
579 record_align = MAX (record_align, DECL_ALIGN (field));
581 if (TYPE_PACKED (rli->t))
582 rli->record_align = record_align;
585 /* Make a TRANSFORM_EXPR to later expand GNAT_NODE into code. */
587 tree
588 make_transform_expr (gnat_node)
589 Node_Id gnat_node;
591 tree gnu_result = build (TRANSFORM_EXPR, void_type_node);
593 TREE_SIDE_EFFECTS (gnu_result) = 1;
594 TREE_COMPLEXITY (gnu_result) = gnat_node;
595 return gnu_result;
598 /* Update the setjmp buffer BUF with the current stack pointer. We assume
599 here that a __builtin_setjmp was done to BUF. */
601 void
602 update_setjmp_buf (buf)
603 tree buf;
605 enum machine_mode sa_mode = Pmode;
606 rtx stack_save;
608 #ifdef HAVE_save_stack_nonlocal
609 if (HAVE_save_stack_nonlocal)
610 sa_mode = insn_data[(int) CODE_FOR_save_stack_nonlocal].operand[0].mode;
611 #endif
612 #ifdef STACK_SAVEAREA_MODE
613 sa_mode = STACK_SAVEAREA_MODE (SAVE_NONLOCAL);
614 #endif
616 stack_save
617 = gen_rtx_MEM (sa_mode,
618 memory_address
619 (sa_mode,
620 plus_constant (expand_expr
621 (build_unary_op (ADDR_EXPR, NULL_TREE, buf),
622 NULL_RTX, VOIDmode, 0),
623 2 * GET_MODE_SIZE (Pmode))));
625 #ifdef HAVE_setjmp
626 if (HAVE_setjmp)
627 emit_insn (gen_setjmp ());
628 #endif
630 emit_stack_save (SAVE_NONLOCAL, &stack_save, NULL_RTX);
633 /* These routines are used in conjunction with GCC exception handling. */
635 /* Map compile-time to run-time tree for GCC exception handling scheme. */
637 static tree
638 gnat_eh_runtime_type (type)
639 tree type;
641 return type;
644 /* Return true if type A catches type B. Callback for flow analysis from
645 the exception handling part of the back-end. */
647 static int
648 gnat_eh_type_covers (a, b)
649 tree a, b;
651 /* a catches b if they represent the same exception id or if a
652 is an "others".
654 ??? integer_zero_node for "others" is hardwired in too many places
655 currently. */
656 return (a == b || a == integer_zero_node);
659 /* See if DECL has an RTL that is indirect via a pseudo-register or a
660 memory location and replace it with an indirect reference if so.
661 This improves the debugger's ability to display the value. */
663 void
664 adjust_decl_rtl (decl)
665 tree decl;
667 tree new_type;
669 /* If this decl is already indirect, don't do anything. This should
670 mean that the decl cannot be indirect, but there's no point in
671 adding an abort to check that. */
672 if (TREE_CODE (decl) != CONST_DECL
673 && ! DECL_BY_REF_P (decl)
674 && (GET_CODE (DECL_RTL (decl)) == MEM
675 && (GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
676 || (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG
677 && (REGNO (XEXP (DECL_RTL (decl), 0))
678 > LAST_VIRTUAL_REGISTER))))
679 /* We can't do this if the reference type's mode is not the same
680 as the current mode, which means this may not work on mixed 32/64
681 bit systems. */
682 && (new_type = build_reference_type (TREE_TYPE (decl))) != 0
683 && TYPE_MODE (new_type) == GET_MODE (XEXP (DECL_RTL (decl), 0))
684 /* If this is a PARM_DECL, we can only do it if DECL_INCOMING_RTL
685 is also an indirect and of the same mode and if the object is
686 readonly, the latter condition because we don't want to upset the
687 handling of CICO_LIST. */
688 && (TREE_CODE (decl) != PARM_DECL
689 || (GET_CODE (DECL_INCOMING_RTL (decl)) == MEM
690 && (TYPE_MODE (new_type)
691 == GET_MODE (XEXP (DECL_INCOMING_RTL (decl), 0)))
692 && TREE_READONLY (decl))))
694 new_type
695 = build_qualified_type (new_type,
696 (TYPE_QUALS (new_type) | TYPE_QUAL_CONST));
698 DECL_POINTS_TO_READONLY_P (decl) = TREE_READONLY (decl);
699 DECL_BY_REF_P (decl) = 1;
700 SET_DECL_RTL (decl, XEXP (DECL_RTL (decl), 0));
701 TREE_TYPE (decl) = new_type;
702 DECL_MODE (decl) = TYPE_MODE (new_type);
703 DECL_ALIGN (decl) = TYPE_ALIGN (new_type);
704 DECL_SIZE (decl) = TYPE_SIZE (new_type);
706 if (TREE_CODE (decl) == PARM_DECL)
707 DECL_INCOMING_RTL (decl) = XEXP (DECL_INCOMING_RTL (decl), 0);
709 /* If DECL_INITIAL was set, it should be updated to show that
710 the decl is initialized to the address of that thing.
711 Otherwise, just set it to the address of this decl.
712 It needs to be set so that GCC does not think the decl is
713 unused. */
714 DECL_INITIAL (decl)
715 = build1 (ADDR_EXPR, new_type,
716 DECL_INITIAL (decl) != 0 ? DECL_INITIAL (decl) : decl);
720 /* Record the current code position in GNAT_NODE. */
722 void
723 record_code_position (gnat_node)
724 Node_Id gnat_node;
726 if (global_bindings_p ())
728 /* Make a dummy entry so multiple things at the same location don't
729 end up in the same place. */
730 add_pending_elaborations (NULL_TREE, NULL_TREE);
731 save_gnu_tree (gnat_node, get_elaboration_location (), 1);
733 else
734 /* Always emit another insn in case marking the last insn
735 addressable needs some fixups and also for above reason. */
736 save_gnu_tree (gnat_node,
737 build (RTL_EXPR, void_type_node, NULL_TREE,
738 (tree) emit_note (0, NOTE_INSN_DELETED)),
742 /* Insert the code for GNAT_NODE at the position saved for that node. */
744 void
745 insert_code_for (gnat_node)
746 Node_Id gnat_node;
748 if (global_bindings_p ())
750 push_pending_elaborations ();
751 gnat_to_code (gnat_node);
752 Check_Elaboration_Code_Allowed (gnat_node);
753 insert_elaboration_list (get_gnu_tree (gnat_node));
754 pop_pending_elaborations ();
756 else
758 rtx insns;
760 do_pending_stack_adjust ();
761 start_sequence ();
762 mark_all_temps_used ();
763 gnat_to_code (gnat_node);
764 do_pending_stack_adjust ();
765 insns = get_insns ();
766 end_sequence ();
767 emit_insn_after (insns, RTL_EXPR_RTL (get_gnu_tree (gnat_node)));
771 /* Get the alias set corresponding to a type or expression. */
773 static HOST_WIDE_INT
774 gnat_get_alias_set (type)
775 tree type;
777 /* If this is a padding type, use the type of the first field. */
778 if (TREE_CODE (type) == RECORD_TYPE
779 && TYPE_IS_PADDING_P (type))
780 return get_alias_set (TREE_TYPE (TYPE_FIELDS (type)));
782 /* If the type is an unconstrained array, use the type of the
783 self-referential array we make. */
784 else if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE)
785 return
786 get_alias_set (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (type)))));
789 return -1;
792 /* GNU_TYPE is a type. Determine if it should be passed by reference by
793 default. */
796 default_pass_by_ref (gnu_type)
797 tree gnu_type;
799 CUMULATIVE_ARGS cum;
801 INIT_CUMULATIVE_ARGS (cum, NULL_TREE, NULL_RTX, 0);
803 /* We pass aggregates by reference if they are sufficiently large. The
804 choice of constant here is somewhat arbitrary. We also pass by
805 reference if the target machine would either pass or return by
806 reference. Strictly speaking, we need only check the return if this
807 is an In Out parameter, but it's probably best to err on the side of
808 passing more things by reference. */
809 return (0
810 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
811 || FUNCTION_ARG_PASS_BY_REFERENCE (cum, TYPE_MODE (gnu_type),
812 gnu_type, 1)
813 #endif
814 || RETURN_IN_MEMORY (gnu_type)
815 || (AGGREGATE_TYPE_P (gnu_type)
816 && (! host_integerp (TYPE_SIZE (gnu_type), 1)
817 || 0 < compare_tree_int (TYPE_SIZE (gnu_type),
818 8 * TYPE_ALIGN (gnu_type)))));
821 /* GNU_TYPE is the type of a subprogram parameter. Determine from the type if
822 it should be passed by reference. */
825 must_pass_by_ref (gnu_type)
826 tree gnu_type;
828 /* We pass only unconstrained objects, those required by the language
829 to be passed by reference, and objects of variable size. The latter
830 is more efficient, avoids problems with variable size temporaries,
831 and does not produce compatibility problems with C, since C does
832 not have such objects. */
833 return (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE
834 || (AGGREGATE_TYPE_P (gnu_type) && TYPE_BY_REFERENCE_P (gnu_type))
835 || (TYPE_SIZE (gnu_type) != 0
836 && TREE_CODE (TYPE_SIZE (gnu_type)) != INTEGER_CST));
839 /* This function returns the version of GCC being used. Here it's GCC 3. */
842 gcc_version ()
844 return 3;