* gcc-interface/misc.c (gnat_tree_size): Move around.
[official-gcc.git] / gcc / ada / gcc-interface / misc.c
blob7bdb3803c13dcf49bed99608127086f75f2905df
1 /****************************************************************************
2 * *
3 * GNAT COMPILER COMPONENTS *
4 * *
5 * M I S C *
6 * *
7 * C Implementation File *
8 * *
9 * Copyright (C) 1992-2017, 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 "target.h"
30 #include "tree.h"
31 #include "diagnostic.h"
32 #include "opts.h"
33 #include "alias.h"
34 #include "fold-const.h"
35 #include "stor-layout.h"
36 #include "print-tree.h"
37 #include "toplev.h"
38 #include "langhooks.h"
39 #include "langhooks-def.h"
40 #include "plugin.h"
41 #include "calls.h" /* For pass_by_reference. */
42 #include "dwarf2out.h"
44 #include "ada.h"
45 #include "adadecode.h"
46 #include "types.h"
47 #include "atree.h"
48 #include "namet.h"
49 #include "nlists.h"
50 #include "uintp.h"
51 #include "fe.h"
52 #include "sinfo.h"
53 #include "einfo.h"
54 #include "ada-tree.h"
55 #include "gigi.h"
57 /* This symbol needs to be defined for the front-end. */
58 void *callgraph_info_file = NULL;
60 /* Command-line argc and argv. These variables are global since they are
61 imported in back_end.adb. */
62 unsigned int save_argc;
63 const char **save_argv;
65 /* GNAT argc and argv generated by the binder for all Ada programs. */
66 extern int gnat_argc;
67 extern const char **gnat_argv;
69 /* Ada code requires variables for these settings rather than elements
70 of the global_options structure because they are imported. */
71 #undef gnat_encodings
72 enum dwarf_gnat_encodings gnat_encodings = DWARF_GNAT_ENCODINGS_DEFAULT;
74 #undef optimize
75 int optimize;
77 #undef optimize_size
78 int optimize_size;
80 #undef flag_compare_debug
81 int flag_compare_debug;
83 #undef flag_short_enums
84 int flag_short_enums;
86 #undef flag_stack_check
87 enum stack_check_type flag_stack_check = NO_STACK_CHECK;
89 #ifdef __cplusplus
90 extern "C" {
91 #endif
93 /* Declare functions we use as part of startup. */
94 extern void __gnat_initialize (void *);
95 extern void __gnat_install_SEH_handler (void *);
96 extern void adainit (void);
97 extern void _ada_gnat1drv (void);
99 #ifdef __cplusplus
101 #endif
103 /* The parser for the language. For us, we process the GNAT tree. */
105 static void
106 gnat_parse_file (void)
108 int seh[2];
110 /* Call the target specific initializations. */
111 __gnat_initialize (NULL);
113 /* ??? Call the SEH initialization routine. This is to workaround
114 a bootstrap path problem. The call below should be removed at some
115 point and the SEH pointer passed to __gnat_initialize above. */
116 __gnat_install_SEH_handler ((void *)seh);
118 /* Call the front-end elaboration procedures. */
119 adainit ();
121 /* Call the front end. */
122 _ada_gnat1drv ();
124 /* Write the global declarations. */
125 gnat_write_global_declarations ();
128 /* Return language mask for option processing. */
130 static unsigned int
131 gnat_option_lang_mask (void)
133 return CL_Ada;
136 /* Decode all the language specific options that cannot be decoded by GCC.
137 The option decoding phase of GCC calls this routine on the flags that
138 are marked as Ada-specific. Return true on success or false on failure. */
140 static bool
141 gnat_handle_option (size_t scode, const char *arg, int value, int kind,
142 location_t loc, const struct cl_option_handlers *handlers)
144 enum opt_code code = (enum opt_code) scode;
146 switch (code)
148 case OPT_Wall:
149 handle_generated_option (&global_options, &global_options_set,
150 OPT_Wunused, NULL, value,
151 gnat_option_lang_mask (), kind, loc,
152 handlers, true, global_dc);
153 warn_uninitialized = value;
154 warn_maybe_uninitialized = value;
155 break;
157 case OPT_gant:
158 warning (0, "%<-gnat%> misspelled as %<-gant%>");
160 /* ... fall through ... */
162 case OPT_gnat:
163 case OPT_gnatO:
164 case OPT_fRTS_:
165 case OPT_I:
166 case OPT_nostdinc:
167 case OPT_nostdlib:
168 /* These are handled by the front-end. */
169 break;
171 case OPT_fshort_enums:
172 case OPT_fsigned_char:
173 /* These are handled by the middle-end. */
174 break;
176 case OPT_fbuiltin_printf:
177 /* This is ignored in Ada but needs to be accepted so it can be
178 defaulted. */
179 break;
181 default:
182 gcc_unreachable ();
185 Ada_handle_option_auto (&global_options, &global_options_set,
186 scode, arg, value,
187 gnat_option_lang_mask (), kind, loc,
188 handlers, global_dc);
189 return true;
192 /* Initialize options structure OPTS. */
194 static void
195 gnat_init_options_struct (struct gcc_options *opts)
197 /* Uninitialized really means uninitialized in Ada. */
198 opts->x_flag_zero_initialized_in_bss = 0;
200 /* We don't care about errno in Ada and it causes __builtin_sqrt to
201 call the libm function rather than do it inline. */
202 opts->x_flag_errno_math = 0;
203 opts->frontend_set_flag_errno_math = true;
206 /* Initialize for option processing. */
208 static void
209 gnat_init_options (unsigned int decoded_options_count,
210 struct cl_decoded_option *decoded_options)
212 /* Reconstruct an argv array for use of back_end.adb.
214 ??? back_end.adb should not rely on this; instead, it should work with
215 decoded options without such reparsing, to ensure consistency in how
216 options are decoded. */
217 save_argv = XNEWVEC (const char *, 2 * decoded_options_count + 1);
218 save_argc = 0;
219 for (unsigned int i = 0; i < decoded_options_count; i++)
221 size_t num_elements = decoded_options[i].canonical_option_num_elements;
223 if (decoded_options[i].errors
224 || decoded_options[i].opt_index == OPT_SPECIAL_unknown
225 || num_elements == 0)
226 continue;
228 /* Deal with -I- specially since it must be a single switch. */
229 if (decoded_options[i].opt_index == OPT_I
230 && num_elements == 2
231 && decoded_options[i].canonical_option[1][0] == '-'
232 && decoded_options[i].canonical_option[1][1] == '\0')
233 save_argv[save_argc++] = "-I-";
234 else
236 gcc_assert (num_elements >= 1 && num_elements <= 2);
237 save_argv[save_argc++] = decoded_options[i].canonical_option[0];
238 if (num_elements >= 2)
239 save_argv[save_argc++] = decoded_options[i].canonical_option[1];
242 save_argv[save_argc] = NULL;
244 /* Pass just the name of the command through the regular channel. */
245 gnat_argv = (const char **) xmalloc (sizeof (char *));
246 gnat_argv[0] = xstrdup (save_argv[0]);
247 gnat_argc = 1;
250 /* Settings adjustments after switches processing by the back-end.
251 Note that the front-end switches processing (Scan_Compiler_Arguments)
252 has not been done yet at this point! */
254 static bool
255 gnat_post_options (const char **pfilename ATTRIBUTE_UNUSED)
257 /* Excess precision other than "fast" requires front-end support. */
258 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD)
259 sorry ("-fexcess-precision=standard for Ada");
260 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
262 /* No psABI change warnings for Ada. */
263 warn_psabi = 0;
265 /* No caret by default for Ada. */
266 if (!global_options_set.x_flag_diagnostics_show_caret)
267 global_dc->show_caret = false;
269 /* Warn only if STABS is not the default: we don't want to emit a warning if
270 the user did not use a -gstabs option. */
271 if (PREFERRED_DEBUGGING_TYPE != DBX_DEBUG && write_symbols == DBX_DEBUG)
272 warning (0, "STABS debugging information for Ada is obsolete and not "
273 "supported anymore");
275 /* Copy global settings to local versions. */
276 gnat_encodings = global_options.x_gnat_encodings;
277 optimize = global_options.x_optimize;
278 optimize_size = global_options.x_optimize_size;
279 flag_compare_debug = global_options.x_flag_compare_debug;
280 flag_stack_check = global_options.x_flag_stack_check;
281 flag_short_enums = global_options.x_flag_short_enums;
283 /* Unfortunately the post_options hook is called before the value of
284 flag_short_enums is autodetected, if need be. Mimic the process
285 for our private flag_short_enums. */
286 if (flag_short_enums == 2)
287 flag_short_enums = targetm.default_short_enums ();
289 return false;
292 /* Here is the function to handle the compiler error processing in GCC. */
294 static void
295 internal_error_function (diagnostic_context *context, const char *msgid,
296 va_list *ap)
298 text_info tinfo;
299 char *buffer, *p, *loc;
300 String_Template temp, temp_loc;
301 String_Pointer sp, sp_loc;
302 expanded_location xloc;
304 /* Warn if plugins present. */
305 warn_if_plugins ();
307 /* Reset the pretty-printer. */
308 pp_clear_output_area (context->printer);
310 /* Format the message into the pretty-printer. */
311 tinfo.format_spec = msgid;
312 tinfo.args_ptr = ap;
313 tinfo.err_no = errno;
314 pp_format_verbatim (context->printer, &tinfo);
316 /* Extract a (writable) pointer to the formatted text. */
317 buffer = xstrdup (pp_formatted_text (context->printer));
319 /* Go up to the first newline. */
320 for (p = buffer; *p; p++)
321 if (*p == '\n')
323 *p = '\0';
324 break;
327 temp.Low_Bound = 1;
328 temp.High_Bound = p - buffer;
329 sp.Bounds = &temp;
330 sp.Array = buffer;
332 xloc = expand_location (input_location);
333 if (context->show_column && xloc.column != 0)
334 loc = xasprintf ("%s:%d:%d", xloc.file, xloc.line, xloc.column);
335 else
336 loc = xasprintf ("%s:%d", xloc.file, xloc.line);
337 temp_loc.Low_Bound = 1;
338 temp_loc.High_Bound = strlen (loc);
339 sp_loc.Bounds = &temp_loc;
340 sp_loc.Array = loc;
342 Current_Error_Node = error_gnat_node;
343 Compiler_Abort (sp, sp_loc, true);
346 /* Perform all the initialization steps that are language-specific. */
348 static bool
349 gnat_init (void)
351 /* Do little here, most of the standard declarations are set up after the
352 front-end has been run. Use the same `char' as C for Interfaces.C. */
353 build_common_tree_nodes (flag_signed_char);
355 /* In Ada, we use an unsigned 8-bit type for the default boolean type. */
356 boolean_type_node = make_unsigned_type (8);
357 TREE_SET_CODE (boolean_type_node, BOOLEAN_TYPE);
358 SET_TYPE_RM_MAX_VALUE (boolean_type_node,
359 build_int_cst (boolean_type_node, 1));
360 SET_TYPE_RM_SIZE (boolean_type_node, bitsize_int (1));
361 boolean_true_node = TYPE_MAX_VALUE (boolean_type_node);
362 boolean_false_node = TYPE_MIN_VALUE (boolean_type_node);
364 sbitsize_one_node = sbitsize_int (1);
365 sbitsize_unit_node = sbitsize_int (BITS_PER_UNIT);
367 /* Register our internal error function. */
368 global_dc->internal_error = &internal_error_function;
370 return true;
373 /* Initialize the GCC support for exception handling. */
375 void
376 gnat_init_gcc_eh (void)
378 /* We shouldn't do anything if the No_Exceptions_Handler pragma is set,
379 though. This could for instance lead to the emission of tables with
380 references to symbols (such as the Ada eh personality routine) within
381 libraries we won't link against. */
382 if (No_Exception_Handlers_Set ())
383 return;
385 /* Tell GCC we are handling cleanup actions through exception propagation.
386 This opens possibilities that we don't take advantage of yet, but is
387 nonetheless necessary to ensure that fixup code gets assigned to the
388 right exception regions. */
389 using_eh_for_cleanups ();
391 /* Turn on -fexceptions, -fnon-call-exceptions and -fdelete-dead-exceptions.
392 The first one triggers the generation of the necessary exception tables.
393 The second one is useful for two reasons: 1/ we map some asynchronous
394 signals like SEGV to exceptions, so we need to ensure that the insns
395 which can lead to such signals are correctly attached to the exception
396 region they pertain to, 2/ some calls to pure subprograms are handled as
397 libcall blocks and then marked as "cannot trap" if the flag is not set
398 (see emit_libcall_block). We should not let this be since it is possible
399 for such calls to actually raise in Ada.
400 The third one is an optimization that makes it possible to delete dead
401 instructions that may throw exceptions, most notably loads and stores,
402 as permitted in Ada. */
403 flag_exceptions = 1;
404 flag_non_call_exceptions = 1;
405 flag_delete_dead_exceptions = 1;
407 init_eh ();
410 /* Initialize the GCC support for floating-point operations. */
412 void
413 gnat_init_gcc_fp (void)
415 /* Disable FP optimizations that ignore the signedness of zero if
416 S'Signed_Zeros is true, but don't override the user if not. */
417 if (Signed_Zeros_On_Target)
418 flag_signed_zeros = 1;
419 else if (!global_options_set.x_flag_signed_zeros)
420 flag_signed_zeros = 0;
422 /* Assume that FP operations can trap if S'Machine_Overflow is true,
423 but don't override the user if not. */
424 if (Machine_Overflows_On_Target)
425 flag_trapping_math = 1;
426 else if (!global_options_set.x_flag_trapping_math)
427 flag_trapping_math = 0;
430 /* Print language-specific items in declaration NODE. */
432 static void
433 gnat_print_decl (FILE *file, tree node, int indent)
435 switch (TREE_CODE (node))
437 case CONST_DECL:
438 print_node (file, "corresponding var",
439 DECL_CONST_CORRESPONDING_VAR (node), indent + 4);
440 break;
442 case FIELD_DECL:
443 print_node (file, "original field", DECL_ORIGINAL_FIELD (node),
444 indent + 4);
445 break;
447 case VAR_DECL:
448 if (DECL_LOOP_PARM_P (node))
449 print_node (file, "induction var", DECL_INDUCTION_VAR (node),
450 indent + 4);
451 else
452 print_node (file, "renamed object", DECL_RENAMED_OBJECT (node),
453 indent + 4);
454 break;
456 default:
457 break;
461 /* Print language-specific items in type NODE. */
463 static void
464 gnat_print_type (FILE *file, tree node, int indent)
466 switch (TREE_CODE (node))
468 case FUNCTION_TYPE:
469 print_node (file, "ci/co list", TYPE_CI_CO_LIST (node), indent + 4);
470 break;
472 case INTEGER_TYPE:
473 if (TYPE_MODULAR_P (node))
474 print_node_brief (file, "modulus", TYPE_MODULUS (node), indent + 4);
475 else if (TYPE_FIXED_POINT_P (node))
476 print_node (file, "scale factor", TYPE_SCALE_FACTOR (node),
477 indent + 4);
478 else if (TYPE_HAS_ACTUAL_BOUNDS_P (node))
479 print_node (file, "actual bounds", TYPE_ACTUAL_BOUNDS (node),
480 indent + 4);
481 else
482 print_node (file, "index type", TYPE_INDEX_TYPE (node), indent + 4);
484 /* ... fall through ... */
486 case ENUMERAL_TYPE:
487 case BOOLEAN_TYPE:
488 print_node_brief (file, "RM size", TYPE_RM_SIZE (node), indent + 4);
490 /* ... fall through ... */
492 case REAL_TYPE:
493 print_node_brief (file, "RM min", TYPE_RM_MIN_VALUE (node), indent + 4);
494 print_node_brief (file, "RM max", TYPE_RM_MAX_VALUE (node), indent + 4);
495 break;
497 case ARRAY_TYPE:
498 print_node (file,"actual bounds", TYPE_ACTUAL_BOUNDS (node), indent + 4);
499 break;
501 case VECTOR_TYPE:
502 print_node (file,"representative array",
503 TYPE_REPRESENTATIVE_ARRAY (node), indent + 4);
504 break;
506 case RECORD_TYPE:
507 if (TYPE_FAT_POINTER_P (node) || TYPE_CONTAINS_TEMPLATE_P (node))
508 print_node (file, "unconstrained array",
509 TYPE_UNCONSTRAINED_ARRAY (node), indent + 4);
510 else
511 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
512 break;
514 case UNION_TYPE:
515 case QUAL_UNION_TYPE:
516 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
517 break;
519 default:
520 break;
523 if (TYPE_CAN_HAVE_DEBUG_TYPE_P (node) && TYPE_DEBUG_TYPE (node))
524 print_node_brief (file, "debug type", TYPE_DEBUG_TYPE (node), indent + 4);
526 if (TYPE_IMPL_PACKED_ARRAY_P (node) && TYPE_ORIGINAL_PACKED_ARRAY (node))
527 print_node_brief (file, "original packed array",
528 TYPE_ORIGINAL_PACKED_ARRAY (node), indent + 4);
531 /* Return the name to be printed for DECL. */
533 static const char *
534 gnat_printable_name (tree decl, int verbosity)
536 const char *coded_name = IDENTIFIER_POINTER (DECL_NAME (decl));
537 char *ada_name = (char *) ggc_alloc_atomic (strlen (coded_name) * 2 + 60);
539 __gnat_decode (coded_name, ada_name, 0);
541 if (verbosity == 2 && !DECL_IS_BUILTIN (decl))
543 Set_Identifier_Casing (ada_name, DECL_SOURCE_FILE (decl));
544 return ggc_strdup (Name_Buffer);
547 return ada_name;
550 /* Return the name to be used in DWARF debug info for DECL. */
552 static const char *
553 gnat_dwarf_name (tree decl, int verbosity ATTRIBUTE_UNUSED)
555 gcc_assert (DECL_P (decl));
556 return (const char *) IDENTIFIER_POINTER (DECL_NAME (decl));
559 /* Return the descriptive type associated with TYPE, if any. */
561 static tree
562 gnat_descriptive_type (const_tree type)
564 if (TYPE_STUB_DECL (type))
565 return DECL_PARALLEL_TYPE (TYPE_STUB_DECL (type));
566 else
567 return NULL_TREE;
570 /* Return the underlying base type of an enumeration type. */
572 static tree
573 gnat_enum_underlying_base_type (const_tree)
575 /* Enumeration types are base types in Ada. */
576 return void_type_node;
579 /* Return the type to be used for debugging information instead of TYPE or
580 NULL_TREE if TYPE is fine. */
582 static tree
583 gnat_get_debug_type (const_tree type)
585 if (TYPE_CAN_HAVE_DEBUG_TYPE_P (type) && TYPE_DEBUG_TYPE (type))
587 type = TYPE_DEBUG_TYPE (type);
589 /* ??? The get_debug_type language hook is processed after the array
590 descriptor language hook, so if there is an array behind this type,
591 the latter is supposed to handle it. Still, we can get here with
592 a type we are not supposed to handle (e.g. when the DWARF back-end
593 processes the type of a variable), so keep this guard. */
594 if (type && TYPE_CAN_HAVE_DEBUG_TYPE_P (type))
595 return const_cast<tree> (type);
598 return NULL_TREE;
601 /* Provide information in INFO for debugging output about the TYPE fixed-point
602 type. Return whether TYPE is handled. */
604 static bool
605 gnat_get_fixed_point_type_info (const_tree type,
606 struct fixed_point_type_info *info)
608 tree scale_factor;
610 /* GDB cannot handle fixed-point types yet, so rely on GNAT encodings
611 instead for it. */
612 if (!TYPE_IS_FIXED_POINT_P (type)
613 || gnat_encodings != DWARF_GNAT_ENCODINGS_MINIMAL)
614 return false;
616 scale_factor = TYPE_SCALE_FACTOR (type);
618 /* We expect here only a finite set of pattern. See fixed-point types
619 handling in gnat_to_gnu_entity. */
621 /* Put invalid values when compiler internals cannot represent the scale
622 factor. */
623 if (scale_factor == integer_zero_node)
625 info->scale_factor_kind = fixed_point_scale_factor_arbitrary;
626 info->scale_factor.arbitrary.numerator = 0;
627 info->scale_factor.arbitrary.denominator = 0;
628 return true;
631 if (TREE_CODE (scale_factor) == RDIV_EXPR)
633 const tree num = TREE_OPERAND (scale_factor, 0);
634 const tree den = TREE_OPERAND (scale_factor, 1);
636 /* See if we have a binary or decimal scale. */
637 if (TREE_CODE (den) == POWER_EXPR)
639 const tree base = TREE_OPERAND (den, 0);
640 const tree exponent = TREE_OPERAND (den, 1);
642 /* We expect the scale factor to be 1 / 2 ** N or 1 / 10 ** N. */
643 gcc_assert (num == integer_one_node
644 && TREE_CODE (base) == INTEGER_CST
645 && TREE_CODE (exponent) == INTEGER_CST);
647 switch (tree_to_shwi (base))
649 case 2:
650 info->scale_factor_kind = fixed_point_scale_factor_binary;
651 info->scale_factor.binary = -tree_to_shwi (exponent);
652 return true;
654 case 10:
655 info->scale_factor_kind = fixed_point_scale_factor_decimal;
656 info->scale_factor.decimal = -tree_to_shwi (exponent);
657 return true;
659 default:
660 gcc_unreachable ();
664 /* If we reach this point, we are handling an arbitrary scale factor. We
665 expect N / D with constant operands. */
666 gcc_assert (TREE_CODE (num) == INTEGER_CST
667 && TREE_CODE (den) == INTEGER_CST);
669 info->scale_factor_kind = fixed_point_scale_factor_arbitrary;
670 info->scale_factor.arbitrary.numerator = tree_to_uhwi (num);
671 info->scale_factor.arbitrary.denominator = tree_to_shwi (den);
672 return true;
675 gcc_unreachable ();
678 /* Return true if types T1 and T2 are identical for type hashing purposes.
679 Called only after doing all language independent checks. At present,
680 this function is only called when both types are FUNCTION_TYPE. */
682 static bool
683 gnat_type_hash_eq (const_tree t1, const_tree t2)
685 gcc_assert (TREE_CODE (t1) == FUNCTION_TYPE);
686 return fntype_same_flags_p (t1, TYPE_CI_CO_LIST (t2),
687 TYPE_RETURN_UNCONSTRAINED_P (t2),
688 TYPE_RETURN_BY_DIRECT_REF_P (t2),
689 TREE_ADDRESSABLE (t2));
692 /* Do nothing (return the tree node passed). */
694 static tree
695 gnat_return_tree (tree t)
697 return t;
700 /* Get the alias set corresponding to a type or expression. */
702 static alias_set_type
703 gnat_get_alias_set (tree type)
705 /* If this is a padding type, use the type of the first field. */
706 if (TYPE_IS_PADDING_P (type))
707 return get_alias_set (TREE_TYPE (TYPE_FIELDS (type)));
709 /* If the type is an unconstrained array, use the type of the
710 self-referential array we make. */
711 else if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE)
712 return
713 get_alias_set (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (type)))));
715 /* If the type can alias any other types, return the alias set 0. */
716 else if (TYPE_P (type)
717 && !TYPE_IS_DUMMY_P (type)
718 && TYPE_UNIVERSAL_ALIASING_P (type))
719 return 0;
721 return -1;
724 /* GNU_TYPE is a type. Return its maximum size in bytes, if known,
725 as a constant when possible. */
727 static tree
728 gnat_type_max_size (const_tree gnu_type)
730 /* First see what we can get from TYPE_SIZE_UNIT, which might not
731 be constant even for simple expressions if it has already been
732 elaborated and possibly replaced by a VAR_DECL. */
733 tree max_unitsize = max_size (TYPE_SIZE_UNIT (gnu_type), true);
735 /* If we don't have a constant, try to look at attributes which should have
736 stayed untouched. */
737 if (!tree_fits_uhwi_p (max_unitsize))
739 /* For record types, see what we can get from TYPE_ADA_SIZE. */
740 if (RECORD_OR_UNION_TYPE_P (gnu_type)
741 && !TYPE_FAT_POINTER_P (gnu_type)
742 && TYPE_ADA_SIZE (gnu_type))
744 tree max_adasize = max_size (TYPE_ADA_SIZE (gnu_type), true);
746 /* If we have succeeded in finding a constant, round it up to the
747 type's alignment and return the result in units. */
748 if (tree_fits_uhwi_p (max_adasize))
749 max_unitsize
750 = size_binop (CEIL_DIV_EXPR,
751 round_up (max_adasize, TYPE_ALIGN (gnu_type)),
752 bitsize_unit_node);
755 /* For array types, see what we can get from TYPE_INDEX_TYPE. */
756 else if (TREE_CODE (gnu_type) == ARRAY_TYPE
757 && TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type))
758 && tree_fits_uhwi_p (TYPE_SIZE_UNIT (TREE_TYPE (gnu_type))))
760 tree lb = TYPE_MIN_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type)));
761 tree hb = TYPE_MAX_VALUE (TYPE_INDEX_TYPE (TYPE_DOMAIN (gnu_type)));
762 if (TREE_CODE (lb) != INTEGER_CST
763 && TYPE_RM_SIZE (TREE_TYPE (lb))
764 && compare_tree_int (TYPE_RM_SIZE (TREE_TYPE (lb)), 16) <= 0)
765 lb = TYPE_MIN_VALUE (TREE_TYPE (lb));
766 if (TREE_CODE (hb) != INTEGER_CST
767 && TYPE_RM_SIZE (TREE_TYPE (hb))
768 && compare_tree_int (TYPE_RM_SIZE (TREE_TYPE (hb)), 16) <= 0)
769 hb = TYPE_MAX_VALUE (TREE_TYPE (hb));
770 if (TREE_CODE (lb) == INTEGER_CST && TREE_CODE (hb) == INTEGER_CST)
772 tree ctype = get_base_type (TREE_TYPE (lb));
773 lb = fold_convert (ctype, lb);
774 hb = fold_convert (ctype, hb);
775 if (tree_int_cst_le (lb, hb))
777 tree length
778 = fold_build2 (PLUS_EXPR, ctype,
779 fold_build2 (MINUS_EXPR, ctype, hb, lb),
780 build_int_cst (ctype, 1));
781 max_unitsize
782 = fold_build2 (MULT_EXPR, sizetype,
783 fold_convert (sizetype, length),
784 TYPE_SIZE_UNIT (TREE_TYPE (gnu_type)));
790 return max_unitsize;
793 static tree get_array_bit_stride (tree);
795 /* Provide information in INFO for debug output about the TYPE array type.
796 Return whether TYPE is handled. */
798 static bool
799 gnat_get_array_descr_info (const_tree const_type,
800 struct array_descr_info *info)
802 bool convention_fortran_p;
803 bool is_array = false;
804 bool is_fat_ptr = false;
805 bool is_packed_array = false;
806 tree type = const_cast<tree> (const_type);
807 const_tree first_dimen = NULL_TREE;
808 const_tree last_dimen = NULL_TREE;
809 const_tree dimen;
810 int i;
812 /* Temporaries created in the first pass and used in the second one for thin
813 pointers. The first one is an expression that yields the template record
814 from the base address (i.e. the PLACEHOLDER_EXPR). The second one is just
815 a cursor through this record's fields. */
816 tree thinptr_template_expr = NULL_TREE;
817 tree thinptr_bound_field = NULL_TREE;
819 /* ??? See gnat_get_debug_type. */
820 type = maybe_debug_type (type);
822 /* If we have an implementation type for a packed array, get the orignial
823 array type. */
824 if (TYPE_IMPL_PACKED_ARRAY_P (type) && TYPE_ORIGINAL_PACKED_ARRAY (type))
826 type = TYPE_ORIGINAL_PACKED_ARRAY (type);
827 is_packed_array = true;
830 /* First pass: gather all information about this array except everything
831 related to dimensions. */
833 /* Only handle ARRAY_TYPE nodes that come from GNAT. */
834 if (TREE_CODE (type) == ARRAY_TYPE
835 && TYPE_DOMAIN (type)
836 && TYPE_INDEX_TYPE (TYPE_DOMAIN (type)))
838 is_array = true;
839 first_dimen = type;
840 info->data_location = NULL_TREE;
843 else if (TYPE_IS_FAT_POINTER_P (type)
844 && gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL)
846 const tree ua_type = TYPE_UNCONSTRAINED_ARRAY (type);
848 /* This will be our base object address. */
849 const tree placeholder_expr = build0 (PLACEHOLDER_EXPR, type);
851 /* We assume below that maybe_unconstrained_array returns an INDIRECT_REF
852 node. */
853 const tree ua_val
854 = maybe_unconstrained_array (build_unary_op (INDIRECT_REF,
855 ua_type,
856 placeholder_expr));
858 is_fat_ptr = true;
859 first_dimen = TREE_TYPE (ua_val);
861 /* Get the *address* of the array, not the array itself. */
862 info->data_location = TREE_OPERAND (ua_val, 0);
865 /* Unlike fat pointers (which appear for unconstrained arrays passed in
866 argument), thin pointers are used only for array access types, so we want
867 them to appear in the debug info as pointers to an array type. That's why
868 we match only the RECORD_TYPE here instead of the POINTER_TYPE with the
869 TYPE_IS_THIN_POINTER_P predicate. */
870 else if (TREE_CODE (type) == RECORD_TYPE
871 && TYPE_CONTAINS_TEMPLATE_P (type)
872 && gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL)
874 /* This will be our base object address. Note that we assume that
875 pointers to these will actually point to the array field (thin
876 pointers are shifted). */
877 const tree placeholder_expr = build0 (PLACEHOLDER_EXPR, type);
878 const tree placeholder_addr
879 = build_unary_op (ADDR_EXPR, NULL_TREE, placeholder_expr);
881 const tree bounds_field = TYPE_FIELDS (type);
882 const tree bounds_type = TREE_TYPE (bounds_field);
883 const tree array_field = DECL_CHAIN (bounds_field);
884 const tree array_type = TREE_TYPE (array_field);
886 /* Shift the thin pointer address to get the address of the template. */
887 const tree shift_amount
888 = fold_build1 (NEGATE_EXPR, sizetype, byte_position (array_field));
889 tree template_addr
890 = build_binary_op (POINTER_PLUS_EXPR, TREE_TYPE (placeholder_addr),
891 placeholder_addr, shift_amount);
892 template_addr
893 = fold_convert (TYPE_POINTER_TO (bounds_type), template_addr);
895 first_dimen = array_type;
897 /* The thin pointer is already the pointer to the array data, so there's
898 no need for a specific "data location" expression. */
899 info->data_location = NULL_TREE;
901 thinptr_template_expr = build_unary_op (INDIRECT_REF,
902 bounds_type,
903 template_addr);
904 thinptr_bound_field = TYPE_FIELDS (bounds_type);
906 else
907 return false;
909 /* Second pass: compute the remaining information: dimensions and
910 corresponding bounds. */
912 if (TYPE_PACKED (first_dimen))
913 is_packed_array = true;
914 /* If this array has fortran convention, it's arranged in column-major
915 order, so our view here has reversed dimensions. */
916 convention_fortran_p = TYPE_CONVENTION_FORTRAN_P (first_dimen);
917 /* ??? For row major ordering, we probably want to emit nothing and
918 instead specify it as the default in Dw_TAG_compile_unit. */
919 info->ordering = (convention_fortran_p
920 ? array_descr_ordering_column_major
921 : array_descr_ordering_row_major);
923 /* Count how many dimensions this array has. */
924 for (i = 0, dimen = first_dimen; ; ++i, dimen = TREE_TYPE (dimen))
926 if (i > 0
927 && (TREE_CODE (dimen) != ARRAY_TYPE
928 || !TYPE_MULTI_ARRAY_P (dimen)))
929 break;
930 last_dimen = dimen;
933 info->ndimensions = i;
934 info->rank = NULL_TREE;
936 /* Too many dimensions? Give up generating proper description: yield instead
937 nested arrays. Note that in this case, this hook is invoked once on each
938 intermediate array type: be consistent and output nested arrays for all
939 dimensions. */
940 if (info->ndimensions > DWARF2OUT_ARRAY_DESCR_INFO_MAX_DIMEN
941 || TYPE_MULTI_ARRAY_P (first_dimen))
943 info->ndimensions = 1;
944 last_dimen = first_dimen;
947 info->element_type = TREE_TYPE (last_dimen);
949 /* Now iterate over all dimensions in source-order and fill the info
950 structure. */
951 for (i = (convention_fortran_p ? info->ndimensions - 1 : 0),
952 dimen = first_dimen;
953 0 <= i && i < info->ndimensions;
954 i += (convention_fortran_p ? -1 : 1),
955 dimen = TREE_TYPE (dimen))
957 /* We are interested in the stored bounds for the debug info. */
958 tree index_type = TYPE_INDEX_TYPE (TYPE_DOMAIN (dimen));
960 if (is_array || is_fat_ptr)
962 /* GDB does not handle very well the self-referencial bound
963 expressions we are able to generate here for XUA types (they are
964 used only by XUP encodings) so avoid them in this case. Note that
965 there are two cases where we generate self-referencial bound
966 expressions: arrays that are constrained by record discriminants
967 and XUA types. */
968 if (TYPE_CONTEXT (first_dimen)
969 && TREE_CODE (TYPE_CONTEXT (first_dimen)) != RECORD_TYPE
970 && CONTAINS_PLACEHOLDER_P (TYPE_MIN_VALUE (index_type))
971 && gnat_encodings != DWARF_GNAT_ENCODINGS_MINIMAL)
973 info->dimen[i].lower_bound = NULL_TREE;
974 info->dimen[i].upper_bound = NULL_TREE;
976 else
978 info->dimen[i].lower_bound
979 = maybe_character_value (TYPE_MIN_VALUE (index_type));
980 info->dimen[i].upper_bound
981 = maybe_character_value (TYPE_MAX_VALUE (index_type));
985 /* This is a thin pointer. */
986 else
988 info->dimen[i].lower_bound
989 = build_component_ref (thinptr_template_expr, thinptr_bound_field,
990 false);
991 thinptr_bound_field = DECL_CHAIN (thinptr_bound_field);
993 info->dimen[i].upper_bound
994 = build_component_ref (thinptr_template_expr, thinptr_bound_field,
995 false);
996 thinptr_bound_field = DECL_CHAIN (thinptr_bound_field);
999 /* The DWARF back-end will output BOUNDS_TYPE as the base type of
1000 the array index, so get to the base type of INDEX_TYPE. */
1001 while (TREE_TYPE (index_type))
1002 index_type = TREE_TYPE (index_type);
1004 info->dimen[i].bounds_type = maybe_debug_type (index_type);
1005 info->dimen[i].stride = NULL_TREE;
1008 /* These are Fortran-specific fields. They make no sense here. */
1009 info->allocated = NULL_TREE;
1010 info->associated = NULL_TREE;
1012 if (gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL)
1014 /* When arrays contain dynamically-sized elements, we usually wrap them
1015 in padding types, or we create constrained types for them. Then, if
1016 such types are stripped in the debugging information output, the
1017 debugger needs a way to know the size that is reserved for each
1018 element. This is why we emit a stride in such situations. */
1019 tree source_element_type = info->element_type;
1021 while (true)
1023 if (TYPE_DEBUG_TYPE (source_element_type))
1024 source_element_type = TYPE_DEBUG_TYPE (source_element_type);
1025 else if (TYPE_IS_PADDING_P (source_element_type))
1026 source_element_type
1027 = TREE_TYPE (TYPE_FIELDS (source_element_type));
1028 else
1029 break;
1032 if (TREE_CODE (TYPE_SIZE_UNIT (source_element_type)) != INTEGER_CST)
1034 info->stride = TYPE_SIZE_UNIT (info->element_type);
1035 info->stride_in_bits = false;
1038 /* We need to specify a bit stride when it does not correspond to the
1039 natural size of the contained elements. ??? Note that we do not
1040 support packed records and nested packed arrays. */
1041 else if (is_packed_array)
1043 info->stride = get_array_bit_stride (info->element_type);
1044 info->stride_in_bits = true;
1048 return true;
1051 /* Given the component type COMP_TYPE of a packed array, return an expression
1052 that computes the bit stride of this packed array. Return NULL_TREE when
1053 unsuccessful. */
1055 static tree
1056 get_array_bit_stride (tree comp_type)
1058 struct array_descr_info info;
1059 tree stride;
1061 /* Simple case: the array contains an integral type: return its RM size. */
1062 if (INTEGRAL_TYPE_P (comp_type))
1063 return TYPE_RM_SIZE (comp_type);
1065 /* Otherwise, see if this is an array we can analyze; if it's not, punt. */
1066 memset (&info, 0, sizeof (info));
1067 if (!gnat_get_array_descr_info (comp_type, &info) || !info.stride)
1068 return NULL_TREE;
1070 /* Otherwise, the array stride is the inner array's stride multiplied by the
1071 number of elements it contains. Note that if the inner array is not
1072 packed, then the stride is "natural" and thus does not deserve an
1073 attribute. */
1074 stride = info.stride;
1075 if (!info.stride_in_bits)
1077 stride = fold_convert (bitsizetype, stride);
1078 stride = build_binary_op (MULT_EXPR, bitsizetype,
1079 stride, build_int_cst (bitsizetype, 8));
1082 for (int i = 0; i < info.ndimensions; ++i)
1084 tree count;
1086 if (!info.dimen[i].lower_bound || !info.dimen[i].upper_bound)
1087 return NULL_TREE;
1089 /* Put in count an expression that computes the length of this
1090 dimension. */
1091 count = build_binary_op (MINUS_EXPR, sbitsizetype,
1092 fold_convert (sbitsizetype,
1093 info.dimen[i].upper_bound),
1094 fold_convert (sbitsizetype,
1095 info.dimen[i].lower_bound)),
1096 count = build_binary_op (PLUS_EXPR, sbitsizetype,
1097 count, build_int_cst (sbitsizetype, 1));
1098 count = build_binary_op (MAX_EXPR, sbitsizetype,
1099 count,
1100 build_int_cst (sbitsizetype, 0));
1101 count = fold_convert (bitsizetype, count);
1102 stride = build_binary_op (MULT_EXPR, bitsizetype, stride, count);
1105 return stride;
1108 /* GNU_TYPE is a subtype of an integral type. Set LOWVAL to the low bound
1109 and HIGHVAL to the high bound, respectively. */
1111 static void
1112 gnat_get_subrange_bounds (const_tree gnu_type, tree *lowval, tree *highval)
1114 *lowval = TYPE_MIN_VALUE (gnu_type);
1115 *highval = TYPE_MAX_VALUE (gnu_type);
1118 /* Return the bias of GNU_TYPE, if any. */
1120 static tree
1121 gnat_get_type_bias (const_tree gnu_type)
1123 if (TREE_CODE (gnu_type) == INTEGER_TYPE
1124 && TYPE_BIASED_REPRESENTATION_P (gnu_type)
1125 && gnat_encodings == DWARF_GNAT_ENCODINGS_MINIMAL)
1126 return TYPE_RM_MIN_VALUE (gnu_type);
1128 return NULL_TREE;
1131 /* GNU_TYPE is the type of a subprogram parameter. Determine if it should be
1132 passed by reference by default. */
1134 bool
1135 default_pass_by_ref (tree gnu_type)
1137 /* We pass aggregates by reference if they are sufficiently large for
1138 their alignment. The ratio is somewhat arbitrary. We also pass by
1139 reference if the target machine would either pass or return by
1140 reference. Strictly speaking, we need only check the return if this
1141 is an In Out parameter, but it's probably best to err on the side of
1142 passing more things by reference. */
1144 if (pass_by_reference (NULL, TYPE_MODE (gnu_type), gnu_type, true))
1145 return true;
1147 if (targetm.calls.return_in_memory (gnu_type, NULL_TREE))
1148 return true;
1150 if (AGGREGATE_TYPE_P (gnu_type)
1151 && (!valid_constant_size_p (TYPE_SIZE_UNIT (gnu_type))
1152 || 0 < compare_tree_int (TYPE_SIZE_UNIT (gnu_type),
1153 TYPE_ALIGN (gnu_type))))
1154 return true;
1156 return false;
1159 /* GNU_TYPE is the type of a subprogram parameter. Determine if it must be
1160 passed by reference. */
1162 bool
1163 must_pass_by_ref (tree gnu_type)
1165 /* We pass only unconstrained objects, those required by the language
1166 to be passed by reference, and objects of variable size. The latter
1167 is more efficient, avoids problems with variable size temporaries,
1168 and does not produce compatibility problems with C, since C does
1169 not have such objects. */
1170 return (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE
1171 || TYPE_IS_BY_REFERENCE_P (gnu_type)
1172 || (TYPE_SIZE_UNIT (gnu_type)
1173 && TREE_CODE (TYPE_SIZE_UNIT (gnu_type)) != INTEGER_CST));
1176 /* This function is called by the front-end to enumerate all the supported
1177 modes for the machine, as well as some predefined C types. F is a function
1178 which is called back with the parameters as listed below, first a string,
1179 then seven ints. The name is any arbitrary null-terminated string and has
1180 no particular significance, except for the case of predefined C types, where
1181 it should be the name of the C type. For integer types, only signed types
1182 should be listed, unsigned versions are assumed. The order of types should
1183 be in order of preference, with the smallest/cheapest types first.
1185 In particular, C predefined types should be listed before other types,
1186 binary floating point types before decimal ones, and narrower/cheaper
1187 type versions before more expensive ones. In type selection the first
1188 matching variant will be used.
1190 NAME pointer to first char of type name
1191 DIGS number of decimal digits for floating-point modes, else 0
1192 COMPLEX_P nonzero is this represents a complex mode
1193 COUNT count of number of items, nonzero for vector mode
1194 FLOAT_REP Float_Rep_Kind for FP, otherwise undefined
1195 PRECISION number of bits used to store data
1196 SIZE number of bits occupied by the mode
1197 ALIGN number of bits to which mode is aligned. */
1199 void
1200 enumerate_modes (void (*f) (const char *, int, int, int, int, int, int, int))
1202 const tree c_types[]
1203 = { float_type_node, double_type_node, long_double_type_node };
1204 const char *const c_names[]
1205 = { "float", "double", "long double" };
1206 int iloop;
1208 /* We are going to compute it below. */
1209 fp_arith_may_widen = false;
1211 for (iloop = 0; iloop < NUM_MACHINE_MODES; iloop++)
1213 machine_mode i = (machine_mode) iloop;
1214 machine_mode inner_mode = i;
1215 bool float_p = false;
1216 bool complex_p = false;
1217 bool vector_p = false;
1218 bool skip_p = false;
1219 int digs = 0;
1220 unsigned int nameloop;
1221 Float_Rep_Kind float_rep = IEEE_Binary; /* Until proven otherwise */
1223 switch (GET_MODE_CLASS (i))
1225 case MODE_INT:
1226 break;
1227 case MODE_FLOAT:
1228 float_p = true;
1229 break;
1230 case MODE_COMPLEX_INT:
1231 complex_p = true;
1232 inner_mode = GET_MODE_INNER (i);
1233 break;
1234 case MODE_COMPLEX_FLOAT:
1235 float_p = true;
1236 complex_p = true;
1237 inner_mode = GET_MODE_INNER (i);
1238 break;
1239 case MODE_VECTOR_INT:
1240 vector_p = true;
1241 inner_mode = GET_MODE_INNER (i);
1242 break;
1243 case MODE_VECTOR_FLOAT:
1244 float_p = true;
1245 vector_p = true;
1246 inner_mode = GET_MODE_INNER (i);
1247 break;
1248 default:
1249 skip_p = true;
1252 if (float_p)
1254 const struct real_format *fmt = REAL_MODE_FORMAT (inner_mode);
1256 /* ??? Cope with the ghost XFmode of the ARM port. */
1257 if (!fmt)
1258 continue;
1260 /* Be conservative and consider that floating-point arithmetics may
1261 use wider intermediate results as soon as there is an extended
1262 Motorola or Intel mode supported by the machine. */
1263 if (fmt == &ieee_extended_motorola_format
1264 || fmt == &ieee_extended_intel_96_format
1265 || fmt == &ieee_extended_intel_96_round_53_format
1266 || fmt == &ieee_extended_intel_128_format)
1268 #ifdef TARGET_FPMATH_DEFAULT
1269 if (TARGET_FPMATH_DEFAULT == FPMATH_387)
1270 #endif
1271 fp_arith_may_widen = true;
1274 if (fmt->b == 2)
1275 digs = (fmt->p - 1) * 1233 / 4096; /* scale by log (2) */
1277 else if (fmt->b == 10)
1278 digs = fmt->p;
1280 else
1281 gcc_unreachable ();
1284 /* First register any C types for this mode that the front end
1285 may need to know about, unless the mode should be skipped. */
1286 if (!skip_p && !vector_p)
1287 for (nameloop = 0; nameloop < ARRAY_SIZE (c_types); nameloop++)
1289 tree type = c_types[nameloop];
1290 const char *name = c_names[nameloop];
1292 if (TYPE_MODE (type) == i)
1294 f (name, digs, complex_p, 0, float_rep, TYPE_PRECISION (type),
1295 TREE_INT_CST_LOW (TYPE_SIZE (type)), TYPE_ALIGN (type));
1296 skip_p = true;
1300 /* If no predefined C types were found, register the mode itself. */
1301 if (!skip_p)
1302 f (GET_MODE_NAME (i), digs, complex_p,
1303 vector_p ? GET_MODE_NUNITS (i) : 0, float_rep,
1304 GET_MODE_PRECISION (i), GET_MODE_BITSIZE (i),
1305 GET_MODE_ALIGNMENT (i));
1309 /* Return the size of the FP mode with precision PREC. */
1312 fp_prec_to_size (int prec)
1314 opt_scalar_float_mode opt_mode;
1316 FOR_EACH_MODE_IN_CLASS (opt_mode, MODE_FLOAT)
1318 scalar_float_mode mode = opt_mode.require ();
1319 if (GET_MODE_PRECISION (mode) == prec)
1320 return GET_MODE_BITSIZE (mode);
1323 gcc_unreachable ();
1326 /* Return the precision of the FP mode with size SIZE. */
1329 fp_size_to_prec (int size)
1331 opt_scalar_float_mode opt_mode;
1333 FOR_EACH_MODE_IN_CLASS (opt_mode, MODE_FLOAT)
1335 scalar_mode mode = opt_mode.require ();
1336 if (GET_MODE_BITSIZE (mode) == size)
1337 return GET_MODE_PRECISION (mode);
1340 gcc_unreachable ();
1343 static GTY(()) tree gnat_eh_personality_decl;
1345 /* Return the GNAT personality function decl. */
1347 static tree
1348 gnat_eh_personality (void)
1350 if (!gnat_eh_personality_decl)
1351 gnat_eh_personality_decl = build_personality_function ("gnat");
1352 return gnat_eh_personality_decl;
1355 /* Initialize language-specific bits of tree_contains_struct. */
1357 static void
1358 gnat_init_ts (void)
1360 MARK_TS_COMMON (UNCONSTRAINED_ARRAY_TYPE);
1362 MARK_TS_TYPED (UNCONSTRAINED_ARRAY_REF);
1363 MARK_TS_TYPED (NULL_EXPR);
1364 MARK_TS_TYPED (PLUS_NOMOD_EXPR);
1365 MARK_TS_TYPED (MINUS_NOMOD_EXPR);
1366 MARK_TS_TYPED (POWER_EXPR);
1367 MARK_TS_TYPED (ATTR_ADDR_EXPR);
1368 MARK_TS_TYPED (STMT_STMT);
1369 MARK_TS_TYPED (LOOP_STMT);
1370 MARK_TS_TYPED (EXIT_STMT);
1373 /* Return the size of a tree with CODE, which is a language-specific tree code
1374 in category tcc_constant, tcc_exceptional or tcc_type. The default expects
1375 never to be called. */
1377 static size_t
1378 gnat_tree_size (enum tree_code code)
1380 gcc_checking_assert (code >= NUM_TREE_CODES);
1381 switch (code)
1383 case UNCONSTRAINED_ARRAY_TYPE:
1384 return sizeof (tree_type_non_common);
1385 default:
1386 gcc_unreachable ();
1390 /* Return the lang specific structure attached to NODE. Allocate it (cleared)
1391 if needed. */
1393 struct lang_type *
1394 get_lang_specific (tree node)
1396 if (!TYPE_LANG_SPECIFIC (node))
1397 TYPE_LANG_SPECIFIC (node) = ggc_cleared_alloc<struct lang_type> ();
1398 return TYPE_LANG_SPECIFIC (node);
1401 /* Definitions for our language-specific hooks. */
1403 #undef LANG_HOOKS_NAME
1404 #define LANG_HOOKS_NAME "GNU Ada"
1405 #undef LANG_HOOKS_IDENTIFIER_SIZE
1406 #define LANG_HOOKS_IDENTIFIER_SIZE sizeof (struct tree_identifier)
1407 #undef LANG_HOOKS_TREE_SIZE
1408 #define LANG_HOOKS_TREE_SIZE gnat_tree_size
1409 #undef LANG_HOOKS_INIT
1410 #define LANG_HOOKS_INIT gnat_init
1411 #undef LANG_HOOKS_OPTION_LANG_MASK
1412 #define LANG_HOOKS_OPTION_LANG_MASK gnat_option_lang_mask
1413 #undef LANG_HOOKS_INIT_OPTIONS_STRUCT
1414 #define LANG_HOOKS_INIT_OPTIONS_STRUCT gnat_init_options_struct
1415 #undef LANG_HOOKS_INIT_OPTIONS
1416 #define LANG_HOOKS_INIT_OPTIONS gnat_init_options
1417 #undef LANG_HOOKS_HANDLE_OPTION
1418 #define LANG_HOOKS_HANDLE_OPTION gnat_handle_option
1419 #undef LANG_HOOKS_POST_OPTIONS
1420 #define LANG_HOOKS_POST_OPTIONS gnat_post_options
1421 #undef LANG_HOOKS_PARSE_FILE
1422 #define LANG_HOOKS_PARSE_FILE gnat_parse_file
1423 #undef LANG_HOOKS_TYPE_HASH_EQ
1424 #define LANG_HOOKS_TYPE_HASH_EQ gnat_type_hash_eq
1425 #undef LANG_HOOKS_GETDECLS
1426 #define LANG_HOOKS_GETDECLS hook_tree_void_null
1427 #undef LANG_HOOKS_PUSHDECL
1428 #define LANG_HOOKS_PUSHDECL gnat_return_tree
1429 #undef LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL
1430 #define LANG_HOOKS_WARN_UNUSED_GLOBAL_DECL hook_bool_const_tree_false
1431 #undef LANG_HOOKS_GET_ALIAS_SET
1432 #define LANG_HOOKS_GET_ALIAS_SET gnat_get_alias_set
1433 #undef LANG_HOOKS_PRINT_DECL
1434 #define LANG_HOOKS_PRINT_DECL gnat_print_decl
1435 #undef LANG_HOOKS_PRINT_TYPE
1436 #define LANG_HOOKS_PRINT_TYPE gnat_print_type
1437 #undef LANG_HOOKS_TYPE_MAX_SIZE
1438 #define LANG_HOOKS_TYPE_MAX_SIZE gnat_type_max_size
1439 #undef LANG_HOOKS_DECL_PRINTABLE_NAME
1440 #define LANG_HOOKS_DECL_PRINTABLE_NAME gnat_printable_name
1441 #undef LANG_HOOKS_DWARF_NAME
1442 #define LANG_HOOKS_DWARF_NAME gnat_dwarf_name
1443 #undef LANG_HOOKS_GIMPLIFY_EXPR
1444 #define LANG_HOOKS_GIMPLIFY_EXPR gnat_gimplify_expr
1445 #undef LANG_HOOKS_TYPE_FOR_MODE
1446 #define LANG_HOOKS_TYPE_FOR_MODE gnat_type_for_mode
1447 #undef LANG_HOOKS_TYPE_FOR_SIZE
1448 #define LANG_HOOKS_TYPE_FOR_SIZE gnat_type_for_size
1449 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
1450 #define LANG_HOOKS_TYPES_COMPATIBLE_P gnat_types_compatible_p
1451 #undef LANG_HOOKS_GET_ARRAY_DESCR_INFO
1452 #define LANG_HOOKS_GET_ARRAY_DESCR_INFO gnat_get_array_descr_info
1453 #undef LANG_HOOKS_GET_SUBRANGE_BOUNDS
1454 #define LANG_HOOKS_GET_SUBRANGE_BOUNDS gnat_get_subrange_bounds
1455 #undef LANG_HOOKS_GET_TYPE_BIAS
1456 #define LANG_HOOKS_GET_TYPE_BIAS gnat_get_type_bias
1457 #undef LANG_HOOKS_DESCRIPTIVE_TYPE
1458 #define LANG_HOOKS_DESCRIPTIVE_TYPE gnat_descriptive_type
1459 #undef LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE
1460 #define LANG_HOOKS_ENUM_UNDERLYING_BASE_TYPE gnat_enum_underlying_base_type
1461 #undef LANG_HOOKS_GET_DEBUG_TYPE
1462 #define LANG_HOOKS_GET_DEBUG_TYPE gnat_get_debug_type
1463 #undef LANG_HOOKS_GET_FIXED_POINT_TYPE_INFO
1464 #define LANG_HOOKS_GET_FIXED_POINT_TYPE_INFO gnat_get_fixed_point_type_info
1465 #undef LANG_HOOKS_ATTRIBUTE_TABLE
1466 #define LANG_HOOKS_ATTRIBUTE_TABLE gnat_internal_attribute_table
1467 #undef LANG_HOOKS_BUILTIN_FUNCTION
1468 #define LANG_HOOKS_BUILTIN_FUNCTION gnat_builtin_function
1469 #undef LANG_HOOKS_INIT_TS
1470 #define LANG_HOOKS_INIT_TS gnat_init_ts
1471 #undef LANG_HOOKS_EH_PERSONALITY
1472 #define LANG_HOOKS_EH_PERSONALITY gnat_eh_personality
1473 #undef LANG_HOOKS_DEEP_UNSHARING
1474 #define LANG_HOOKS_DEEP_UNSHARING true
1475 #undef LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS
1476 #define LANG_HOOKS_CUSTOM_FUNCTION_DESCRIPTORS true
1478 struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
1480 #include "gt-ada-misc.h"