Patchwork Add ToLower .opt facility

login
register
mail settings
Submitter Joseph S. Myers
Date April 2, 2011, 12:23 a.m.
Message ID <Pine.LNX.4.64.1104020022110.32286@digraph.polyomino.org.uk>
Download mbox | patch
Permalink /patch/89374/
State New
Headers show

Comments

Joseph S. Myers - April 2, 2011, 12:23 a.m.
This patch adds a ToLower .opt feature, for option arguments that are
case-insensitive and should be converted to a canonical lowercase
form.

This is relevant to at least mips, mn10300 and rx.  This patch makes
rx use it, thereby causing an existing spec that tested only for a
lowercase option form to start to work correctly with both variants
(since specs only need to match canonical options).

Bootstrapped with no regressions on x86_64-unknown-linux-gnu, and
tested building cc1 and xgcc for cross to rx-elf.  Will commit to
trunk in the absence of target maintainer objections.

2011-04-01  Joseph Myers  <joseph@codesourcery.com>

	* doc/options.texi (ToLower): Document.
	* opt-functions.awk (switch_bit_fields): Initialize cl_tolower
	field.
	* opts-common.c (decode_cmdline_option): Handle cl_tolower.
	* opts.h (cl_option): Add cl_tolower field.
	* config/rx/rx.c (rx_handle_option): Use strcmp of -mcpu=
	arguments with lowercase strings.
	* config/rx/rx.opt (mcpu=): Add ToLower.
	* config/rx/t-rx (MULTILIB_MATCHES): Don't handle uppercase -mcpu=
	argument.
Nick Clifton - April 4, 2011, 9:14 a.m.
Hi Joseph,

> This patch adds a ToLower .opt feature, for option arguments that are
> case-insensitive and should be converted to a canonical lowercase
> form.
>
> This is relevant to at least mips, mn10300 and rx.  This patch makes
> rx use it, thereby causing an existing spec that tested only for a
> lowercase option form to start to work correctly with both variants
> (since specs only need to match canonical options).

Thanks!

> Bootstrapped with no regressions on x86_64-unknown-linux-gnu, and
> tested building cc1 and xgcc for cross to rx-elf.  Will commit to
> trunk in the absence of target maintainer objections.

No objections and definite approval from me.

> 2011-04-01  Joseph Myers<joseph@codesourcery.com>
>
> 	* doc/options.texi (ToLower): Document.
> 	* opt-functions.awk (switch_bit_fields): Initialize cl_tolower
> 	field.
> 	* opts-common.c (decode_cmdline_option): Handle cl_tolower.
> 	* opts.h (cl_option): Add cl_tolower field.
> 	* config/rx/rx.c (rx_handle_option): Use strcmp of -mcpu=
> 	arguments with lowercase strings.
> 	* config/rx/rx.opt (mcpu=): Add ToLower.
> 	* config/rx/t-rx (MULTILIB_MATCHES): Don't handle uppercase -mcpu=
> 	argument.

Cheers
   Nick

Patch

Index: gcc/doc/options.texi
===================================================================
--- gcc/doc/options.texi	(revision 171804)
+++ gcc/doc/options.texi	(working copy)
@@ -257,6 +257,11 @@  option handler.  @code{UInteger} should 
 @code{-falign-loops}=@var{n} are supported to make sure the saved
 options are given a full integer.
 
+@item ToLower
+The option's argument should be converted to lowercase as part of
+putting it in canonical form, and before comparing with the strings
+indicated by any @code{Enum} property.
+
 @item NoDriverArg
 For an option marked @code{Separate}, the option only takes an
 argument in the compiler proper, not in the driver.  This is for
