This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH RFC] Take into account OVERRIDE_OPTIONS when printing help messages
- From: Kaz Kojima <kkojima at rr dot iij4u dot or dot jp>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 25 May 2010 05:59:42 +0900 (JST)
- Subject: [PATCH RFC] Take into account OVERRIDE_OPTIONS when printing help messages
Hi,
When I modified OVERRIDE_OPTIONS, I noticed that cc1 --help
doesn't report the changes I made. The attached patch is
a trial to reflect OVERRIDE_OPTIONS to the result printed
with the help options.
Here is an example of the difference between --help messages
without/with the patch for my i386 compiler at -O2.
# 656,657c656,657
# < -falign-functions [enabled]
# < -falign-jumps [enabled]
# ---
# > -falign-functions [disabled]
# > -falign-jumps [disabled]
# 659,660c659,660
# < -falign-loops [disabled]
# < -fasynchronous-unwind-tables [enabled]
# ---
# > -falign-loops [enabled]
# > -fasynchronous-unwind-tables [disabled]
# 718c718
# < -fomit-frame-pointer [enabled]
# ---
# > -fomit-frame-pointer [disabled]
# 826c826
# < -maccumulate-outgoing-args [disabled]
# ---
# > -maccumulate-outgoing-args [enabled]
# 833c833
# < -march=
# ---
# > -march= i386
# 867c867
# < -mred-zone [enabled]
# ---
# > -mred-zone [disabled]
# 870c870
# < -msahf [disabled]
# ---
# > -msahf [enabled]
# 883c883
# < -mstackrealign [enabled]
# ---
# > -mstackrealign [disabled]
# 887c887
# < -mtune=
# ---
# > -mtune= generic32
# 970c970
# < -fpcc-struct-return [disabled]
# ---
# > -fpcc-struct-return [enabled]
The patch is tested with native i686-pc-linux-gnu, with no
regressions.
Regards,
kaz
--
2010-05-24 Kaz Kojima <kkojima@gcc.gnu.org>
* opts.c (read_cmdline_option): Add DO_PRINT_HELP argument.
Call handle_help_option if DO_PRINT_HELP is true.
(read_cmdline_options): Tune read_cmdline_option call.
(print_cmdline_options): New.
(decode_options): Call print_cmdline_options if exit_after_options
is set.
(common_handle_option): Move the code for printing specific help
messages to handle_help_option.
(handle_help_option): New.
diff -up ORIG/trunk/gcc/opts.c trunk/gcc/opts.c
--- ORIG/trunk/gcc/opts.c 2010-05-21 09:25:39.000000000 +0900
+++ trunk/gcc/opts.c 2010-05-24 10:15:17.000000000 +0900
@@ -373,6 +373,7 @@ unsigned num_in_fnames;
static int common_handle_option (size_t scode, const char *arg, int value,
unsigned int lang_mask, int kind);
+static void handle_help_option (size_t scode, const char *arg);
static void handle_param (const char *);
static char *write_langs (unsigned int lang_mask);
static void complain_wrong_lang (const char *, const struct cl_option *,
@@ -531,9 +532,11 @@ handle_option (int opt_index, int value,
}
/* Handle the switch beginning at ARGV for the language indicated by
- LANG_MASK. Returns the number of switches consumed. */
+ LANG_MASK. Returns the number of switches consumed. When set
+ DO_PRINT_HELP, print specific help. */
static unsigned int
-read_cmdline_option (const char **argv, unsigned int lang_mask)
+read_cmdline_option (const char **argv, unsigned int lang_mask,
+ bool do_print_help)
{
size_t opt_index;
const char *opt, *arg = 0;
@@ -654,7 +657,12 @@ read_cmdline_option (const char **argv,
}
}
- if (!handle_option (opt_index, value, arg, lang_mask, DK_UNSPECIFIED))
+ if (do_print_help)
+ {
+ handle_help_option (opt_index, arg);
+ result = 0;
+ }
+ else if (!handle_option (opt_index, value, arg, lang_mask, DK_UNSPECIFIED))
result = 0;
done:
@@ -778,7 +786,7 @@ read_cmdline_options (unsigned int argc,
continue;
}
- n = read_cmdline_option (argv + i, lang_mask);
+ n = read_cmdline_option (argv + i, lang_mask, false);
if (!n)
{
@@ -788,6 +796,26 @@ read_cmdline_options (unsigned int argc,
}
}
+/* Decode options and print specific help. */
+static void
+print_cmdline_options (unsigned int argc, const char **argv,
+ unsigned int lang_mask)
+{
+ unsigned int i;
+
+#ifdef OVERRIDE_OPTIONS
+ /* Some machines may reject certain combinations of options. */
+ OVERRIDE_OPTIONS;
+#endif
+ for (i = 1; i < argc; i++)
+ {
+ const char *opt = argv[i];
+
+ if (opt[0] == '-' && opt[1] != '\0')
+ read_cmdline_option (argv + i, lang_mask, true);
+ }
+}
+
/* Parse command line options and set default flag values. Do minimal
options processing. */
void
@@ -1172,6 +1200,9 @@ decode_options (unsigned int argc, const
check option consistency. */
if (flag_lto && flag_whopr)
error ("-flto and -fwhopr are mutually exclusive");
+
+ if (exit_after_options)
+ print_cmdline_options (argc, argv, lang_mask);
}
#define LEFT_COLUMN 27
@@ -1489,7 +1520,6 @@ static int
common_handle_option (size_t scode, const char *arg, int value,
unsigned int lang_mask, int kind ATTRIBUTE_UNUSED)
{
- static bool verbose = false;
enum opt_code code = (enum opt_code) scode;
switch (code)
@@ -1499,159 +1529,14 @@ common_handle_option (size_t scode, cons
break;
case OPT_v:
- verbose = true;
break;
case OPT_fhelp:
case OPT__help:
- {
- unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
- unsigned int undoc_mask;
- unsigned int i;
-
- undoc_mask = (verbose | extra_warnings) ? 0 : CL_UNDOCUMENTED;
- /* First display any single language specific options. */
- for (i = 0; i < cl_lang_count; i++)
- print_specific_help
- (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0);
- /* Next display any multi language specific options. */
- print_specific_help (0, undoc_mask, all_langs_mask);
- /* Then display any remaining, non-language options. */
- for (i = CL_MIN_OPTION_CLASS; i <= CL_MAX_OPTION_CLASS; i <<= 1)
- print_specific_help (i, undoc_mask, 0);
- exit_after_options = true;
- break;
- }
-
case OPT_ftarget_help:
case OPT__target_help:
- print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0);
- exit_after_options = true;
-
- /* Allow the target a chance to give the user some additional information. */
- if (targetm.target_help)
- targetm.target_help ();
- break;
-
case OPT_fhelp_:
case OPT__help_:
- {
- const char * a = arg;
- unsigned int include_flags = 0;
- /* Note - by default we include undocumented options when listing
- specific classes. If you only want to see documented options
- then add ",^undocumented" to the --help= option. E.g.:
-
- --help=target,^undocumented */
- unsigned int exclude_flags = 0;
-
- /* Walk along the argument string, parsing each word in turn.
- The format is:
- arg = [^]{word}[,{arg}]
- word = {optimizers|target|warnings|undocumented|
- params|common|<language>} */
- while (* a != 0)
- {
- static struct
- {
- const char * string;
- unsigned int flag;
- }
- specifics[] =
- {
- { "optimizers", CL_OPTIMIZATION },
- { "target", CL_TARGET },
- { "warnings", CL_WARNING },
- { "undocumented", CL_UNDOCUMENTED },
- { "params", CL_PARAMS },
- { "joined", CL_JOINED },
- { "separate", CL_SEPARATE },
- { "common", CL_COMMON },
- { NULL, 0 }
- };
- unsigned int * pflags;
- const char * comma;
- unsigned int lang_flag, specific_flag;
- unsigned int len;
- unsigned int i;
-
- if (* a == '^')
- {
- ++ a;
- pflags = & exclude_flags;
- }
- else
- pflags = & include_flags;
-
- comma = strchr (a, ',');
- if (comma == NULL)
- len = strlen (a);
- else
- len = comma - a;
- if (len == 0)
- {
- a = comma + 1;
- continue;
- }
-
- /* Check to see if the string matches an option class name. */
- for (i = 0, specific_flag = 0; specifics[i].string != NULL; i++)
- if (strncasecmp (a, specifics[i].string, len) == 0)
- {
- specific_flag = specifics[i].flag;
- break;
- }
-
- /* Check to see if the string matches a language name.
- Note - we rely upon the alpha-sorted nature of the entries in
- the lang_names array, specifically that shorter names appear
- before their longer variants. (i.e. C before C++). That way
- when we are attempting to match --help=c for example we will
- match with C first and not C++. */
- for (i = 0, lang_flag = 0; i < cl_lang_count; i++)
- if (strncasecmp (a, lang_names[i], len) == 0)
- {
- lang_flag = 1U << i;
- break;
- }
-
- if (specific_flag != 0)
- {
- if (lang_flag == 0)
- * pflags |= specific_flag;
- else
- {
- /* The option's argument matches both the start of a
- language name and the start of an option class name.
- We have a special case for when the user has
- specified "--help=c", but otherwise we have to issue
- a warning. */
- if (strncasecmp (a, "c", len) == 0)
- * pflags |= lang_flag;
- else
- fnotice (stderr,
- "warning: --help argument %.*s is ambiguous, please be more specific\n",
- len, a);
- }
- }
- else if (lang_flag != 0)
- * pflags |= lang_flag;
- else
- fnotice (stderr,
- "warning: unrecognized argument to --help= option: %.*s\n",
- len, a);
-
- if (comma == NULL)
- break;
- a = comma + 1;
- }
-
- if (include_flags)
- print_specific_help (include_flags, exclude_flags, 0);
- exit_after_options = true;
- break;
- }
-
case OPT_fversion:
case OPT__version:
exit_after_options = true;
@@ -2185,6 +2070,172 @@ common_handle_option (size_t scode, cons
return 1;
}
+/* Handle help options and print specific help messages. */
+static void
+handle_help_option (size_t scode, const char *arg)
+{
+ static bool verbose = false;
+ enum opt_code code = (enum opt_code) scode;
+
+ switch (code)
+ {
+ case OPT_v:
+ verbose = true;
+ break;
+
+ case OPT_fhelp:
+ case OPT__help:
+ {
+ unsigned int all_langs_mask = (1U << cl_lang_count) - 1;
+ unsigned int undoc_mask;
+ unsigned int i;
+
+ undoc_mask = (verbose | extra_warnings) ? 0 : CL_UNDOCUMENTED;
+ /* First display any single language specific options. */
+ for (i = 0; i < cl_lang_count; i++)
+ print_specific_help
+ (1U << i, (all_langs_mask & (~ (1U << i))) | undoc_mask, 0);
+ /* Next display any multi language specific options. */
+ print_specific_help (0, undoc_mask, all_langs_mask);
+ /* Then display any remaining, non-language options. */
+ for (i = CL_MIN_OPTION_CLASS; i <= CL_MAX_OPTION_CLASS; i <<= 1)
+ print_specific_help (i, undoc_mask, 0);
+ break;
+ }
+
+ case OPT_ftarget_help:
+ case OPT__target_help:
+ print_specific_help (CL_TARGET, CL_UNDOCUMENTED, 0);
+
+ /* Allow the target a chance to give the user some additional
+ information. */
+ if (targetm.target_help)
+ targetm.target_help ();
+ break;
+
+ case OPT_fhelp_:
+ case OPT__help_:
+ {
+ const char * a = arg;
+ unsigned int include_flags = 0;
+ /* Note - by default we include undocumented options when listing
+ specific classes. If you only want to see documented options
+ then add ",^undocumented" to the --help= option. E.g.:
+
+ --help=target,^undocumented */
+ unsigned int exclude_flags = 0;
+
+ /* Walk along the argument string, parsing each word in turn.
+ The format is:
+ arg = [^]{word}[,{arg}]
+ word = {optimizers|target|warnings|undocumented|
+ params|common|<language>} */
+ while (* a != 0)
+ {
+ static struct
+ {
+ const char * string;
+ unsigned int flag;
+ }
+ specifics[] =
+ {
+ { "optimizers", CL_OPTIMIZATION },
+ { "target", CL_TARGET },
+ { "warnings", CL_WARNING },
+ { "undocumented", CL_UNDOCUMENTED },
+ { "params", CL_PARAMS },
+ { "joined", CL_JOINED },
+ { "separate", CL_SEPARATE },
+ { "common", CL_COMMON },
+ { NULL, 0 }
+ };
+ unsigned int * pflags;
+ const char * comma;
+ unsigned int lang_flag, specific_flag;
+ unsigned int len;
+ unsigned int i;
+
+ if (* a == '^')
+ {
+ ++ a;
+ pflags = & exclude_flags;
+ }
+ else
+ pflags = & include_flags;
+
+ comma = strchr (a, ',');
+ if (comma == NULL)
+ len = strlen (a);
+ else
+ len = comma - a;
+ if (len == 0)
+ {
+ a = comma + 1;
+ continue;
+ }
+
+ /* Check to see if the string matches an option class name. */
+ for (i = 0, specific_flag = 0; specifics[i].string != NULL; i++)
+ if (strncasecmp (a, specifics[i].string, len) == 0)
+ {
+ specific_flag = specifics[i].flag;
+ break;
+ }
+
+ /* Check to see if the string matches a language name.
+ Note - we rely upon the alpha-sorted nature of the entries in
+ the lang_names array, specifically that shorter names appear
+ before their longer variants. (i.e. C before C++). That way
+ when we are attempting to match --help=c for example we will
+ match with C first and not C++. */
+ for (i = 0, lang_flag = 0; i < cl_lang_count; i++)
+ if (strncasecmp (a, lang_names[i], len) == 0)
+ {
+ lang_flag = 1U << i;
+ break;
+ }
+
+ if (specific_flag != 0)
+ {
+ if (lang_flag == 0)
+ * pflags |= specific_flag;
+ else
+ {
+ /* The option's argument matches both the start of a
+ language name and the start of an option class name.
+ We have a special case for when the user has
+ specified "--help=c", but otherwise we have to issue
+ a warning. */
+ if (strncasecmp (a, "c", len) == 0)
+ * pflags |= lang_flag;
+ else
+ fnotice (stderr,
+ "warning: --help argument %.*s is ambiguous, please be more specific\n",
+ len, a);
+ }
+ }
+ else if (lang_flag != 0)
+ * pflags |= lang_flag;
+ else
+ fnotice (stderr,
+ "warning: unrecognized argument to --help= option: %.*s\n",
+ len, a);
+
+ if (comma == NULL)
+ break;
+ a = comma + 1;
+ }
+
+ if (include_flags)
+ print_specific_help (include_flags, exclude_flags, 0);
+ break;
+ }
+
+ default:
+ break;
+ }
+}
+
/* Handle --param NAME=VALUE. */
static void
handle_param (const char *carg)