OSDN Git Service

* config/i386/i386.md (lshr<mode>3): Macroize expander from
[pf3gnuchains/gcc-fork.git] / libgfortran / runtime / stop.c
1 /* Implementation of the STOP statement.
2    Copyright 2002, 2005, 2007, 2009, 2010 Free Software Foundation, Inc.
3    Contributed by Paul Brook <paul@nowt.org>
4
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
6
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public
9 License as published by the Free Software Foundation; either
10 version 3 of the License, or (at your option) any later version.
11
12 Libgfortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
20
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
24 <http://www.gnu.org/licenses/>.  */
25
26 #include "libgfortran.h"
27 #include <string.h>
28
29 /* A numeric STOP statement.  */
30
31 extern void stop_numeric (GFC_INTEGER_4)
32   __attribute__ ((noreturn));
33 export_proto(stop_numeric);
34
35 void
36 stop_numeric (GFC_INTEGER_4 code)
37 {
38   st_printf ("STOP %d\n", (int)code);
39   sys_exit (code);
40 }
41
42 /* A character string or blank STOP statement.  */
43
44 void
45 stop_string (const char *string, GFC_INTEGER_4 len)
46 {
47   if (string)
48     {
49       st_printf ("STOP ");
50       while (len--)
51         st_printf ("%c", *(string++));
52       st_printf ("\n");
53     }
54   sys_exit (0);
55 }
56
57
58 /* Per Fortran 2008, section 8.4:  "Execution of a STOP statement initiates
59    normal termination of execution. Execution of an ERROR STOP statement
60    initiates error termination of execution."  Thus, error_stop_string returns
61    a nonzero exit status code.  */
62
63 extern void error_stop_string (const char *, GFC_INTEGER_4)
64   __attribute__ ((noreturn));
65 export_proto(error_stop_string);
66
67 void
68 error_stop_string (const char *string, GFC_INTEGER_4 len)
69 {
70   st_printf ("ERROR STOP ");
71   while (len--)
72     st_printf ("%c", *(string++));
73   st_printf ("\n");
74
75   sys_exit (1);
76 }
77
78 /* A numeric or blank ERROR STOP statement.  */
79
80 extern void error_stop_numeric (GFC_INTEGER_4)
81   __attribute__ ((noreturn));
82 export_proto(error_stop_numeric);
83
84 void
85 error_stop_numeric (GFC_INTEGER_4 code)
86 {
87   st_printf ("ERROR STOP %d\n", (int) code);
88   sys_exit (code);
89 }
90
91 extern void error_stop_string (const char *, GFC_INTEGER_4);
92 export_proto(error_stop_string);
93
94
95 /* Per Fortran 2008, section 8.4:  "Execution of a STOP statement initiates
96    normal termination of execution. Execution of an ERROR STOP statement
97    initiates error termination of execution."  Thus, error_stop_string returns
98    a nonzero exit status code.  */
99 void
100 error_stop_string (const char *string, GFC_INTEGER_4 len)
101 {
102   st_printf ("ERROR STOP ");
103   while (len--)
104     st_printf ("%c", *(string++));
105   st_printf ("\n");
106
107   sys_exit (1);
108 }