This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [gfortran] Let f951 generate type infos for SELECTED_*_KIND
Tobias Schlüter wrote:
> Paul Brook wrote:
>
>>Can't you rename the option to -fsomething? That should be passed properly, so
>>you won't need the --print-prog-name= stuff. You can just do gfortran
>>-fsomething -o file.inc.
>
>
> Won't work per se, because the driver only calls the compiler if a source file
> is given. This can of course be helped by adding a bogus filename to the
> command line.
>
Revised patch attached. This renames the flags to -foutput-real-type-infos and
-foutput-integer-type-infos. But even with this we have to play some tricks to
make the driver invoke the compiler, and I'm not sure if this is the right way
to do this. I contemplated using '-x f95 /dev/zero' as source file (it won't
actually be read, this is only meant to satisfy the driver), but this might
not be portable. I also realized that this might not be stage 3 material. I
would still appreciate if someone tried if this does the right thing on a
multilibbed target.
- Tobi
2004-10-05 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 (foutput-integer-type-infos, foutput-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: gcc/fortran/gfortran.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/gfortran.h,v
retrieving revision 1.39
diff -u -p -r1.39 gfortran.h
--- gcc/fortran/gfortran.h 4 Oct 2004 21:30:26 -0000 1.39
+++ gcc/fortran/gfortran.h 5 Oct 2004 18:57:04 -0000
@@ -1557,6 +1557,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);
Index: gcc/fortran/lang.opt
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/lang.opt,v
retrieving revision 1.7
diff -u -p -r1.7 lang.opt
--- gcc/fortran/lang.opt 18 Jul 2004 13:00:34 -0000 1.7
+++ gcc/fortran/lang.opt 5 Oct 2004 18:57:04 -0000
@@ -85,6 +85,14 @@ ffree-form
F95
Assume that the source file is free form
+foutput-integer-type-infos
+F95
+Output a list of integer kinds in appropriate form for inclusion in the runtime library
+
+foutput-real-type-infos
+F95
+Output a list of real kinds in appropriate for for inclusion in the runtime library
+
funderscoring
F95
Append underscores to externally visible names
Index: gcc/fortran/options.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/options.c,v
retrieving revision 1.11
diff -u -p -r1.11 options.c
--- gcc/fortran/options.c 27 Aug 2004 14:49:34 -0000 1.11
+++ gcc/fortran/options.c 5 Oct 2004 18:57:04 -0000
@@ -256,6 +256,14 @@ gfc_handle_option (size_t scode, const c
gfc_option.flag_no_backend = value;
break;
+ case OPT_foutput_integer_type_infos:
+ gfc_output_integer_type_infos ();
+ /* Not reached. */
+
+ case OPT_foutput_real_type_infos:
+ gfc_output_real_type_infos ();
+ /* Not reached. */
+
case OPT_fpack_derived:
gfc_option.flag_pack_derived = value;
break;
Index: gcc/fortran/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
--- gcc/fortran/trans-types.c 24 Sep 2004 16:26:47 -0000 1.31
+++ gcc/fortran/trans-types.c 5 Oct 2004 18:57:06 -0000
@@ -1656,5 +1656,63 @@ 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 -foutput-{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 ("! automatically generated via the -foutput-integer-type-infos\n"
+ "! command line option\n"
+ "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 ("! automatically generated via the -foutput-real-type-infos\n"
+ "! command line option\n"
+ "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: libgfortran/Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libgfortran/Makefile.am,v
retrieving revision 1.20
diff -u -p -r1.20 Makefile.am
--- libgfortran/Makefile.am 4 Oct 2004 21:30:27 -0000 1.20
+++ libgfortran/Makefile.am 5 Oct 2004 18:57:43 -0000
@@ -388,11 +388,22 @@ 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_real_kind.inc: $(srcdir)/mk-srk-inc.sh
- $(SHELL) $(srcdir)/mk-srk-inc.sh '$(F77COMPILE)' > $@
+## we have to create the temporary file, because the driver checks if the
+## file exists, and doesn't call the compiler if it doesn't. This in turn
+## forces us to use the '-c' option, because otherwise the driver invokes
+## linker for the non-existant ouput file.
+## We have to go through the compiler dirver in order to get the correct
+## options in case of a multilibbed target.
+
+selected_int_kind.inc:
+ echo > call_compiler.f90
+ $(F77COMPILE) -c -foutput-integer-type-infos call_compiler.f90 > $@
+ rm call_compiler.f90
+
+selected_real_kind.inc:
+ echo > call_compiler.f90
+ $(F77COMPILE) -c -foutput-real-type-infos call_compiler.f90 > $@
+ rm call_compiler.f90
## A 'normal' build shouldn't need to regenerate these
## so we only include them in maintainer mode