OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [fortran/] [options.c] - Blame information for rev 12

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 12 jlechner
/* Parse and display command line options.
2
   Copyright (C) 2000, 2001, 2002, 2003, 2004,
3
   2005, 2006 Free Software Foundation, Inc.
4
   Contributed by Andy Vaught
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 2, 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 COPYING.  If not, write to the Free
20
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21
02110-1301, USA.  */
22
 
23
 
24
#include "config.h"
25
#include "system.h"
26
#include "coretypes.h"
27
#include "tree.h"
28
#include "flags.h"
29
#include "intl.h"
30
#include "opts.h"
31
#include "options.h"
32
#include "tree-inline.h"
33
 
34
#include "gfortran.h"
35
#include "target.h"
36
 
37
gfc_option_t gfc_option;
38
 
39
 
40
/* Get ready for options handling.  */
41
 
42
unsigned int
43
gfc_init_options (unsigned int argc ATTRIBUTE_UNUSED,
44
                  const char **argv ATTRIBUTE_UNUSED)
45
{
46
  gfc_source_file = NULL;
47
  gfc_option.module_dir = NULL;
48
  gfc_option.source_form = FORM_UNKNOWN;
49
  gfc_option.fixed_line_length = -1;
50
  gfc_option.free_line_length = -1;
51
  gfc_option.max_identifier_length = GFC_MAX_SYMBOL_LEN;
52
  gfc_option.verbose = 0;
53
 
54
  gfc_option.warn_aliasing = 0;
55
  gfc_option.warn_ampersand = 0;
56
  gfc_option.warn_conversion = 0;
57
  gfc_option.warn_implicit_interface = 0;
58
  gfc_option.warn_line_truncation = 0;
59
  gfc_option.warn_surprising = 0;
60
  gfc_option.warn_underflow = 1;
61
  gfc_option.warn_unused_labels = 0;
62
 
63
  gfc_option.flag_default_double = 0;
64
  gfc_option.flag_default_integer = 0;
65
  gfc_option.flag_default_real = 0;
66
  gfc_option.flag_dollar_ok = 0;
67
  gfc_option.flag_underscoring = 1;
68
  gfc_option.flag_f2c = 0;
69
  gfc_option.flag_second_underscore = -1;
70
  gfc_option.flag_implicit_none = 0;
71
  gfc_option.flag_max_stack_var_size = 32768;
72
  gfc_option.flag_module_access_private = 0;
73
  gfc_option.flag_no_backend = 0;
74
  gfc_option.flag_pack_derived = 0;
75
  gfc_option.flag_repack_arrays = 0;
76
  gfc_option.flag_preprocessed = 0;
77
  gfc_option.flag_automatic = 1;
78
  gfc_option.flag_backslash = 1;
79
  gfc_option.flag_cray_pointer = 0;
80
  gfc_option.flag_d_lines = -1;
81
 
82
  gfc_option.q_kind = gfc_default_double_kind;
83
 
84
  gfc_option.fpe = 0;
85
 
86
  flag_argument_noalias = 2;
87
  flag_errno_math = 0;
88
 
89
  gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
90
    | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F77 | GFC_STD_GNU
91
    | GFC_STD_LEGACY;
92
  gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
93
    | GFC_STD_LEGACY;
94
 
95
  gfc_option.warn_nonstd_intrinsics = 0;
96
 
97
  /* -fshort-enums can be default on some targets.  */
98
  gfc_option.fshort_enums = targetm.default_short_enums ();
99
 
100
  return CL_Fortran;
101
}
102
 
103
 
104
/* Determine the source form from the filename extension.  We assume
105
   case insensitivity.  */
106
 
