OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [opts.c] - Blame information for rev 294

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 38 julius
/* Command line option handling.
2
   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007
3
   Free Software Foundation, Inc.
4
   Contributed by Neil Booth.
5
 
6
This file is part of GCC.
7
 
8
GCC is free software; you can redistribute it and/or modify it under
9
the terms of the GNU General Public License as published by the Free
10
Software Foundation; either version 3, or (at your option) any later
11
version.
12
 
13
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14
WARRANTY; without even the implied warranty of MERCHANTABILITY or
15
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16
for more details.
17
 
18
You should have received a copy of the GNU General Public License
19
along with GCC; see the file COPYING3.  If not see
20
<http://www.gnu.org/licenses/>.  */
21
 
22
#include "config.h"
23
#include "system.h"
24
#include "intl.h"
25
#include "coretypes.h"
26
#include "tm.h"
27
#include "tree.h"
28
#include "rtl.h"
29
#include "ggc.h"
30
#include "output.h"
31
#include "langhooks.h"
32
#include "opts.h"
33
#include "options.h"
34
#include "flags.h"
35
#include "toplev.h"
36
#include "params.h"
37
#include "diagnostic.h"
38
#include "tm_p.h"               /* For OPTIMIZATION_OPTIONS.  */
39
#include "insn-attr.h"          /* For INSN_SCHEDULING.  */
40
#include "target.h"
41
#include "tree-pass.h"
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
/* Print various extra warnings.  -W/-Wextra.  */
51
bool extra_warnings;
52
 
53
/* True to warn about any objects definitions whose size is larger
54
   than N bytes.  Also want about function definitions whose returned
55
   values are larger than N bytes, where N is `larger_than_size'.  */
56
bool warn_larger_than;
57
HOST_WIDE_INT larger_than_size;
58
 
59
/* Nonzero means warn about constructs which might not be
60
   strict-aliasing safe.  */
61
int warn_strict_aliasing;
62
 
63
/* Nonzero means warn about optimizations which rely on undefined
64
   signed overflow.  */
65
int warn_strict_overflow;
66
 
67
/* Hack for cooperation between set_Wunused and set_Wextra.  */
68
static bool maybe_warn_unused_parameter;
69
 
70
/* Type(s) of debugging information we are producing (if any).  See
71
   flags.h for the definitions of the different possible types of
72
   debugging information.  */
73
enum debug_info_type write_symbols = NO_DEBUG;
74
 
75
/* Level of debugging information we are producing.  See flags.h for
76
   the definitions of the different possible levels.  */
77
enum debug_info_level debug_info_level = DINFO_LEVEL_NONE;
78
 
79
/* Nonzero means use GNU-only extensions in the generated symbolic
80
   debugging information.  Currently, this only has an effect when
81
   write_symbols is set to DBX_DEBUG, XCOFF_DEBUG, or DWARF_DEBUG.  */
82
bool use_gnu_debug_info_extensions;
83
 
84
/* The default visibility for all symbols (unless overridden) */
85
enum symbol_visibility default_visibility = VISIBILITY_DEFAULT;
86
 
87
/* Disable unit-at-a-time for frontends that might be still broken in this
88
   respect.  */
89
 
90
bool no_unit_at_a_time_default;
91
 
92
/* Global visibility options.  */
93
struct visibility_flags visibility_options;
94
 
95
/* Columns of --help display.  */
96
static unsigned int columns = 80;
97
 
98
/* What to print when a switch has no documentation.  */
99
static const char undocumented_msg[] = N_("This switch lacks documentation");
100
 
101
/* Used for bookkeeping on whether user set these flags so
102
   -fprofile-use/-fprofile-generate does not use them.  */
103
static bool profile_arc_flag_set, flag_profile_values_set;
104
static bool flag_unroll_loops_set, flag_tracer_set;
105
static bool flag_value_profile_transformations_set;
106
static bool flag_peel_loops_set, flag_branch_probabilities_set;
107
 
108
/* Input file names.  */
109
const char **in_fnames;
110
unsigned num_in_fnames;
111
 
112
static int common_handle_option (size_t scode, const char *arg, int value,
113
                                 unsigned int lang_mask);
114
static void handle_param (const char *);
115
static void set_Wextra (int);
116
static unsigned int handle_option (const char **argv, unsigned int lang_mask);
117
static char *write_langs (unsigned int lang_mask);
118
static void complain_wrong_lang (const char *, const struct cl_option *,
119
                                 unsigned int lang_mask);
120
static void handle_options (unsigned int, const char **, unsigned int);
121
static void wrap_help (const char *help, const char *item, unsigned int);
122
static void print_target_help (void);
123
static void print_help (void);
124
static void print_param_help (void);
125
static void print_filtered_help (unsigned int);
126
static unsigned int print_switch (const char *text, unsigned int indent);
127
static void set_debug_level (enum debug_info_type type, int extended,
128
                             const char *arg);
129
 
130
/* If ARG is a non-negative integer made up solely of digits, return its
131
   value, otherwise return -1.  */
132
static int
133
integral_argument (const char *arg)
134
{
135
  const char *p = arg;
136
 
137
  while (*p && ISDIGIT (*p))
138
    p++;
139
 
140
  if (*p == '\0')
141
    return atoi (arg);
142
 
143
  return -1;
144
}
145
 
146
/* Return a malloced slash-separated list of languages in MASK.  */
147
static char *
148
write_langs (unsigned int mask)
149
{
150
  unsigned int n = 0, len = 0;
151
  const char *lang_name;
152
  char *result;
153
 
154
  for (n = 0; (lang_name = lang_names[n]) != 0; n++)
155
    if (mask & (1U << n))
156
      len += strlen (lang_name) + 1;
157
 
158
  result = XNEWVEC (char, len);
159
  len = 0;
160
  for (n = 0; (lang_name = lang_names[n]) != 0; n++)
161
    if (mask & (1U << n))
162
      {
163
        if (len)
164
          result[len++] = '/';
165
        strcpy (result + len, lang_name);
166
        len += strlen (lang_name);
167
      }
168
 
169
  result[len] = 0;
170
 
171
  return result;
172
}
173
 
