From patchwork Tue Sep 28 08:17:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 65939 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id E0F79B70F0 for ; Tue, 28 Sep 2010 18:17:52 +1000 (EST) Received: (qmail 23508 invoked by alias); 28 Sep 2010 08:17:44 -0000 Received: (qmail 23481 invoked by uid 22791); 28 Sep 2010 08:17:40 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, TW_CP X-Spam-Check-By: sourceware.org Received: from mx02.qsc.de (HELO mx02.qsc.de) (213.148.130.14) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 28 Sep 2010 08:17:30 +0000 Received: from [192.168.178.22] (port-92-204-109-183.dynamic.qsc.de [92.204.109.183]) by mx02.qsc.de (Postfix) with ESMTP id E6E4C1E8A6; Tue, 28 Sep 2010 10:17:27 +0200 (CEST) Message-ID: <4CA1A497.7040405@net-b.de> Date: Tue, 28 Sep 2010 10:17:27 +0200 From: Tobias Burnus User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100914 SUSE/3.1.4 Thunderbird/3.1.4 MIME-Version: 1.0 To: gcc patches , gfortran Subject: [Patch] gcc/toplev.{c, h} + PR fortran/{40569, 40568} compiler_options() + fixes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org The gcc/toplev.{c,h} part of the patch needs middle-end review, the rest is in the Fortran FE. The patch exports the "save_decoded_options" in gcc/toplev.{c,h} and uses it in gcc/fortran/options.c to construct a string with the compiler flags. Additionally changed: - Add documentation - Include compiler name in compiler_version ("value that identi es the name and version [...] of the processor") - Mark the functions as inquiry functions The patch was build and loosely tested. It is currently bootstrapping and will then be regtested on x86-64-linux. OK for the trunk? Example: use iso_fortran_env print '(5a)', 'This file was compiled by "', & compiler_version(), '" using the the options "', & compiler_options(),'"' end That gives: $ gfortran -march=native -m32 hjf34.f90 && ./a.out This file was compiled by "GCC version 4.6.0 20100928 (experimental) [trunk revision 164668]" using the the options "-march=k8-sse3 -msahf --param l1-cache-size=64 --param l1-cache-line-size=64 --param l2-cache-size=1024 -mtune=k8 -m32" $ gfortran -Dignored hjf34.f90 && ./a.out This file was compiled by "GCC version 4.6.0 20100928 (experimental) [trunk revision 164668]" using the the options "-mtune=generic -march=x86-64" $ gfortran -Dwith=cpp -cpp hjf34.f90 && ./a.out This file was compiled by "GCC version 4.6.0 20100928 (experimental) [trunk revision 164668]" using the the options "-cpp -D with=cpp -mtune=generic -march=x86-64" Tobias PS: Still to do: -Wall fixes (bogus warning regarding functions already typed), inquiry fixes in expr.c's check_inquiry. gcc/ 2010-09-28 Tobias Burnus 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 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. Index: gcc/toplev.c =================================================================== --- gcc/toplev.c (revision 164676) +++ gcc/toplev.c (working copy) @@ -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. Index: gcc/toplev.h =================================================================== --- gcc/toplev.h (revision 164676) +++ gcc/toplev.h (working copy) @@ -29,6 +29,11 @@ along with GCC; see the file COPYING3. #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); Index: gcc/fortran/intrinsic.c =================================================================== --- gcc/fortran/intrinsic.c (revision 164676) +++ gcc/fortran/intrinsic.c (working copy) @@ -2644,12 +2644,12 @@ 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, + add_sym_0 ("compiler_options", GFC_ISYM_COMPILER_OPTIONS, CLASS_INQUIRY, ACTUAL_NO, BT_CHARACTER, 1, GFC_STD_F2008, NULL, gfc_simplify_compiler_options, NULL); make_from_module(); - add_sym_0 ("compiler_version", GFC_ISYM_COMPILER_VERSION, CLASS_IMPURE, + add_sym_0 ("compiler_version", GFC_ISYM_COMPILER_VERSION, CLASS_INQUIRY, ACTUAL_NO, BT_CHARACTER, 1, GFC_STD_F2008, NULL, gfc_simplify_compiler_version, NULL); make_from_module(); Index: gcc/fortran/gfortran.h =================================================================== --- gcc/fortran/gfortran.h (revision 164676) +++ gcc/fortran/gfortran.h (working copy) @@ -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); Index: gcc/fortran/intrinsic.texi =================================================================== --- gcc/fortran/intrinsic.texi (revision 164676) +++ gcc/fortran/intrinsic.texi (working copy) @@ -86,6 +86,8 @@ Some basic guidelines for editing this d * @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 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. Index: gcc/fortran/options.c =================================================================== --- gcc/fortran/options.c (revision 164676) +++ gcc/fortran/options.c (working copy) @@ -27,6 +27,7 @@ along with GCC; see the file COPYING3. #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,75 @@ gfc_handle_option (size_t scode, const c return result; } + + +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. */ + continue; + } + + /* 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=". */ + 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; +} Index: gcc/fortran/simplify.c =================================================================== --- gcc/fortran/simplify.c (revision 164676) +++ gcc/fortran/simplify.c (working copy) @@ -6739,16 +6739,26 @@ gfc_convert_char_constant (gfc_expr *e, 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); }