1 /****************************************************************************
3 * GNAT COMPILER COMPONENTS *
7 * C Implementation File *
9 * Copyright (C) 1992-2003 Free Software Foundation, Inc. *
11 * GNAT is free software; you can redistribute it and/or modify it under *
12 * terms of the GNU General Public License as published by the Free Soft- *
13 * ware Foundation; either version 2, or (at your option) any later ver- *
14 * sion. GNAT is distributed in the hope that it will be useful, but WITH- *
15 * OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY *
16 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
17 * for more details. You should have received a copy of the GNU General *
18 * Public License distributed with GNAT; see file COPYING. If not, write *
19 * to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, *
20 * MA 02111-1307, USA. *
22 * As a special exception, if you link this file with other files to *
23 * produce an executable, this file does not by itself cause the resulting *
24 * executable to be covered by the GNU General Public License. This except- *
25 * ion does not however invalidate any other reasons why the executable *
26 * file might be covered by the GNU Public License. *
28 * GNAT was originally developed by the GNAT team at New York University. *
29 * Extensive contributions were provided by Ada Core Technologies Inc. *
31 ****************************************************************************/
33 /* This file contains parts of the compiler that are required for interfacing
34 with GCC but otherwise do nothing and parts of Gigi that need to know
39 #include "coretypes.h"
45 #include "diagnostic.h"
51 #include "insn-codes.h"
52 #include "insn-flags.h"
53 #include "insn-config.h"
60 #include "langhooks.h"
61 #include "langhooks-def.h"
77 #include "adadecode.h"
81 extern FILE *asm_out_file;
83 /* The largest alignment, in bits, that is needed for using the widest
85 unsigned int largest_move_alignment;
87 static size_t gnat_tree_size (enum tree_code);
88 static bool gnat_init (void);
89 static void gnat_finish_incomplete_decl (tree);
90 static unsigned int gnat_init_options (unsigned int, const char **);
91 static int gnat_handle_option (size_t, const char *, int);
92 static HOST_WIDE_INT gnat_get_alias_set (tree);
93 static void gnat_print_decl (FILE *, tree, int);
94 static void gnat_print_type (FILE *, tree, int);
95 static const char *gnat_printable_name (tree, int);
96 static tree gnat_eh_runtime_type (tree);
97 static int gnat_eh_type_covers (tree, tree);
98 static void gnat_parse_file (int);
99 static rtx gnat_expand_expr (tree, rtx, enum machine_mode, int);
100 static void internal_error_function (const char *, va_list *);
101 static void gnat_adjust_rli (record_layout_info);
103 /* Structure giving our language-specific hooks. */
105 #undef LANG_HOOKS_NAME
106 #define LANG_HOOKS_NAME "GNU Ada"
107 #undef LANG_HOOKS_IDENTIFIER_SIZE
108 #define LANG_HOOKS_IDENTIFIER_SIZE sizeof (struct tree_identifier)
109 #undef LANG_HOOKS_TREE_SIZE
110 #define LANG_HOOKS_TREE_SIZE gnat_tree_size
111 #undef LANG_HOOKS_INIT
112 #define LANG_HOOKS_INIT gnat_init
113 #undef LANG_HOOKS_INIT_OPTIONS
114 #define LANG_HOOKS_INIT_OPTIONS gnat_init_options
115 #undef LANG_HOOKS_HANDLE_OPTION
116 #define LANG_HOOKS_HANDLE_OPTION gnat_handle_option
117 #undef LANG_HOOKS_PARSE_FILE
118 #define LANG_HOOKS_PARSE_FILE gnat_parse_file
119 #undef LANG_HOOKS_HONOR_READONLY
120 #define LANG_HOOKS_HONOR_READONLY 1
121 #undef LANG_HOOKS_FINISH_INCOMPLETE_DECL
122 #define LANG_HOOKS_FINISH_INCOMPLETE_DECL gnat_finish_incomplete_decl
123 #undef LANG_HOOKS_GET_ALIAS_SET
124 #define LANG_HOOKS_GET_ALIAS_SET gnat_get_alias_set
125 #undef LANG_HOOKS_EXPAND_EXPR
126 #define LANG_HOOKS_EXPAND_EXPR gnat_expand_expr
127 #undef LANG_HOOKS_MARK_ADDRESSABLE
128 #define LANG_HOOKS_MARK_ADDRESSABLE gnat_mark_addressable
129 #undef LANG_HOOKS_TRUTHVALUE_CONVERSION
130 #define LANG_HOOKS_TRUTHVALUE_CONVERSION gnat_truthvalue_conversion
131 #undef LANG_HOOKS_PRINT_DECL
132 #define LANG_HOOKS_PRINT_DECL gnat_print_decl
133 #undef LANG_HOOKS_PRINT_TYPE
134 #define LANG_HOOKS_PRINT_TYPE gnat_print_type
135 #undef LANG_HOOKS_DECL_PRINTABLE_NAME
136 #define LANG_HOOKS_DECL_PRINTABLE_NAME gnat_printable_name
137 #undef LANG_HOOKS_TYPE_FOR_MODE
138 #define LANG_HOOKS_TYPE_FOR_MODE gnat_type_for_mode
139 #undef LANG_HOOKS_TYPE_FOR_SIZE
140 #define LANG_HOOKS_TYPE_FOR_SIZE gnat_type_for_size
141 #undef LANG_HOOKS_SIGNED_TYPE
142 #define LANG_HOOKS_SIGNED_TYPE gnat_signed_type
143 #undef LANG_HOOKS_UNSIGNED_TYPE
144 #define LANG_HOOKS_UNSIGNED_TYPE gnat_unsigned_type
145 #undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE
146 #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE gnat_signed_or_unsigned_type
148 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
150 /* Tables describing GCC tree codes used only by GNAT.
152 Table indexed by tree code giving a string containing a character
153 classifying the tree code. Possibilities are
154 t, d, s, c, r, <, 1 and 2. See cp-tree.def for details. */
156 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
158 const char tree_code_type[] = {
161 #include "ada-tree.def"
165 /* Table indexed by tree code giving number of expression
166 operands beyond the fixed part of the node structure.
167 Not used for types or decls. */
169 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
171 const unsigned char tree_code_length[] = {
174 #include "ada-tree.def"
178 /* Names of tree components.
179 Used for printing out the tree and error messages. */
180 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
182 const char *const tree_code_name[] = {
185 #include "ada-tree.def"
189 /* Command-line argc and argv.
190 These variables are global, since they are imported and used in
193 unsigned int save_argc;
194 const char **save_argv;
196 /* gnat standard argc argv */
198 extern int gnat_argc;
199 extern char **gnat_argv;
202 /* Declare functions we use as part of startup. */
203 extern void __gnat_initialize (void);
204 extern void adainit (void);
205 extern void _ada_gnat1drv (void);
207 /* The parser for the language. For us, we process the GNAT tree. */
210 gnat_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
212 /* call the target specific initializations */
215 /* Call the front-end elaboration procedures */
218 immediate_size_expand = 1;
220 /* Call the front end */
224 /* Decode all the language specific options that cannot be decoded by GCC.
225 The option decoding phase of GCC calls this routine on the flags that
226 it cannot decode. This routine returns the number of consecutive arguments
227 from ARGV that it successfully decoded; 0 indicates failure. */
230 gnat_handle_option (size_t scode, const char *arg, int value ATTRIBUTE_UNUSED)
232 const struct cl_option *option = &cl_options[scode];
233 enum opt_code code = (enum opt_code) scode;
237 if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
239 error ("missing argument to \"-%s\"", option->opt_text);
249 q = xmalloc (sizeof("-I") + strlen (arg));
252 gnat_argv[gnat_argc] = q;
256 /* All front ends are expected to accept this. */
258 /* These are used in the GCC Makefile. */
259 case OPT_Wmissing_prototypes:
260 case OPT_Wstrict_prototypes:
261 case OPT_Wwrite_strings:
265 /* This is handled by the front-end. */
270 gnat_argv[gnat_argc] = xstrdup ("-nostdlib");
275 gnat_argv[gnat_argc] = xstrdup ("-fRTS");
280 warning ("`-gnat' misspelled as `-gant'");
282 /* ... fall through ... */
285 /* Recopy the switches without the 'gnat' prefix. */
286 gnat_argv[gnat_argc] = xmalloc (strlen (arg) + 2);
287 gnat_argv[gnat_argc][0] = '-';
288 strcpy (gnat_argv[gnat_argc] + 1, arg);
292 for (i = 1; i < save_argc - 1; i++)
293 if (!strncmp (save_argv[i], "-gnatO", 6))
294 if (save_argv[++i][0] != '-')
296 /* Preserve output filename as GCC doesn't save it for GNAT. */
297 gnat_argv[gnat_argc] = xstrdup (save_argv[i]);
307 /* Initialize for option processing. */
310 gnat_init_options (unsigned int argc, const char **argv)
312 /* Initialize gnat_argv with save_argv size. */
313 gnat_argv = (char **) xmalloc ((argc + 1) * sizeof (argv[0]));
314 gnat_argv[0] = xstrdup (argv[0]); /* name of the command */
323 /* Here is the function to handle the compiler error processing in GCC. */
326 internal_error_function (const char *msgid, va_list *ap)
328 char buffer[1000]; /* Assume this is big enough. */
330 String_Template temp;
333 vsprintf (buffer, msgid, *ap);
335 /* Go up to the first newline. */
336 for (p = buffer; *p != 0; p++)
343 temp.Low_Bound = 1, temp.High_Bound = strlen (buffer);
344 fp.Array = buffer, fp.Bounds = &temp;
346 Current_Error_Node = error_gnat_node;
347 Compiler_Abort (fp, -1);
350 /* Langhook for tree_size: Determine size of our 'x' and 'c' nodes. */
353 gnat_tree_size (enum tree_code code)
358 return sizeof (struct tree_loop_id);
365 /* Perform all the initialization steps that are language-specific. */
370 /* Performs whatever initialization steps needed by the language-dependent
372 gnat_init_decl_processing ();
374 /* Add the input filename as the last argument. */
375 gnat_argv[gnat_argc] = (char *) main_input_filename;
377 gnat_argv[gnat_argc] = 0;
379 global_dc->internal_error = &internal_error_function;
381 /* Show that REFERENCE_TYPEs are internal and should be Pmode. */
382 internal_reference_types ();
384 set_lang_adjust_rli (gnat_adjust_rli);
389 /* This function is called indirectly from toplev.c to handle incomplete
390 declarations, i.e. VAR_DECL nodes whose DECL_SIZE is zero. To be precise,
391 compile_file in toplev.c makes an indirect call through the function pointer
392 incomplete_decl_finalize_hook which is initialized to this routine in
393 init_decl_processing. */
396 gnat_finish_incomplete_decl (tree dont_care ATTRIBUTE_UNUSED)
401 /* Compute the alignment of the largest mode that can be used for copying
405 gnat_compute_largest_alignment (void)
407 enum machine_mode mode;
409 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
410 mode = GET_MODE_WIDER_MODE (mode))
411 if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
412 largest_move_alignment = MIN (BIGGEST_ALIGNMENT,
413 MAX (largest_move_alignment,
414 GET_MODE_ALIGNMENT (mode)));
417 /* If we are using the GCC mechanism to process exception handling, we
418 have to register the personality routine for Ada and to initialize
419 various language dependent hooks. */
422 gnat_init_gcc_eh (void)
424 /* We shouldn't do anything if the No_Exceptions_Handler pragma is set,
425 though. This could for instance lead to the emission of tables with
426 references to symbols (such as the Ada eh personality routine) within
427 libraries we won't link against. */
428 if (No_Exception_Handlers_Set ())
431 /* Tell GCC we are handling cleanup actions through exception propagation.
432 This opens possibilities that we don't take advantage of yet, but is
433 nonetheless necessary to ensure that fixup code gets assigned to the
434 right exception regions. */
435 using_eh_for_cleanups ();
437 eh_personality_libfunc = init_one_libfunc ("__gnat_eh_personality");
438 lang_eh_type_covers = gnat_eh_type_covers;
439 lang_eh_runtime_type = gnat_eh_runtime_type;
441 /* Turn on -fexceptions and -fnon-call-exceptions. The first one triggers
442 the generation of the necessary exception runtime tables. The second one
443 is useful for two reasons: 1/ we map some asynchronous signals like SEGV
444 to exceptions, so we need to ensure that the insns which can lead to such
445 signals are correctly attached to the exception region they pertain to,
446 2/ Some calls to pure subprograms are handled as libcall blocks and then
447 marked as "cannot trap" if the flag is not set (see emit_libcall_block).
448 We should not let this be since it is possible for such calls to actually
452 flag_non_call_exceptions = 1;
455 #ifdef DWARF2_UNWIND_INFO
456 if (dwarf2out_do_frame ())
457 dwarf2out_frame_init ();
461 /* Language hooks, first one to print language-specific items in a DECL. */
464 gnat_print_decl (FILE *file, tree node, int indent)
466 switch (TREE_CODE (node))
469 print_node (file, "const_corresponding_var",
470 DECL_CONST_CORRESPONDING_VAR (node), indent + 4);
474 print_node (file, "original field", DECL_ORIGINAL_FIELD (node),
484 gnat_print_type (FILE *file, tree node, int indent)
486 switch (TREE_CODE (node))
489 print_node (file, "ci_co_list", TYPE_CI_CO_LIST (node), indent + 4);
493 print_node (file, "RM size", TYPE_RM_SIZE_ENUM (node), indent + 4);
497 if (TYPE_MODULAR_P (node))
498 print_node (file, "modulus", TYPE_MODULUS (node), indent + 4);
499 else if (TYPE_HAS_ACTUAL_BOUNDS_P (node))
500 print_node (file, "actual bounds", TYPE_ACTUAL_BOUNDS (node),
502 else if (TYPE_VAX_FLOATING_POINT_P (node))
505 print_node (file, "index type", TYPE_INDEX_TYPE (node), indent + 4);
507 print_node (file, "RM size", TYPE_RM_SIZE_INT (node), indent + 4);
511 print_node (file,"actual bounds", TYPE_ACTUAL_BOUNDS (node), indent + 4);
515 if (TYPE_IS_FAT_POINTER_P (node) || TYPE_CONTAINS_TEMPLATE_P (node))
516 print_node (file, "unconstrained array",
517 TYPE_UNCONSTRAINED_ARRAY (node), indent + 4);
519 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
523 case QUAL_UNION_TYPE:
524 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
533 gnat_printable_name (tree decl, int verbosity ATTRIBUTE_UNUSED)
535 const char *coded_name = IDENTIFIER_POINTER (DECL_NAME (decl));
536 char *ada_name = (char *) ggc_alloc (strlen (coded_name) * 2 + 60);
538 __gnat_decode (coded_name, ada_name, 0);
540 return (const char *) ada_name;
543 /* Expands GNAT-specific GCC tree nodes. The only ones we support
544 here are TRANSFORM_EXPR, ALLOCATE_EXPR, USE_EXPR and NULL_EXPR. */
547 gnat_expand_expr (tree exp, rtx target, enum machine_mode tmode, int modifier)
549 tree type = TREE_TYPE (exp);
553 /* If this is a statement, call the expansion routine for statements. */
556 gnat_expand_stmt (exp);
560 /* Update EXP to be the new expression to expand. */
561 switch (TREE_CODE (exp))
564 gnat_to_code (TREE_COMPLEXITY (exp));
569 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
571 /* We aren't going to be doing anything with this memory, but allocate
572 it anyway. If it's variable size, make a bogus address. */
573 if (! host_integerp (TYPE_SIZE_UNIT (type), 1))
574 result = gen_rtx_MEM (BLKmode, virtual_stack_vars_rtx);
576 result = assign_temp (type, 0, TREE_ADDRESSABLE (exp), 1);
582 allocate_dynamic_stack_space
583 (expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, TYPE_MODE (sizetype),
585 NULL_RTX, tree_low_cst (TREE_OPERAND (exp, 1), 1));
588 if (target != const0_rtx)
591 /* First write a volatile ASM_INPUT to prevent anything from being
593 result = gen_rtx_ASM_INPUT (VOIDmode, "");
594 MEM_VOLATILE_P (result) = 1;
597 result = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode,
599 emit_insn (gen_rtx_USE (VOIDmode, result));
603 return expand_expr (build1 (NOP_EXPR, type, TREE_OPERAND (exp, 0)),
604 target, tmode, modifier);
606 case UNCONSTRAINED_ARRAY_REF:
607 /* If we are evaluating just for side-effects, just evaluate our
608 operand. Otherwise, abort since this code should never appear
609 in a tree to be evaluated (objects aren't unconstrained). */
610 if (target == const0_rtx || TREE_CODE (type) == VOID_TYPE)
611 return expand_expr (TREE_OPERAND (exp, 0), const0_rtx,
614 /* ... fall through ... */
620 return expand_expr (new, target, tmode, modifier);
623 /* Adjusts the RLI used to layout a record after all the fields have been
624 added. We only handle the packed case and cause it to use the alignment
625 that will pad the record at the end. */
628 gnat_adjust_rli (record_layout_info rli ATTRIBUTE_UNUSED)
631 /* ??? This code seems to have no actual effect; record_align should already
632 reflect the largest alignment desired by a field. jason 2003-04-01 */
633 unsigned int record_align = rli->unpadded_align;
636 /* If an alignment has been specified, don't use anything larger unless we
638 if (TYPE_ALIGN (rli->t) != 0 && TYPE_ALIGN (rli->t) < record_align)
639 record_align = MAX (rli->record_align, TYPE_ALIGN (rli->t));
641 /* If any fields have variable size, we need to force the record to be at
642 least as aligned as the alignment of that type. */
643 for (field = TYPE_FIELDS (rli->t); field; field = TREE_CHAIN (field))
644 if (TREE_CODE (DECL_SIZE_UNIT (field)) != INTEGER_CST)
645 record_align = MAX (record_align, DECL_ALIGN (field));
647 if (TYPE_PACKED (rli->t))
648 rli->record_align = record_align;
652 /* Make a TRANSFORM_EXPR to later expand GNAT_NODE into code. */
655 make_transform_expr (Node_Id gnat_node)
657 tree gnu_result = build (TRANSFORM_EXPR, void_type_node);
659 TREE_SIDE_EFFECTS (gnu_result) = 1;
660 TREE_COMPLEXITY (gnu_result) = gnat_node;
664 /* Update the setjmp buffer BUF with the current stack pointer. We assume
665 here that a __builtin_setjmp was done to BUF. */
668 update_setjmp_buf (tree buf)
670 enum machine_mode sa_mode = Pmode;
673 #ifdef HAVE_save_stack_nonlocal
674 if (HAVE_save_stack_nonlocal)
675 sa_mode = insn_data[(int) CODE_FOR_save_stack_nonlocal].operand[0].mode;
677 #ifdef STACK_SAVEAREA_MODE
678 sa_mode = STACK_SAVEAREA_MODE (SAVE_NONLOCAL);
682 = gen_rtx_MEM (sa_mode,
685 plus_constant (expand_expr
686 (build_unary_op (ADDR_EXPR, NULL_TREE, buf),
687 NULL_RTX, VOIDmode, 0),
688 2 * GET_MODE_SIZE (Pmode))));
692 emit_insn (gen_setjmp ());
695 emit_stack_save (SAVE_NONLOCAL, &stack_save, NULL_RTX);
698 /* These routines are used in conjunction with GCC exception handling. */
700 /* Map compile-time to run-time tree for GCC exception handling scheme. */
703 gnat_eh_runtime_type (tree type)
708 /* Return true if type A catches type B. Callback for flow analysis from
709 the exception handling part of the back-end. */
712 gnat_eh_type_covers (tree a, tree b)
714 /* a catches b if they represent the same exception id or if a
717 ??? integer_zero_node for "others" is hardwired in too many places
719 return (a == b || a == integer_zero_node);
722 /* See if DECL has an RTL that is indirect via a pseudo-register or a
723 memory location and replace it with an indirect reference if so.
724 This improves the debugger's ability to display the value. */
727 adjust_decl_rtl (tree decl)
731 /* If this decl is already indirect, don't do anything. This should
732 mean that the decl cannot be indirect, but there's no point in
733 adding an abort to check that. */
734 if (TREE_CODE (decl) != CONST_DECL
735 && ! DECL_BY_REF_P (decl)
736 && (GET_CODE (DECL_RTL (decl)) == MEM
737 && (GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
738 || (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG
739 && (REGNO (XEXP (DECL_RTL (decl), 0))
740 > LAST_VIRTUAL_REGISTER))))
741 /* We can't do this if the reference type's mode is not the same
742 as the current mode, which means this may not work on mixed 32/64
744 && (new_type = build_reference_type (TREE_TYPE (decl))) != 0
745 && TYPE_MODE (new_type) == GET_MODE (XEXP (DECL_RTL (decl), 0))
746 /* If this is a PARM_DECL, we can only do it if DECL_INCOMING_RTL
747 is also an indirect and of the same mode and if the object is
748 readonly, the latter condition because we don't want to upset the
749 handling of CICO_LIST. */
750 && (TREE_CODE (decl) != PARM_DECL
751 || (GET_CODE (DECL_INCOMING_RTL (decl)) == MEM
752 && (TYPE_MODE (new_type)
753 == GET_MODE (XEXP (DECL_INCOMING_RTL (decl), 0)))
754 && TREE_READONLY (decl))))
757 = build_qualified_type (new_type,
758 (TYPE_QUALS (new_type) | TYPE_QUAL_CONST));
760 DECL_POINTS_TO_READONLY_P (decl) = TREE_READONLY (decl);
761 DECL_BY_REF_P (decl) = 1;
762 SET_DECL_RTL (decl, XEXP (DECL_RTL (decl), 0));
763 TREE_TYPE (decl) = new_type;
764 DECL_MODE (decl) = TYPE_MODE (new_type);
765 DECL_ALIGN (decl) = TYPE_ALIGN (new_type);
766 DECL_SIZE (decl) = TYPE_SIZE (new_type);
768 if (TREE_CODE (decl) == PARM_DECL)
769 DECL_INCOMING_RTL (decl) = XEXP (DECL_INCOMING_RTL (decl), 0);
771 /* If DECL_INITIAL was set, it should be updated to show that
772 the decl is initialized to the address of that thing.
773 Otherwise, just set it to the address of this decl.
774 It needs to be set so that GCC does not think the decl is
777 = build1 (ADDR_EXPR, new_type,
778 DECL_INITIAL (decl) != 0 ? DECL_INITIAL (decl) : decl);
782 /* Record the current code position in GNAT_NODE. */
785 record_code_position (Node_Id gnat_node)
787 if (global_bindings_p ())
789 /* Make a dummy entry so multiple things at the same location don't
790 end up in the same place. */
791 add_pending_elaborations (NULL_TREE, NULL_TREE);
792 save_gnu_tree (gnat_node, get_elaboration_location (), 1);
795 /* Always emit another insn in case marking the last insn
796 addressable needs some fixups and also for above reason. */
797 save_gnu_tree (gnat_node,
798 build (RTL_EXPR, void_type_node, NULL_TREE,
799 (tree) emit_note (NOTE_INSN_DELETED)),
803 /* Insert the code for GNAT_NODE at the position saved for that node. */
806 insert_code_for (Node_Id gnat_node)
808 if (global_bindings_p ())
810 push_pending_elaborations ();
811 gnat_to_code (gnat_node);
812 Check_Elaboration_Code_Allowed (gnat_node);
813 insert_elaboration_list (get_gnu_tree (gnat_node));
814 pop_pending_elaborations ();
820 do_pending_stack_adjust ();
822 mark_all_temps_used ();
823 gnat_to_code (gnat_node);
824 do_pending_stack_adjust ();
825 insns = get_insns ();
827 emit_insn_after (insns, RTL_EXPR_RTL (get_gnu_tree (gnat_node)));
831 /* Get the alias set corresponding to a type or expression. */
834 gnat_get_alias_set (tree type)
836 /* If this is a padding type, use the type of the first field. */
837 if (TREE_CODE (type) == RECORD_TYPE
838 && TYPE_IS_PADDING_P (type))
839 return get_alias_set (TREE_TYPE (TYPE_FIELDS (type)));
841 /* If the type is an unconstrained array, use the type of the
842 self-referential array we make. */
843 else if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE)
845 get_alias_set (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (type)))));
851 /* GNU_TYPE is a type. Determine if it should be passed by reference by
855 default_pass_by_ref (tree gnu_type)
859 INIT_CUMULATIVE_ARGS (cum, NULL_TREE, NULL_RTX, 0);
861 /* We pass aggregates by reference if they are sufficiently large. The
862 choice of constant here is somewhat arbitrary. We also pass by
863 reference if the target machine would either pass or return by
864 reference. Strictly speaking, we need only check the return if this
865 is an In Out parameter, but it's probably best to err on the side of
866 passing more things by reference. */
868 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
869 || FUNCTION_ARG_PASS_BY_REFERENCE (cum, TYPE_MODE (gnu_type),
872 || targetm.calls.return_in_memory (gnu_type, NULL_TREE)
873 || (AGGREGATE_TYPE_P (gnu_type)
874 && (! host_integerp (TYPE_SIZE (gnu_type), 1)
875 || 0 < compare_tree_int (TYPE_SIZE (gnu_type),
876 8 * TYPE_ALIGN (gnu_type)))));
879 /* GNU_TYPE is the type of a subprogram parameter. Determine from the type if
880 it should be passed by reference. */
883 must_pass_by_ref (tree gnu_type)
885 /* We pass only unconstrained objects, those required by the language
886 to be passed by reference, and objects of variable size. The latter
887 is more efficient, avoids problems with variable size temporaries,
888 and does not produce compatibility problems with C, since C does
889 not have such objects. */
890 return (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE
891 || (AGGREGATE_TYPE_P (gnu_type) && TYPE_BY_REFERENCE_P (gnu_type))
892 || (TYPE_SIZE (gnu_type) != 0
893 && TREE_CODE (TYPE_SIZE (gnu_type)) != INTEGER_CST));
896 /* This function is called by the front end to enumerate all the supported
897 modes for the machine. We pass a function which is called back with
898 the following integer parameters:
900 FLOAT_P nonzero if this represents a floating-point mode
901 COMPLEX_P nonzero is this represents a complex mode
902 COUNT count of number of items, nonzero for vector mode
903 PRECISION number of bits in data representation
904 MANTISSA number of bits in mantissa, if FP and known, else zero.
905 SIZE number of bits used to store data
906 ALIGN number of bits to which mode is aligned. */
909 enumerate_modes (void (*f) (int, int, int, int, int, int, unsigned int))
913 for (i = 0; i < NUM_MACHINE_MODES; i++)
921 enum machine_mode inner_mode = i;
923 switch (GET_MODE_CLASS (i))
930 case MODE_COMPLEX_INT:
932 inner_mode = GET_MODE_INNER (i);
934 case MODE_COMPLEX_FLOAT:
937 inner_mode = GET_MODE_INNER (i);
939 case MODE_VECTOR_INT:
941 inner_mode = GET_MODE_INNER (i);
943 case MODE_VECTOR_FLOAT:
946 inner_mode = GET_MODE_INNER (i);
952 /* Skip this mode if it's one the front end doesn't need to know about
953 (e.g., the CC modes) or if there is no add insn for that mode (or
954 any wider mode), meaning it is not supported by the hardware. If
955 this a complex or vector mode, we care about the inner mode. */
956 for (j = inner_mode; j != VOIDmode; j = GET_MODE_WIDER_MODE (j))
957 if (add_optab->handlers[j].insn_code != CODE_FOR_nothing)
962 const struct real_format *fmt = REAL_MODE_FORMAT (inner_mode);
964 mantissa = fmt->p * fmt->log2_b;
967 if (!skip_p && j != VOIDmode)
968 (*f) (float_p, complex_p, vector_p ? GET_MODE_NUNITS (i) : 0,
969 GET_MODE_BITSIZE (i), mantissa,
970 GET_MODE_SIZE (i) * BITS_PER_UNIT, GET_MODE_ALIGNMENT (i));
975 fp_prec_to_size (int prec)
977 enum machine_mode mode;
979 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
980 mode = GET_MODE_WIDER_MODE (mode))
981 if (GET_MODE_PRECISION (mode) == prec)
982 return GET_MODE_BITSIZE (mode);
988 fp_size_to_prec (int size)
990 enum machine_mode mode;
992 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
993 mode = GET_MODE_WIDER_MODE (mode))
994 if (GET_MODE_BITSIZE (mode) == size)
995 return GET_MODE_PRECISION (mode);