174
/* Complain that switch OPT_INDEX does not apply to this front end.  */
175
static void
176
complain_wrong_lang (const char *text, const struct cl_option *option,
177
                     unsigned int lang_mask)
178
{
179
  char *ok_langs, *bad_lang;
180
 
181
  ok_langs = write_langs (option->flags);
182
  bad_lang = write_langs (lang_mask);
183
 
184
  /* Eventually this should become a hard error IMO.  */
185
  warning (0, "command line option \"%s\" is valid for %s but not for %s",
186
           text, ok_langs, bad_lang);
187
 
188
  free (ok_langs);
189
  free (bad_lang);
190
}
191
 
192
/* Handle the switch beginning at ARGV for the language indicated by
193
   LANG_MASK.  Returns the number of switches consumed.  */
194
static unsigned int
195
handle_option (const char **argv, unsigned int lang_mask)
196
{
197
  size_t opt_index;
198
  const char *opt, *arg = 0;
199
  char *dup = 0;
200
  int value = 1;
201
  unsigned int result = 0;
202
  const struct cl_option *option;
203
 
204
  opt = argv[0];
205
 
206
  opt_index = find_opt (opt + 1, lang_mask | CL_COMMON | CL_TARGET);
207
  if (opt_index == cl_options_count
208
      && (opt[1] == 'W' || opt[1] == 'f' || opt[1] == 'm')
209
      && opt[2] == 'n' && opt[3] == 'o' && opt[4] == '-')
210
    {
211
      /* Drop the "no-" from negative switches.  */
212
      size_t len = strlen (opt) - 3;
213
 
214
      dup = XNEWVEC (char, len + 1);
215
      dup[0] = '-';
216
      dup[1] = opt[1];
217
      memcpy (dup + 2, opt + 5, len - 2 + 1);
218
      opt = dup;
219
      value = 0;
220
      opt_index = find_opt (opt + 1, lang_mask | CL_COMMON | CL_TARGET);
221
    }
222
 
223
  if (opt_index == cl_options_count)
224
    goto done;
225
 
226
  option = &cl_options[opt_index];
227
 
228
  /* Reject negative form of switches that don't take negatives as
229
     unrecognized.  */
230
  if (!value && (option->flags & CL_REJECT_NEGATIVE))
231
    goto done;
232
 
233
  /* We've recognized this switch.  */
234
  result = 1;
235
 
236
  /* Check to see if the option is disabled for this configuration.  */
237
  if (option->flags & CL_DISABLED)
238
    {
239
      error ("command line option %qs"
240
             " is not supported by this configuration", opt);
241
      goto done;
242
    }
243
 
244
  /* Sort out any argument the switch takes.  */
245
  if (option->flags & CL_JOINED)
246
    {
247
      /* Have arg point to the original switch.  This is because
248
         some code, such as disable_builtin_function, expects its
249
         argument to be persistent until the program exits.  */
250
      arg = argv[0] + cl_options[opt_index].opt_len + 1;
251
      if (!value)
252
        arg += strlen ("no-");
253
 
254
      if (*arg == '\0' && !(option->flags & CL_MISSING_OK))
255
        {
256
          if (option->flags & CL_SEPARATE)
257
            {
258
              arg = argv[1];
259
              result = 2;
260
            }
261
          else
262
            /* Missing argument.  */
263
            arg = NULL;
264
        }
265
    }
266
  else if (option->flags & CL_SEPARATE)
267
    {
268
      arg = argv[1];
269
      result = 2;
270
    }
271
 
272
  /* Now we've swallowed any potential argument, complain if this
273
     is a switch for a different front end.  */
274
  if (!(option->flags & (lang_mask | CL_COMMON | CL_TARGET)))
275
    {
276
      complain_wrong_lang (argv[0], option, lang_mask);
277
      goto done;
278
    }
279
 
280
  if (arg == NULL && (option->flags & (CL_JOINED | CL_SEPARATE)))
281
    {
282
      if (!lang_hooks.missing_argument (opt, opt_index))
283
        error ("missing argument to \"%s\"", opt);
284
      goto done;
285
    }
286
 
287
  /* If the switch takes an integer, convert it.  */
288
  if (arg && (option->flags & CL_UINTEGER))
289
    {
290
      value = integral_argument (arg);
291
      if (value == -1)
292
        {
293
          error ("argument to \"%s\" should be a non-negative integer",
294
                 option->opt_text);
295
          goto done;
296
        }
297
    }
298
 
299
  if (option->flag_var)
300
    switch (option->var_type)
301
      {
302
      case CLVC_BOOLEAN:
303
        *(int *) option->flag_var = value;
304
        break;
305
 
306
      case CLVC_EQUAL:
307
        *(int *) option->flag_var = (value
308
                                     ? option->var_value
309
                                     : !option->var_value);
310
        break;
311
 
312
      case CLVC_BIT_CLEAR:
313
      case CLVC_BIT_SET:
314
        if ((value != 0) == (option->var_type == CLVC_BIT_SET))
315
          *(int *) option->flag_var |= option->var_value;
316
        else
317
          *(int *) option->flag_var &= ~option->var_value;
318
        if (option->flag_var == &target_flags)
319
          target_flags_explicit |= option->var_value;
320
        break;
321
 
322
      case CLVC_STRING:
323
        *(const char **) option->flag_var = arg;
324
        break;
325
      }
326
 
327
  if (option->flags & lang_mask)
328
    if (lang_hooks.handle_option (opt_index, arg, value) == 0)
329
      result = 0;
330
 
331
  if (result && (option->flags & CL_COMMON))
332
    if (common_handle_option (opt_index, arg, value, lang_mask) == 0)
333
      result = 0;
334
 
335
  if (result && (option->flags & CL_TARGET))
336
    if (!targetm.handle_option (opt_index, arg, value))
337
      result = 0;
338
 
339
 done:
340
  if (dup)
341
    free (dup);
342
  return result;
343
}
344
 
345
/* Handle FILENAME from the command line.  */
346
static void
347
add_input_filename (const char *filename)
348
{
349
  num_in_fnames++;
350
  in_fnames = xrealloc (in_fnames, num_in_fnames * sizeof (in_fnames[0]));
351
  in_fnames[num_in_fnames - 1] = filename;
352
}
353
 
