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]

Patch: TARGET_OPTION_TRANSLATE_TABLE



I'm working on a port with a complex N-to-N (usually, (1 of N)-to-N)
mapping of command line options to other options, and as the "other
options" include things that affect multilib selection (no, the
MULITLIB_* t-foo macros won't cover this) it needs to be handled in
gcc.c and not via per-pass specs.  Tested on Linux with a dummy table.

2001-07-03  DJ Delorie  <dj@redhat.com>

	* gcc.c (TARGET_OPTION_TRANSLATE_TABLE): New.
	(translate_options): If the above is defined, use it to map
	given options to new options.
	* doc/tm.texi: Document it.

Index: gcc.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcc.c,v
retrieving revision 1.234
diff -p -3 -r1.234 gcc.c
*** gcc.c	2001/06/30 08:46:31	1.234
--- gcc.c	2001/07/04 01:53:45
*************** struct option_map option_map[] =
*** 952,957 ****
--- 952,969 ----
     {"--", "-f", "*j"}
   };
  
+ 
+ #ifdef TARGET_OPTION_TRANSLATE_TABLE
+ static struct {
+   const char *option_found;
+   const char *replacements;
+ } target_option_translations[] =
+ {
+   TARGET_OPTION_TRANSLATE_TABLE,
+   { 0, 0 }
+ };
+ #endif
+ 
  /* Translate the options described by *ARGCP and *ARGVP.
     Make a new vector and store it back in *ARGVP,
     and store its length in *ARGVC.  */
*************** translate_options (argcp, argvp)
*** 964,971 ****
    int i;
    int argc = *argcp;
    const char *const *argv = *argvp;
    const char **newv =
!     (const char **) xmalloc ((argc + 2) * 2 * sizeof (const char *));
    int newindex = 0;
  
    i = 0;
--- 976,984 ----
    int i;
    int argc = *argcp;
    const char *const *argv = *argvp;
+   int newvsize = (argc + 2) * 2 * sizeof (const char *);
    const char **newv =
!     (const char **) xmalloc (newvsize);
    int newindex = 0;
  
    i = 0;
*************** translate_options (argcp, argvp)
*** 973,978 ****
--- 986,1041 ----
  
    while (i < argc)
      {
+ #ifdef TARGET_OPTION_TRANSLATE_TABLE
+       int tott_idx;
+ 
+       for (tott_idx = 0;
+ 	   target_option_translations[tott_idx].option_found;
+ 	   tott_idx++)
+ 	{
+ 	  if (strcmp (target_option_translations[tott_idx].option_found,
+ 		      argv[i]) == 0)
+ 	    {
+ 	      int spaces = 1;
+ 	      const char *sp;
+ 	      char *np;
+ 
+ 	      for (sp = target_option_translations[tott_idx].replacements;
+ 		   *sp; sp++)
+ 		{
+ 		  if (*sp == ' ')
+ 		    spaces ++;
+ 		}
+ 
+ 	      newvsize += spaces * sizeof (const char *);
+ 	      newv = (const char **) xrealloc (newv, newvsize);
+ 
+ 	      sp = target_option_translations[tott_idx].replacements;
+ 	      np = (char *) xmalloc (strlen (sp) + 1);
+ 	      strcpy (np, sp);
+ 
+ 	      while (1)
+ 		{
+ 		  while (*np == ' ')
+ 		    np++;
+ 		  if (*np == 0)
+ 		    break;
+ 		  newv[newindex++] = np;
+ 		  while (*np != ' ' && *np)
+ 		    np++;
+ 		  if (*np == 0)
+ 		    break;
+ 		  *np++ = 0;
+ 		}
+ 
+ 	      i ++;
+ 	      break;
+ 	    }
+ 	}
+       if (target_option_translations[tott_idx].option_found)
+ 	continue;
+ #endif
+ 
        /* Translate -- options.  */
        if (argv[i][0] == '-' && argv[i][1] == '-')
  	{
Index: doc/tm.texi
===================================================================
RCS file: /cvs/gcc/gcc/gcc/doc/tm.texi,v
retrieving revision 1.22
diff -p -3 -r1.22 tm.texi
*** tm.texi	2001/07/03 00:46:05	1.22
--- tm.texi	2001/07/04 01:53:58
*************** the linker needs a space between the opt
*** 140,145 ****
--- 140,165 ----
  
  If this macro is not defined, the default value is @code{""}.
  
+ @findex TARGET_OPTION_TRANSLATE_TABLE
+ @item TARGET_OPTION_TRANSLATE_TABLE
+ If defined, a list of pairs of strings, the first of which is a
+ potential command line target to the @file{gcc} driver program, and the
+ second of which is a space-separated (tabs and other whitespace are not
+ supported) list of options with which to replace the first option.  The
+ target defining this list is responsible for assuring that the results
+ are valid.  Replacement options may not be the @code{--opt} style, they
+ must be the @code{-opt} style.  It is the intention of this macro to
+ provide a mechanism for substitution that affects the multilibs chosen,
+ such as one option that enables many options, some of which select
+ multilibs.  Example nonsensical definition, where @code{-malt-abi},
+ @code{-EB}, and @code{-mspoo} cause different multilibs to be chosen:
+ 
+ @example
+ #define TARGET_OPTION_TRANSLATE_TABLE \
+ @{ "-fast",   "-march=fast-foo -malt-abi -I/usr/fast-foo" @}, \
+ @{ "-compat", "-EB -malign=4 -mspoo" @}
+ @end example
+ 
  @findex CPP_SPEC
  @item CPP_SPEC
  A C string constant that tells the GCC driver program options to


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