* configure.in: Fix sed invocation for GFORTRAN_FOR_TARGET.
[official-gcc.git] / gcc / opts.c
blobcd9e8e3db72acce449c740112b146605026c450b
1 /* Command line option handling.
2 Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3 Contributed by Neil Booth.
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 2, 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 COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 #include "config.h"
23 #include "system.h"
24 #include "intl.h"
25 #include "coretypes.h"
26 #include "tm.h"
27 #include "tree.h"
28 #include "rtl.h"
29 #include "ggc.h"
30 #include "output.h"
31 #include "langhooks.h"
32 #include "opts.h"
33 #include "options.h"
34 #include "flags.h"
35 #include "toplev.h"
36 #include "params.h"
37 #include "diagnostic.h"
38 #include "tm_p.h" /* For OPTIMIZATION_OPTIONS. */
39 #include "insn-attr.h" /* For INSN_SCHEDULING. */
40 #include "target.h"
42 /* Value of the -G xx switch, and whether it was passed or not. */
43 unsigned HOST_WIDE_INT g_switch_value;
44 bool g_switch_set;
46 /* True if we should exit after parsing options. */
47 bool exit_after_options;
49 /* If -version. */
50 bool version_flag;
52 /* Print various extra warnings. -W/-Wextra. */
53 bool extra_warnings;
55 /* Don't print warning messages. -w. */
56 bool inhibit_warnings;
58 /* Treat warnings as errors. -Werror. */
59 bool warnings_are_errors;
61 /* Warn if a function returns an aggregate, since there are often
62 incompatible calling conventions for doing this. */
63 bool warn_aggregate_return;
65 /* Nonzero means warn about pointer casts that increase the required
66 alignment of the target type (and might therefore lead to a crash
67 due to a misaligned access). */
68 bool warn_cast_align;
70 /* Nonzero means warn about uses of __attribute__((deprecated))
71 declarations. */
72 bool warn_deprecated_decl = true;
74 /* Warn when an optimization pass is disabled. */
75 bool warn_disabled_optimization;
77 /* Nonzero means warn if inline function is too large. */
78 bool warn_inline;
80 /* True to warn about any objects definitions whose size is larger
81 than N bytes. Also want about function definitions whose returned
82 values are larger than N bytes, where N is `larger_than_size'. */
83 bool warn_larger_than;
84 HOST_WIDE_INT larger_than_size;
86 /* Warn about functions which might be candidates for attribute noreturn. */
87 bool warn_missing_noreturn;
89 /* True to warn about code which is never reached. */
90 bool warn_notreached;
92 /* Warn if packed attribute on struct is unnecessary and inefficient. */
93 bool warn_packed;
95 /* Warn when gcc pads a structure to an alignment boundary. */
96 bool warn_padded;
98 /* True means warn about all declarations which shadow others. */
99 bool warn_shadow;
101 /* Nonzero means warn about constructs which might not be
102 strict-aliasing safe. */
103 int warn_strict_aliasing;
105 /* True to warn if a switch on an enum, that does not have a default
106 case, fails to have a case for every enum value. */
107 bool warn_switch;
109 /* Warn if a switch does not have a default case. */
110 bool warn_switch_default;
112 /* Warn if a switch on an enum fails to have a case for every enum
113 value (regardless of the presence or otherwise of a default case). */
114 bool warn_switch_enum;
116 /* Don't suppress warnings from system headers. -Wsystem-headers. */
117 bool warn_system_headers;
119 /* True to warn about variables used before they are initialized. */
120 int warn_uninitialized;
122 /* True to warn about unused variables, functions et.al. */
123 bool warn_unused_function;
124 bool warn_unused_label;
125 bool warn_unused_parameter;
126 bool warn_unused_variable;
127 bool warn_unused_value;
129 /* Hack for cooperation between set_Wunused and set_Wextra. */
130 static bool maybe_warn_unused_parameter;
132 /* Type(s) of debugging information we are producing (if any). See
133 flags.h for the definitions of the different possible types of
134 debugging information. */
135 enum debug_info_type write_symbols = NO_DEBUG;
137 /* Level of debugging information we are producing. See flags.h for
138 the definitions of the different possible levels. */
139 enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
141 /* Nonzero means use GNU-only extensions in the generated symbolic
142 debugging information. Currently, this only has an effect when
143 write_symbols is set to DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG. */
144 bool use_gnu_debug_info_extensions;
146 /* Columns of --help display. */
147 static unsigned int columns = 80;
149 /* What to print when a switch has no documentation. */
150 static const char undocumented_msg[] = N_("This switch lacks documentation");
152 /* Used for bookkeeping on whether user set these flags so
153 -fprofile-use/-fprofile-generate does not use them. */
154 static bool profile_arc_flag_set, flag_profile_values_set;
155 static bool flag_unroll_loops_set, flag_tracer_set;
156 static bool flag_value_profile_transformations_set;
157 static bool flag_peel_loops_set, flag_branch_probabilities_set;
159 /* Input file names. */
160 const char **in_fnames;
161 unsigned num_in_fnames;
163 static size_t find_opt (const char *, int);
164 static int common_handle_option (size_t scode, const char *arg, int value);
165 static void handle_param (const char *);
166 static void set_Wextra (int);
167 static unsigned int handle_option (const char **argv, unsigned int lang_mask);
168 static char *write_langs (unsigned int lang_mask);
169 static void complain_wrong_lang (const char *, const struct cl_option *,
170 unsigned int lang_mask);
171 static void handle_options (unsigned int, const char **, unsigned int);
172 static void wrap_help (const char *help, const char *item, unsigned int);
173 static void print_help (void);
174 static void print_param_help (void);
175 static void print_filtered_help (unsigned int flag);
176 static unsigned int print_switch (const char *text, unsigned int indent);
177 static void set_debug_level (enum debug_info_type type, int extended,
178 const char *arg);
180 /* Perform a binary search to find which option the command-line INPUT
181 matches. Returns its index in the option array, and N_OPTS
182 (cl_options_count) on failure.
184 This routine is quite subtle. A normal binary search is not good
185 enough because some options can be suffixed with an argument, and
186 multiple sub-matches can occur, e.g. input of "-pedantic" matching
187 the initial substring of "-pedantic-errors".
189 A more complicated example is -gstabs. It should match "-g" with
190 an argument of "stabs". Suppose, however, that the number and list
191 of switches are such that the binary search tests "-gen-decls"
192 before having tested "-g". This doesn't match, and as "-gen-decls"
193 is less than "-gstabs", it will become the lower bound of the
194 binary search range, and "-g" will never be seen. To resolve this
195 issue, opts.sh makes "-gen-decls" point, via the back_chain member,
196 to "-g" so that failed searches that end between "-gen-decls" and
197 the lexicographically subsequent switch know to go back and see if
198 "-g" causes a match (which it does in this example).
200 This search is done in such a way that the longest match for the
201 front end in question wins. If there is no match for the current
202 front end, the longest match for a different front end is returned
203 (or N_OPTS if none) and the caller emits an error message. */
204 static size_t
205 find_opt (const char *input, int lang_mask)
207 size_t mn, mx, md, opt_len;
208 size_t match_wrong_lang;
209 int comp;
211 mn = 0;
212 mx = cl_options_count;
214 /* Find mn such this lexicographical inequality holds:
215 cl_options[mn] <= input < cl_options[mn + 1]. */
216 while (mx - mn > 1)
218 md = (mn + mx) / 2;
219 opt_len = cl_options[md].opt_len;
220 comp = strncmp (input, cl_options[md].opt_text + 1, opt_len);
222 if (comp < 0)
223 mx = md;
224 else
225 mn = md;
228 /* This is the switch that is the best match but for a different
229 front end, or cl_options_count if there is no match at all. */
230 match_wrong_lang = cl_options_count;
232 /* Backtrace the chain of possible matches, returning the longest
233 one, if any, that fits best. With current GCC switches, this
234 loop executes at most twice. */
237 const struct cl_option *opt = &cl_options[mn];
239 /* Is this switch a prefix of the input? */
240 if (!strncmp (input, opt->opt_text + 1, opt->opt_len))
242 /* If language is OK, and the match is exact or the switch
243 takes a joined argument, return it. */
244 if ((opt->flags & lang_mask)
245 && (input[opt->opt_len] == '\0' || (opt->flags & CL_JOINED)))
246 return mn;
248 /* If we haven't remembered a prior match, remember this
249 one. Any prior match is necessarily better. */
250 if (match_wrong_lang == cl_options_count)
251 match_wrong_lang = mn;
254 /* Try the next possibility. This is cl_options_count if there
255 are no more. */
256 mn = opt->back_chain;
258 while (mn != cl_options_count);
260 /* Return the best wrong match, or cl_options_count if none. */
261 return match_wrong_lang;
264 /* If ARG is a non-negative integer made up solely of digits, return its
265 value, otherwise return -1. */
266 static int
267 integral_argument (const char *arg)
269 const char *p = arg;
271 while (*p && ISDIGIT (*p))
272 p++;
274 if (*p == '\0')
275 return atoi (arg);
277 return -1;
280 /* Return a malloced slash-separated list of languages in MASK. */
281 static char *
282 write_langs (unsigned int mask)
284 unsigned int n = 0, len = 0;
285 const char *lang_name;
286 char *result;
288 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
289 if (mask & (1U << n))
290 len += strlen (lang_name) + 1;
292 result = xmalloc (len);
293 len = 0;
294 for (n = 0; (lang_name = lang_names[n]) != 0; n++)
295 if (mask & (1U << n))
297 if (len)
298 result[len++] = '/';
299 strcpy (result + len, lang_name);
300 len += strlen (lang_name);
303 result[len] = 0;
305 return result;
308 /* Complain that switch OPT_INDEX does not apply to this front end. */
309 static void
310 complain_wrong_lang (const char *text, const struct cl_option *option,
311 unsigned int lang_mask)
313 char *ok_langs, *bad_lang;
315 ok_langs = write_langs (option->flags);
316 bad_lang = write_langs (lang_mask);
318 /* Eventually this should become a hard error IMO. */
319 warning ("command line option \"%s\" is valid for %s but not for %s",
320 text, ok_langs, bad_lang);
322 free (ok_langs);
323 free (bad_lang);
326 /* Handle the switch beginning at ARGV for the language indicated by
327 LANG_MASK. Returns the number of switches consumed. */
328 static unsigned int
329 handle_option (const char **argv, unsigned int lang_mask)
331 size_t opt_index;
332 const char *opt, *arg = 0;
333 char *dup = 0;
334 int value = 1;
335 unsigned int result = 0;
336 const struct cl_option *option;
338 opt = argv[0];
340 /* Drop the "no-" from negative switches. */
341 if ((opt[1] == 'W' || opt[1] == 'f')
342 && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
344 size_t len = strlen (opt) - 3;
346 dup = xmalloc (len + 1);
347 dup[0] = '-';
348 dup[1] = opt[1];
349 memcpy (dup + 2, opt + 5, len - 2 + 1);
350 opt = dup;
351 value = 0;
354 opt_index = find_opt (opt + 1, lang_mask | CL_COMMON);
355 if (opt_index == cl_options_count)
356 goto done;
358 option = &cl_options[opt_index];
360 /* Reject negative form of switches that don't take negatives as
361 unrecognized. */
362 if (!value && (option->flags & CL_REJECT_NEGATIVE))
363 goto done;
365 /* We've recognized this switch. */
366 result = 1;
368 /* Sort out any argument the switch takes. */
369 if (option->flags & CL_JOINED)
371 /* Have arg point to the original switch. This is because
372 some code, such as disable_builtin_function, expects its
373 argument to be persistent until the program exits. */
374 arg = argv[0] + cl_options[opt_index].opt_len + 1;
375 if (!value)
376 arg += strlen ("no-");
378 if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
380 if (option->flags & CL_SEPARATE)
382 arg = argv[1];
383 result = 2;
385 else
386 /* Missing argument. */
387 arg = NULL;
390 else if (option->flags & CL_SEPARATE)
392 arg = argv[1];
393 result = 2;
396 /* Now we've swallowed any potential argument, complain if this
397 is a switch for a different front end. */
398 if (!(option->flags & (lang_mask | CL_COMMON)))
400 complain_wrong_lang (argv[0], option, lang_mask);
401 goto done;
404 if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
406 if (!lang_hooks.missing_argument (opt, opt_index))
407 error ("missing argument to \"%s\"", opt);
408 goto done;
411 /* If the switch takes an integer, convert it. */
412 if (arg && (option->flags & CL_UINTEGER))
414 value = integral_argument (arg);
415 if (value == -1)
417 error ("argument to \"%s\" should be a non-negative integer",
418 option->opt_text);
419 goto done;
423 if (option->flags & lang_mask)
424 if (lang_hooks.handle_option (opt_index, arg, value) == 0)
425 result = 0;
427 if (result && (option->flags & CL_COMMON))
428 if (common_handle_option (opt_index, arg, value) == 0)
429 result = 0;
431 done:
432 if (dup)
433 free (dup);
434 return result;
437 /* Decode and handle the vector of command line options. LANG_MASK
438 contains has a single bit set representing the current
439 language. */
440 static void
441 handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
443 unsigned int n, i;
445 for (i = 1; i < argc; i += n)
447 const char *opt = argv[i];
449 /* Interpret "-" or a non-switch as a file name. */
450 if (opt[0] != '-' || opt[1] == '\0')
452 if (main_input_filename == NULL)
453 main_input_filename = opt;
454 add_input_filename (opt);
455 n = 1;
456 continue;
459 n = handle_option (argv + i, lang_mask);
461 if (!n)
463 n = 1;
464 error ("unrecognized command line option \"%s\"", opt);
469 /* Handle FILENAME from the command line. */
470 void
471 add_input_filename (const char *filename)
473 num_in_fnames++;
474 in_fnames = xrealloc (in_fnames, num_in_fnames * sizeof (in_fnames[0]));
475 in_fnames[num_in_fnames - 1] = filename;
478 /* Parse command line options and set default flag values. Do minimal
479 options processing. */
480 void
481 decode_options (unsigned int argc, const char **argv)
483 unsigned int i, lang_mask;
485 /* Perform language-specific options initialization. */
486 lang_mask = lang_hooks.init_options (argc, argv);
488 lang_hooks.initialize_diagnostics (global_dc);
490 /* Scan to see what optimization level has been specified. That will
491 determine the default value of many flags. */
492 for (i = 1; i < argc; i++)
494 if (!strcmp (argv[i], "-O"))
496 optimize = 1;
497 optimize_size = 0;
499 else if (argv[i][0] == '-' && argv[i][1] == 'O')
501 /* Handle -Os, -O2, -O3, -O69, ... */
502 const char *p = &argv[i][2];
504 if ((p[0] == 's') && (p[1] == 0))
506 optimize_size = 1;
508 /* Optimizing for size forces optimize to be 2. */
509 optimize = 2;
511 else
513 const int optimize_val = read_integral_parameter (p, p - 2, -1);
514 if (optimize_val != -1)
516 optimize = optimize_val;
517 optimize_size = 0;
523 if (!optimize)
525 flag_merge_constants = 0;
528 if (optimize >= 1)
530 flag_defer_pop = 1;
531 flag_thread_jumps = 1;
532 #ifdef DELAY_SLOTS
533 flag_delayed_branch = 1;
534 #endif
535 #ifdef CAN_DEBUG_WITHOUT_FP
536 flag_omit_frame_pointer = 1;
537 #endif
538 flag_guess_branch_prob = 1;
539 flag_cprop_registers = 1;
540 flag_loop_optimize = 1;
541 flag_if_conversion = 1;
542 flag_if_conversion2 = 1;
543 flag_tree_ccp = 1;
544 flag_tree_dce = 1;
545 flag_tree_dom = 1;
546 flag_tree_dse = 1;
547 flag_tree_pre = 1;
548 flag_tree_ter = 1;
549 flag_tree_live_range_split = 1;
550 flag_tree_sra = 1;
551 flag_tree_copyrename = 1;
553 if (!optimize_size)
555 /* Loop header copying usually increases size of the code. This used
556 not to be true, since quite often it is possible to verify that
557 the condition is satisfied in the first iteration and therefore
558 to eliminate it. Jump threading handles these cases now. */
559 flag_tree_ch = 1;
563 if (optimize >= 2)
565 flag_crossjumping = 1;
566 flag_optimize_sibling_calls = 1;
567 flag_cse_follow_jumps = 1;
568 flag_cse_skip_blocks = 1;
569 flag_gcse = 1;
570 flag_expensive_optimizations = 1;
571 flag_strength_reduce = 1;
572 flag_rerun_cse_after_loop = 1;
573 flag_rerun_loop_opt = 1;
574 flag_caller_saves = 1;
575 flag_force_mem = 1;
576 flag_peephole2 = 1;
577 #ifdef INSN_SCHEDULING
578 flag_schedule_insns = 1;
579 flag_schedule_insns_after_reload = 1;
580 #endif
581 flag_regmove = 1;
582 flag_strict_aliasing = 1;
583 flag_delete_null_pointer_checks = 1;
584 flag_reorder_blocks = 1;
585 flag_reorder_functions = 1;
586 flag_unit_at_a_time = 1;
589 if (optimize >= 3)
591 flag_inline_functions = 1;
592 flag_unswitch_loops = 1;
593 flag_gcse_after_reload = 1;
596 if (optimize < 2 || optimize_size)
598 align_loops = 1;
599 align_jumps = 1;
600 align_labels = 1;
601 align_functions = 1;
603 /* Don't reorder blocks when optimizing for size because extra
604 jump insns may be created; also barrier may create extra padding.
606 More correctly we should have a block reordering mode that tried
607 to minimize the combined size of all the jumps. This would more
608 or less automatically remove extra jumps, but would also try to
609 use more short jumps instead of long jumps. */
610 flag_reorder_blocks = 0;
611 flag_reorder_blocks_and_partition = 0;
614 if (optimize_size)
616 /* Inlining of very small functions usually reduces total size. */
617 set_param_value ("max-inline-insns-single", 5);
618 set_param_value ("max-inline-insns-auto", 5);
619 set_param_value ("max-inline-insns-rtl", 10);
620 flag_inline_functions = 1;
623 /* Initialize whether `char' is signed. */
624 flag_signed_char = DEFAULT_SIGNED_CHAR;
625 /* Set this to a special "uninitialized" value. The actual default is set
626 after target options have been processed. */
627 flag_short_enums = 2;
629 /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
630 modify it. */
631 target_flags = 0;
632 set_target_switch ("");
634 /* Unwind tables are always present in an ABI-conformant IA-64
635 object file, so the default should be ON. */
636 #ifdef IA64_UNWIND_INFO
637 flag_unwind_tables = IA64_UNWIND_INFO;
638 #endif
640 #ifdef OPTIMIZATION_OPTIONS
641 /* Allow default optimizations to be specified on a per-machine basis. */
642 OPTIMIZATION_OPTIONS (optimize, optimize_size);
643 #endif
645 handle_options (argc, argv, lang_mask);
647 if (flag_pie)
648 flag_pic = flag_pie;
649 if (flag_pic && !flag_pie)
650 flag_shlib = 1;
652 if (flag_no_inline == 2)
653 flag_no_inline = 0;
654 else
655 flag_really_no_inline = flag_no_inline;
657 /* Set flag_no_inline before the post_options () hook. The C front
658 ends use it to determine tree inlining defaults. FIXME: such
659 code should be lang-independent when all front ends use tree
660 inlining, in which case it, and this condition, should be moved
661 to the top of process_options() instead. */
662 if (optimize == 0)
664 /* Inlining does not work if not optimizing,
665 so force it not to be done. */
666 flag_no_inline = 1;
667 warn_inline = 0;
669 /* The c_decode_option function and decode_option hook set
670 this to `2' if -Wall is used, so we can avoid giving out
671 lots of errors for people who don't realize what -Wall does. */
672 if (warn_uninitialized == 1)
673 warning ("-Wuninitialized is not supported without -O");
676 if (flag_really_no_inline == 2)
677 flag_really_no_inline = flag_no_inline;
679 /* The optimization to partition hot and cold basic blocks into separate
680 sections of the .o and executable files does not work (currently)
681 with exception handling. If flag_exceptions is turned on we need to
682 turn off the partitioning optimization. */
684 if (flag_exceptions && flag_reorder_blocks_and_partition)
686 warning
687 ("-freorder-blocks-and-partition does not work with exceptions");
688 flag_reorder_blocks_and_partition = 0;
689 flag_reorder_blocks = 1;
693 /* Handle target- and language-independent options. Return zero to
694 generate an "unknown option" message. */
695 static int
696 common_handle_option (size_t scode, const char *arg,
697 int value ATTRIBUTE_UNUSED)
699 enum opt_code code = (enum opt_code) scode;
701 switch (code)
703 default:
704 abort ();
706 case OPT__help:
707 print_help ();
708 exit_after_options = true;
709 break;
711 case OPT__param:
712 handle_param (arg);
713 break;
715 case OPT__target_help:
716 display_target_options ();
717 exit_after_options = true;
718 break;
720 case OPT__version:
721 print_version (stderr, "");
722 exit_after_options = true;
723 break;
725 case OPT_G:
726 g_switch_value = value;
727 g_switch_set = true;
728 break;
730 case OPT_O:
731 case OPT_Os:
732 /* Currently handled in a prescan. */
733 break;
735 case OPT_W:
736 /* For backward compatibility, -W is the same as -Wextra. */
737 set_Wextra (value);
738 break;
740 case OPT_Waggregate_return:
741 warn_aggregate_return = value;
742 break;
744 case OPT_Wcast_align:
745 warn_cast_align = value;
746 break;
748 case OPT_Wdeprecated_declarations:
749 warn_deprecated_decl = value;
750 break;
752 case OPT_Wdisabled_optimization:
753 warn_disabled_optimization = value;
754 break;
756 case OPT_Werror:
757 warnings_are_errors = value;
758 break;
760 case OPT_Wextra:
761 set_Wextra (value);
762 break;
764 case OPT_Wfatal_errors:
765 flag_fatal_errors = value;
766 break;
768 case OPT_Winline:
769 warn_inline = value;
770 break;
772 case OPT_Wlarger_than_:
773 larger_than_size = value;
774 warn_larger_than = value != -1;
775 break;
777 case OPT_Wmissing_noreturn:
778 warn_missing_noreturn = value;
779 break;
781 case OPT_Wpacked:
782 warn_packed = value;
783 break;
785 case OPT_Wpadded:
786 warn_padded = value;
787 break;
789 case OPT_Wshadow:
790 warn_shadow = value;
791 break;
793 case OPT_Wstrict_aliasing:
794 case OPT_Wstrict_aliasing_:
795 warn_strict_aliasing = value;
796 break;
798 case OPT_Wswitch:
799 warn_switch = value;
800 break;
802 case OPT_Wswitch_default:
803 warn_switch_default = value;
804 break;
806 case OPT_Wswitch_enum:
807 warn_switch_enum = value;
808 break;
810 case OPT_Wsystem_headers:
811 warn_system_headers = value;
812 break;
814 case OPT_Wuninitialized:
815 warn_uninitialized = value;
816 break;
818 case OPT_Wunreachable_code:
819 warn_notreached = value;
820 break;
822 case OPT_Wunused:
823 set_Wunused (value);
824 break;
826 case OPT_Wunused_function:
827 warn_unused_function = value;
828 break;
830 case OPT_Wunused_label:
831 warn_unused_label = value;
832 break;
834 case OPT_Wunused_parameter:
835 warn_unused_parameter = value;
836 break;
838 case OPT_Wunused_value:
839 warn_unused_value = value;
840 break;
842 case OPT_Wunused_variable:
843 warn_unused_variable = value;
844 break;
846 case OPT_aux_info:
847 case OPT_aux_info_:
848 aux_info_file_name = arg;
849 flag_gen_aux_info = 1;
850 break;
852 case OPT_auxbase:
853 aux_base_name = arg;
854 break;
856 case OPT_auxbase_strip:
858 char *tmp = xstrdup (arg);
859 strip_off_ending (tmp, strlen (tmp));
860 if (tmp[0])
861 aux_base_name = tmp;
863 break;
865 case OPT_d:
866 decode_d_option (arg);
867 break;
869 case OPT_dumpbase:
870 dump_base_name = arg;
871 break;
873 case OPT_fPIC:
874 flag_pic = value + value;
875 break;
877 case OPT_fPIE:
878 flag_pie = value + value;
879 break;
881 case OPT_fabi_version_:
882 flag_abi_version = value;
883 break;
885 case OPT_falign_functions:
886 align_functions = !value;
887 break;
889 case OPT_falign_functions_:
890 align_functions = value;
891 break;
893 case OPT_falign_jumps:
894 align_jumps = !value;
895 break;
897 case OPT_falign_jumps_:
898 align_jumps = value;
899 break;
901 case OPT_falign_labels:
902 align_labels = !value;
903 break;
905 case OPT_falign_labels_:
906 align_labels = value;
907 break;
909 case OPT_falign_loops:
910 align_loops = !value;
911 break;
913 case OPT_falign_loops_:
914 align_loops = value;
915 break;
917 case OPT_fargument_alias:
918 flag_argument_noalias = !value;
919 break;
921 case OPT_fargument_noalias:
922 flag_argument_noalias = value;
923 break;
925 case OPT_fargument_noalias_global:
926 flag_argument_noalias = value + value;
927 break;
929 case OPT_fasynchronous_unwind_tables:
930 flag_asynchronous_unwind_tables = value;
931 break;
933 case OPT_fbounds_check:
934 flag_bounds_check = value;
935 break;
937 case OPT_fbranch_count_reg:
938 flag_branch_on_count_reg = value;
939 break;
941 case OPT_fbranch_probabilities:
942 flag_branch_probabilities_set = true;
943 flag_branch_probabilities = value;
944 break;
946 case OPT_fbranch_target_load_optimize:
947 flag_branch_target_load_optimize = value;
948 break;
950 case OPT_fbranch_target_load_optimize2:
951 flag_branch_target_load_optimize2 = value;
952 break;
954 case OPT_fbtr_bb_exclusive:
955 flag_btr_bb_exclusive = value;
956 break;
958 case OPT_fcall_used_:
959 fix_register (arg, 0, 1);
960 break;
962 case OPT_fcall_saved_:
963 fix_register (arg, 0, 0);
964 break;
966 case OPT_fcaller_saves:
967 flag_caller_saves = value;
968 break;
970 case OPT_fcommon:
971 flag_no_common = !value;
972 break;
974 case OPT_fcprop_registers:
975 flag_cprop_registers = value;
976 break;
978 case OPT_fcrossjumping:
979 flag_crossjumping = value;
980 break;
982 case OPT_fcse_follow_jumps:
983 flag_cse_follow_jumps = value;
984 break;
986 case OPT_fcse_skip_blocks:
987 flag_cse_skip_blocks = value;
988 break;
990 case OPT_fdata_sections:
991 flag_data_sections = value;
992 break;
994 case OPT_fdefer_pop:
995 flag_defer_pop = value;
996 break;
998 case OPT_fdelayed_branch:
999 flag_delayed_branch = value;
1000 break;
1002 case OPT_fdelete_null_pointer_checks:
1003 flag_delete_null_pointer_checks = value;
1004 break;
1006 case OPT_fdiagnostics_show_location_:
1007 if (!strcmp (arg, "once"))
1008 diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
1009 else if (!strcmp (arg, "every-line"))
1010 diagnostic_prefixing_rule (global_dc)
1011 = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
1012 else
1013 return 0;
1014 break;
1016 case OPT_fdump_:
1017 if (!dump_switch_p (arg))
1018 return 0;
1019 break;
1021 case OPT_fdump_unnumbered:
1022 flag_dump_unnumbered = value;
1023 break;
1025 case OPT_feliminate_dwarf2_dups:
1026 flag_eliminate_dwarf2_dups = value;
1027 break;
1029 case OPT_feliminate_unused_debug_types:
1030 flag_eliminate_unused_debug_types = value;
1031 break;
1033 case OPT_feliminate_unused_debug_symbols:
1034 flag_debug_only_used_symbols = value;
1035 break;
1037 case OPT_fexceptions:
1038 flag_exceptions = value;
1039 break;
1041 case OPT_fexpensive_optimizations:
1042 flag_expensive_optimizations = value;
1043 break;
1045 case OPT_ffast_math:
1046 set_fast_math_flags (value);
1047 break;
1049 case OPT_ffinite_math_only:
1050 flag_finite_math_only = value;
1051 break;
1053 case OPT_ffixed_:
1054 fix_register (arg, 1, 1);
1055 break;
1057 case OPT_ffunction_cse:
1058 flag_no_function_cse = !value;
1059 break;
1061 case OPT_ffloat_store:
1062 flag_float_store = value;
1063 break;
1065 case OPT_fforce_addr:
1066 flag_force_addr = value;
1067 break;
1069 case OPT_fforce_mem:
1070 flag_force_mem = value;
1071 break;
1073 case OPT_ffunction_sections:
1074 flag_function_sections = value;
1075 break;
1077 case OPT_fgcse:
1078 flag_gcse = value;
1079 break;
1081 case OPT_fgcse_lm:
1082 flag_gcse_lm = value;
1083 break;
1085 case OPT_fgcse_sm:
1086 flag_gcse_sm = value;
1087 break;
1089 case OPT_fgcse_after_reload:
1090 flag_gcse_after_reload = value;
1091 break;
1093 case OPT_fgcse_las:
1094 flag_gcse_las = value;
1095 break;
1097 case OPT_fguess_branch_probability:
1098 flag_guess_branch_prob = value;
1099 break;
1101 case OPT_fident:
1102 flag_no_ident = !value;
1103 break;
1105 case OPT_fif_conversion:
1106 flag_if_conversion = value;
1107 break;
1109 case OPT_fif_conversion2:
1110 flag_if_conversion2 = value;
1111 break;
1113 case OPT_finhibit_size_directive:
1114 flag_inhibit_size_directive = value;
1115 break;
1117 case OPT_finline:
1118 flag_no_inline = !value;
1119 break;
1121 case OPT_finline_functions:
1122 flag_inline_functions = value;
1123 break;
1125 case OPT_finline_limit_:
1126 case OPT_finline_limit_eq:
1127 set_param_value ("max-inline-insns-single", value / 2);
1128 set_param_value ("max-inline-insns-auto", value / 2);
1129 set_param_value ("max-inline-insns-rtl", value);
1130 break;
1132 case OPT_finstrument_functions:
1133 flag_instrument_function_entry_exit = value;
1134 break;
1136 case OPT_fkeep_inline_functions:
1137 flag_keep_inline_functions =value;
1138 break;
1140 case OPT_fkeep_static_consts:
1141 flag_keep_static_consts = value;
1142 break;
1144 case OPT_fleading_underscore:
1145 flag_leading_underscore = value;
1146 break;
1148 case OPT_floop_optimize:
1149 flag_loop_optimize = value;
1150 break;
1152 case OPT_fmath_errno:
1153 flag_errno_math = value;
1154 break;
1156 case OPT_fmem_report:
1157 mem_report = value;
1158 break;
1160 case OPT_fmerge_all_constants:
1161 flag_merge_constants = value + value;
1162 break;
1164 case OPT_fmerge_constants:
1165 flag_merge_constants = value;
1166 break;
1168 case OPT_fmessage_length_:
1169 pp_set_line_maximum_length (global_dc->printer, value);
1170 break;
1172 case OPT_fmove_all_movables:
1173 flag_move_all_movables = value;
1174 break;
1176 case OPT_fmudflap:
1177 flag_mudflap = value;
1178 break;
1180 case OPT_fmudflapth:
1181 flag_mudflap = value;
1182 flag_mudflap_threads = value;
1183 break;
1185 case OPT_fmudflapir:
1186 flag_mudflap_ignore_reads = value;
1187 break;
1189 case OPT_fnew_ra:
1190 flag_new_regalloc = value;
1191 break;
1193 case OPT_fnon_call_exceptions:
1194 flag_non_call_exceptions = value;
1195 break;
1197 case OPT_fold_unroll_all_loops:
1198 flag_old_unroll_all_loops = value;
1199 break;
1201 case OPT_fold_unroll_loops:
1202 flag_old_unroll_loops = value;
1203 break;
1205 case OPT_fomit_frame_pointer:
1206 flag_omit_frame_pointer = value;
1207 break;
1209 case OPT_foptimize_register_move:
1210 flag_regmove = value;
1211 break;
1213 case OPT_foptimize_sibling_calls:
1214 flag_optimize_sibling_calls = value;
1215 break;
1217 case OPT_fpack_struct:
1218 flag_pack_struct = value;
1219 break;
1221 case OPT_fpeel_loops:
1222 flag_peel_loops_set = true;
1223 flag_peel_loops = value;
1224 break;
1226 case OPT_fpcc_struct_return:
1227 flag_pcc_struct_return = value;
1228 break;
1230 case OPT_fpeephole:
1231 flag_no_peephole = !value;
1232 break;
1234 case OPT_fpeephole2:
1235 flag_peephole2 = value;
1236 break;
1238 case OPT_fpic:
1239 flag_pic = value;
1240 break;
1242 case OPT_fpie:
1243 flag_pie = value;
1244 break;
1246 case OPT_fprefetch_loop_arrays:
1247 flag_prefetch_loop_arrays = value;
1248 break;
1250 case OPT_fprofile:
1251 profile_flag = value;
1252 break;
1254 case OPT_fprofile_arcs:
1255 profile_arc_flag_set = true;
1256 profile_arc_flag = value;
1257 break;
1259 case OPT_fprofile_use:
1260 if (!flag_branch_probabilities_set)
1261 flag_branch_probabilities = value;
1262 if (!flag_profile_values_set)
1263 flag_profile_values = value;
1264 if (!flag_unroll_loops_set)
1265 flag_unroll_loops = value;
1266 if (!flag_peel_loops_set)
1267 flag_peel_loops = value;
1268 if (!flag_tracer_set)
1269 flag_tracer = value;
1270 if (!flag_value_profile_transformations_set)
1271 flag_value_profile_transformations = value;
1272 break;
1274 case OPT_fprofile_generate:
1275 if (!profile_arc_flag_set)
1276 profile_arc_flag = value;
1277 if (!flag_profile_values_set)
1278 flag_profile_values = value;
1279 if (!flag_value_profile_transformations_set)
1280 flag_value_profile_transformations = value;
1281 break;
1283 case OPT_fprofile_values:
1284 flag_profile_values_set = true;
1285 flag_profile_values = value;
1286 break;
1288 case OPT_fvpt:
1289 flag_value_profile_transformations_set = value;
1290 flag_value_profile_transformations = value;
1291 break;
1293 case OPT_frandom_seed:
1294 /* The real switch is -fno-random-seed. */
1295 if (value)
1296 return 0;
1297 flag_random_seed = NULL;
1298 break;
1300 case OPT_frandom_seed_:
1301 flag_random_seed = arg;
1302 break;
1304 case OPT_freduce_all_givs:
1305 flag_reduce_all_givs = value;
1306 break;
1308 case OPT_freg_struct_return:
1309 flag_pcc_struct_return = !value;
1310 break;
1312 case OPT_fregmove:
1313 flag_regmove = value;
1314 break;
1316 case OPT_frename_registers:
1317 flag_rename_registers = value;
1318 break;
1320 case OPT_freorder_blocks:
1321 flag_reorder_blocks = value;
1322 break;
1324 case OPT_freorder_blocks_and_partition:
1325 flag_reorder_blocks_and_partition = value;
1326 break;
1328 case OPT_freorder_functions:
1329 flag_reorder_functions = value;
1330 break;
1332 case OPT_frerun_cse_after_loop:
1333 flag_rerun_cse_after_loop = value;
1334 break;
1336 case OPT_frerun_loop_opt:
1337 flag_rerun_loop_opt = value;
1338 break;
1340 case OPT_frounding_math:
1341 flag_rounding_math = value;
1342 break;
1344 case OPT_fsched_interblock:
1345 flag_schedule_interblock = value;
1346 break;
1348 case OPT_fsched_spec:
1349 flag_schedule_speculative = value;
1350 break;
1352 case OPT_fsched_spec_load:
1353 flag_schedule_speculative_load = value;
1354 break;
1356 case OPT_fsched_spec_load_dangerous:
1357 flag_schedule_speculative_load_dangerous = value;
1358 break;
1360 case OPT_fsched_verbose_:
1361 #ifdef INSN_SCHEDULING
1362 fix_sched_param ("verbose", arg);
1363 break;
1364 #else
1365 return 0;
1366 #endif
1368 case OPT_fsched2_use_superblocks:
1369 flag_sched2_use_superblocks = value;
1370 break;
1372 case OPT_fsched2_use_traces:
1373 flag_sched2_use_traces = value;
1374 break;
1376 case OPT_fschedule_insns:
1377 flag_schedule_insns = value;
1378 break;
1380 case OPT_fschedule_insns2:
1381 flag_schedule_insns_after_reload = value;
1382 break;
1384 case OPT_fsched_stalled_insns:
1385 flag_sched_stalled_insns = value;
1386 break;
1388 case OPT_fsched_stalled_insns_:
1389 flag_sched_stalled_insns = value;
1390 if (flag_sched_stalled_insns == 0)
1391 flag_sched_stalled_insns = -1;
1392 break;
1394 case OPT_fsched_stalled_insns_dep:
1395 flag_sched_stalled_insns_dep = 1;
1396 break;
1398 case OPT_fsched_stalled_insns_dep_:
1399 flag_sched_stalled_insns_dep = value;
1400 break;
1401 case OPT_fmodulo_sched:
1402 flag_modulo_sched = 1;
1403 break;
1404 case OPT_fshared_data:
1405 flag_shared_data = value;
1406 break;
1408 case OPT_fsignaling_nans:
1409 flag_signaling_nans = value;
1410 break;
1412 case OPT_fsingle_precision_constant:
1413 flag_single_precision_constant = value;
1414 break;
1416 case OPT_fstack_check:
1417 flag_stack_check = value;
1418 break;
1420 case OPT_fstack_limit:
1421 /* The real switch is -fno-stack-limit. */
1422 if (value)
1423 return 0;
1424 stack_limit_rtx = NULL_RTX;
1425 break;
1427 case OPT_fstack_limit_register_:
1429 int reg = decode_reg_name (arg);
1430 if (reg < 0)
1431 error ("unrecognized register name \"%s\"", arg);
1432 else
1433 stack_limit_rtx = gen_rtx_REG (Pmode, reg);
1435 break;
1437 case OPT_fstack_limit_symbol_:
1438 stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
1439 break;
1441 case OPT_fstrength_reduce:
1442 flag_strength_reduce = value;
1443 break;
1445 case OPT_fstrict_aliasing:
1446 flag_strict_aliasing = value;
1447 break;
1449 case OPT_fsyntax_only:
1450 flag_syntax_only = value;
1451 break;
1453 case OPT_ftest_coverage:
1454 flag_test_coverage = value;
1455 break;
1457 case OPT_fthread_jumps:
1458 flag_thread_jumps = value;
1459 break;
1461 case OPT_ftime_report:
1462 time_report = value;
1463 break;
1465 case OPT_ftls_model_:
1466 if (!strcmp (arg, "global-dynamic"))
1467 flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
1468 else if (!strcmp (arg, "local-dynamic"))
1469 flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
1470 else if (!strcmp (arg, "initial-exec"))
1471 flag_tls_default = TLS_MODEL_INITIAL_EXEC;
1472 else if (!strcmp (arg, "local-exec"))
1473 flag_tls_default = TLS_MODEL_LOCAL_EXEC;
1474 else
1475 warning ("unknown tls-model \"%s\"", arg);
1476 break;
1478 case OPT_ftracer:
1479 flag_tracer_set = true;
1480 flag_tracer = value;
1481 break;
1483 case OPT_ftrapping_math:
1484 flag_trapping_math = value;
1485 break;
1487 case OPT_ftrapv:
1488 flag_trapv = value;
1489 break;
1491 case OPT_ftree_based_profiling:
1492 flag_tree_based_profiling = value;
1493 break;
1495 case OPT_ftree_ccp:
1496 flag_tree_ccp = value;
1497 break;
1499 case OPT_ftree_dce:
1500 flag_tree_dce = value;
1501 break;
1503 case OPT_ftree_combine_temps:
1504 flag_tree_combine_temps = value;
1505 break;
1507 case OPT_ftree_ter:
1508 flag_tree_ter = value;
1509 break;
1511 case OPT_ftree_lrs:
1512 flag_tree_live_range_split = value;
1513 break;
1515 case OPT_ftree_dominator_opts:
1516 flag_tree_dom = value;
1517 break;
1519 case OPT_ftree_copyrename:
1520 flag_tree_copyrename = value;
1521 break;
1523 case OPT_ftree_ch:
1524 flag_tree_ch = value;
1525 break;
1527 case OPT_ftree_dse:
1528 flag_tree_dse = value;
1529 break;
1531 case OPT_ftree_sra:
1532 flag_tree_sra = value;
1533 break;
1535 case OPT_ftree_points_to_:
1536 if (!strcmp (arg, "andersen"))
1537 #ifdef HAVE_BANSHEE
1538 flag_tree_points_to = PTA_ANDERSEN;
1539 #else
1540 warning ("Andersen's PTA not available - libbanshee not compiled.");
1541 #endif
1542 else if (!strcmp (arg, "none"))
1543 flag_tree_points_to = PTA_NONE;
1544 else
1546 warning ("`%s`: unknown points-to analysis algorithm", arg);
1547 return 0;
1549 break;
1551 case OPT_ftree_pre:
1552 flag_tree_pre = value;
1553 break;
1555 case OPT_funit_at_a_time:
1556 flag_unit_at_a_time = value;
1557 break;
1559 case OPT_funroll_all_loops:
1560 flag_unroll_all_loops = value;
1561 break;
1563 case OPT_funroll_loops:
1564 flag_unroll_loops_set = true;
1565 flag_unroll_loops = value;
1566 break;
1568 case OPT_funsafe_math_optimizations:
1569 flag_unsafe_math_optimizations = value;
1570 break;
1572 case OPT_funswitch_loops:
1573 flag_unswitch_loops = value;
1574 break;
1576 case OPT_funwind_tables:
1577 flag_unwind_tables = value;
1578 break;
1580 case OPT_fvar_tracking:
1581 flag_var_tracking = value;
1582 break;
1584 case OPT_fverbose_asm:
1585 flag_verbose_asm = value;
1586 break;
1588 case OPT_fweb:
1589 flag_web = value;
1590 break;
1592 case OPT_fwrapv:
1593 flag_wrapv = value;
1594 break;
1596 case OPT_fzero_initialized_in_bss:
1597 flag_zero_initialized_in_bss = value;
1598 break;
1600 case OPT_g:
1601 set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg);
1602 break;
1604 case OPT_gcoff:
1605 set_debug_level (SDB_DEBUG, false, arg);
1606 break;
1608 case OPT_gdwarf_2:
1609 set_debug_level (DWARF2_DEBUG, false, arg);
1610 break;
1612 case OPT_ggdb:
1613 set_debug_level (NO_DEBUG, 2, arg);
1614 break;
1616 case OPT_gstabs:
1617 case OPT_gstabs_:
1618 set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg);
1619 break;
1621 case OPT_gvms:
1622 set_debug_level (VMS_DEBUG, false, arg);
1623 break;
1625 case OPT_gxcoff:
1626 case OPT_gxcoff_:
1627 set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg);
1628 break;
1630 case OPT_m:
1631 set_target_switch (arg);
1632 break;
1634 case OPT_o:
1635 asm_file_name = arg;
1636 break;
1638 case OPT_p:
1639 profile_flag = 1;
1640 break;
1642 case OPT_pedantic:
1643 pedantic = 1;
1644 break;
1646 case OPT_pedantic_errors:
1647 flag_pedantic_errors = pedantic = 1;
1648 break;
1650 case OPT_quiet:
1651 quiet_flag = 1;
1652 break;
1654 case OPT_version:
1655 version_flag = 1;
1656 break;
1658 case OPT_w:
1659 inhibit_warnings = true;
1660 break;
1663 return 1;
1666 /* Handle --param NAME=VALUE. */
1667 static void
1668 handle_param (const char *carg)
1670 char *equal, *arg;
1671 int value;
1673 arg = xstrdup (carg);
1674 equal = strchr (arg, '=');
1675 if (!equal)
1676 error ("%s: --param arguments should be of the form NAME=VALUE", arg);
1677 else
1679 value = integral_argument (equal + 1);
1680 if (value == -1)
1681 error ("invalid --param value `%s'", equal + 1);
1682 else
1684 *equal = '\0';
1685 set_param_value (arg, value);
1689 free (arg);
1692 /* Handle -W and -Wextra. */
1693 static void
1694 set_Wextra (int setting)
1696 extra_warnings = setting;
1697 warn_unused_value = setting;
1698 warn_unused_parameter = (setting && maybe_warn_unused_parameter);
1700 /* We save the value of warn_uninitialized, since if they put
1701 -Wuninitialized on the command line, we need to generate a
1702 warning about not using it without also specifying -O. */
1703 if (setting == 0)
1704 warn_uninitialized = 0;
1705 else if (warn_uninitialized != 1)
1706 warn_uninitialized = 2;
1709 /* Initialize unused warning flags. */
1710 void
1711 set_Wunused (int setting)
1713 warn_unused_function = setting;
1714 warn_unused_label = setting;
1715 /* Unused function parameter warnings are reported when either
1716 ``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
1717 Thus, if -Wextra has already been seen, set warn_unused_parameter;
1718 otherwise set maybe_warn_extra_parameter, which will be picked up
1719 by set_Wextra. */
1720 maybe_warn_unused_parameter = setting;
1721 warn_unused_parameter = (setting && extra_warnings);
1722 warn_unused_variable = setting;
1723 warn_unused_value = setting;
1726 /* The following routines are useful in setting all the flags that
1727 -ffast-math and -fno-fast-math imply. */
1728 void
1729 set_fast_math_flags (int set)
1731 flag_trapping_math = !set;
1732 flag_unsafe_math_optimizations = set;
1733 flag_finite_math_only = set;
1734 flag_errno_math = !set;
1735 if (set)
1737 flag_signaling_nans = 0;
1738 flag_rounding_math = 0;
1742 /* Return true iff flags are set as if -ffast-math. */
1743 bool
1744 fast_math_flags_set_p (void)
1746 return (!flag_trapping_math
1747 && flag_unsafe_math_optimizations
1748 && flag_finite_math_only
1749 && !flag_errno_math);
1752 /* Handle a debug output -g switch. EXTENDED is true or false to support
1753 extended output (2 is special and means "-ggdb" was given). */
1754 static void
1755 set_debug_level (enum debug_info_type type, int extended, const char *arg)
1757 static bool type_explicit;
1759 use_gnu_debug_info_extensions = extended;
1761 if (type == NO_DEBUG)
1763 if (write_symbols == NO_DEBUG)
1765 write_symbols = PREFERRED_DEBUGGING_TYPE;
1767 if (extended == 2)
1769 #ifdef DWARF2_DEBUGGING_INFO
1770 write_symbols = DWARF2_DEBUG;
1771 #elif defined DBX_DEBUGGING_INFO
1772 write_symbols = DBX_DEBUG;
1773 #endif
1776 if (write_symbols == NO_DEBUG)
1777 warning ("target system does not support debug output");
1780 else
1782 /* Does it conflict with an already selected type? */
1783 if (type_explicit && write_symbols != NO_DEBUG && type != write_symbols)
1784 error ("debug format \"%s\" conflicts with prior selection",
1785 debug_type_names[type]);
1786 write_symbols = type;
1787 type_explicit = true;
1790 /* A debug flag without a level defaults to level 2. */
1791 if (*arg == '\0')
1793 if (!debug_info_level)
1794 debug_info_level = 2;
1796 else
1798 debug_info_level = integral_argument (arg);
1799 if (debug_info_level == (unsigned int) -1)
1800 error ("unrecognised debug output level \"%s\"", arg);
1801 else if (debug_info_level > 3)
1802 error ("debug output level %s is too high", arg);
1806 /* Output --help text. */
1807 static void
1808 print_help (void)
1810 size_t i;
1811 const char *p;
1813 GET_ENVIRONMENT (p, "COLUMNS");
1814 if (p)
1816 int value = atoi (p);
1817 if (value > 0)
1818 columns = value;
1821 puts (_("The following options are language-independent:\n"));
1823 print_filtered_help (CL_COMMON);
1824 print_param_help ();
1826 for (i = 0; lang_names[i]; i++)
1828 printf (_("The %s front end recognizes the following options:\n\n"),
1829 lang_names[i]);
1830 print_filtered_help (1U << i);
1833 display_target_options ();
1836 /* Print the help for --param. */
1837 static void
1838 print_param_help (void)
1840 size_t i;
1842 puts (_("The --param option recognizes the following as parameters:\n"));
1844 for (i = 0; i < LAST_PARAM; i++)
1846 const char *help = compiler_params[i].help;
1847 const char *param = compiler_params[i].option;
1849 if (help == NULL || *help == '\0')
1850 help = undocumented_msg;
1852 /* Get the translation. */
1853 help = _(help);
1855 wrap_help (help, param, strlen (param));
1858 putchar ('\n');
1861 /* Print help for a specific front-end, etc. */
1862 static void
1863 print_filtered_help (unsigned int flag)
1865 unsigned int i, len, filter, indent = 0;
1866 bool duplicates = false;
1867 const char *help, *opt, *tab;
1868 static char *printed;
1870 if (flag == CL_COMMON)
1872 filter = flag;
1873 if (!printed)
1874 printed = xmalloc (cl_options_count);
1875 memset (printed, 0, cl_options_count);
1877 else
1879 /* Don't print COMMON options twice. */
1880 filter = flag | CL_COMMON;
1882 for (i = 0; i < cl_options_count; i++)
1884 if ((cl_options[i].flags & filter) != flag)
1885 continue;
1887 /* Skip help for internal switches. */
1888 if (cl_options[i].flags & CL_UNDOCUMENTED)
1889 continue;
1891 /* Skip switches that have already been printed, mark them to be
1892 listed later. */
1893 if (printed[i])
1895 duplicates = true;
1896 indent = print_switch (cl_options[i].opt_text, indent);
1900 if (duplicates)
1902 putchar ('\n');
1903 putchar ('\n');
1907 for (i = 0; i < cl_options_count; i++)
1909 if ((cl_options[i].flags & filter) != flag)
1910 continue;
1912 /* Skip help for internal switches. */
1913 if (cl_options[i].flags & CL_UNDOCUMENTED)
1914 continue;
1916 /* Skip switches that have already been printed. */
1917 if (printed[i])
1918 continue;
1920 printed[i] = true;
1922 help = cl_options[i].help;
1923 if (!help)
1924 help = undocumented_msg;
1926 /* Get the translation. */
1927 help = _(help);
1929 tab = strchr (help, '\t');
1930 if (tab)
1932 len = tab - help;
1933 opt = help;
1934 help = tab + 1;
1936 else
1938 opt = cl_options[i].opt_text;
1939 len = strlen (opt);
1942 wrap_help (help, opt, len);
1945 putchar ('\n');
1948 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1949 word-wrapped HELP in a second column. */
1950 static unsigned int
1951 print_switch (const char *text, unsigned int indent)
1953 unsigned int len = strlen (text) + 1; /* trailing comma */
1955 if (indent)
1957 putchar (',');
1958 if (indent + len > columns)
1960 putchar ('\n');
1961 putchar (' ');
1962 indent = 1;
1965 else
1966 putchar (' ');
1968 putchar (' ');
1969 fputs (text, stdout);
1971 return indent + len + 1;
1974 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1975 word-wrapped HELP in a second column. */
1976 static void
1977 wrap_help (const char *help, const char *item, unsigned int item_width)
1979 unsigned int col_width = 27;
1980 unsigned int remaining, room, len;
1982 remaining = strlen (help);
1986 room = columns - 3 - MAX (col_width, item_width);
1987 if (room > columns)
1988 room = 0;
1989 len = remaining;
1991 if (room < len)
1993 unsigned int i;
1995 for (i = 0; help[i]; i++)
1997 if (i >= room && len != remaining)
1998 break;
1999 if (help[i] == ' ')
2000 len = i;
2001 else if ((help[i] == '-' || help[i] == '/')
2002 && help[i + 1] != ' '
2003 && i > 0 && ISALPHA (help[i - 1]))
2004 len = i + 1;
2008 printf( " %-*.*s %.*s\n", col_width, item_width, item, len, help);
2009 item_width = 0;
2010 while (help[len] == ' ')
2011 len++;
2012 help += len;
2013 remaining -= len;
2015 while (remaining);