354
/* Decode and handle the vector of command line options.  LANG_MASK
355
   contains has a single bit set representing the current
356
   language.  */
357
static void
358
handle_options (unsigned int argc, const char **argv, unsigned int lang_mask)
359
{
360
  unsigned int n, i;
361
 
362
  for (i = 1; i < argc; i += n)
363
    {
364
      const char *opt = argv[i];
365
 
366
      /* Interpret "-" or a non-switch as a file name.  */
367
      if (opt[0] != '-' || opt[1] == '\0')
368
        {
369
          if (main_input_filename == NULL)
370
            main_input_filename = opt;
371
          add_input_filename (opt);
372
          n = 1;
373
          continue;
374
        }
375
 
376
      n = handle_option (argv + i, lang_mask);
377
 
378
      if (!n)
379
        {
380
          n = 1;
381
          error ("unrecognized command line option \"%s\"", opt);
382
        }
383
    }
384
}
385
 
386
/* Parse command line options and set default flag values.  Do minimal
387
   options processing.  */
388
void
389
decode_options (unsigned int argc, const char **argv)
390
{
391
  unsigned int i, lang_mask;
392
 
393
  /* Perform language-specific options initialization.  */
394
  lang_mask = lang_hooks.init_options (argc, argv);
395
 
396
  lang_hooks.initialize_diagnostics (global_dc);
397
 
398
  /* Scan to see what optimization level has been specified.  That will
399
     determine the default value of many flags.  */
400
  for (i = 1; i < argc; i++)
401
    {
402
      if (!strcmp (argv[i], "-O"))
403
        {
404
          optimize = 1;
405
          optimize_size = 0;
406
        }
407
      else if (argv[i][0] == '-' && argv[i][1] == 'O')
408
        {
409
          /* Handle -Os, -O2, -O3, -O69, ...  */
410
          const char *p = &argv[i][2];
411
 
412
          if ((p[0] == 's') && (p[1] == 0))
413
            {
414
              optimize_size = 1;
415
 
416
              /* Optimizing for size forces optimize to be 2.  */
417
              optimize = 2;
418
            }
419
          else
420
            {
421
              const int optimize_val = read_integral_parameter (p, p - 2, -1);
422
              if (optimize_val != -1)
423
                {
424
                  optimize = optimize_val;
425
                  optimize_size = 0;
426
                }
427
            }
428
        }
429
    }
430
 
431
  if (!optimize)
432
    {
433
      flag_merge_constants = 0;
434
    }
435
 
436
  if (optimize >= 1)
437
    {
438
      flag_defer_pop = 1;
439
#ifdef DELAY_SLOTS
440
      flag_delayed_branch = 1;
441
#endif
442
#ifdef CAN_DEBUG_WITHOUT_FP
443
      flag_omit_frame_pointer = 1;
444
#endif
445
      flag_guess_branch_prob = 1;
446
      flag_cprop_registers = 1;
447
      flag_if_conversion = 1;
448
      flag_if_conversion2 = 1;
449
      flag_ipa_pure_const = 1;
450
      flag_ipa_reference = 1;
451
      flag_tree_ccp = 1;
452
      flag_tree_dce = 1;
453
      flag_tree_dom = 1;
454
      flag_tree_dse = 1;
455
      flag_tree_ter = 1;
456
      flag_tree_live_range_split = 1;
457
      flag_tree_sra = 1;
458
      flag_tree_copyrename = 1;
459
      flag_tree_fre = 1;
460
      flag_tree_copy_prop = 1;
461
      flag_tree_sink = 1;
462
      flag_tree_salias = 1;
463
      if (!no_unit_at_a_time_default)
464
        flag_unit_at_a_time = 1;
465
 
466
      if (!optimize_size)
467
        {
468
          /* Loop header copying usually increases size of the code.  This used
469
             not to be true, since quite often it is possible to verify that
470
             the condition is satisfied in the first iteration and therefore
471
             to eliminate it.  Jump threading handles these cases now.  */
472
          flag_tree_ch = 1;
473
        }
474
    }
475
 
476
  if (optimize >= 2)
477
    {
478
      flag_thread_jumps = 1;
479
      flag_crossjumping = 1;
480
      flag_optimize_sibling_calls = 1;
481
      flag_cse_follow_jumps = 1;
482
      flag_cse_skip_blocks = 1;
483
      flag_gcse = 1;
484
      flag_expensive_optimizations = 1;
485
      flag_ipa_type_escape = 1;
486
      flag_rerun_cse_after_loop = 1;
487
      flag_caller_saves = 1;
488
      flag_peephole2 = 1;
489
#ifdef INSN_SCHEDULING
490
      flag_schedule_insns = 1;
491
      flag_schedule_insns_after_reload = 1;
492
#endif
493
      flag_regmove = 1;
494
      flag_strict_aliasing = 1;
495
      flag_strict_overflow = 1;
496
      flag_delete_null_pointer_checks = 1;
497
      flag_reorder_blocks = 1;
498
      flag_reorder_functions = 1;
499
      flag_tree_store_ccp = 1;
500
      flag_tree_store_copy_prop = 1;
501
      flag_tree_vrp = 1;
502
 
503
      if (!optimize_size)
504
        {
505
          /* PRE tends to generate bigger code.  */
506
          flag_tree_pre = 1;
507
        }
508
    }
509
 
510
  if (optimize >= 3)
511
    {
512
      flag_inline_functions = 1;
513
      flag_unswitch_loops = 1;
514
      flag_gcse_after_reload = 1;
515
    }
516
 
517
  if (optimize < 2 || optimize_size)
518
    {
519
      align_loops = 1;
520
      align_jumps = 1;
521
      align_labels = 1;
522
      align_functions = 1;
523
 
524
      /* Don't reorder blocks when optimizing for size because extra
525
         jump insns may be created; also barrier may create extra padding.
526
 
527
         More correctly we should have a block reordering mode that tried
528
         to minimize the combined size of all the jumps.  This would more
529
         or less automatically remove extra jumps, but would also try to
530
         use more short jumps instead of long jumps.  */
531
      flag_reorder_blocks = 0;
532
      flag_reorder_blocks_and_partition = 0;
533
    }
534
 
535
  if (optimize_size)
536
    {
537
      /* Inlining of very small functions usually reduces total size.  */
538
      set_param_value ("max-inline-insns-single", 5);
539
      set_param_value ("max-inline-insns-auto", 5);
540
      flag_inline_functions = 1;
541
 
542
      /* We want to crossjump as much as possible.  */
543
      set_param_value ("min-crossjump-insns", 1);
544
    }
545
 
546
  /* Initialize whether `char' is signed.  */
547
  flag_signed_char = DEFAULT_SIGNED_CHAR;
548
  /* Set this to a special "uninitialized" value.  The actual default is set
549
     after target options have been processed.  */
550
  flag_short_enums = 2;
551
 
552
  /* Initialize target_flags before OPTIMIZATION_OPTIONS so the latter can
553
     modify it.  */
554
  target_flags = targetm.default_target_flags;
555
 
556
  /* Some tagets have ABI-specified unwind tables.  */
557
  flag_unwind_tables = targetm.unwind_tables_default;
558
 
559
#ifdef OPTIMIZATION_OPTIONS
560
  /* Allow default optimizations to be specified on a per-machine basis.  */
561
  OPTIMIZATION_OPTIONS (optimize, optimize_size);
562
#endif
563
 
564
  handle_options (argc, argv, lang_mask);
565
 
566
  if (flag_pie)
567
    flag_pic = flag_pie;
568
  if (flag_pic && !flag_pie)
569
    flag_shlib = 1;
570
 
571
  if (flag_no_inline == 2)
572
    flag_no_inline = 0;
573
  else
574
    flag_really_no_inline = flag_no_inline;
575
 
576
  /* Set flag_no_inline before the post_options () hook.  The C front
577
     ends use it to determine tree inlining defaults.  FIXME: such
578
     code should be lang-independent when all front ends use tree
579
     inlining, in which case it, and this condition, should be moved
580
     to the top of process_options() instead.  */
581
  if (optimize == 0)
582
    {
583
      /* Inlining does not work if not optimizing,
584
         so force it not to be done.  */
585
      flag_no_inline = 1;
586
      warn_inline = 0;
587
 
588
      /* The c_decode_option function and decode_option hook set
589
         this to `2' if -Wall is used, so we can avoid giving out
590
         lots of errors for people who don't realize what -Wall does.  */
591
      if (warn_uninitialized == 1)
592
        warning (OPT_Wuninitialized,
593
                 "-Wuninitialized is not supported without -O");
594
    }
595
 
596
  if (flag_really_no_inline == 2)
597
    flag_really_no_inline = flag_no_inline;
598
 
599
  /* The optimization to partition hot and cold basic blocks into separate
600
     sections of the .o and executable files does not work (currently)
601
     with exception handling.  This is because there is no support for
602
     generating unwind info.  If flag_exceptions is turned on we need to
603
     turn off the partitioning optimization.  */
604
 
605
  if (flag_exceptions && flag_reorder_blocks_and_partition)
606
    {
607
      inform
608
            ("-freorder-blocks-and-partition does not work with exceptions");
609
      flag_reorder_blocks_and_partition = 0;
610
      flag_reorder_blocks = 1;
611
    }
612
 
613
  /* If user requested unwind info, then turn off the partitioning
614
     optimization.  */
615
 
616
  if (flag_unwind_tables && ! targetm.unwind_tables_default
617
      && flag_reorder_blocks_and_partition)
618
    {
619
      inform ("-freorder-blocks-and-partition does not support unwind info");
620
      flag_reorder_blocks_and_partition = 0;
621
      flag_reorder_blocks = 1;
622
    }
623
 
624
  /* If the target requested unwind info, then turn off the partitioning
625
     optimization with a different message.  Likewise, if the target does not
626
     support named sections.  */
627
 
628
  if (flag_reorder_blocks_and_partition
629
      && (!targetm.have_named_sections
630
          || (flag_unwind_tables && targetm.unwind_tables_default)))
631
    {
632
      inform
633
       ("-freorder-blocks-and-partition does not work on this architecture");
634
      flag_reorder_blocks_and_partition = 0;
635
      flag_reorder_blocks = 1;
636
    }
637
}
638
 
