| 1 |
# Copyright (C) 2023-2025 Free Software Foundation, Inc. |
| 2 |
# |
| 3 |
# This program is free software; you can redistribute it and/or modify it |
| 4 |
# under the terms of the GNU General Public License as published by the |
| 5 |
# Free Software Foundation; either version 3, or (at your option) any |
| 6 |
# later version. |
| 7 |
# |
| 8 |
# This program is distributed in the hope that it will be useful, |
| 9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
# GNU General Public License for more details. |
| 12 |
# |
| 13 |
# You should have received a copy of the GNU General Public License |
| 14 |
# along with this program; see the file COPYING3. If not see |
| 15 |
# <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
# This Awk script reads in the option records generated from |
| 18 |
# opt-gather.awk, and generates a C++ file containing an array |
| 19 |
# of URL suffixes (possibly NULL), one per option. |
| 20 |
|
| 21 |
# This program uses functions from opt-functions.awk and code from |
| 22 |
# opt-read.awk. |
| 23 |
# |
| 24 |
# Usage: awk -f opt-functions.awk -f opt-read.awk -f options-urls-cc-gen.awk \ |
| 25 |
# [-v header_name=header.h] < inputfile > options-urls.cc |
| 26 |
|
| 27 |
END { |
| 28 |
|
| 29 |
|
| 30 |
print "/* This file is auto-generated by options-urls-cc-gen.awk. */" |
| 31 |
print "" |
| 32 |
print "#define INCLUDE_MEMORY" |
| 33 |
n_headers = split(header_name, headers, " ") |
| 34 |
for (i = 1; i <= n_headers; i++) |
| 35 |
print "#include " quote headers[i] quote |
| 36 |
print "#include " quote "opts.h" quote |
| 37 |
print "#include " quote "intl.h" quote |
| 38 |
print "#include " quote "insn-attr-common.h" quote |
| 39 |
print "" |
| 40 |
|
| 41 |
if (n_extra_c_includes > 0) { |
| 42 |
for (i = 0; i < n_extra_c_includes; i++) { |
| 43 |
print "#include " quote extra_c_includes[i] quote |
| 44 |
} |
| 45 |
print "" |
| 46 |
} |
| 47 |
|
| 48 |
print "const char *" |
| 49 |
print "get_opt_url_suffix (int option_index, unsigned lang_mask)" |
| 50 |
print "{" |
| 51 |
print " switch (option_index)" |
| 52 |
print " {" |
| 53 |
|
| 54 |
|
| 55 |
optindex = 0 |
| 56 |
for (i = 0; i < n_opts; i++) { |
| 57 |
# Combine the flags of identical switches. Switches |
| 58 |
# appear many times if they are handled by many front |
| 59 |
# ends, for example. |
| 60 |
while( i + 1 != n_opts && opts[i] == opts[i + 1] ) { |
| 61 |
flags[i + 1] = flags[i] " " flags[i + 1]; |
| 62 |
i++; |
| 63 |
} |
| 64 |
|
| 65 |
len = length (opts[i]); |
| 66 |
enum = opt_enum(opts[i]) |
| 67 |
|
| 68 |
# Aliases do not get enumeration names. |
| 69 |
if ((flag_set_p("Alias.*", flags[i]) \ |
| 70 |
&& !flag_set_p("SeparateAlias", flags[i])) \ |
| 71 |
|| flag_set_p("Ignore", flags[i])) { |
| 72 |
show_case = 0; |
| 73 |
} else { |
| 74 |
show_case = 1; |
| 75 |
} |
| 76 |
|
| 77 |
if (show_case) { |
| 78 |
printf(" case %s:\n", opt_enum(opts[i])) |
| 79 |
|
| 80 |
# Handle any lang-specific LangUrlSuffix directives: |
| 81 |
for (lang_idx = 0; lang_idx < n_langs; lang_idx++) { |
| 82 |
lang_name = lang_sanitized_name(langs[lang_idx]) |
| 83 |
u = lang_url_suffix(flags[i], lang_name) |
| 84 |
if (u != "") { |
| 85 |
printf(" if (lang_mask & CL_%s)\n", lang_name) |
| 86 |
printf(" return \"%s\";\n", u) |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
# Use any language-independent UrlSuffix directive: |
| 91 |
u = url_suffix(flags[i]) |
| 92 |
if (u != "") { |
| 93 |
printf(" return \"%s\";\n", u) |
| 94 |
} else { |
| 95 |
printf(" break;\n") |
| 96 |
} |
| 97 |
} |
| 98 |
|
| 99 |
# Bump up the informational option index. |
| 100 |
++optindex |
| 101 |
} |
| 102 |
|
| 103 |
print " }" |
| 104 |
print " return nullptr;" |
| 105 |
print "}" |
| 106 |
} |