This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFA: some minor tweaks to the options scripts
- From: Richard Sandiford <rsandifo at redhat dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sat, 19 Mar 2005 09:12:35 +0000
- Subject: RFA: some minor tweaks to the options scripts
I'm about to submit a patch to add a new options flag, "MaskExists".
While writing that patch, I noticed a difference between the way
opt-functions.awk and opt[hc]-gen.awk check for flags: the former
carefully checks for word boundaries but the latter don't.
It's hardly a big deal or anything, and it certainly doesn't cause
problems at the moment. On the other hand, I guess each new flag
increases the likelihood of a substring match triggering unexpectedly,
so while adding this new flag, I thought I might as well add a new
function for wrapping up the stricter check performed by
opt-functions.awk.
Making this change led to some overly-long lines in the way we
built up the CL_* mask. Rather than split the lines up, it seemed
more readable to rework it to use a single assignment and helper
function instead.
The patch also makes the Init(...) handling use the recently-added
opt_args function.
All in all, it's pretty whimsical stuff, sorry.
Patch bootstrapped & regression tested on i686-pc-linux-gnu.
I also checked that it has no effect on the options.[hc] output
for that target. OK to install?
Richard
* opt-functions.awk (flag_set_p, test_flag): New functions.
(switch_flags): Use them.
* opth-gen.awk: Use flag_set_p to check for flags.
* optc-gen.awk: Likewise. Use opt_args to check for Init(...) flags.
Index: opt-functions.awk
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opt-functions.awk,v
retrieving revision 2.2
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r2.2 opt-functions.awk
--- opt-functions.awk 14 Mar 2005 20:18:38 -0000 2.2
+++ opt-functions.awk 18 Mar 2005 08:59:01 -0000
@@ -18,6 +18,21 @@
# Some common subroutines for use by opt[ch]-gen.awk.
+# Return nonzero if FLAGS contains a flag matching REGEX.
+function flag_set_p(regex, flags)
+{
+ return (" " flags " ") ~ (" " regex " ")
+}
+
+# Return STRING if FLAGS contains a flag matching regexp REGEX,
+# otherwise return the empty string.
+function test_flag(regex, flags, string)
+{
+ if (flag_set_p(regex, flags))
+ return string
+ return ""
+}
+
# If FLAGS contains a "NAME(...argument...)" flag, return the value
# of the argument. Return the empty string otherwise.
function opt_args(name, flags)
@@ -47,24 +62,22 @@ function nth_arg(n, s)
# Return a bitmask of CL_* values for option flags FLAGS.
function switch_flags (flags)
{
- flags = " " flags " "
result = "0"
for (j = 0; j < n_langs; j++) {
- regex = " " langs[j] " "
+ regex = langs[j]
gsub ( "\\+", "\\+", regex )
- if (flags ~ regex)
- result = result " | " macros[j]
+ result = result test_flag(regex, flags, " | " macros[j])
}
- if (flags ~ " Common ") result = result " | CL_COMMON"
- if (flags ~ " Target ") result = result " | CL_TARGET"
- if (flags ~ " Joined ") result = result " | CL_JOINED"
- if (flags ~ " JoinedOrMissing ") \
- result = result " | CL_JOINED | CL_MISSING_OK"
- if (flags ~ " Separate ") result = result " | CL_SEPARATE"
- if (flags ~ " RejectNegative ") result = result " | CL_REJECT_NEGATIVE"
- if (flags ~ " UInteger ") result = result " | CL_UINTEGER"
- if (flags ~ " Undocumented ") result = result " | CL_UNDOCUMENTED"
- if (flags ~ " Report ") result = result " | CL_REPORT"
+ result = result \
+ test_flag("Common", flags, " | CL_COMMON") \
+ test_flag("Target", flags, " | CL_TARGET") \
+ test_flag("Joined", flags, " | CL_JOINED") \
+ test_flag("JoinedOrMissing", flags, " | CL_JOINED | CL_MISSING_OK") \
+ test_flag("Separate", flags, " | CL_SEPARATE") \
+ test_flag("RejectNegative", flags, " | CL_REJECT_NEGATIVE") \
+ test_flag("UInteger", flags, " | CL_UINTEGER") \
+ test_flag("Undocumented", flags, " | CL_UNDOCUMENTED") \
+ test_flag("Report", flags, " | CL_REPORT")
sub( "^0 \\| ", "", result )
return result
}
Index: opth-gen.awk
===================================================================
RCS file: /cvs/gcc/gcc/gcc/opth-gen.awk,v
retrieving revision 2.2
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r2.2 opth-gen.awk
--- opth-gen.awk 14 Mar 2005 20:18:38 -0000 2.2
+++ opth-gen.awk 18 Mar 2005 08:59:01 -0000
@@ -127,7 +127,7 @@ for (i = 0; i < n_opts; i++)
# a later switch S is a longer prefix of a switch T, T
# will be back-chained to S in a later iteration of this
# for() loop, which is what we want.
- if (flags[i] ~ "Joined") {
+ if (flag_set_p("Joined.*", flags[i])) {
for (j = i + 1; j < n_opts; j++) {
if (substr (opts[j], 1, len) != opts[i])
break;
Index: optc-gen.awk
===================================================================
RCS file: /cvs/gcc/gcc/gcc/optc-gen.awk,v
retrieving revision 2.1
diff -u -p -F^\([(a-zA-Z0-9_]\|#define\) -r2.1 optc-gen.awk
--- optc-gen.awk 18 Jun 2004 01:59:45 -0000 2.1
+++ optc-gen.awk 18 Mar 2005 08:59:01 -0000
@@ -63,22 +63,16 @@ for (i = 0; i < n_opts; i++) {
if (name == "")
continue;
- if (flags[i] ~ "VarExists")
+ if (flag_set_p("VarExists", flags[i]))
continue;
- if (flags[i] ~ "Init\\(")
- {
- init = flags[i];
- sub(".*Init\\(","",init);
- sub("\\).*","",init);
- init = " = " init;
- }
- else
- init = "";
+ init = opt_args("Init", flags[i])
+ if (init != "")
+ init = " = " init;
- printf ("/* Set by -%s.\n %s */\nint %s%s;\n\n",
+ printf ("/* Set by -%s.\n %s */\nint %s%s;\n\n",
opts[i], help[i], name,init)
- }
+}
print "const char * const lang_names[] =\n{"
@@ -117,7 +111,7 @@ for (i = 0; i < n_opts; i++)
# a later switch S is a longer prefix of a switch T, T
# will be back-chained to S in a later iteration of this
# for() loop, which is what we want.
- if (flags[i] ~ "Joined") {
+ if (flag_set_p("Joined.*", flags[i])) {
for (j = i + 1; j < n_opts; j++) {
if (substr (opts[j], 1, len) != opts[i])
break;