Fix PR ada/97504 on hppa*-*-hpux*.
[official-gcc.git] / gcc / opts.h
blobd62bfcfdf6af1dcdfc3c94e4401ee9fbab63e6a9
1 /* Command line option handling.
2 Copyright (C) 2002-2020 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_OPTS_H
21 #define GCC_OPTS_H
23 #include "obstack.h"
25 /* Specifies how a switch's VAR_VALUE relates to its FLAG_VAR. */
26 enum cl_var_type {
27 /* The switch is enabled when FLAG_VAR is nonzero. */
28 CLVC_BOOLEAN,
30 /* The switch is enabled when FLAG_VAR == VAR_VALUE. */
31 CLVC_EQUAL,
33 /* The switch is enabled when VAR_VALUE is not set in FLAG_VAR. */
34 CLVC_BIT_CLEAR,
36 /* The switch is enabled when VAR_VALUE is set in FLAG_VAR. */
37 CLVC_BIT_SET,
39 /* The switch is enabled when FLAG_VAR is less than HOST_WIDE_INT_M1U. */
40 CLVC_SIZE,
42 /* The switch takes a string argument and FLAG_VAR points to that
43 argument. */
44 CLVC_STRING,
46 /* The switch takes an enumerated argument (VAR_ENUM says what
47 enumeration) and FLAG_VAR points to that argument. */
48 CLVC_ENUM,
50 /* The switch should be stored in the VEC pointed to by FLAG_VAR for
51 later processing. */
52 CLVC_DEFER
55 struct cl_option
57 /* Text of the option, including initial '-'. */
58 const char *opt_text;
59 /* Help text for --help, or NULL. */
60 const char *help;
61 /* Error message for missing argument, or NULL. */
62 const char *missing_argument_error;
63 /* Warning to give when this option is used, or NULL. */
64 const char *warn_message;
65 /* Argument of alias target when positive option given, or NULL. */
66 const char *alias_arg;
67 /* Argument of alias target when negative option given, or NULL. */
68 const char *neg_alias_arg;
69 /* Alias target, or N_OPTS if not an alias. */
70 unsigned short alias_target;
71 /* Previous option that is an initial substring of this one, or
72 N_OPTS if none. */
73 unsigned short back_chain;
74 /* Option length, not including initial '-'. */
75 unsigned char opt_len;
76 /* Next option in a sequence marked with Negative, or -1 if none.
77 For a single option with both a negative and a positve form
78 (such as -Wall and -Wno-all), NEG_IDX is equal to the option's
79 own index (i.e., cl_options[IDX].neg_idx == IDX holds). */
80 int neg_index;
81 /* CL_* flags for this option. */
82 unsigned int flags;
83 /* Disabled in this configuration. */
84 BOOL_BITFIELD cl_disabled : 1;
85 /* Options marked with CL_SEPARATE take a number of separate
86 arguments (1 to 4) that is one more than the number in this
87 bit-field. */
88 unsigned int cl_separate_nargs : 2;
89 /* Option is an alias when used with separate argument. */
90 BOOL_BITFIELD cl_separate_alias : 1;
91 /* Alias to negative form of option. */
92 BOOL_BITFIELD cl_negative_alias : 1;
93 /* Option takes no argument in the driver. */
94 BOOL_BITFIELD cl_no_driver_arg : 1;
95 /* Reject this option in the driver. */
96 BOOL_BITFIELD cl_reject_driver : 1;
97 /* Reject no- form. */
98 BOOL_BITFIELD cl_reject_negative : 1;
99 /* Missing argument OK (joined). */
100 BOOL_BITFIELD cl_missing_ok : 1;
101 /* Argument is an integer >=0. */
102 BOOL_BITFIELD cl_uinteger : 1;
103 /* Argument is a HOST_WIDE_INT. */
104 BOOL_BITFIELD cl_host_wide_int : 1;
105 /* Argument should be converted to lowercase. */
106 BOOL_BITFIELD cl_tolower : 1;
107 /* Report argument with -fverbose-asm */
108 BOOL_BITFIELD cl_report : 1;
109 /* Argument is an unsigned integer with an optional byte suffix. */
110 BOOL_BITFIELD cl_byte_size: 1;
111 /* Offset of field for this option in struct gcc_options, or
112 (unsigned short) -1 if none. */
113 unsigned short flag_var_offset;
114 /* Index in cl_enums of enum used for this option's arguments, for
115 CLVC_ENUM options. */
116 unsigned short var_enum;
117 /* How this option's value is determined and sets a field. */
118 enum cl_var_type var_type;
119 /* Value or bit-mask with which to set a field. */
120 HOST_WIDE_INT var_value;
121 /* Range info minimum, or -1. */
122 int range_min;
123 /* Range info maximum, or -1. */
124 int range_max;
127 struct cl_var
129 /* Name of the variable. */
130 const char *var_name;
131 /* Offset of field for this var in struct gcc_options. */
132 unsigned short var_offset;
135 /* Records that the state of an option consists of SIZE bytes starting
136 at DATA. DATA might point to CH in some cases. */
137 struct cl_option_state {
138 const void *data;
139 size_t size;
140 char ch;
143 extern const struct cl_option cl_options[];
144 extern const unsigned int cl_options_count;
145 #ifdef ENABLE_PLUGIN
146 extern const struct cl_var cl_vars[];
147 #endif
148 extern const char *const lang_names[];
149 extern const unsigned int cl_lang_count;
151 #define CL_PARAMS (1U << 16) /* Fake entry. Used to display --param info with --help. */
152 #define CL_WARNING (1U << 17) /* Enables an (optional) warning message. */
153 #define CL_OPTIMIZATION (1U << 18) /* Enables an (optional) optimization. */
154 #define CL_DRIVER (1U << 19) /* Driver option. */
155 #define CL_TARGET (1U << 20) /* Target-specific option. */
156 #define CL_COMMON (1U << 21) /* Language-independent. */
158 #define CL_MIN_OPTION_CLASS CL_PARAMS
159 #define CL_MAX_OPTION_CLASS CL_COMMON
161 /* From here on the bits describe attributes of the options.
162 Before this point the bits have described the class of the option.
163 This distinction is important because --help will not list options
164 which only have these higher bits set. */
166 #define CL_JOINED (1U << 22) /* If takes joined argument. */
167 #define CL_SEPARATE (1U << 23) /* If takes a separate argument. */
168 #define CL_UNDOCUMENTED (1U << 24) /* Do not output with --help. */
169 #define CL_NO_DWARF_RECORD (1U << 25) /* Do not add to producer string. */
170 #define CL_PCH_IGNORE (1U << 26) /* Do compare state for pch. */
172 /* Flags for an enumerated option argument. */
173 #define CL_ENUM_CANONICAL (1 << 0) /* Canonical for this value. */
174 #define CL_ENUM_DRIVER_ONLY (1 << 1) /* Only accepted in the driver. */
176 /* Structure describing an enumerated option argument. */
178 struct cl_enum_arg
180 /* The argument text, or NULL at the end of the array. */
181 const char *arg;
183 /* The corresponding integer value. */
184 int value;
186 /* Flags associated with this argument. */
187 unsigned int flags;
190 /* Structure describing an enumerated set of option arguments. */
192 struct cl_enum
194 /* Help text, or NULL if the values should not be listed in --help
195 output. */
196 const char *help;
198 /* Error message for unknown arguments, or NULL to use a generic
199 error. */
200 const char *unknown_error;
202 /* Array of possible values. */
203 const struct cl_enum_arg *values;
205 /* The size of the type used to store a value. */
206 size_t var_size;
208 /* Function to set a variable of this type. */
209 void (*set) (void *var, int value);
211 /* Function to get the value of a variable of this type. */
212 int (*get) (const void *var);
215 extern const struct cl_enum cl_enums[];
216 extern const unsigned int cl_enums_count;
218 /* Possible ways in which a command-line option may be erroneous.
219 These do not include not being known at all; an option index of
220 OPT_SPECIAL_unknown is used for that. */
222 #define CL_ERR_DISABLED (1 << 0) /* Disabled in this configuration. */
223 #define CL_ERR_MISSING_ARG (1 << 1) /* Argument required but missing. */
224 #define CL_ERR_WRONG_LANG (1 << 2) /* Option for wrong language. */
225 #define CL_ERR_UINT_ARG (1 << 3) /* Bad unsigned integer argument. */
226 #define CL_ERR_INT_RANGE_ARG (1 << 4) /* Bad unsigned integer argument. */
227 #define CL_ERR_ENUM_ARG (1 << 5) /* Bad enumerated argument. */
228 #define CL_ERR_NEGATIVE (1 << 6) /* Negative form of option
229 not permitted (together
230 with OPT_SPECIAL_unknown). */
232 /* Structure describing the result of decoding an option. */
234 struct cl_decoded_option
236 /* The index of this option, or an OPT_SPECIAL_* value for
237 non-options and unknown options. */
238 size_t opt_index;
240 /* Any warning to give for use of this option, or NULL if none. */
241 const char *warn_message;
243 /* The string argument, or NULL if none. For OPT_SPECIAL_* cases,
244 the option or non-option command-line argument. */
245 const char *arg;
247 /* The original text of option plus arguments, with separate argv
248 elements concatenated into one string with spaces separating
249 them. This is for such uses as diagnostics and
250 -frecord-gcc-switches. */
251 const char *orig_option_with_args_text;
253 /* The canonical form of the option and its argument, for when it is
254 necessary to reconstruct argv elements (in particular, for
255 processing specs and passing options to subprocesses from the
256 driver). */
257 const char *canonical_option[4];
259 /* The number of elements in the canonical form of the option and
260 arguments; always at least 1. */
261 size_t canonical_option_num_elements;
263 /* For a boolean option, 1 for the true case and 0 for the "no-"
264 case. For an unsigned integer option, the value of the
265 argument. 1 in all other cases. */
266 HOST_WIDE_INT value;
268 /* Any flags describing errors detected in this option. */
269 int errors;
272 /* Structure describing an option deferred for handling after the main
273 option handlers. */
275 struct cl_deferred_option
277 /* Elements from struct cl_decoded_option used for deferred
278 options. */
279 size_t opt_index;
280 const char *arg;
281 int value;
284 /* Structure describing a single option-handling callback. */
286 struct cl_option_handler_func
288 /* The function called to handle the option. */
289 bool (*handler) (struct gcc_options *opts,
290 struct gcc_options *opts_set,
291 const struct cl_decoded_option *decoded,
292 unsigned int lang_mask, int kind, location_t loc,
293 const struct cl_option_handlers *handlers,
294 diagnostic_context *dc,
295 void (*target_option_override_hook) (void));
297 /* The mask that must have some bit in common with the flags for the
298 option for this particular handler to be used. */
299 unsigned int mask;
302 /* Structure describing the callbacks used in handling options. */
304 struct cl_option_handlers
306 /* Callback for an unknown option to determine whether to give an
307 error for it, and possibly store information to diagnose the
308 option at a later point. Return true if an error should be
309 given, false otherwise. */
310 bool (*unknown_option_callback) (const struct cl_decoded_option *decoded);
312 /* Callback to handle, and possibly diagnose, an option for another
313 language. */
314 void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
315 unsigned int lang_mask);
317 /* Target option override hook. */
318 void (*target_option_override_hook) (void);
320 /* The number of individual handlers. */
321 size_t num_handlers;
323 /* The handlers themselves. */
324 struct cl_option_handler_func handlers[3];
327 /* Hold command-line options associated with stack limitation. */
328 extern const char *opt_fstack_limit_symbol_arg;
329 extern int opt_fstack_limit_register_no;
331 /* Input file names. */
333 extern const char **in_fnames;
335 /* The count of input filenames. */
337 extern unsigned num_in_fnames;
339 extern char *opts_concat (const char *first, ...);
341 /* Obstack for option strings. */
343 extern struct obstack opts_obstack;
345 size_t find_opt (const char *input, unsigned int lang_mask);
346 extern HOST_WIDE_INT integral_argument (const char *arg, int * = NULL, bool = false);
347 extern bool enum_value_to_arg (const struct cl_enum_arg *enum_args,
348 const char **argp, int value,
349 unsigned int lang_mask);
350 extern void decode_cmdline_options_to_array (unsigned int argc,
351 const char **argv,
352 unsigned int lang_mask,
353 struct cl_decoded_option **decoded_options,
354 unsigned int *decoded_options_count);
355 extern void init_options_once (void);
356 extern void init_options_struct (struct gcc_options *opts,
357 struct gcc_options *opts_set);
358 extern void init_opts_obstack (void);
359 extern void decode_cmdline_options_to_array_default_mask (unsigned int argc,
360 const char **argv,
361 struct cl_decoded_option **decoded_options,
362 unsigned int *decoded_options_count);
363 extern void set_default_handlers (struct cl_option_handlers *handlers,
364 void (*target_option_override_hook) (void));
365 extern void decode_options (struct gcc_options *opts,
366 struct gcc_options *opts_set,
367 struct cl_decoded_option *decoded_options,
368 unsigned int decoded_options_count,
369 location_t loc,
370 diagnostic_context *dc,
371 void (*target_option_override_hook) (void));
372 extern int option_enabled (int opt_idx, unsigned lang_mask, void *opts);
374 extern bool get_option_state (struct gcc_options *, int,
375 struct cl_option_state *);
376 extern void set_option (struct gcc_options *opts,
377 struct gcc_options *opts_set,
378 int opt_index, HOST_WIDE_INT value, const char *arg,
379 int kind, location_t loc, diagnostic_context *dc);
380 extern void *option_flag_var (int opt_index, struct gcc_options *opts);
381 bool handle_generated_option (struct gcc_options *opts,
382 struct gcc_options *opts_set,
383 size_t opt_index, const char *arg,
384 HOST_WIDE_INT value,
385 unsigned int lang_mask, int kind, location_t loc,
386 const struct cl_option_handlers *handlers,
387 bool generated_p, diagnostic_context *dc);
388 void generate_option (size_t opt_index, const char *arg, HOST_WIDE_INT value,
389 unsigned int lang_mask,
390 struct cl_decoded_option *decoded);
391 void generate_option_input_file (const char *file,
392 struct cl_decoded_option *decoded);
393 extern void read_cmdline_option (struct gcc_options *opts,
394 struct gcc_options *opts_set,
395 struct cl_decoded_option *decoded,
396 location_t loc,
397 unsigned int lang_mask,
398 const struct cl_option_handlers *handlers,
399 diagnostic_context *dc);
400 extern void control_warning_option (unsigned int opt_index, int kind,
401 const char *arg, bool imply, location_t loc,
402 unsigned int lang_mask,
403 const struct cl_option_handlers *handlers,
404 struct gcc_options *opts,
405 struct gcc_options *opts_set,
406 diagnostic_context *dc);
407 extern char *write_langs (unsigned int mask);
408 extern void print_ignored_options (void);
409 extern void handle_common_deferred_options (void);
410 unsigned int parse_sanitizer_options (const char *, location_t, int,
411 unsigned int, int, bool);
413 unsigned int parse_no_sanitize_attribute (char *value);
414 extern bool common_handle_option (struct gcc_options *opts,
415 struct gcc_options *opts_set,
416 const struct cl_decoded_option *decoded,
417 unsigned int lang_mask, int kind,
418 location_t loc,
419 const struct cl_option_handlers *handlers,
420 diagnostic_context *dc,
421 void (*target_option_override_hook) (void));
422 extern bool target_handle_option (struct gcc_options *opts,
423 struct gcc_options *opts_set,
424 const struct cl_decoded_option *decoded,
425 unsigned int lang_mask, int kind,
426 location_t loc,
427 const struct cl_option_handlers *handlers,
428 diagnostic_context *dc,
429 void (*target_option_override_hook) (void));
430 extern void finish_options (struct gcc_options *opts,
431 struct gcc_options *opts_set,
432 location_t loc);
433 extern void print_help (struct gcc_options *opts, unsigned int lang_mask, const
434 char *help_option_argument);
435 extern void default_options_optimization (struct gcc_options *opts,
436 struct gcc_options *opts_set,
437 struct cl_decoded_option *decoded_options,
438 unsigned int decoded_options_count,
439 location_t loc,
440 unsigned int lang_mask,
441 const struct cl_option_handlers *handlers,
442 diagnostic_context *dc);
443 extern void set_struct_debug_option (struct gcc_options *opts,
444 location_t loc,
445 const char *value);
446 extern bool opt_enum_arg_to_value (size_t opt_index, const char *arg,
447 int *value,
448 unsigned int lang_mask);
450 extern const struct sanitizer_opts_s
452 const char *const name;
453 unsigned int flag;
454 size_t len;
455 bool can_recover;
456 } sanitizer_opts[];
458 extern const struct zero_call_used_regs_opts_s
460 const char *const name;
461 unsigned int flag;
462 } zero_call_used_regs_opts[];
464 extern vec<const char *> help_option_arguments;
466 extern void add_misspelling_candidates (auto_vec<char *> *candidates,
467 const struct cl_option *option,
468 const char *base_option);
469 extern const char *candidates_list_and_hint (const char *arg, char *&str,
470 const auto_vec <const char *> &
471 candidates);
474 extern bool parse_and_check_align_values (const char *flag,
475 const char *name,
476 auto_vec<unsigned> &result_values,
477 bool report_error,
478 location_t loc);
480 extern void parse_options_from_collect_gcc_options (const char *, obstack *,
481 int *);
483 extern void prepend_xassembler_to_collect_as_options (const char *, obstack *);
485 /* Set OPTION in OPTS to VALUE if the option is not set in OPTS_SET. */
487 #define SET_OPTION_IF_UNSET(OPTS, OPTS_SET, OPTION, VALUE) \
488 do \
490 if (!(OPTS_SET)->x_ ## OPTION) \
491 (OPTS)->x_ ## OPTION = VALUE; \
493 while (false)
495 #endif