opts.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. /* Command line option handling.
  2. Copyright (C) 2002-2015 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 "input.h"
  18. #include "vec.h"
  19. #include "obstack.h"
  20. /* Specifies how a switch's VAR_VALUE relates to its FLAG_VAR. */
  21. enum cl_var_type {
  22. /* The switch is enabled when FLAG_VAR is nonzero. */
  23. CLVC_BOOLEAN,
  24. /* The switch is enabled when FLAG_VAR == VAR_VALUE. */
  25. CLVC_EQUAL,
  26. /* The switch is enabled when VAR_VALUE is not set in FLAG_VAR. */
  27. CLVC_BIT_CLEAR,
  28. /* The switch is enabled when VAR_VALUE is set in FLAG_VAR. */
  29. CLVC_BIT_SET,
  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. int neg_index;
  63. /* CL_* flags for this option. */
  64. unsigned int flags;
  65. /* Disabled in this configuration. */
  66. BOOL_BITFIELD cl_disabled : 1;
  67. /* Options marked with CL_SEPARATE take a number of separate
  68. arguments (1 to 4) that is one more than the number in this
  69. bit-field. */
  70. unsigned int cl_separate_nargs : 2;
  71. /* Option is an alias when used with separate argument. */
  72. BOOL_BITFIELD cl_separate_alias : 1;
  73. /* Alias to negative form of option. */
  74. BOOL_BITFIELD cl_negative_alias : 1;
  75. /* Option takes no argument in the driver. */
  76. BOOL_BITFIELD cl_no_driver_arg : 1;
  77. /* Reject this option in the driver. */
  78. BOOL_BITFIELD cl_reject_driver : 1;
  79. /* Reject no- form. */
  80. BOOL_BITFIELD cl_reject_negative : 1;
  81. /* Missing argument OK (joined). */
  82. BOOL_BITFIELD cl_missing_ok : 1;
  83. /* Argument is an integer >=0. */
  84. BOOL_BITFIELD cl_uinteger : 1;
  85. /* Argument is a HOST_WIDE_INT. */
  86. BOOL_BITFIELD cl_host_wide_int : 1;
  87. /* Argument should be converted to lowercase. */
  88. BOOL_BITFIELD cl_tolower : 1;
  89. /* Report argument with -fverbose-asm */
  90. BOOL_BITFIELD cl_report : 1;
  91. /* Offset of field for this option in struct gcc_options, or
  92. (unsigned short) -1 if none. */
  93. unsigned short flag_var_offset;
  94. /* Index in cl_enums of enum used for this option's arguments, for
  95. CLVC_ENUM options. */
  96. unsigned short var_enum;
  97. /* How this option's value is determined and sets a field. */
  98. enum cl_var_type var_type;
  99. /* Value or bit-mask with which to set a field. */
  100. HOST_WIDE_INT var_value;
  101. };
  102. /* Records that the state of an option consists of SIZE bytes starting
  103. at DATA. DATA might point to CH in some cases. */
  104. struct cl_option_state {
  105. const void *data;
  106. size_t size;
  107. char ch;
  108. };
  109. extern const struct cl_option cl_options[];
  110. extern const unsigned int cl_options_count;
  111. extern const char *const lang_names[];
  112. extern const unsigned int cl_lang_count;
  113. #define CL_PARAMS (1U << 16) /* Fake entry. Used to display --param info with --help. */
  114. #define CL_WARNING (1U << 17) /* Enables an (optional) warning message. */
  115. #define CL_OPTIMIZATION (1U << 18) /* Enables an (optional) optimization. */
  116. #define CL_DRIVER (1U << 19) /* Driver option. */
  117. #define CL_TARGET (1U << 20) /* Target-specific option. */
  118. #define CL_COMMON (1U << 21) /* Language-independent. */
  119. #define CL_MIN_OPTION_CLASS CL_PARAMS
  120. #define CL_MAX_OPTION_CLASS CL_COMMON
  121. /* From here on the bits describe attributes of the options.
  122. Before this point the bits have described the class of the option.
  123. This distinction is important because --help will not list options
  124. which only have these higher bits set. */
  125. #define CL_JOINED (1U << 22) /* If takes joined argument. */
  126. #define CL_SEPARATE (1U << 23) /* If takes a separate argument. */
  127. #define CL_UNDOCUMENTED (1U << 24) /* Do not output with --help. */
  128. #define CL_NO_DWARF_RECORD (1U << 25) /* Do not add to producer string. */
  129. #define CL_PCH_IGNORE (1U << 26) /* Do compare state for pch. */
  130. /* Flags for an enumerated option argument. */
  131. #define CL_ENUM_CANONICAL (1 << 0) /* Canonical for this value. */
  132. #define CL_ENUM_DRIVER_ONLY (1 << 1) /* Only accepted in the driver. */
  133. /* Structure describing an enumerated option argument. */
  134. struct cl_enum_arg
  135. {
  136. /* The argument text, or NULL at the end of the array. */
  137. const char *arg;
  138. /* The corresponding integer value. */
  139. int value;
  140. /* Flags associated with this argument. */
  141. unsigned int flags;
  142. };
  143. /* Structure describing an enumerated set of option arguments. */
  144. struct cl_enum
  145. {
  146. /* Help text, or NULL if the values should not be listed in --help
  147. output. */
  148. const char *help;
  149. /* Error message for unknown arguments, or NULL to use a generic
  150. error. */
  151. const char *unknown_error;
  152. /* Array of possible values. */
  153. const struct cl_enum_arg *values;
  154. /* The size of the type used to store a value. */
  155. size_t var_size;
  156. /* Function to set a variable of this type. */
  157. void (*set) (void *var, int value);
  158. /* Function to get the value of a variable of this type. */
  159. int (*get) (const void *var);
  160. };
  161. extern const struct cl_enum cl_enums[];
  162. extern const unsigned int cl_enums_count;
  163. /* Possible ways in which a command-line option may be erroneous.
  164. These do not include not being known at all; an option index of
  165. OPT_SPECIAL_unknown is used for that. */
  166. #define CL_ERR_DISABLED (1 << 0) /* Disabled in this configuration. */
  167. #define CL_ERR_MISSING_ARG (1 << 1) /* Argument required but missing. */
  168. #define CL_ERR_WRONG_LANG (1 << 2) /* Option for wrong language. */
  169. #define CL_ERR_UINT_ARG (1 << 3) /* Bad unsigned integer argument. */
  170. #define CL_ERR_ENUM_ARG (1 << 4) /* Bad enumerated argument. */
  171. #define CL_ERR_NEGATIVE (1 << 5) /* Negative form of option
  172. not permitted (together
  173. with OPT_SPECIAL_unknown). */
  174. /* Structure describing the result of decoding an option. */
  175. struct cl_decoded_option
  176. {
  177. /* The index of this option, or an OPT_SPECIAL_* value for
  178. non-options and unknown options. */
  179. size_t opt_index;
  180. /* Any warning to give for use of this option, or NULL if none. */
  181. const char *warn_message;
  182. /* The string argument, or NULL if none. For OPT_SPECIAL_* cases,
  183. the option or non-option command-line argument. */
  184. const char *arg;
  185. /* The original text of option plus arguments, with separate argv
  186. elements concatenated into one string with spaces separating
  187. them. This is for such uses as diagnostics and
  188. -frecord-gcc-switches. */
  189. const char *orig_option_with_args_text;
  190. /* The canonical form of the option and its argument, for when it is
  191. necessary to reconstruct argv elements (in particular, for
  192. processing specs and passing options to subprocesses from the
  193. driver). */
  194. const char *canonical_option[4];
  195. /* The number of elements in the canonical form of the option and
  196. arguments; always at least 1. */
  197. size_t canonical_option_num_elements;
  198. /* For a boolean option, 1 for the true case and 0 for the "no-"
  199. case. For an unsigned integer option, the value of the
  200. argument. 1 in all other cases. */
  201. int value;
  202. /* Any flags describing errors detected in this option. */
  203. int errors;
  204. };
  205. /* Structure describing an option deferred for handling after the main
  206. option handlers. */
  207. struct cl_deferred_option
  208. {
  209. /* Elements from struct cl_decoded_option used for deferred
  210. options. */
  211. size_t opt_index;
  212. const char *arg;
  213. int value;
  214. };
  215. /* Structure describing a single option-handling callback. */
  216. struct cl_option_handler_func
  217. {
  218. /* The function called to handle the option. */
  219. bool (*handler) (struct gcc_options *opts,
  220. struct gcc_options *opts_set,
  221. const struct cl_decoded_option *decoded,
  222. unsigned int lang_mask, int kind, location_t loc,
  223. const struct cl_option_handlers *handlers,
  224. diagnostic_context *dc);
  225. /* The mask that must have some bit in common with the flags for the
  226. option for this particular handler to be used. */
  227. unsigned int mask;
  228. };
  229. /* Structure describing the callbacks used in handling options. */
  230. struct cl_option_handlers
  231. {
  232. /* Callback for an unknown option to determine whether to give an
  233. error for it, and possibly store information to diagnose the
  234. option at a later point. Return true if an error should be
  235. given, false otherwise. */
  236. bool (*unknown_option_callback) (const struct cl_decoded_option *decoded);
  237. /* Callback to handle, and possibly diagnose, an option for another
  238. language. */
  239. void (*wrong_lang_callback) (const struct cl_decoded_option *decoded,
  240. unsigned int lang_mask);
  241. /* The number of individual handlers. */
  242. size_t num_handlers;
  243. /* The handlers themselves. */
  244. struct cl_option_handler_func handlers[3];
  245. };
  246. /* Input file names. */
  247. extern const char **in_fnames;
  248. /* The count of input filenames. */
  249. extern unsigned num_in_fnames;
  250. extern char *opts_concat (const char *first, ...);
  251. /* Obstack for option strings. */
  252. extern struct obstack opts_obstack;
  253. size_t find_opt (const char *input, unsigned int lang_mask);
  254. extern int integral_argument (const char *arg);
  255. extern bool enum_value_to_arg (const struct cl_enum_arg *enum_args,
  256. const char **argp, int value,
  257. unsigned int lang_mask);
  258. extern void decode_cmdline_options_to_array (unsigned int argc,
  259. const char **argv,
  260. unsigned int lang_mask,
  261. struct cl_decoded_option **decoded_options,
  262. unsigned int *decoded_options_count);
  263. extern void init_options_once (void);
  264. extern void init_options_struct (struct gcc_options *opts,
  265. struct gcc_options *opts_set);
  266. extern void finalize_options_struct (struct gcc_options *opts);
  267. extern void decode_cmdline_options_to_array_default_mask (unsigned int argc,
  268. const char **argv,
  269. struct cl_decoded_option **decoded_options,
  270. unsigned int *decoded_options_count);
  271. extern void set_default_handlers (struct cl_option_handlers *handlers);
  272. extern void decode_options (struct gcc_options *opts,
  273. struct gcc_options *opts_set,
  274. struct cl_decoded_option *decoded_options,
  275. unsigned int decoded_options_count,
  276. location_t loc,
  277. diagnostic_context *dc);
  278. extern int option_enabled (int opt_idx, void *opts);
  279. extern bool get_option_state (struct gcc_options *, int,
  280. struct cl_option_state *);
  281. extern void set_option (struct gcc_options *opts,
  282. struct gcc_options *opts_set,
  283. int opt_index, int value, const char *arg, int kind,
  284. location_t loc, diagnostic_context *dc);
  285. extern void *option_flag_var (int opt_index, struct gcc_options *opts);
  286. bool handle_generated_option (struct gcc_options *opts,
  287. struct gcc_options *opts_set,
  288. size_t opt_index, const char *arg, int value,
  289. unsigned int lang_mask, int kind, location_t loc,
  290. const struct cl_option_handlers *handlers,
  291. diagnostic_context *dc);
  292. void generate_option (size_t opt_index, const char *arg, int value,
  293. unsigned int lang_mask,
  294. struct cl_decoded_option *decoded);
  295. void generate_option_input_file (const char *file,
  296. struct cl_decoded_option *decoded);
  297. extern void read_cmdline_option (struct gcc_options *opts,
  298. struct gcc_options *opts_set,
  299. struct cl_decoded_option *decoded,
  300. location_t loc,
  301. unsigned int lang_mask,
  302. const struct cl_option_handlers *handlers,
  303. diagnostic_context *dc);
  304. extern void control_warning_option (unsigned int opt_index, int kind,
  305. bool imply, location_t loc,
  306. unsigned int lang_mask,
  307. const struct cl_option_handlers *handlers,
  308. struct gcc_options *opts,
  309. struct gcc_options *opts_set,
  310. diagnostic_context *dc);
  311. extern void print_ignored_options (void);
  312. extern void handle_common_deferred_options (void);
  313. extern bool common_handle_option (struct gcc_options *opts,
  314. struct gcc_options *opts_set,
  315. const struct cl_decoded_option *decoded,
  316. unsigned int lang_mask, int kind,
  317. location_t loc,
  318. const struct cl_option_handlers *handlers,
  319. diagnostic_context *dc);
  320. extern bool target_handle_option (struct gcc_options *opts,
  321. struct gcc_options *opts_set,
  322. const struct cl_decoded_option *decoded,
  323. unsigned int lang_mask, int kind,
  324. location_t loc,
  325. const struct cl_option_handlers *handlers,
  326. diagnostic_context *dc);
  327. extern void finish_options (struct gcc_options *opts,
  328. struct gcc_options *opts_set,
  329. location_t loc);
  330. extern void default_options_optimization (struct gcc_options *opts,
  331. struct gcc_options *opts_set,
  332. struct cl_decoded_option *decoded_options,
  333. unsigned int decoded_options_count,
  334. location_t loc,
  335. unsigned int lang_mask,
  336. const struct cl_option_handlers *handlers,
  337. diagnostic_context *dc);
  338. extern void set_struct_debug_option (struct gcc_options *opts,
  339. location_t loc,
  340. const char *value);
  341. extern bool opt_enum_arg_to_value (size_t opt_index, const char *arg,
  342. int *value, unsigned int lang_mask);
  343. #endif