1 /* Parse and display command line options.
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3 Free Software Foundation, Inc.
4 Contributed by Andy Vaught
6 This file is part of GCC.
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 2, or (at your option) any later
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
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
25 #include "coretypes.h"
32 #include "tree-inline.h"
36 gfc_option_t gfc_option;
39 /* Set flags that control warnings and errors for different
40 Fortran standards to their default values. */
43 set_default_std_flags (void)
45 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
46 | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F77 | GFC_STD_GNU
48 gfc_option.warn_std = GFC_STD_F95_DEL | GFC_STD_LEGACY;
51 /* Get ready for options handling. */
54 gfc_init_options (unsigned int argc ATTRIBUTE_UNUSED,
55 const char **argv ATTRIBUTE_UNUSED)
57 gfc_source_file = NULL;
58 gfc_option.module_dir = NULL;
59 gfc_option.source_form = FORM_UNKNOWN;
60 gfc_option.fixed_line_length = 72;
61 gfc_option.free_line_length = 132;
62 gfc_option.max_continue_fixed = 19;
63 gfc_option.max_continue_free = 39;
64 gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
65 gfc_option.max_subrecord_length = 0;
66 gfc_option.convert = CONVERT_NATIVE;
67 gfc_option.record_marker = 0;
68 gfc_option.verbose = 0;
70 gfc_option.warn_aliasing = 0;
71 gfc_option.warn_ampersand = 0;
72 gfc_option.warn_character_truncation = 0;
73 gfc_option.warn_conversion = 0;
74 gfc_option.warn_implicit_interface = 0;
75 gfc_option.warn_line_truncation = 0;
76 gfc_option.warn_surprising = 0;
77 gfc_option.warn_tabs = 1;
78 gfc_option.warn_underflow = 1;
79 gfc_option.max_errors = 25;
81 gfc_option.flag_all_intrinsics = 0;
82 gfc_option.flag_default_double = 0;
83 gfc_option.flag_default_integer = 0;
84 gfc_option.flag_default_real = 0;
85 gfc_option.flag_dollar_ok = 0;
86 gfc_option.flag_underscoring = 1;
87 gfc_option.flag_f2c = 0;
88 gfc_option.flag_second_underscore = -1;
89 gfc_option.flag_implicit_none = 0;
90 gfc_option.flag_max_stack_var_size = 32768;
91 gfc_option.flag_range_check = 1;
92 gfc_option.flag_pack_derived = 0;
93 gfc_option.flag_repack_arrays = 0;
94 gfc_option.flag_preprocessed = 0;
95 gfc_option.flag_automatic = 1;
96 gfc_option.flag_backslash = 1;
97 gfc_option.flag_backtrace = 0;
98 gfc_option.flag_allow_leading_underscore = 0;
99 gfc_option.flag_dump_core = 0;
100 gfc_option.flag_external_blas = 0;
101 gfc_option.blas_matmul_limit = 30;
102 gfc_option.flag_cray_pointer = 0;
103 gfc_option.flag_d_lines = -1;
104 gfc_option.flag_openmp = 0;
108 /* Argument pointers cannot point to anything but their argument. */
109 flag_argument_noalias = 3;
113 set_default_std_flags ();
115 gfc_option.warn_nonstd_intrinsics = 0;
117 /* -fshort-enums can be default on some targets. */
118 gfc_option.fshort_enums = targetm.default_short_enums ();
124 /* Determine the source form from the filename extension. We assume
125 case insensitivity. */
127 static gfc_source_form
128 form_from_filename (const char *filename)
132 const char *extension;
133 gfc_source_form form;
154 }; /* sentinel value */
156 gfc_source_form f_form;
160 /* Find end of file name. Note, filename is either a NULL pointer or
161 a NUL terminated string. */
163 while (filename[i] != '\0')
166 /* Find last period. */
167 while (i >= 0 && (filename[i] != '.'))
170 /* Did we see a file extension? */
172 return FORM_UNKNOWN; /* Nope */
174 /* Get file extension and compare it to others. */
175 fileext = &(filename[i]);
178 f_form = FORM_UNKNOWN;
182 if (strcasecmp (fileext, exttype[i].extension) == 0)
184 f_form = exttype[i].form;
188 while (exttype[i].form != FORM_UNKNOWN);
194 /* Finalize commandline options. */
197 gfc_post_options (const char **pfilename)
199 const char *filename = *pfilename, *canon_source_file = NULL;
203 /* Verify the input file name. */
204 if (!filename || strcmp (filename, "-") == 0)
209 if (gfc_option.flag_preprocessed)
211 /* For preprocessed files, if the first tokens are of the form # NUM.
212 handle the directives so we know the original file name. */
213 gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
214 if (gfc_source_file == NULL)
215 gfc_source_file = filename;
217 *pfilename = gfc_source_file;
220 gfc_source_file = filename;
222 if (canon_source_file == NULL)
223 canon_source_file = gfc_source_file;
225 /* Adds the path where the source file is to the list of include files. */
227 i = strlen (canon_source_file);
228 while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
233 source_path = alloca (i + 1);
234 memcpy (source_path, canon_source_file, i);
236 gfc_add_include_path (source_path, true);
239 gfc_add_include_path (".", true);
241 if (canon_source_file != gfc_source_file)
242 gfc_free ((void *) canon_source_file);
244 /* Decide which form the file will be read in as. */
246 if (gfc_option.source_form != FORM_UNKNOWN)
247 gfc_current_form = gfc_option.source_form;
250 gfc_current_form = form_from_filename (filename);
252 if (gfc_current_form == FORM_UNKNOWN)
254 gfc_current_form = FORM_FREE;
255 gfc_warning_now ("Reading file '%s' as free form",
256 (filename[0] == '\0') ? "<stdin>" : filename);
260 /* If the user specified -fd-lines-as-{code|comments} verify that we're
262 if (gfc_current_form == FORM_FREE)
264 if (gfc_option.flag_d_lines == 0)
265 gfc_warning_now ("'-fd-lines-as-comments' has no effect "
267 else if (gfc_option.flag_d_lines == 1)
268 gfc_warning_now ("'-fd-lines-as-code' has no effect in free form");
271 flag_inline_trees = 1;
273 /* Use tree inlining. */
276 if (flag_inline_functions)
277 flag_inline_trees = 2;
279 /* If -pedantic, warn about the use of GNU extensions. */
280 if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
281 gfc_option.warn_std |= GFC_STD_GNU;
282 /* -std=legacy -pedantic is effectively -std=gnu. */
283 if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
284 gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
286 /* If the user didn't explicitly specify -f(no)-second-underscore we
287 use it if we're trying to be compatible with f2c, and not
289 if (gfc_option.flag_second_underscore == -1)
290 gfc_option.flag_second_underscore = gfc_option.flag_f2c;
292 /* Implement -fno-automatic as -fmax-stack-var-size=0. */
293 if (!gfc_option.flag_automatic)
294 gfc_option.flag_max_stack_var_size = 0;
298 gfc_option.warn_ampersand = 1;
299 gfc_option.warn_tabs = 0;
302 if (gfc_option.flag_all_intrinsics)
303 gfc_option.warn_nonstd_intrinsics = 0;
309 /* Set the options for -Wall. */
312 set_Wall (int setting)
314 gfc_option.warn_aliasing = setting;
315 gfc_option.warn_ampersand = setting;
316 gfc_option.warn_line_truncation = setting;
317 gfc_option.warn_nonstd_intrinsics = setting;
318 gfc_option.warn_surprising = setting;
319 gfc_option.warn_tabs = !setting;
320 gfc_option.warn_underflow = setting;
321 gfc_option.warn_character_truncation = setting;
323 set_Wunused (setting);
324 warn_return_type = setting;
325 warn_switch = setting;
327 /* We save the value of warn_uninitialized, since if they put
328 -Wuninitialized on the command line, we need to generate a
329 warning about not using it without also specifying -O. */
331 warn_uninitialized = 0;
332 else if (warn_uninitialized != 1)
333 warn_uninitialized = 2;
338 gfc_handle_module_path_options (const char *arg)
341 if (gfc_option.module_dir != NULL)
343 gfc_status ("gfortran: Only one -M option allowed\n");
349 gfc_status ("gfortran: Directory required after -M\n");
353 gfc_option.module_dir = (char *) gfc_getmem (strlen (arg) + 2);
354 strcpy (gfc_option.module_dir, arg);
355 strcat (gfc_option.module_dir, "/");
357 gfc_add_include_path (gfc_option.module_dir, true);
362 gfc_handle_fpe_trap_option (const char *arg)
364 int result, pos = 0, n;
365 static const char * const exception[] = { "invalid", "denormal", "zero",
366 "overflow", "underflow",
368 static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
369 GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
370 GFC_FPE_UNDERFLOW, GFC_FPE_PRECISION,
378 while (arg[pos] && arg[pos] != ',')
382 for (n = 0; exception[n] != NULL; n++)
384 if (exception[n] && strncmp (exception[n], arg, pos) == 0)
386 gfc_option.fpe |= opt_exception[n];
394 gfc_fatal_error ("Argument to -ffpe-trap is not valid: %s", arg);
399 /* Handle command-line options. Returns 0 if unrecognized, 1 if
400 recognized and handled. */
403 gfc_handle_option (size_t scode, const char *arg, int value)
406 enum opt_code code = (enum opt_code) scode;
408 /* Ignore file names. */
423 gfc_option.warn_aliasing = value;
427 gfc_option.warn_ampersand = value;
430 case OPT_Wcharacter_truncation:
431 gfc_option.warn_character_truncation = value;
434 case OPT_Wconversion:
435 gfc_option.warn_conversion = value;
438 case OPT_Wimplicit_interface:
439 gfc_option.warn_implicit_interface = value;
442 case OPT_Wline_truncation:
443 gfc_option.warn_line_truncation = value;
446 case OPT_Wsurprising:
447 gfc_option.warn_surprising = value;
451 gfc_option.warn_tabs = value;
455 gfc_option.warn_underflow = value;
458 case OPT_fall_intrinsics:
459 gfc_option.flag_all_intrinsics = 1;
463 gfc_option.flag_automatic = value;
466 case OPT_fallow_leading_underscore:
467 gfc_option.flag_allow_leading_underscore = value;
471 gfc_option.flag_backslash = value;
475 gfc_option.flag_backtrace = value;
479 gfc_option.flag_dump_core = value;
482 case OPT_fcray_pointer:
483 gfc_option.flag_cray_pointer = value;
487 gfc_option.flag_f2c = value;
491 gfc_option.flag_dollar_ok = value;
494 case OPT_fexternal_blas:
495 gfc_option.flag_external_blas = value;
498 case OPT_fblas_matmul_limit_:
499 gfc_option.blas_matmul_limit = value;
502 case OPT_fd_lines_as_code:
503 gfc_option.flag_d_lines = 1;
506 case OPT_fd_lines_as_comments:
507 gfc_option.flag_d_lines = 0;
510 case OPT_fdump_parse_tree:
511 gfc_option.verbose = value;
514 case OPT_ffixed_form:
515 gfc_option.source_form = FORM_FIXED;
518 case OPT_ffixed_line_length_none:
519 gfc_option.fixed_line_length = 0;
522 case OPT_ffixed_line_length_:
523 if (value != 0 && value < 7)
524 gfc_fatal_error ("Fixed line length must be at least seven.");
525 gfc_option.fixed_line_length = value;
529 gfc_option.source_form = FORM_FREE;
533 gfc_option.flag_openmp = value;
536 case OPT_ffree_line_length_none:
537 gfc_option.free_line_length = 0;
540 case OPT_ffree_line_length_:
541 if (value != 0 && value < 4)
542 gfc_fatal_error ("Free line length must be at least three.");
543 gfc_option.free_line_length = value;
546 case OPT_funderscoring:
547 gfc_option.flag_underscoring = value;
550 case OPT_fsecond_underscore:
551 gfc_option.flag_second_underscore = value;
554 case OPT_static_libgfortran:
555 #ifndef HAVE_LD_STATIC_DYNAMIC
556 gfc_fatal_error ("-static-libgfortran is not supported in this "
561 case OPT_fimplicit_none:
562 gfc_option.flag_implicit_none = value;
565 case OPT_fintrinsic_modules_path:
566 gfc_add_include_path (arg, false);
567 gfc_add_intrinsic_modules_path (arg);
570 case OPT_fmax_errors_:
571 gfc_option.max_errors = value;
574 case OPT_fmax_stack_var_size_:
575 gfc_option.flag_max_stack_var_size = value;
578 case OPT_frange_check:
579 gfc_option.flag_range_check = value;
582 case OPT_fpack_derived:
583 gfc_option.flag_pack_derived = value;
586 case OPT_frepack_arrays:
587 gfc_option.flag_repack_arrays = value;
590 case OPT_fpreprocessed:
591 gfc_option.flag_preprocessed = value;
594 case OPT_fmax_identifier_length_:
595 if (value > GFC_MAX_SYMBOL_LEN)
596 gfc_fatal_error ("Maximum supported identifier length is %d",
598 gfc_option.max_identifier_length = value;
601 case OPT_fdefault_integer_8:
602 gfc_option.flag_default_integer = value;
605 case OPT_fdefault_real_8:
606 gfc_option.flag_default_real = value;
609 case OPT_fdefault_double_8:
610 gfc_option.flag_default_double = value;
614 gfc_add_include_path (arg, true);
619 gfc_handle_module_path_options (arg);
623 gfc_handle_fpe_trap_option (arg);
627 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77;
628 gfc_option.warn_std = GFC_STD_F95_OBS;
629 gfc_option.max_identifier_length = 31;
630 gfc_option.warn_ampersand = 1;
631 gfc_option.warn_tabs = 0;
635 gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
636 | GFC_STD_F2003 | GFC_STD_F95;
637 gfc_option.warn_std = GFC_STD_F95_OBS;
638 gfc_option.max_continue_fixed = 255;
639 gfc_option.max_continue_free = 255;
640 gfc_option.max_identifier_length = 63;
641 gfc_option.warn_ampersand = 1;
642 gfc_option.warn_tabs = 0;
646 set_default_std_flags ();
650 set_default_std_flags ();
651 gfc_option.warn_std = 0;
654 case OPT_Wnonstd_intrinsics:
655 gfc_option.warn_nonstd_intrinsics = value;
658 case OPT_fshort_enums:
659 gfc_option.fshort_enums = 1;
662 case OPT_fconvert_little_endian:
663 gfc_option.convert = CONVERT_LITTLE;
666 case OPT_fconvert_big_endian:
667 gfc_option.convert = CONVERT_BIG;
670 case OPT_fconvert_native:
671 gfc_option.convert = CONVERT_NATIVE;
674 case OPT_fconvert_swap:
675 gfc_option.convert = CONVERT_SWAP;
678 case OPT_frecord_marker_4:
679 gfc_option.record_marker = 4;
682 case OPT_frecord_marker_8:
683 gfc_option.record_marker = 8;
686 case OPT_fmax_subrecord_length_:
687 if (value > MAX_SUBRECORD_LENGTH)
688 gfc_fatal_error ("Maximum subrecord length cannot exceed %d",
689 MAX_SUBRECORD_LENGTH);
691 gfc_option.max_subrecord_length = value;