111
|
1 /* Copyright (C) 2002-2017 Free Software Foundation, Inc.
|
|
2 Contributed by Andy Vaught and Paul Brook <paul@nowt.org>
|
|
3
|
|
4 This file is part of the GNU Fortran 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 3, or (at your option)
|
|
9 any later version.
|
|
10
|
|
11 Libgfortran is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14 GNU General Public License for more details.
|
|
15
|
|
16 Under Section 7 of GPL version 3, you are granted additional
|
|
17 permissions described in the GCC Runtime Library Exception, version
|
|
18 3.1, as published by the Free Software Foundation.
|
|
19
|
|
20 You should have received a copy of the GNU General Public License and
|
|
21 a copy of the GCC Runtime Library Exception along with this program;
|
|
22 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
23 <http://www.gnu.org/licenses/>. */
|
|
24
|
|
25 #include "libgfortran.h"
|
|
26
|
|
27
|
|
28 /* Stupid function to be sure the constructor is always linked in, even
|
|
29 in the case of static linking. See PR libfortran/22298 for details. */
|
|
30 void
|
|
31 stupid_function_name_for_static_linking (void)
|
|
32 {
|
|
33 return;
|
|
34 }
|
|
35
|
|
36 /* This will be 0 for little-endian
|
|
37 machines and 1 for big-endian machines. */
|
|
38 int big_endian = 0;
|
|
39
|
|
40
|
|
41 /* Figure out endianness for this machine. */
|
|
42
|
|
43 static void
|
|
44 determine_endianness (void)
|
|
45 {
|
|
46 union
|
|
47 {
|
|
48 GFC_LOGICAL_8 l8;
|
|
49 GFC_LOGICAL_4 l4[2];
|
|
50 } u;
|
|
51
|
|
52 u.l8 = 1;
|
|
53 if (u.l4[0])
|
|
54 big_endian = 0;
|
|
55 else if (u.l4[1])
|
|
56 big_endian = 1;
|
|
57 else
|
|
58 runtime_error ("Unable to determine machine endianness");
|
|
59 }
|
|
60
|
|
61
|
|
62 static int argc_save;
|
|
63 static char **argv_save;
|
|
64
|
|
65
|
|
66 /* Set the saved values of the command line arguments. */
|
|
67
|
|
68 void
|
|
69 set_args (int argc, char **argv)
|
|
70 {
|
|
71 argc_save = argc;
|
|
72 argv_save = argv;
|
|
73 }
|
|
74 iexport(set_args);
|
|
75
|
|
76
|
|
77 /* Retrieve the saved values of the command line arguments. */
|
|
78
|
|
79 void
|
|
80 get_args (int *argc, char ***argv)
|
|
81 {
|
|
82 *argc = argc_save;
|
|
83 *argv = argv_save;
|
|
84 }
|
|
85
|
|
86
|
|
87 /* Initialize the runtime library. */
|
|
88
|
|
89 static void __attribute__((constructor))
|
|
90 init (void)
|
|
91 {
|
|
92 /* Figure out the machine endianness. */
|
|
93 determine_endianness ();
|
|
94
|
|
95 /* Must be first */
|
|
96 init_variables ();
|
|
97
|
|
98 init_units ();
|
|
99
|
|
100 /* If (and only if) the user asked for it, set up the FPU state. */
|
|
101 if (options.fpe != 0)
|
|
102 set_fpu ();
|
|
103
|
|
104 init_compile_options ();
|
|
105 }
|
|
106
|
|
107
|
|
108 /* Cleanup the runtime library. */
|
|
109
|
|
110 static void __attribute__((destructor))
|
|
111 cleanup (void)
|
|
112 {
|
|
113 close_units ();
|
|
114 }
|