public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@redhat.com>
To: Joseph Myers <joseph@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org, David Malcolm <dmalcolm@redhat.com>
Subject: [PATCH 3/4] opts: add logic to generate options-urls.cc
Date: Thu, 16 Nov 2023 09:28:57 -0500	[thread overview]
Message-ID: <20231116142858.3996740-4-dmalcolm@redhat.com> (raw)
In-Reply-To: <20231116142858.3996740-1-dmalcolm@redhat.com>

Changed in v2:
- split out from the code that uses this
- now handles lang-specific URLs, as well as generic URLs
- the generated options-urls.cc now contains a function with a
  switch statement, rather than an array, to support
  lang-specific URLs:

const char *
get_opt_url_suffix (int option_index, unsigned lang_mask)
{
  switch (option_index)
    {
     [...snip...]
     case OPT_B:
       if (lang_mask & CL_D)
         return "gdc/Directory-Options.html#index-B";
       return "gcc/Directory-Options.html#index-B";
    [...snip...]
  return nullptr;
}

gcc/ChangeLog:
	* Makefile.in (ALL_OPT_URL_FILES): New.
	(GCC_OBJS): Add options-urls.o.
	(OBJS): Likewise.
	(OBJS-libcommon): Likewise.
	(s-options): Depend on $(ALL_OPT_URL_FILES), and add this to
	inputs to opt-gather.awk.
	(options-urls.cc): New Makefile target.
	* opt-functions.awk (url_suffix): New function.
	(lang_url_suffix): New function.
	* options-urls-cc-gen.awk: New file.
	* opts.h (get_opt_url_suffix): New decl.
---
 gcc/Makefile.in             |  18 +++++--
 gcc/opt-functions.awk       |  15 ++++++
 gcc/options-urls-cc-gen.awk | 105 ++++++++++++++++++++++++++++++++++++
 gcc/opts.h                  |   4 ++
 4 files changed, 138 insertions(+), 4 deletions(-)
 create mode 100644 gcc/options-urls-cc-gen.awk

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index f3b79b8a2663..72daf907c530 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1272,6 +1272,8 @@ FLAGS_TO_PASS = \
 # All option source files
 ALL_OPT_FILES=$(lang_opt_files) $(extra_opt_files)
 
+ALL_OPT_URL_FILES=$(patsubst %, %.urls, $(ALL_OPT_FILES))
+
 # Target specific, C specific object file
 C_TARGET_OBJS=@c_target_objs@
 
@@ -1288,7 +1290,7 @@ FORTRAN_TARGET_OBJS=@fortran_target_objs@
 RUST_TARGET_OBJS=@rust_target_objs@
 
 # Object files for gcc many-languages driver.
-GCC_OBJS = gcc.o gcc-main.o ggc-none.o gcc-urlifier.o
+GCC_OBJS = gcc.o gcc-main.o ggc-none.o gcc-urlifier.o options-urls.o
 
 c-family-warn = $(STRICT_WARN)
 
@@ -1608,6 +1610,7 @@ OBJS = \
 	optinfo.o \
 	optinfo-emit-json.o \
 	options-save.o \
+	options-urls.o \
 	opts-global.o \
 	ordered-hash-map-tests.o \
 	passes.o \
@@ -1834,7 +1837,8 @@ OBJS-libcommon = diagnostic-spec.o diagnostic.o diagnostic-color.o \
 # compiler and containing target-dependent code.
 OBJS-libcommon-target = $(common_out_object_file) prefix.o \
 	opts.o opts-common.o options.o vec.o hooks.o common/common-targhooks.o \
-	hash-table.o file-find.o spellcheck.o selftest.o opt-suggestions.o
+	hash-table.o file-find.o spellcheck.o selftest.o opt-suggestions.o \
+	options-urls.o
 
 # This lists all host objects for the front ends.
 ALL_HOST_FRONTEND_OBJS = $(foreach v,$(CONFIG_LANGUAGES),$($(v)_OBJS))
@@ -2437,9 +2441,9 @@ s-specs : Makefile
 	$(STAMP) s-specs
 
 optionlist: s-options ; @true
-s-options: $(ALL_OPT_FILES) Makefile $(srcdir)/opt-gather.awk
+s-options: $(ALL_OPT_FILES) $(ALL_OPT_URL_FILES) Makefile $(srcdir)/opt-gather.awk
 	LC_ALL=C ; export LC_ALL ; \
-	$(AWK) -f $(srcdir)/opt-gather.awk $(ALL_OPT_FILES) > tmp-optionlist
+	$(AWK) -f $(srcdir)/opt-gather.awk $(ALL_OPT_FILES) $(ALL_OPT_URL_FILES) > tmp-optionlist
 	$(SHELL) $(srcdir)/../move-if-change tmp-optionlist optionlist
 	$(STAMP) s-options
 
@@ -2455,6 +2459,12 @@ options-save.cc: optionlist $(srcdir)/opt-functions.awk $(srcdir)/opt-read.awk \
 	       -f $(srcdir)/optc-save-gen.awk \
 	       -v header_name="config.h system.h coretypes.h tm.h" < $< > $@
 
+options-urls.cc: optionlist $(srcdir)/opt-functions.awk $(srcdir)/opt-read.awk \
+    $(srcdir)/options-urls-cc-gen.awk
+	$(AWK) -f $(srcdir)/opt-functions.awk -f $(srcdir)/opt-read.awk \
+	       -f $(srcdir)/options-urls-cc-gen.awk \
+	       -v header_name="config.h system.h coretypes.h tm.h" < $< > $@
+
 options.h: s-options-h ; @true
 s-options-h: optionlist $(srcdir)/opt-functions.awk $(srcdir)/opt-read.awk \
     $(srcdir)/opth-gen.awk
diff --git a/gcc/opt-functions.awk b/gcc/opt-functions.awk
index a58e93815e30..c31e66f2105a 100644
--- a/gcc/opt-functions.awk
+++ b/gcc/opt-functions.awk
@@ -193,6 +193,21 @@ function var_name(flags)
 	return nth_arg(0, opt_args("Var", flags))
 }
 
