OSDN Git Service

PR fortran/31832
[pf3gnuchains/gcc-fork.git] / libgfortran / runtime / compile_options.c
1 /* Handling of compile-time options that influence the library.
2    Copyright (C) 2005, 2007 Free Software Foundation, Inc.
3
4 This file is part of the GNU Fortran 95 runtime library (libgfortran).
5
6 Libgfortran is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 In addition to the permissions in the GNU General Public License, the
12 Free Software Foundation gives you unlimited permission to link the
13 compiled version of this file into combinations with other programs,
14 and to distribute those combinations without any restriction coming
15 from the use of this file.  (The General Public License restrictions
16 do apply in other respects; for example, they cover modification of
17 the file, and distribution when not linked into a combine
18 executable.)
19
20 Libgfortran is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with libgfortran; see the file COPYING.  If not, write to
27 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
28 Boston, MA 02110-1301, USA.  */
29
30 #include "libgfortran.h"
31
32 #ifdef HAVE_SIGNAL_H
33 #include <signal.h>
34 #endif
35
36
37 /* Useful compile-time options will be stored in here.  */
38 compile_options_t compile_options;
39
40
41 /* A signal handler to allow us to output a backtrace.  */
42 void
43 handler (int signum)
44 {
45   const char * name = NULL, * desc = NULL;
46
47   switch (signum)
48     {
49 #if defined(SIGSEGV)
50       case SIGSEGV:
51         name = "SIGSEGV";
52         desc = "Segmentation fault";
53         break;
54 #endif
55
56 #if defined(SIGBUS)
57       case SIGBUS:
58         name = "SIGBUS";
59         desc = "Bus error";
60         break;
61 #endif
62
63 #if defined(SIGILL)
64       case SIGILL:
65         name = "SIGILL";
66         desc = "Illegal instruction";
67         break;
68 #endif
69
70 #if defined(SIGFPE)
71       case SIGFPE:
72         name = "SIGFPE";
73         desc = "Floating-point exception";
74         break;
75 #endif
76     }
77
78   if (name)
79     st_printf ("\nProgram received signal %d (%s): %s.\n", signum, name, desc);
80   else
81     st_printf ("\nProgram received signal %d.\n", signum);
82
83   sys_exit (5);
84 }
85
86
87 /* Set the usual compile-time options.  */
88 extern void set_options (int , int []);
89 export_proto(set_options);
90
91 void
92 set_options (int num, int options[])
93 {
94   if (num >= 1)
95     compile_options.warn_std = options[0];
96   if (num >= 2)
97     compile_options.allow_std = options[1];
98   if (num >= 3)
99     compile_options.pedantic = options[2];
100   if (num >= 4)
101     compile_options.dump_core = options[3];
102   if (num >= 5)
103     compile_options.backtrace = options[4];
104   if (num >= 6)
105     compile_options.sign_zero = options[5];
106   if (num >= 7)
107     compile_options.bounds_check = options[6];
108   if (num >= 8)
109     compile_options.range_check = options[7];
110
111   /* If backtrace is required, we set signal handlers on most common
112      signals.  */
113 #if defined(HAVE_SIGNAL) && (defined(SIGSEGV) || defined(SIGBUS) \
114                              || defined(SIGILL) || defined(SIGFPE))
115   if (compile_options.backtrace)
116     {
117 #if defined(SIGSEGV)
118       signal (SIGSEGV, handler);
119 #endif
120
121 #if defined(SIGBUS)
122       signal (SIGBUS, handler);
123 #endif
124
125 #if defined(SIGILL)
126       signal (SIGILL, handler);
127 #endif
128
129 #if defined(SIGFPE)
130       signal (SIGFPE, handler);
131 #endif
132     }
133 #endif
134
135 }
136
137
138 /* Default values for the compile-time options.  Keep in sync with
139    gcc/fortran/options.c (gfc_init_options).  */
140 void
141 init_compile_options (void)
142 {
143   compile_options.warn_std = GFC_STD_F95_DEL | GFC_STD_LEGACY;
144   compile_options.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
145     | GFC_STD_F2003 | GFC_STD_F2008 | GFC_STD_F95 | GFC_STD_F77
146     | GFC_STD_GNU | GFC_STD_LEGACY;
147   compile_options.pedantic = 0;
148   compile_options.dump_core = 0;
149   compile_options.backtrace = 0;
150   compile_options.sign_zero = 1;
151   compile_options.range_check = 1;
152 }
153
154 /* Function called by the front-end to tell us the
155    default for unformatted data conversion.  */
156
157 extern void set_convert (int);
158 export_proto (set_convert);
159
160 void
161 set_convert (int conv)
162 {
163   compile_options.convert = conv;
164 }
165
166 extern void set_record_marker (int);
167 export_proto (set_record_marker);
168
169
170 void
171 set_record_marker (int val)
172 {
173
174   switch(val)
175     {
176     case 4:
177       compile_options.record_marker = sizeof (GFC_INTEGER_4);
178       break;
179
180     case 8:
181       compile_options.record_marker = sizeof (GFC_INTEGER_8);
182       break;
183
184     default:
185       runtime_error ("Invalid value for record marker");
186       break;
187     }
188 }
189
190 extern void set_max_subrecord_length (int);
191 export_proto (set_max_subrecord_length);
192
193 void set_max_subrecord_length(int val)
194 {
195   if (val > GFC_MAX_SUBRECORD_LENGTH || val < 1)
196     {
197       runtime_error ("Invalid value for maximum subrecord length");
198       return;
199     }
200
201   compile_options.max_subrecord_length = val;
202 }