opts.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /* Command line option handling.
  2. Copyright (C) 2002-2019 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  9. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  11. for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef GCC_OPTS_H
  16. #define GCC_OPTS_H
  17. #include "obstack.h"
  18. /* Specifies how a switch's VAR_VALUE relates to its FLAG_VAR. */
  19. enum cl_var_type {
  20. /* The switch is enabled when FLAG_VAR is nonzero. */
  21. CLVC_BOOLEAN,
  22. /* The switch is enabled when FLAG_VAR == VAR_VALUE. */
  23. CLVC_EQUAL,
  24. /* The switch is enabled when VAR_VALUE is not set in FLAG_VAR. */
  25. CLVC_BIT_CLEAR,
  26. /* The switch is enabled when VAR_VALUE is set in FLAG_VAR. */
  27. CLVC_BIT_SET,
  28. /* The switch is enabled when FLAG_VAR is less than HOST_WIDE_INT_M1U. */
  29. CLVC_SIZE,
  30. /* The switch takes a string argument and FLAG_VAR points to that
  31. argument. */
  32. CLVC_STRING,
  33. /* The switch takes an enumerated argument (VAR_ENUM says what
  34. enumeration) and FLAG_VAR points to that argument. */
  35. CLVC_ENUM,
  36. /* The switch should be stored in the VEC pointed to by FLAG_VAR for
  37. later processing. */
  38. CLVC_DEFER
  39. };
  40. struct cl_option
  41. {
  42. /* Text of the option, including initial '-'. */
  43. const char *opt_text;
  44. /* Help text for --help, or NULL. */
  45. const char *help;
  46. /* Error message for missing argument, or NULL. */
  47. const char *missing_argument_error;
  48. /* Warning to give when this option is used, or NULL. */
  49. const char *warn_message;
  50. /* Argument of alias target when positive option given, or NULL. */
  51. const char *alias_arg;
  52. /* Argument of alias target when negative option given, or NULL. */
  53. const char *neg_alias_arg;
  54. /* Alias target, or N_OPTS if not an alias. */
  55. unsigned short alias_target;
  56. /* Previous option that is an initial substring of this one, or
  57. N_OPTS if none. */
  58. unsigned short back_chain;
  59. /* Option length, not including initial '-'. */
  60. unsigned char opt_len;
  61. /* Next option in a sequence marked with Negative, or -1 if none.
  62. For a single option with both a negative and a positve form
  63. (such as -Wall and -Wno-all), NEG_IDX is equal to the option's
  64. own index (i.e., cl_options[IDX].neg_idx == IDX holds). */
  65. int neg_index;
  66. /* CL_* flags for this option. */
  67. unsigned int flags;
  68. /* Disabled in this configuration. */
  69. BOOL_BITFIELD cl_disabled : 1;
  70. /* Options marked with CL_SEPARATE take a number of separate
  71. arguments (1 to 4) that is one more than the number in this
  72. bit-field. */
  73. unsigned int cl_separate_nargs : 2;
  74. /* Option is an alias when used with separate argument. */
  75. BOOL_BITFIELD cl_separate_alias : 1;
  76. /* Alias to negative form of option. */
  77. BOOL_BITFIELD cl_negative_alias : 1;
  78. /* Option takes no argument in the driver. */
  79. BOOL_BITFIELD cl_no_driver_arg : 1;
  80. /* Reject this option in the driver. */
  81. BOOL_BITFIELD cl_reject_driver : 1;
  82. /* Reject no- form. */
  83. BOOL_BITFIELD cl_reject_negative : 1;
  84. /* Missing argument OK (joined). */
  85. BOOL_BITFIELD cl_missing_ok : 1;
  86. /* Argument is an integer >=0. */
  87. BOOL_BITFIELD cl_uinteger : 1;
  88. /* Argument is a HOST_WIDE_INT. */
  89. BOOL_BITFIELD cl_host_wide_int : 1;
  90. /* Argument should be converted to lowercase. */
  91. BOOL_BITFIELD cl_tolower : 1;
  92. /* Report argument with -fverbose-asm */
  93. BOOL_BITFIELD cl_report : 1;
  94. /* Argument is an unsigned integer with an optional byte suffix. */
  95. BOOL_BITFIELD cl_byte_size: 1;
  96. /* Offset of field for this option in struct gcc_options, or
  97. (unsigned short) -1 if none. */
  98. unsigned short flag_var_offset;
  99. /* Index in cl_enums of enum used for this option's arguments, for
  100. CLVC_ENUM options. */
  101. unsigned short var_enum;
  102. /* How this option's value is determined and sets a field. */
  103. enum cl_var_type var_type;
  104. /* Value or bit-mask with which to set a field. */
  105. HOST_WIDE_INT var_value;
  106. /* Range info minimum, or -1. */
  107. int range_min;
  108. /* Range info maximum, or -1. */
  109. int range_max;
  110. };
  111. /* Records that the state of an option consists of SIZE bytes starting
  112. at DATA. DATA might point to CH in some cases. */
  113. struct cl_option_state {
  114. const void *data;
  115. size_t size;
  116. char ch;
  117. };
  118. extern const struct cl_option cl_options[];
  119. extern const unsigned int cl_options_count;
  120. extern const char *const lang_names[];
  121. extern const unsigned int cl_lang_count;
  122. #define CL_PARAMS (1U << 16) /* Fake entry. Used to display --param info with --help. */
  123. #define CL_WARNING (1U << 17) /* Enables an (optional) warning message. */
  124. #define CL_OPTIMIZATION (1U << 18) /* Enables an (optional) optimization. */
  125. #define CL_DRIVER (1U << 19) /* Driver option. */
  126. #define CL_TARGET (1U << 20) /* Target-specific option. */
  127. #define CL_COMMON (1U << 21) /* Language-independent. */
  128. #define CL_MIN_OPTION_CLASS CL_PARAMS
  129. #define CL_MAX_OPTION_CLASS CL_COMMON
  130. /* From here on the bits describe attributes of the options.
  131. Before this point the bits have described the class of the option.
  132. This distinction is important because --help will not list options
  133. which only have these higher bits set. */
  134. #define CL_JOINED (1U << 22) /* If takes joined argument. */
  135. #define CL_SEPARATE (1U << 23) /* If takes a separate argument. */
  136. #define CL_UNDOCUMENTED (1U << 24) /* Do not output with --help. */
  137. #define CL_NO_DWARF_RECORD (1U << 25) /* Do not add to producer string. */
  138. #define CL_PCH_IGNORE (1U << 26) /* Do compare state for pch. */
  139. /* Flags for an enumerated option argument. */
  140. #define CL_ENUM_CANONICAL (1 << 0) /* Canonical for this value. */
  141. #define CL_ENUM_DRIVER_ONLY (1 << 1) /* Only accepted in the driver. */
  142. /* Structure describing an enumerated option argument. */
  143. struct cl_enum_arg
  144. {
  145. /* The argument text, or NULL at the end of the array. */
  146. const char *arg;
  147. /* The corresponding integer value. */
  148. int value;
  149. /* Flags associated with this argument. */
  150. unsigned int flags;
  151. };
  152. /* Structure describing an enumerated set of option arguments. */
  153. struct cl_enum
  154. {
  155. /* Help text, or NULL if the values should not be listed in --help
  156. output. */
  157. const char *help;
  158. /* Error message for unknown arguments, or NULL to use a generic
  159. error. */
  160. const char *unknown_error;
  161. /* Array of possible values. */
  162. const struct cl_enum_arg *values;
  163. /* The size of the type used to store a value. */
  164. size_t var_size;
  165. /* Function to set a variable of this type. */
  166. void (*set) (void *var, int value);
  167. /* Function to get the value of a variable of this type. */
  168. int (*get) (const void *var);
  169. };
  170. extern const struct cl_enum cl_enums[];
  171. extern const unsigned int cl_enums_count;
  172. /* Possible ways in which a command-line option may be erroneous.
  173. These do not include not being known at all; an option index of
  174. OPT_SPECIAL_unknown is used for that. */
  175. #define CL_ERR_DISABLED (1 << 0) /* Disabled in this configuration. */
  176. #define CL_ERR_MISSING_ARG (1 << 1) /* Argument required but missing. */
  177. #define CL_ERR_WRONG_LANG (1 << 2) /* Option for wrong language. */
  178. #define CL_ERR_UINT_ARG (1 << 3) /* Bad unsigned integer argument. */
  179. #define CL_ERR_INT_RANGE_ARG (1 << 4) /* Bad unsigned integer argument. */
  180. #define CL_ERR_ENUM_ARG (1 << 5) /* Bad enumerated argument. */
  181. #define CL_ERR_NEGATIVE (1 << 6) /* Negative form of option
  182. not permitted (together
  183. with OPT_SPECIAL_unknown). */
  184. /* Structure describing the result of decoding an option. */
  185. struct cl_decoded_option
  186. {
  187. /* The index of this option, or an OPT_SPECIAL_* value for
  188. non-options and unknown options. */
  189. size_t opt_index;
  190. /* Any warning to give for use of this option, or NULL if none. */
  191. const char *warn_message;
  192. /* The string argument, or NULL if none. For OPT_SPECIAL_* cases,
  193. the option or non-option command-line argument. */
  194. const char *arg;
  195. /* The original text of option plus arguments, with separate argv
  196. elements concatenated into one string with spaces separating
  197. them. This is for such uses as diagnostics and
  198. -frecord-gcc-switches. */
  199. const char *orig_option_with_args_text;
  200. /* The canonical form of the option and its argument, for when it is
  201. necessary to reconstruct argv elements (in particular, for
  202. processing specs and passing options to subprocesses from the
  203. driver). */
  204. 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;
  208. /* For a boolean option, 1 for the true case and 0 for the "no-"
  209. case. For an unsigned integer option, the value of the
  210. argument. 1 in all other cases. */
  211. HOST_WIDE_INT value;
  212. /* Any flags describing errors detected in this option. */
  213. int errors;
  214. };
  215. /* Structure describing an option deferred for handling after the main
  216. option handlers. */
  217. struct cl_deferred_option
  218. {
  219. /* Elements from struct cl_decoded_option used for deferred
  220. options. */
  221. size_t opt_index;
  222. const char *arg;
  223. int value;
  224. };
  225. /* Structure describing a single option-handling callback. */
  226. struct cl_option_handler_func
  227. {
  228. /* The function called to handle the option. */
  229. bool (*handler) (struct gcc_options *opts,
  230. struct gcc_options *opts_set,
  231. const struct cl_decoded_option *decoded,
  232. unsigned int lang_mask, int kind, location_t loc,
  233. const struct cl_option_handlers *handlers,
  234. diagnostic_context *dc,
  235. void (*target_option_override_hook) (void));
  236. /* The mask that must have some bit in common with the flags for the
  237. option for this particular handler to be used. */
  238. unsigned int mask;
  239. };
  240. /* Structure describing the callbacks used in handling options. */
  241. struct cl_option_handlers
  242. {
  243. /* Callback for an unknown option to determine whether to give an
  244. error for it, and possibly store information to diagnose the
  245. option at a later point. Return true if an error should be
  246. given, false otherwise. */
  247. bool (*unknown_option_callback) (const struct cl_decoded_option *decoded);
  248. /* Callback to handle, and possibly diagnose, an option for another
  249. language. */
  250. void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
  251. unsigned int lang_mask);
  252. /* Target option override hook. */
  253. void (*target_option_override_hook) (void);
  254. /* The number of individual handlers. */
  255. size_t num_handlers;
  256. /* The handlers themselves. */
  257. struct cl_option_handler_func handlers[3];
  258. };
  259. /* Hold command-line options associated with stack limitation. */
  260. extern const char *opt_fstack_limit_symbol_arg;
  261. extern int opt_fstack_limit_register_no;
  262. /* Input file names. */
  263. extern const char **in_fnames;
  264. /* The count of input filenames. */
  265. extern unsigned num_in_fnames;
  266. extern char *opts_concat (const char *first, ...);
  267. /* Obstack for option strings. */
  268. extern struct obstack opts_obstack;
  269. size_t find_opt (const char *input, unsigned int lang_mask);
  270. extern HOST_WIDE_INT integral_argument (const char *arg, int * = NULL, bool = false);
  271. extern bool enum_value_to_arg (const struct cl_enum_arg *enum_args,
  272. const char **argp, int value,
  273. unsigned int lang_mask);
  274. extern void decode_cmdline_options_to_array (unsigned int argc,
  275. const char **argv,
  276. unsigned int lang_mask,
  277. struct cl_decoded_option **decoded_options,
  278. unsigned int *decoded_options_count);
  279. extern void init_options_once (void);
  280. extern void init_options_struct (struct gcc_options *opts,
  281. struct gcc_options *opts_set);
  282. extern void init_opts_obstack (void);
  283. extern void finalize_options_struct (struct gcc_options *opts);
  284. extern void decode_cmdline_options_to_array_default_mask (unsigned int argc,
  285. const char **argv,
  286. struct cl_decoded_option **decoded_options,
  287. unsigned int *decoded_options_count);
  288. extern void set_default_handlers (struct cl_option_handlers *handlers,
  289. void (*target_option_override_hook) (void));
  290. extern void decode_options (struct gcc_options *opts,
  291. struct gcc_options *opts_set,
  292. struct cl_decoded_option *decoded_options,
  293. unsigned int decoded_options_count,
  294. location_t loc,
  295. diagnostic_context *dc,
  296. void (*target_option_override_hook) (void));
  297. extern int option_enabled (int opt_idx, void *opts);
  298. extern bool get_option_state (struct gcc_options *, int,
  299. struct cl_option_state *);
  300. extern void set_option (struct gcc_options *opts,
  301. struct gcc_options *opts_set,
  302. int opt_index, HOST_WIDE_INT value, const char *arg,
  303. int kind, location_t loc, diagnostic_context *dc);
  304. extern void *option_flag_var (int opt_index, struct gcc_options *opts);
  305. bool handle_generated_option (struct gcc_options *opts,
  306. struct gcc_options *opts_set,
  307. size_t opt_index, const char *arg,
  308. HOST_WIDE_INT value,
  309. unsigned int lang_mask, int kind, location_t loc,
  310. const struct cl_option_handlers *handlers,
  311. bool generated_p, diagnostic_context *dc);
  312. void generate_option (size_t opt_index, const char *arg, HOST_WIDE_INT value,
  313. unsigned int lang_mask,
  314. struct cl_decoded_option *decoded);
  315. void generate_option_input_file (const char *file,
  316. struct cl_decoded_option *decoded);
  317. extern void read_cmdline_option (struct gcc_options *opts,
  318. struct gcc_options *opts_set,
  319. struct cl_decoded_option *decoded,
  320. location_t loc,
  321. unsigned int lang_mask,
  322. const struct cl_option_handlers *handlers,
  323. diagnostic_context *dc);
  324. extern void control_warning_option (unsigned int opt_index, int kind,
  325. const char *arg, bool imply, location_t loc,
  326. unsigned int lang_mask,
  327. const struct cl_option_handlers *handlers,
  328. struct gcc_options *opts,
  329. struct gcc_options *opts_set,
  330. diagnostic_context *dc);
  331. extern char *write_langs (unsigned int mask);
  332. extern void print_ignored_options (void);
  333. extern void handle_common_deferred_options (void);
  334. unsigned int parse_sanitizer_options (const char *, location_t, int,
  335. unsigned int, int, bool);
  336. unsigned int parse_no_sanitize_attribute (char *value);
  337. extern bool common_handle_option (struct gcc_options *opts,
  338. struct gcc_options *opts_set,
  339. const struct cl_decoded_option *decoded,
  340. unsigned int lang_mask, int kind,
  341. location_t loc,
  342. const struct cl_option_handlers *handlers,
  343. diagnostic_context *dc,
  344. void (*target_option_override_hook) (void));
  345. extern bool target_handle_option (struct gcc_options *opts,
  346. struct gcc_options *opts_set,
  347. const struct cl_decoded_option *decoded,
  348. unsigned int lang_mask, int kind,
  349. location_t loc,
  350. const struct cl_option_handlers *handlers,
  351. diagnostic_context *dc,
  352. void (*target_option_override_hook) (void));
  353. extern void finish_options (struct gcc_options *opts,
  354. struct gcc_options *opts_set,
  355. location_t loc);
  356. extern void default_options_optimization (struct gcc_options *opts,
  357. struct gcc_options *opts_set,
  358. struct cl_decoded_option *decoded_options,
  359. unsigned int decoded_options_count,
  360. location_t loc,
  361. unsigned int lang_mask,
  362. const struct cl_option_handlers *handlers,
  363. diagnostic_context *dc);
  364. extern void set_struct_debug_option (struct gcc_options *opts,
  365. location_t loc,
  366. const char *value);
  367. extern bool opt_enum_arg_to_value (size_t opt_index, const char *arg,
  368. int *value,
  369. unsigned int lang_mask);
  370. extern const struct sanitizer_opts_s
  371. {
  372. const char *const name;
  373. unsigned int flag;
  374. size_t len;
  375. bool can_recover;
  376. } sanitizer_opts[];
  377. extern void add_misspelling_candidates (auto_vec<char *> *candidates,
  378. const struct cl_option *option,
  379. const char *base_option);
  380. extern const char *candidates_list_and_hint (const char *arg, char *&str,
  381. const auto_vec <const char *> &
  382. candidates);
  383. extern bool parse_and_check_align_values (const char *flag,
  384. const char *name,
  385. auto_vec<unsigned> &result_values,
  386. bool report_error,
  387. location_t loc);
  388. #endif