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