OSDN Git Service

2004-04-19 Paolo Bonzini <bonzini@gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / opts.c
1 /* Command line option handling.
2    Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
3    Contributed by Neil Booth.
4
5 This file is part of GCC.
6
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.
11
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.
16
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.  */
21
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"
41
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;
45
46 /* True if we should exit after parsing options.  */
47 bool exit_after_options;
48
49 /* If -version.  */
50 bool version_flag;
51
52 /* Print various extra warnings.  -W/-Wextra.  */
53 bool extra_warnings;
54
55 /* Don't print warning messages.  -w.  */
56 bool inhibit_warnings;
57
58 /* Treat warnings as errors.  -Werror.  */
59 bool warnings_are_errors;
60
61 /* Warn if a function returns an aggregate, since there are often
62    incompatible calling conventions for doing this.  */
63 bool warn_aggregate_return;
64
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;
69
70 /* Nonzero means warn about uses of __attribute__((deprecated))
71    declarations.  */
72 bool warn_deprecated_decl = true;
73
74 /* Warn when an optimization pass is disabled.  */
75 bool warn_disabled_optimization;
76
77 /* Nonzero means warn if inline function is too large.  */
78 bool warn_inline;
79
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;
85
86 /* Warn about functions which might be candidates for attribute noreturn.  */
87 bool warn_missing_noreturn;
88
89 /* True to warn about code which is never reached.  */
90 bool warn_notreached;
91
92 /* Warn if packed attribute on struct is unnecessary and inefficient.  */
93 bool warn_packed;
94
95 /* Warn when gcc pads a structure to an alignment boundary.  */
96 bool warn_padded;
97
98 /* True means warn about all declarations which shadow others.  */
99 bool warn_shadow;
100
101 /* Nonzero means warn about constructs which might not be
102    strict-aliasing safe.  */
103 int warn_strict_aliasing;
104
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;
108
109 /* Warn if a switch does not have a default case.  */
110 bool warn_switch_default;
111
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;
115
116 /* Don't suppress warnings from system headers.  -Wsystem-headers.  */
117 bool warn_system_headers;
118
119 /* True to warn about variables used before they are initialized.  */
120 int warn_uninitialized;
121
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;
128
129 /* Hack for cooperation between set_Wunused and set_Wextra.  */
130 static bool maybe_warn_unused_parameter;
131
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;
136
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;
140
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;
145
146 /* Columns of --help display.  */
147 static unsigned int columns = 80;
148
149 /* What to print when a switch has no documentation.  */
150 static const char undocumented_msg[] = N_("This switch lacks documentation");
151
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;
158
159 /* Input file names.  */
160 const char **in_fnames;
161 unsigned num_in_fnames;
162
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);
179
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.
183
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".
188
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).
199
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)
206 {
207   size_t mn, mx, md, opt_len;
208   size_t match_wrong_lang;
209   int comp;
210
211   mn = 0;
212   mx = cl_options_count;
213
214   /* Find mn such this lexicographical inequality holds:
215      cl_options[mn] <= input < cl_options[mn + 1].  */
216   while (mx - mn > 1)
217     {
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);
221
222       if (comp < 0)
223         mx = md;
224       else
225         mn = md;
226     }
227
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;
231
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.  */
235   do
236     {
237       const struct cl_option *opt = &cl_options[mn];
238
239       /* Is this switch a prefix of the input?  */
240       if (!strncmp (input, opt->opt_text + 1, opt->opt_len))
241         {
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;
247
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;
252         }
253
254       /* Try the next possibility.  This is cl_options_count if there
255          are no more.  */
256       mn = opt->back_chain;
257     }
258   while (mn != cl_options_count);
259
260   /* Return the best wrong match, or cl_options_count if none.  */
261   return match_wrong_lang;
262 }
263
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)
268 {
269   const char *p = arg;
270
271   while (*p && ISDIGIT (*p))
272     p++;
273
274   if (*p == '\0')
275     return atoi (arg);
276
277   return -1;
278 }
279
280 /* Return a malloced slash-separated list of languages in MASK.  */
281 static char *
282 write_langs (unsigned int mask)
283 {
284   unsigned int n = 0, len = 0;
285   const char *lang_name;
286   char *result;
287
288   for (n = 0; (lang_name = lang_names[n]) != 0; n++)
289     if (mask & (1U << n))
290       len += strlen (lang_name) + 1;
291
292   result = xmalloc (len);
293   len = 0;
294   for (n = 0; (lang_name = lang_names[n]) != 0; n++)
295     if (mask & (1U << n))
296       {
297         if (len)
298           result[len++] = '/';
299         strcpy (result + len, lang_name);
300         len += strlen (lang_name);
301       }
302
303   result[len] = 0;
304
305   return result;
306 }
307
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)
312 {
313   char *ok_langs, *bad_lang;
314
315   ok_langs = write_langs (option->flags);
316   bad_lang = write_langs (lang_mask);
317
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);
321
322   free (ok_langs);
323   free (bad_lang);
324 }
325
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)
330 {
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;
337
338   opt = argv[0];
339
340   /* Drop the "no-" from negative switches.  */
341   if ((opt[1] == 'W' || opt[1] == 'f')
342       && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
343     {
344       size_t len = strlen (opt) - 3;
345
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;
352     }
353
354   opt_index = find_opt (opt + 1, lang_mask | CL_COMMON);
355   if (opt_index == cl_options_count)
356     goto done;
357
358   option = &cl_options[opt_index];
359
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;
364
365   /* We've recognized this switch.  */
366   result = 1;
367
368   /* Sort out any argument the switch takes.  */
369   if (option->flags & CL_JOINED)
370     {
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-");
377
378       if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
379         {
380           if (option->flags & CL_SEPARATE)
381             {
382               arg = argv[1];
383               result = 2;
384             }
385           else
386             /* Missing argument.  */
387             arg = NULL;
388         }
389     }
390   else if (option->flags & CL_SEPARATE)
391     {
392       arg = argv[1];
393       result = 2;
394     }
395
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)))
399     {
400       complain_wrong_lang (argv[0], option, lang_mask);
401       goto done;
402     }
403
404   if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
405     {
406       if (!lang_hooks.missing_argument (opt, opt_index))
407         error ("missing argument to \"%s\"", opt);
408       goto done;
409     }
410
411   /* If the switch takes an integer, convert it.  */
412   if (arg && (option->flags & CL_UINTEGER))
413     {
414       value = integral_argument (arg);
415       if (value == -1)
416         {
417           error ("argument to \"%s\" should be a non-negative integer",
418                  option->opt_text);
419           goto done;
420         }
421     }
422
423   if (option->flags & lang_mask)
424     if (lang_hooks.handle_option (opt_index, arg, value) == 0)
425       result = 0;
426
427   if (result && (option->flags & CL_COMMON))
428     if (common_handle_option (opt_index, arg, value) == 0)
429       result = 0;
430
431  done:
432   if (dup)
433     free (dup);
434   return result;
435 }
436
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)
442 {
443   unsigned int n, i;
444
445   for (i = 1; i < argc; i += n)
446     {
447       const char *opt = argv[i];
448
449       /* Interpret "-" or a non-switch as a file name.  */
450       if (opt[0] != '-' || opt[1] == '\0')
451         {
452           if (main_input_filename == NULL)
453             main_input_filename = opt;
454           add_input_filename (opt);
455           n = 1;
456           continue;
457         }
458
459       n = handle_option (argv + i, lang_mask);
460
461       if (!n)
462         {
463           n = 1;
464           error ("unrecognized command line option \"%s\"", opt);
465         }
466     }
467 }
468
469 /* Handle FILENAME from the command line.  */
470 void
471 add_input_filename (const char *filename)
472 {
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;
476 }
477
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)
482 {
483   unsigned int i, lang_mask;
484
485   /* Perform language-specific options initialization.  */
486   lang_mask = lang_hooks.init_options (argc, argv);
487
488   lang_hooks.initialize_diagnostics (global_dc);
489
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++)
493     {
494       if (!strcmp (argv[i], "-O"))
495         {
496           optimize = 1;
497           optimize_size = 0;
498         }
499       else if (argv[i][0] == '-' && argv[i][1] == 'O')
500         {
501           /* Handle -Os, -O2, -O3, -O69, ...  */
502           const char *p = &argv[i][2];
503
504           if ((p[0] == 's') && (p[1] == 0))
505             {
506               optimize_size = 1;
507
508               /* Optimizing for size forces optimize to be 2.  */
509               optimize = 2;
510             }
511           else
512             {
513               const int optimize_val = read_integral_parameter (p, p - 2, -1);
514               if (optimize_val != -1)
515                 {
516                   optimize = optimize_val;
517                   optimize_size = 0;
518                 }
519             }
520         }
521     }
522
523   if (!optimize)
524     {
525       flag_merge_constants = 0;
526     }
527
528   if (optimize >= 1)
529     {
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     }
544
545   if (optimize >= 2)
546     {
547       flag_crossjumping = 1;
548       flag_optimize_sibling_calls = 1;
549       flag_cse_follow_jumps = 1;
550       flag_cse_skip_blocks = 1;
551       flag_gcse = 1;
552       flag_expensive_optimizations = 1;
553       flag_strength_reduce = 1;
554       flag_rerun_cse_after_loop = 1;
555       flag_rerun_loop_opt = 1;
556       flag_caller_saves = 1;
557       flag_force_mem = 1;
558       flag_peephole2 = 1;
559 #ifdef INSN_SCHEDULING
560       flag_schedule_insns = 1;
561       flag_schedule_insns_after_reload = 1;
562 #endif
563       flag_regmove = 1;
564       flag_strict_aliasing = 1;
565       flag_delete_null_pointer_checks = 1;
566       flag_reorder_blocks = 1;
567       flag_reorder_functions = 1;
568       flag_unit_at_a_time = 1;
569     }
570
571   if (optimize >= 3)
572     {
573       flag_inline_functions = 1;
574       flag_unswitch_loops = 1;
575       flag_gcse_after_reload = 1;
576     }
577
578   if (optimize < 2 || optimize_size)
579     {
580       align_loops = 1;
581       align_jumps = 1;
582       align_labels = 1;
583       align_functions = 1;
584
585       /* Don't reorder blocks when optimizing for size because extra
586          jump insns may be created; also barrier may create extra padding.
587
588          More correctly we should have a block reordering mode that tried
589          to minimize the combined size of all the jumps.  This would more
590          or less automatically remove extra jumps, but would also try to
591          use more short jumps instead of long jumps.  */
592       flag_reorder_blocks = 0;
593       flag_reorder_blocks_and_partition = 0;
594     }
595
596   if (optimize_size)
597     {
598       /* Inlining of very small functions usually reduces total size.  */
599       set_param_value ("max-inline-insns-single", 5);
600       set_param_value ("max-inline-insns-auto", 5);
601       set_param_value ("max-inline-insns-rtl", 10);
602       flag_inline_functions = 1;
603     }
604
605   /* Initialize whether `char' is signed.  */
606   flag_signed_char = DEFAULT_SIGNED_CHAR;
607   /* Initialize how much space enums occupy, by default.  */
608   flag_short_enums = targetm.default_short_enums ();
609
610   /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
611      modify it.  */
612   target_flags = 0;
613   set_target_switch ("");
614
615   /* Unwind tables are always present in an ABI-conformant IA-64
616      object file, so the default should be ON.  */
617 #ifdef IA64_UNWIND_INFO
618   flag_unwind_tables = IA64_UNWIND_INFO;
619 #endif
620
621 #ifdef OPTIMIZATION_OPTIONS
622   /* Allow default optimizations to be specified on a per-machine basis.  */
623   OPTIMIZATION_OPTIONS (optimize, optimize_size);
624 #endif
625
626   handle_options (argc, argv, lang_mask);
627
628   if (flag_pie)
629     flag_pic = flag_pie;
630   if (flag_pic && !flag_pie)
631     flag_shlib = 1;
632
633   if (flag_no_inline == 2)
634     flag_no_inline = 0;
635   else
636     flag_really_no_inline = flag_no_inline;
637
638   /* Set flag_no_inline before the post_options () hook.  The C front
639      ends use it to determine tree inlining defaults.  FIXME: such
640      code should be lang-independent when all front ends use tree
641      inlining, in which case it, and this condition, should be moved
642      to the top of process_options() instead.  */
643   if (optimize == 0)
644     {
645       /* Inlining does not work if not optimizing,
646          so force it not to be done.  */
647       flag_no_inline = 1;
648       warn_inline = 0;
649
650       /* The c_decode_option function and decode_option hook set
651          this to `2' if -Wall is used, so we can avoid giving out
652          lots of errors for people who don't realize what -Wall does.  */
653       if (warn_uninitialized == 1)
654         warning ("-Wuninitialized is not supported without -O");
655     }
656
657   if (flag_really_no_inline == 2)
658     flag_really_no_inline = flag_no_inline;
659
660   /* The optimization to partition hot and cold basic blocks into separate
661      sections of the .o and executable files does not work (currently)
662      with exception handling.  If flag_exceptions is turned on we need to
663      turn off the partitioning optimization.  */
664
665   if (flag_exceptions && flag_reorder_blocks_and_partition)
666     {
667       warning 
668             ("-freorder-blocks-and-partition does not work with exceptions");
669       flag_reorder_blocks_and_partition = 0;
670       flag_reorder_blocks = 1;
671     }
672 }
673
674 /* Handle target- and language-independent options.  Return zero to
675    generate an "unknown option" message.  */
676 static int
677 common_handle_option (size_t scode, const char *arg,
678                       int value ATTRIBUTE_UNUSED)
679 {
680   enum opt_code code = (enum opt_code) scode;
681
682   switch (code)
683     {
684     default:
685       abort ();
686
687     case OPT__help:
688       print_help ();
689       exit_after_options = true;
690       break;
691
692     case OPT__param:
693       handle_param (arg);
694       break;
695
696     case OPT__target_help:
697       display_target_options ();
698       exit_after_options = true;
699       break;
700
701     case OPT__version:
702       print_version (stderr, "");
703       exit_after_options = true;
704       break;
705
706     case OPT_G:
707       g_switch_value = value;
708       g_switch_set = true;
709       break;
710
711     case OPT_O:
712     case OPT_Os:
713       /* Currently handled in a prescan.  */
714       break;
715
716     case OPT_W:
717       /* For backward compatibility, -W is the same as -Wextra.  */
718       set_Wextra (value);
719       break;
720
721     case OPT_Waggregate_return:
722       warn_aggregate_return = value;
723       break;
724
725     case OPT_Wcast_align:
726       warn_cast_align = value;
727       break;
728
729     case OPT_Wdeprecated_declarations:
730       warn_deprecated_decl = value;
731       break;
732
733     case OPT_Wdisabled_optimization:
734       warn_disabled_optimization = value;
735       break;
736
737     case OPT_Werror:
738       warnings_are_errors = value;
739       break;
740
741     case OPT_Wextra:
742       set_Wextra (value);
743       break;
744
745     case OPT_Winline:
746       warn_inline = value;
747       break;
748
749     case OPT_Wlarger_than_:
750       larger_than_size = value;
751       warn_larger_than = value != -1;
752       break;
753
754     case OPT_Wmissing_noreturn:
755       warn_missing_noreturn = value;
756       break;
757
758     case OPT_Wpacked:
759       warn_packed = value;
760       break;
761
762     case OPT_Wpadded:
763       warn_padded = value;
764       break;
765
766     case OPT_Wshadow:
767       warn_shadow = value;
768       break;
769
770     case OPT_Wstrict_aliasing:
771     case OPT_Wstrict_aliasing_:
772       warn_strict_aliasing = value;
773       break;
774
775     case OPT_Wswitch:
776       warn_switch = value;
777       break;
778
779     case OPT_Wswitch_default:
780       warn_switch_default = value;
781       break;
782
783     case OPT_Wswitch_enum:
784       warn_switch_enum = value;
785       break;
786
787     case OPT_Wsystem_headers:
788       warn_system_headers = value;
789       break;
790
791     case OPT_Wuninitialized:
792       warn_uninitialized = value;
793       break;
794
795     case OPT_Wunreachable_code:
796       warn_notreached = value;
797       break;
798
799     case OPT_Wunused:
800       set_Wunused (value);
801       break;
802
803     case OPT_Wunused_function:
804       warn_unused_function = value;
805       break;
806
807     case OPT_Wunused_label:
808       warn_unused_label = value;
809       break;
810
811     case OPT_Wunused_parameter:
812       warn_unused_parameter = value;
813       break;
814
815     case OPT_Wunused_value:
816       warn_unused_value = value;
817       break;
818
819     case OPT_Wunused_variable:
820       warn_unused_variable = value;
821       break;
822
823     case OPT_aux_info:
824     case OPT_aux_info_:
825       aux_info_file_name = arg;
826       flag_gen_aux_info = 1;
827       break;
828
829     case OPT_auxbase:
830       aux_base_name = arg;
831       break;
832
833     case OPT_auxbase_strip:
834       {
835         char *tmp = xstrdup (arg);
836         strip_off_ending (tmp, strlen (tmp));
837         if (tmp[0])
838           aux_base_name = tmp;
839       }
840       break;
841
842     case OPT_d:
843       decode_d_option (arg);
844       break;
845
846     case OPT_dumpbase:
847       dump_base_name = arg;
848       break;
849
850     case OPT_fPIC:
851       flag_pic = value + value;
852       break;
853
854     case OPT_fPIE:
855       flag_pie = value + value;
856       break;
857
858     case OPT_fabi_version_:
859       flag_abi_version = value;
860       break;
861
862     case OPT_falign_functions:
863       align_functions = !value;
864       break;
865
866     case OPT_falign_functions_:
867       align_functions = value;
868       break;
869
870     case OPT_falign_jumps:
871       align_jumps = !value;
872       break;
873
874     case OPT_falign_jumps_:
875       align_jumps = value;
876       break;
877
878     case OPT_falign_labels:
879       align_labels = !value;
880       break;
881
882     case OPT_falign_labels_:
883       align_labels = value;
884       break;
885
886     case OPT_falign_loops:
887       align_loops = !value;
888       break;
889
890     case OPT_falign_loops_:
891       align_loops = value;
892       break;
893
894     case OPT_fargument_alias:
895       flag_argument_noalias = !value;
896       break;
897
898     case OPT_fargument_noalias:
899       flag_argument_noalias = value;
900       break;
901
902     case OPT_fargument_noalias_global:
903       flag_argument_noalias = value + value;
904       break;
905
906     case OPT_fasynchronous_unwind_tables:
907       flag_asynchronous_unwind_tables = value;
908       break;
909
910     case OPT_fbounds_check:
911       flag_bounds_check = value;
912       break;
913
914     case OPT_fbranch_count_reg:
915       flag_branch_on_count_reg = value;
916       break;
917
918     case OPT_fbranch_probabilities:
919       flag_branch_probabilities_set = true;
920       flag_branch_probabilities = value;
921       break;
922
923     case OPT_fbranch_target_load_optimize:
924       flag_branch_target_load_optimize = value;
925       break;
926
927     case OPT_fbranch_target_load_optimize2:
928       flag_branch_target_load_optimize2 = value;
929       break;
930
931     case OPT_fbtr_bb_exclusive:
932       flag_btr_bb_exclusive = value;
933       break;
934
935     case OPT_fcall_used_:
936       fix_register (arg, 0, 1);
937       break;
938
939     case OPT_fcall_saved_:
940       fix_register (arg, 0, 0);
941       break;
942
943     case OPT_fcaller_saves:
944       flag_caller_saves = value;
945       break;
946
947     case OPT_fcommon:
948       flag_no_common = !value;
949       break;
950
951     case OPT_fcprop_registers:
952       flag_cprop_registers = value;
953       break;
954
955     case OPT_fcrossjumping:
956       flag_crossjumping = value;
957       break;
958
959     case OPT_fcse_follow_jumps:
960       flag_cse_follow_jumps = value;
961       break;
962
963     case OPT_fcse_skip_blocks:
964       flag_cse_skip_blocks = value;
965       break;
966
967     case OPT_fdata_sections:
968       flag_data_sections = value;
969       break;
970
971     case OPT_fdefer_pop:
972       flag_defer_pop = value;
973       break;
974
975     case OPT_fdelayed_branch:
976       flag_delayed_branch = value;
977       break;
978
979     case OPT_fdelete_null_pointer_checks:
980       flag_delete_null_pointer_checks = value;
981       break;
982
983     case OPT_fdiagnostics_show_location_:
984       if (!strcmp (arg, "once"))
985         diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
986       else if (!strcmp (arg, "every-line"))
987         diagnostic_prefixing_rule (global_dc)
988           = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
989       else
990         return 0;
991       break;
992
993     case OPT_fdump_unnumbered:
994       flag_dump_unnumbered = value;
995       break;
996
997     case OPT_feliminate_dwarf2_dups:
998       flag_eliminate_dwarf2_dups = value;
999       break;
1000
1001     case OPT_feliminate_unused_debug_types:
1002       flag_eliminate_unused_debug_types = value;
1003       break;
1004
1005     case OPT_feliminate_unused_debug_symbols:
1006       flag_debug_only_used_symbols = value;
1007       break;
1008
1009     case OPT_fexceptions:
1010       flag_exceptions = value;
1011       break;
1012
1013     case OPT_fexpensive_optimizations:
1014       flag_expensive_optimizations = value;
1015       break;
1016
1017     case OPT_ffast_math:
1018       set_fast_math_flags (value);
1019       break;
1020
1021     case OPT_ffinite_math_only:
1022       flag_finite_math_only = value;
1023       break;
1024
1025     case OPT_ffixed_:
1026       fix_register (arg, 1, 1);
1027       break;
1028
1029     case OPT_ffunction_cse:
1030       flag_no_function_cse = !value;
1031       break;
1032
1033     case OPT_ffloat_store:
1034       flag_float_store = value;
1035       break;
1036
1037     case OPT_fforce_addr:
1038       flag_force_addr = value;
1039       break;
1040
1041     case OPT_fforce_mem:
1042       flag_force_mem = value;
1043       break;
1044
1045     case OPT_ffunction_sections:
1046       flag_function_sections = value;
1047       break;
1048
1049     case OPT_fgcse:
1050       flag_gcse = value;
1051       break;
1052
1053     case OPT_fgcse_lm:
1054       flag_gcse_lm = value;
1055       break;
1056
1057     case OPT_fgcse_sm:
1058       flag_gcse_sm = value;
1059       break;
1060
1061     case OPT_fgcse_after_reload:
1062       flag_gcse_after_reload = value;
1063       break;
1064
1065     case OPT_fgcse_las:
1066       flag_gcse_las = value;
1067       break;
1068
1069     case OPT_fguess_branch_probability:
1070       flag_guess_branch_prob = value;
1071       break;
1072
1073     case OPT_fident:
1074       flag_no_ident = !value;
1075       break;
1076
1077     case OPT_fif_conversion:
1078       flag_if_conversion = value;
1079       break;
1080
1081     case OPT_fif_conversion2:
1082       flag_if_conversion2 = value;
1083       break;
1084
1085     case OPT_finhibit_size_directive:
1086       flag_inhibit_size_directive = value;
1087       break;
1088
1089     case OPT_finline:
1090       flag_no_inline = !value;
1091       break;
1092
1093     case OPT_finline_functions:
1094       flag_inline_functions = value;
1095       break;
1096
1097     case OPT_finline_limit_:
1098     case OPT_finline_limit_eq:
1099       set_param_value ("max-inline-insns-single", value / 2);
1100       set_param_value ("max-inline-insns-auto", value / 2);
1101       set_param_value ("max-inline-insns-rtl", value);
1102       break;
1103
1104     case OPT_finstrument_functions:
1105       flag_instrument_function_entry_exit = value;
1106       break;
1107
1108     case OPT_fkeep_inline_functions:
1109       flag_keep_inline_functions =value;
1110       break;
1111
1112     case OPT_fkeep_static_consts:
1113       flag_keep_static_consts = value;
1114       break;
1115
1116     case OPT_fleading_underscore:
1117       flag_leading_underscore = value;
1118       break;
1119
1120     case OPT_floop_optimize:
1121       flag_loop_optimize = value;
1122       break;
1123
1124     case OPT_fmath_errno:
1125       flag_errno_math = value;
1126       break;
1127
1128     case OPT_fmem_report:
1129       mem_report = value;
1130       break;
1131
1132     case OPT_fmerge_all_constants:
1133       flag_merge_constants = value + value;
1134       break;
1135
1136     case OPT_fmerge_constants:
1137       flag_merge_constants = value;
1138       break;
1139
1140     case OPT_fmessage_length_:
1141       pp_set_line_maximum_length (global_dc->printer, value);
1142       break;
1143
1144     case OPT_fmove_all_movables:
1145       flag_move_all_movables = value;
1146       break;
1147
1148     case OPT_fnew_ra:
1149       flag_new_regalloc = value;
1150       break;
1151
1152     case OPT_fnon_call_exceptions:
1153       flag_non_call_exceptions = value;
1154       break;
1155
1156     case OPT_fold_unroll_all_loops:
1157       flag_old_unroll_all_loops = value;
1158       break;
1159
1160     case OPT_fold_unroll_loops:
1161       flag_old_unroll_loops = value;
1162       break;
1163
1164     case OPT_fomit_frame_pointer:
1165       flag_omit_frame_pointer = value;
1166       break;
1167
1168     case OPT_foptimize_register_move:
1169       flag_regmove = value;
1170       break;
1171
1172     case OPT_foptimize_sibling_calls:
1173       flag_optimize_sibling_calls = value;
1174       break;
1175
1176     case OPT_fpack_struct:
1177       flag_pack_struct = value;
1178       break;
1179
1180     case OPT_fpeel_loops:
1181       flag_peel_loops_set = true;
1182       flag_peel_loops = value;
1183       break;
1184
1185     case OPT_fpcc_struct_return:
1186       flag_pcc_struct_return = value;
1187       break;
1188
1189     case OPT_fpeephole:
1190       flag_no_peephole = !value;
1191       break;
1192
1193     case OPT_fpeephole2:
1194       flag_peephole2 = value;
1195       break;
1196
1197     case OPT_fpic:
1198       flag_pic = value;
1199       break;
1200
1201     case OPT_fpie:
1202       flag_pie = value;
1203       break;
1204
1205     case OPT_fprefetch_loop_arrays:
1206       flag_prefetch_loop_arrays = value;
1207       break;
1208
1209     case OPT_fprofile:
1210       profile_flag = value;
1211       break;
1212
1213     case OPT_fprofile_arcs:
1214       profile_arc_flag_set = true;
1215       profile_arc_flag = value;
1216       break;
1217
1218     case OPT_fprofile_use:
1219       if (!flag_branch_probabilities_set)
1220         flag_branch_probabilities = value;
1221       if (!flag_profile_values_set)
1222         flag_profile_values = value;
1223       if (!flag_unroll_loops_set)
1224         flag_unroll_loops = value;
1225       if (!flag_peel_loops_set)
1226         flag_peel_loops = value;
1227       if (!flag_tracer_set)
1228         flag_tracer = value;
1229       if (!flag_value_profile_transformations_set)
1230         flag_value_profile_transformations = value;
1231       break;
1232
1233     case OPT_fprofile_generate:
1234       if (!profile_arc_flag_set)
1235         profile_arc_flag = value;
1236       if (!flag_profile_values_set)
1237         flag_profile_values = value;
1238       if (!flag_value_profile_transformations_set)
1239         flag_value_profile_transformations = value;
1240       break;
1241
1242     case OPT_fprofile_values:
1243       flag_profile_values_set = true;
1244       flag_profile_values = value;
1245       break;
1246
1247     case OPT_fvpt:
1248       flag_value_profile_transformations_set = value;
1249       flag_value_profile_transformations = value;
1250       break;
1251
1252     case OPT_frandom_seed:
1253       /* The real switch is -fno-random-seed.  */
1254       if (value)
1255         return 0;
1256       flag_random_seed = NULL;
1257       break;
1258
1259     case OPT_frandom_seed_:
1260       flag_random_seed = arg;
1261       break;
1262
1263     case OPT_freduce_all_givs:
1264       flag_reduce_all_givs = value;
1265       break;
1266
1267     case OPT_freg_struct_return:
1268       flag_pcc_struct_return = !value;
1269       break;
1270
1271     case OPT_fregmove:
1272       flag_regmove = value;
1273       break;
1274
1275     case OPT_frename_registers:
1276       flag_rename_registers = value;
1277       break;
1278
1279     case OPT_freorder_blocks:
1280       flag_reorder_blocks = value;
1281       break;
1282
1283     case OPT_freorder_blocks_and_partition:
1284       flag_reorder_blocks_and_partition = value;
1285       break;
1286   
1287     case OPT_freorder_functions:
1288       flag_reorder_functions = value;
1289       break;
1290
1291     case OPT_frerun_cse_after_loop:
1292       flag_rerun_cse_after_loop = value;
1293       break;
1294
1295     case OPT_frerun_loop_opt:
1296       flag_rerun_loop_opt = value;
1297       break;
1298
1299     case OPT_frounding_math:
1300       flag_rounding_math = value;
1301       break;
1302
1303     case OPT_fsched_interblock:
1304       flag_schedule_interblock = value;
1305       break;
1306
1307     case OPT_fsched_spec:
1308       flag_schedule_speculative = value;
1309       break;
1310
1311     case OPT_fsched_spec_load:
1312       flag_schedule_speculative_load = value;
1313       break;
1314
1315     case OPT_fsched_spec_load_dangerous:
1316       flag_schedule_speculative_load_dangerous = value;
1317       break;
1318
1319     case OPT_fsched_verbose_:
1320 #ifdef INSN_SCHEDULING
1321       fix_sched_param ("verbose", arg);
1322       break;
1323 #else
1324       return 0;
1325 #endif
1326
1327     case OPT_fsched2_use_superblocks:
1328       flag_sched2_use_superblocks = value;
1329       break;
1330
1331     case OPT_fsched2_use_traces:
1332       flag_sched2_use_traces = value;
1333       break;
1334
1335     case OPT_fschedule_insns:
1336       flag_schedule_insns = value;
1337       break;
1338
1339     case OPT_fschedule_insns2:
1340       flag_schedule_insns_after_reload = value;
1341       break;
1342
1343     case OPT_fsched_stalled_insns:
1344       flag_sched_stalled_insns = value;
1345       break;
1346
1347     case OPT_fsched_stalled_insns_:
1348       flag_sched_stalled_insns = value;
1349       if (flag_sched_stalled_insns == 0)
1350         flag_sched_stalled_insns = -1;
1351       break;
1352
1353     case OPT_fsched_stalled_insns_dep:
1354       flag_sched_stalled_insns_dep = 1;
1355       break;
1356
1357     case OPT_fsched_stalled_insns_dep_:
1358       flag_sched_stalled_insns_dep = value;
1359       break;
1360
1361     case OPT_fshared_data:
1362       flag_shared_data = value;
1363       break;
1364
1365     case OPT_fsignaling_nans:
1366       flag_signaling_nans = value;
1367       break;
1368
1369     case OPT_fsingle_precision_constant:
1370       flag_single_precision_constant = value;
1371       break;
1372
1373     case OPT_fstack_check:
1374       flag_stack_check = value;
1375       break;
1376
1377     case OPT_fstack_limit:
1378       /* The real switch is -fno-stack-limit.  */
1379       if (value)
1380         return 0;
1381       stack_limit_rtx = NULL_RTX;
1382       break;
1383
1384     case OPT_fstack_limit_register_:
1385       {
1386         int reg = decode_reg_name (arg);
1387         if (reg < 0)
1388           error ("unrecognized register name \"%s\"", arg);
1389         else
1390           stack_limit_rtx = gen_rtx_REG (Pmode, reg);
1391       }
1392       break;
1393
1394     case OPT_fstack_limit_symbol_:
1395       stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
1396       break;
1397
1398     case OPT_fstrength_reduce:
1399       flag_strength_reduce = value;
1400       break;
1401
1402     case OPT_fstrict_aliasing:
1403       flag_strict_aliasing = value;
1404       break;
1405
1406     case OPT_fsyntax_only:
1407       flag_syntax_only = value;
1408       break;
1409
1410     case OPT_ftest_coverage:
1411       flag_test_coverage = value;
1412       break;
1413
1414     case OPT_fthread_jumps:
1415       flag_thread_jumps = value;
1416       break;
1417
1418     case OPT_ftime_report:
1419       time_report = value;
1420       break;
1421
1422     case OPT_ftls_model_:
1423       if (!strcmp (arg, "global-dynamic"))
1424         flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
1425       else if (!strcmp (arg, "local-dynamic"))
1426         flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
1427       else if (!strcmp (arg, "initial-exec"))
1428         flag_tls_default = TLS_MODEL_INITIAL_EXEC;
1429       else if (!strcmp (arg, "local-exec"))
1430         flag_tls_default = TLS_MODEL_LOCAL_EXEC;
1431       else
1432         warning ("unknown tls-model \"%s\"", arg);
1433       break;
1434
1435     case OPT_ftracer:
1436       flag_tracer_set = true;
1437       flag_tracer = value;
1438       break;
1439
1440     case OPT_ftrapping_math:
1441       flag_trapping_math = value;
1442       break;
1443
1444     case OPT_ftrapv:
1445       flag_trapv = value;
1446       break;
1447
1448     case OPT_funit_at_a_time:
1449       flag_unit_at_a_time = value;
1450       break;
1451
1452     case OPT_funroll_all_loops:
1453       flag_unroll_all_loops = value;
1454       break;
1455
1456     case OPT_funroll_loops:
1457       flag_unroll_loops_set = true;
1458       flag_unroll_loops = value;
1459       break;
1460
1461     case OPT_funsafe_math_optimizations:
1462       flag_unsafe_math_optimizations = value;
1463       break;
1464
1465     case OPT_funswitch_loops:
1466       flag_unswitch_loops = value;
1467       break;
1468
1469     case OPT_funwind_tables:
1470       flag_unwind_tables = value;
1471       break;
1472
1473     case OPT_fvar_tracking:
1474       flag_var_tracking = value;
1475       break;
1476
1477     case OPT_fverbose_asm:
1478       flag_verbose_asm = value;
1479       break;
1480
1481     case OPT_fweb:
1482       flag_web = value;
1483       break;
1484       
1485     case OPT_fwrapv:
1486       flag_wrapv = value;
1487       break;
1488
1489     case OPT_fzero_initialized_in_bss:
1490       flag_zero_initialized_in_bss = value;
1491       break;
1492
1493     case OPT_g:
1494       set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg);
1495       break;
1496
1497     case OPT_gcoff:
1498       set_debug_level (SDB_DEBUG, false, arg);
1499       break;
1500
1501     case OPT_gdwarf_2:
1502       set_debug_level (DWARF2_DEBUG, false, arg);
1503       break;
1504
1505     case OPT_ggdb:
1506       set_debug_level (NO_DEBUG, 2, arg);
1507       break;
1508
1509     case OPT_gstabs:
1510     case OPT_gstabs_:
1511       set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg);
1512       break;
1513
1514     case OPT_gvms:
1515       set_debug_level (VMS_DEBUG, false, arg);
1516       break;
1517
1518     case OPT_gxcoff:
1519     case OPT_gxcoff_:
1520       set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg);
1521       break;
1522
1523     case OPT_m:
1524       set_target_switch (arg);
1525       break;
1526
1527     case OPT_o:
1528       asm_file_name = arg;
1529       break;
1530
1531     case OPT_p:
1532       profile_flag = 1;
1533       break;
1534
1535     case OPT_pedantic:
1536       pedantic = 1;
1537       break;
1538
1539     case OPT_pedantic_errors:
1540       flag_pedantic_errors = pedantic = 1;
1541       break;
1542
1543     case OPT_quiet:
1544       quiet_flag = 1;
1545       break;
1546
1547     case OPT_version:
1548       version_flag = 1;
1549       break;
1550
1551     case OPT_w:
1552       inhibit_warnings = true;
1553       break;      
1554     }
1555
1556   return 1;
1557 }
1558
1559 /* Handle --param NAME=VALUE.  */
1560 static void
1561 handle_param (const char *carg)
1562 {
1563   char *equal, *arg;
1564   int value;
1565
1566   arg = xstrdup (carg);
1567   equal = strchr (arg, '=');
1568   if (!equal)
1569     error ("%s: --param arguments should be of the form NAME=VALUE", arg);
1570   else
1571     {
1572       value = integral_argument (equal + 1);
1573       if (value == -1)
1574         error ("invalid --param value `%s'", equal + 1);
1575       else
1576         {
1577           *equal = '\0';
1578           set_param_value (arg, value);
1579         }
1580     }
1581
1582   free (arg);
1583 }
1584
1585 /* Handle -W and -Wextra.  */
1586 static void
1587 set_Wextra (int setting)
1588 {
1589   extra_warnings = setting;
1590   warn_unused_value = setting;
1591   warn_unused_parameter = (setting && maybe_warn_unused_parameter);
1592
1593   /* We save the value of warn_uninitialized, since if they put
1594      -Wuninitialized on the command line, we need to generate a
1595      warning about not using it without also specifying -O.  */
1596   if (setting == 0)
1597     warn_uninitialized = 0;
1598   else if (warn_uninitialized != 1)
1599     warn_uninitialized = 2;
1600 }
1601
1602 /* Initialize unused warning flags.  */
1603 void
1604 set_Wunused (int setting)
1605 {
1606   warn_unused_function = setting;
1607   warn_unused_label = setting;
1608   /* Unused function parameter warnings are reported when either
1609      ``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
1610      Thus, if -Wextra has already been seen, set warn_unused_parameter;
1611      otherwise set maybe_warn_extra_parameter, which will be picked up
1612      by set_Wextra.  */
1613   maybe_warn_unused_parameter = setting;
1614   warn_unused_parameter = (setting && extra_warnings);
1615   warn_unused_variable = setting;
1616   warn_unused_value = setting;
1617 }
1618
1619 /* The following routines are useful in setting all the flags that
1620    -ffast-math and -fno-fast-math imply.  */
1621 void
1622 set_fast_math_flags (int set)
1623 {
1624   flag_trapping_math = !set;
1625   flag_unsafe_math_optimizations = set;
1626   flag_finite_math_only = set;
1627   flag_errno_math = !set;
1628   if (set)
1629     {
1630       flag_signaling_nans = 0;
1631       flag_rounding_math = 0;
1632     }
1633 }
1634
1635 /* Return true iff flags are set as if -ffast-math.  */
1636 bool
1637 fast_math_flags_set_p (void)
1638 {
1639   return (!flag_trapping_math
1640           && flag_unsafe_math_optimizations
1641           && flag_finite_math_only
1642           && !flag_errno_math);
1643 }
1644
1645 /* Handle a debug output -g switch.  EXTENDED is true or false to support
1646    extended output (2 is special and means "-ggdb" was given).  */
1647 static void
1648 set_debug_level (enum debug_info_type type, int extended, const char *arg)
1649 {
1650   static bool type_explicit;
1651
1652   use_gnu_debug_info_extensions = extended;
1653
1654   if (type == NO_DEBUG)
1655     {
1656       if (write_symbols == NO_DEBUG)
1657         {
1658           write_symbols = PREFERRED_DEBUGGING_TYPE;
1659
1660           if (extended == 2)
1661             {
1662 #ifdef DWARF2_DEBUGGING_INFO
1663               write_symbols = DWARF2_DEBUG;
1664 #elif defined DBX_DEBUGGING_INFO
1665               write_symbols = DBX_DEBUG;
1666 #endif
1667             }
1668
1669           if (write_symbols == NO_DEBUG)
1670             warning ("target system does not support debug output");
1671         }
1672     }
1673   else
1674     {
1675       /* Does it conflict with an already selected type?  */
1676       if (type_explicit && write_symbols != NO_DEBUG && type != write_symbols)
1677         error ("debug format \"%s\" conflicts with prior selection",
1678                debug_type_names[type]);
1679       write_symbols = type;
1680       type_explicit = true;
1681     }
1682
1683   /* A debug flag without a level defaults to level 2.  */
1684   if (*arg == '\0')
1685     {
1686       if (!debug_info_level)
1687         debug_info_level = 2;
1688     }
1689   else
1690     {
1691       debug_info_level = integral_argument (arg);
1692       if (debug_info_level == (unsigned int) -1)
1693         error ("unrecognised debug output level \"%s\"", arg);
1694       else if (debug_info_level > 3)
1695         error ("debug output level %s is too high", arg);
1696     }
1697 }
1698
1699 /* Output --help text.  */
1700 static void
1701 print_help (void)
1702 {
1703   size_t i;
1704   const char *p;
1705
1706   GET_ENVIRONMENT (p, "COLUMNS");
1707   if (p)
1708     {
1709       int value = atoi (p);
1710       if (value > 0)
1711         columns = value;
1712     }
1713
1714   puts (_("The following options are language-independent:\n"));
1715
1716   print_filtered_help (CL_COMMON);
1717   print_param_help ();
1718
1719   for (i = 0; lang_names[i]; i++)
1720     {
1721       printf (_("The %s front end recognizes the following options:\n\n"),
1722               lang_names[i]);
1723       print_filtered_help (1U << i);
1724     }
1725
1726   display_target_options ();
1727 }
1728
1729 /* Print the help for --param.  */
1730 static void
1731 print_param_help (void)
1732 {
1733   size_t i;
1734
1735   puts (_("The --param option recognizes the following as parameters:\n"));
1736
1737   for (i = 0; i < LAST_PARAM; i++)
1738     {
1739       const char *help = compiler_params[i].help;
1740       const char *param = compiler_params[i].option;
1741
1742       if (help == NULL || *help == '\0')
1743         help = undocumented_msg;
1744
1745       /* Get the translation.  */
1746       help = _(help);
1747
1748       wrap_help (help, param, strlen (param));
1749     }
1750
1751   putchar ('\n');
1752 }
1753
1754 /* Print help for a specific front-end, etc.  */
1755 static void
1756 print_filtered_help (unsigned int flag)
1757 {
1758   unsigned int i, len, filter, indent = 0;
1759   bool duplicates = false;
1760   const char *help, *opt, *tab;
1761   static char *printed;
1762
1763   if (flag == CL_COMMON)
1764     {
1765       filter = flag;
1766       if (!printed)
1767         printed = xmalloc (cl_options_count);
1768       memset (printed, 0, cl_options_count);
1769     }
1770   else
1771     {
1772       /* Don't print COMMON options twice.  */
1773       filter = flag | CL_COMMON;
1774
1775       for (i = 0; i < cl_options_count; i++)
1776         {
1777           if ((cl_options[i].flags & filter) != flag)
1778             continue;
1779
1780           /* Skip help for internal switches.  */
1781           if (cl_options[i].flags & CL_UNDOCUMENTED)
1782             continue;
1783
1784           /* Skip switches that have already been printed, mark them to be
1785              listed later.  */
1786           if (printed[i])
1787             {
1788               duplicates = true;
1789               indent = print_switch (cl_options[i].opt_text, indent);
1790             }
1791         }
1792
1793       if (duplicates)
1794         {
1795           putchar ('\n');
1796           putchar ('\n');
1797         }
1798     }
1799
1800   for (i = 0; i < cl_options_count; i++)
1801     {
1802       if ((cl_options[i].flags & filter) != flag)
1803         continue;
1804
1805       /* Skip help for internal switches.  */
1806       if (cl_options[i].flags & CL_UNDOCUMENTED)
1807         continue;
1808
1809       /* Skip switches that have already been printed.  */
1810       if (printed[i])
1811         continue;
1812
1813       printed[i] = true;
1814
1815       help = cl_options[i].help;
1816       if (!help)
1817         help = undocumented_msg;
1818
1819       /* Get the translation.  */
1820       help = _(help);
1821
1822       tab = strchr (help, '\t');
1823       if (tab)
1824         {
1825           len = tab - help;
1826           opt = help;
1827           help = tab + 1;
1828         }
1829       else
1830         {
1831           opt = cl_options[i].opt_text;
1832           len = strlen (opt);
1833         }
1834
1835       wrap_help (help, opt, len);
1836     }
1837
1838   putchar ('\n');
1839 }
1840
1841 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1842    word-wrapped HELP in a second column.  */
1843 static unsigned int
1844 print_switch (const char *text, unsigned int indent)
1845 {
1846   unsigned int len = strlen (text) + 1; /* trailing comma */
1847
1848   if (indent)
1849     {
1850       putchar (',');
1851       if (indent + len > columns)
1852         {
1853           putchar ('\n');
1854           putchar (' ');
1855           indent = 1;
1856         }
1857     }
1858   else
1859     putchar (' ');
1860
1861   putchar (' ');
1862   fputs (text, stdout);
1863
1864   return indent + len + 1;
1865 }
1866
1867 /* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1868    word-wrapped HELP in a second column.  */
1869 static void
1870 wrap_help (const char *help, const char *item, unsigned int item_width)
1871 {
1872   unsigned int col_width = 27;
1873   unsigned int remaining, room, len;
1874
1875   remaining = strlen (help);
1876
1877   do
1878     {
1879       room = columns - 3 - MAX (col_width, item_width);
1880       if (room > columns)
1881         room = 0;
1882       len = remaining;
1883
1884       if (room < len)
1885         {
1886           unsigned int i;
1887
1888           for (i = 0; help[i]; i++)
1889             {
1890               if (i >= room && len != remaining)
1891                 break;
1892               if (help[i] == ' ')
1893                 len = i;
1894               else if ((help[i] == '-' || help[i] == '/')
1895                        && help[i + 1] != ' '
1896                        && i > 0 && ISALPHA (help[i - 1]))
1897                 len = i + 1;
1898             }
1899         }
1900
1901       printf( "  %-*.*s %.*s\n", col_width, item_width, item, len, help);
1902       item_width = 0;
1903       while (help[len] == ' ')
1904         len++;
1905       help += len;
1906       remaining -= len;
1907     }
1908   while (remaining);
1909 }