* [PATCH,fortran] Add pre-defined macros for different available types
@ 2018-12-25 21:49 Steve Kargl
2018-12-25 22:36 ` Steve Kargl
2018-12-28 19:40 ` Steve Kargl
0 siblings, 2 replies; 4+ messages in thread
From: Steve Kargl @ 2018-12-25 21:49 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 747 bytes --]
Here's a Holiday present for Fortranners.
2018-12-25 Steven G. Kargl <kargl@gcc.gnu.org>
* cpp.c (gfc_cpp_init): Add pre-defined macros for INTEGER(1)
INTEGER(2), INTEGER(8) and INTEGER(16) if supported. Add pre-defined
macros for REAL(10) and REAL(16) if available.
* gfortran.texi: Document new macros.
As a Fortran compiler is required to have default integer kind,
default real kind, and double precision, I did not include macros
for these types (ie., there are no __GFC_INTEGER_4__, __GFC_REAL_4__,
and __GFC_REAL_8__).
This allows code like
% cat a.F90
program foo
#ifdef __GFC_REAL_16__
real(16) x
x = 1
print *, x
#endif
end program foo
% gfcx -o z a.F90 && ./z
1.00000000000000000000000000000000000
--
Steve
[-- Attachment #2: cpp.c.diff --]
[-- Type: text/x-diff, Size: 2498 bytes --]
Index: gcc/fortran/cpp.c
===================================================================
--- gcc/fortran/cpp.c (revision 267418)
+++ gcc/fortran/cpp.c (working copy)
@@ -570,6 +570,8 @@ void
gfc_cpp_init (void)
{
int i;
+ gfc_integer_info *int_info;
+ gfc_real_info *real_info;
if (gfc_option.flag_preprocessed)
return;
@@ -607,6 +609,26 @@ gfc_cpp_init (void)
else if (opt->code == OPT_MT || opt->code == OPT_MQ)
deps_add_target (cpp_get_deps (cpp_in),
opt->arg, opt->code == OPT_MQ);
+ }
+
+ for (int_info = gfc_integer_kinds; int_info->kind != 0; int_info++)
+ {
+ if (int_info->kind == 1)
+ cpp_define (cpp_in, "__GFC_INT_1__=1");
+ if (int_info->kind == 2)
+ cpp_define (cpp_in, "__GFC_INT_2__=1");
+ if (int_info->kind == 8)
+ cpp_define (cpp_in, "__GFC_INT_8__=1");
+ if (int_info->kind == 8)
+ cpp_define (cpp_in, "__GFC_INT_16__=1");
+ }
+
+ for (real_info = gfc_real_kinds; real_info->kind != 0; real_info++)
+ {
+ if (real_info->kind == 10)
+ cpp_define (cpp_in, "__GFC_REAL_10__=1");
+ if (real_info->kind == 16)
+ cpp_define (cpp_in, "__GFC_REAL_16__=1");
}
if (gfc_cpp_option.working_directory
Index: gcc/fortran/gfortran.texi
===================================================================
--- gcc/fortran/gfortran.texi (revision 267418)
+++ gcc/fortran/gfortran.texi (working copy)
@@ -418,9 +418,17 @@ statement, the included file is not preprocessed. To
files, use the equivalent preprocessor statement @code{#include}.
If GNU Fortran invokes the preprocessor, @code{__GFORTRAN__}
-is defined and @code{__GNUC__}, @code{__GNUC_MINOR__} and
+is defined. The macros @code{__GNUC__}, @code{__GNUC_MINOR__} and
@code{__GNUC_PATCHLEVEL__} can be used to determine the version of the
compiler. See @ref{Top,,Overview,cpp,The C Preprocessor} for details.
+
+GNU Fortran supports a number of @code{INTEGER} and @code{REAL} kind types
+in additional to the kind types required by the Fortran standard.
+The availability of any given kind type is architecture dependent. The
+following pre-defined preprocessor macros can be used to conditional
+include code for these additional kind types: @code{__GFC_INTEGER_1__},
+@code{__GFC_INTEGER_2__}, @code{__GFC_INTEGER_8__}, @code{__GFC_INTEGER_16__},
+@code{__GFC_REAL_10__}, and @code{__GFC_REAL_16__}.
While CPP is the de-facto standard for preprocessing Fortran code,
Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH,fortran] Add pre-defined macros for different available types
2018-12-25 21:49 [PATCH,fortran] Add pre-defined macros for different available types Steve Kargl
@ 2018-12-25 22:36 ` Steve Kargl
2018-12-28 19:40 ` Steve Kargl
1 sibling, 0 replies; 4+ messages in thread
From: Steve Kargl @ 2018-12-25 22:36 UTC (permalink / raw)
To: fortran, gcc-patches
> + }
> +
> + for (int_info = gfc_integer_kinds; int_info->kind != 0; int_info++)
> + {
> + if (int_info->kind == 1)
> + cpp_define (cpp_in, "__GFC_INT_1__=1");
> + if (int_info->kind == 2)
> + cpp_define (cpp_in, "__GFC_INT_2__=1");
> + if (int_info->kind == 8)
> + cpp_define (cpp_in, "__GFC_INT_8__=1");
> + if (int_info->kind == 8)
yes, that's suppose to be 16.
> + cpp_define (cpp_in, "__GFC_INT_16__=1");
> + }
> +
> + for (real_info = gfc_real_kinds; real_info->kind != 0; real_info++)
> + {
> + if (real_info->kind == 10)
> + cpp_define (cpp_in, "__GFC_REAL_10__=1");
> + if (real_info->kind == 16)
> + cpp_define (cpp_in, "__GFC_REAL_16__=1");
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH,fortran] Add pre-defined macros for different available types
2018-12-25 21:49 [PATCH,fortran] Add pre-defined macros for different available types Steve Kargl
2018-12-25 22:36 ` Steve Kargl
@ 2018-12-28 19:40 ` Steve Kargl
2018-12-29 2:16 ` Jerry DeLisle
1 sibling, 1 reply; 4+ messages in thread
From: Steve Kargl @ 2018-12-28 19:40 UTC (permalink / raw)
To: fortran, gcc-patches
Ping.
On Tue, Dec 25, 2018 at 01:44:10PM -0800, Steve Kargl wrote:
> Here's a Holiday present for Fortranners.
>
> 2018-12-25 Steven G. Kargl <kargl@gcc.gnu.org>
>
> * cpp.c (gfc_cpp_init): Add pre-defined macros for INTEGER(1)
> INTEGER(2), INTEGER(8) and INTEGER(16) if supported. Add pre-defined
> macros for REAL(10) and REAL(16) if available.
> * gfortran.texi: Document new macros.
>
> As a Fortran compiler is required to have default integer kind,
> default real kind, and double precision, I did not include macros
> for these types (ie., there are no __GFC_INTEGER_4__, __GFC_REAL_4__,
> and __GFC_REAL_8__).
>
> This allows code like
>
> % cat a.F90
> program foo
> #ifdef __GFC_REAL_16__
> real(16) x
> x = 1
> print *, x
> #endif
> end program foo
> % gfcx -o z a.F90 && ./z
> 1.00000000000000000000000000000000000
>
> --
> Steve
> Index: gcc/fortran/cpp.c
> ===================================================================
> --- gcc/fortran/cpp.c (revision 267418)
> +++ gcc/fortran/cpp.c (working copy)
> @@ -570,6 +570,8 @@ void
> gfc_cpp_init (void)
> {
> int i;
> + gfc_integer_info *int_info;
> + gfc_real_info *real_info;
>
> if (gfc_option.flag_preprocessed)
> return;
> @@ -607,6 +609,26 @@ gfc_cpp_init (void)
> else if (opt->code == OPT_MT || opt->code == OPT_MQ)
> deps_add_target (cpp_get_deps (cpp_in),
> opt->arg, opt->code == OPT_MQ);
> + }
> +
> + for (int_info = gfc_integer_kinds; int_info->kind != 0; int_info++)
> + {
> + if (int_info->kind == 1)
> + cpp_define (cpp_in, "__GFC_INT_1__=1");
> + if (int_info->kind == 2)
> + cpp_define (cpp_in, "__GFC_INT_2__=1");
> + if (int_info->kind == 8)
> + cpp_define (cpp_in, "__GFC_INT_8__=1");
> + if (int_info->kind == 8)
> + cpp_define (cpp_in, "__GFC_INT_16__=1");
> + }
> +
> + for (real_info = gfc_real_kinds; real_info->kind != 0; real_info++)
> + {
> + if (real_info->kind == 10)
> + cpp_define (cpp_in, "__GFC_REAL_10__=1");
> + if (real_info->kind == 16)
> + cpp_define (cpp_in, "__GFC_REAL_16__=1");
> }
>
> if (gfc_cpp_option.working_directory
> Index: gcc/fortran/gfortran.texi
> ===================================================================
> --- gcc/fortran/gfortran.texi (revision 267418)
> +++ gcc/fortran/gfortran.texi (working copy)
> @@ -418,9 +418,17 @@ statement, the included file is not preprocessed. To
> files, use the equivalent preprocessor statement @code{#include}.
>
> If GNU Fortran invokes the preprocessor, @code{__GFORTRAN__}
> -is defined and @code{__GNUC__}, @code{__GNUC_MINOR__} and
> +is defined. The macros @code{__GNUC__}, @code{__GNUC_MINOR__} and
> @code{__GNUC_PATCHLEVEL__} can be used to determine the version of the
> compiler. See @ref{Top,,Overview,cpp,The C Preprocessor} for details.
> +
> +GNU Fortran supports a number of @code{INTEGER} and @code{REAL} kind types
> +in additional to the kind types required by the Fortran standard.
> +The availability of any given kind type is architecture dependent. The
> +following pre-defined preprocessor macros can be used to conditional
> +include code for these additional kind types: @code{__GFC_INTEGER_1__},
> +@code{__GFC_INTEGER_2__}, @code{__GFC_INTEGER_8__}, @code{__GFC_INTEGER_16__},
> +@code{__GFC_REAL_10__}, and @code{__GFC_REAL_16__}.
>
> While CPP is the de-facto standard for preprocessing Fortran code,
> Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
--
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH,fortran] Add pre-defined macros for different available types
2018-12-28 19:40 ` Steve Kargl
@ 2018-12-29 2:16 ` Jerry DeLisle
0 siblings, 0 replies; 4+ messages in thread
From: Jerry DeLisle @ 2018-12-29 2:16 UTC (permalink / raw)
To: sgk, fortran, gcc-patches
OK Steve,
Jerry
On 12/28/18 10:43 AM, Steve Kargl wrote:
> Ping.
>
> On Tue, Dec 25, 2018 at 01:44:10PM -0800, Steve Kargl wrote:
>> Here's a Holiday present for Fortranners.
>>
>> 2018-12-25 Steven G. Kargl <kargl@gcc.gnu.org>
>>
>> * cpp.c (gfc_cpp_init): Add pre-defined macros for INTEGER(1)
>> INTEGER(2), INTEGER(8) and INTEGER(16) if supported. Add pre-defined
>> macros for REAL(10) and REAL(16) if available.
>> * gfortran.texi: Document new macros.
>>
>> As a Fortran compiler is required to have default integer kind,
>> default real kind, and double precision, I did not include macros
>> for these types (ie., there are no __GFC_INTEGER_4__, __GFC_REAL_4__,
>> and __GFC_REAL_8__).
>>
>> This allows code like
>>
>> % cat a.F90
>> program foo
>> #ifdef __GFC_REAL_16__
>> real(16) x
>> x = 1
>> print *, x
>> #endif
>> end program foo
>> % gfcx -o z a.F90 && ./z
>> 1.00000000000000000000000000000000000
>>
>> --
>> Steve
>
>> Index: gcc/fortran/cpp.c
>> ===================================================================
>> --- gcc/fortran/cpp.c (revision 267418)
>> +++ gcc/fortran/cpp.c (working copy)
>> @@ -570,6 +570,8 @@ void
>> gfc_cpp_init (void)
>> {
>> int i;
>> + gfc_integer_info *int_info;
>> + gfc_real_info *real_info;
>>
>> if (gfc_option.flag_preprocessed)
>> return;
>> @@ -607,6 +609,26 @@ gfc_cpp_init (void)
>> else if (opt->code == OPT_MT || opt->code == OPT_MQ)
>> deps_add_target (cpp_get_deps (cpp_in),
>> opt->arg, opt->code == OPT_MQ);
>> + }
>> +
>> + for (int_info = gfc_integer_kinds; int_info->kind != 0; int_info++)
>> + {
>> + if (int_info->kind == 1)
>> + cpp_define (cpp_in, "__GFC_INT_1__=1");
>> + if (int_info->kind == 2)
>> + cpp_define (cpp_in, "__GFC_INT_2__=1");
>> + if (int_info->kind == 8)
>> + cpp_define (cpp_in, "__GFC_INT_8__=1");
>> + if (int_info->kind == 8)
>> + cpp_define (cpp_in, "__GFC_INT_16__=1");
>> + }
>> +
>> + for (real_info = gfc_real_kinds; real_info->kind != 0; real_info++)
>> + {
>> + if (real_info->kind == 10)
>> + cpp_define (cpp_in, "__GFC_REAL_10__=1");
>> + if (real_info->kind == 16)
>> + cpp_define (cpp_in, "__GFC_REAL_16__=1");
>> }
>>
>> if (gfc_cpp_option.working_directory
>> Index: gcc/fortran/gfortran.texi
>> ===================================================================
>> --- gcc/fortran/gfortran.texi (revision 267418)
>> +++ gcc/fortran/gfortran.texi (working copy)
>> @@ -418,9 +418,17 @@ statement, the included file is not preprocessed. To
>> files, use the equivalent preprocessor statement @code{#include}.
>>
>> If GNU Fortran invokes the preprocessor, @code{__GFORTRAN__}
>> -is defined and @code{__GNUC__}, @code{__GNUC_MINOR__} and
>> +is defined. The macros @code{__GNUC__}, @code{__GNUC_MINOR__} and
>> @code{__GNUC_PATCHLEVEL__} can be used to determine the version of the
>> compiler. See @ref{Top,,Overview,cpp,The C Preprocessor} for details.
>> +
>> +GNU Fortran supports a number of @code{INTEGER} and @code{REAL} kind types
>> +in additional to the kind types required by the Fortran standard.
>> +The availability of any given kind type is architecture dependent. The
>> +following pre-defined preprocessor macros can be used to conditional
>> +include code for these additional kind types: @code{__GFC_INTEGER_1__},
>> +@code{__GFC_INTEGER_2__}, @code{__GFC_INTEGER_8__}, @code{__GFC_INTEGER_16__},
>> +@code{__GFC_REAL_10__}, and @code{__GFC_REAL_16__}.
>>
>> While CPP is the de-facto standard for preprocessing Fortran code,
>> Part 3 of the Fortran 95 standard (ISO/IEC 1539-3:1998) defines
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-12-29 0:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-25 21:49 [PATCH,fortran] Add pre-defined macros for different available types Steve Kargl
2018-12-25 22:36 ` Steve Kargl
2018-12-28 19:40 ` Steve Kargl
2018-12-29 2:16 ` Jerry DeLisle
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).