639
/* Handle target- and language-independent options.  Return zero to
640
   generate an "unknown option" message.  Only options that need
641
   extra handling need to be listed here; if you simply want
642
   VALUE assigned to a variable, it happens automatically.  */
643
 
644
static int
645
common_handle_option (size_t scode, const char *arg, int value,
646
                      unsigned int lang_mask)
647
{
648
  enum opt_code code = (enum opt_code) scode;
649
 
650
  switch (code)
651
    {
652
    case OPT__help:
653
      print_help ();
654
      exit_after_options = true;
655
      break;
656
 
657
    case OPT__param:
658
      handle_param (arg);
659
      break;
660
 
661
    case OPT__target_help:
662
      print_target_help ();
663
      exit_after_options = true;
664
      break;
665
 
666
    case OPT__version:
667
      print_version (stderr, "");
668
      exit_after_options = true;
669
      break;
670
 
671
    case OPT_G:
672
      g_switch_value = value;
673
      g_switch_set = true;
674
      break;
675
 
676
    case OPT_O:
677
    case OPT_Os:
678
      /* Currently handled in a prescan.  */
679
      break;
680
 
681
    case OPT_W:
682
      /* For backward compatibility, -W is the same as -Wextra.  */
683
      set_Wextra (value);
684
      break;
685
 
686
    case OPT_Werror_:
687
      {
688
        char *new_option;
689
        int option_index;
690
        new_option = XNEWVEC (char, strlen (arg) + 2);
691
        new_option[0] = 'W';
692
        strcpy (new_option+1, arg);
693
        option_index = find_opt (new_option, lang_mask);
694
        if (option_index == N_OPTS)
695
          {
696
            error ("-Werror=%s: No option -%s", arg, new_option);
697
          }
698
        else
699
          {
700
            int kind = value ? DK_ERROR : DK_WARNING;
701
            diagnostic_classify_diagnostic (global_dc, option_index, kind);
702
 
703
            /* -Werror=foo implies -Wfoo.  */
704
            if (cl_options[option_index].var_type == CLVC_BOOLEAN
705
                && cl_options[option_index].flag_var
706
                && kind == DK_ERROR)
707
              *(int *) cl_options[option_index].flag_var = 1;
708
            free (new_option);
709
          }
710
      }
711
      break;
712
 
713
    case OPT_Wextra:
714
      set_Wextra (value);
715
      break;
716
 
717
    case OPT_Wlarger_than_:
718
      larger_than_size = value;
719
      warn_larger_than = value != -1;
720
      break;
721
 
722
    case OPT_Wstrict_aliasing:
723
    case OPT_Wstrict_aliasing_:
724
      warn_strict_aliasing = value;
725
      break;
726
 
727
    case OPT_Wstrict_overflow:
728
      warn_strict_overflow = (value
729
                              ? (int) WARN_STRICT_OVERFLOW_CONDITIONAL
730
                              : 0);
731
      break;
732
 
733
    case OPT_Wstrict_overflow_:
734
      warn_strict_overflow = value;
735
      break;
736
 
737
    case OPT_Wunused:
738
      set_Wunused (value);
739
      break;
740
 
741
    case OPT_aux_info:
742
    case OPT_aux_info_:
743
      aux_info_file_name = arg;
744
      flag_gen_aux_info = 1;
745
      break;
746
 
747
    case OPT_auxbase:
748
      aux_base_name = arg;
749
      break;
750
 
751
    case OPT_auxbase_strip:
752
      {
753
        char *tmp = xstrdup (arg);
754
        strip_off_ending (tmp, strlen (tmp));
755
        if (tmp[0])
756
          aux_base_name = tmp;
757
      }
758
      break;
759
 
760
    case OPT_d:
761
      decode_d_option (arg);
762
      break;
763
 
764
    case OPT_dumpbase:
765
      dump_base_name = arg;
766
      break;
767
 
768
    case OPT_falign_functions_:
769
      align_functions = value;
770
      break;
771
 
772
    case OPT_falign_jumps_:
773
      align_jumps = value;
774
      break;
775
 
776
    case OPT_falign_labels_:
777
      align_labels = value;
778
      break;
779
 
780
    case OPT_falign_loops_:
781
      align_loops = value;
782
      break;
783
 
784
    case OPT_fbranch_probabilities:
785
      flag_branch_probabilities_set = true;
786
      break;
787
 
788
    case OPT_fcall_used_:
789
      fix_register (arg, 0, 1);
790
      break;
791
 
792
    case OPT_fcall_saved_:
793
      fix_register (arg, 0, 0);
794
      break;
795
 
796
    case OPT_fdiagnostics_show_location_:
797
      if (!strcmp (arg, "once"))
798
        diagnostic_prefixing_rule (global_dc) = DIAGNOSTICS_SHOW_PREFIX_ONCE;
799
      else if (!strcmp (arg, "every-line"))
800
        diagnostic_prefixing_rule (global_dc)
801
          = DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE;
802
      else
803
        return 0;
804
      break;
805
 
806
    case OPT_fdiagnostics_show_option:
807
      global_dc->show_option_requested = true;
808
      break;
809
 
810
    case OPT_fdump_:
811
      if (!dump_switch_p (arg))
812
        return 0;
813
      break;
814
 
815
    case OPT_ffast_math:
816
      set_fast_math_flags (value);
817
      break;
818
 
819
    case OPT_ffixed_:
820
      fix_register (arg, 1, 1);
821
      break;
822
 
823
    case OPT_finline_limit_:
824
    case OPT_finline_limit_eq:
825
      set_param_value ("max-inline-insns-single", value / 2);
826
      set_param_value ("max-inline-insns-auto", value / 2);
827
      break;
828
 
829
    case OPT_fmessage_length_:
830
      pp_set_line_maximum_length (global_dc->printer, value);
831
      break;
832
 
833
    case OPT_fpack_struct_:
834
      if (value <= 0 || (value & (value - 1)) || value > 16)
835
        error("structure alignment must be a small power of two, not %d", value);
836
      else
837
        {
838
          initial_max_fld_align = value;
839
          maximum_field_alignment = value * BITS_PER_UNIT;
840
        }
841
      break;
842
 
843
    case OPT_fpeel_loops:
844
      flag_peel_loops_set = true;
845
      break;
846
 
847
    case OPT_fprofile_arcs:
848
      profile_arc_flag_set = true;
849
      break;
850
 
851
    case OPT_fprofile_use:
852
      if (!flag_branch_probabilities_set)
853
        flag_branch_probabilities = value;
854
      if (!flag_profile_values_set)
855
        flag_profile_values = value;
856
      if (!flag_unroll_loops_set)
857
        flag_unroll_loops = value;
858
      if (!flag_peel_loops_set)
859
        flag_peel_loops = value;
860
      if (!flag_tracer_set)
861
        flag_tracer = value;
862
      if (!flag_value_profile_transformations_set)
863
        flag_value_profile_transformations = value;
864
      break;
865
 
866
    case OPT_fprofile_generate:
867
      if (!profile_arc_flag_set)
868
        profile_arc_flag = value;
869
      if (!flag_profile_values_set)
870
        flag_profile_values = value;
871
      if (!flag_value_profile_transformations_set)
872
        flag_value_profile_transformations = value;
873
      break;
874
 
875
    case OPT_fprofile_values:
876
      flag_profile_values_set = true;
877
      break;
878
 
879
    case OPT_fvisibility_:
880
      {
881
        if (!strcmp(arg, "default"))
882
          default_visibility = VISIBILITY_DEFAULT;
883
        else if (!strcmp(arg, "internal"))
884
          default_visibility = VISIBILITY_INTERNAL;
885
        else if (!strcmp(arg, "hidden"))
886
          default_visibility = VISIBILITY_HIDDEN;
887
        else if (!strcmp(arg, "protected"))
888
          default_visibility = VISIBILITY_PROTECTED;
889
        else
890
          error ("unrecognized visibility value \"%s\"", arg);
891
      }
892
      break;
893
 
894
    case OPT_fvpt:
895
      flag_value_profile_transformations_set = true;
896
      break;
897
 
898
    case OPT_frandom_seed:
899
      /* The real switch is -fno-random-seed.  */
900
      if (value)
901
        return 0;
902
      flag_random_seed = NULL;
903
      break;
904
 
905
    case OPT_frandom_seed_:
906
      flag_random_seed = arg;
907
      break;
908
 
909
    case OPT_fsched_verbose_:
910
#ifdef INSN_SCHEDULING
911
      fix_sched_param ("verbose", arg);
912
      break;
913
#else
914
      return 0;
915
#endif
916
 
917
    case OPT_fsched_stalled_insns_:
918
      flag_sched_stalled_insns = value;
919
      if (flag_sched_stalled_insns == 0)
920
        flag_sched_stalled_insns = -1;
921
      break;
922
 
923
    case OPT_fsched_stalled_insns_dep_:
924
      flag_sched_stalled_insns_dep = value;
925
      break;
926
 
927
    case OPT_fstack_limit:
928
      /* The real switch is -fno-stack-limit.  */
929
      if (value)
930
        return 0;
931
      stack_limit_rtx = NULL_RTX;
932
      break;
933
 
934
    case OPT_fstack_limit_register_:
935
      {
936
        int reg = decode_reg_name (arg);
937
        if (reg < 0)
938
          error ("unrecognized register name \"%s\"", arg);
939
        else
940
          stack_limit_rtx = gen_rtx_REG (Pmode, reg);
941
      }
942
      break;
943
 
944
    case OPT_fstack_limit_symbol_:
945
      stack_limit_rtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (arg));
946
      break;
947
 
948
    case OPT_ftree_vectorizer_verbose_:
949
      vect_set_verbosity_level (arg);
950
      break;
951
 
952
    case OPT_ftls_model_:
953
      if (!strcmp (arg, "global-dynamic"))
954
        flag_tls_default = TLS_MODEL_GLOBAL_DYNAMIC;
955
      else if (!strcmp (arg, "local-dynamic"))
956
        flag_tls_default = TLS_MODEL_LOCAL_DYNAMIC;
957
      else if (!strcmp (arg, "initial-exec"))
958
        flag_tls_default = TLS_MODEL_INITIAL_EXEC;
959
      else if (!strcmp (arg, "local-exec"))
960
        flag_tls_default = TLS_MODEL_LOCAL_EXEC;
961
      else
962
        warning (0, "unknown tls-model \"%s\"", arg);
963
      break;
964
 
965
    case OPT_ftracer:
966
      flag_tracer_set = true;
967
      break;
968
 
969
    case OPT_funroll_loops:
970
      flag_unroll_loops_set = true;
971
      break;
972
 
973
    case OPT_g:
974
      set_debug_level (NO_DEBUG, DEFAULT_GDB_EXTENSIONS, arg);
975
      break;
976
 
977
    case OPT_gcoff:
978
      set_debug_level (SDB_DEBUG, false, arg);
979
      break;
980
 
981
    case OPT_gdwarf_2:
982
      set_debug_level (DWARF2_DEBUG, false, arg);
983
      break;
984
 
985
    case OPT_ggdb:
986
      set_debug_level (NO_DEBUG, 2, arg);
987
      break;
988
 
989
    case OPT_gstabs:
990
    case OPT_gstabs_:
991
      set_debug_level (DBX_DEBUG, code == OPT_gstabs_, arg);
992
      break;
993
 
994
    case OPT_gvms:
995
      set_debug_level (VMS_DEBUG, false, arg);
996
      break;
997
 
998
    case OPT_gxcoff:
999
    case OPT_gxcoff_:
1000
      set_debug_level (XCOFF_DEBUG, code == OPT_gxcoff_, arg);
1001
      break;
1002
 
1003
    case OPT_o:
1004
      asm_file_name = arg;
1005
      break;
1006
 
1007
    case OPT_pedantic_errors:
1008
      flag_pedantic_errors = pedantic = 1;
1009
      break;
1010
 
1011
    case OPT_fforce_mem:
1012
      warning (0, "-f[no-]force-mem is nop and option will be removed in 4.3");
1013
      break;
1014
 
1015
    case OPT_floop_optimize:
1016
    case OPT_frerun_loop_opt:
1017
    case OPT_fstrength_reduce:
1018
      /* These are no-ops, preserved for backward compatibility.  */
1019
      break;
1020
 
1021
    default:
1022
      /* If the flag was handled in a standard way, assume the lack of
1023
         processing here is intentional.  */
1024
      gcc_assert (cl_options[scode].flag_var);
1025
      break;
1026
    }
