Modula-2: Add claimed command line options to lang.opt [PR108555].

Message ID 20230126202745.49379-1-iain@sandoe.co.uk
State New
Headers
Series Modula-2: Add claimed command line options to lang.opt [PR108555]. |

Commit Message

Iain Sandoe Jan. 26, 2023, 8:27 p.m. UTC
  This has been retested on x86_64, powerpc64 linux-gnu (with 32b multilibs)
 on i686, powerpc darwin  (with 64b multilibs), x86_64 darwin with and
 without 32b multilibs,
 OK for trunk?
 thanks
 Iain
 
 --- 8< ---

This is a partial reversion of the changes in r13-5373-g80cf2c5e8f496b.

As observed in the PR, handling the C and Driver options in the Modula-2
lang-specific code could be difficult to emulate; This reverts to adding
the required options to the language-specific .opt file.

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>

	PR modula2/108555
	PR modula2/108182
	PR modula2/102343

gcc/m2/ChangeLog:

	* gm2-lang.cc (gm2_langhook_option_lang_mask): Do not claim CL_C
	or CL_DRIVER.
	(gm2_langhook_init_options): Handle options that we want to pass
	to the preprocessor.
	* lang-specs.h: Pass -B and -save-temps to regular compile lines.
	* lang.opt: Add C and Driver options that Modula-2 intercepts for
	internal use. Reorder options into two sections and to collate.
---
 gcc/m2/gm2-lang.cc  |  53 ++++++-------
 gcc/m2/lang-specs.h |   5 +-
 gcc/m2/lang.opt     | 185 +++++++++++++++++++++++++++++++++++---------
 3 files changed, 177 insertions(+), 66 deletions(-)
  

Comments

Richard Biener Jan. 27, 2023, 7:46 a.m. UTC | #1
On Thu, 26 Jan 2023, Iain Sandoe wrote:

>  This has been retested on x86_64, powerpc64 linux-gnu (with 32b multilibs)
>  on i686, powerpc darwin  (with 64b multilibs), x86_64 darwin with and
>  without 32b multilibs,
>  OK for trunk?

OK.

Thanks,
Richard.

