Merge aosp-toolchain/gcc/gcc-4_9 changes.
[official-gcc.git] / gcc-4_6 / gcc / opts.h
blobdd88380a6f01d085cbbf3c6e529b59bb3afc3ca9
1 /* Command line option handling.
2 Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
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 const char *opt_text;
57 const char *help;
58 const char *missing_argument_error;
59 const char *warn_message;
60 const char *alias_arg;
61 const char *neg_alias_arg;
62 unsigned short alias_target;
63 unsigned short back_chain;
64 unsigned char opt_len;
65 int neg_index;
66 unsigned int flags;
67 unsigned short flag_var_offset;
68 unsigned short var_enum;
69 enum cl_var_type var_type;
70 int var_value;
73 /* Records that the state of an option consists of SIZE bytes starting
74 at DATA. DATA might point to CH in some cases. */
75 struct cl_option_state {
76 const void *data;
77 size_t size;
78 char ch;
81 extern const struct cl_option cl_options[];
82 extern const unsigned int cl_options_count;
83 extern const char *const lang_names[];
84 extern const unsigned int cl_lang_count;
86 #define CL_PARAMS (1 << 11) /* Fake entry. Used to display --param info with --help. */
87 #define CL_WARNING (1 << 12) /* Enables an (optional) warning message. */
88 #define CL_OPTIMIZATION (1 << 13) /* Enables an (optional) optimization. */
89 #define CL_DRIVER (1 << 14) /* Driver option. */
90 #define CL_TARGET (1 << 15) /* Target-specific option. */
91 #define CL_COMMON (1 << 16) /* Language-independent. */
93 #define CL_MIN_OPTION_CLASS CL_PARAMS
94 #define CL_MAX_OPTION_CLASS CL_COMMON
96 /* From here on the bits describe attributes of the options.
97 Before this point the bits have described the class of the option.
98 This distinction is important because --help will not list options
99 which only have these higher bits set. */
101 /* Options marked with CL_SEPARATE take a number of separate arguments
102 (1 to 4) that is one more than the number in this bit-field. */
103 #define CL_SEPARATE_NARGS_SHIFT 17
104 #define CL_SEPARATE_NARGS_MASK (3 << CL_SEPARATE_NARGS_SHIFT)
106 #define CL_SEPARATE_ALIAS (1 << 19) /* Option is an alias when used with separate argument. */
107 #define CL_NO_DRIVER_ARG (1 << 20) /* Option takes no argument in the driver. */
108 #define CL_REJECT_DRIVER (1 << 21) /* Reject this option in the driver. */
109 #define CL_SAVE (1 << 22) /* Target-specific option for attribute. */
110 #define CL_DISABLED (1 << 23) /* Disabled in this configuration. */
111 #define CL_REPORT (1 << 24) /* Report argument with -fverbose-asm */
112 #define CL_JOINED (1 << 25) /* If takes joined argument. */
113 #define CL_SEPARATE (1 << 26) /* If takes a separate argument. */
114 #define CL_REJECT_NEGATIVE (1 << 27) /* Reject no- form. */
115 #define CL_MISSING_OK (1 << 28) /* Missing argument OK (joined). */
116 #define CL_UINTEGER (1 << 29) /* Argument is an integer >=0. */
117 #define CL_UNDOCUMENTED (1 << 30) /* Do not output with --help. */
119 /* Flags for an enumerated option argument. */
120 #define CL_ENUM_CANONICAL (1 << 0) /* Canonical for this value. */
121 #define CL_ENUM_DRIVER_ONLY (1 << 1) /* Only accepted in the driver. */
123 /* Structure describing an enumerated option argument. */
125 struct cl_enum_arg
127 /* The argument text, or NULL at the end of the array. */
128 const char *arg;
130 /* The corresponding integer value. */
131 int value;
133 /* Flags associated with this argument. */
134 unsigned int flags;
137 /* Structure describing an enumerated set of option arguments. */
139 struct cl_enum
141 /* Help text, or NULL if the values should not be listed in --help
142 output. */
143 const char *help;
145 /* Error message for unknown arguments, or NULL to use a generic
146 error. */
147 const char *unknown_error;
149 /* Array of possible values. */
150 const struct cl_enum_arg *values;
152 /* The size of the type used to store a value. */
153 size_t var_size;
155 /* Function to set a variable of this type. */
156 void (*set) (void *var, int value);
158 /* Function to get the value of a variable of this type. */
159 int (*get) (const void *var);
162 extern const struct cl_enum cl_enums[];
163 extern const unsigned int cl_enums_count;
165 /* Possible ways in which a command-line option may be erroneous.
166 These do not include not being known at all; an option index of
167 OPT_SPECIAL_unknown is used for that. */
169 #define CL_ERR_DISABLED (1 << 0) /* Disabled in this configuration. */
170 #define CL_ERR_MISSING_ARG (1 << 1) /* Argument required but missing. */
171 #define CL_ERR_WRONG_LANG (1 << 2) /* Option for wrong language. */
172 #define CL_ERR_UINT_ARG (1 << 3) /* Bad unsigned integer argument. */
173 #define CL_ERR_ENUM_ARG (1 << 4) /* Bad enumerated argument. */
174 #define CL_ERR_NEGATIVE (1 << 5) /* Negative form of option
175 not permitted (together
176 with OPT_SPECIAL_unknown). */
178 /* Structure describing the result of decoding an option. */
180 struct cl_decoded_option
182 /* The index of this option, or an OPT_SPECIAL_* value for
183 non-options and unknown options. */
184 size_t opt_index;
186 /* Any warning to give for use of this option, or NULL if none. */
187 const char *warn_message;
189 /* The string argument, or NULL if none. For OPT_SPECIAL_* cases,
190 the option or non-option command-line argument. */
191 const char *arg;
193 /* The original text of option plus arguments, with separate argv
194 elements concatenated into one string with spaces separating
195 them. This is for such uses as diagnostics and
196 -frecord-gcc-switches. */
197 const char *orig_option_with_args_text;
199 /* The canonical form of the option and its argument, for when it is
200 necessary to reconstruct argv elements (in particular, for
201 processing specs and passing options to subprocesses from the
202 driver). */
203 const char *canonical_option[4];
205 /* The number of elements in the canonical form of the option and
206 arguments; always at least 1. */
207 size_t canonical_option_num_elements;
209 /* For a boolean option, 1 for the true case and 0 for the "no-"
210 case. For an unsigned integer option, the value of the
211 argument. 1 in all other cases. */
212 int value;
214 /* Any flags describing errors detected in this option. */
215 int errors;
218 /* Structure describing an option deferred for handling after the main
219 option handlers. */
221 typedef struct
223 /* Elements from struct cl_decoded_option used for deferred
224 options. */
225 size_t opt_index;
226 const char *arg;
227 int value;
228 } cl_deferred_option;
229 DEF_VEC_O(cl_deferred_option);
230 DEF_VEC_ALLOC_O(cl_deferred_option,heap);
232 /* Structure describing a single option-handling callback. */
234 struct cl_option_handler_func
236 /* The function called to handle the option. */
237 bool (*handler) (struct gcc_options *opts,
238 struct gcc_options *opts_set,
239 const struct cl_decoded_option *decoded,
240 unsigned int lang_mask, int kind, location_t loc,
241 const struct cl_option_handlers *handlers,
242 diagnostic_context *dc);
244 /* The mask that must have some bit in common with the flags for the
245 option for this particular handler to be used. */
246 unsigned int mask;
249 /* Structure describing the callbacks used in handling options. */
251 struct cl_option_handlers
253 /* Callback for an unknown option to determine whether to give an
254 error for it, and possibly store information to diagnose the
255 option at a later point. Return true if an error should be
256 given, false otherwise. */
257 bool (*unknown_option_callback) (const struct cl_decoded_option *decoded);
259 /* Callback to handle, and possibly diagnose, an option for another
260 language. */
261 void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
262 unsigned int lang_mask);
264 /* Callback to call after the successful handling of any option. */
265 void (*post_handling_callback) (const struct cl_decoded_option *decoded,
266 unsigned int mask);
268 /* The number of individual handlers. */
269 size_t num_handlers;
271 /* The handlers themselves. */
272 struct cl_option_handler_func handlers[3];
275 /* Input file names. */
277 extern const char **in_fnames;
279 /* The count of input filenames. */
281 extern unsigned num_in_fnames;
283 /* GCC command-line arguments used during profile-gen, that are saved to the
284 profile data file. During profile-use, these can be compared to make sure
285 only those auxiliary modules are actually imported that use a compatible
286 set of GCC flags as the primary module. */
287 extern const char **lipo_cl_args;
289 /* The size of the above mentioned mentioned array. */
290 extern unsigned num_lipo_cl_args;
292 size_t find_opt (const char *input, int lang_mask);
293 extern int integral_argument (const char *arg);
294 extern bool enum_value_to_arg (const struct cl_enum_arg *enum_args,
295 const char **argp, int value,
296 unsigned int lang_mask);
297 extern void decode_cmdline_options_to_array (unsigned int argc,
298 const char **argv,
299 unsigned int lang_mask,
300 struct cl_decoded_option **decoded_options,
301 unsigned int *decoded_options_count);
302 extern void init_options_once (void);
303 extern void init_options_struct (struct gcc_options *opts,
304 struct gcc_options *opts_set);
305 extern void decode_cmdline_options_to_array_default_mask (unsigned int argc,
306 const char **argv,
307 struct cl_decoded_option **decoded_options,
308 unsigned int *decoded_options_count);
309 extern void set_default_handlers (struct cl_option_handlers *handlers);
310 extern void decode_options (struct gcc_options *opts,
311 struct gcc_options *opts_set,
312 struct cl_decoded_option *decoded_options,
313 unsigned int decoded_options_count,
314 location_t loc,
315 diagnostic_context *dc);
316 extern int option_enabled (int opt_idx, void *opts);
317 extern bool get_option_state (struct gcc_options *, int,
318 struct cl_option_state *);
319 extern void set_option (struct gcc_options *opts,
320 struct gcc_options *opts_set,
321 int opt_index, int value, const char *arg, int kind,
322 location_t loc, diagnostic_context *dc);
323 extern void *option_flag_var (int opt_index, struct gcc_options *opts);
324 bool handle_generated_option (struct gcc_options *opts,
325 struct gcc_options *opts_set,
326 size_t opt_index, const char *arg, int value,
327 unsigned int lang_mask, int kind, location_t loc,
328 const struct cl_option_handlers *handlers,
329 diagnostic_context *dc);
330 void generate_option (size_t opt_index, const char *arg, int value,
331 unsigned int lang_mask,
332 struct cl_decoded_option *decoded);
333 void generate_option_input_file (const char *file,
334 struct cl_decoded_option *decoded);
335 extern void read_cmdline_option (struct gcc_options *opts,
336 struct gcc_options *opts_set,
337 struct cl_decoded_option *decoded,
338 location_t loc,
339 unsigned int lang_mask,
340 const struct cl_option_handlers *handlers,
341 diagnostic_context *dc);
342 extern void control_warning_option (unsigned int opt_index, int kind,
343 bool imply, location_t loc,
344 unsigned int lang_mask,
345 const struct cl_option_handlers *handlers,
346 struct gcc_options *opts,
347 struct gcc_options *opts_set,
348 diagnostic_context *dc);
349 extern void print_ignored_options (void);
350 extern void add_input_filename (const char *filename);
351 extern void add_module_info (unsigned mod_id, bool is_primary, int index);
352 extern void set_lipo_c_parsing_context (struct cpp_reader *parse_in, int i, bool verbose);
353 extern void coverage_note_define (const char *cpp_def, bool is_def);
354 extern void coverage_note_include (const char *filename);
355 extern void handle_common_deferred_options (void);
356 extern bool common_handle_option (struct gcc_options *opts,
357 struct gcc_options *opts_set,
358 const struct cl_decoded_option *decoded,
359 unsigned int lang_mask, int kind,
360 location_t loc,
361 const struct cl_option_handlers *handlers,
362 diagnostic_context *dc);
363 extern bool target_handle_option (struct gcc_options *opts,
364 struct gcc_options *opts_set,
365 const struct cl_decoded_option *decoded,
366 unsigned int lang_mask, int kind,
367 location_t loc,
368 const struct cl_option_handlers *handlers,
369 diagnostic_context *dc);
370 extern void finish_options (struct gcc_options *opts,
371 struct gcc_options *opts_set,
372 location_t loc);
373 extern void default_options_optimization (struct gcc_options *opts,
374 struct gcc_options *opts_set,
375 struct cl_decoded_option *decoded_options,
376 unsigned int decoded_options_count,
377 location_t loc,
378 unsigned int lang_mask,
379 const struct cl_option_handlers *handlers,
380 diagnostic_context *dc);
381 extern void set_struct_debug_option (struct gcc_options *opts,
382 location_t loc,
383 const char *value);
384 extern void write_opts_to_asm (void);
385 extern void pattern_match_function_attributes (tree);
386 #endif