Index: gcc/opts-common.c
===================================================================
--- gcc/opts-common.c	(revision 171804)
+++ gcc/opts-common.c	(working copy)
@@ -567,6 +567,19 @@  decode_cmdline_option (const char **argv
   if (!option_ok_for_language (option, lang_mask))
     errors |= CL_ERR_WRONG_LANG;
 
+  /* Convert the argument to lowercase if appropriate.  */
+  if (arg && option->cl_tolower)
+    {
+      size_t j;
+      size_t len = strlen (arg);
+      char *arg_lower = XNEWVEC (char, len + 1);
+
+      for (j = 0; j < len; j++)
+	arg_lower[j] = TOLOWER ((unsigned char) arg[j]);
+      arg_lower[len] = 0;
+      arg = arg_lower;
+    }
+
   /* If the switch takes an integer, convert it.  */
   if (arg && option->cl_uinteger)
     {
Index: gcc/opts.h
===================================================================
--- gcc/opts.h	(revision 171804)
+++ gcc/opts.h	(working copy)
@@ -96,6 +96,8 @@  struct cl_option
   BOOL_BITFIELD cl_missing_ok : 1;
   /* Argument is an integer >=0.  */
   BOOL_BITFIELD cl_uinteger : 1;
+  /* Argument should be converted to lowercase.  */
+  BOOL_BITFIELD cl_tolower : 1;
   /* Report argument with -fverbose-asm  */
   BOOL_BITFIELD cl_report : 1;
   /* Offset of field for this option in struct gcc_options, or
Index: gcc/opt-functions.awk
===================================================================
--- gcc/opt-functions.awk	(revision 171804)
+++ gcc/opt-functions.awk	(working copy)
@@ -126,6 +126,7 @@  function switch_bit_fields (flags)
 	  flag_init("RejectNegative", flags) \
 	  flag_init("JoinedOrMissing", flags) \
 	  flag_init("UInteger", flags) \
+	  flag_init("ToLower", flags) \
 	  flag_init("Report", flags)
 
 	sub(", $", "", result)
Index: gcc/config/rx/rx.c
===================================================================
--- gcc/config/rx/rx.c	(revision 171804)
+++ gcc/config/rx/rx.c	(working copy)
@@ -2308,14 +2308,14 @@  rx_handle_option (struct gcc_options *op
       return value >= 0 && value <= 4;
 
     case OPT_mcpu_:
-      if (strcasecmp (arg, "RX610") == 0)
+      if (strcmp (arg, "rx610") == 0)
 	rx_cpu_type = RX610;
-      else if (strcasecmp (arg, "RX200") == 0)
+      else if (strcmp (arg, "rx200") == 0)
 	{
 	  target_flags |= MASK_NO_USE_FPU;
 	  rx_cpu_type = RX200;
 	}
-      else if (strcasecmp (arg, "RX600") != 0)
+      else if (strcmp (arg, "rx600") != 0)
 	warning (0, "unrecognized argument '%s' to -mcpu= option", arg);
       break;
       
Index: gcc/config/rx/rx.opt
===================================================================
--- gcc/config/rx/rx.opt	(revision 171804)
+++ gcc/config/rx/rx.opt	(working copy)
@@ -1,5 +1,5 @@ 
 ; Command line options for the Renesas RX port of GCC.
-; Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+; Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 ; Contributed by Red Hat.
 ;
 ; This file is part of GCC.
@@ -43,7 +43,7 @@  Enable the use of RX FPU instructions.  
 ;---------------------------------------------------
 
 mcpu=
-Target RejectNegative Joined Var(rx_cpu_name) Report
+Target RejectNegative Joined Var(rx_cpu_name) Report ToLower
 Specify the target RX cpu type.
 
 ;---------------------------------------------------
Index: gcc/config/rx/t-rx
===================================================================
--- gcc/config/rx/t-rx	(revision 171804)
+++ gcc/config/rx/t-rx	(working copy)
@@ -1,5 +1,5 @@ 
 # Makefile fragment for building GCC for the Renesas RX target.
-# Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
+# Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
 # Contributed by Red Hat.
 #
 # This file is part of GCC.
@@ -23,7 +23,7 @@ 
 MULTILIB_OPTIONS    = m64bit-doubles  nofpu        mbig-endian-data 
 MULTILIB_DIRNAMES   =  64-bit-double  no-fpu-libs   big-endian-data 
 
-MULTILIB_MATCHES    = nofpu=mnofpu  nofpu=mcpu?rx200  nofpu=mcpu?RX200
+MULTILIB_MATCHES    = nofpu=mnofpu  nofpu=mcpu?rx200
 
 MULTILIB_EXCEPTIONS =
 MULTILIB_EXTRA_OPTS =