>  thanks
>  Iain
>  
>  --- 8< ---
> 
> This is a partial reversion of the changes in r13-5373-g80cf2c5e8f496b.
> 
> As observed in the PR, handling the C and Driver options in the Modula-2
> lang-specific code could be difficult to emulate; This reverts to adding
> the required options to the language-specific .opt file.
> 
> Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
> 
> 	PR modula2/108555
> 	PR modula2/108182
> 	PR modula2/102343
> 
> gcc/m2/ChangeLog:
> 
> 	* gm2-lang.cc (gm2_langhook_option_lang_mask): Do not claim CL_C
> 	or CL_DRIVER.
> 	(gm2_langhook_init_options): Handle options that we want to pass
> 	to the preprocessor.
> 	* lang-specs.h: Pass -B and -save-temps to regular compile lines.
> 	* lang.opt: Add C and Driver options that Modula-2 intercepts for
> 	internal use. Reorder options into two sections and to collate.
> ---
>  gcc/m2/gm2-lang.cc  |  53 ++++++-------
>  gcc/m2/lang-specs.h |   5 +-
>  gcc/m2/lang.opt     | 185 +++++++++++++++++++++++++++++++++++---------
>  3 files changed, 177 insertions(+), 66 deletions(-)
> 
> diff --git a/gcc/m2/gm2-lang.cc b/gcc/m2/gm2-lang.cc
> index a30e626620c..999c57c1cfa 100644
> --- a/gcc/m2/gm2-lang.cc
> +++ b/gcc/m2/gm2-lang.cc
> @@ -137,9 +137,7 @@ gm2_langhook_init (void)
>  static unsigned int
>  gm2_langhook_option_lang_mask (void)
>  {
> -  /* We need to process some driver options and pass through some C
> -     ones to build our preprocessing lines.  */
> -  return CL_ModulaX2 | CL_C | CL_DRIVER;
> +  return CL_ModulaX2;
>  }
>  
>  /* Initialize the options structure.  */
> @@ -262,21 +260,22 @@ gm2_langhook_init_options (unsigned int decoded_options_count,
>  	     For now skip all plugins to avoid fails with the m2 one.  */
>  	  break;
>  
> -	/* Preprocessor arguments with a following filename.  */
> +	/* Preprocessor arguments with a following filename, we add these
> +	   back to the main file preprocess line, but not to dependents
> +	   TODO Handle MF.  */
>  	case OPT_MD:
> +	  M2Options_SetMD (arg);
> +	  break;
>  	case OPT_MMD:
> -	  /* Save the filename associated with the MD/MMD which will also
> -	     mark the option as used.  FIXME: maybe we should diagnose a
> -	     missing filename here, rather than assert.  */
> -	  gcc_checking_assert (i+1 < decoded_options_count);
> -	  gcc_checking_assert (decoded_options[i+1].opt_index
> -			       == OPT_SPECIAL_input_file);
> -	  /* Pick up the following filename.  */
> -	  arg = decoded_options[i+1].arg;
> -	  if (code == OPT_MD)
> -	    M2Options_SetMD (arg);
> -	  else
> -	    M2Options_SetMMD (arg);
> +	  M2Options_SetMMD (arg);
> +	  break;
> +
> +	/* Modula 2 claimed options we pass to the preprocessor.  */
> +	case OPT_ansi:
> +	case OPT_traditional_cpp:
> +	  if (building_cpp_command)
> +	    M2Options_CppArg (opt, arg, (option->flags & CL_JOINED)
> +			      && !(option->flags & CL_SEPARATE));
>  	  break;
>  
>  	/* Options we act on and also pass to the preprocessor.  */
> @@ -286,6 +285,12 @@ gm2_langhook_init_options (unsigned int decoded_options_count,
>  	    M2Options_CppArg (opt, arg, (option->flags & CL_JOINED)
>  			      && !(option->flags & CL_SEPARATE));
>  	  break;
> +	case OPT_quiet:
> +	  M2Options_SetQuiet (value);
> +	  if (building_cpp_command)
> +	    M2Options_CppArg (opt, arg, (option->flags & CL_JOINED)
> +			      && !(option->flags & CL_SEPARATE));
> +	  break;
>  	case OPT_v:
>  	  M2Options_SetVerbose (value);
>  	  /* FALLTHROUGH */
> @@ -533,9 +538,6 @@ gm2_langhook_handle_option (
>        /* Otherwise, ignored, at least for now. */
>        return 1;
>        break;
> -    case OPT_quiet:
> -      M2Options_SetQuiet (value);
> -      return 1;
>      case OPT_fm2_whole_program:
>        M2Options_SetWholeProgram (value);
>        return 1;
> @@ -557,20 +559,19 @@ gm2_langhook_handle_option (
>          }
>        else
>          return 0;
> -    case OPT_o:
> -      /* Options we ignore, always.  */
> -      return 1;
>      default:
>        if (insideCppArgs)
> -	/* Already handled.  */
> +	/* Handled in gm2_langhook_init_options ().  */
>  	return 1;
>        else if (option->flags & CL_DRIVER)
> -	/* Ignore driver options we do not specifically use.  */
> +	/* Driver options (unless specifically claimed above) should be handled
> +	   in gm2_langhook_init_options ().  */
>  	return 1;
>        else if (option->flags & CL_C)
> -	/* Ignore C options we do not specifically use.  */
> +	/* C options (unless specifically claimed above) should be handled
> +	   in gm2_langhook_init_options ().  */
>  	return 1;
> -      return 0;
> +      break;
>      }
>    return 0;
>  }
> diff --git a/gcc/m2/lang-specs.h b/gcc/m2/lang-specs.h
> index 6228c3c5dad..65004e1cabd 100644
> --- a/gcc/m2/lang-specs.h
> +++ b/gcc/m2/lang-specs.h
> @@ -26,7 +26,7 @@ along with GCC; see the file COPYING3.  If not see
>    "%{E|M|MM|fcpp: %{E} -fcpp-begin " \
>    "      %{!E:-E} %(cpp_unique_options) -traditional-cpp -ansi " \
>    "      -fcpp-end %{B*} %{save-temps*} ; \
> -     : %{v} %I } "
> +     : %{v} %I %{B*} %{save-temps*} } "
>  
>  /* We have three modes:
>     1. When the preprocessing step is explict and there is no following
> @@ -44,7 +44,8 @@ along with GCC; see the file COPYING3.  If not see
>        cc1gm2 " M2CPP " %{!fcpp:-fcpp;:%{fcpp}} %{I*} %i } \
>      %{!E:%{!M:%{!MM:\
>        cc1gm2 " M2CPP " %(cc1_options) %{I*} %i %{c} \
> -      %{MF*:%eto generate dependencies you must specify either '-M' or '-MM'} \
> +      %{!fcpp:%{MD|MMD|MF*: \
> +		%eto generate dependencies you must specify '-fcpp' }} \
>        %{!fsyntax-only:%(invoke_as)} \
>      }}}", 0, 0, 0},
>    {".m2i", "@modula-2-cpp-output", 0, 0, 0},
> diff --git a/gcc/m2/lang.opt b/gcc/m2/lang.opt
> index 43d6ba56767..ab4ea5547eb 100644
> --- a/gcc/m2/lang.opt
> +++ b/gcc/m2/lang.opt
> @@ -21,19 +21,15 @@
>  
>  ; See the GCC internals manual for a description of this file's format.
>  
> +; There are two sections:
> +;  1. Options specific to Modula-2
> +;  2. Options shared with C or the Driver.
> +; Please keep any new additions for either case in the relevant section.
>  ; Please try to keep this file in ASCII collating order.
>  
>  Language
>  Modula-2
>  
> -Wall
> -Modula-2
> -; Documented in c.opt
> -
> -Wpedantic
> -Modula-2
> -; Documented in common.opt
> -
>  Wpedantic-param-names
>  Modula-2
>  compiler checks to force definition module procedure parameter names with their implementation module counterpart
> @@ -50,18 +46,6 @@ Wstyle
>  Modula-2
>  extra compile time semantic checking, typically tries to catch poor programming style
>  
> -Wunused-variable
> -Modula-2
> -; Documented in c.opt
> -
> -Wunused-parameter
> -Modula-2
> -; Documented in c.opt
> -
> -c
> -Modula-2
> -; Documented in c.opt
> -
>  fauto-init
>  Modula-2
>  automatically initializes all pointers to NIL
> @@ -74,10 +58,6 @@ fcase
>  Modula-2
>  turns on runtime checking to check whether a CASE statement requires an ELSE clause when on was not specified
>  
> -fobjc-std=objc1
> -Modula-2
> -; Documented in c.opt
> -
>  fcpp
>  Modula-2
>  use cpp to preprocess the module
> @@ -118,10 +98,6 @@ fdump-system-exports
>  Modula-2
>  display all inbuilt system items
>  
> -fexceptions
> -Modula-2
> -; Documented in common.opt
> -
>  fextended-opaque
>  Modula-2
>  allows opaque types to be implemented as any type (a GNU Modula-2 extension)
> @@ -202,10 +178,6 @@ fpositive-mod-floor-div
>  Modula-2
>  force positive result from MOD and DIV result floor
>  
> -fpreprocessed
> -Modula-2
> -; Documented in c.opt
> -
>  fpthread
>  Modula-2
>  link against the pthread library (default on)
> @@ -282,16 +254,153 @@ fwholevalue
>  Modula-2
>  turns on runtime checking to check whether a whole number is about to exceed range
>  
> -;fworking-directory
> -;Modula-2
> +static-libgm2
> +Driver
> +Link the standard Modula-2 libraries statically in the compilation.
> +
> +; Here are C options that we also recognise, either within the compiler
> +; or to build the preprocessor command lines.
> +
> +Wall
> +Modula-2
>  ; Documented in c.opt
>  
> -lang-asm
> +Wpedantic
> +Modula-2
> +; Documented in common.opt
> +
> +Wunused-variable
>  Modula-2
>  ; Documented in c.opt
>  
> -static-libgm2
> -Driver
> -Link the standard Modula-2 libraries statically in the compilation.
> +Wunused-parameter
> +Modula-2
> +; Documented in c.opt
> +
> +B
> +Modula-2
> +; Documented in c.opt
> +
> +D
> +Modula-2
> +; Documented in c.opt
> +
> +E
> +Modula-2
> +; Documented in c.opt
> +
> +I
> +Modula-2 Joined Separate
> +; Documented in c.opt
> +
> +L
> +Modula-2 Joined Separate
> +; Not documented
> +
> +M
> +Modula-2
> +; Documented in c.opt
> +
> +MD
> +Modula-2
> +; Documented in c.opt
> +
> +MF
> +Modula-2
> +; Documented in c.opt
> +
> +MG
> +Modula-2
> +; Documented in c.opt
> +
> +MM
> +Modula-2
> +; Documented in c.opt
> +
> +MMD
> +Modula-2
> +; Documented in c.opt
> +
> +Mmodules
> +Modula-2
> +; Documented in c.opt
> +
> +Mno-modules
> +Modula-2
> +; Documented in c.opt
> +
> +MP
> +Modula-2
> +; Documented in c.opt
> +
> +MQ
> +Modula-2
> +; Documented in c.opt
> +
> +MT
> +Modula-2
> +; Documented in c.opt
> +
> +P
> +Modula-2
> +; Documented in c.opt
> +
> +ansi
> +Modula-2
> +; Documented in c.opt
> +
> +c
> +Modula-2
> +; Documented in c.opt
> +
> +fexceptions
> +Modula-2
> +; Documented in common.opt
> +
> +fobjc-std=objc1
> +Modula-2
> +; Documented in c.opt
> +
> +fpreprocessed
> +Modula-2
> +; Documented in c.opt
> +
> +fworking-directory
> +Modula-2
> +; Documented in c.opt
> +
> +iprefix
> +Modula-2
> +; Documented in c.opt
> +
> +iquote
> +Modula-2
> +; Documented in c.opt
> +
> +isystem
> +Modula-2
> +; Documented in c.opt
> +
> +idirafter
> +Modula-2
> +; Documented in c.opt
> +
> +imultilib
> +Modula-2
> +
> +-save-temps
> +Modula-2 Alias(save-temps)
> +
> +save-temps
> +Modula-2
> +save temporary preprocessed files
> +
> +save-temps=
> +Modula-2 Joined
> +save temporary preprocessed files
> +
> +traditional-cpp
> +Modula-2
> +; Documented in c.opt
>  
>  ; This comment is to ensure we retain the blank line above.
>
  

Patch

diff --git a/gcc/m2/gm2-lang.cc b/gcc/m2/gm2-lang.cc
index a30e626620c..999c57c1cfa 100644
--- a/gcc/m2/gm2-lang.cc
+++ b/gcc/m2/gm2-lang.cc
@@ -137,9 +137,7 @@  gm2_langhook_init (void)
 static unsigned int
 gm2_langhook_option_lang_mask (void)
 {
-  /* We need to process some driver options and pass through some C
-     ones to build our preprocessing lines.  */
-  return CL_ModulaX2 | CL_C | CL_DRIVER;
+  return CL_ModulaX2;
 }
 
 /* Initialize the options structure.  */
