From: DJ Delorie Date: Thu, 5 Jul 2001 20:09:34 +0000 (-0400) Subject: gcc.c (TARGET_OPTION_TRANSLATE_TABLE): New. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0259b07a28f451df6f509ac9d0be1cfef134487f;p=gcc.git gcc.c (TARGET_OPTION_TRANSLATE_TABLE): New. * 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. From-SVN: r43787 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 2c8be244f8e..9769799897e 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2001-07-05 DJ Delorie + + * 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. + 2001-07-05 Brad Lucier Gerald Pfeifer diff --git a/gcc/doc/tm.texi b/gcc/doc/tm.texi index 7a1d8bce34b..ad9e29cf71c 100644 --- a/gcc/doc/tm.texi +++ b/gcc/doc/tm.texi @@ -140,6 +140,26 @@ the linker needs a space between the option and its argument. 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 diff --git a/gcc/gcc.c b/gcc/gcc.c index cec9954caf1..409ac2bbe9a 100644 --- a/gcc/gcc.c +++ b/gcc/gcc.c @@ -952,6 +952,18 @@ struct option_map option_map[] = {"--", "-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. */ @@ -964,8 +976,9 @@ translate_options (argcp, argvp) int i; int argc = *argcp; const char *const *argv = *argvp; + int newvsize = (argc + 2) * 2 * sizeof (const char *); const char **newv = - (const char **) xmalloc ((argc + 2) * 2 * sizeof (const char *)); + (const char **) xmalloc (newvsize); int newindex = 0; i = 0; @@ -973,6 +986,56 @@ translate_options (argcp, argvp) 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] == '-') {