Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libgfortran / runtime / main.c
blob19c975f927f3d75256f3d64ba6c1c7b811b0f175
1 /* Copyright (C) 2002-2003 Free Software Foundation, Inc.
2 Contributed by Andy Vaught and Paul Brook <paul@nowt.org>
4 This file is part of the GNU Fortran 95 runtime library (libgfortran).
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.
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.)
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.
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, 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. */
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <math.h>
34 #include <stddef.h>
36 #include "libgfortran.h"
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;
44 /* Figure out endianness for this machine. */
46 static void
47 determine_endianness (void)
49 union
51 GFC_LOGICAL_8 l8;
52 GFC_LOGICAL_4 l4[2];
53 } u;
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");
65 static int argc_save;
66 static char **argv_save;
68 /* Set the saved values of the command line arguments. */
70 void
71 set_args (int argc, char **argv)
73 argc_save = argc;
74 argv_save = argv;
77 /* Retrieve the saved values of the command line arguments. */
79 void
80 get_args (int *argc, char ***argv)
82 *argc = argc_save;
83 *argv = argv_save;
87 /* Initialize the runtime library. */
89 static void __attribute__((constructor))
90 init (void)
92 /* Figure out the machine endianness. */
93 determine_endianness ();
95 /* Must be first */
96 init_variables ();
98 init_units ();
100 #ifdef DEBUG
101 /* Check for special command lines. */
103 if (argc > 1 && strcmp (argv[1], "--help") == 0)
104 show_variables ();
106 /* if (argc > 1 && strcmp(argv[1], "--resume") == 0) resume(); */
107 #endif
109 random_seed(NULL,NULL,NULL);
113 /* Cleanup the runtime library. */
115 static void __attribute__((destructor))
116 cleanup ()
118 close_units ();