OSDN Git Service

PR libfortran/21185
[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
109   /* If backtrace is required, we set signal handlers on most common
110      signals.  */
111 #if defined(HAVE_SIGNAL) && (defined(SIGSEGV) || defined(SIGBUS) \
112                              || defined(SIGILL) || defined(SIGFPE))
113   if (compile_options.backtrace)
114     {
115 #if defined(SIGSEGV)
116       signal (SIGSEGV, handler);
117 #endif
118
119 #if defined(SIGBUS)
120       signal (SIGBUS, handler);
121 #endif
122
123 #if defined(SIGILL)
124       signal (SIGILL, handler);
125 #endif
126
127 #if defined(SIGFPE)
128       signal (SIGFPE, handler);
129 #endif
130     }
131 #endif
132
133 }
134
135
136 /* Default values for the compile-time options.  Keep in sync with
137    gcc/fortran/options.c (gfc_init_options).  */
138 void
139 init_compile_options (void)
140 {
141   compile_options.warn_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
142     | GFC_STD_F2003 | GFC_STD_LEGACY;
143   compile_options.allow_std = GFC_STD_F95_OBS | GFC_STD_F95_DEL
144     | GFC_STD_F2003 | GFC_STD_F95 | GFC_STD_F77 | GFC_STD_GNU | GFC_STD_LEGACY;
145   compile_options.pedantic = 0;
146   compile_options.dump_core = 0;
147   compile_options.backtrace = 0;
148   compile_options.sign_zero = 1;
149 }
150
151 /* Function called by the front-end to tell us the
152    default for unformatted data conversion.  */
153
154 extern void set_convert (int);
155 export_proto (set_convert);
156
157 void
158 set_convert (int conv)
159 {
160   compile_options.convert = conv;
161 }
162
163 extern void set_record_marker (int);
164 export_proto (set_record_marker);
165
166
167 void
168 set_record_marker (int val)
169 {
170
171   switch(val)
172     {
173     case 4:
174       compile_options.record_marker = sizeof (GFC_INTEGER_4);
175       break;
176
177     case 8:
178       compile_options.record_marker = sizeof (GFC_INTEGER_8);
179       break;
180
181     default:
182       runtime_error ("Invalid value for record marker");
183       break;
184     }
185 }
186
187 extern void set_max_subrecord_length (int);
188 export_proto (set_max_subrecord_length);
189
190 void set_max_subrecord_length(int val)
191 {
192   if (val > GFC_MAX_SUBRECORD_LENGTH || val < 1)
193     {
194       runtime_error ("Invalid value for maximum subrecord length");
195       return;
196     }
197
198   compile_options.max_subrecord_length = val;
199 }