* gcc-interface/gigi.h (ref_filename): Delete.
[official-gcc.git] / gcc / ada / gcc-interface / misc.c
blob9d8d2621c45d521fa1b62297b9b6cf35ae35cd60
1 /****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * M I S C *
6 * *
7 * C Implementation File *
8 * *
9 * Copyright (C) 1992-2015, Free Software Foundation, Inc. *
10 * *
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 3, 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 COPYING3. If not see *
19 * <http://www.gnu.org/licenses/>. *
20 * *
21 * GNAT was originally developed by the GNAT team at New York University. *
22 * Extensive contributions were provided by Ada Core Technologies Inc. *
23 * *
24 ****************************************************************************/
26 #include "config.h"
27 #include "system.h"
28 #include "coretypes.h"
29 #include "opts.h"
30 #include "options.h"
31 #include "tm.h"
32 #include "vec.h"
33 #include "alias.h"
34 #include "tree.h"
35 #include "inchash.h"
36 #include "fold-const.h"
37 #include "stor-layout.h"
38 #include "print-tree.h"
39 #include "diagnostic.h"
40 #include "target.h"
41 #include "ggc.h"
42 #include "flags.h"
43 #include "debug.h"
44 #include "toplev.h"
45 #include "langhooks.h"
46 #include "langhooks-def.h"
47 #include "plugin.h"
48 #include "hashtab.h"
49 #include "hard-reg-set.h"
50 #include "calls.h" /* For pass_by_reference. */
51 #include "dwarf2out.h"
53 #include "ada.h"
54 #include "adadecode.h"
55 #include "types.h"
56 #include "atree.h"
57 #include "elists.h"
58 #include "namet.h"
59 #include "nlists.h"
60 #include "stringt.h"
61 #include "uintp.h"
62 #include "fe.h"
63 #include "sinfo.h"
64 #include "einfo.h"
65 #include "ada-tree.h"
66 #include "gigi.h"
68 /* This symbol needs to be defined for the front-end. */
69 void *callgraph_info_file = NULL;
71 /* Command-line argc and argv. These variables are global since they are
72 imported in back_end.adb. */
73 unsigned int save_argc;
74 const char **save_argv;
76 /* GNAT argc and argv. */
77 extern int gnat_argc;
78 extern char **gnat_argv;
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
84 /* Declare functions we use as part of startup. */
85 extern void __gnat_initialize (void *);
86 extern void __gnat_install_SEH_handler (void *);
87 extern void adainit (void);
88 extern void _ada_gnat1drv (void);
90 #ifdef __cplusplus
92 #endif
94 /* The parser for the language. For us, we process the GNAT tree. */
96 static void
97 gnat_parse_file (void)
99 int seh[2];
101 /* Call the target specific initializations. */
102 __gnat_initialize (NULL);
104 /* ??? Call the SEH initialization routine. This is to workaround
105 a bootstrap path problem. The call below should be removed at some
106 point and the SEH pointer passed to __gnat_initialize() above. */
107 __gnat_install_SEH_handler((void *)seh);
109 /* Call the front-end elaboration procedures. */
110 adainit ();
112 /* Call the front end. */
113 _ada_gnat1drv ();
115 /* Write the global declarations. */
116 gnat_write_global_declarations ();
119 /* Return language mask for option processing. */
121 static unsigned int
122 gnat_option_lang_mask (void)
124 return CL_Ada;
127 /* Decode all the language specific options that cannot be decoded by GCC.
128 The option decoding phase of GCC calls this routine on the flags that
129 are marked as Ada-specific. Return true on success or false on failure. */
131 static bool
132 gnat_handle_option (size_t scode, const char *arg ATTRIBUTE_UNUSED, int value,
133 int kind ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED,
134 const struct cl_option_handlers *handlers ATTRIBUTE_UNUSED)
136 enum opt_code code = (enum opt_code) scode;
138 switch (code)
140 case OPT_Wall:
141 handle_generated_option (&global_options, &global_options_set,
142 OPT_Wunused, NULL, value,
143 gnat_option_lang_mask (), kind, loc,
144 handlers, global_dc);
145 warn_uninitialized = value;
146 warn_maybe_uninitialized = value;
147 break;
149 case OPT_gant:
150 warning (0, "%<-gnat%> misspelled as %<-gant%>");
152 /* ... fall through ... */
154 case OPT_gnat:
155 case OPT_gnatO:
156 case OPT_fRTS_:
157 case OPT_I:
158 case OPT_nostdinc:
159 case OPT_nostdlib:
160 /* These are handled by the front-end. */
161 break;
163 case OPT_fshort_enums:
164 /* This is handled by the middle-end. */
165 break;
167 default:
168 gcc_unreachable ();
171 Ada_handle_option_auto (&global_options, &global_options_set,
172 scode, arg, value,
173 gnat_option_lang_mask (), kind,
174 loc, handlers, global_dc);
175 return true;
178 /* Initialize options structure OPTS. */
180 static void
181 gnat_init_options_struct (struct gcc_options *opts)
183 /* Uninitialized really means uninitialized in Ada. */
184 opts->x_flag_zero_initialized_in_bss = 0;
186 /* We don't care about errno in Ada and it causes __builtin_sqrt to
187 call the libm function rather than do it inline. */
188 opts->x_flag_errno_math = 0;
189 opts->frontend_set_flag_errno_math = true;
192 /* Initialize for option processing. */
194 static void
195 gnat_init_options (unsigned int decoded_options_count,
196 struct cl_decoded_option *decoded_options)
198 /* Reconstruct an argv array for use of back_end.adb.
200 ??? back_end.adb should not rely on this; instead, it should work with
201 decoded options without such reparsing, to ensure consistency in how
202 options are decoded. */
203 unsigned int i;
205 save_argv = XNEWVEC (const char *, 2 * decoded_options_count + 1);
206 save_argc = 0;
207 for (i = 0; i < decoded_options_count; i++)
209 size_t num_elements = decoded_options[i].canonical_option_num_elements;
211 if (decoded_options[i].errors
212 || decoded_options[i].opt_index == OPT_SPECIAL_unknown
213 || num_elements == 0)
214 continue;
216 /* Deal with -I- specially since it must be a single switch. */
217 if (decoded_options[i].opt_index == OPT_I
218 && num_elements == 2
219 && decoded_options[i].canonical_option[1][0] == '-'
220 && decoded_options[i].canonical_option[1][1] == '\0')
221 save_argv[save_argc++] = "-I-";
222 else
224 gcc_assert (num_elements >= 1 && num_elements <= 2);
225 save_argv[save_argc++] = decoded_options[i].canonical_option[0];
226 if (num_elements >= 2)
227 save_argv[save_argc++] = decoded_options[i].canonical_option[1];
230 save_argv[save_argc] = NULL;
232 gnat_argv = (char **) xmalloc (sizeof (save_argv[0]));
233 gnat_argv[0] = xstrdup (save_argv[0]); /* name of the command */
234 gnat_argc = 1;
237 /* Ada code requires variables for these settings rather than elements
238 of the global_options structure. */
239 #undef optimize
240 #undef optimize_size
241 #undef flag_compare_debug
242 #undef flag_short_enums
243 #undef flag_stack_check
244 int gnat_encodings = 0;
245 int optimize;
246 int optimize_size;
247 int flag_compare_debug;
248 int flag_short_enums;
249 enum stack_check_type flag_stack_check = NO_STACK_CHECK;
251 /* Settings adjustments after switches processing by the back-end.
252 Note that the front-end switches processing (Scan_Compiler_Arguments)
253 has not been done yet at this point! */
255 static bool
256 gnat_post_options (const char **pfilename ATTRIBUTE_UNUSED)
258 /* Excess precision other than "fast" requires front-end support. */
259 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
260 && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
261 sorry ("-fexcess-precision=standard for Ada");
262 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
264 /* No psABI change warnings for Ada. */
265 warn_psabi = 0;
267 /* No caret by default for Ada. */
268 if (!global_options_set.x_flag_diagnostics_show_caret)
269 global_dc->show_caret = false;
271 optimize = global_options.x_optimize;
272 optimize_size = global_options.x_optimize_size;
273 flag_compare_debug = global_options.x_flag_compare_debug;
274 flag_stack_check = global_options.x_flag_stack_check;
275 flag_short_enums = global_options.x_flag_short_enums;
277 /* Unfortunately the post_options hook is called before the value of
278 flag_short_enums is autodetected, if need be. Mimic the process
279 for our private flag_short_enums. */
280 if (flag_short_enums == 2)
281 flag_short_enums = targetm.default_short_enums ();
283 return false;
286 /* Here is the function to handle the compiler error processing in GCC. */
288 static void
289 internal_error_function (diagnostic_context *context,
290 const char *msgid, va_list *ap)
292 text_info tinfo;
293 char *buffer, *p, *loc;
294 String_Template temp, temp_loc;
295 String_Pointer sp, sp_loc;
296 expanded_location xloc;
298 /* Warn if plugins present. */
299 warn_if_plugins ();
301 /* Reset the pretty-printer. */
302 pp_clear_output_area (context->printer);
304 /* Format the message into the pretty-printer. */
305 tinfo.format_spec = msgid;
306 tinfo.args_ptr = ap;
307 tinfo.err_no = errno;
308 pp_format_verbatim (context->printer, &tinfo);
310 /* Extract a (writable) pointer to the formatted text. */
311 buffer = xstrdup (pp_formatted_text (context->printer));
313 /* Go up to the first newline. */
314 for (p = buffer; *p; p++)
315 if (*p == '\n')
317 *p = '\0';
318 break;
321 temp.Low_Bound = 1;
322 temp.High_Bound = p - buffer;
323 sp.Bounds = &temp;
324 sp.Array = buffer;
326 xloc = expand_location (input_location);
327 if (context->show_column && xloc.column != 0)
328 loc = xasprintf ("%s:%d:%d", xloc.file, xloc.line, xloc.column);
329 else
330 loc = xasprintf ("%s:%d", xloc.file, xloc.line);
331 temp_loc.Low_Bound = 1;
332 temp_loc.High_Bound = strlen (loc);
333 sp_loc.Bounds = &temp_loc;
334 sp_loc.Array = loc;
336 Current_Error_Node = error_gnat_node;
337 Compiler_Abort (sp, sp_loc, true);
340 /* Perform all the initialization steps that are language-specific. */
342 static bool
343 gnat_init (void)
345 /* Do little here, most of the standard declarations are set up after the
346 front-end has been run. Use the same `char' as C, this doesn't really
347 matter since we'll use the explicit `unsigned char' for Character. */
348 build_common_tree_nodes (flag_signed_char, false);
350 /* In Ada, we use an unsigned 8-bit type for the default boolean type. */
351 boolean_type_node = make_unsigned_type (8);
352 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
353 SET_TYPE_RM_MAX_VALUE (boolean_type_node,
354 build_int_cst (boolean_type_node, 1));
355 SET_TYPE_RM_SIZE (boolean_type_node, bitsize_int (1));
356 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
357 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
359 sbitsize_one_node = sbitsize_int (1);
360 sbitsize_unit_node = sbitsize_int (BITS_PER_UNIT);
362 /* Show that REFERENCE_TYPEs are internal and should be Pmode. */
363 internal_reference_types ();
365 /* Register our internal error function. */
366 global_dc->internal_error = &internal_error_function;
368 return true;
371 /* Initialize the GCC support for exception handling. */
373 void
374 gnat_init_gcc_eh (void)
376 /* We shouldn't do anything if the No_Exceptions_Handler pragma is set,
377 though. This could for instance lead to the emission of tables with
378 references to symbols (such as the Ada eh personality routine) within
379 libraries we won't link against. */
380 if (No_Exception_Handlers_Set ())
381 return;
383 /* Tell GCC we are handling cleanup actions through exception propagation.
384 This opens possibilities that we don't take advantage of yet, but is
385 nonetheless necessary to ensure that fixup code gets assigned to the
386 right exception regions. */
387 using_eh_for_cleanups ();
389 /* Turn on -fexceptions, -fnon-call-exceptions and -fdelete-dead-exceptions.
390 The first one triggers the generation of the necessary exception tables.
391 The second one is useful for two reasons: 1/ we map some asynchronous
392 signals like SEGV to exceptions, so we need to ensure that the insns
393 which can lead to such signals are correctly attached to the exception
394 region they pertain to, 2/ some calls to pure subprograms are handled as
395 libcall blocks and then marked as "cannot trap" if the flag is not set
396 (see emit_libcall_block). We should not let this be since it is possible
397 for such calls to actually raise in Ada.
398 The third one is an optimization that makes it possible to delete dead
399 instructions that may throw exceptions, most notably loads and stores,
400 as permitted in Ada. */
401 flag_exceptions = 1;
402 flag_non_call_exceptions = 1;
403 flag_delete_dead_exceptions = 1;
405 init_eh ();
408 /* Initialize the GCC support for floating-point operations. */
410 void
411 gnat_init_gcc_fp (void)
413 /* Disable FP optimizations that ignore the signedness of zero if
414 S'Signed_Zeros is true, but don't override the user if not. */
415 if (Signed_Zeros_On_Target)
416 flag_signed_zeros = 1;
417 else if (!global_options_set.x_flag_signed_zeros)
418 flag_signed_zeros = 0;
420 /* Assume that FP operations can trap if S'Machine_Overflow is true,
421 but don't override the user if not. */
422 if (Machine_Overflows_On_Target)
423 flag_trapping_math = 1;
424 else if (!global_options_set.x_flag_trapping_math)
425 flag_trapping_math = 0;
428 /* Print language-specific items in declaration NODE. */
430 static void
431 gnat_print_decl (FILE *file, tree node, int indent)
433 switch (TREE_CODE (node))
435 case CONST_DECL:
436 print_node (file, "corresponding var",
437 DECL_CONST_CORRESPONDING_VAR (node), indent + 4);
438 break;
440 case FIELD_DECL:
441 print_node (file, "original field", DECL_ORIGINAL_FIELD (node),
442 indent + 4);
443 break;
445 case VAR_DECL:
446 if (DECL_LOOP_PARM_P (node))
447 print_node (file, "induction var", DECL_INDUCTION_VAR (node),
448 indent + 4);
449 else
450 print_node (file, "renamed object", DECL_RENAMED_OBJECT (node),
451 indent + 4);
452 break;
454 default:
455 break;
459 /* Print language-specific items in type NODE. */
461 static void
462 gnat_print_type (FILE *file, tree node, int indent)
464 switch (TREE_CODE (node))
466 case FUNCTION_TYPE:
467 print_node (file, "ci/co list", TYPE_CI_CO_LIST (node), indent + 4);
468 break;
470 case INTEGER_TYPE:
471 if (TYPE_MODULAR_P (node))
472 print_node_brief (file, "modulus", TYPE_MODULUS (node), indent + 4);
473 else if (TYPE_HAS_ACTUAL_BOUNDS_P (node))
474 print_node (file, "actual bounds", TYPE_ACTUAL_BOUNDS (node),
475 indent + 4);
476 else
477 print_node (file, "index type", TYPE_INDEX_TYPE (node), indent + 4);
479 /* ... fall through ... */
481 case ENUMERAL_TYPE:
482 case BOOLEAN_TYPE:
483 print_node_brief (file, "RM size", TYPE_RM_SIZE (node), indent + 4);
485 /* ... fall through ... */
487 case REAL_TYPE:
488 print_node_brief (file, "RM min", TYPE_RM_MIN_VALUE (node), indent + 4);
489 print_node_brief (file, "RM max", TYPE_RM_MAX_VALUE (node), indent + 4);
490 break;
492 case ARRAY_TYPE:
493 print_node (file,"actual bounds", TYPE_ACTUAL_BOUNDS (node), indent + 4);
494 break;
496 case VECTOR_TYPE:
497 print_node (file,"representative array",
498 TYPE_REPRESENTATIVE_ARRAY (node), indent + 4);
499 break;
501 case RECORD_TYPE:
502 if (TYPE_FAT_POINTER_P (node) || TYPE_CONTAINS_TEMPLATE_P (node))
503 print_node (file, "unconstrained array",
504 TYPE_UNCONSTRAINED_ARRAY (node), indent + 4);
505 else
506 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
507 break;
509 case UNION_TYPE:
510 case QUAL_UNION_TYPE:
511 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
512 break;
514 default:
515 break;
519 /* Return the name to be printed for DECL. */
521 static const char *
522 gnat_printable_name (tree decl, int verbosity)
524 const char *coded_name = IDENTIFIER_POINTER (DECL_NAME (decl));
525 char *ada_name = (char *) ggc_alloc_atomic (strlen (coded_name) * 2 + 60);
527 __gnat_decode (coded_name, ada_name, 0);
529 if (verbosity == 2 && !DECL_IS_BUILTIN (decl))
531 Set_Identifier_Casing (ada_name, DECL_SOURCE_FILE (decl));
532 return ggc_strdup (Name_Buffer);
535 return ada_name;
538 /* Return the name to be used in DWARF debug info for DECL. */
540 static const char *
541 gnat_dwarf_name (tree decl, int verbosity ATTRIBUTE_UNUSED)
543 gcc_assert (DECL_P (decl));
544 return (const char *) IDENTIFIER_POINTER (DECL_NAME (decl));
547 /* Return the descriptive type associated with TYPE, if any. */
549 static tree
550 gnat_descriptive_type (const_tree type)
552 if (TYPE_STUB_DECL (type))
553 return DECL_PARALLEL_TYPE (TYPE_STUB_DECL (type));
554 else
555 return NULL_TREE;
558 /* Return true if types T1 and T2 are identical for type hashing purposes.
559 Called only after doing all language independent checks. At present,
560 this function is only called when both types are FUNCTION_TYPE. */
562 static bool
563 gnat_type_hash_eq (const_tree t1, const_tree t2)
565 gcc_assert (TREE_CODE (t1) == FUNCTION_TYPE);
566 return fntype_same_flags_p (t1, TYPE_CI_CO_LIST (t2),
567 TYPE_RETURN_UNCONSTRAINED_P (t2),
568 TYPE_RETURN_BY_DIRECT_REF_P (t2),
569 TREE_ADDRESSABLE (t2));
572 /* Do nothing (return the tree node passed). */
574 static tree
575 gnat_return_tree (tree t)
577 return t;
580 /* Get the alias set corresponding to a type or expression. */
582 static alias_set_type
583 gnat_get_alias_set (tree type)
585 /* If this is a padding type, use the type of the first field. */
586 if (TYPE_IS_PADDING_P (type))
587 return get_alias_set (TREE_TYPE (TYPE_FIELDS (type)));
589 /* If the type is an unconstrained array, use the type of the
590 self-referential array we make. */
591 else if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE)
592 return
593 get_alias_set (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (type)))));
595 /* If the type can alias any other types, return the alias set 0. */
596 else if (TYPE_P (type) && TYPE_UNIVERSAL_ALIASING_P (type))
597 return 0;
599 return -1;
602 /* GNU_TYPE is a type. Return its maximum size in bytes, if known,
603 as a constant when possible. */
605 static tree
606 gnat_type_max_size (const_tree gnu_type)
608 /* First see what we can get from TYPE_SIZE_UNIT, which might not
609 be constant even for simple expressions if it has already been
610 elaborated and possibly replaced by a VAR_DECL. */
611 tree max_unitsize = max_size (TYPE_SIZE_UNIT (gnu_type), true);
613 /* If we don't have a constant, see what we can get from TYPE_ADA_SIZE,
614 which should stay untouched. */
615 if (!tree_fits_uhwi_p (max_unitsize)
616 && RECORD_OR_UNION_TYPE_P (gnu_type)
617 && !TYPE_FAT_POINTER_P (gnu_type)
618 && TYPE_ADA_SIZE (gnu_type))
620 tree max_adasize = max_size (TYPE_ADA_SIZE (gnu_type), true);
622 /* If we have succeeded in finding a constant, round it up to the
623 type's alignment and return the result in units. */
624 if (tree_fits_uhwi_p (max_adasize))
625 max_unitsize
626 = size_binop (CEIL_DIV_EXPR,
627 round_up (max_adasize, TYPE_ALIGN (gnu_type)),
628 bitsize_unit_node);
631 return max_unitsize;
634 /* Provide information in INFO for debug output about the TYPE array type.
635 Return whether TYPE is handled. */
637 static bool
638 gnat_get_array_descr_info (const_tree type, struct array_descr_info *info)
640 bool convention_fortran_p;
641 tree index_type;
643 const_tree dimen = NULL_TREE;
644 const_tree last_dimen = NULL_TREE;
645 int i;
647 if (TREE_CODE (type) != ARRAY_TYPE
648 || !TYPE_DOMAIN (type)
649 || !TYPE_INDEX_TYPE (TYPE_DOMAIN (type)))
650 return false;
652 /* Count how many dimentions this array has. */
653 for (i = 0, dimen = type; ; ++i, dimen = TREE_TYPE (dimen))
654 if (i > 0
655 && (TREE_CODE (dimen) != ARRAY_TYPE
656 || !TYPE_MULTI_ARRAY_P (dimen)))
657 break;
658 info->ndimensions = i;
659 convention_fortran_p = TYPE_CONVENTION_FORTRAN_P (type);
661 /* TODO: for row major ordering, we probably want to emit nothing and
662 instead specify it as the default in Dw_TAG_compile_unit. */
663 info->ordering = (convention_fortran_p
664 ? array_descr_ordering_column_major
665 : array_descr_ordering_row_major);
666 info->base_decl = NULL_TREE;
667 info->data_location = NULL_TREE;
668 info->allocated = NULL_TREE;
669 info->associated = NULL_TREE;
671 for (i = (convention_fortran_p ? info->ndimensions - 1 : 0),
672 dimen = type;
674 0 <= i && i < info->ndimensions;
676 i += (convention_fortran_p ? -1 : 1),
677 dimen = TREE_TYPE (dimen))
679 /* We are interested in the stored bounds for the debug info. */
680 index_type = TYPE_INDEX_TYPE (TYPE_DOMAIN (dimen));
682 info->dimen[i].bounds_type = index_type;
683 info->dimen[i].lower_bound = TYPE_MIN_VALUE (index_type);
684 info->dimen[i].upper_bound = TYPE_MAX_VALUE (index_type);
685 last_dimen = dimen;
688 info->element_type = TREE_TYPE (last_dimen);
690 return true;
693 /* GNU_TYPE is a subtype of an integral type. Set LOWVAL to the low bound
694 and HIGHVAL to the high bound, respectively. */
696 static void
697 gnat_get_subrange_bounds (const_tree gnu_type, tree *lowval, tree *highval)
699 *lowval = TYPE_MIN_VALUE (gnu_type);
700 *highval = TYPE_MAX_VALUE (gnu_type);
703 /* GNU_TYPE is the type of a subprogram parameter. Determine if it should be
704 passed by reference by default. */
706 bool
707 default_pass_by_ref (tree gnu_type)
709 /* We pass aggregates by reference if they are sufficiently large for
710 their alignment. The ratio is somewhat arbitrary. We also pass by
711 reference if the target machine would either pass or return by
712 reference. Strictly speaking, we need only check the return if this
713 is an In Out parameter, but it's probably best to err on the side of
714 passing more things by reference. */
716 if (pass_by_reference (NULL, TYPE_MODE (gnu_type), gnu_type, true))
717 return true;
719 if (targetm.calls.return_in_memory (gnu_type, NULL_TREE))
720 return true;
722 if (AGGREGATE_TYPE_P (gnu_type)
723 && (!valid_constant_size_p (TYPE_SIZE_UNIT (gnu_type))
724 || 0 < compare_tree_int (TYPE_SIZE_UNIT (gnu_type),
725 TYPE_ALIGN (gnu_type))))
726 return true;
728 return false;
731 /* GNU_TYPE is the type of a subprogram parameter. Determine if it must be
732 passed by reference. */
734 bool
735 must_pass_by_ref (tree gnu_type)
737 /* We pass only unconstrained objects, those required by the language
738 to be passed by reference, and objects of variable size. The latter
739 is more efficient, avoids problems with variable size temporaries,
740 and does not produce compatibility problems with C, since C does
741 not have such objects. */
742 return (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE
743 || TYPE_IS_BY_REFERENCE_P (gnu_type)
744 || (TYPE_SIZE_UNIT (gnu_type)
745 && TREE_CODE (TYPE_SIZE_UNIT (gnu_type)) != INTEGER_CST));
748 /* This function is called by the front-end to enumerate all the supported
749 modes for the machine, as well as some predefined C types. F is a function
750 which is called back with the parameters as listed below, first a string,
751 then seven ints. The name is any arbitrary null-terminated string and has
752 no particular significance, except for the case of predefined C types, where
753 it should be the name of the C type. For integer types, only signed types
754 should be listed, unsigned versions are assumed. The order of types should
755 be in order of preference, with the smallest/cheapest types first.
757 In particular, C predefined types should be listed before other types,
758 binary floating point types before decimal ones, and narrower/cheaper
759 type versions before more expensive ones. In type selection the first
760 matching variant will be used.
762 NAME pointer to first char of type name
763 DIGS number of decimal digits for floating-point modes, else 0
764 COMPLEX_P nonzero is this represents a complex mode
765 COUNT count of number of items, nonzero for vector mode
766 FLOAT_REP Float_Rep_Kind for FP, otherwise undefined
767 PRECISION number of bits used to store data
768 SIZE number of bits occupied by the mode
769 ALIGN number of bits to which mode is aligned. */
771 void
772 enumerate_modes (void (*f) (const char *, int, int, int, int, int, int, int))
774 const tree c_types[]
775 = { float_type_node, double_type_node, long_double_type_node };
776 const char *const c_names[]
777 = { "float", "double", "long double" };
778 int iloop;
780 /* We are going to compute it below. */
781 fp_arith_may_widen = false;
783 for (iloop = 0; iloop < NUM_MACHINE_MODES; iloop++)
785 machine_mode i = (machine_mode) iloop;
786 machine_mode inner_mode = i;
787 bool float_p = false;
788 bool complex_p = false;
789 bool vector_p = false;
790 bool skip_p = false;
791 int digs = 0;
792 unsigned int nameloop;
793 Float_Rep_Kind float_rep = IEEE_Binary; /* Until proven otherwise */
795 switch (GET_MODE_CLASS (i))
797 case MODE_INT:
798 break;
799 case MODE_FLOAT:
800 float_p = true;
801 break;
802 case MODE_COMPLEX_INT:
803 complex_p = true;
804 inner_mode = GET_MODE_INNER (i);
805 break;
806 case MODE_COMPLEX_FLOAT:
807 float_p = true;
808 complex_p = true;
809 inner_mode = GET_MODE_INNER (i);
810 break;
811 case MODE_VECTOR_INT:
812 vector_p = true;
813 inner_mode = GET_MODE_INNER (i);
814 break;
815 case MODE_VECTOR_FLOAT:
816 float_p = true;
817 vector_p = true;
818 inner_mode = GET_MODE_INNER (i);
819 break;
820 default:
821 skip_p = true;
824 if (float_p)
826 const struct real_format *fmt = REAL_MODE_FORMAT (inner_mode);
828 /* ??? Cope with the ghost XFmode of the ARM port. */
829 if (!fmt)
830 continue;
832 /* Be conservative and consider that floating-point arithmetics may
833 use wider intermediate results as soon as there is an extended
834 Motorola or Intel mode supported by the machine. */
835 if (fmt == &ieee_extended_motorola_format
836 || fmt == &ieee_extended_intel_96_format
837 || fmt == &ieee_extended_intel_96_round_53_format
838 || fmt == &ieee_extended_intel_128_format)
840 #ifdef TARGET_FPMATH_DEFAULT
841 if (TARGET_FPMATH_DEFAULT == FPMATH_387)
842 #endif
843 fp_arith_may_widen = true;
846 if (fmt->b == 2)
847 digs = (fmt->p - 1) * 1233 / 4096; /* scale by log (2) */
849 else if (fmt->b == 10)
850 digs = fmt->p;
852 else
853 gcc_unreachable();
856 /* First register any C types for this mode that the front end
857 may need to know about, unless the mode should be skipped. */
858 if (!skip_p && !vector_p)
859 for (nameloop = 0; nameloop < ARRAY_SIZE (c_types); nameloop++)
861 tree type = c_types[nameloop];
862 const char *name = c_names[nameloop];
864 if (TYPE_MODE (type) == i)
866 f (name, digs, complex_p, 0, float_rep, TYPE_PRECISION (type),
867 TREE_INT_CST_LOW (TYPE_SIZE (type)), TYPE_ALIGN (type));
868 skip_p = true;
872 /* If no predefined C types were found, register the mode itself. */
873 if (!skip_p)
874 f (GET_MODE_NAME (i), digs, complex_p,
875 vector_p ? GET_MODE_NUNITS (i) : 0, float_rep,
876 GET_MODE_PRECISION (i), GET_MODE_BITSIZE (i),
877 GET_MODE_ALIGNMENT (i));
881 /* Return the size of the FP mode with precision PREC. */
884 fp_prec_to_size (int prec)
886 machine_mode mode;
888 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
889 mode = GET_MODE_WIDER_MODE (mode))
890 if (GET_MODE_PRECISION (mode) == prec)
891 return GET_MODE_BITSIZE (mode);
893 gcc_unreachable ();
896 /* Return the precision of the FP mode with size SIZE. */
899 fp_size_to_prec (int size)
901 machine_mode mode;
903 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
904 mode = GET_MODE_WIDER_MODE (mode))
905 if (GET_MODE_BITSIZE (mode) == size)
906 return GET_MODE_PRECISION (mode);
908 gcc_unreachable ();
911 static GTY(()) tree gnat_eh_personality_decl;
913 /* Return the GNAT personality function decl. */
915 static tree
916 gnat_eh_personality (void)
918 if (!gnat_eh_personality_decl)
919 gnat_eh_personality_decl = build_personality_function ("gnat");
920 return gnat_eh_personality_decl;
923 /* Initialize language-specific bits of tree_contains_struct. */
925 static void
926 gnat_init_ts (void)
928 MARK_TS_COMMON (UNCONSTRAINED_ARRAY_TYPE);
930 MARK_TS_TYPED (UNCONSTRAINED_ARRAY_REF);
931 MARK_TS_TYPED (NULL_EXPR);
932 MARK_TS_TYPED (PLUS_NOMOD_EXPR);
933 MARK_TS_TYPED (MINUS_NOMOD_EXPR);
934 MARK_TS_TYPED (ATTR_ADDR_EXPR);
935 MARK_TS_TYPED (STMT_STMT);
936 MARK_TS_TYPED (LOOP_STMT);
937 MARK_TS_TYPED (EXIT_STMT);
940 /* Definitions for our language-specific hooks. */
942 #undef LANG_HOOKS_NAME
943 #define LANG_HOOKS_NAME "GNU Ada"
944 #undef LANG_HOOKS_IDENTIFIER_SIZE
945 #define LANG_HOOKS_IDENTIFIER_SIZE sizeof (struct tree_identifier)
946 #undef LANG_HOOKS_INIT
947 #define LANG_HOOKS_INIT gnat_init
948 #undef LANG_HOOKS_OPTION_LANG_MASK
949 #define LANG_HOOKS_OPTION_LANG_MASK gnat_option_lang_mask
950 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
951 #define LANG_HOOKS_INIT_OPTIONS_STRUCT gnat_init_options_struct
952 #undef LANG_HOOKS_INIT_OPTIONS
953 #define LANG_HOOKS_INIT_OPTIONS gnat_init_options
954 #undef LANG_HOOKS_HANDLE_OPTION
955 #define LANG_HOOKS_HANDLE_OPTION gnat_handle_option
956 #undef LANG_HOOKS_POST_OPTIONS
957 #define LANG_HOOKS_POST_OPTIONS gnat_post_options
958 #undef LANG_HOOKS_PARSE_FILE
959 #define LANG_HOOKS_PARSE_FILE gnat_parse_file
960 #undef LANG_HOOKS_TYPE_HASH_EQ
961 #define LANG_HOOKS_TYPE_HASH_EQ gnat_type_hash_eq
962 #undef LANG_HOOKS_GETDECLS
963 #define LANG_HOOKS_GETDECLS lhd_return_null_tree_v
964 #undef LANG_HOOKS_PUSHDECL
965 #define LANG_HOOKS_PUSHDECL gnat_return_tree
966 #undef LANG_HOOKS_GET_ALIAS_SET
967 #define LANG_HOOKS_GET_ALIAS_SET gnat_get_alias_set
968 #undef LANG_HOOKS_PRINT_DECL
969 #define LANG_HOOKS_PRINT_DECL gnat_print_decl
970 #undef LANG_HOOKS_PRINT_TYPE
971 #define LANG_HOOKS_PRINT_TYPE gnat_print_type
972 #undef LANG_HOOKS_TYPE_MAX_SIZE
973 #define LANG_HOOKS_TYPE_MAX_SIZE gnat_type_max_size
974 #undef LANG_HOOKS_DECL_PRINTABLE_NAME
975 #define LANG_HOOKS_DECL_PRINTABLE_NAME gnat_printable_name
976 #undef LANG_HOOKS_DWARF_NAME
977 #define LANG_HOOKS_DWARF_NAME gnat_dwarf_name
978 #undef LANG_HOOKS_GIMPLIFY_EXPR
979 #define LANG_HOOKS_GIMPLIFY_EXPR gnat_gimplify_expr
980 #undef LANG_HOOKS_TYPE_FOR_MODE
981 #define LANG_HOOKS_TYPE_FOR_MODE gnat_type_for_mode
982 #undef LANG_HOOKS_TYPE_FOR_SIZE
983 #define LANG_HOOKS_TYPE_FOR_SIZE gnat_type_for_size
984 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
985 #define LANG_HOOKS_TYPES_COMPATIBLE_P gnat_types_compatible_p
986 #undef LANG_HOOKS_GET_ARRAY_DESCR_INFO
987 #define LANG_HOOKS_GET_ARRAY_DESCR_INFO gnat_get_array_descr_info
988 #undef LANG_HOOKS_GET_SUBRANGE_BOUNDS
989 #define LANG_HOOKS_GET_SUBRANGE_BOUNDS gnat_get_subrange_bounds
990 #undef LANG_HOOKS_DESCRIPTIVE_TYPE
991 #define LANG_HOOKS_DESCRIPTIVE_TYPE gnat_descriptive_type
992 #undef LANG_HOOKS_ATTRIBUTE_TABLE
993 #define LANG_HOOKS_ATTRIBUTE_TABLE gnat_internal_attribute_table
994 #undef LANG_HOOKS_BUILTIN_FUNCTION
995 #define LANG_HOOKS_BUILTIN_FUNCTION gnat_builtin_function
996 #undef LANG_HOOKS_EH_PERSONALITY
997 #define LANG_HOOKS_EH_PERSONALITY gnat_eh_personality
998 #undef LANG_HOOKS_DEEP_UNSHARING
999 #define LANG_HOOKS_DEEP_UNSHARING true
1000 #undef LANG_HOOKS_INIT_TS
1001 #define LANG_HOOKS_INIT_TS gnat_init_ts
1002 #undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL
1003 #define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL hook_bool_const_tree_false
1005 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
1007 #include "gt-ada-misc.h"