49 lines · cpp
1//===-- lib/runtime/main.cpp ------------------------------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "flang/Runtime/main.h"10#include "flang-rt/runtime/environment.h"11#include "flang-rt/runtime/terminator.h"12#include <cfenv>13#include <cstdio>14#include <cstdlib>15 16static void ConfigureFloatingPoint() {17#ifdef feclearexcept // a macro in some environments; omit std::18 feclearexcept(FE_ALL_EXCEPT);19#else20 std::feclearexcept(FE_ALL_EXCEPT);21#endif22#ifdef fesetround23 fesetround(FE_TONEAREST);24#else25 std::fesetround(FE_TONEAREST);26#endif27}28 29extern "C" {30void RTNAME(ProgramStart)(int argc, const char *argv[], const char *envp[],31 const EnvironmentDefaultList *envDefaults) {32 std::atexit(Fortran::runtime::NotifyOtherImagesOfNormalEnd);33 Fortran::runtime::executionEnvironment.Configure(34 argc, argv, envp, envDefaults);35 ConfigureFloatingPoint();36 // I/O is initialized on demand so that it works for non-Fortran main().37}38 39void RTNAME(ByteswapOption)() {40 if (Fortran::runtime::executionEnvironment.conversion ==41 Fortran::runtime::Convert::Unknown) {42 // The environment variable overrides the command-line option;43 // either of them take precedence over explicit OPEN(CONVERT=) specifiers.44 Fortran::runtime::executionEnvironment.conversion =45 Fortran::runtime::Convert::Swap;46 }47}48}49