2021-09-02 08:14:01 +00:00
|
|
|
//===-- runtime/main.cpp --------------------------------------------------===//
|
2020-01-08 13:27:32 -08:00
|
|
|
//
|
|
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
|
//
|
2020-01-10 12:12:03 -08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2020-01-08 13:27:32 -08:00
|
|
|
|
2021-09-01 16:00:53 -07:00
|
|
|
#include "flang/Runtime/main.h"
|
2020-01-23 16:59:27 -08:00
|
|
|
#include "environment.h"
|
2020-01-08 13:27:32 -08:00
|
|
|
#include "terminator.h"
|
|
|
|
|
#include <cfenv>
|
2020-01-16 13:51:25 -08:00
|
|
|
#include <cstdio>
|
2020-01-08 13:27:32 -08:00
|
|
|
#include <cstdlib>
|
2020-01-09 14:01:40 -08:00
|
|
|
|
2020-01-16 13:51:25 -08:00
|
|
|
static void ConfigureFloatingPoint() {
|
2020-03-28 21:00:16 -07:00
|
|
|
#ifdef feclearexcept // a macro in some environments; omit std::
|
2020-01-09 14:01:40 -08:00
|
|
|
feclearexcept(FE_ALL_EXCEPT);
|
|
|
|
|
#else
|
2020-01-08 13:27:32 -08:00
|
|
|
std::feclearexcept(FE_ALL_EXCEPT);
|
2020-01-09 14:01:40 -08:00
|
|
|
#endif
|
|
|
|
|
#ifdef fesetround
|
|
|
|
|
fesetround(FE_TONEAREST);
|
|
|
|
|
#else
|
2020-01-08 13:27:32 -08:00
|
|
|
std::fesetround(FE_TONEAREST);
|
2020-01-09 14:01:40 -08:00
|
|
|
#endif
|
2020-01-16 13:51:25 -08:00
|
|
|
}
|
2020-01-09 14:01:40 -08:00
|
|
|
|
2020-01-16 13:51:25 -08:00
|
|
|
extern "C" {
|
2022-07-19 11:47:25 -07:00
|
|
|
void RTNAME(ProgramStart)(int argc, const char *argv[], const char *envp[],
|
|
|
|
|
const EnvironmentDefaultList *envDefaults) {
|
2020-01-08 13:27:32 -08:00
|
|
|
std::atexit(Fortran::runtime::NotifyOtherImagesOfNormalEnd);
|
2022-07-19 11:47:25 -07:00
|
|
|
Fortran::runtime::executionEnvironment.Configure(
|
|
|
|
|
argc, argv, envp, envDefaults);
|
2020-01-16 13:51:25 -08:00
|
|
|
ConfigureFloatingPoint();
|
2020-02-13 14:41:56 -08:00
|
|
|
// I/O is initialized on demand so that it works for non-Fortran main().
|
2020-01-08 13:27:32 -08:00
|
|
|
}
|
2020-07-21 17:37:35 -07:00
|
|
|
|
|
|
|
|
void RTNAME(ByteswapOption)() {
|
|
|
|
|
if (Fortran::runtime::executionEnvironment.conversion ==
|
|
|
|
|
Fortran::runtime::Convert::Unknown) {
|
|
|
|
|
// The environment variable overrides the command-line option;
|
|
|
|
|
// either of them take precedence over explicit OPEN(CONVERT=) specifiers.
|
|
|
|
|
Fortran::runtime::executionEnvironment.conversion =
|
|
|
|
|
Fortran::runtime::Convert::Swap;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-08 13:27:32 -08:00
|
|
|
}
|