@@ -262,21 +260,22 @@  gm2_langhook_init_options (unsigned int decoded_options_count,
 	     For now skip all plugins to avoid fails with the m2 one.  */
 	  break;
 
-	/* Preprocessor arguments with a following filename.  */
+	/* Preprocessor arguments with a following filename, we add these
+	   back to the main file preprocess line, but not to dependents
+	   TODO Handle MF.  */
 	case OPT_MD:
+	  M2Options_SetMD (arg);
+	  break;
 	case OPT_MMD:
-	  /* Save the filename associated with the MD/MMD which will also
-	     mark the option as used.  FIXME: maybe we should diagnose a
-	     missing filename here, rather than assert.  */
-	  gcc_checking_assert (i+1 < decoded_options_count);
-	  gcc_checking_assert (decoded_options[i+1].opt_index
-			       == OPT_SPECIAL_input_file);
-	  /* Pick up the following filename.  */
-	  arg = decoded_options[i+1].arg;
-	  if (code == OPT_MD)
-	    M2Options_SetMD (arg);
-	  else
-	    M2Options_SetMMD (arg);
+	  M2Options_SetMMD (arg);
+	  break;
+
+	/* Modula 2 claimed options we pass to the preprocessor.  */
+	case OPT_ansi:
+	case OPT_traditional_cpp:
+	  if (building_cpp_command)
+	    M2Options_CppArg (opt, arg, (option->flags & CL_JOINED)
+			      && !(option->flags & CL_SEPARATE));
 	  break;
 
 	/* Options we act on and also pass to the preprocessor.  */
@@ -286,6 +285,12 @@  gm2_langhook_init_options (unsigned int decoded_options_count,
 	    M2Options_CppArg (opt, arg, (option->flags & CL_JOINED)
 			      && !(option->flags & CL_SEPARATE));
 	  break;
+	case OPT_quiet:
+	  M2Options_SetQuiet (value);
+	  if (building_cpp_command)
+	    M2Options_CppArg (opt, arg, (option->flags & CL_JOINED)
+			      && !(option->flags & CL_SEPARATE));
+	  break;
 	case OPT_v:
 	  M2Options_SetVerbose (value);
 	  /* FALLTHROUGH */
@@ -533,9 +538,6 @@  gm2_langhook_handle_option (
       /* Otherwise, ignored, at least for now. */
       return 1;
       break;
-    case OPT_quiet:
-      M2Options_SetQuiet (value);
-      return 1;
     case OPT_fm2_whole_program:
       M2Options_SetWholeProgram (value);
       return 1;
@@ -557,20 +559,19 @@  gm2_langhook_handle_option (
         }
       else
         return 0;
-    case OPT_o:
-      /* Options we ignore, always.  */
-      return 1;
     default:
       if (insideCppArgs)
-	/* Already handled.  */
+	/* Handled in gm2_langhook_init_options ().  */
 	return 1;
       else if (option->flags & CL_DRIVER)
-	/* Ignore driver options we do not specifically use.  */
+	/* Driver options (unless specifically claimed above) should be handled
+	   in gm2_langhook_init_options ().  */
 	return 1;
       else if (option->flags & CL_C)
-	/* Ignore C options we do not specifically use.  */
+	/* C options (unless specifically claimed above) should be handled
+	   in gm2_langhook_init_options ().  */
 	return 1;
-      return 0;
+      break;
     }
   return 0;
 }
diff --git a/gcc/m2/lang-specs.h b/gcc/m2/lang-specs.h
index 6228c3c5dad..65004e1cabd 100644
--- a/gcc/m2/lang-specs.h
+++ b/gcc/m2/lang-specs.h
@@ -26,7 +26,7 @@  along with GCC; see the file COPYING3.  If not see
   "%{E|M|MM|fcpp: %{E} -fcpp-begin " \
   "      %{!E:-E} %(cpp_unique_options) -traditional-cpp -ansi " \
   "      -fcpp-end %{B*} %{save-temps*} ; \
-     : %{v} %I } "
+     : %{v} %I %{B*} %{save-temps*} } "
 
 /* We have three modes:
    1. When the preprocessing step is explict and there is no following
@@ -44,7 +44,8 @@  along with GCC; see the file COPYING3.  If not see
       cc1gm2 " M2CPP " %{!fcpp:-fcpp;:%{fcpp}} %{I*} %i } \
     %{!E:%{!M:%{!MM:\
       cc1gm2 " M2CPP " %(cc1_options) %{I*} %i %{c} \
-      %{MF*:%eto generate dependencies you must specify either '-M' or '-MM'} \
+      %{!fcpp:%{MD|MMD|MF*: \
+		%eto generate dependencies you must specify '-fcpp' }} \
       %{!fsyntax-only:%(invoke_as)} \
     }}}", 0, 0, 0},
   {".m2i", "@modula-2-cpp-output", 0, 0, 0},
diff --git a/gcc/m2/lang.opt b/gcc/m2/lang.opt
index 43d6ba56767..ab4ea5547eb 100644
--- a/gcc/m2/lang.opt
+++ b/gcc/m2/lang.opt
@@ -21,19 +21,15 @@ 
 
 ; See the GCC internals manual for a description of this file's format.
 
+; There are two sections:
+;  1. Options specific to Modula-2
+;  2. Options shared with C or the Driver.
+; Please keep any new additions for either case in the relevant section.
 ; Please try to keep this file in ASCII collating order.
 
 Language
 Modula-2
 
-Wall
-Modula-2
-; Documented in c.opt
-
-Wpedantic
-Modula-2
-; Documented in common.opt
-
 Wpedantic-param-names
 Modula-2
 compiler checks to force definition module procedure parameter names with their implementation module counterpart
@@ -50,18 +46,6 @@  Wstyle
 Modula-2
 extra compile time semantic checking, typically tries to catch poor programming style
 
-Wunused-variable
-Modula-2
-; Documented in c.opt
-
-Wunused-parameter
-Modula-2
-; Documented in c.opt
-
-c
-Modula-2
-; Documented in c.opt
-
 fauto-init
 Modula-2
 automatically initializes all pointers to NIL
@@ -74,10 +58,6 @@  fcase
 Modula-2
 turns on runtime checking to check whether a CASE statement requires an ELSE clause when on was not specified
 
-fobjc-std=objc1
-Modula-2
-; Documented in c.opt
-
 fcpp
 Modula-2
 use cpp to preprocess the module
@@ -118,10 +98,6 @@  fdump-system-exports
 Modula-2
 display all inbuilt system items
 
-fexceptions
-Modula-2
-; Documented in common.opt
-
 fextended-opaque
 Modula-2
 allows opaque types to be implemented as any type (a GNU Modula-2 extension)
@@ -202,10 +178,6 @@  fpositive-mod-floor-div
 Modula-2
 force positive result from MOD and DIV result floor
 
-fpreprocessed
-Modula-2
-; Documented in c.opt
-
 fpthread
 Modula-2
 link against the pthread library (default on)
@@ -282,16 +254,153 @@  fwholevalue
 Modula-2
 turns on runtime checking to check whether a whole number is about to exceed range
 
-;fworking-directory
-;Modula-2
+static-libgm2
+Driver
+Link the standard Modula-2 libraries statically in the compilation.
+
+; Here are C options that we also recognise, either within the compiler
+; or to build the preprocessor command lines.
+
+Wall
+Modula-2
 ; Documented in c.opt
 
-lang-asm
+Wpedantic
+Modula-2
+; Documented in common.opt
+
+Wunused-variable
 Modula-2
 ; Documented in c.opt
 
-static-libgm2
-Driver
-Link the standard Modula-2 libraries statically in the compilation.
+Wunused-parameter
+Modula-2
+; Documented in c.opt
+
+B
+Modula-2
+; Documented in c.opt
+
+D
+Modula-2
+; Documented in c.opt
+
+E
+Modula-2
+; Documented in c.opt
+
+I
+Modula-2 Joined Separate
+; Documented in c.opt
+
+L
+Modula-2 Joined Separate
+; Not documented
+
+M
+Modula-2
+; Documented in c.opt
+
+MD
+Modula-2
+; Documented in c.opt
+
+MF
+Modula-2
+; Documented in c.opt
+
+MG
+Modula-2
+; Documented in c.opt
+
+MM
+Modula-2
+; Documented in c.opt
+
+MMD
+Modula-2
+; Documented in c.opt
+
+Mmodules
+Modula-2
+; Documented in c.opt
+
+Mno-modules
+Modula-2
+; Documented in c.opt
+
+MP
+Modula-2
+; Documented in c.opt
+
+MQ
+Modula-2
+; Documented in c.opt
+
+MT
+Modula-2
+; Documented in c.opt
+
+P
+Modula-2
+; Documented in c.opt
+
+ansi
+Modula-2
+; Documented in c.opt
+
+c
+Modula-2
+; Documented in c.opt
+
+fexceptions
+Modula-2
+; Documented in common.opt
+
+fobjc-std=objc1
+Modula-2
+; Documented in c.opt
+
+fpreprocessed
+Modula-2
+; Documented in c.opt
+
+fworking-directory
+Modula-2
+; Documented in c.opt
+
+iprefix
+Modula-2
+; Documented in c.opt
+
+iquote
+Modula-2
+; Documented in c.opt
+
+isystem
+Modula-2
+; Documented in c.opt
+
+idirafter
+Modula-2
+; Documented in c.opt
+
+imultilib
+Modula-2
+
+-save-temps
+Modula-2 Alias(save-temps)
+
+save-temps
+Modula-2
+save temporary preprocessed files
+
+save-temps=
+Modula-2 Joined
+save temporary preprocessed files
+
+traditional-cpp
+Modula-2
+; Documented in c.opt
 
 ; This comment is to ensure we retain the blank line above.