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]

[rfc w/ patch] enhancing TARGET_OPTIONS



I propose the attached patch to do the following (see doc patch for
details):

* Act as a workaround for targets where TARGET_SWITCHES has exceeded
  the 31 bits available for that method.

* Allow switches with more than two states (i.e. tri-state options).

* Allow switch-like options with option-like variants.

* Allow options to have a default value.

* Allow subtargets to isolate their switches from the target-generic
  switch mask.

* Provide more flexibility in how switches and options may be treated
  in the future.

I built with this on linux and tested the docs via DVI creation.
Since nothing uses the enhanced functionality yet, such testing will
have to be deferred until then but I will of course take
responsibility for any bugs found then.  If this patch is approved, I
will of course add ", 0" to all existing TARGET_OPTIONS definitions to
prevent the "missing initializer" warnings.

2002-03-14  DJ Delorie  <dj@redhat.com>

	* toplev.c (target_options): Add value field.
	(set_target_switch): Handle target options with default
	values.
	* doc/tm.texi: Document how default vs non-default target
	options work.

Index: toplev.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/toplev.c,v
retrieving revision 1.595
diff -p -3 -r1.595 toplev.c
*** toplev.c	2002/03/14 10:10:11	1.595
--- toplev.c	2002/03/14 16:30:38
*************** static const struct
*** 1347,1352 ****
--- 1347,1353 ----
    const char *const prefix;
    const char **const variable;
    const char *const description;
+   const char *const value;
  }
  target_options [] = TARGET_OPTIONS;
  #endif
*************** set_target_switch (name)
*** 4339,4348 ****
      for (j = 0; j < ARRAY_SIZE (target_options); j++)
        {
  	int len = strlen (target_options[j].prefix);
! 	if (!strncmp (target_options[j].prefix, name, len))
  	  {
! 	    *target_options[j].variable = name + len;
! 	    valid_target_option = 1;
  	  }
        }
  #endif
--- 4340,4360 ----
      for (j = 0; j < ARRAY_SIZE (target_options); j++)
        {
  	int len = strlen (target_options[j].prefix);
! 	if (target_options[j].value)
  	  {
! 	    if (!strcmp (target_options[j].prefix, name))
! 	      {
! 		*target_options[j].variable = target_options[j].value;
! 		valid_target_option = 1;
! 	      }
! 	  }
! 	else
! 	  {
! 	    if (!strncmp (target_options[j].prefix, name, len))
! 	      {
! 		*target_options[j].variable = name + len;
! 		valid_target_option = 1;
! 	      }
  	  }
        }
  #endif
Index: doc/tm.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/tm.texi,v
retrieving revision 1.111
diff -p -3 -r1.111 tm.texi
*** tm.texi	2002/03/12 05:28:21	1.111
--- tm.texi	2002/03/14 16:30:41
*************** options that have values.  Its definitio
*** 717,733 ****
  subgrouping for each command option.
  
  Each subgrouping contains a string constant, that defines the fixed part
! of the option name, the address of a variable, and a description string.
! Non-empty description strings should be marked with @code{N_(@dots{})} for
! @command{xgettext}.  Please do not mark empty strings because the empty
! string is reserved by GNU gettext. @code{gettext("")} returns the header entry
! of the message catalog with meta information, not the empty string.
! 
! The variable, type @code{char *}, is set to the variable part of the
! given option if the fixed part matches.  The actual option name is made
! by appending @samp{-m} to the specified name.  Again, each option should
! also be documented in @file{invoke.texi}.
  
  Here is an example which defines @option{-mshort-data-@var{number}}.  If the
  given option is @option{-mshort-data-512}, the variable @code{m88k_short_data}
  will be set to the string @code{"512"}.
--- 717,739 ----
  subgrouping for each command option.
  
  Each subgrouping contains a string constant, that defines the fixed part
! of the option name, the address of a variable, a description string, and
! a default value.  Non-empty description strings should be marked with
! @code{N_(@dots{})} for @command{xgettext}.  Please do not mark empty
! strings because the empty string is reserved by GNU
! gettext. @code{gettext("")} returns the header entry of the message
! catalog with meta information, not the empty string.
  
+ If the default value is @code{NULL}, then the variable, type @code{char
+ *}, is set to the variable part of the given option if the fixed part
+ matches.  The actual option name is made by appending @samp{-m} to the
+ specified name.  Again, each option should also be documented in
+ @file{invoke.texi}.
+ 
+ If the default value is non-@code{NULL}, then the variable is instead
+ set to the default value part of the given option if the entire option
+ matches.
+ 
  Here is an example which defines @option{-mshort-data-@var{number}}.  If the
  given option is @option{-mshort-data-512}, the variable @code{m88k_short_data}
  will be set to the string @code{"512"}.
*************** will be set to the string @code{"512"}.
*** 736,742 ****
  extern char *m88k_short_data;
  #define TARGET_OPTIONS \
   @{ @{ "short-data-", &m88k_short_data, \
!      N_("Specify the size of the short data section") @} @}
  @end smallexample
  
  @findex TARGET_VERSION
--- 742,779 ----
  extern char *m88k_short_data;
  #define TARGET_OPTIONS \
   @{ @{ "short-data-", &m88k_short_data, \
!      N_("Specify the size of the short data section"), 0 @} @}
! @end smallexample
! 
! Here is an variant of the above that allows you to also specify just
! @option{-mshort-data} where a default of @code{64} is used.
! 
! @smallexample
! extern char *m88k_short_data;
! #define TARGET_OPTIONS \
!  @{ @{ "short-data-", &m88k_short_data, \
!      N_("Specify the size of the short data section"), 0 @} \
!     @{ "short-data", &m88k_short_data, "", "64" @},
!     @}
! @end smallexample
! 
! Here is an example which defines @option{-mno-alu}, @option{-malu1}, and
! @option{-malu2} as a three-state switch, along with suitable macros for
! checking the state of the option (documentation is elided for brevity).
! 
! @smallexample
! [chip.c]
! char *chip_alu = ""; /* Specify default here.  */
! 
! [chip.h]
! extern char *chip_alu;
! #define TARGET_OPTIONS \
!   @{ @{ "no-alu", &chip_alu, "", "" @}, \
!      @{ "alu1", &chip_alu, "", "1" @}, \
!      @{ "alu2", &chip_alu, "", "2" @}, @}
! #define TARGET_ALU (chip_alu[0] != '\0')
! #define TARGET_ALU1 (chip_alu[0] == '1')
! #define TARGET_ALU2 (chip_alu[0] == '2')
  @end smallexample
  
  @findex TARGET_VERSION


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