]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/opts.h
2015-06-17 Andrew MacLeod <amacleod@redhat.com>
[thirdparty/gcc.git] / gcc / opts.h
CommitLineData
5457b645 1/* Command line option handling.
d353bf18 2 Copyright (C) 2002-2015 Free Software Foundation, Inc.
5457b645 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
8c4c00c1 8Software Foundation; either version 3, or (at your option) any later
5457b645 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
8c4c00c1 17along with GCC; see the file COPYING3. If not see
18<http://www.gnu.org/licenses/>. */
5457b645 19
20#ifndef GCC_OPTS_H
21#define GCC_OPTS_H
22
ba30d337 23#include "obstack.h"
3c6c0e40 24
ff05e09e 25/* Specifies how a switch's VAR_VALUE relates to its FLAG_VAR. */
0fe44c73 26enum cl_var_type {
ff05e09e 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. */
0fe44c73 37 CLVC_BIT_SET,
38
39 /* The switch takes a string argument and FLAG_VAR points to that
40 argument. */
f0da0668 41 CLVC_STRING,
42
d62a5950 43 /* The switch takes an enumerated argument (VAR_ENUM says what
44 enumeration) and FLAG_VAR points to that argument. */
45 CLVC_ENUM,
46
f0da0668 47 /* The switch should be stored in the VEC pointed to by FLAG_VAR for
48 later processing. */
49 CLVC_DEFER
ff05e09e 50};
5457b645 51
55da3817 52struct cl_option
53{
ec840af4 54 /* Text of the option, including initial '-'. */
55da3817 55 const char *opt_text;
ec840af4 56 /* Help text for --help, or NULL. */
53b8e5c1 57 const char *help;
ec840af4 58 /* Error message for missing argument, or NULL. */
fecf9011 59 const char *missing_argument_error;
ec840af4 60 /* Warning to give when this option is used, or NULL. */
3b0273a1 61 const char *warn_message;
ec840af4 62 /* Argument of alias target when positive option given, or NULL. */
67089c6b 63 const char *alias_arg;
ec840af4 64 /* Argument of alias target when negative option given, or NULL. */
67089c6b 65 const char *neg_alias_arg;
ec840af4 66 /* Alias target, or N_OPTS if not an alias. */
67089c6b 67 unsigned short alias_target;
ec840af4 68 /* Previous option that is an initial substring of this one, or
69 N_OPTS if none. */
6b1f09ff 70 unsigned short back_chain;
ec840af4 71 /* Option length, not including initial '-'. */
55da3817 72 unsigned char opt_len;
ec840af4 73 /* Next option in a sequence marked with Negative, or -1 if none. */
a1baa5f1 74 int neg_index;
ec840af4 75 /* CL_* flags for this option. */
3272db82 76 unsigned int flags;
ec840af4 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;
72ec6882 97 /* Argument is a HOST_WIDE_INT. */
98 BOOL_BITFIELD cl_host_wide_int : 1;
cb14e058 99 /* Argument should be converted to lowercase. */
100 BOOL_BITFIELD cl_tolower : 1;
ec840af4 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. */
2c5d2e39 105 unsigned short flag_var_offset;
ec840af4 106 /* Index in cl_enums of enum used for this option's arguments, for
107 CLVC_ENUM options. */
d62a5950 108 unsigned short var_enum;
ec840af4 109 /* How this option's value is determined and sets a field. */
0fe44c73 110 enum cl_var_type var_type;
ec840af4 111 /* Value or bit-mask with which to set a field. */
72ec6882 112 HOST_WIDE_INT var_value;
55da3817 113};
114
7abcc497 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
55da3817 123extern const struct cl_option cl_options[];
124extern const unsigned int cl_options_count;
9cf6679e 125extern const char *const lang_names[];
87c75316 126extern const unsigned int cl_lang_count;
55da3817 127
634b1f85 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. */
151ef6b4 134
135#define CL_MIN_OPTION_CLASS CL_PARAMS
87c75316 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
634b1f85 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. */
3fe1aabe 146#define CL_NO_DWARF_RECORD (1U << 25) /* Do not add to producer string. */
d8f2baf5 147#define CL_PCH_IGNORE (1U << 26) /* Do compare state for pch. */
5457b645 148
d62a5950 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
06907f25 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
615ef0bb 197 OPT_SPECIAL_unknown is used for that. */
06907f25 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. */
d62a5950 203#define CL_ERR_ENUM_ARG (1 << 4) /* Bad enumerated argument. */
204#define CL_ERR_NEGATIVE (1 << 5) /* Negative form of option
19c8675b 205 not permitted (together
206 with OPT_SPECIAL_unknown). */
06907f25 207
208/* Structure describing the result of decoding an option. */
209
210struct cl_decoded_option
211{
615ef0bb 212 /* The index of this option, or an OPT_SPECIAL_* value for
213 non-options and unknown options. */
06907f25 214 size_t opt_index;
215
3b0273a1 216 /* Any warning to give for use of this option, or NULL if none. */
217 const char *warn_message;
218
615ef0bb 219 /* The string argument, or NULL if none. For OPT_SPECIAL_* cases,
220 the option or non-option command-line argument. */
06907f25 221 const char *arg;
222
615ef0bb 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
e88d34f6 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
71a2f35e 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;
e88d34f6 238
06907f25 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
f0da0668 248/* Structure describing an option deferred for handling after the main
249 option handlers. */
250
b3e7c666 251struct cl_deferred_option
f0da0668 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;
b3e7c666 258};
f0da0668 259
b78351e5 260/* Structure describing a single option-handling callback. */
261
262struct cl_option_handler_func
263{
264 /* The function called to handle the option. */
2c5d2e39 265 bool (*handler) (struct gcc_options *opts,
f83b64ca 266 struct gcc_options *opts_set,
2c5d2e39 267 const struct cl_decoded_option *decoded,
3c6c0e40 268 unsigned int lang_mask, int kind, location_t loc,
6bd9d862 269 const struct cl_option_handlers *handlers,
270 diagnostic_context *dc);
b78351e5 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. */
666f4bf0 285 bool (*unknown_option_callback) (const struct cl_decoded_option *decoded);
b78351e5 286
287 /* Callback to handle, and possibly diagnose, an option for another
288 language. */
666f4bf0 289 void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
b78351e5 290 unsigned int lang_mask);
291
b78351e5 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
7981458e 299/* Input file names. */
dcfa26d9 300
301extern const char **in_fnames;
302
7981458e 303/* The count of input filenames. */
dcfa26d9 304
305extern unsigned num_in_fnames;
306
ba30d337 307extern char *opts_concat (const char *first, ...);
308
309/* Obstack for option strings. */
310
311extern struct obstack opts_obstack;
312
607eb2c8 313size_t find_opt (const char *input, unsigned int lang_mask);
06907f25 314extern int integral_argument (const char *arg);
d62a5950 315extern bool enum_value_to_arg (const struct cl_enum_arg *enum_args,
316 const char **argp, int value,
317 unsigned int lang_mask);
615ef0bb 318extern void decode_cmdline_options_to_array (unsigned int argc,
319 const char **argv,
320 unsigned int lang_mask,
321 struct cl_decoded_option **decoded_options,
322 unsigned int *decoded_options_count);
f3f006ad 323extern void init_options_once (void);
324extern void init_options_struct (struct gcc_options *opts,
325 struct gcc_options *opts_set);
d7be771e 326extern void finalize_options_struct (struct gcc_options *opts);
f3f006ad 327extern void decode_cmdline_options_to_array_default_mask (unsigned int argc,
328 const char **argv,
329 struct cl_decoded_option **decoded_options,
330 unsigned int *decoded_options_count);
c123f04d 331extern void set_default_handlers (struct cl_option_handlers *handlers);
f3f006ad 332extern void decode_options (struct gcc_options *opts,
333 struct gcc_options *opts_set,
334 struct cl_decoded_option *decoded_options,
6bd9d862 335 unsigned int decoded_options_count,
3c6c0e40 336 location_t loc,
6bd9d862 337 diagnostic_context *dc);
2c5d2e39 338extern int option_enabled (int opt_idx, void *opts);
339extern bool get_option_state (struct gcc_options *, int,
340 struct cl_option_state *);
f83b64ca 341extern void set_option (struct gcc_options *opts,
342 struct gcc_options *opts_set,
24ca3b4e 343 int opt_index, int value, const char *arg, int kind,
3c6c0e40 344 location_t loc, diagnostic_context *dc);
2c5d2e39 345extern void *option_flag_var (int opt_index, struct gcc_options *opts);
2c5d2e39 346bool handle_generated_option (struct gcc_options *opts,
f83b64ca 347 struct gcc_options *opts_set,
2c5d2e39 348 size_t opt_index, const char *arg, int value,
3c6c0e40 349 unsigned int lang_mask, int kind, location_t loc,
24ca3b4e 350 const struct cl_option_handlers *handlers,
351 diagnostic_context *dc);
cb22f930 352void generate_option (size_t opt_index, const char *arg, int value,
353 unsigned int lang_mask,
354 struct cl_decoded_option *decoded);
355void generate_option_input_file (const char *file,
356 struct cl_decoded_option *decoded);
2c5d2e39 357extern void read_cmdline_option (struct gcc_options *opts,
f83b64ca 358 struct gcc_options *opts_set,
2c5d2e39 359 struct cl_decoded_option *decoded,
3c6c0e40 360 location_t loc,
b78351e5 361 unsigned int lang_mask,
24ca3b4e 362 const struct cl_option_handlers *handlers,
363 diagnostic_context *dc);
c123f04d 364extern void control_warning_option (unsigned int opt_index, int kind,
365 bool imply, location_t loc,
366 unsigned int lang_mask,
367 const struct cl_option_handlers *handlers,
368 struct gcc_options *opts,
369 struct gcc_options *opts_set,
370 diagnostic_context *dc);
ddb48b82 371extern void print_ignored_options (void);
f0da0668 372extern void handle_common_deferred_options (void);
79396169 373extern bool common_handle_option (struct gcc_options *opts,
374 struct gcc_options *opts_set,
375 const struct cl_decoded_option *decoded,
376 unsigned int lang_mask, int kind,
377 location_t loc,
378 const struct cl_option_handlers *handlers,
379 diagnostic_context *dc);
380extern bool target_handle_option (struct gcc_options *opts,
381 struct gcc_options *opts_set,
382 const struct cl_decoded_option *decoded,
383 unsigned int lang_mask, int kind,
384 location_t loc,
385 const struct cl_option_handlers *handlers,
386 diagnostic_context *dc);
387extern void finish_options (struct gcc_options *opts,
9faf44d6 388 struct gcc_options *opts_set,
389 location_t loc);
79396169 390extern void default_options_optimization (struct gcc_options *opts,
391 struct gcc_options *opts_set,
392 struct cl_decoded_option *decoded_options,
393 unsigned int decoded_options_count,
394 location_t loc,
395 unsigned int lang_mask,
396 const struct cl_option_handlers *handlers,
397 diagnostic_context *dc);
9faf44d6 398extern void set_struct_debug_option (struct gcc_options *opts,
399 location_t loc,
400 const char *value);
9105695c 401extern bool opt_enum_arg_to_value (size_t opt_index, const char *arg,
402 int *value, unsigned int lang_mask);
5457b645 403#endif