1027
 
1028
  return 1;
1029
}
1030
 
1031
/* Handle --param NAME=VALUE.  */
1032
static void
1033
handle_param (const char *carg)
1034
{
1035
  char *equal, *arg;
1036
  int value;
1037
 
1038
  arg = xstrdup (carg);
1039
  equal = strchr (arg, '=');
1040
  if (!equal)
1041
    error ("%s: --param arguments should be of the form NAME=VALUE", arg);
1042
  else
1043
    {
1044
      value = integral_argument (equal + 1);
1045
      if (value == -1)
1046
        error ("invalid --param value %qs", equal + 1);
1047
      else
1048
        {
1049
          *equal = '\0';
1050
          set_param_value (arg, value);
1051
        }
1052
    }
1053
 
1054
  free (arg);
1055
}
1056
 
1057
/* Handle -W and -Wextra.  */
1058
static void
1059
set_Wextra (int setting)
1060
{
1061
  extra_warnings = setting;
1062
  warn_unused_value = setting;
1063
  warn_unused_parameter = (setting && maybe_warn_unused_parameter);
1064
 
1065
  /* We save the value of warn_uninitialized, since if they put
1066
     -Wuninitialized on the command line, we need to generate a
1067
     warning about not using it without also specifying -O.  */
1068
  if (setting == 0)
1069
    warn_uninitialized = 0;
1070
  else if (warn_uninitialized != 1)
1071
    warn_uninitialized = 2;
1072
}
1073
 
