OSDN Git Service

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