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