1074
/* Initialize unused warning flags.  */
1075
void
1076
set_Wunused (int setting)
1077
{
1078
  warn_unused_function = setting;
1079
  warn_unused_label = setting;
1080
  /* Unused function parameter warnings are reported when either
1081
     ``-Wextra -Wunused'' or ``-Wunused-parameter'' is specified.
1082
     Thus, if -Wextra has already been seen, set warn_unused_parameter;
1083
     otherwise set maybe_warn_extra_parameter, which will be picked up
1084
     by set_Wextra.  */
1085
  maybe_warn_unused_parameter = setting;
1086
  warn_unused_parameter = (setting && extra_warnings);
1087
  warn_unused_variable = setting;
1088
  warn_unused_value = setting;
1089
}
1090
 
1091
/* The following routines are useful in setting all the flags that
1092
   -ffast-math and -fno-fast-math imply.  */
1093
void
1094
set_fast_math_flags (int set)
1095
{
1096
  flag_trapping_math = !set;
1097
  flag_unsafe_math_optimizations = set;
1098
  flag_finite_math_only = set;
1099
  flag_errno_math = !set;
1100
  if (set)
1101
    {
1102
      flag_signaling_nans = 0;
1103
      flag_rounding_math = 0;
1104
      flag_cx_limited_range = 1;
1105
    }
1106
}
1107
 
