1 /****************************************************************************
3 * GNAT COMPILER COMPONENTS *
7 * C Implementation File *
9 * Copyright (C) 1992-2004 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,
101 static void internal_error_function (const char *, va_list *);
102 static void gnat_adjust_rli (record_layout_info);
104 /* Definitions for our language-specific hooks. */
106 #undef LANG_HOOKS_NAME
107 #define LANG_HOOKS_NAME "GNU Ada"
108 #undef LANG_HOOKS_IDENTIFIER_SIZE
109 #define LANG_HOOKS_IDENTIFIER_SIZE sizeof (struct tree_identifier)
110 #undef LANG_HOOKS_TREE_SIZE
111 #define LANG_HOOKS_TREE_SIZE gnat_tree_size
112 #undef LANG_HOOKS_INIT
113 #define LANG_HOOKS_INIT gnat_init
114 #undef LANG_HOOKS_INIT_OPTIONS
115 #define LANG_HOOKS_INIT_OPTIONS gnat_init_options
116 #undef LANG_HOOKS_HANDLE_OPTION
117 #define LANG_HOOKS_HANDLE_OPTION gnat_handle_option
118 #undef LANG_HOOKS_PARSE_FILE
119 #define LANG_HOOKS_PARSE_FILE gnat_parse_file
120 #undef LANG_HOOKS_HONOR_READONLY
121 #define LANG_HOOKS_HONOR_READONLY true
122 #undef LANG_HOOKS_HASH_TYPES
123 #define LANG_HOOKS_HASH_TYPES false
124 #undef LANG_HOOKS_FINISH_INCOMPLETE_DECL
125 #define LANG_HOOKS_FINISH_INCOMPLETE_DECL gnat_finish_incomplete_decl
126 #undef LANG_HOOKS_GET_ALIAS_SET
127 #define LANG_HOOKS_GET_ALIAS_SET gnat_get_alias_set
128 #undef LANG_HOOKS_EXPAND_EXPR
129 #define LANG_HOOKS_EXPAND_EXPR gnat_expand_expr
130 #undef LANG_HOOKS_MARK_ADDRESSABLE
131 #define LANG_HOOKS_MARK_ADDRESSABLE gnat_mark_addressable
132 #undef LANG_HOOKS_TRUTHVALUE_CONVERSION
133 #define LANG_HOOKS_TRUTHVALUE_CONVERSION gnat_truthvalue_conversion
134 #undef LANG_HOOKS_PRINT_DECL
135 #define LANG_HOOKS_PRINT_DECL gnat_print_decl
136 #undef LANG_HOOKS_PRINT_TYPE
137 #define LANG_HOOKS_PRINT_TYPE gnat_print_type
138 #undef LANG_HOOKS_DECL_PRINTABLE_NAME
139 #define LANG_HOOKS_DECL_PRINTABLE_NAME gnat_printable_name
140 #undef LANG_HOOKS_TYPE_FOR_MODE
141 #define LANG_HOOKS_TYPE_FOR_MODE gnat_type_for_mode
142 #undef LANG_HOOKS_TYPE_FOR_SIZE
143 #define LANG_HOOKS_TYPE_FOR_SIZE gnat_type_for_size
144 #undef LANG_HOOKS_SIGNED_TYPE
145 #define LANG_HOOKS_SIGNED_TYPE gnat_signed_type
146 #undef LANG_HOOKS_UNSIGNED_TYPE
147 #define LANG_HOOKS_UNSIGNED_TYPE gnat_unsigned_type
148 #undef LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE
149 #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE gnat_signed_or_unsigned_type
151 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
153 /* Tables describing GCC tree codes used only by GNAT.
155 Table indexed by tree code giving a string containing a character
156 classifying the tree code. Possibilities are
157 t, d, s, c, r, <, 1 and 2. See cp-tree.def for details. */
159 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) TYPE,
161 const char tree_code_type[] = {
164 #include "ada-tree.def"
168 /* Table indexed by tree code giving number of expression
169 operands beyond the fixed part of the node structure.
170 Not used for types or decls. */
172 #define DEFTREECODE(SYM, NAME, TYPE, LENGTH) LENGTH,
174 const unsigned char tree_code_length[] = {
177 #include "ada-tree.def"
181 /* Names of tree components.
182 Used for printing out the tree and error messages. */
183 #define DEFTREECODE(SYM, NAME, TYPE, LEN) NAME,
185 const char *const tree_code_name[] = {
188 #include "ada-tree.def"
192 /* Command-line argc and argv.
193 These variables are global, since they are imported and used in
196 unsigned int save_argc;
197 const char **save_argv;
199 /* gnat standard argc argv */
201 extern int gnat_argc;
202 extern char **gnat_argv;
205 /* Declare functions we use as part of startup. */
206 extern void __gnat_initialize (void);
207 extern void adainit (void);
208 extern void _ada_gnat1drv (void);
210 /* The parser for the language. For us, we process the GNAT tree. */
213 gnat_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
215 /* call the target specific initializations */
218 /* Call the front-end elaboration procedures */
221 immediate_size_expand = 1;
223 /* Call the front end */
227 /* Decode all the language specific options that cannot be decoded by GCC.
228 The option decoding phase of GCC calls this routine on the flags that
229 it cannot decode. This routine returns the number of consecutive arguments
230 from ARGV that it successfully decoded; 0 indicates failure. */
233 gnat_handle_option (size_t scode, const char *arg, int value ATTRIBUTE_UNUSED)
235 const struct cl_option *option = &cl_options[scode];
236 enum opt_code code = (enum opt_code) scode;
240 if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
242 error ("missing argument to \"-%s\"", option->opt_text);
252 q = xmalloc (sizeof("-I") + strlen (arg));
255 gnat_argv[gnat_argc] = q;
259 /* All front ends are expected to accept this. */
261 /* These are used in the GCC Makefile. */
262 case OPT_Wmissing_prototypes:
263 case OPT_Wstrict_prototypes:
264 case OPT_Wwrite_strings:
268 /* This is handled by the front-end. */
273 gnat_argv[gnat_argc] = xstrdup ("-nostdlib");
278 gnat_argv[gnat_argc] = xstrdup ("-fRTS");
283 warning ("`-gnat' misspelled as `-gant'");
285 /* ... fall through ... */
288 /* Recopy the switches without the 'gnat' prefix. */
289 gnat_argv[gnat_argc] = xmalloc (strlen (arg) + 2);
290 gnat_argv[gnat_argc][0] = '-';
291 strcpy (gnat_argv[gnat_argc] + 1, arg);
295 for (i = 1; i < save_argc - 1; i++)
296 if (!strncmp (save_argv[i], "-gnatO", 6))
297 if (save_argv[++i][0] != '-')
299 /* Preserve output filename as GCC doesn't save it for GNAT. */
300 gnat_argv[gnat_argc] = xstrdup (save_argv[i]);
310 /* Initialize for option processing. */
313 gnat_init_options (unsigned int argc, const char **argv)
315 /* Initialize gnat_argv with save_argv size. */
316 gnat_argv = (char **) xmalloc ((argc + 1) * sizeof (argv[0]));
317 gnat_argv[0] = xstrdup (argv[0]); /* name of the command */
326 /* Here is the function to handle the compiler error processing in GCC. */
329 internal_error_function (const char *msgid, va_list *ap)
331 char buffer[1000]; /* Assume this is big enough. */
333 String_Template temp;
336 vsprintf (buffer, msgid, *ap);
338 /* Go up to the first newline. */
339 for (p = buffer; *p != 0; p++)
346 temp.Low_Bound = 1, temp.High_Bound = strlen (buffer);
347 fp.Array = buffer, fp.Bounds = &temp;
349 Current_Error_Node = error_gnat_node;
350 Compiler_Abort (fp, -1);
353 /* Langhook for tree_size: Determine size of our 'x' and 'c' nodes. */
356 gnat_tree_size (enum tree_code code)
361 return sizeof (struct tree_loop_id);
368 /* Perform all the initialization steps that are language-specific. */
373 /* Performs whatever initialization steps needed by the language-dependent
375 gnat_init_decl_processing ();
377 /* Add the input filename as the last argument. */
378 gnat_argv[gnat_argc] = (char *) main_input_filename;
380 gnat_argv[gnat_argc] = 0;
382 global_dc->internal_error = &internal_error_function;
384 /* Show that REFERENCE_TYPEs are internal and should be Pmode. */
385 internal_reference_types ();
387 set_lang_adjust_rli (gnat_adjust_rli);
392 /* This function is called indirectly from toplev.c to handle incomplete
393 declarations, i.e. VAR_DECL nodes whose DECL_SIZE is zero. To be precise,
394 compile_file in toplev.c makes an indirect call through the function pointer
395 incomplete_decl_finalize_hook which is initialized to this routine in
396 init_decl_processing. */
399 gnat_finish_incomplete_decl (tree dont_care ATTRIBUTE_UNUSED)
404 /* Compute the alignment of the largest mode that can be used for copying
408 gnat_compute_largest_alignment (void)
410 enum machine_mode mode;
412 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
413 mode = GET_MODE_WIDER_MODE (mode))
414 if (mov_optab->handlers[(int) mode].insn_code != CODE_FOR_nothing)
415 largest_move_alignment = MIN (BIGGEST_ALIGNMENT,
416 MAX (largest_move_alignment,
417 GET_MODE_ALIGNMENT (mode)));
420 /* If we are using the GCC mechanism to process exception handling, we
421 have to register the personality routine for Ada and to initialize
422 various language dependent hooks. */
425 gnat_init_gcc_eh (void)
427 /* We shouldn't do anything if the No_Exceptions_Handler pragma is set,
428 though. This could for instance lead to the emission of tables with
429 references to symbols (such as the Ada eh personality routine) within
430 libraries we won't link against. */
431 if (No_Exception_Handlers_Set ())
434 /* Tell GCC we are handling cleanup actions through exception propagation.
435 This opens possibilities that we don't take advantage of yet, but is
436 nonetheless necessary to ensure that fixup code gets assigned to the
437 right exception regions. */
438 using_eh_for_cleanups ();
440 eh_personality_libfunc = init_one_libfunc ("__gnat_eh_personality");
441 lang_eh_type_covers = gnat_eh_type_covers;
442 lang_eh_runtime_type = gnat_eh_runtime_type;
444 /* Turn on -fexceptions and -fnon-call-exceptions. The first one triggers
445 the generation of the necessary exception runtime tables. The second one
446 is useful for two reasons: 1/ we map some asynchronous signals like SEGV
447 to exceptions, so we need to ensure that the insns which can lead to such
448 signals are correctly attached to the exception region they pertain to,
449 2/ Some calls to pure subprograms are handled as libcall blocks and then
450 marked as "cannot trap" if the flag is not set (see emit_libcall_block).
451 We should not let this be since it is possible for such calls to actually
455 flag_non_call_exceptions = 1;
458 #ifdef DWARF2_UNWIND_INFO
459 if (dwarf2out_do_frame ())
460 dwarf2out_frame_init ();
464 /* Language hooks, first one to print language-specific items in a DECL. */
467 gnat_print_decl (FILE *file, tree node, int indent)
469 switch (TREE_CODE (node))
472 print_node (file, "const_corresponding_var",
473 DECL_CONST_CORRESPONDING_VAR (node), indent + 4);
477 print_node (file, "original field", DECL_ORIGINAL_FIELD (node),
487 gnat_print_type (FILE *file, tree node, int indent)
489 switch (TREE_CODE (node))
492 print_node (file, "ci_co_list", TYPE_CI_CO_LIST (node), indent + 4);
496 print_node (file, "RM size", TYPE_RM_SIZE_ENUM (node), indent + 4);
500 if (TYPE_MODULAR_P (node))
501 print_node (file, "modulus", TYPE_MODULUS (node), indent + 4);
502 else if (TYPE_HAS_ACTUAL_BOUNDS_P (node))
503 print_node (file, "actual bounds", TYPE_ACTUAL_BOUNDS (node),
505 else if (TYPE_VAX_FLOATING_POINT_P (node))
508 print_node (file, "index type", TYPE_INDEX_TYPE (node), indent + 4);
510 print_node (file, "RM size", TYPE_RM_SIZE_INT (node), indent + 4);
514 print_node (file,"actual bounds", TYPE_ACTUAL_BOUNDS (node), indent + 4);
518 if (TYPE_IS_FAT_POINTER_P (node) || TYPE_CONTAINS_TEMPLATE_P (node))
519 print_node (file, "unconstrained array",
520 TYPE_UNCONSTRAINED_ARRAY (node), indent + 4);
522 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
526 case QUAL_UNION_TYPE:
527 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
536 gnat_printable_name (tree decl, int verbosity)
538 const char *coded_name = IDENTIFIER_POINTER (DECL_NAME (decl));
539 char *ada_name = (char *) ggc_alloc (strlen (coded_name) * 2 + 60);
541 __gnat_decode (coded_name, ada_name, 0);
545 Set_Identifier_Casing (ada_name, (char *) DECL_SOURCE_FILE (decl));
546 ada_name = Name_Buffer;
549 return (const char *) ada_name;
552 /* Expands GNAT-specific GCC tree nodes. The only ones we support
553 here are TRANSFORM_EXPR, ALLOCATE_EXPR, USE_EXPR and NULL_EXPR. */
556 gnat_expand_expr (tree exp, rtx target, enum machine_mode tmode,
557 int modifier, rtx *alt_rtl)
559 tree type = TREE_TYPE (exp);
563 /* If this is a statement, call the expansion routine for statements. */
566 gnat_expand_stmt (exp);
570 /* Update EXP to be the new expression to expand. */
571 switch (TREE_CODE (exp))
574 gnat_to_code (TREE_COMPLEXITY (exp));
579 expand_expr (TREE_OPERAND (exp, 0), const0_rtx, VOIDmode, 0);
581 /* We aren't going to be doing anything with this memory, but allocate
582 it anyway. If it's variable size, make a bogus address. */
583 if (! host_integerp (TYPE_SIZE_UNIT (type), 1))
584 result = gen_rtx_MEM (BLKmode, virtual_stack_vars_rtx);
586 result = assign_temp (type, 0, TREE_ADDRESSABLE (exp), 1);
592 allocate_dynamic_stack_space
593 (expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, TYPE_MODE (sizetype),
595 NULL_RTX, tree_low_cst (TREE_OPERAND (exp, 1), 1));
598 if (target != const0_rtx)
601 /* First write a volatile ASM_INPUT to prevent anything from being
603 result = gen_rtx_ASM_INPUT (VOIDmode, "");
604 MEM_VOLATILE_P (result) = 1;
607 result = expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, VOIDmode,
609 emit_insn (gen_rtx_USE (VOIDmode, result));
613 return expand_expr_real (build1 (NOP_EXPR, type, TREE_OPERAND (exp, 0)),
614 target, tmode, modifier, alt_rtl);
616 case UNCONSTRAINED_ARRAY_REF:
617 /* If we are evaluating just for side-effects, just evaluate our
618 operand. Otherwise, abort since this code should never appear
619 in a tree to be evaluated (objects aren't unconstrained). */
620 if (target == const0_rtx || TREE_CODE (type) == VOID_TYPE)
621 return expand_expr (TREE_OPERAND (exp, 0), const0_rtx,
624 /* ... fall through ... */
630 return expand_expr_real (new, target, tmode, modifier, alt_rtl);
633 /* Adjusts the RLI used to layout a record after all the fields have been
634 added. We only handle the packed case and cause it to use the alignment
635 that will pad the record at the end. */
638 gnat_adjust_rli (record_layout_info rli ATTRIBUTE_UNUSED)
641 /* ??? This code seems to have no actual effect; record_align should already
642 reflect the largest alignment desired by a field. jason 2003-04-01 */
643 unsigned int record_align = rli->unpadded_align;
646 /* If an alignment has been specified, don't use anything larger unless we
648 if (TYPE_ALIGN (rli->t) != 0 && TYPE_ALIGN (rli->t) < record_align)
649 record_align = MAX (rli->record_align, TYPE_ALIGN (rli->t));
651 /* If any fields have variable size, we need to force the record to be at
652 least as aligned as the alignment of that type. */
653 for (field = TYPE_FIELDS (rli->t); field; field = TREE_CHAIN (field))
654 if (TREE_CODE (DECL_SIZE_UNIT (field)) != INTEGER_CST)
655 record_align = MAX (record_align, DECL_ALIGN (field));
657 if (TYPE_PACKED (rli->t))
658 rli->record_align = record_align;
662 /* Make a TRANSFORM_EXPR to later expand GNAT_NODE into code. */
665 make_transform_expr (Node_Id gnat_node)
667 tree gnu_result = build (TRANSFORM_EXPR, void_type_node);
669 TREE_SIDE_EFFECTS (gnu_result) = 1;
670 TREE_COMPLEXITY (gnu_result) = gnat_node;
674 /* Update the setjmp buffer BUF with the current stack pointer. We assume
675 here that a __builtin_setjmp was done to BUF. */
678 update_setjmp_buf (tree buf)
680 enum machine_mode sa_mode = Pmode;
683 #ifdef HAVE_save_stack_nonlocal
684 if (HAVE_save_stack_nonlocal)
685 sa_mode = insn_data[(int) CODE_FOR_save_stack_nonlocal].operand[0].mode;
687 #ifdef STACK_SAVEAREA_MODE
688 sa_mode = STACK_SAVEAREA_MODE (SAVE_NONLOCAL);
692 = gen_rtx_MEM (sa_mode,
695 plus_constant (expand_expr
696 (build_unary_op (ADDR_EXPR, NULL_TREE, buf),
697 NULL_RTX, VOIDmode, 0),
698 2 * GET_MODE_SIZE (Pmode))));
702 emit_insn (gen_setjmp ());
705 emit_stack_save (SAVE_NONLOCAL, &stack_save, NULL_RTX);
708 /* These routines are used in conjunction with GCC exception handling. */
710 /* Map compile-time to run-time tree for GCC exception handling scheme. */
713 gnat_eh_runtime_type (tree type)
718 /* Return true if type A catches type B. Callback for flow analysis from
719 the exception handling part of the back-end. */
722 gnat_eh_type_covers (tree a, tree b)
724 /* a catches b if they represent the same exception id or if a
727 ??? integer_zero_node for "others" is hardwired in too many places
729 return (a == b || a == integer_zero_node);
732 /* See if DECL has an RTL that is indirect via a pseudo-register or a
733 memory location and replace it with an indirect reference if so.
734 This improves the debugger's ability to display the value. */
737 adjust_decl_rtl (tree decl)
741 /* If this decl is already indirect, don't do anything. This should
742 mean that the decl cannot be indirect, but there's no point in
743 adding an abort to check that. */
744 if (TREE_CODE (decl) != CONST_DECL
745 && ! DECL_BY_REF_P (decl)
746 && (GET_CODE (DECL_RTL (decl)) == MEM
747 && (GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
748 || (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG
749 && (REGNO (XEXP (DECL_RTL (decl), 0))
750 > LAST_VIRTUAL_REGISTER))))
751 /* We can't do this if the reference type's mode is not the same
752 as the current mode, which means this may not work on mixed 32/64
754 && (new_type = build_reference_type (TREE_TYPE (decl))) != 0
755 && TYPE_MODE (new_type) == GET_MODE (XEXP (DECL_RTL (decl), 0))
756 /* If this is a PARM_DECL, we can only do it if DECL_INCOMING_RTL
757 is also an indirect and of the same mode and if the object is
758 readonly, the latter condition because we don't want to upset the
759 handling of CICO_LIST. */
760 && (TREE_CODE (decl) != PARM_DECL
761 || (GET_CODE (DECL_INCOMING_RTL (decl)) == MEM
762 && (TYPE_MODE (new_type)
763 == GET_MODE (XEXP (DECL_INCOMING_RTL (decl), 0)))
764 && TREE_READONLY (decl))))
767 = build_qualified_type (new_type,
768 (TYPE_QUALS (new_type) | TYPE_QUAL_CONST));
770 DECL_POINTS_TO_READONLY_P (decl) = TREE_READONLY (decl);
771 DECL_BY_REF_P (decl) = 1;
772 SET_DECL_RTL (decl, XEXP (DECL_RTL (decl), 0));
773 TREE_TYPE (decl) = new_type;
774 DECL_MODE (decl) = TYPE_MODE (new_type);
775 DECL_ALIGN (decl) = TYPE_ALIGN (new_type);
776 DECL_SIZE (decl) = TYPE_SIZE (new_type);
778 if (TREE_CODE (decl) == PARM_DECL)
779 set_decl_incoming_rtl (decl, XEXP (DECL_INCOMING_RTL (decl), 0));
781 /* If DECL_INITIAL was set, it should be updated to show that
782 the decl is initialized to the address of that thing.
783 Otherwise, just set it to the address of this decl.
784 It needs to be set so that GCC does not think the decl is
787 = build1 (ADDR_EXPR, new_type,
788 DECL_INITIAL (decl) != 0 ? DECL_INITIAL (decl) : decl);
792 /* Record the current code position in GNAT_NODE. */
795 record_code_position (Node_Id gnat_node)
797 if (global_bindings_p ())
799 /* Make a dummy entry so multiple things at the same location don't
800 end up in the same place. */
801 add_pending_elaborations (NULL_TREE, NULL_TREE);
802 save_gnu_tree (gnat_node, get_elaboration_location (), 1);
805 /* Always emit another insn in case marking the last insn
806 addressable needs some fixups and also for above reason. */
807 save_gnu_tree (gnat_node,
808 build (RTL_EXPR, void_type_node, NULL_TREE,
809 (tree) emit_note (NOTE_INSN_DELETED), NULL_TREE),
813 /* Insert the code for GNAT_NODE at the position saved for that node. */
816 insert_code_for (Node_Id gnat_node)
818 if (global_bindings_p ())
820 push_pending_elaborations ();
821 gnat_to_code (gnat_node);
822 Check_Elaboration_Code_Allowed (gnat_node);
823 insert_elaboration_list (get_gnu_tree (gnat_node));
824 pop_pending_elaborations ();
830 do_pending_stack_adjust ();
832 mark_all_temps_used ();
833 gnat_to_code (gnat_node);
834 do_pending_stack_adjust ();
835 insns = get_insns ();
837 emit_insn_after (insns, RTL_EXPR_RTL (get_gnu_tree (gnat_node)));
841 /* Get the alias set corresponding to a type or expression. */
844 gnat_get_alias_set (tree type)
846 /* If this is a padding type, use the type of the first field. */
847 if (TREE_CODE (type) == RECORD_TYPE
848 && TYPE_IS_PADDING_P (type))
849 return get_alias_set (TREE_TYPE (TYPE_FIELDS (type)));
851 /* If the type is an unconstrained array, use the type of the
852 self-referential array we make. */
853 else if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE)
855 get_alias_set (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (type)))));
861 /* GNU_TYPE is a type. Determine if it should be passed by reference by
865 default_pass_by_ref (tree gnu_type)
869 INIT_CUMULATIVE_ARGS (cum, NULL_TREE, NULL_RTX, 0, 2);
871 /* We pass aggregates by reference if they are sufficiently large. The
872 choice of constant here is somewhat arbitrary. We also pass by
873 reference if the target machine would either pass or return by
874 reference. Strictly speaking, we need only check the return if this
875 is an In Out parameter, but it's probably best to err on the side of
876 passing more things by reference. */
878 #ifdef FUNCTION_ARG_PASS_BY_REFERENCE
879 || FUNCTION_ARG_PASS_BY_REFERENCE (cum, TYPE_MODE (gnu_type),
882 || targetm.calls.return_in_memory (gnu_type, NULL_TREE)
883 || (AGGREGATE_TYPE_P (gnu_type)
884 && (! host_integerp (TYPE_SIZE (gnu_type), 1)
885 || 0 < compare_tree_int (TYPE_SIZE (gnu_type),
886 8 * TYPE_ALIGN (gnu_type)))));
889 /* GNU_TYPE is the type of a subprogram parameter. Determine from the type if
890 it should be passed by reference. */
893 must_pass_by_ref (tree gnu_type)
895 /* We pass only unconstrained objects, those required by the language
896 to be passed by reference, and objects of variable size. The latter
897 is more efficient, avoids problems with variable size temporaries,
898 and does not produce compatibility problems with C, since C does
899 not have such objects. */
900 return (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE
901 || (AGGREGATE_TYPE_P (gnu_type) && TYPE_BY_REFERENCE_P (gnu_type))
902 || (TYPE_SIZE (gnu_type) != 0
903 && TREE_CODE (TYPE_SIZE (gnu_type)) != INTEGER_CST));
906 /* This function is called by the front end to enumerate all the supported
907 modes for the machine. We pass a function which is called back with
908 the following integer parameters:
910 FLOAT_P nonzero if this represents a floating-point mode
911 COMPLEX_P nonzero is this represents a complex mode
912 COUNT count of number of items, nonzero for vector mode
913 PRECISION number of bits in data representation
914 MANTISSA number of bits in mantissa, if FP and known, else zero.
915 SIZE number of bits used to store data
916 ALIGN number of bits to which mode is aligned. */
919 enumerate_modes (void (*f) (int, int, int, int, int, int, unsigned int))
923 for (i = 0; i < NUM_MACHINE_MODES; i++)
931 enum machine_mode inner_mode = i;
933 switch (GET_MODE_CLASS (i))
940 case MODE_COMPLEX_INT:
942 inner_mode = GET_MODE_INNER (i);
944 case MODE_COMPLEX_FLOAT:
947 inner_mode = GET_MODE_INNER (i);
949 case MODE_VECTOR_INT:
951 inner_mode = GET_MODE_INNER (i);
953 case MODE_VECTOR_FLOAT:
956 inner_mode = GET_MODE_INNER (i);
962 /* Skip this mode if it's one the front end doesn't need to know about
963 (e.g., the CC modes) or if there is no add insn for that mode (or
964 any wider mode), meaning it is not supported by the hardware. If
965 this a complex or vector mode, we care about the inner mode. */
966 for (j = inner_mode; j != VOIDmode; j = GET_MODE_WIDER_MODE (j))
967 if (add_optab->handlers[j].insn_code != CODE_FOR_nothing)
972 const struct real_format *fmt = REAL_MODE_FORMAT (inner_mode);
974 mantissa = fmt->p * fmt->log2_b;
977 if (!skip_p && j != VOIDmode)
978 (*f) (float_p, complex_p, vector_p ? GET_MODE_NUNITS (i) : 0,
979 GET_MODE_BITSIZE (i), mantissa,
980 GET_MODE_SIZE (i) * BITS_PER_UNIT, GET_MODE_ALIGNMENT (i));
985 fp_prec_to_size (int prec)
987 enum machine_mode mode;
989 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
990 mode = GET_MODE_WIDER_MODE (mode))
991 if (GET_MODE_PRECISION (mode) == prec)
992 return GET_MODE_BITSIZE (mode);
998 fp_size_to_prec (int size)
1000 enum machine_mode mode;
1002 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
1003 mode = GET_MODE_WIDER_MODE (mode))
1004 if (GET_MODE_BITSIZE (mode) == size)
1005 return GET_MODE_PRECISION (mode);