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
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
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/>. */
27 /* Specifies how a switch's VAR_VALUE relates to its FLAG_VAR. */
29 /* The switch is enabled when FLAG_VAR is nonzero. */
32 /* The switch is enabled when FLAG_VAR == VAR_VALUE. */
35 /* The switch is enabled when VAR_VALUE is not set in FLAG_VAR. */
38 /* The switch is enabled when VAR_VALUE is set in FLAG_VAR. */
41 /* The switch takes a string argument and FLAG_VAR points to that
45 /* The switch takes an enumerated argument (VAR_ENUM says what
46 enumeration) and FLAG_VAR points to that argument. */
49 /* The switch should be stored in the VEC pointed to by FLAG_VAR for
56 /* Text of the option, including initial '-'. */
58 /* Help text for --help, or NULL. */
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
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. */
77 /* CL_* flags for this option. */
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
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 should be converted to lowercase. */
100 BOOL_BITFIELD cl_tolower
: 1;
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. */
105 unsigned short flag_var_offset
;
106 /* Index in cl_enums of enum used for this option's arguments, for
107 CLVC_ENUM options. */
108 unsigned short var_enum
;
109 /* How this option's value is determined and sets a field. */
110 enum cl_var_type var_type
;
111 /* Value or bit-mask with which to set a field. */
115 /* Records that the state of an option consists of SIZE bytes starting
116 at DATA. DATA might point to CH in some cases. */
117 struct cl_option_state
{
123 extern const struct cl_option cl_options
[];
124 extern const unsigned int cl_options_count
;
125 extern const char *const lang_names
[];
126 extern const unsigned int cl_lang_count
;
128 #define CL_PARAMS (1U << 11) /* Fake entry. Used to display --param info with --help. */
129 #define CL_WARNING (1U << 12) /* Enables an (optional) warning message. */
130 #define CL_OPTIMIZATION (1U << 13) /* Enables an (optional) optimization. */
131 #define CL_DRIVER (1U << 14) /* Driver option. */
132 #define CL_TARGET (1U << 15) /* Target-specific option. */
133 #define CL_COMMON (1U << 16) /* Language-independent. */
135 #define CL_MIN_OPTION_CLASS CL_PARAMS
136 #define CL_MAX_OPTION_CLASS CL_COMMON
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. */
143 #define CL_JOINED (1U << 17) /* If takes joined argument. */
144 #define CL_SEPARATE (1U << 18) /* If takes a separate argument. */
145 #define CL_UNDOCUMENTED (1U << 19) /* Do not output with --help. */
147 /* Flags for an enumerated option argument. */
148 #define CL_ENUM_CANONICAL (1 << 0) /* Canonical for this value. */
149 #define CL_ENUM_DRIVER_ONLY (1 << 1) /* Only accepted in the driver. */
151 /* Structure describing an enumerated option argument. */
155 /* The argument text, or NULL at the end of the array. */
158 /* The corresponding integer value. */
161 /* Flags associated with this argument. */
165 /* Structure describing an enumerated set of option arguments. */
169 /* Help text, or NULL if the values should not be listed in --help
173 /* Error message for unknown arguments, or NULL to use a generic
175 const char *unknown_error
;
177 /* Array of possible values. */
178 const struct cl_enum_arg
*values
;
180 /* The size of the type used to store a value. */
183 /* Function to set a variable of this type. */
184 void (*set
) (void *var
, int value
);
186 /* Function to get the value of a variable of this type. */
187 int (*get
) (const void *var
);
190 extern const struct cl_enum cl_enums
[];
191 extern const unsigned int cl_enums_count
;
193 /* Possible ways in which a command-line option may be erroneous.
194 These do not include not being known at all; an option index of
195 OPT_SPECIAL_unknown is used for that. */
197 #define CL_ERR_DISABLED (1 << 0) /* Disabled in this configuration. */
198 #define CL_ERR_MISSING_ARG (1 << 1) /* Argument required but missing. */
199 #define CL_ERR_WRONG_LANG (1 << 2) /* Option for wrong language. */
200 #define CL_ERR_UINT_ARG (1 << 3) /* Bad unsigned integer argument. */
201 #define CL_ERR_ENUM_ARG (1 << 4) /* Bad enumerated argument. */
202 #define CL_ERR_NEGATIVE (1 << 5) /* Negative form of option
203 not permitted (together
204 with OPT_SPECIAL_unknown). */
206 /* Structure describing the result of decoding an option. */
208 struct cl_decoded_option
210 /* The index of this option, or an OPT_SPECIAL_* value for
211 non-options and unknown options. */
214 /* Any warning to give for use of this option, or NULL if none. */
215 const char *warn_message
;
217 /* The string argument, or NULL if none. For OPT_SPECIAL_* cases,
218 the option or non-option command-line argument. */
221 /* The original text of option plus arguments, with separate argv
222 elements concatenated into one string with spaces separating
223 them. This is for such uses as diagnostics and
224 -frecord-gcc-switches. */
225 const char *orig_option_with_args_text
;
227 /* The canonical form of the option and its argument, for when it is
228 necessary to reconstruct argv elements (in particular, for
229 processing specs and passing options to subprocesses from the
231 const char *canonical_option
[4];
233 /* The number of elements in the canonical form of the option and
234 arguments; always at least 1. */
235 size_t canonical_option_num_elements
;
237 /* For a boolean option, 1 for the true case and 0 for the "no-"
238 case. For an unsigned integer option, the value of the
239 argument. 1 in all other cases. */
242 /* Any flags describing errors detected in this option. */
246 /* Structure describing an option deferred for handling after the main
251 /* Elements from struct cl_decoded_option used for deferred
256 } cl_deferred_option
;
257 DEF_VEC_O(cl_deferred_option
);
258 DEF_VEC_ALLOC_O(cl_deferred_option
,heap
);
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. */
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
289 void (*wrong_lang_callback
) (const struct cl_decoded_option
*decoded
,
290 unsigned int lang_mask
);
292 /* Callback to call after the successful handling of any option. */
293 void (*post_handling_callback
) (const struct cl_decoded_option
*decoded
,
296 /* The number of individual handlers. */
299 /* The handlers themselves. */
300 struct cl_option_handler_func handlers
[3];
303 /* Input file names. */
305 extern const char **in_fnames
;
307 /* The count of input filenames. */
309 extern unsigned num_in_fnames
;
311 size_t find_opt (const char *input
, unsigned int lang_mask
);
312 extern int integral_argument (const char *arg
);
313 extern bool enum_value_to_arg (const struct cl_enum_arg
*enum_args
,
314 const char **argp
, int value
,
315 unsigned int lang_mask
);
316 extern void decode_cmdline_options_to_array (unsigned int argc
,
318 unsigned int lang_mask
,
319 struct cl_decoded_option
**decoded_options
,
320 unsigned int *decoded_options_count
);
321 extern void init_options_once (void);
322 extern void init_options_struct (struct gcc_options
*opts
,
323 struct gcc_options
*opts_set
);
324 extern void decode_cmdline_options_to_array_default_mask (unsigned int argc
,
326 struct cl_decoded_option
**decoded_options
,
327 unsigned int *decoded_options_count
);
328 extern void set_default_handlers (struct cl_option_handlers
*handlers
);
329 extern void decode_options (struct gcc_options
*opts
,
330 struct gcc_options
*opts_set
,
331 struct cl_decoded_option
*decoded_options
,
332 unsigned int decoded_options_count
,
334 diagnostic_context
*dc
);
335 extern int option_enabled (int opt_idx
, void *opts
);
336 extern bool get_option_state (struct gcc_options
*, int,
337 struct cl_option_state
*);
338 extern void set_option (struct gcc_options
*opts
,
339 struct gcc_options
*opts_set
,
340 int opt_index
, int value
, const char *arg
, int kind
,
341 location_t loc
, diagnostic_context
*dc
);
342 extern void *option_flag_var (int opt_index
, struct gcc_options
*opts
);
343 bool handle_generated_option (struct gcc_options
*opts
,
344 struct gcc_options
*opts_set
,
345 size_t opt_index
, const char *arg
, int value
,
346 unsigned int lang_mask
, int kind
, location_t loc
,
347 const struct cl_option_handlers
*handlers
,
348 diagnostic_context
*dc
);
349 void generate_option (size_t opt_index
, const char *arg
, int value
,
350 unsigned int lang_mask
,
351 struct cl_decoded_option
*decoded
);
352 void generate_option_input_file (const char *file
,
353 struct cl_decoded_option
*decoded
);
354 extern void read_cmdline_option (struct gcc_options
*opts
,
355 struct gcc_options
*opts_set
,
356 struct cl_decoded_option
*decoded
,
358 unsigned int lang_mask
,
359 const struct cl_option_handlers
*handlers
,
360 diagnostic_context
*dc
);
361 extern void control_warning_option (unsigned int opt_index
, int kind
,
362 bool imply
, location_t loc
,
363 unsigned int lang_mask
,
364 const struct cl_option_handlers
*handlers
,
365 struct gcc_options
*opts
,
366 struct gcc_options
*opts_set
,
367 diagnostic_context
*dc
);
368 extern void print_ignored_options (void);
369 extern void handle_common_deferred_options (void);
370 extern bool common_handle_option (struct gcc_options
*opts
,
371 struct gcc_options
*opts_set
,
372 const struct cl_decoded_option
*decoded
,
373 unsigned int lang_mask
, int kind
,
375 const struct cl_option_handlers
*handlers
,
376 diagnostic_context
*dc
);
377 extern bool target_handle_option (struct gcc_options
*opts
,
378 struct gcc_options
*opts_set
,
379 const struct cl_decoded_option
*decoded
,
380 unsigned int lang_mask
, int kind
,
382 const struct cl_option_handlers
*handlers
,
383 diagnostic_context
*dc
);
384 extern void finish_options (struct gcc_options
*opts
,
385 struct gcc_options
*opts_set
,
387 extern void default_options_optimization (struct gcc_options
*opts
,
388 struct gcc_options
*opts_set
,
389 struct cl_decoded_option
*decoded_options
,
390 unsigned int decoded_options_count
,
392 unsigned int lang_mask
,
393 const struct cl_option_handlers
*handlers
,
394 diagnostic_context
*dc
);
395 extern void set_struct_debug_option (struct gcc_options
*opts
,
398 extern bool opt_enum_arg_to_value (size_t opt_index
, const char *arg
,
399 int *value
, unsigned int lang_mask
);