1 # Copyright (C) 2023-2024 Free Software Foundation, Inc.
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
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.
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/>.
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.
21 # This program uses functions from opt-functions.awk and code from
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
30 print "/* This file is auto-generated by options-urls-cc-gen.awk. */"
32 n_headers =
split(header_name
, headers
, " ")
33 for (i =
1; i
<= n_headers
; i
++)
34 print "#include " quote headers
[i
] quote
35 print "#include " quote
"opts.h" quote
36 print "#include " quote
"intl.h" quote
37 print "#include " quote
"insn-attr-common.h" quote
40 if (n_extra_c_includes
> 0) {
41 for (i =
0; i
< n_extra_c_includes
; i
++) {
42 print "#include " quote extra_c_includes
[i
] quote
48 print "get_opt_url_suffix (int option_index, unsigned lang_mask)"
50 print " switch (option_index)"
55 for (i =
0; i
< n_opts
; i
++) {
56 # Combine the flags of identical switches. Switches
57 # appear many times if they are handled by many front
59 while( i
+ 1 != n_opts
&& opts
[i
] == opts
[i
+ 1] ) {
60 flags
[i
+ 1] = flags
[i
] " " flags
[i
+ 1];
64 len =
length (opts
[i
]);
65 enum = opt_enum
(opts
[i
])
67 # Aliases do not get enumeration names.
68 if ((flag_set_p
("Alias.*", flags
[i
]) \
69 && !flag_set_p
("SeparateAlias", flags
[i
])) \
70 || flag_set_p
("Ignore", flags
[i
])) {
77 printf(" case %s:\n", opt_enum
(opts
[i
]))
79 # Handle any lang-specific LangUrlSuffix directives:
80 for (lang_idx =
0; lang_idx
< n_langs
; lang_idx
++) {
81 lang_name = lang_sanitized_name
(langs
[lang_idx
])
82 u = lang_url_suffix
(flags
[i
], lang_name
)
84 printf(" if (lang_mask & CL_%s)\n", lang_name
)
85 printf(" return \"%s\";\n", u
)
89 # Use any language-independent UrlSuffix directive:
90 u = url_suffix
(flags
[i
])
92 printf(" return \"%s\";\n", u
)
98 # Bump up the informational option index.
103 print " return nullptr;"