1108
/* Return true iff flags are set as if -ffast-math.  */
1109
bool
1110
fast_math_flags_set_p (void)
1111
{
1112
  return (!flag_trapping_math
1113
          && flag_unsafe_math_optimizations
1114
          && flag_finite_math_only
1115
          && !flag_errno_math);
1116
}
1117
 
1118
/* Handle a debug output -g switch.  EXTENDED is true or false to support
1119
   extended output (2 is special and means "-ggdb" was given).  */
1120
static void
1121
set_debug_level (enum debug_info_type type, int extended, const char *arg)
1122
{
1123
  static bool type_explicit;
1124
 
1125
  use_gnu_debug_info_extensions = extended;
1126
 
1127
  if (type == NO_DEBUG)
1128
    {
1129
      if (write_symbols == NO_DEBUG)
1130
        {
1131
          write_symbols = PREFERRED_DEBUGGING_TYPE;
1132
 
1133
          if (extended == 2)
1134
            {
1135
#ifdef DWARF2_DEBUGGING_INFO
1136
              write_symbols = DWARF2_DEBUG;
1137
#elif defined DBX_DEBUGGING_INFO
1138
              write_symbols = DBX_DEBUG;
1139
#endif
1140
            }
1141
 
1142
          if (write_symbols == NO_DEBUG)
1143
            warning (0, "target system does not support debug output");
1144
        }
1145
    }
1146
  else
1147
    {
1148
      /* Does it conflict with an already selected type?  */
1149
      if (type_explicit && write_symbols != NO_DEBUG && type != write_symbols)
1150
        error ("debug format \"%s\" conflicts with prior selection",
1151
               debug_type_names[type]);
1152
      write_symbols = type;
1153
      type_explicit = true;
1154
    }
1155
 
1156
  /* A debug flag without a level defaults to level 2.  */
1157
  if (*arg == '\0')
1158
    {
1159
      if (!debug_info_level)
1160
        debug_info_level = 2;
1161
    }
1162
  else
1163
    {
1164
      debug_info_level = integral_argument (arg);
1165
      if (debug_info_level == (unsigned int) -1)
1166
        error ("unrecognised debug output level \"%s\"", arg);
1167
      else if (debug_info_level > 3)
1168
        error ("debug output level %s is too high", arg);
1169
    }
1170
}
1171
 
1172
/* Display help for target options.  */
1173
static void
1174
print_target_help (void)
1175
{
1176
  unsigned int i;
1177
  static bool displayed = false;
1178
 
1179
  /* Avoid double printing for --help --target-help.  */
1180
  if (displayed)
1181
    return;
1182
 
1183
  displayed = true;
1184
  for (i = 0; i < cl_options_count; i++)
1185
    if ((cl_options[i].flags & (CL_TARGET | CL_UNDOCUMENTED)) == CL_TARGET)
1186
      {
1187
        printf (_("\nTarget specific options:\n"));
1188
        print_filtered_help (CL_TARGET);
1189
        break;
1190
      }
1191
}
1192
 
1193
/* Output --help text.  */
1194
static void
1195
print_help (void)
1196
{
1197
  size_t i;
1198
  const char *p;
1199
 
1200
  GET_ENVIRONMENT (p, "COLUMNS");
1201
  if (p)
1202
    {
1203
      int value = atoi (p);
1204
      if (value > 0)
1205
        columns = value;
1206
    }
1207
 
1208
  puts (_("The following options are language-independent:\n"));
1209
 
1210
  print_filtered_help (CL_COMMON);
1211
  print_param_help ();
1212
 
1213
  for (i = 0; lang_names[i]; i++)
1214
    {
1215
      printf (_("The %s front end recognizes the following options:\n\n"),
1216
              lang_names[i]);
1217
      print_filtered_help (1U << i);
1218
    }
1219
  print_target_help ();
1220
}
1221
 
1222
/* Print the help for --param.  */
1223
static void
1224
print_param_help (void)
1225
{
1226
  size_t i;
1227
 
1228
  puts (_("The --param option recognizes the following as parameters:\n"));
1229
 
1230
  for (i = 0; i < LAST_PARAM; i++)
1231
    {
1232
      const char *help = compiler_params[i].help;
1233
      const char *param = compiler_params[i].option;
1234
 
1235
      if (help == NULL || *help == '\0')
1236
        help = undocumented_msg;
1237
 
1238
      /* Get the translation.  */
1239
      help = _(help);
1240
 
1241
      wrap_help (help, param, strlen (param));
1242
    }
1243
 
1244
  putchar ('\n');
1245
}
1246
 
