]>
Commit | Line | Data |
---|---|---|
6de9cd9a DN |
1 | /* Copyright (C) 2002-2003 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 95 runtime library (libgfor). | |
5 | ||
6 | Libgfor 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 | Libgfor 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 | You should have received a copy of the GNU General Public License | |
17 | along with libgfor; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include <stdio.h> | |
22 | #include <stdlib.h> | |
23 | #include <string.h> | |
24 | #include <math.h> | |
25 | #include <stddef.h> | |
26 | ||
27 | #include "libgfortran.h" | |
28 | ||
29 | /* This is the offset (in bytes) required to cast from logical(8)* to | |
30 | logical(4)*. and still get the same result. Will be 0 for little-endian | |
31 | machines and 4 for big-endian machines. */ | |
7d7b8bfe | 32 | int l8_to_l4_offset = 0; |
6de9cd9a DN |
33 | |
34 | ||
35 | /* Figure out endianness for this machine. */ | |
36 | ||
6de9cd9a DN |
37 | static void |
38 | determine_endianness (void) | |
39 | { | |
40 | union | |
41 | { | |
42 | GFC_LOGICAL_8 l8; | |
43 | GFC_LOGICAL_4 l4[2]; | |
44 | } u; | |
45 | ||
46 | u.l8 = 1; | |
47 | if (u.l4[0]) | |
48 | l8_to_l4_offset = 0; | |
49 | else if (u.l4[1]) | |
50 | l8_to_l4_offset = 1; | |
51 | else | |
52 | runtime_error ("Unable to determine machine endianness"); | |
53 | } | |
54 | ||
55 | ||
56 | static int argc_save; | |
57 | static char **argv_save; | |
58 | ||
59 | /* Set the saved values of the command line arguments. */ | |
60 | ||
61 | void | |
62 | set_args (int argc, char **argv) | |
63 | { | |
64 | argc_save = argc; | |
65 | argv_save = argv; | |
66 | } | |
67 | ||
68 | /* Retrieve the saved values of the command line arguments. */ | |
69 | ||
70 | void | |
71 | get_args (int *argc, char ***argv) | |
72 | { | |
6de9cd9a DN |
73 | *argc = argc_save; |
74 | *argv = argv_save; | |
75 | } | |
76 | ||
77 | ||
78 | /* Initialize the runtime library. */ | |
79 | ||
80 | static void __attribute__((constructor)) | |
81 | init (void) | |
82 | { | |
83 | /* Figure out the machine endianness. */ | |
84 | determine_endianness (); | |
85 | ||
86 | /* Must be first */ | |
87 | init_variables (); | |
88 | ||
89 | init_units (); | |
90 | ||
91 | #ifdef DEBUG | |
92 | /* Check for special command lines. */ | |
93 | ||
94 | if (argc > 1 && strcmp (argv[1], "--help") == 0) | |
95 | show_variables (); | |
96 | ||
7d7b8bfe | 97 | /* if (argc > 1 && strcmp(argv[1], "--resume") == 0) resume(); */ |
6de9cd9a DN |
98 | #endif |
99 | ||
abdef811 | 100 | random_seed(NULL,NULL,NULL); |
6de9cd9a DN |
101 | } |
102 | ||
103 | ||
104 | /* Cleanup the runtime library. */ | |
105 | ||
106 | static void __attribute__((destructor)) | |
107 | cleanup () | |
108 | { | |
109 | close_units (); | |
110 | } |