* inclhack.def (AAB_aix_fcntl): New fix.
[official-gcc.git] / gcc / opts.h
bloba9336af74bcb657e7d834ab554cb2caedb4ea16e
1 /* Command line option handling.
2 Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #ifndef GCC_OPTS_H
22 #define GCC_OPTS_H
24 #include "input.h"
25 #include "vec.h"
27 /* Specifies how a switch's VAR_VALUE relates to its FLAG_VAR. */
28 enum cl_var_type {
29 /* The switch is enabled when FLAG_VAR is nonzero. */
30 CLVC_BOOLEAN,
32 /* The switch is enabled when FLAG_VAR == VAR_VALUE. */
33 CLVC_EQUAL,
35 /* The switch is enabled when VAR_VALUE is not set in FLAG_VAR. */
36 CLVC_BIT_CLEAR,
38 /* The switch is enabled when VAR_VALUE is set in FLAG_VAR. */
39 CLVC_BIT_SET,
41 /* The switch takes a string argument and FLAG_VAR points to that
42 argument. */
43 CLVC_STRING,
45 /* The switch takes an enumerated argument (VAR_ENUM says what
46 enumeration) and FLAG_VAR points to that argument. */
47 CLVC_ENUM,
49 /* The switch should be stored in the VEC pointed to by FLAG_VAR for
50 later processing. */
51 CLVC_DEFER
54 struct cl_option
56 /* Text of the option, including initial '-'. */
57 const char *opt_text;
58 /* Help text for --help, or NULL. */
59 const char *help;
60 /* Error message for missing argument, or NULL. */
61 const char *missing_argument_error;
62 /* Warning to give when this option is used, or NULL. */
63 const char *warn_message;
64 /* Argument of alias target when positive option given, or NULL. */
65 const char *alias_arg;
66 /* Argument of alias target when negative option given, or NULL. */
67 const char *neg_alias_arg;
68 /* Alias target, or N_OPTS if not an alias. */
69 unsigned short alias_target;
70 /* Previous option that is an initial substring of this one, or
71 N_OPTS if none. */
72 unsigned short back_chain;
73 /* Option length, not including initial '-'. */
74 unsigned char opt_len;
75 /* Next option in a sequence marked with Negative, or -1 if none. */
76 int neg_index;
77 /* CL_* flags for this option. */
78 unsigned int flags;
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;
99 /* Argument is a HOST_WIDE_INT. */
100 BOOL_BITFIELD cl_host_wide_int : 1;
101 /* Argument should be converted to lowercase. */
102 BOOL_BITFIELD cl_tolower : 1;
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. */
107 unsigned short flag_var_offset;
108 /* Index in cl_enums of enum used for this option's arguments, for
109 CLVC_ENUM options. */
110 unsigned short var_enum;
111 /* How this option's value is determined and sets a field. */
112 enum cl_var_type var_type;
113 /* Value or bit-mask with which to set a field. */
114 HOST_WIDE_INT var_value;
117 /* Records that the state of an option consists of SIZE bytes starting
118 at DATA. DATA might point to CH in some cases. */
119 struct cl_option_state {
120 const void *data;
121 size_t size;
122 char ch;
125 extern const struct cl_option cl_options[];
126 extern const unsigned int cl_options_count;
127 extern const char *const lang_names[];
128 extern const unsigned int cl_lang_count;
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. */
137 #define CL_MIN_OPTION_CLASS CL_PARAMS
138 #define CL_MAX_OPTION_CLASS CL_COMMON
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. */
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. */
148 #define CL_NO_DWARF_RECORD (1U << 25) /* Do not add to producer string. */
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. */
154 /* Structure describing an enumerated option argument. */
156 struct cl_enum_arg
158 /* The argument text, or NULL at the end of the array. */
159 const char *arg;
161 /* The corresponding integer value. */
162 int value;
164 /* Flags associated with this argument. */
165 unsigned int flags;
168 /* Structure describing an enumerated set of option arguments. */
170 struct cl_enum
172 /* Help text, or NULL if the values should not be listed in --help
173 output. */
174 const char *help;
176 /* Error message for unknown arguments, or NULL to use a generic
177 error. */
178 const char *unknown_error;
180 /* Array of possible values. */
181 const struct cl_enum_arg *values;
183 /* The size of the type used to store a value. */
184 size_t var_size;
186 /* Function to set a variable of this type. */
187 void (*set) (void *var, int value);
189 /* Function to get the value of a variable of this type. */
190 int (*get) (const void *var);
193 extern const struct cl_enum cl_enums[];
194 extern const unsigned int cl_enums_count;
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
198 OPT_SPECIAL_unknown is used for that. */
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. */
204 #define CL_ERR_ENUM_ARG (1 << 4) /* Bad enumerated argument. */
205 #define CL_ERR_NEGATIVE (1 << 5) /* Negative form of option
206 not permitted (together
207 with OPT_SPECIAL_unknown). */
209 /* Structure describing the result of decoding an option. */
211 struct cl_decoded_option
213 /* The index of this option, or an OPT_SPECIAL_* value for
214 non-options and unknown options. */
215 size_t opt_index;
217 /* Any warning to give for use of this option, or NULL if none. */
218 const char *warn_message;
220 /* The string argument, or NULL if none. For OPT_SPECIAL_* cases,
221 the option or non-option command-line argument. */
222 const char *arg;
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;
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
233 driver). */
234 const char *canonical_option[4];
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;
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;
245 /* Any flags describing errors detected in this option. */
246 int errors;
249 /* Structure describing an option deferred for handling after the main
250 option handlers. */
252 typedef struct
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;
260 DEF_VEC_O(cl_deferred_option);
261 DEF_VEC_ALLOC_O(cl_deferred_option,heap);
263 /* Structure describing a single option-handling callback. */
265 struct cl_option_handler_func
267 /* The function called to handle the option. */
268 bool (*handler) (struct gcc_options *opts,
269 struct gcc_options *opts_set,
270 const struct cl_decoded_option *decoded,
271 unsigned int lang_mask, int kind, location_t loc,
272 const struct cl_option_handlers *handlers,
273 diagnostic_context *dc);
275 /* The mask that must have some bit in common with the flags for the
276 option for this particular handler to be used. */
277 unsigned int mask;
280 /* Structure describing the callbacks used in handling options. */
282 struct cl_option_handlers
284 /* Callback for an unknown option to determine whether to give an
285 error for it, and possibly store information to diagnose the
286 option at a later point. Return true if an error should be
287 given, false otherwise. */
288 bool (*unknown_option_callback) (const struct cl_decoded_option *decoded);
290 /* Callback to handle, and possibly diagnose, an option for another
291 language. */
292 void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
293 unsigned int lang_mask);
295 /* The number of individual handlers. */
296 size_t num_handlers;
298 /* The handlers themselves. */
299 struct cl_option_handler_func handlers[3];
302 /* Input file names. */
304 extern const char **in_fnames;
306 /* The count of input filenames. */
308 extern unsigned num_in_fnames;
310 size_t find_opt (const char *input, unsigned int lang_mask);
311 extern int integral_argument (const char *arg);
312 extern bool enum_value_to_arg (const struct cl_enum_arg *enum_args,
313 const char **argp, int value,
314 unsigned int lang_mask);
315 extern void decode_cmdline_options_to_array (unsigned int argc,
316 const char **argv,
317 unsigned int lang_mask,
318 struct cl_decoded_option **decoded_options,
319 unsigned int *decoded_options_count);
320 extern void init_options_once (void);
321 extern void init_options_struct (struct gcc_options *opts,
322 struct gcc_options *opts_set);
323 extern void decode_cmdline_options_to_array_default_mask (unsigned int argc,
324 const char **argv,
325 struct cl_decoded_option **decoded_options,
326 unsigned int *decoded_options_count);
327 extern void set_default_handlers (struct cl_option_handlers *handlers);
328 extern void decode_options (struct gcc_options *opts,
329 struct gcc_options *opts_set,
330 struct cl_decoded_option *decoded_options,
331 unsigned int decoded_options_count,
332 location_t loc,
333 diagnostic_context *dc);
334 extern int option_enabled (int opt_idx, void *opts);
335 extern bool get_option_state (struct gcc_options *, int,
336 struct cl_option_state *);
337 extern void set_option (struct gcc_options *opts,
338 struct gcc_options *opts_set,
339 int opt_index, int value, const char *arg, int kind,
340 location_t loc, diagnostic_context *dc);
341 extern void *option_flag_var (int opt_index, struct gcc_options *opts);
342 bool handle_generated_option (struct gcc_options *opts,
343 struct gcc_options *opts_set,
344 size_t opt_index, const char *arg, int value,
345 unsigned int lang_mask, int kind, location_t loc,
346 const struct cl_option_handlers *handlers,
347 diagnostic_context *dc);
348 void generate_option (size_t opt_index, const char *arg, int value,
349 unsigned int lang_mask,
350 struct cl_decoded_option *decoded);
351 void generate_option_input_file (const char *file,
352 struct cl_decoded_option *decoded);
353 extern void read_cmdline_option (struct gcc_options *opts,
354 struct gcc_options *opts_set,
355 struct cl_decoded_option *decoded,
356 location_t loc,
357 unsigned int lang_mask,
358 const struct cl_option_handlers *handlers,
359 diagnostic_context *dc);
360 extern void control_warning_option (unsigned int opt_index, int kind,
361 bool imply, location_t loc,
362 unsigned int lang_mask,
363 const struct cl_option_handlers *handlers,
364 struct gcc_options *opts,
365 struct gcc_options *opts_set,
366 diagnostic_context *dc);
367 extern void print_ignored_options (void);
368 extern void handle_common_deferred_options (void);
369 extern bool common_handle_option (struct gcc_options *opts,
370 struct gcc_options *opts_set,
371 const struct cl_decoded_option *decoded,
372 unsigned int lang_mask, int kind,
373 location_t loc,
374 const struct cl_option_handlers *handlers,
375 diagnostic_context *dc);
376 extern bool target_handle_option (struct gcc_options *opts,
377 struct gcc_options *opts_set,
378 const struct cl_decoded_option *decoded,
379 unsigned int lang_mask, int kind,
380 location_t loc,
381 const struct cl_option_handlers *handlers,
382 diagnostic_context *dc);
383 extern void finish_options (struct gcc_options *opts,
384 struct gcc_options *opts_set,
385 location_t loc);
386 extern void default_options_optimization (struct gcc_options *opts,
387 struct gcc_options *opts_set,
388 struct cl_decoded_option *decoded_options,
389 unsigned int decoded_options_count,
390 location_t loc,
391 unsigned int lang_mask,
392 const struct cl_option_handlers *handlers,
393 diagnostic_context *dc);
394 extern void set_struct_debug_option (struct gcc_options *opts,
395 location_t loc,
396 const char *value);
397 extern bool opt_enum_arg_to_value (size_t opt_index, const char *arg,
398 int *value, unsigned int lang_mask);
399 #endif