]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/opts.h
sh: Fixes for RTL checking
[thirdparty/gcc.git] / gcc / opts.h
CommitLineData
2772ef3e 1/* Command line option handling.
cbe34bb5 2 Copyright (C) 2002-2017 Free Software Foundation, Inc.
2772ef3e
NB
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify it under
7the terms of the GNU General Public License as published by the Free
9dcd6f09 8Software Foundation; either version 3, or (at your option) any later
2772ef3e
NB
9version.
10
11GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12WARRANTY; without even the implied warranty of MERCHANTABILITY or
13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14for more details.
15
16You should have received a copy of the GNU General Public License
9dcd6f09
NC
17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
2772ef3e
NB
19
20#ifndef GCC_OPTS_H
21#define GCC_OPTS_H
22
dc357798 23#include "obstack.h"
a4d8c676 24
75685792 25/* Specifies how a switch's VAR_VALUE relates to its FLAG_VAR. */
55bea00a 26enum cl_var_type {
75685792
RS
27 /* The switch is enabled when FLAG_VAR is nonzero. */
28 CLVC_BOOLEAN,
29
30 /* The switch is enabled when FLAG_VAR == VAR_VALUE. */
31 CLVC_EQUAL,
32
33 /* The switch is enabled when VAR_VALUE is not set in FLAG_VAR. */
34 CLVC_BIT_CLEAR,
35
36 /* The switch is enabled when VAR_VALUE is set in FLAG_VAR. */
55bea00a
RS
37 CLVC_BIT_SET,
38
39 /* The switch takes a string argument and FLAG_VAR points to that
40 argument. */
21bf1558
JM
41 CLVC_STRING,
42
e6d4b984
JM
43 /* The switch takes an enumerated argument (VAR_ENUM says what
44 enumeration) and FLAG_VAR points to that argument. */
45 CLVC_ENUM,
46
21bf1558
JM
47 /* The switch should be stored in the VEC pointed to by FLAG_VAR for
48 later processing. */
49 CLVC_DEFER
75685792 50};
2772ef3e 51
35399bdc
NB
52struct cl_option
53{
300d83d9 54 /* Text of the option, including initial '-'. */
35399bdc 55 const char *opt_text;
300d83d9 56 /* Help text for --help, or NULL. */
cf03fd63 57 const char *help;
300d83d9 58 /* Error message for missing argument, or NULL. */
61ff2bdc 59 const char *missing_argument_error;
300d83d9 60 /* Warning to give when this option is used, or NULL. */
2d2bd949 61 const char *warn_message;
300d83d9 62 /* Argument of alias target when positive option given, or NULL. */
5de8299c 63 const char *alias_arg;
300d83d9 64 /* Argument of alias target when negative option given, or NULL. */
5de8299c 65 const char *neg_alias_arg;
300d83d9 66 /* Alias target, or N_OPTS if not an alias. */
5de8299c 67 unsigned short alias_target;
300d83d9
JM
68 /* Previous option that is an initial substring of this one, or
69 N_OPTS if none. */
9cd23ed2 70 unsigned short back_chain;
300d83d9 71 /* Option length, not including initial '-'. */
35399bdc 72 unsigned char opt_len;
300d83d9 73 /* Next option in a sequence marked with Negative, or -1 if none. */
14c7833c 74 int neg_index;
300d83d9 75 /* CL_* flags for this option. */
d7b42618 76 unsigned int flags;
300d83d9
JM
77 /* Disabled in this configuration. */
78 BOOL_BITFIELD cl_disabled : 1;
79 /* Options marked with CL_SEPARATE take a number of separate
80 arguments (1 to 4) that is one more than the number in this
81 bit-field. */
82 unsigned int cl_separate_nargs : 2;
83 /* Option is an alias when used with separate argument. */
84 BOOL_BITFIELD cl_separate_alias : 1;
85 /* Alias to negative form of option. */
86 BOOL_BITFIELD cl_negative_alias : 1;
87 /* Option takes no argument in the driver. */
88 BOOL_BITFIELD cl_no_driver_arg : 1;
89 /* Reject this option in the driver. */
90 BOOL_BITFIELD cl_reject_driver : 1;
91 /* Reject no- form. */
92 BOOL_BITFIELD cl_reject_negative : 1;
93 /* Missing argument OK (joined). */
94 BOOL_BITFIELD cl_missing_ok : 1;
95 /* Argument is an integer >=0. */
96 BOOL_BITFIELD cl_uinteger : 1;
99114bbf
L
97 /* Argument is a HOST_WIDE_INT. */
98 BOOL_BITFIELD cl_host_wide_int : 1;
413519ae
JM
99 /* Argument should be converted to lowercase. */
100 BOOL_BITFIELD cl_tolower : 1;
300d83d9
JM
101 /* Report argument with -fverbose-asm */
102 BOOL_BITFIELD cl_report : 1;
103 /* Offset of field for this option in struct gcc_options, or
104 (unsigned short) -1 if none. */
46625112 105 unsigned short flag_var_offset;
300d83d9
JM
106 /* Index in cl_enums of enum used for this option's arguments, for
107 CLVC_ENUM options. */
e6d4b984 108 unsigned short var_enum;
300d83d9 109 /* How this option's value is determined and sets a field. */
55bea00a 110 enum cl_var_type var_type;
300d83d9 111 /* Value or bit-mask with which to set a field. */
99114bbf 112 HOST_WIDE_INT var_value;
35399bdc
NB
113};
114
5c60a017
RS
115/* Records that the state of an option consists of SIZE bytes starting
116 at DATA. DATA might point to CH in some cases. */
117struct cl_option_state {
118 const void *data;
119 size_t size;
120 char ch;
121};
122
35399bdc
NB
123extern const struct cl_option cl_options[];
124extern const unsigned int cl_options_count;
f18754d6 125extern const char *const lang_names[];
c662432e 126extern const unsigned int cl_lang_count;
35399bdc 127
58265ea6
GF
128#define CL_PARAMS (1U << 16) /* Fake entry. Used to display --param info with --help. */
129#define CL_WARNING (1U << 17) /* Enables an (optional) warning message. */
130#define CL_OPTIMIZATION (1U << 18) /* Enables an (optional) optimization. */
131#define CL_DRIVER (1U << 19) /* Driver option. */
132#define CL_TARGET (1U << 20) /* Target-specific option. */
133#define CL_COMMON (1U << 21) /* Language-independent. */
a1fd13d0
JJ
134
135#define CL_MIN_OPTION_CLASS CL_PARAMS
c662432e
NC
136#define CL_MAX_OPTION_CLASS CL_COMMON
137
138/* From here on the bits describe attributes of the options.
139 Before this point the bits have described the class of the option.
140 This distinction is important because --help will not list options
141 which only have these higher bits set. */
142
58265ea6
GF
143#define CL_JOINED (1U << 22) /* If takes joined argument. */
144#define CL_SEPARATE (1U << 23) /* If takes a separate argument. */
145#define CL_UNDOCUMENTED (1U << 24) /* Do not output with --help. */
77ee7190 146#define CL_NO_DWARF_RECORD (1U << 25) /* Do not add to producer string. */
212bfe71 147#define CL_PCH_IGNORE (1U << 26) /* Do compare state for pch. */
2772ef3e 148
e6d4b984
JM
149/* Flags for an enumerated option argument. */
150#define CL_ENUM_CANONICAL (1 << 0) /* Canonical for this value. */
151#define CL_ENUM_DRIVER_ONLY (1 << 1) /* Only accepted in the driver. */
152
153/* Structure describing an enumerated option argument. */
154
155struct cl_enum_arg
156{
157 /* The argument text, or NULL at the end of the array. */
158 const char *arg;
159
160 /* The corresponding integer value. */
161 int value;
162
163 /* Flags associated with this argument. */
164 unsigned int flags;
165};
166
167/* Structure describing an enumerated set of option arguments. */
168
169struct cl_enum
170{
171 /* Help text, or NULL if the values should not be listed in --help
172 output. */
173 const char *help;
174
175 /* Error message for unknown arguments, or NULL to use a generic
176 error. */
177 const char *unknown_error;
178
179 /* Array of possible values. */
180 const struct cl_enum_arg *values;
181
182 /* The size of the type used to store a value. */
183 size_t var_size;
184
185 /* Function to set a variable of this type. */
186 void (*set) (void *var, int value);
187
188 /* Function to get the value of a variable of this type. */
189 int (*get) (const void *var);
190};
191
192extern const struct cl_enum cl_enums[];
193extern const unsigned int cl_enums_count;
194
5d4b393f
JM
195/* Possible ways in which a command-line option may be erroneous.
196 These do not include not being known at all; an option index of
6e2f1956 197 OPT_SPECIAL_unknown is used for that. */
5d4b393f
JM
198
199#define CL_ERR_DISABLED (1 << 0) /* Disabled in this configuration. */
200#define CL_ERR_MISSING_ARG (1 << 1) /* Argument required but missing. */
201#define CL_ERR_WRONG_LANG (1 << 2) /* Option for wrong language. */
202#define CL_ERR_UINT_ARG (1 << 3) /* Bad unsigned integer argument. */
e6d4b984
JM
203#define CL_ERR_ENUM_ARG (1 << 4) /* Bad enumerated argument. */
204#define CL_ERR_NEGATIVE (1 << 5) /* Negative form of option
184eb658
JM
205 not permitted (together
206 with OPT_SPECIAL_unknown). */
5d4b393f
JM
207
208/* Structure describing the result of decoding an option. */
209
210struct cl_decoded_option
211{
6e2f1956
JM
212 /* The index of this option, or an OPT_SPECIAL_* value for
213 non-options and unknown options. */
5d4b393f
JM
214 size_t opt_index;
215
2d2bd949
JM
216 /* Any warning to give for use of this option, or NULL if none. */
217 const char *warn_message;
218
6e2f1956
JM
219 /* The string argument, or NULL if none. For OPT_SPECIAL_* cases,
220 the option or non-option command-line argument. */
5d4b393f
JM
221 const char *arg;
222
6e2f1956
JM
223 /* The original text of option plus arguments, with separate argv
224 elements concatenated into one string with spaces separating
225 them. This is for such uses as diagnostics and
226 -frecord-gcc-switches. */
227 const char *orig_option_with_args_text;
228
7a9bf9a4
JM
229 /* The canonical form of the option and its argument, for when it is
230 necessary to reconstruct argv elements (in particular, for
231 processing specs and passing options to subprocesses from the
eea13ead
JM
232 driver). */
233 const char *canonical_option[4];
234
235 /* The number of elements in the canonical form of the option and
236 arguments; always at least 1. */
237 size_t canonical_option_num_elements;
7a9bf9a4 238
5d4b393f
JM
239 /* For a boolean option, 1 for the true case and 0 for the "no-"
240 case. For an unsigned integer option, the value of the
241 argument. 1 in all other cases. */
242 int value;
243
244 /* Any flags describing errors detected in this option. */
245 int errors;
246};
247
21bf1558
JM
248/* Structure describing an option deferred for handling after the main
249 option handlers. */
250
84562394 251struct cl_deferred_option
21bf1558
JM
252{
253 /* Elements from struct cl_decoded_option used for deferred
254 options. */
255 size_t opt_index;
256 const char *arg;
257 int value;
84562394 258};
21bf1558 259
5f20c657
JM
260/* Structure describing a single option-handling callback. */
261
262struct cl_option_handler_func
263{
264 /* The function called to handle the option. */
46625112 265 bool (*handler) (struct gcc_options *opts,
d4d24ba4 266 struct gcc_options *opts_set,
46625112 267 const struct cl_decoded_option *decoded,
a4d8c676 268 unsigned int lang_mask, int kind, location_t loc,
d5478783
JM
269 const struct cl_option_handlers *handlers,
270 diagnostic_context *dc);
5f20c657
JM
271
272 /* The mask that must have some bit in common with the flags for the
273 option for this particular handler to be used. */
274 unsigned int mask;
275};
276
277/* Structure describing the callbacks used in handling options. */
278
279struct cl_option_handlers
280{
281 /* Callback for an unknown option to determine whether to give an
282 error for it, and possibly store information to diagnose the
283 option at a later point. Return true if an error should be
284 given, false otherwise. */
481e1176 285 bool (*unknown_option_callback) (const struct cl_decoded_option *decoded);
5f20c657
JM
286
287 /* Callback to handle, and possibly diagnose, an option for another
288 language. */
481e1176 289 void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
5f20c657
JM
290 unsigned int lang_mask);
291
5f20c657
JM
292 /* The number of individual handlers. */
293 size_t num_handlers;
294
295 /* The handlers themselves. */
296 struct cl_option_handler_func handlers[3];
297};
298
ecf835e9
KN
299/* Hold command-line options associated with stack limitation. */
300extern const char *opt_fstack_limit_symbol_arg;
301extern int opt_fstack_limit_register_no;
302
59e4e217 303/* Input file names. */
40e941af
PB
304
305extern const char **in_fnames;
306
59e4e217 307/* The count of input filenames. */
40e941af
PB
308
309extern unsigned num_in_fnames;
310
dc357798
JJ
311extern char *opts_concat (const char *first, ...);
312
313/* Obstack for option strings. */
314
315extern struct obstack opts_obstack;
316
eb50f63a 317size_t find_opt (const char *input, unsigned int lang_mask);
5d4b393f 318extern int integral_argument (const char *arg);
e6d4b984
JM
319extern bool enum_value_to_arg (const struct cl_enum_arg *enum_args,
320 const char **argp, int value,
321 unsigned int lang_mask);
6e2f1956
JM
322extern void decode_cmdline_options_to_array (unsigned int argc,
323 const char **argv,
324 unsigned int lang_mask,
325 struct cl_decoded_option **decoded_options,
326 unsigned int *decoded_options_count);
a75bfaa6
JM
327extern void init_options_once (void);
328extern void init_options_struct (struct gcc_options *opts,
329 struct gcc_options *opts_set);
de5672fc 330extern void init_opts_obstack (void);
0ef443cf 331extern void finalize_options_struct (struct gcc_options *opts);
a75bfaa6
JM
332extern void decode_cmdline_options_to_array_default_mask (unsigned int argc,
333 const char **argv,
334 struct cl_decoded_option **decoded_options,
335 unsigned int *decoded_options_count);
c5fa0890 336extern void set_default_handlers (struct cl_option_handlers *handlers);
a75bfaa6
JM
337extern void decode_options (struct gcc_options *opts,
338 struct gcc_options *opts_set,
339 struct cl_decoded_option *decoded_options,
d5478783 340 unsigned int decoded_options_count,
a4d8c676 341 location_t loc,
d5478783 342 diagnostic_context *dc);
46625112
JM
343extern int option_enabled (int opt_idx, void *opts);
344extern bool get_option_state (struct gcc_options *, int,
345 struct cl_option_state *);
d4d24ba4
JM
346extern void set_option (struct gcc_options *opts,
347 struct gcc_options *opts_set,
1ebe4b4f 348 int opt_index, int value, const char *arg, int kind,
a4d8c676 349 location_t loc, diagnostic_context *dc);
46625112 350extern void *option_flag_var (int opt_index, struct gcc_options *opts);
46625112 351bool handle_generated_option (struct gcc_options *opts,
d4d24ba4 352 struct gcc_options *opts_set,
46625112 353 size_t opt_index, const char *arg, int value,
a4d8c676 354 unsigned int lang_mask, int kind, location_t loc,
1ebe4b4f
JM
355 const struct cl_option_handlers *handlers,
356 diagnostic_context *dc);
d9d16a19
JM
357void generate_option (size_t opt_index, const char *arg, int value,
358 unsigned int lang_mask,
359 struct cl_decoded_option *decoded);
360void generate_option_input_file (const char *file,
361 struct cl_decoded_option *decoded);
46625112 362extern void read_cmdline_option (struct gcc_options *opts,
d4d24ba4 363 struct gcc_options *opts_set,
46625112 364 struct cl_decoded_option *decoded,
a4d8c676 365 location_t loc,
5f20c657 366 unsigned int lang_mask,
1ebe4b4f
JM
367 const struct cl_option_handlers *handlers,
368 diagnostic_context *dc);
c5fa0890 369extern void control_warning_option (unsigned int opt_index, int kind,
63bbf46d 370 const char *arg, bool imply, location_t loc,
c5fa0890
JM
371 unsigned int lang_mask,
372 const struct cl_option_handlers *handlers,
373 struct gcc_options *opts,
374 struct gcc_options *opts_set,
375 diagnostic_context *dc);
c1822f9c 376extern char *write_langs (unsigned int mask);
369dcbd9 377extern void print_ignored_options (void);
21bf1558 378extern void handle_common_deferred_options (void);
b1b46af0
JJ
379unsigned int parse_sanitizer_options (const char *, location_t, int,
380 unsigned int, int, bool);
c98cd5bf
JM
381extern bool common_handle_option (struct gcc_options *opts,
382 struct gcc_options *opts_set,
383 const struct cl_decoded_option *decoded,
384 unsigned int lang_mask, int kind,
385 location_t loc,
386 const struct cl_option_handlers *handlers,
387 diagnostic_context *dc);
388extern bool target_handle_option (struct gcc_options *opts,
389 struct gcc_options *opts_set,
390 const struct cl_decoded_option *decoded,
391 unsigned int lang_mask, int kind,
392 location_t loc,
393 const struct cl_option_handlers *handlers,
394 diagnostic_context *dc);
395extern void finish_options (struct gcc_options *opts,
299404a1
JM
396 struct gcc_options *opts_set,
397 location_t loc);
c98cd5bf
JM
398extern void default_options_optimization (struct gcc_options *opts,
399 struct gcc_options *opts_set,
400 struct cl_decoded_option *decoded_options,
401 unsigned int decoded_options_count,
402 location_t loc,
403 unsigned int lang_mask,
404 const struct cl_option_handlers *handlers,
405 diagnostic_context *dc);
299404a1
JM
406extern void set_struct_debug_option (struct gcc_options *opts,
407 location_t loc,
408 const char *value);
8023568e
JM
409extern bool opt_enum_arg_to_value (size_t opt_index, const char *arg,
410 int *value, unsigned int lang_mask);
61789eed
DM
411
412extern const struct sanitizer_opts_s
413{
414 const char *const name;
415 unsigned int flag;
416 size_t len;
5cc6c41c 417 bool can_recover;
61789eed
DM
418} sanitizer_opts[];
419
420extern void add_misspelling_candidates (auto_vec<char *> *candidates,
603107fb 421 const struct cl_option *option,
61789eed 422 const char *base_option);
14bce257
JJ
423extern const char *candidates_list_and_hint (const char *arg, char *&str,
424 const auto_vec <const char *> &
425 candidates);
61789eed 426
2772ef3e 427#endif