diff options
author | Tobias Burnus <burnus@net-b.de> | 2010-09-28 21:51:38 +0200 |
---|---|---|
committer | Tobias Burnus <burnus@gcc.gnu.org> | 2010-09-28 21:51:38 +0200 |
commit | 41804a5be02d8d811e5189a9cca9060f41cea765 (patch) | |
tree | f3feddbb7172dda121a8dcfbdba67d925fe2b5df /gcc | |
parent | 770a498aeea017024d45dded87022d3f05bb27c9 (diff) | |
download | gcc-41804a5be02d8d811e5189a9cca9060f41cea765.zip gcc-41804a5be02d8d811e5189a9cca9060f41cea765.tar.gz gcc-41804a5be02d8d811e5189a9cca9060f41cea765.tar.bz2 |
re PR fortran/40569 (F2008: Support COMPILER_OPTIONS() / COMPILER_VERSION())
gcc/
2010-09-28 Tobias Burnus <burnus@net-b.de>
PR fortran/40569
PR fortran/40568
* toplev.h (save_decoded_options, save_decoded_options_count):
New global variables.
* toplev.c (save_decoded_options, save_decoded_options_count):
export variables.
gcc/fortran/
2010-09-28 Tobias Burnus <burnus@net-b.de>
PR fortran/40569
PR fortran/40568
* intrinsic.c (add_functions): Make compiler_version and
compiler_options CLASS_INQUIRY.
* gfortran.h (gfc_get_option_string): New prototype.
* intrinsic.texi (COMPILER_VERSION, COMPILER_OPTIONS):
Add documentation.
(C_SIZEOF): Mark as inquiry function of ISO_C_BINDING.
(ISO_FORTRAN_ENV): Refer to COMPILER_VERSION and COMPILER_OPTIONS.
(ISO_C_BINDING): Refer to C_SIZEOF.
* options.c (gfc_get_option_string): New function.
* simplify.c (gfc_simplify_compiler_options): Use it.
(gfc_simplify_compiler_version): Include compiler name.
From-SVN: r164698
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 9 | ||||
-rw-r--r-- | gcc/fortran/ChangeLog | 16 | ||||
-rw-r--r-- | gcc/fortran/gfortran.h | 1 | ||||
-rw-r--r-- | gcc/fortran/intrinsic.c | 8 | ||||
-rw-r--r-- | gcc/fortran/intrinsic.texi | 96 | ||||
-rw-r--r-- | gcc/fortran/options.c | 77 | ||||
-rw-r--r-- | gcc/fortran/simplify.c | 20 | ||||
-rw-r--r-- | gcc/toplev.c | 4 | ||||
-rw-r--r-- | gcc/toplev.h | 4 |
9 files changed, 222 insertions, 13 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 989d77d..440c257 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2010-09-28 Tobias Burnus <burnus@net-b.de> + + PR fortran/40569 + PR fortran/40568 + * toplev.h (save_decoded_options, save_decoded_options_count): + New global variables. + * toplev.c (save_decoded_options, save_decoded_options_count): + export variables. + 2010-09-28 Ian Lance Taylor <iant@google.com> * config/i386/i386.c (ix86_supports_split_stack): Test diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 138f458..ef7257d 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,19 @@ +2010-09-28 Tobias Burnus <burnus@net-b.de> + + PR fortran/40569 + PR fortran/40568 + * intrinsic.c (add_functions): Make compiler_version and + compiler_options CLASS_INQUIRY. + * gfortran.h (gfc_get_option_string): New prototype. + * intrinsic.texi (COMPILER_VERSION, COMPILER_OPTIONS): + Add documentation. + (C_SIZEOF): Mark as inquiry function of ISO_C_BINDING. + (ISO_FORTRAN_ENV): Refer to COMPILER_VERSION and COMPILER_OPTIONS. + (ISO_C_BINDING): Refer to C_SIZEOF. + * options.c (gfc_get_option_string): New function. + * simplify.c (gfc_simplify_compiler_options): Use it. + (gfc_simplify_compiler_version): Include compiler name. + 2010-09-28 Jan Hubicka <jh@suse.cz> * f95-lang.c (gfc_define_builtin): Make leaf. diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 5fdd0d7..c42be85 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -2403,6 +2403,7 @@ void gfc_init_options (unsigned int, bool gfc_handle_option (size_t, const char *, int, int, const struct cl_option_handlers *); bool gfc_post_options (const char **); +char *gfc_get_option_string (void); /* f95-lang.c */ void gfc_maybe_initialize_eh (void); diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c index 625ff03..436afb7 100644 --- a/gcc/fortran/intrinsic.c +++ b/gcc/fortran/intrinsic.c @@ -2644,13 +2644,13 @@ add_functions (void) make_from_module(); /* COMPILER_OPTIONS and COMPILER_VERSION are part of ISO_FORTRAN_ENV. */ - add_sym_0 ("compiler_options", GFC_ISYM_COMPILER_OPTIONS, CLASS_IMPURE, - ACTUAL_NO, BT_CHARACTER, 1, GFC_STD_F2008, + add_sym_0 ("compiler_options", GFC_ISYM_COMPILER_OPTIONS, CLASS_INQUIRY, + ACTUAL_NO, BT_CHARACTER, dc, GFC_STD_F2008, NULL, gfc_simplify_compiler_options, NULL); make_from_module(); - add_sym_0 ("compiler_version", GFC_ISYM_COMPILER_VERSION, CLASS_IMPURE, - ACTUAL_NO, BT_CHARACTER, 1, GFC_STD_F2008, + add_sym_0 ("compiler_version", GFC_ISYM_COMPILER_VERSION, CLASS_INQUIRY, + ACTUAL_NO, BT_CHARACTER, dc, GFC_STD_F2008, NULL, gfc_simplify_compiler_version, NULL); make_from_module(); diff --git a/gcc/fortran/intrinsic.texi b/gcc/fortran/intrinsic.texi index 5c7d463..09f5278 100644 --- a/gcc/fortran/intrinsic.texi +++ b/gcc/fortran/intrinsic.texi @@ -86,6 +86,8 @@ Some basic guidelines for editing this document: * @code{CMPLX}: CMPLX, Complex conversion function * @code{COMMAND_ARGUMENT_COUNT}: COMMAND_ARGUMENT_COUNT, Get number of command line arguments * @code{COMPLEX}: COMPLEX, Complex conversion function +* @code{COMPILER_VERSION}: COMPILER_VERSION, Compiler version string +* @code{COMPILER_OPTIONS}: COMPILER_OPTIONS, Options passed to the compiler * @code{CONJG}: CONJG, Complex conjugate function * @code{COS}: COS, Cosine function * @code{COSH}: COSH, Hyperbolic cosine function @@ -2363,7 +2365,7 @@ expression @code{X} occupies. Fortran 2008 @item @emph{Class}: -Intrinsic function +Inquiry function of the module @code{ISO_C_BINDING} @item @emph{Syntax}: @code{N = C_SIZEOF(X)} @@ -2375,7 +2377,7 @@ Intrinsic function @item @emph{Return value}: The return value is of type integer and of the system-dependent kind -@var{C_SIZE_T} (from the @var{ISO_C_BINDING} module). Its value is the +@code{C_SIZE_T} (from the @code{ISO_C_BINDING} module). Its value is the number of bytes occupied by the argument. If the argument has the @code{POINTER} attribute, the number of bytes of the storage area pointed to is returned. If the argument is of a derived type with @code{POINTER} @@ -2719,6 +2721,92 @@ end program test_command_argument_count +@node COMPILER_OPTIONS +@section @code{COMPILER_OPTIONS} --- Options passed to the compiler +@fnindex COMPILER_OPTIONS +@cindex flags inquiry function +@cindex options inquiry function +@cindex compiler flags inquiry function + +@table @asis +@item @emph{Description}: +@code{COMPILER_OPTIONS()} returns a string with the options used for +compiling. + +@item @emph{Standard}: +Fortran 2008 + +@item @emph{Class}: +Inquiry function of the module @code{ISO_FORTRAN_ENV} + +@item @emph{Syntax}: +@code{STR = COMPILER_OPTIONS()} + +@item @emph{Arguments}: +None. + +@item @emph{Return value}: +The return value is a default-kind string with system-dependent length. +It contains the compiler flags used to compile the file, which called +the @code{COMPILER_OPTIONS} intrinsic. + +@item @emph{Example}: +@smallexample + use iso_fortran_env + print '(4a)', 'This file was compiled by ', & + compiler_version(), ' using the the options ', & + compiler_options() + end +@end smallexample + +@item @emph{See also}: +@ref{COMPILER_VERSION}, @ref{ISO_FORTRAN_ENV} +@end table + + + +@node COMPILER_VERSION +@section @code{COMPILER_VERSION} --- Compiler version string +@fnindex COMPILER_VERSION +@cindex compiler, name and version +@cindex version of the compiler + +@table @asis +@item @emph{Description}: +@code{COMPILER_VERSION()} returns a string with the name and the +version of the compiler. + +@item @emph{Standard}: +Fortran 2008 + +@item @emph{Class}: +Inquiry function of the module @code{ISO_FORTRAN_ENV} + +@item @emph{Syntax}: +@code{STR = COMPILER_VERSION()} + +@item @emph{Arguments}: +None. + +@item @emph{Return value}: +The return value is a default-kind string with system-dependent length. +It contains the name of the compiler and its version number. + +@item @emph{Example}: +@smallexample + use iso_fortran_env + print '(4a)', 'This file was compiled by ', & + compiler_version(), ' using the the options ', & + compiler_options() + end +@end smallexample + +@item @emph{See also}: +@ref{COMPILER_OPTIONS}, @ref{ISO_FORTRAN_ENV} +@end table + + + @node COMPLEX @section @code{COMPLEX} --- Complex conversion function @fnindex COMPLEX @@ -12685,6 +12773,9 @@ Scalar default-integer constant used as STAT= return value by @code{UNLOCK} to denote that the lock variable is unlocked. (Fortran 2008 or later.) @end table +The module also provides the following intrinsic procedures: +@ref{COMPILER_OPTIONS} and @ref{COMPILER_VERSION}. + @node ISO_C_BINDING @@ -12704,6 +12795,7 @@ manual. @item @code{C_F_PROCPOINTER} @item @code{C_FUNLOC} @item @code{C_LOC} +@item @code{C_SIZEOF} @end table @c TODO: Vertical spacing between C_FUNLOC and C_LOC wrong in PDF, @c don't really know why. diff --git a/gcc/fortran/options.c b/gcc/fortran/options.c index c49620a..f7f76f4 100644 --- a/gcc/fortran/options.c +++ b/gcc/fortran/options.c @@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. If not see #include "flags.h" #include "intl.h" #include "opts.h" +#include "toplev.h" /* For save_decoded_options. */ #include "options.h" #include "params.h" #include "tree-inline.h" @@ -966,3 +967,79 @@ gfc_handle_option (size_t scode, const char *arg, int value, return result; } + + +/* Return a string with the options passed to the compiler; used for + Fortran's compiler_options() intrinsic. */ + +char * +gfc_get_option_string (void) +{ + unsigned j; + size_t len, pos; + char *result; + + /* Determine required string length. */ + + len = 0; + for (j = 1; j < save_decoded_options_count; j++) + { + switch (save_decoded_options[j].opt_index) + { + case OPT_o: + case OPT_d: + case OPT_dumpbase: + case OPT_dumpdir: + case OPT_auxbase: + case OPT_quiet: + case OPT_version: + case OPT_fintrinsic_modules_path: + /* Ignore these. */ + break; + default: + /* Ignore file names. */ + if (save_decoded_options[j].orig_option_with_args_text[0] == '-') + len += 1 + + strlen (save_decoded_options[j].orig_option_with_args_text); + } + } + + result = (char *) gfc_getmem (len); + + pos = 0; + for (j = 1; j < save_decoded_options_count; j++) + { + switch (save_decoded_options[j].opt_index) + { + case OPT_o: + case OPT_d: + case OPT_dumpbase: + case OPT_dumpdir: + case OPT_auxbase: + case OPT_quiet: + case OPT_version: + case OPT_fintrinsic_modules_path: + /* Ignore these. */ + continue; + + case OPT_cpp_: + /* Use "-cpp" rather than "-cpp=<temporary file>". */ + len = 4; + break; + + default: + /* Ignore file names. */ + if (save_decoded_options[j].orig_option_with_args_text[0] != '-') + continue; + + len = strlen (save_decoded_options[j].orig_option_with_args_text); + } + + memcpy (&result[pos], save_decoded_options[j].orig_option_with_args_text, len); + pos += len; + result[pos++] = ' '; + } + + result[--pos] = '\0'; + return result; +} diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index 8748ecf..cdefcb5 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -6739,16 +6739,26 @@ gfc_convert_char_constant (gfc_expr *e, bt type ATTRIBUTE_UNUSED, int kind) gfc_expr * gfc_simplify_compiler_options (void) { - /* FIXME: PR40569 - return the proper compiler arguments. */ - return gfc_get_character_expr (gfc_default_character_kind, - &gfc_current_locus, "", 0); + char *str; + gfc_expr *result; + + str = gfc_get_option_string (); + result = gfc_get_character_expr (gfc_default_character_kind, + &gfc_current_locus, str, strlen (str)); + gfc_free (str); + return result; } gfc_expr * gfc_simplify_compiler_version (void) { + char *buffer; + size_t len; + + len = strlen ("GCC version ") + strlen (version_string) + 1; + buffer = (char*) alloca (len); + snprintf (buffer, len, "GCC version %s", version_string); return gfc_get_character_expr (gfc_default_character_kind, - &gfc_current_locus, version_string, - strlen (version_string)); + &gfc_current_locus, buffer, len); } diff --git a/gcc/toplev.c b/gcc/toplev.c index e43b6d9..cf12b2f 100644 --- a/gcc/toplev.c +++ b/gcc/toplev.c @@ -127,8 +127,8 @@ static bool no_backend; #define MAX_LINE 75 /* Decoded options, and number of such options. */ -static struct cl_decoded_option *save_decoded_options; -static unsigned int save_decoded_options_count; +struct cl_decoded_option *save_decoded_options; +unsigned int save_decoded_options_count; /* Name of top-level original source file (what was input to cpp). This comes from the #-command at the beginning of the actual input. diff --git a/gcc/toplev.h b/gcc/toplev.h index 6de27a0..c72f468 100644 --- a/gcc/toplev.h +++ b/gcc/toplev.h @@ -29,6 +29,10 @@ along with GCC; see the file COPYING3. If not see #define skip_leading_substring(whole, part) \ (strncmp (whole, part, strlen (part)) ? NULL : whole + strlen (part)) +/* Decoded options, and number of such options. */ +extern struct cl_decoded_option *save_decoded_options; +extern unsigned int save_decoded_options_count; + extern int toplev_main (int, char **); extern void strip_off_ending (char *, int); extern void rest_of_decl_compilation (tree, int, int); |