1247
/* Print help for a specific front-end, etc.  */
1248
static void
1249
print_filtered_help (unsigned int flag)
1250
{
1251
  unsigned int i, len, filter, indent = 0;
1252
  bool duplicates = false;
1253
  const char *help, *opt, *tab;
1254
  static char *printed;
1255
 
1256
  if (flag == CL_COMMON || flag == CL_TARGET)
1257
    {
1258
      filter = flag;
1259
      if (!printed)
1260
        printed = xmalloc (cl_options_count);
1261
      memset (printed, 0, cl_options_count);
1262
    }
1263
  else
1264
    {
1265
      /* Don't print COMMON options twice.  */
1266
      filter = flag | CL_COMMON;
1267
 
1268
      for (i = 0; i < cl_options_count; i++)
1269
        {
1270
          if ((cl_options[i].flags & filter) != flag)
1271
            continue;
1272
 
1273
          /* Skip help for internal switches.  */
1274
          if (cl_options[i].flags & CL_UNDOCUMENTED)
1275
            continue;
1276
 
1277
          /* Skip switches that have already been printed, mark them to be
1278
             listed later.  */
1279
          if (printed[i])
1280
            {
1281
              duplicates = true;
1282
              indent = print_switch (cl_options[i].opt_text, indent);
1283
            }
1284
        }
1285
 
1286
      if (duplicates)
1287
        {
1288
          putchar ('\n');
1289
          putchar ('\n');
1290
        }
1291
    }
1292
 
1293
  for (i = 0; i < cl_options_count; i++)
1294
    {
1295
      if ((cl_options[i].flags & filter) != flag)
1296
        continue;
1297
 
1298
      /* Skip help for internal switches.  */
1299
      if (cl_options[i].flags & CL_UNDOCUMENTED)
1300
        continue;
1301
 
1302
      /* Skip switches that have already been printed.  */
1303
      if (printed[i])
1304
        continue;
1305
 
1306
      printed[i] = true;
1307
 
1308
      help = cl_options[i].help;
1309
      if (!help)
1310
        help = undocumented_msg;
1311
 
1312
      /* Get the translation.  */
1313
      help = _(help);
1314
 
1315
      tab = strchr (help, '\t');
1316
      if (tab)
1317
        {
1318
          len = tab - help;
1319
          opt = help;
1320
          help = tab + 1;
1321
        }
1322
      else
1323
        {
1324
          opt = cl_options[i].opt_text;
1325
          len = strlen (opt);
1326
        }
1327
 
1328
      wrap_help (help, opt, len);
1329
    }
1330
 
1331
  putchar ('\n');
1332
}
1333
 
1334
/* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1335
   word-wrapped HELP in a second column.  */
1336
static unsigned int
1337
print_switch (const char *text, unsigned int indent)
1338
{
1339
  unsigned int len = strlen (text) + 1; /* trailing comma */
1340
 
1341
  if (indent)
1342
    {
1343
      putchar (',');
1344
      if (indent + len > columns)
1345
        {
1346
          putchar ('\n');
1347
          putchar (' ');
1348
          indent = 1;
1349
        }
1350
    }
1351
  else
1352
    putchar (' ');
1353
 
1354
  putchar (' ');
1355
  fputs (text, stdout);
1356
 
1357
  return indent + len + 1;
1358
}
1359
 
1360
/* Output ITEM, of length ITEM_WIDTH, in the left column, followed by
1361
   word-wrapped HELP in a second column.  */
1362
static void
1363
wrap_help (const char *help, const char *item, unsigned int item_width)
1364
{
1365
  unsigned int col_width = 27;
1366
  unsigned int remaining, room, len;
1367
 
1368
  remaining = strlen (help);
1369
 
1370
  do
1371
    {
1372
      room = columns - 3 - MAX (col_width, item_width);
1373
      if (room > columns)
1374
        room = 0;
1375
      len = remaining;
1376
 
1377
      if (room < len)
1378
        {
1379
          unsigned int i;
1380
 
1381
          for (i = 0; help[i]; i++)
1382
            {
1383
              if (i >= room && len != remaining)
1384
                break;
1385
              if (help[i] == ' ')
1386
                len = i;
1387
              else if ((help[i] == '-' || help[i] == '/')
1388
                       && help[i + 1] != ' '
1389
                       && i > 0 && ISALPHA (help[i - 1]))
1390
                len = i + 1;
1391
            }
1392
        }
1393
 
1394
      printf( "  %-*.*s %.*s\n", col_width, item_width, item, len, help);
1395
      item_width = 0;
1396
      while (help[len] == ' ')
1397
        len++;
1398
      help += len;
1399
      remaining -= len;
1400
    }
1401
  while (remaining);
1402
}
1403
 
1404
/* Return 1 if OPTION is enabled, 0 if it is disabled, or -1 if it isn't
1405
   a simple on-off switch.  */
1406
 
1407
int
1408
option_enabled (int opt_idx)
1409
{
1410
  const struct cl_option *option = &(cl_options[opt_idx]);
1411
  if (option->flag_var)
1412
    switch (option->var_type)
1413
      {
1414
      case CLVC_BOOLEAN:
1415
        return *(int *) option->flag_var != 0;
1416
 
1417
      case CLVC_EQUAL:
1418
        return *(int *) option->flag_var == option->var_value;
1419
 
1420
      case CLVC_BIT_CLEAR:
1421
        return (*(int *) option->flag_var & option->var_value) == 0;
1422
 
1423
      case CLVC_BIT_SET:
1424
        return (*(int *) option->flag_var & option->var_value) != 0;
1425
 
1426
      case CLVC_STRING:
1427
        break;
1428
      }
1429
  return -1;
1430
}
1431
 
1432
/* Fill STATE with the current state of option OPTION.  Return true if
1433
   there is some state to store.  */
1434
 
1435
bool
1436
get_option_state (int option, struct cl_option_state *state)
1437
{
1438
  if (cl_options[option].flag_var == 0)
1439
    return false;
1440
 
1441
  switch (cl_options[option].var_type)
1442
    {
1443
    case CLVC_BOOLEAN:
1444
    case CLVC_EQUAL:
1445
      state->data = cl_options[option].flag_var;
1446
      state->size = sizeof (int);
1447
      break;
1448
 
1449
    case CLVC_BIT_CLEAR:
1450
    case CLVC_BIT_SET:
1451
      state->ch = option_enabled (option);
1452
      state->data = &state->ch;
1453
      state->size = 1;
1454
      break;
1455
 
1456
    case CLVC_STRING:
1457
      state->data = *(const char **) cl_options[option].flag_var;
1458
      if (state->data == 0)
1459
        state->data = "";
1460
      state->size = strlen (state->data) + 1;
1461
      break;
1462
    }
1463
  return true;
1464
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.