107
static gfc_source_form
108
form_from_filename (const char *filename)
109
{
110
 
111
  static const struct
112
  {
113
    const char *extension;
114
    gfc_source_form form;
115
  }
116
  exttype[] =
117
  {
118
    {
119
    ".f90", FORM_FREE}
120
    ,
121
    {
122
    ".f95", FORM_FREE}
123
    ,
124
    {
125
    ".f", FORM_FIXED}
126
    ,
127
    {
128
    ".for", FORM_FIXED}
129
    ,
130
    {
131
    "", FORM_UNKNOWN}
132
  };            /* sentinel value */
133
 
134
  gfc_source_form f_form;
135
  const char *fileext;
136
  int i;
137
 
138
  /* Find end of file name.  Note, filename is either a NULL pointer or
139
     a NUL terminated string.  */
140
  i = 0;
141
  while (filename[i] != '\0')
142
    i++;
143
 
144
  /* Find last period.  */
145
  while (i >= 0 && (filename[i] != '.'))
146
    i--;
147
 
148
  /* Did we see a file extension?  */
149
  if (i < 0)
150
    return FORM_UNKNOWN; /* Nope  */
151
 
152
  /* Get file extension and compare it to others.  */
153
  fileext = &(filename[i]);
154
 
155
  i = -1;
156
  f_form = FORM_UNKNOWN;
157
  do
158
    {
159
      i++;
160
      if (strcasecmp (fileext, exttype[i].extension) == 0)
161
        {
162
          f_form = exttype[i].form;
163
          break;
164
        }
165
    }
166
  while (exttype[i].form != FORM_UNKNOWN);
167
 
168
  return f_form;
169
}
170
 
171
 
172
/* Finalize commandline options.  */
173
 
174
bool
175
gfc_post_options (const char **pfilename)
176
{
177
  const char *filename = *pfilename, *canon_source_file = NULL;
178
  char *source_path;
179
  int i;
180
 
181
  /* Verify the input file name.  */
182
  if (!filename || strcmp (filename, "-") == 0)
183
    {
184
      filename = "";
185
    }
186
 
187
  if (gfc_option.flag_preprocessed)
188
    {
189
      /* For preprocessed files, if the first tokens are of the form # NUM.
190
         handle the directives so we know the original file name.  */
191
      gfc_source_file = gfc_read_orig_filename (filename, &canon_source_file);
192
      if (gfc_source_file == NULL)
193
        gfc_source_file = filename;
194
      else
195
        *pfilename = gfc_source_file;
196
    }
197
  else
198
    gfc_source_file = filename;
199
 
200
  if (canon_source_file == NULL)
201
    canon_source_file = gfc_source_file;
202
 
203
  /* Adds the path where the source file is to the list of include files.  */
204
 
205
  i = strlen (canon_source_file);
206
  while (i > 0 && !IS_DIR_SEPARATOR (canon_source_file[i]))
207
    i--;
208
  if (i != 0)
209
    {
210
      source_path = alloca (i + 1);
211
      memcpy (source_path, canon_source_file, i);
212
      source_path[i] = 0;
213
      gfc_add_include_path (source_path);
214
    }
215
  else
216
    gfc_add_include_path (".");
217
 
218
  if (canon_source_file != gfc_source_file)
219
    gfc_free ((void *) canon_source_file);
220
 
221
  /* Decide which form the file will be read in as.  */
222
 
223
  if (gfc_option.source_form != FORM_UNKNOWN)
224
    gfc_current_form = gfc_option.source_form;
225
  else
226
    {
227
      gfc_current_form = form_from_filename (filename);
228
 
229
      if (gfc_current_form == FORM_UNKNOWN)
230
        {
231
          gfc_current_form = FORM_FREE;
232
          gfc_warning_now ("Reading file '%s' as free form.",
233
                           (filename[0] == '\0') ? "<stdin>" : filename);
234
        }
235
    }
236
 
237
  /* If the user specified -fd-lines-as-{code|comments} verify that we're
238
     in fixed form.  */
239
  if (gfc_current_form == FORM_FREE)
240
    {
241
      if (gfc_option.flag_d_lines == 0)
242
        gfc_warning_now ("'-fd-lines-as-comments' has no effect "
243
                         "in free form.");
244
      else if (gfc_option.flag_d_lines == 1)
245
        gfc_warning_now ("'-fd-lines-as-code' has no effect "
246
                         "in free form.");
247
    }
248
 
249
  flag_inline_trees = 1;
250
 
251
  /* Use tree inlining.  */
252
  if (!flag_no_inline)
253
    flag_no_inline = 1;
254
  if (flag_inline_functions)
255
    flag_inline_trees = 2;
256
 
257
  /* If -pedantic, warn about the use of GNU extensions.  */
258
  if (pedantic && (gfc_option.allow_std & GFC_STD_GNU) != 0)
259
    gfc_option.warn_std |= GFC_STD_GNU;
260
  /* -std=legacy -pedantic is effectively -std=gnu.  */
261
  if (pedantic && (gfc_option.allow_std & GFC_STD_LEGACY) != 0)
262
    gfc_option.warn_std |= GFC_STD_F95_OBS | GFC_STD_F95_DEL | GFC_STD_LEGACY;
263
 
264
  /* If the user didn't explicitly specify -f(no)-second-underscore we
265
     use it if we're trying to be compatible with f2c, and not
266
     otherwise.  */
267
  if (gfc_option.flag_second_underscore == -1)
268
    gfc_option.flag_second_underscore = gfc_option.flag_f2c;
269
 
270
  /* Implement -fno-automatic as -fmax-stack-var-size=0.  */
271
  if (!gfc_option.flag_automatic)
272
    gfc_option.flag_max_stack_var_size = 0;
273
 
274
  if (pedantic)
275
    gfc_option.warn_ampersand = 1;
276
 
277
  return false;
278
}
279
 
