Update copyright years in libatomic.
[official-gcc.git] / gcc / opts.h
blob723c20bfe11dfcc7caf4feabcef1a144ef8d5002
1 /* Command line option handling.
2 Copyright (C) 2002-2013 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 "input.h"
24 #include "vec.h"
26 /* Specifies how a switch's VAR_VALUE relates to its FLAG_VAR. */
27 enum cl_var_type {
28 /* The switch is enabled when FLAG_VAR is nonzero. */
29 CLVC_BOOLEAN,
31 /* The switch is enabled when FLAG_VAR == VAR_VALUE. */
32 CLVC_EQUAL,
34 /* The switch is enabled when VAR_VALUE is not set in FLAG_VAR. */
35 CLVC_BIT_CLEAR,
37 /* The switch is enabled when VAR_VALUE is set in FLAG_VAR. */
38 CLVC_BIT_SET,
40 /* The switch takes a string argument and FLAG_VAR points to that
41 argument. */
42 CLVC_STRING,
44 /* The switch takes an enumerated argument (VAR_ENUM says what
45 enumeration) and FLAG_VAR points to that argument. */
46 CLVC_ENUM,
48 /* The switch should be stored in the VEC pointed to by FLAG_VAR for
49 later processing. */
50 CLVC_DEFER
53 struct cl_option
55 /* Text of the option, including initial '-'. */
56 const char *opt_text;
57 /* Help text for --help, or NULL. */
58 const char *help;
59 /* Error message for missing argument, or NULL. */
60 const char *missing_argument_error;
61 /* Warning to give when this option is used, or NULL. */
62 const char *warn_message;
63 /* Argument of alias target when positive option given, or NULL. */
64 const char *alias_arg;
65 /* Argument of alias target when negative option given, or NULL. */
66 const char *neg_alias_arg;
67 /* Alias target, or N_OPTS if not an alias. */
68 unsigned short alias_target;
69 /* Previous option that is an initial substring of this one, or
70 N_OPTS if none. */
71 unsigned short back_chain;
72 /* Option length, not including initial '-'. */
73 unsigned char opt_len;
74 /* Next option in a sequence marked with Negative, or -1 if none. */
75 int neg_index;
76 /* CL_* flags for this option. */
77 unsigned int flags;
78 /* Disabled in this configuration. */
79 BOOL_BITFIELD cl_disabled : 1;
80 /* Options marked with CL_SEPARATE take a number of separate
81 arguments (1 to 4) that is one more than the number in this
82 bit-field. */
83 unsigned int cl_separate_nargs : 2;
84 /* Option is an alias when used with separate argument. */
85 BOOL_BITFIELD cl_separate_alias : 1;
86 /* Alias to negative form of option. */
87 BOOL_BITFIELD cl_negative_alias : 1;
88 /* Option takes no argument in the driver. */
89 BOOL_BITFIELD cl_no_driver_arg : 1;
90 /* Reject this option in the driver. */
91 BOOL_BITFIELD cl_reject_driver : 1;
92 /* Reject no- form. */
93 BOOL_BITFIELD cl_reject_negative : 1;
94 /* Missing argument OK (joined). */
95 BOOL_BITFIELD cl_missing_ok : 1;
96 /* Argument is an integer >=0. */
97 BOOL_BITFIELD cl_uinteger : 1;
98 /* Argument is a HOST_WIDE_INT. */
99 BOOL_BITFIELD cl_host_wide_int : 1;
100 /* Argument should be converted to lowercase. */
101 BOOL_BITFIELD cl_tolower : 1;
102 /* Report argument with -fverbose-asm */
103 BOOL_BITFIELD cl_report : 1;
104 /* Offset of field for this option in struct gcc_options, or
105 (unsigned short) -1 if none. */
106 unsigned short flag_var_offset;
107 /* Index in cl_enums of enum used for this option's arguments, for
108 CLVC_ENUM options. */
109 unsigned short var_enum;
110 /* How this option's value is determined and sets a field. */
111 enum cl_var_type var_type;
112 /* Value or bit-mask with which to set a field. */
113 HOST_WIDE_INT var_value;
116 /* Records that the state of an option consists of SIZE bytes starting
117 at DATA. DATA might point to CH in some cases. */
118 struct cl_option_state {
119 const void *data;
120 size_t size;
121 char ch;
124 extern const struct cl_option cl_options[];
125 extern const unsigned int cl_options_count;
126 extern const char *const lang_names[];
127 extern const unsigned int cl_lang_count;
129 #define CL_PARAMS (1U << 16) /* Fake entry. Used to display --param info with --help. */
130 #define CL_WARNING (1U << 17) /* Enables an (optional) warning message. */
131 #define CL_OPTIMIZATION (1U << 18) /* Enables an (optional) optimization. */
132 #define CL_DRIVER (1U << 19) /* Driver option. */
133 #define CL_TARGET (1U << 20) /* Target-specific option. */
134 #define CL_COMMON (1U << 21) /* Language-independent. */
136 #define CL_MIN_OPTION_CLASS CL_PARAMS
137 #define CL_MAX_OPTION_CLASS CL_COMMON
139 /* From here on the bits describe attributes of the options.
140 Before this point the bits have described the class of the option.
141 This distinction is important because --help will not list options
142 which only have these higher bits set. */
144 #define CL_JOINED (1U << 22) /* If takes joined argument. */
145 #define CL_SEPARATE (1U << 23) /* If takes a separate argument. */
146 #define CL_UNDOCUMENTED (1U << 24) /* Do not output with --help. */
147 #define CL_NO_DWARF_RECORD (1U << 25) /* Do not add to producer string. */
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. */
153 /* Structure describing an enumerated option argument. */
155 struct cl_enum_arg
157 /* The argument text, or NULL at the end of the array. */
158 const char *arg;
160 /* The corresponding integer value. */
161 int value;
163 /* Flags associated with this argument. */
164 unsigned int flags;
167 /* Structure describing an enumerated set of option arguments. */
169 struct cl_enum
171 /* Help text, or NULL if the values should not be listed in --help
172 output. */
173 const char *help;
175 /* Error message for unknown arguments, or NULL to use a generic
176 error. */
177 const char *unknown_error;
179 /* Array of possible values. */
180 const struct cl_enum_arg *values;
182 /* The size of the type used to store a value. */
183 size_t var_size;
185 /* Function to set a variable of this type. */
186 void (*set) (void *var, int value);
188 /* Function to get the value of a variable of this type. */
189 int (*get) (const void *var);
192 extern const struct cl_enum cl_enums[];
193 extern const unsigned int cl_enums_count;
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
197 OPT_SPECIAL_unknown is used for that. */
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. */
203 #define CL_ERR_ENUM_ARG (1 << 4) /* Bad enumerated argument. */
204 #define CL_ERR_NEGATIVE (1 << 5) /* Negative form of option
205 not permitted (together
206 with OPT_SPECIAL_unknown). */
208 /* Structure describing the result of decoding an option. */
210 struct cl_decoded_option
212 /* The index of this option, or an OPT_SPECIAL_* value for
213 non-options and unknown options. */
214 size_t opt_index;
216 /* Any warning to give for use of this option, or NULL if none. */
217 const char *warn_message;
219 /* The string argument, or NULL if none. For OPT_SPECIAL_* cases,
220 the option or non-option command-line argument. */
221 const char *arg;
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;
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
232 driver). */
233 const char *canonical_option[4];
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;
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;
244 /* Any flags describing errors detected in this option. */
245 int errors;
248 /* Structure describing an option deferred for handling after the main
249 option handlers. */
251 typedef struct
253 /* Elements from struct cl_decoded_option used for deferred
254 options. */
255 size_t opt_index;
256 const char *arg;
257 int value;
258 } cl_deferred_option;
260 /* Structure describing a single option-handling callback. */
262 struct cl_option_handler_func
264 /* The function called to handle the option. */
265 bool (*handler) (struct gcc_options *opts,
266 struct gcc_options *opts_set,
267 const struct cl_decoded_option *decoded,
268 unsigned int lang_mask, int kind, location_t loc,
269 const struct cl_option_handlers *handlers,
270 diagnostic_context *dc);
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;
277 /* Structure describing the callbacks used in handling options. */
279 struct cl_option_handlers
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. */
285 bool (*unknown_option_callback) (const struct cl_decoded_option *decoded);
287 /* Callback to handle, and possibly diagnose, an option for another
288 language. */
289 void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
290 unsigned int lang_mask);
292 /* The number of individual handlers. */
293 size_t num_handlers;
295 /* The handlers themselves. */
296 struct cl_option_handler_func handlers[3];
299 /* Input file names. */
301 extern const char **in_fnames;
303 /* The count of input filenames. */
305 extern unsigned num_in_fnames;
307 size_t find_opt (const char *input, unsigned int lang_mask);
308 extern int integral_argument (const char *arg);
309 extern bool enum_value_to_arg (const struct cl_enum_arg *enum_args,
310 const char **argp, int value,
311 unsigned int lang_mask);
312 extern void decode_cmdline_options_to_array (unsigned int argc,
313 const char **argv,
314 unsigned int lang_mask,
315 struct cl_decoded_option **decoded_options,
316 unsigned int *decoded_options_count);
317 extern void init_options_once (void);
318 extern void init_options_struct (struct gcc_options *opts,
319 struct gcc_options *opts_set);
320 extern void decode_cmdline_options_to_array_default_mask (unsigned int argc,
321 const char **argv,
322 struct cl_decoded_option **decoded_options,
323 unsigned int *decoded_options_count);
324 extern void set_default_handlers (struct cl_option_handlers *handlers);
325 extern void decode_options (struct gcc_options *opts,
326 struct gcc_options *opts_set,
327 struct cl_decoded_option *decoded_options,
328 unsigned int decoded_options_count,
329 location_t loc,
330 diagnostic_context *dc);
331 extern int option_enabled (int opt_idx, void *opts);
332 extern bool get_option_state (struct gcc_options *, int,
333 struct cl_option_state *);
334 extern void set_option (struct gcc_options *opts,
335 struct gcc_options *opts_set,
336 int opt_index, int value, const char *arg, int kind,
337 location_t loc, diagnostic_context *dc);
338 extern void *option_flag_var (int opt_index, struct gcc_options *opts);
339 bool handle_generated_option (struct gcc_options *opts,
340 struct gcc_options *opts_set,
341 size_t opt_index, const char *arg, int value,
342 unsigned int lang_mask, int kind, location_t loc,
343 const struct cl_option_handlers *handlers,
344 diagnostic_context *dc);
345 void generate_option (size_t opt_index, const char *arg, int value,
346 unsigned int lang_mask,
347 struct cl_decoded_option *decoded);
348 void generate_option_input_file (const char *file,
349 struct cl_decoded_option *decoded);
350 extern void read_cmdline_option (struct gcc_options *opts,
351 struct gcc_options *opts_set,
352 struct cl_decoded_option *decoded,
353 location_t loc,
354 unsigned int lang_mask,
355 const struct cl_option_handlers *handlers,
356 diagnostic_context *dc);
357 extern void control_warning_option (unsigned int opt_index, int kind,
358 bool imply, location_t loc,
359 unsigned int lang_mask,
360 const struct cl_option_handlers *handlers,
361 struct gcc_options *opts,
362 struct gcc_options *opts_set,
363 diagnostic_context *dc);
364 extern void print_ignored_options (void);
365 extern void handle_common_deferred_options (void);
366 extern bool common_handle_option (struct gcc_options *opts,
367 struct gcc_options *opts_set,
368 const struct cl_decoded_option *decoded,
369 unsigned int lang_mask, int kind,
370 location_t loc,
371 const struct cl_option_handlers *handlers,
372 diagnostic_context *dc);
373 extern bool target_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);
380 extern void finish_options (struct gcc_options *opts,
381 struct gcc_options *opts_set,
382 location_t loc);
383 extern void default_options_optimization (struct gcc_options *opts,
384 struct gcc_options *opts_set,
385 struct cl_decoded_option *decoded_options,
386 unsigned int decoded_options_count,
387 location_t loc,
388 unsigned int lang_mask,
389 const struct cl_option_handlers *handlers,
390 diagnostic_context *dc);
391 extern void set_struct_debug_option (struct gcc_options *opts,
392 location_t loc,
393 const char *value);
394 extern bool opt_enum_arg_to_value (size_t opt_index, const char *arg,
395 int *value, unsigned int lang_mask);
396 #endif