+# If FLAGS includes a UrlSuffix flag, return the value it specifies.
+# Return the empty string otherwise.
+function url_suffix(flags)
+{
+	return nth_arg(0, opt_args("UrlSuffix", flags))
+}
+
+# If FLAGS includes a LangUrlSuffix_LANG flag, return the
+# value it specifies.
+# Return the empty string otherwise.
+function lang_url_suffix(flags, lang)
+{
+	return nth_arg(0, opt_args("LangUrlSuffix_" lang, flags))
+}
+
 # Return the name of the variable if FLAGS has a HOST_WIDE_INT variable. 
 # Return the empty string otherwise.
 function host_wide_int_var_name(flags)
diff --git a/gcc/options-urls-cc-gen.awk b/gcc/options-urls-cc-gen.awk
new file mode 100644
index 000000000000..e021e7c3f1bc
--- /dev/null
+++ b/gcc/options-urls-cc-gen.awk
@@ -0,0 +1,105 @@
+#  Copyright (C) 2023 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; either version 3, or (at your option) any
+# later version.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; see the file COPYING3.  If not see
+# <http://www.gnu.org/licenses/>.
+
+# This Awk script reads in the option records generated from 
+# opt-gather.awk, and generates a C++ file containing an array
+# of URL suffixes (possibly NULL), one per option.
+
+# This program uses functions from opt-functions.awk and code from
+# opt-read.awk.
+#
+# Usage: awk -f opt-functions.awk -f opt-read.awk -f options-urls-cc-gen.awk \
+#            [-v header_name=header.h] < inputfile > options-urls.cc
+
+END {
+
+
+print "/* This file is auto-generated by options-urls-cc-gen.awk.  */"
+print ""
+n_headers = split(header_name, headers, " ")
+for (i = 1; i <= n_headers; i++)
+	print "#include " quote headers[i] quote
+print "#include " quote "opts.h" quote
+print "#include " quote "intl.h" quote
+print "#include " quote "insn-attr-common.h" quote
+print ""
+
+if (n_extra_c_includes > 0) {
+	for (i = 0; i < n_extra_c_includes; i++) {
+		print "#include " quote extra_c_includes[i] quote
+	}
+	print ""
+}
+
+print "const char *"
+print "get_opt_url_suffix (int option_index, unsigned lang_mask)"
+print "{"
+print "  switch (option_index)"
+print "    {"
+
+
+optindex = 0
+for (i = 0; i < n_opts; i++) {
+	# Combine the flags of identical switches.  Switches
+	# appear many times if they are handled by many front
+	# ends, for example.
+	while( i + 1 != n_opts && opts[i] == opts[i + 1] ) {
+		flags[i + 1] = flags[i] " " flags[i + 1];
+		i++;
+	}
+
+	len = length (opts[i]);
+	enum = opt_enum(opts[i])
+
+	# Aliases do not get enumeration names.
+	if ((flag_set_p("Alias.*", flags[i]) \
+	     && !flag_set_p("SeparateAlias", flags[i])) \
+	    || flag_set_p("Ignore", flags[i])) {
+	    show_case = 0;
+	} else {
+	    show_case = 1;
+	}
+
+	if (show_case) {
+	    printf("     case %s:\n", opt_enum(opts[i]))
+
+	    # Handle any lang-specific LangUrlSuffix directives:
+	    for (lang_idx = 0; lang_idx < n_langs; lang_idx++) {
+		lang_name = lang_sanitized_name(langs[lang_idx])
+		u = lang_url_suffix(flags[i], lang_name)
+		if (u != "") {
+		    printf("       if (lang_mask & CL_%s)\n", lang_name)
+		    printf("         return \"%s\";\n", u)
+		}
+	    }
+
+	    # Use any language-independent UrlSuffix directive:
+	    u = url_suffix(flags[i])
+	    if (u != "") {
+		printf("       return \"%s\";\n", u)
+	    } else {
+		printf("       break;\n")
+	    }
+	}
+
+	# Bump up the informational option index.
+	++optindex
+ }
+
+print "    }"
+print "  return nullptr;"
+print "}"
+}
diff --git a/gcc/opts.h b/gcc/opts.h
index 00f377f9ca7e..0e47d3425604 100644
--- a/gcc/opts.h
+++ b/gcc/opts.h
@@ -152,6 +152,10 @@ struct cl_option_state {
 
 extern const struct cl_option cl_options[];
 extern const unsigned int cl_options_count;
+
+extern const char *
+get_opt_url_suffix (int option_index, unsigned lang_mask);
+
 #ifdef ENABLE_PLUGIN
 extern const struct cl_var cl_vars[];
 #endif
-- 
2.26.3


  parent reply	other threads:[~2023-11-16 14:29 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-10 21:42 [PATCH 0/3] Option handling: add documentation URLs David Malcolm
2023-11-10 21:42 ` [PATCH 1/3] options: add gcc/regenerate-opt-urls.py David Malcolm
2023-11-10 21:42 ` [PATCH 2/3] Add generated .opt.urls files David Malcolm
2023-11-12 10:56   ` Iain Buclaw
2023-11-13 14:07     ` David Malcolm
2023-11-13 13:11   ` Marc Poulhiès
2023-11-13 14:07     ` David Malcolm
2023-11-13 16:02       ` Marc Poulhiès
2023-12-19 14:47         ` Marc Poulhiès
2023-11-10 21:42 ` [PATCH 3/3] diagnostics: use the .opt.urls files to urlify quoted text David Malcolm
2023-11-14 17:44   ` Arthur Cohen
2023-11-14  0:12 ` [PATCH 0/3] Option handling: add documentation URLs Joseph Myers
2023-11-15 22:50   ` David Malcolm
2023-11-15 23:40     ` Joseph Myers
2023-11-16 14:28       ` [PATCH 0/4] v2 of " David Malcolm
2023-11-16 14:28         ` [PATCH 1/4] options: add gcc/regenerate-opt-urls.py David Malcolm
2023-11-16 14:28         ` [PATCH 2/4] Add generated .opt.urls files David Malcolm
2023-11-16 14:28         ` David Malcolm [this message]
2023-11-16 14:28         ` [PATCH 4/4] options: wire up options-urls.cc into gcc_urlifier David Malcolm
2023-11-21  1:09         ` [PATCH 0/4] v2 of Option handling: add documentation URLs Hans-Peter Nilsson
2023-11-21 13:57           ` David Malcolm
2023-11-21 14:12             ` Tobias Burnus
2023-11-21 15:23               ` David Malcolm
2023-11-21 23:43               ` Joseph Myers
2023-12-08 23:35                 ` David Malcolm
2023-12-10 23:35                   ` Mark Wielaard
2023-12-14 15:01                     ` [PATCH 0/4] v3 of: " David Malcolm
2023-12-14 15:01                       ` [PATCH 1/4; v3] options: add gcc/regenerate-opt-urls.py David Malcolm
2023-12-20  0:24                         ` Joseph Myers
2023-12-14 15:01                       ` [PATCH 2/4; v3] Add generated .opt.urls files David Malcolm
2023-12-14 15:01                       ` [PATCH 3/4; v2] opts: add logic to generate options-urls.cc David Malcolm
2023-12-14 15:01                       ` [PATCH 4/4; v2] options: wire up options-urls.cc into gcc_urlifier David Malcolm
2023-12-15  0:59                       ` [PATCH 0/4] v3 of: Option handling: add documentation URLs Mark Wielaard
2023-12-15 14:47                         ` David Malcolm
2024-01-04 14:57                         ` CI for "Option handling: add documentation URLs" David Malcolm
2024-02-18 22:58                           ` Mark Wielaard
2024-02-19 11:38                             ` Mark Wielaard
2024-02-22  3:57                             ` YunQiang Su
2024-02-24 17:42                               ` Mark Wielaard
2024-03-03 20:04                                 ` Mark Wielaard
2024-03-04 13:48                                   ` David Malcolm
2024-03-05 12:06                                     ` Mark Wielaard
2024-03-05 13:34                                       ` David Malcolm
2024-03-05 20:24                                         ` Mark Wielaard
2024-03-15  7:33                                           ` YunQiang Su
2024-03-15 10:06                                             ` Mark Wielaard
2023-12-20  0:28                       ` [PATCH 0/4] v3 of: Option handling: add documentation URLs Joseph Myers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231116142858.3996740-4-dmalcolm@redhat.com \
    --to=dmalcolm@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=joseph@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).