280
 
281
/* Set the options for -Wall.  */
282
 
283
static void
284
set_Wall (void)
285
{
286
 
287
  gfc_option.warn_aliasing = 1;
288
  gfc_option.warn_ampersand = 1;
289
  gfc_option.warn_line_truncation = 1;
290
  gfc_option.warn_nonstd_intrinsics = 1;
291
  gfc_option.warn_surprising = 1;
292
  gfc_option.warn_underflow = 1;
293
  gfc_option.warn_unused_labels = 1;
294
 
295
  set_Wunused (1);
296
  warn_return_type = 1;
297
  warn_switch = 1;
298
 
299
  /* We save the value of warn_uninitialized, since if they put
300
     -Wuninitialized on the command line, we need to generate a
301
     warning about not using it without also specifying -O.  */
302
 
303
  if (warn_uninitialized != 1)
304
    warn_uninitialized = 2;
305
}
306
 
307
 
308
static void
309
gfc_handle_module_path_options (const char *arg)
310
{
311
 
312
  if (gfc_option.module_dir != NULL)
313
    {
314
      gfc_status ("gfortran: Only one -M option allowed\n");
315
      exit (3);
316
    }
317
 
318
  if (arg == NULL)
319
    {
320
      gfc_status ("gfortran: Directory required after -M\n");
321
      exit (3);
322
    }
323
 
324
  gfc_option.module_dir = (char *) gfc_getmem (strlen (arg) + 2);
325
  strcpy (gfc_option.module_dir, arg);
326
  strcat (gfc_option.module_dir, "/");
327
}
328
 
