OSDN Git Service

77204309aaedda1bee9f5b5b24b758b152782c5d
[pf3gnuchains/gcc-fork.git] / libgfortran / runtime / main.c
1 /* Copyright (C) 2002-2003, 2005 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 (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 <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <math.h>
34 #include <stddef.h>
35
36 #include "libgfortran.h"
37
38 /* This is the offset (in bytes) required to cast from logical(8)* to
39    logical(4)*. and still get the same result.  Will be 0 for little-endian
40    machines and 4 for big-endian machines.  */
41 int l8_to_l4_offset = 0;
42
43
44 /* Figure out endianness for this machine.  */
45
46 static void
47 determine_endianness (void)
48 {
49   union
50   {
51     GFC_LOGICAL_8 l8;
52     GFC_LOGICAL_4 l4[2];
53   } u;
54
55   u.l8 = 1;
56   if (u.l4[0])
57     l8_to_l4_offset = 0;
58   else if (u.l4[1])
59     l8_to_l4_offset = 1;
60   else
61     runtime_error ("Unable to determine machine endianness");
62 }
63
64
65 static int argc_save;
66 static char **argv_save;
67
68 /* Set the saved values of the command line arguments.  */
69
70 void
71 set_args (int argc, char **argv)
72 {
73   argc_save = argc;
74   argv_save = argv;
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   init_compile_options ();
100
101 #ifdef DEBUG
102   /* Check for special command lines.  */
103
104   if (argc > 1 && strcmp (argv[1], "--help") == 0)
105     show_variables ();
106
107   /* if (argc > 1 && strcmp(argv[1], "--resume") == 0) resume();  */
108 #endif
109
110   random_seed(NULL,NULL,NULL);
111 }
112
113
114 /* Cleanup the runtime library.  */
115
116 static void __attribute__((destructor))
117 cleanup (void)
118 {
119   close_units ();
120 }