1 /****************************************************************************
3 * GNAT COMPILER COMPONENTS *
7 * C Implementation File *
9 * Copyright (C) 1992-2009, 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, 51 Franklin Street, Fifth Floor, *
20 * Boston, MA 02110-1301, 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"
44 #include "diagnostic.h"
51 #include "tree-inline.h"
52 #include "insn-codes.h"
53 #include "insn-flags.h"
54 #include "insn-config.h"
61 #include "langhooks.h"
62 #include "langhooks-def.h"
78 #include "adadecode.h"
82 extern FILE *asm_out_file;
84 /* The largest alignment, in bits, that is needed for using the widest
86 unsigned int largest_move_alignment;
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 bool gnat_post_options (const char **);
93 static alias_set_type gnat_get_alias_set (tree);
94 static void gnat_print_decl (FILE *, tree, int);
95 static void gnat_print_type (FILE *, tree, int);
96 static const char *gnat_printable_name (tree, int);
97 static const char *gnat_dwarf_name (tree, int);
98 static tree gnat_return_tree (tree);
99 static int gnat_eh_type_covers (tree, tree);
100 static void gnat_parse_file (int);
101 static rtx gnat_expand_expr (tree, rtx, enum machine_mode, int,
103 static void internal_error_function (const char *, va_list *);
104 static tree gnat_type_max_size (const_tree);
106 /* Definitions for our language-specific hooks. */
108 #undef LANG_HOOKS_NAME
109 #define LANG_HOOKS_NAME "GNU Ada"
110 #undef LANG_HOOKS_IDENTIFIER_SIZE
111 #define LANG_HOOKS_IDENTIFIER_SIZE sizeof (struct tree_identifier)
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_POST_OPTIONS
119 #define LANG_HOOKS_POST_OPTIONS gnat_post_options
120 #undef LANG_HOOKS_PARSE_FILE
121 #define LANG_HOOKS_PARSE_FILE gnat_parse_file
122 #undef LANG_HOOKS_HASH_TYPES
123 #define LANG_HOOKS_HASH_TYPES false
124 #undef LANG_HOOKS_GETDECLS
125 #define LANG_HOOKS_GETDECLS lhd_return_null_tree_v
126 #undef LANG_HOOKS_PUSHDECL
127 #define LANG_HOOKS_PUSHDECL gnat_return_tree
128 #undef LANG_HOOKS_WRITE_GLOBALS
129 #define LANG_HOOKS_WRITE_GLOBALS gnat_write_global_declarations
130 #undef LANG_HOOKS_FINISH_INCOMPLETE_DECL
131 #define LANG_HOOKS_FINISH_INCOMPLETE_DECL gnat_finish_incomplete_decl
132 #undef LANG_HOOKS_GET_ALIAS_SET
133 #define LANG_HOOKS_GET_ALIAS_SET gnat_get_alias_set
134 #undef LANG_HOOKS_EXPAND_EXPR
135 #define LANG_HOOKS_EXPAND_EXPR gnat_expand_expr
136 #undef LANG_HOOKS_MARK_ADDRESSABLE
137 #define LANG_HOOKS_MARK_ADDRESSABLE gnat_mark_addressable
138 #undef LANG_HOOKS_PRINT_DECL
139 #define LANG_HOOKS_PRINT_DECL gnat_print_decl
140 #undef LANG_HOOKS_PRINT_TYPE
141 #define LANG_HOOKS_PRINT_TYPE gnat_print_type
142 #undef LANG_HOOKS_TYPE_MAX_SIZE
143 #define LANG_HOOKS_TYPE_MAX_SIZE gnat_type_max_size
144 #undef LANG_HOOKS_DECL_PRINTABLE_NAME
145 #define LANG_HOOKS_DECL_PRINTABLE_NAME gnat_printable_name
146 #undef LANG_HOOKS_DWARF_NAME
147 #define LANG_HOOKS_DWARF_NAME gnat_dwarf_name
148 #undef LANG_HOOKS_GIMPLIFY_EXPR
149 #define LANG_HOOKS_GIMPLIFY_EXPR gnat_gimplify_expr
150 #undef LANG_HOOKS_TYPE_FOR_MODE
151 #define LANG_HOOKS_TYPE_FOR_MODE gnat_type_for_mode
152 #undef LANG_HOOKS_TYPE_FOR_SIZE
153 #define LANG_HOOKS_TYPE_FOR_SIZE gnat_type_for_size
154 #undef LANG_HOOKS_TYPES_COMPATIBLE_P
155 #define LANG_HOOKS_TYPES_COMPATIBLE_P gnat_types_compatible_p
156 #undef LANG_HOOKS_ATTRIBUTE_TABLE
157 #define LANG_HOOKS_ATTRIBUTE_TABLE gnat_internal_attribute_table
158 #undef LANG_HOOKS_BUILTIN_FUNCTION
159 #define LANG_HOOKS_BUILTIN_FUNCTION gnat_builtin_function
161 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
163 /* How much we want of our DWARF extensions. Some of our dwarf+ extensions
164 are incompatible with regular GDB versions, so we must make sure to only
165 produce them on explicit request. This is eventually reflected into the
166 use_gnu_debug_info_extensions common flag for later processing. */
168 static int gnat_dwarf_extensions = 0;
170 /* Command-line argc and argv.
171 These variables are global, since they are imported and used in
174 unsigned int save_argc;
175 const char **save_argv;
177 /* gnat standard argc argv */
179 extern int gnat_argc;
180 extern char **gnat_argv;
183 /* Declare functions we use as part of startup. */
184 extern void __gnat_initialize (void *);
185 extern void __gnat_install_SEH_handler (void *);
186 extern void adainit (void);
187 extern void _ada_gnat1drv (void);
189 /* The parser for the language. For us, we process the GNAT tree. */
192 gnat_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
196 /* Call the target specific initializations. */
197 __gnat_initialize (NULL);
199 /* ??? Call the SEH initialization routine. This is to workaround
200 a bootstrap path problem. The call below should be removed at some
201 point and the SEH pointer passed to __gnat_initialize() above. */
202 __gnat_install_SEH_handler((void *)seh);
204 /* Call the front-end elaboration procedures. */
207 /* Call the front end. */
210 /* We always have a single compilation unit in Ada. */
211 cgraph_finalize_compilation_unit ();
214 /* Decode all the language specific options that cannot be decoded by GCC.
215 The option decoding phase of GCC calls this routine on the flags that
216 it cannot decode. This routine returns the number of consecutive arguments
217 from ARGV that it successfully decoded; 0 indicates failure. */
220 gnat_handle_option (size_t scode, const char *arg, int value)
222 const struct cl_option *option = &cl_options[scode];
223 enum opt_code code = (enum opt_code) scode;
226 if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
228 error ("missing argument to \"-%s\"", option->opt_text);
235 q = XNEWVEC (char, sizeof("-I") + strlen (arg));
238 gnat_argv[gnat_argc] = q;
245 /* We save the value of warn_uninitialized, since if they put
246 -Wuninitialized on the command line, we need to generate a
247 warning about not using it without also specifying -O. */
248 if (warn_uninitialized != 1)
249 warn_uninitialized = (value ? 2 : 0);
252 /* These are used in the GCC Makefile. */
253 case OPT_Wmissing_prototypes:
254 case OPT_Wstrict_prototypes:
255 case OPT_Wwrite_strings:
257 case OPT_Wvariadic_macros:
258 case OPT_Wold_style_definition:
259 case OPT_Wmissing_format_attribute:
260 case OPT_Woverlength_strings:
263 /* This is handled by the front-end. */
268 gnat_argv[gnat_argc] = xstrdup ("-nostdlib");
272 case OPT_feliminate_unused_debug_types:
273 /* We arrange for post_option to be able to only set the corresponding
274 flag to 1 when explicitly requested by the user. We expect the
275 default flag value to be either 0 or positive, and expose a positive
276 -f as a negative value to post_option. */
277 flag_eliminate_unused_debug_types = -value;
281 gnat_argv[gnat_argc] = xstrdup ("-fRTS");
286 warning (0, "%<-gnat%> misspelled as %<-gant%>");
288 /* ... fall through ... */
291 /* Recopy the switches without the 'gnat' prefix. */
292 gnat_argv[gnat_argc] = XNEWVEC (char, strlen (arg) + 2);
293 gnat_argv[gnat_argc][0] = '-';
294 strcpy (gnat_argv[gnat_argc] + 1, arg);
299 gnat_argv[gnat_argc] = xstrdup ("-O");
301 gnat_argv[gnat_argc] = xstrdup (arg);
306 gnat_dwarf_extensions ++;
316 /* Initialize for option processing. */
319 gnat_init_options (unsigned int argc, const char **argv)
321 /* Initialize gnat_argv with save_argv size. */
322 gnat_argv = (char **) xmalloc ((argc + 1) * sizeof (argv[0]));
323 gnat_argv[0] = xstrdup (argv[0]); /* name of the command */
329 /* Uninitialized really means uninitialized in Ada. */
330 flag_zero_initialized_in_bss = 0;
335 /* Post-switch processing. */
338 gnat_post_options (const char **pfilename ATTRIBUTE_UNUSED)
340 /* Excess precision other than "fast" requires front-end
342 if (flag_excess_precision_cmdline == EXCESS_PRECISION_STANDARD
343 && TARGET_FLT_EVAL_METHOD_NON_DEFAULT)
344 sorry ("-fexcess-precision=standard for Ada");
345 flag_excess_precision_cmdline = EXCESS_PRECISION_FAST;
347 /* ??? The warning machinery is outsmarted by Ada. */
348 warn_unused_parameter = 0;
350 /* No psABI change warnings for Ada. */
353 /* Force eliminate_unused_debug_types to 0 unless an explicit positive
354 -f has been passed. This forces the default to 0 for Ada, which might
355 differ from the common default. */
356 if (flag_eliminate_unused_debug_types < 0)
357 flag_eliminate_unused_debug_types = 1;
359 flag_eliminate_unused_debug_types = 0;
361 /* Reflect the explicit request of DWARF extensions into the common
362 flag for use by later passes. */
363 if (write_symbols == DWARF2_DEBUG)
364 use_gnu_debug_info_extensions = gnat_dwarf_extensions > 0;
369 /* Here is the function to handle the compiler error processing in GCC. */
372 internal_error_function (const char *msgid, va_list *ap)
375 char *buffer, *p, *loc;
376 String_Template temp, temp_loc;
377 Fat_Pointer fp, fp_loc;
380 /* Reset the pretty-printer. */
381 pp_clear_output_area (global_dc->printer);
383 /* Format the message into the pretty-printer. */
384 tinfo.format_spec = msgid;
386 tinfo.err_no = errno;
387 pp_format_verbatim (global_dc->printer, &tinfo);
389 /* Extract a (writable) pointer to the formatted text. */
390 buffer = (char*) pp_formatted_text (global_dc->printer);
392 /* Go up to the first newline. */
393 for (p = buffer; *p; p++)
401 temp.High_Bound = p - buffer;
405 s = expand_location (input_location);
406 if (flag_show_column && s.column != 0)
407 asprintf (&loc, "%s:%d:%d", s.file, s.line, s.column);
409 asprintf (&loc, "%s:%d", s.file, s.line);
410 temp_loc.Low_Bound = 1;
411 temp_loc.High_Bound = strlen (loc);
412 fp_loc.Bounds = &temp_loc;
415 Current_Error_Node = error_gnat_node;
416 Compiler_Abort (fp, -1, fp_loc);
419 /* Perform all the initialization steps that are language-specific. */
424 /* Performs whatever initialization steps needed by the language-dependent
426 gnat_init_decl_processing ();
428 /* Add the input filename as the last argument. */
429 gnat_argv[gnat_argc] = (char *) main_input_filename;
431 gnat_argv[gnat_argc] = 0;
433 global_dc->internal_error = &internal_error_function;
435 /* Show that REFERENCE_TYPEs are internal and should be Pmode. */
436 internal_reference_types ();
441 /* This function is called indirectly from toplev.c to handle incomplete
442 declarations, i.e. VAR_DECL nodes whose DECL_SIZE is zero. To be precise,
443 compile_file in toplev.c makes an indirect call through the function pointer
444 incomplete_decl_finalize_hook which is initialized to this routine in
445 init_decl_processing. */
448 gnat_finish_incomplete_decl (tree dont_care ATTRIBUTE_UNUSED)
453 /* Compute the alignment of the largest mode that can be used for copying
457 gnat_compute_largest_alignment (void)
459 enum machine_mode mode;
461 for (mode = GET_CLASS_NARROWEST_MODE (MODE_INT); mode != VOIDmode;
462 mode = GET_MODE_WIDER_MODE (mode))
463 if (optab_handler (mov_optab, mode)->insn_code != CODE_FOR_nothing)
464 largest_move_alignment = MIN (BIGGEST_ALIGNMENT,
465 MAX (largest_move_alignment,
466 GET_MODE_ALIGNMENT (mode)));
469 /* If we are using the GCC mechanism to process exception handling, we
470 have to register the personality routine for Ada and to initialize
471 various language dependent hooks. */
474 gnat_init_gcc_eh (void)
476 #ifdef DWARF2_UNWIND_INFO
477 /* lang_dependent_init already called dwarf2out_frame_init if true. */
478 int dwarf2out_frame_initialized = dwarf2out_do_frame ();
481 /* We shouldn't do anything if the No_Exceptions_Handler pragma is set,
482 though. This could for instance lead to the emission of tables with
483 references to symbols (such as the Ada eh personality routine) within
484 libraries we won't link against. */
485 if (No_Exception_Handlers_Set ())
488 /* Tell GCC we are handling cleanup actions through exception propagation.
489 This opens possibilities that we don't take advantage of yet, but is
490 nonetheless necessary to ensure that fixup code gets assigned to the
491 right exception regions. */
492 using_eh_for_cleanups ();
494 eh_personality_libfunc = init_one_libfunc (USING_SJLJ_EXCEPTIONS
495 ? "__gnat_eh_personality_sj"
496 : "__gnat_eh_personality");
497 lang_eh_type_covers = gnat_eh_type_covers;
498 lang_eh_runtime_type = gnat_return_tree;
499 default_init_unwind_resume_libfunc ();
501 /* Turn on -fexceptions and -fnon-call-exceptions. The first one triggers
502 the generation of the necessary exception runtime tables. The second one
503 is useful for two reasons: 1/ we map some asynchronous signals like SEGV
504 to exceptions, so we need to ensure that the insns which can lead to such
505 signals are correctly attached to the exception region they pertain to,
506 2/ Some calls to pure subprograms are handled as libcall blocks and then
507 marked as "cannot trap" if the flag is not set (see emit_libcall_block).
508 We should not let this be since it is possible for such calls to actually
511 flag_non_call_exceptions = 1;
514 #ifdef DWARF2_UNWIND_INFO
515 if (!dwarf2out_frame_initialized && dwarf2out_do_frame ())
516 dwarf2out_frame_init ();
520 /* Language hooks, first one to print language-specific items in a DECL. */
523 gnat_print_decl (FILE *file, tree node, int indent)
525 switch (TREE_CODE (node))
528 print_node (file, "const_corresponding_var",
529 DECL_CONST_CORRESPONDING_VAR (node), indent + 4);
533 print_node (file, "original_field", DECL_ORIGINAL_FIELD (node),
538 print_node (file, "renamed_object", DECL_RENAMED_OBJECT (node),
548 gnat_print_type (FILE *file, tree node, int indent)
550 switch (TREE_CODE (node))
553 print_node (file, "ci_co_list", TYPE_CI_CO_LIST (node), indent + 4);
558 print_node (file, "RM size", TYPE_RM_SIZE_NUM (node), indent + 4);
562 if (TYPE_MODULAR_P (node))
563 print_node (file, "modulus", TYPE_MODULUS (node), indent + 4);
564 else if (TYPE_HAS_ACTUAL_BOUNDS_P (node))
565 print_node (file, "actual bounds", TYPE_ACTUAL_BOUNDS (node),
567 else if (TYPE_VAX_FLOATING_POINT_P (node))
570 print_node (file, "index type", TYPE_INDEX_TYPE (node), indent + 4);
572 print_node (file, "RM size", TYPE_RM_SIZE_NUM (node), indent + 4);
576 print_node (file,"actual bounds", TYPE_ACTUAL_BOUNDS (node), indent + 4);
580 if (TYPE_IS_FAT_POINTER_P (node) || TYPE_CONTAINS_TEMPLATE_P (node))
581 print_node (file, "unconstrained array",
582 TYPE_UNCONSTRAINED_ARRAY (node), indent + 4);
584 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
588 case QUAL_UNION_TYPE:
589 print_node (file, "Ada size", TYPE_ADA_SIZE (node), indent + 4);
598 gnat_dwarf_name (tree t, int verbosity ATTRIBUTE_UNUSED)
600 gcc_assert (DECL_P (t));
602 return (const char *) IDENTIFIER_POINTER (DECL_NAME (t));
606 gnat_printable_name (tree decl, int verbosity)
608 const char *coded_name = IDENTIFIER_POINTER (DECL_NAME (decl));
609 char *ada_name = (char *) ggc_alloc (strlen (coded_name) * 2 + 60);
611 __gnat_decode (coded_name, ada_name, 0);
613 if (verbosity == 2 && !DECL_IS_BUILTIN (decl))
615 Set_Identifier_Casing (ada_name, (char *) DECL_SOURCE_FILE (decl));
616 return ggc_strdup (Name_Buffer);
622 /* Expands GNAT-specific GCC tree nodes. The only ones we support
623 here are and NULL_EXPR. */
626 gnat_expand_expr (tree exp, rtx target, enum machine_mode tmode,
627 int modifier, rtx *alt_rtl)
629 tree type = TREE_TYPE (exp);
632 /* Update EXP to be the new expression to expand. */
633 switch (TREE_CODE (exp))
638 allocate_dynamic_stack_space
639 (expand_expr (TREE_OPERAND (exp, 0), NULL_RTX, TYPE_MODE (sizetype),
641 NULL_RTX, tree_low_cst (TREE_OPERAND (exp, 1), 1));
644 case UNCONSTRAINED_ARRAY_REF:
645 /* If we are evaluating just for side-effects, just evaluate our
646 operand. Otherwise, abort since this code should never appear
647 in a tree to be evaluated (objects aren't unconstrained). */
648 if (target == const0_rtx || TREE_CODE (type) == VOID_TYPE)
649 return expand_expr (TREE_OPERAND (exp, 0), const0_rtx,
652 /* ... fall through ... */
658 return expand_expr_real (new, target, tmode, modifier, alt_rtl);
661 /* Do nothing (return the tree node passed). */
664 gnat_return_tree (tree t)
669 /* Return true if type A catches type B. Callback for flow analysis from
670 the exception handling part of the back-end. */
673 gnat_eh_type_covers (tree a, tree b)
675 /* a catches b if they represent the same exception id or if a
678 ??? integer_zero_node for "others" is hardwired in too many places
680 return (a == b || a == integer_zero_node);
683 /* Get the alias set corresponding to a type or expression. */
685 static alias_set_type
686 gnat_get_alias_set (tree type)
688 /* If this is a padding type, use the type of the first field. */
689 if (TREE_CODE (type) == RECORD_TYPE
690 && TYPE_IS_PADDING_P (type))
691 return get_alias_set (TREE_TYPE (TYPE_FIELDS (type)));
693 /* If the type is an unconstrained array, use the type of the
694 self-referential array we make. */
695 else if (TREE_CODE (type) == UNCONSTRAINED_ARRAY_TYPE)
697 get_alias_set (TREE_TYPE (TREE_TYPE (TYPE_FIELDS (TREE_TYPE (type)))));
699 /* If the type can alias any other types, return the alias set 0. */
700 else if (TYPE_P (type)
701 && TYPE_UNIVERSAL_ALIASING_P (TYPE_MAIN_VARIANT (type)))
707 /* GNU_TYPE is a type. Return its maximum size in bytes, if known,
708 as a constant when possible. */
711 gnat_type_max_size (const_tree gnu_type)
713 /* First see what we can get from TYPE_SIZE_UNIT, which might not
714 be constant even for simple expressions if it has already been
715 elaborated and possibly replaced by a VAR_DECL. */
716 tree max_unitsize = max_size (TYPE_SIZE_UNIT (gnu_type), true);
718 /* If we don't have a constant, see what we can get from TYPE_ADA_SIZE,
719 which should stay untouched. */
720 if (!host_integerp (max_unitsize, 1)
721 && (TREE_CODE (gnu_type) == RECORD_TYPE
722 || TREE_CODE (gnu_type) == UNION_TYPE
723 || TREE_CODE (gnu_type) == QUAL_UNION_TYPE)
724 && TYPE_ADA_SIZE (gnu_type))
726 tree max_adasize = max_size (TYPE_ADA_SIZE (gnu_type), true);
728 /* If we have succeeded in finding a constant, round it up to the
729 type's alignment and return the result in units. */
730 if (host_integerp (max_adasize, 1))
732 = size_binop (CEIL_DIV_EXPR,
733 round_up (max_adasize, TYPE_ALIGN (gnu_type)),
740 /* GNU_TYPE is a type. Determine if it should be passed by reference by
744 default_pass_by_ref (tree gnu_type)
746 /* We pass aggregates by reference if they are sufficiently large. The
747 choice of constant here is somewhat arbitrary. We also pass by
748 reference if the target machine would either pass or return by
749 reference. Strictly speaking, we need only check the return if this
750 is an In Out parameter, but it's probably best to err on the side of
751 passing more things by reference. */
753 if (pass_by_reference (NULL, TYPE_MODE (gnu_type), gnu_type, 1))
756 if (targetm.calls.return_in_memory (gnu_type, NULL_TREE))
759 if (AGGREGATE_TYPE_P (gnu_type)
760 && (!host_integerp (TYPE_SIZE (gnu_type), 1)
761 || 0 < compare_tree_int (TYPE_SIZE (gnu_type),
762 8 * TYPE_ALIGN (gnu_type))))
768 /* GNU_TYPE is the type of a subprogram parameter. Determine from the type if
769 it should be passed by reference. */
772 must_pass_by_ref (tree gnu_type)
774 /* We pass only unconstrained objects, those required by the language
775 to be passed by reference, and objects of variable size. The latter
776 is more efficient, avoids problems with variable size temporaries,
777 and does not produce compatibility problems with C, since C does
778 not have such objects. */
779 return (TREE_CODE (gnu_type) == UNCONSTRAINED_ARRAY_TYPE
780 || (AGGREGATE_TYPE_P (gnu_type) && TYPE_BY_REFERENCE_P (gnu_type))
781 || (TYPE_SIZE (gnu_type)
782 && TREE_CODE (TYPE_SIZE (gnu_type)) != INTEGER_CST));
785 /* This function is called by the front end to enumerate all the supported
786 modes for the machine. We pass a function which is called back with
787 the following integer parameters:
789 FLOAT_P nonzero if this represents a floating-point mode
790 COMPLEX_P nonzero is this represents a complex mode
791 COUNT count of number of items, nonzero for vector mode
792 PRECISION number of bits in data representation
793 MANTISSA number of bits in mantissa, if FP and known, else zero.
794 SIZE number of bits used to store data
795 ALIGN number of bits to which mode is aligned. */
798 enumerate_modes (void (*f) (int, int, int, int, int, int, unsigned int))
802 for (i = 0; i < NUM_MACHINE_MODES; i++)
810 enum machine_mode inner_mode = i;
812 switch (GET_MODE_CLASS (i))
819 case MODE_COMPLEX_INT:
821 inner_mode = GET_MODE_INNER (i);
823 case MODE_COMPLEX_FLOAT:
826 inner_mode = GET_MODE_INNER (i);
828 case MODE_VECTOR_INT:
830 inner_mode = GET_MODE_INNER (i);
832 case MODE_VECTOR_FLOAT:
835 inner_mode = GET_MODE_INNER (i);
841 /* Skip this mode if it's one the front end doesn't need to know about
842 (e.g., the CC modes) or if there is no add insn for that mode (or
843 any wider mode), meaning it is not supported by the hardware. If
844 this a complex or vector mode, we care about the inner mode. */
845 for (j = inner_mode; j != VOIDmode; j = GET_MODE_WIDER_MODE (j))
846 if (optab_handler (add_optab, j)->insn_code != CODE_FOR_nothing)
851 const struct real_format *fmt = REAL_MODE_FORMAT (inner_mode);
856 if (!skip_p && j != VOIDmode)
857 (*f) (float_p, complex_p, vector_p ? GET_MODE_NUNITS (i) : 0,
858 GET_MODE_BITSIZE (i), mantissa,
859 GET_MODE_SIZE (i) * BITS_PER_UNIT, GET_MODE_ALIGNMENT (i));
864 fp_prec_to_size (int prec)
866 enum machine_mode mode;
868 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
869 mode = GET_MODE_WIDER_MODE (mode))
870 if (GET_MODE_PRECISION (mode) == prec)
871 return GET_MODE_BITSIZE (mode);
877 fp_size_to_prec (int size)
879 enum machine_mode mode;
881 for (mode = GET_CLASS_NARROWEST_MODE (MODE_FLOAT); mode != VOIDmode;
882 mode = GET_MODE_WIDER_MODE (mode))
883 if (GET_MODE_BITSIZE (mode) == size)
884 return GET_MODE_PRECISION (mode);