329
static void
330
gfc_handle_fpe_trap_option (const char *arg)
331
{
332
  int result, pos = 0, n;
333
  static const char * const exception[] = { "invalid", "denormal", "zero",
334
                                            "overflow", "underflow",
335
                                            "precision", NULL };
336
  static const int opt_exception[] = { GFC_FPE_INVALID, GFC_FPE_DENORMAL,
337
                                       GFC_FPE_ZERO, GFC_FPE_OVERFLOW,
338
                                       GFC_FPE_UNDERFLOW, GFC_FPE_PRECISION,
339
 
340
 
341
  while (*arg)
342
    {
343
      while (*arg == ',')
344
        arg++;
345
      while (arg[pos] && arg[pos] != ',')
346
        pos++;
347
      result = 0;
348
      for (n = 0; exception[n] != NULL; n++)
349
        {
350
          if (exception[n] && strncmp (exception[n], arg, pos) == 0)
351
            {
352
              gfc_option.fpe |= opt_exception[n];
353
              arg += pos;
354
              pos = 0;
355
              result = 1;
356
              break;
357
            }
358
        }
359
      if (! result)
360
        gfc_fatal_error ("Argument to -ffpe-trap is not valid: %s", arg);
361
    }
362
}
363
 
364
/* Handle command-line options.  Returns 0 if unrecognized, 1 if
365
   recognized and handled.  */
366
int
367
gfc_handle_option (size_t scode, const char *arg, int value)
368
{
369
  int result = 1;
370
  enum opt_code code = (enum opt_code) scode;
371
 
372
  /* Ignore file names.  */
373
  if (code == N_OPTS)
374
    return 1;
375
 
376
  switch (code)
377
    {
378
    default:
379
      result = 0;
380
      break;
381
 
382
    case OPT_Wall:
383
      set_Wall ();
384
      break;
385
 
386
    case OPT_Waliasing:
387
      gfc_option.warn_aliasing = value;
388
      break;
389
 
390
    case OPT_Wampersand:
391
      gfc_option.warn_ampersand = value;
392
      break;
393
 
394
    case OPT_Wconversion:
395
      gfc_option.warn_conversion = value;
396
      break;
397
 
398
    case OPT_Wimplicit_interface:
399
      gfc_option.warn_implicit_interface = value;
400
      break;
401
 
402
    case OPT_Wline_truncation:
403
      gfc_option.warn_line_truncation = value;
404
      break;
405
 
406
    case OPT_Wsurprising:
407
      gfc_option.warn_surprising = value;
408
      break;
409
 
410
    case OPT_Wunderflow:
411
      gfc_option.warn_underflow = value;
412
      break;
413
 
414
    case OPT_Wunused_labels:
415
      gfc_option.warn_unused_labels = value;
416
      break;
417
 
418
    case OPT_fcray_pointer:
419
      gfc_option.flag_cray_pointer = value;
420
      break;
421
 
422
    case OPT_ff2c:
423
      gfc_option.flag_f2c = value;
424
      break;
425
 
426
    case OPT_fdollar_ok:
427
      gfc_option.flag_dollar_ok = value;
428
      break;
429
 
430
    case OPT_fautomatic:
431
      gfc_option.flag_automatic = value;
432
      break;
433
 
434
    case OPT_fbackslash:
435
      gfc_option.flag_backslash = value;
436
      break;
437
 
438
    case OPT_fd_lines_as_code:
439
      gfc_option.flag_d_lines = 1;
440
      break;
441
 
442
    case OPT_fd_lines_as_comments:
443
      gfc_option.flag_d_lines = 0;
444
      break;
445
 
446
    case OPT_fdump_parse_tree:
447
      gfc_option.verbose = value;
448
      break;
449
 
450
    case OPT_ffixed_form:
451
      gfc_option.source_form = FORM_FIXED;
452
      break;
453
 
454
    case OPT_ffixed_line_length_none:
455
      gfc_option.fixed_line_length = 0;
456
      break;
457
 
458
    case OPT_ffixed_line_length_:
459
      if (value != 0 && value < 7)
460
        gfc_fatal_error ("Fixed line length must be at least seven.");
461
      gfc_option.fixed_line_length = value;
462
      break;
463
 
464
    case OPT_ffree_form:
465
      gfc_option.source_form = FORM_FREE;
466
      break;
467
 
468
    case OPT_ffree_line_length_none:
469
      gfc_option.free_line_length = 0;
470
      break;
471
 
472
    case OPT_ffree_line_length_:
473
      gfc_option.free_line_length = value;
474
      break;
475
 
476
    case OPT_funderscoring:
477
      gfc_option.flag_underscoring = value;
478
      break;
479
 
480
    case OPT_fsecond_underscore:
481
      gfc_option.flag_second_underscore = value;
482
      break;
483
 
484
    case OPT_fimplicit_none:
485
      gfc_option.flag_implicit_none = value;
486
      break;
487
 
488
    case OPT_fmax_stack_var_size_:
489
      gfc_option.flag_max_stack_var_size = value;
490
      break;
491
 
492
    case OPT_fmodule_private:
493
      gfc_option.flag_module_access_private = value;
494
      break;
495
 
496
    case OPT_fno_backend:
497
      gfc_option.flag_no_backend = value;
498
      break;
499
 
500
    case OPT_fpack_derived:
501
      gfc_option.flag_pack_derived = value;
502
      break;
503
 
504
    case OPT_frepack_arrays:
505
      gfc_option.flag_repack_arrays = value;
506
      break;
507
 
508
    case OPT_fpreprocessed:
509
      gfc_option.flag_preprocessed = value;
510
      break;
511
 
512
    case OPT_fmax_identifier_length_:
513
      if (value > GFC_MAX_SYMBOL_LEN)
514
        gfc_fatal_error ("Maximum supported idenitifier length is %d",
515
                         GFC_MAX_SYMBOL_LEN);
516
      gfc_option.max_identifier_length = value;
517
      break;
518
 
519
    case OPT_qkind_:
520
      if (gfc_validate_kind (BT_REAL, value, true) < 0)
521
        gfc_fatal_error ("Argument to -fqkind isn't a valid real kind");
522
      gfc_option.q_kind = value;
523
      break;
524
 
525
    case OPT_fdefault_integer_8:
526
      gfc_option.flag_default_integer = value;
527
      break;
528
 
529
    case OPT_fdefault_real_8:
530
      gfc_option.flag_default_real = value;
531
      break;
532
 
533
    case OPT_fdefault_double_8:
534
      gfc_option.flag_default_double = value;
535
      break;
536
 
537
    case OPT_I:
538
      gfc_add_include_path (arg);
539
      break;
540
 
541
    case OPT_J:
542
    case OPT_M:
543
      gfc_handle_module_path_options (arg);
544
      break;
545
 
546
    case OPT_ffpe_trap_:
547
      gfc_handle_fpe_trap_option (arg);
548
      break;
549
 
550
    case OPT_std_f95:
551
      gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95 | GFC_STD_F77;
552
      gfc_option.warn_std = GFC_STD_F95_OBS;
553
      gfc_option.max_identifier_length = 31;
554
      gfc_option.warn_ampersand = 1;
555
      break;
556
 
557
    case OPT_std_f2003:
558
      gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F77
559
        | GFC_STD_F2003 | GFC_STD_F95;
560
      gfc_option.warn_std = GFC_STD_F95_OBS;
561
      gfc_option.max_identifier_length = 63;
562
      break;
563
 
564
    case OPT_std_gnu:
565
      gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
566
        | GFC_STD_F77 | GFC_STD_F95 | GFC_STD_F2003
567
        | GFC_STD_GNU | GFC_STD_LEGACY;
568
      gfc_option.warn_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
569
        | GFC_STD_LEGACY;
570
      break;
571
 
572
    case OPT_std_legacy:
573
      gfc_option.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
574
        | GFC_STD_F77 | GFC_STD_F95 | GFC_STD_F2003
575
        | GFC_STD_GNU | GFC_STD_LEGACY;
576
      gfc_option.warn_std = 0;
577
      break;
578
 
579
    case OPT_Wnonstd_intrinsics:
580
      gfc_option.warn_nonstd_intrinsics = 1;
581
      break;
582
 
583
    case OPT_fshort_enums:
584
      gfc_option.fshort_enums = 1;
585
      break;
586
 
587
    case OPT_fconvert_little_endian:
588
      gfc_option.convert = CONVERT_LITTLE;
589
      break;
590
 
591
    case OPT_fconvert_big_endian:
592
      gfc_option.convert = CONVERT_BIG;
593
      break;
594
 
595
    case OPT_fconvert_native:
596
      gfc_option.convert = CONVERT_NATIVE;
597
      break;
598
 
599
    case OPT_fconvert_swap:
600
      gfc_option.convert = CONVERT_SWAP;
601
      break;
602
 
603
    case OPT_frecord_marker_4:
604
      gfc_option.record_marker = 4;
605
      break;
606
 
607
    case OPT_frecord_marker_8:
608
      gfc_option.record_marker = 8;
609
      break;
610
    }
611
 
612
  return result;
613
}

powered by: WebSVN 2.1.0

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