public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: [4.7] Avoid global state in score_handle_option
@ 2011-03-10  2:17 Liqin Chen
  0 siblings, 0 replies; 2+ messages in thread
From: Liqin Chen @ 2011-03-10  2:17 UTC (permalink / raw)
  To: Joseph S. Myers; +Cc: gcc-patches

Hi Joseph,

Joseph Myers <joseph@codesourcery.com> 写于 2011-03-10 08:59:52:

> Tested building cc1 and xgcc for cross to score-elf.  Will commit to
> trunk for 4.7 in the absence of target maintainer objections.

Thanks Joseph, please commit.
We will merge it in our new update.

Cheers
--liqin

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [4.7] Avoid global state in score_handle_option
@ 2011-03-10  1:00 Joseph S. Myers
  0 siblings, 0 replies; 2+ messages in thread
From: Joseph S. Myers @ 2011-03-10  1:00 UTC (permalink / raw)
  To: gcc-patches; +Cc: liqin

This patch, for 4.7 and relative to a tree with
<http://gcc.gnu.org/ml/gcc-patches/2011-02/msg01709.html> applied,
stops the SCORE handle_option hook from using global state.

The -march= option is converted to use enumerated arguments.  The
existing handling of this option maps arguments to bits in
target_flags, and this is still done after this patch; it would
probably be better to map architectures to values of an actual enum
type (with flags bits used to describe actual subsets of processors
that support some particular instruction if needed), and to make the
options -mscore<version> into aliases for -march= options (documenting
-march= accordingly), but I don't plan to do this cleanup.

Tested building cc1 and xgcc for cross to score-elf.  Will commit to
trunk for 4.7 in the absence of target maintainer objections.

2011-03-09  Joseph Myers  <joseph@codesourcery.com>

	* config/score/score.c (score_handle_option): Don't assert that
	global structures are in use.  Access target_flags via opts
	pointer.  Use value of -march= option to determine target_flags
	settings.
	* config/score/score.opt (march=): Use Enum.
	(score_arch): New Enum and EnumValue entries.

diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/score/score.c gcc-mainline/gcc/config/score/score.c
--- gcc-mainline-1/gcc/config/score/score.c	2011-02-24 12:56:51.000000000 -0800
+++ gcc-mainline/gcc/config/score/score.c	2011-03-09 13:46:47.000000000 -0800
@@ -309,67 +309,30 @@ score_asm_file_end (void)
 
 /* Implement TARGET_HANDLE_OPTION.  */
 static bool
-score_handle_option (struct gcc_options *opts, struct gcc_options *opts_set,
+score_handle_option (struct gcc_options *opts,
+		     struct gcc_options *opts_set ATTRIBUTE_UNUSED,
 		     const struct cl_decoded_option *decoded,
 		     location_t loc ATTRIBUTE_UNUSED)
 {
   size_t code = decoded->opt_index;
-  const char *arg = decoded->arg;
-
-  gcc_assert (opts == &global_options);
-  gcc_assert (opts_set == &global_options_set);
+  int value = decoded->value;
 
   switch (code)
     {
     case OPT_mscore7d:
-      target_flags &= ~(MASK_ALL_CPU_BITS);
-      target_flags |= MASK_SCORE7 | MASK_SCORE7D;
+      opts->x_target_flags &= ~(MASK_ALL_CPU_BITS);
+      opts->x_target_flags |= MASK_SCORE7 | MASK_SCORE7D;
       return true;
 
     case OPT_mscore3d:
-      target_flags &= ~(MASK_ALL_CPU_BITS);
-      target_flags |= MASK_SCORE3 | MASK_SCORE3D;
+      opts->x_target_flags &= ~(MASK_ALL_CPU_BITS);
+      opts->x_target_flags |= MASK_SCORE3 | MASK_SCORE3D;
       return true;
 
     case OPT_march_:
-      if (strcmp (arg, "score5") == 0)
-        {
-          target_flags &= ~(MASK_ALL_CPU_BITS);
-          target_flags |= MASK_SCORE5;
-          return true;
-        }
-      else if (strcmp (arg, "score5u") == 0)
-        {
-          target_flags &= ~(MASK_ALL_CPU_BITS);
-          target_flags |= MASK_SCORE5U;
-          return true;
-        }
-      else if (strcmp (arg, "score7") == 0)
-        {
-          target_flags &= ~(MASK_ALL_CPU_BITS);
-          target_flags |= MASK_SCORE7;
-          return true;
-        }
-      else if (strcmp (arg, "score7d") == 0)
-        {
-          target_flags &= ~(MASK_ALL_CPU_BITS);
-          target_flags |= MASK_SCORE7 | MASK_SCORE7D;
-          return true;
-        }
-      else if (strcmp (arg, "score3") == 0)
-        {
-          target_flags &= ~(MASK_ALL_CPU_BITS);
-          target_flags |= MASK_SCORE3;
-          return true;
-        }
-      else if (strcmp (arg, "score3d") == 0)
-        {
-          target_flags &= ~(MASK_ALL_CPU_BITS);
-          target_flags |= MASK_SCORE3 | MASK_SCORE3D;
-          return true;
-        }
-      else
-        return false;
+      opts->x_target_flags &= ~(MASK_ALL_CPU_BITS);
+      opts->x_target_flags |= value;
+      return true;
 
     default:
       return true;
diff -rupN --exclude=.svn gcc-mainline-1/gcc/config/score/score.opt gcc-mainline/gcc/config/score/score.opt
--- gcc-mainline-1/gcc/config/score/score.opt	2009-03-28 00:38:42.000000000 -0700
+++ gcc-mainline/gcc/config/score/score.opt	2011-03-09 14:26:06.000000000 -0800
@@ -1,6 +1,6 @@
 ; Options for the Sunnorth port of the compiler.
 
-; Copyright (C) 2005, 2007 Free Software Foundation, Inc.
+; Copyright (C) 2005, 2007, 2011 Free Software Foundation, Inc.
 ;
 ; This file is part of GCC.
 ;
@@ -59,5 +59,27 @@ Target RejectNegative Report Mask(SCORE3
 Support SCORE 3d ISA
 
 march=
-Target RejectNegative Joined
+Target RejectNegative Joined Enum(score_arch)
 Specify the name of the target architecture
+
+Enum
+Name(score_arch) Type(int)
+Known SCORE architectures (for use with the -march= option):
+
+EnumValue
+Enum(score_arch) String(score5) Value(MASK_SCORE5)
+
+EnumValue
+Enum(score_arch) String(score5u) Value(MASK_SCORE5U)
+
+EnumValue
+Enum(score_arch) String(score7) Value(MASK_SCORE7)
+
+EnumValue
+Enum(score_arch) String(score7d) Value(MASK_SCORE7 | MASK_SCORE7D)
+
+EnumValue
+Enum(score_arch) String(score3) Value(MASK_SCORE3)
+
+EnumValue
+Enum(score_arch) String(score3d) Value(MASK_SCORE3 | MASK_SCORE3D)

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-03-10  2:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-10  2:17 [4.7] Avoid global state in score_handle_option Liqin Chen
  -- strict thread matches above, loose matches on Subject: below --
2011-03-10  1:00 Joseph S. Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).