struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / cpp / gcc / opts.h
bloba43ce66cffe10ef2e1ca0d06bfdf4c1302276e0d
1 /* Command line option handling.
2 Copyright (C) 2002-2022 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 an integer value. */
28 CLVC_INTEGER,
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 /* Values for var_value member of CLVC_ENUM. */
56 enum cl_enum_var_value {
57 /* Enum without EnumSet or EnumBitSet. */
58 CLEV_NORMAL,
60 /* EnumSet. */
61 CLEV_SET,
63 /* EnumBitSet. */
64 CLEV_BITSET
67 struct cl_option
69 /* Text of the option, including initial '-'. */
70 const char *opt_text;
71 /* Help text for --help, or NULL. */
72 const char *help;
73 /* Error message for missing argument, or NULL. */
74 const char *missing_argument_error;
75 /* Warning to give when this option is used, or NULL. */
76 const char *warn_message;
77 /* Argument of alias target when positive option given, or NULL. */
78 const char *alias_arg;
79 /* Argument of alias target when negative option given, or NULL. */
80 const char *neg_alias_arg;
81 /* Alias target, or N_OPTS if not an alias. */
82 unsigned short alias_target;
83 /* Previous option that is an initial substring of this one, or
84 N_OPTS if none. */
85 unsigned short back_chain;
86 /* Option length, not including initial '-'. */
87 unsigned char opt_len;
88 /* Next option in a sequence marked with Negative, or -1 if none.
89 For a single option with both a negative and a positve form
90 (such as -Wall and -Wno-all), NEG_IDX is equal to the option's
91 own index (i.e., cl_options[IDX].neg_idx == IDX holds). */
92 int neg_index;
93 /* CL_* flags for this option. */
94 unsigned int flags;
95 /* Disabled in this configuration. */
96 BOOL_BITFIELD cl_disabled : 1;
97 /* Options marked with CL_SEPARATE take a number of separate
98 arguments (1 to 4) that is one more than the number in this
99 bit-field. */
100 unsigned int cl_separate_nargs : 2;
101 /* Option is an alias when used with separate argument. */
102 BOOL_BITFIELD cl_separate_alias : 1;
103 /* Alias to negative form of option. */
104 BOOL_BITFIELD cl_negative_alias : 1;
105 /* Option takes no argument in the driver. */
106 BOOL_BITFIELD cl_no_driver_arg : 1;
107 /* Reject this option in the driver. */
108 BOOL_BITFIELD cl_reject_driver : 1;
109 /* Reject no- form. */
110 BOOL_BITFIELD cl_reject_negative : 1;
111 /* Missing argument OK (joined). */
112 BOOL_BITFIELD cl_missing_ok : 1;
113 /* Argument is an integer >=0. */
114 BOOL_BITFIELD cl_uinteger : 1;
115 /* Argument is a HOST_WIDE_INT. */
116 BOOL_BITFIELD cl_host_wide_int : 1;
117 /* Argument should be converted to lowercase. */
118 BOOL_BITFIELD cl_tolower : 1;
119 /* Argument is an unsigned integer with an optional byte suffix. */
120 BOOL_BITFIELD cl_byte_size: 1;
121 /* Offset of field for this option in struct gcc_options, or
122 (unsigned short) -1 if none. */
123 unsigned short flag_var_offset;
124 /* Index in cl_enums of enum used for this option's arguments, for
125 CLVC_ENUM options. */
126 unsigned short var_enum;
127 /* How this option's value is determined and sets a field. */
128 enum cl_var_type var_type;
129 /* Value or bit-mask with which to set a field. */
130 HOST_WIDE_INT var_value;
131 /* Range info minimum, or -1. */
132 int range_min;
133 /* Range info maximum, or -1. */
134 int range_max;
137 struct cl_var
139 /* Name of the variable. */
140 const char *var_name;
141 /* Offset of field for this var in struct gcc_options. */
142 unsigned short var_offset;
145 /* Records that the state of an option consists of SIZE bytes starting
146 at DATA. DATA might point to CH in some cases. */
147 struct cl_option_state {
148 const void *data;
149 size_t size;
150 char ch;
153 extern const struct cl_option cl_options[];
154 extern const unsigned int cl_options_count;
155 #ifdef ENABLE_PLUGIN
156 extern const struct cl_var cl_vars[];
157 #endif
158 extern const char *const lang_names[];
159 extern const unsigned int cl_lang_count;
161 #define CL_PARAMS (1U << 16) /* Fake entry. Used to display --param info with --help. */
162 #define CL_WARNING (1U << 17) /* Enables an (optional) warning message. */
163 #define CL_OPTIMIZATION (1U << 18) /* Enables an (optional) optimization. */
164 #define CL_DRIVER (1U << 19) /* Driver option. */
165 #define CL_TARGET (1U << 20) /* Target-specific option. */
166 #define CL_COMMON (1U << 21) /* Language-independent. */
168 #define CL_MIN_OPTION_CLASS CL_PARAMS
169 #define CL_MAX_OPTION_CLASS CL_COMMON
171 /* From here on the bits describe attributes of the options.
172 Before this point the bits have described the class of the option.
173 This distinction is important because --help will not list options
174 which only have these higher bits set. */
176 #define CL_JOINED (1U << 22) /* If takes joined argument. */
177 #define CL_SEPARATE (1U << 23) /* If takes a separate argument. */
178 #define CL_UNDOCUMENTED (1U << 24) /* Do not output with --help. */
179 #define CL_NO_DWARF_RECORD (1U << 25) /* Do not add to producer string. */
180 #define CL_PCH_IGNORE (1U << 26) /* Do compare state for pch. */
182 /* Flags for an enumerated option argument. */
183 #define CL_ENUM_CANONICAL (1 << 0) /* Canonical for this value. */
184 #define CL_ENUM_DRIVER_ONLY (1 << 1) /* Only accepted in the driver. */
185 #define CL_ENUM_SET_SHIFT 2 /* Shift for enum set. */
187 /* Structure describing an enumerated option argument. */
189 struct cl_enum_arg
191 /* The argument text, or NULL at the end of the array. */
192 const char *arg;
194 /* The corresponding integer value. */
195 int value;
197 /* Flags associated with this argument. */
198 unsigned int flags;
201 /* Structure describing an enumerated set of option arguments. */
203 struct cl_enum
205 /* Help text, or NULL if the values should not be listed in --help
206 output. */
207 const char *help;
209 /* Error message for unknown arguments, or NULL to use a generic
210 error. */
211 const char *unknown_error;
213 /* Array of possible values. */
214 const struct cl_enum_arg *values;
216 /* The size of the type used to store a value. */
217 size_t var_size;
219 /* Function to set a variable of this type. */
220 void (*set) (void *var, int value);
222 /* Function to get the value of a variable of this type. */
223 int (*get) (const void *var);
226 extern const struct cl_enum cl_enums[];
227 extern const unsigned int cl_enums_count;
229 /* Possible ways in which a command-line option may be erroneous.
230 These do not include not being known at all; an option index of
231 OPT_SPECIAL_unknown is used for that. */
233 #define CL_ERR_DISABLED (1 << 0) /* Disabled in this configuration. */
234 #define CL_ERR_MISSING_ARG (1 << 1) /* Argument required but missing. */
235 #define CL_ERR_WRONG_LANG (1 << 2) /* Option for wrong language. */
236 #define CL_ERR_UINT_ARG (1 << 3) /* Bad unsigned integer argument. */
237 #define CL_ERR_INT_RANGE_ARG (1 << 4) /* Bad unsigned integer argument. */
238 #define CL_ERR_ENUM_ARG (1 << 5) /* Bad enumerated argument. */
239 #define CL_ERR_NEGATIVE (1 << 6) /* Negative form of option
240 not permitted (together
241 with OPT_SPECIAL_unknown). */
242 #define CL_ERR_ENUM_SET_ARG (1 << 7) /* Bad argument of enumerated set. */
244 /* Structure describing the result of decoding an option. */
246 struct cl_decoded_option
248 /* The index of this option, or an OPT_SPECIAL_* value for
249 non-options and unknown options. */
250 size_t opt_index;
252 /* Any warning to give for use of this option, or NULL if none. */
253 const char *warn_message;
255 /* The string argument, or NULL if none. For OPT_SPECIAL_* cases,
256 the option or non-option command-line argument. */
257 const char *arg;
259 /* The original text of option plus arguments, with separate argv
260 elements concatenated into one string with spaces separating
261 them. This is for such uses as diagnostics and
262 -frecord-gcc-switches. */
263 const char *orig_option_with_args_text;
265 /* The canonical form of the option and its argument, for when it is
266 necessary to reconstruct argv elements (in particular, for
267 processing specs and passing options to subprocesses from the
268 driver). */
269 const char *canonical_option[4];
271 /* The number of elements in the canonical form of the option and
272 arguments; always at least 1. */
273 size_t canonical_option_num_elements;
275 /* For a boolean option, 1 for the true case and 0 for the "no-"
276 case. For an unsigned integer option, the value of the
277 argument. For enum the value of the enumerator corresponding
278 to argument string. 1 in all other cases. */
279 HOST_WIDE_INT value;
281 /* For EnumSet the value mask. Variable should be changed to
282 value | (prev_value & ~mask). */
283 HOST_WIDE_INT mask;
285 /* Any flags describing errors detected in this option. */
286 int errors;
289 /* Structure describing an option deferred for handling after the main
290 option handlers. */
292 struct cl_deferred_option
294 /* Elements from struct cl_decoded_option used for deferred
295 options. */
296 size_t opt_index;
297 const char *arg;
298 int value;
301 /* Structure describing a single option-handling callback. */
303 struct cl_option_handler_func
305 /* The function called to handle the option. */
306 bool (*handler) (struct gcc_options *opts,
307 struct gcc_options *opts_set,
308 const struct cl_decoded_option *decoded,
309 unsigned int lang_mask, int kind, location_t loc,
310 const struct cl_option_handlers *handlers,
311 diagnostic_context *dc,
312 void (*target_option_override_hook) (void));
314 /* The mask that must have some bit in common with the flags for the
315 option for this particular handler to be used. */
316 unsigned int mask;
319 /* Structure describing the callbacks used in handling options. */
321 struct cl_option_handlers
323 /* Callback for an unknown option to determine whether to give an
324 error for it, and possibly store information to diagnose the
325 option at a later point. Return true if an error should be
326 given, false otherwise. */
327 bool (*unknown_option_callback) (const struct cl_decoded_option *decoded);
329 /* Callback to handle, and possibly diagnose, an option for another
330 language. */
331 void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
332 unsigned int lang_mask);
334 /* Target option override hook. */
335 void (*target_option_override_hook) (void);
337 /* The number of individual handlers. */
338 size_t num_handlers;
340 /* The handlers themselves. */
341 struct cl_option_handler_func handlers[3];
344 /* Hold command-line options associated with stack limitation. */
345 extern const char *opt_fstack_limit_symbol_arg;
346 extern int opt_fstack_limit_register_no;
348 /* Input file names. */
350 extern const char **in_fnames;
352 /* The count of input filenames. */
354 extern unsigned num_in_fnames;
356 extern char *opts_concat (const char *first, ...);
358 /* Obstack for option strings. */
360 extern struct obstack opts_obstack;
362 size_t find_opt (const char *input, unsigned int lang_mask);
363 extern HOST_WIDE_INT integral_argument (const char *arg, int * = NULL, bool = false);
364 extern bool enum_value_to_arg (const struct cl_enum_arg *enum_args,
365 const char **argp, int value,
366 unsigned int lang_mask);
367 extern void decode_cmdline_options_to_array (unsigned int argc,
368 const char **argv,
369 unsigned int lang_mask,
370 struct cl_decoded_option **decoded_options,
371 unsigned int *decoded_options_count);
372 extern void init_options_once (void);
373 extern void init_options_struct (struct gcc_options *opts,
374 struct gcc_options *opts_set);
375 extern void init_opts_obstack (void);
376 extern void decode_cmdline_options_to_array_default_mask (unsigned int argc,
377 const char **argv,
378 struct cl_decoded_option **decoded_options,
379 unsigned int *decoded_options_count);
380 extern void set_default_handlers (struct cl_option_handlers *handlers,
381 void (*target_option_override_hook) (void));
382 extern void decode_options (struct gcc_options *opts,
383 struct gcc_options *opts_set,
384 struct cl_decoded_option *decoded_options,
385 unsigned int decoded_options_count,
386 location_t loc,
387 diagnostic_context *dc,
388 void (*target_option_override_hook) (void));
389 extern int option_enabled (int opt_idx, unsigned lang_mask, void *opts);
391 extern bool get_option_state (struct gcc_options *, int,
392 struct cl_option_state *);
393 extern void set_option (struct gcc_options *opts,
394 struct gcc_options *opts_set,
395 int opt_index, HOST_WIDE_INT value, const char *arg,
396 int kind, location_t loc, diagnostic_context *dc,
397 HOST_WIDE_INT = 0);
398 extern void *option_flag_var (int opt_index, struct gcc_options *opts);
399 bool handle_generated_option (struct gcc_options *opts,
400 struct gcc_options *opts_set,
401 size_t opt_index, const char *arg,
402 HOST_WIDE_INT value,
403 unsigned int lang_mask, int kind, location_t loc,
404 const struct cl_option_handlers *handlers,
405 bool generated_p, diagnostic_context *dc);
406 void generate_option (size_t opt_index, const char *arg, HOST_WIDE_INT value,
407 unsigned int lang_mask,
408 struct cl_decoded_option *decoded);
409 void generate_option_input_file (const char *file,
410 struct cl_decoded_option *decoded);
411 extern void read_cmdline_option (struct gcc_options *opts,
412 struct gcc_options *opts_set,
413 struct cl_decoded_option *decoded,
414 location_t loc,
415 unsigned int lang_mask,
416 const struct cl_option_handlers *handlers,
417 diagnostic_context *dc);
418 extern void control_warning_option (unsigned int opt_index, int kind,
419 const char *arg, bool imply, location_t loc,
420 unsigned int lang_mask,
421 const struct cl_option_handlers *handlers,
422 struct gcc_options *opts,
423 struct gcc_options *opts_set,
424 diagnostic_context *dc);
425 extern char *write_langs (unsigned int mask);
426 extern void print_ignored_options (void);
427 extern void handle_common_deferred_options (void);
428 unsigned int parse_sanitizer_options (const char *, location_t, int,
429 unsigned int, int, bool);
431 unsigned int parse_no_sanitize_attribute (char *value);
432 extern bool common_handle_option (struct gcc_options *opts,
433 struct gcc_options *opts_set,
434 const struct cl_decoded_option *decoded,
435 unsigned int lang_mask, int kind,
436 location_t loc,
437 const struct cl_option_handlers *handlers,
438 diagnostic_context *dc,
439 void (*target_option_override_hook) (void));
440 extern bool target_handle_option (struct gcc_options *opts,
441 struct gcc_options *opts_set,
442 const struct cl_decoded_option *decoded,
443 unsigned int lang_mask, int kind,
444 location_t loc,
445 const struct cl_option_handlers *handlers,
446 diagnostic_context *dc,
447 void (*target_option_override_hook) (void));
448 extern void finish_options (struct gcc_options *opts,
449 struct gcc_options *opts_set,
450 location_t loc);
451 extern void diagnose_options (gcc_options *opts, gcc_options *opts_set,
452 location_t loc);
453 extern void print_help (struct gcc_options *opts, unsigned int lang_mask, const
454 char *help_option_argument);
455 extern void default_options_optimization (struct gcc_options *opts,
456 struct gcc_options *opts_set,
457 struct cl_decoded_option *decoded_options,
458 unsigned int decoded_options_count,
459 location_t loc,
460 unsigned int lang_mask,
461 const struct cl_option_handlers *handlers,
462 diagnostic_context *dc);
463 extern void set_struct_debug_option (struct gcc_options *opts,
464 location_t loc,
465 const char *value);
466 extern bool opt_enum_arg_to_value (size_t opt_index, const char *arg,
467 int *value,
468 unsigned int lang_mask);
470 extern const struct sanitizer_opts_s
472 const char *const name;
473 unsigned int flag;
474 size_t len;
475 bool can_recover;
476 } sanitizer_opts[];
478 extern const struct zero_call_used_regs_opts_s
480 const char *const name;
481 unsigned int flag;
482 } zero_call_used_regs_opts[];
484 extern vec<const char *> help_option_arguments;
486 extern void add_misspelling_candidates (auto_vec<char *> *candidates,
487 const struct cl_option *option,
488 const char *base_option);
489 extern const char *candidates_list_and_hint (const char *arg, char *&str,
490 const auto_vec <const char *> &
491 candidates);
494 extern bool parse_and_check_align_values (const char *flag,
495 const char *name,
496 auto_vec<unsigned> &result_values,
497 bool report_error,
498 location_t loc);
500 extern void parse_and_check_patch_area (const char *arg, bool report_error,
501 HOST_WIDE_INT *patch_area_size,
502 HOST_WIDE_INT *patch_area_start);
504 extern void parse_options_from_collect_gcc_options (const char *, obstack *,
505 int *);
507 extern void prepend_xassembler_to_collect_as_options (const char *, obstack *);
509 extern char *gen_command_line_string (cl_decoded_option *options,
510 unsigned int options_count);
511 extern char *gen_producer_string (const char *language_string,
512 cl_decoded_option *options,
513 unsigned int options_count);
515 /* Set OPTION in OPTS to VALUE if the option is not set in OPTS_SET. */
517 #define SET_OPTION_IF_UNSET(OPTS, OPTS_SET, OPTION, VALUE) \
518 do \
520 if (!(OPTS_SET)->x_ ## OPTION) \
521 (OPTS)->x_ ## OPTION = VALUE; \
523 while (false)
525 /* Return true if OPTION is set by user in global options. */
527 #define OPTION_SET_P(OPTION) global_options_set.x_ ## OPTION
529 #endif