This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFA: Enabling options with preprocessor conditions


The SH port uses preprocessors macros (usually defined in config.gcc)
to enable or disable certain options.  Disabled options are not recognised
at all: they aren't accepted by the parser and don't appear in the
--help output.

One way of coping with this would be to have separate .opt files
for every group of conditionally-defined options.  But there are
quite a few different groups of options and the rules governing
them are quite complex.  It would be much easier to handle the SH
port if the C declarations for every option were always available
and if certain options could be hidden from the user using
preprocessor conditions.

The patch below does that by adding a new flag called CL_DISABLED.
This flag is conceptually a "grouping" option in the same vein as
CL_TARGET, CL_COMMON and the language-specific flags.

The patch also adds a new option flag, "Condition(FOO)", to say
that an option is only available when condition FOO is true.

If the user uses a disabled option, we could simply pretend that
it doesn't exist, and report the usual "not recognised" error.
However, if the user uses an option for a different language,
we try to be helpful and say that it _is_ recognised, but isn't
available.  I went for the same approach here.

Also, the new flag means that options.c needs to include "tm.h"
(and therefore config.h, system.h and coretypes.h) so that it
can check the preprocessor conditions.  There seems to be some
attempt to avoid hard-coding gccisms in optc-gen.awk, in that
the name of the header file is passed on the command line.  I've
stuck with the spirit of that and simply extended the "header_name"
variable so that it can be a space-separated list.

Tested with the upcoming SH patch on targets like sh-elf.  Also tested
with "make info" and "make dvi".  OK to install?

Richard



	* Makefile.in (options.c): Tell optc-gen.awk to include config.h,
	system.h, coretypes.h and tm.h.
	(options.o): Update dependencies accordingly.
	* optc-gen.awk: Allow header_name to be a list of filenames.
	Handle the "Condition" flag.
	* opts.h (CL_DISABLED): New flag.
	* opts.c (handle_option): Print an error for CL_DISABLED options.
	* doc/options.texi: Document the "Condition" option flag.

Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1482
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.1482 Makefile.in
--- Makefile.in	8 May 2005 21:22:19 -0000	1.1482
+++ Makefile.in	15 May 2005 21:10:16 -0000
@@ -1569,7 +1569,7 @@ s-options: $(ALL_OPT_FILES) Makefile $(s
 
 options.c: optionlist $(srcdir)/opt-functions.awk $(srcdir)/optc-gen.awk
 	$(AWK) -f $(srcdir)/opt-functions.awk -f $(srcdir)/optc-gen.awk \
-	       -v header_name="options.h" < $< > $@ 
+	       -v header_name="config.h system.h coretypes.h tm.h" < $< > $@ 
 
 options.h: s-options-h ; @true
 s-options-h: optionlist $(srcdir)/opt-functions.awk $(srcdir)/opth-gen.awk
@@ -1578,7 +1578,7 @@ s-options-h: optionlist $(srcdir)/opt-fu
 	$(SHELL) $(srcdir)/../move-if-change tmp-options.h options.h
 	$(STAMP) $@
 
-options.o: options.c options.h opts.h intl.h
+options.o: options.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) opts.h intl.h
 
 dumpvers: dumpvers.c
 
Index: optc-gen.awk
===================================================================
RCS file: /cvs/gcc/gcc/gcc/optc-gen.awk,v
retrieving revision 2.6
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r2.6 optc-gen.awk
--- optc-gen.awk	15 May 2005 08:10:10 -0000	2.6
+++ optc-gen.awk	15 May 2005 21:10:16 -0000
@@ -57,7 +57,9 @@ END {
 print "/* This file is auto-generated by opts.sh.  */"
 print ""
 print "#include <intl.h>"
-print "#include " quote header_name quote
+n_headers = split (header_name, headers, " ")
+for (i = 1; i <= n_headers; i++)
+	print "#include " quote headers[i] quote
 print "#include " quote "opts.h" quote
 print ""
 
@@ -135,10 +137,20 @@ for (i = 0; i < n_opts; i++) {
 	else
 		hlp = quote help[i] quote;
 
-	printf("  { %c-%s%c,\n    %s,\n    %s, %u, %s, %s, %s }%s\n",
-		quote, opts[i], quote, hlp, back_chain[i], len,
-		switch_flags(flags[i]),
-		var_ref(flags[i]), var_set(flags[i]), comma)
+	printf("  { %c-%s%c,\n    %s,\n    %s, %u,\n",
+	       quote, opts[i], quote, hlp, back_chain[i], len)
+	condition = opt_args("Condition", flags[i])
+	cl_flags = switch_flags(flags[i])
+	if (condition != "")
+		printf ("#if %s\n" \
+			"    %s,\n" \
+			"#else\n" \
+			"    CL_DISABLED,\n" \
+			"#endif\n",
+			condition, cl_flags, cl_flags)
+	else
+		printf ("    %s,\n", cl_flags)
+	printf("    %s, %s }%s\n", var_ref(flags[i]), var_set(flags[i]), comma)
 }
 
 print "};"
Index: opts.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.h,v
retrieving revision 1.21
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.21 opts.h
--- opts.h	3 May 2005 17:55:38 -0000	1.21
+++ opts.h	15 May 2005 21:10:16 -0000
@@ -52,6 +52,7 @@ extern const struct cl_option cl_options
 extern const unsigned int cl_options_count;
 extern const char *const lang_names[];
 
+#define CL_DISABLED		(1 << 21) /* Disabled in this configuration.  */
 #define CL_TARGET		(1 << 22) /* Target-specific option.  */
 #define CL_REPORT		(1 << 23) /* Report argument with -fverbose-asm  */
 #define CL_JOINED		(1 << 24) /* If takes joined argument.  */
Index: opts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opts.c,v
retrieving revision 1.107
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.107 opts.c
--- opts.c	4 May 2005 01:36:13 -0000	1.107
+++ opts.c	15 May 2005 21:10:16 -0000
@@ -315,6 +315,14 @@ handle_option (const char **argv, unsign
   /* We've recognized this switch.  */
   result = 1;
 
+  /* Check to see if the condition is disabled for this configuration.  */
+  if (option->flags & CL_DISABLED)
+    {
+      error ("command line option %qs"
+	     " is not supported by this configuration", opt);
+      goto done;
+    }
+
   /* Sort out any argument the switch takes.  */
   if (option->flags & CL_JOINED)
     {
Index: doc/options.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/options.texi,v
retrieving revision 1.5
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r1.5 options.texi
--- doc/options.texi	30 Apr 2005 16:05:21 -0000	1.5
+++ doc/options.texi	15 May 2005 21:10:16 -0000
@@ -191,4 +191,11 @@ The state of the option should be printe
 @item Undocumented
 The option is deliberately missing documentation and should not
 be included in the @option{--help} output.
+
+@item Condition(@var{cond})
+The option should only be accepted if preprocessor condition
+@var{cond} is true.  Note that any C declarations associated with the
+option will be present even if @var{cond} is false; @var{cond} simply
+controls whether the option is accepted and whether it is printed in
+the @option{--help} output.
 @end table


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]