This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gfortran] Let f951 generate type infos for SELECTED_*_KIND
- From: Tobias Schlüter <tobias dot schlueter at physik dot uni-muenchen dot de>
- To: GCC Fortran mailing list <fortran at gcc dot gnu dot org>,patch <gcc-patches at gcc dot gnu dot org>
- Date: Sun, 03 Oct 2004 12:44:32 +0200
- Subject: [gfortran] Let f951 generate type infos for SELECTED_*_KIND
When RTH reworked trans-types.c it was briefly discussed to have the compiler
output the list of possible types, instead of simply trying all possibilities
when building the library.
This straightforward patch implements this. The only non-trivial part was
finding out how to pass the new option to f951 during the build, but this
turned out to be trivial as well, after I had found the correct driver option.
Built and tested on i686-pc-linux.
- Tobi
2004-10-03 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de>
libgfortran/
* Makefile.am (selected_int_kind.inc, selected_real_kind.inc): Use new
compiler option to create files.
* Makefile.in: Regenerate.
* mk-sik-inc.sh, mk-srk-inc.sh: Remove
fortran/
* lang.opt (output-integer-type-infos, output-real-type-infos): New
options.
* options.c (gfc_handle_option): Deal with new options.
* trans-types.c (gfc_output_{integer|real}_type_infos): New functions.
* gfortran.h (gfc_output_{integer|real}_type_infos): Add prototypes.
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/Makefile.am,v
retrieving revision 1.18
diff -u -p -r1.18 Makefile.am
--- Makefile.am 15 Sep 2004 14:09:12 -0000 1.18
+++ Makefile.am 3 Oct 2004 10:39:40 -0000
@@ -386,11 +386,11 @@ I_M4_DEPS=m4/iparm.m4
I_M4_DEPS0=$(I_M4_DEPS) m4/iforeach.m4
I_M4_DEPS1=$(I_M4_DEPS) m4/ifunction.m4
-selected_int_kind.inc: $(srcdir)/mk-sik-inc.sh
- $(SHELL) $(srcdir)/mk-sik-inc.sh '$(F77COMPILE)' > $@
+selected_int_kind.inc:
+ `$(F77COMPILE) -print-prog-name=f951` -output-integer-type-infos > $@
-selected_real_kind.inc: $(srcdir)/mk-srk-inc.sh
- $(SHELL) $(srcdir)/mk-srk-inc.sh '$(F77COMPILE)' > $@
+selected_real_kind.inc:
+ `$(F77COMPILE) -print-prog-name=f951` -output-real-type-infos > $@
## A 'normal' build shouldn't need to regenerate these
## so we only include them in maintainer mode
Index: lang.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/lang.opt,v
retrieving revision 1.7
diff -u -p -r1.7 lang.opt
--- lang.opt 18 Jul 2004 13:00:34 -0000 1.7
+++ lang.opt 3 Oct 2004 10:41:53 -0000
@@ -133,6 +133,14 @@ i8
F95
Set the default integer kind to double precision
+output-integer-type-infos
+F95
+Output a list of integer kinds in appropriate form for inclusion in the runtime library
+
+output-real-type-infos
+F95
+Output a list of real kinds in appropriate for for inclusion in the runtime library
+
qkind=
F95 RejectNegative Joined UInteger
-qkind=<n> Set the kind for a real with the 'q' exponent to 'n'
Index: options.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/options.c,v
retrieving revision 1.11
diff -u -p -r1.11 options.c
--- options.c 27 Aug 2004 14:49:34 -0000 1.11
+++ options.c 3 Oct 2004 10:41:53 -0000
@@ -281,6 +281,14 @@ gfc_handle_option (size_t scode, const c
gfc_option.max_identifier_length = value;
break;
+ case OPT_output_integer_type_infos:
+ gfc_output_integer_type_infos ();
+ /* Not reached. */
+
+ case OPT_output_real_type_infos:
+ gfc_output_real_type_infos ();
+ /* Not reached. */
+
case OPT_qkind_:
if (gfc_validate_kind (BT_REAL, value, true) < 0)
gfc_fatal_error ("Argument to -fqkind isn't a valid real kind");
Index: trans-types.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-types.c,v
retrieving revision 1.31
diff -u -p -r1.31 trans-types.c
--- trans-types.c 24 Sep 2004 16:26:47 -0000 1.31
+++ trans-types.c 3 Oct 2004 10:41:54 -0000
@@ -1656,5 +1656,59 @@ gfc_signed_type (tree type)
{
return gfc_signed_or_unsigned_type (0, type);
}
+
+/* The following two functions are called when building the
+ library. They output the stuff needed in the implementations of
+ the SELECT_INT_KIND and SELECT_REAL_kIND intrinsics. They are
+ called when the -output-{integer|real}-type-infos command line
+ options are passed. They also terminate program execution. */
+
+void
+gfc_output_integer_type_infos (void)
+{
+ int i, n, k;
+
+ gfc_init_kinds ();
+
+ for (n = 0; n < MAX_INT_KINDS; n++)
+ if (gfc_integer_kinds[n].kind == 0)
+ break;
+
+ printf ("integer, parameter :: c = %d\n"
+ "type (int_info), parameter :: int_infos(c) = (/ &\n", n);
+ for (i = 0; i < n; i++)
+ {
+ k = gfc_integer_kinds[i].kind;
+ printf ("int_info (%d, range(0_%d))%s\n",
+ k, k, (i < n - 1) ? ", &" : " /)");
+ }
+
+ exit (0);
+}
+
+
+void
+gfc_output_real_type_infos (void)
+{
+ int i, n, k;
+
+ gfc_init_kinds ();
+
+ for (n = 0; n < MAX_REAL_KINDS; n++)
+ if (gfc_real_kinds[n].kind == 0)
+ break;
+
+ printf ("integer, parameter :: c = %d\n"
+ "type (real_info), parameter :: real_infos(c) = (/ &\n", n);
+ for (i = 0; i < n; i++)
+ {
+ k = gfc_real_kinds[i].kind;
+ printf ("real_info (%d, precision(0._%d), range(0._%d))%s\n",
+ k, k, k, (i < n - 1) ? ", &" : " /)");
+ }
+
+ exit (0);
+}
+
#include "gt-fortran-trans-types.h"
Index: gfortran.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/gfortran.h,v
retrieving revision 1.38
diff -u -p -r1.38 gfortran.h
--- gfortran.h 17 Sep 2004 17:07:43 -0000 1.38
+++ gfortran.h 3 Oct 2004 10:41:55 -0000
@@ -1556,6 +1556,8 @@ extern int gfc_default_character_kind;
extern int gfc_default_logical_kind;
extern int gfc_default_complex_kind;
extern int gfc_c_int_kind;
+void gfc_output_integer_type_infos (void) ATTRIBUTE_NORETURN;
+void gfc_output_real_type_infos (void) ATTRIBUTE_NORETURN;
/* symbol.c */
void gfc_clear_new_implicit (void);