1651f58bfSDiana Picus //===-- runtime/main.cpp --------------------------------------------------===// 2352d347aSAlexis Perry // 3352d347aSAlexis Perry // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4352d347aSAlexis Perry // See https://llvm.org/LICENSE.txt for license information. 5352d347aSAlexis Perry // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6352d347aSAlexis Perry // 7352d347aSAlexis Perry //===----------------------------------------------------------------------===// 8352d347aSAlexis Perry 9*830c0b90SPeter Klausler #include "flang/Runtime/main.h" 10f7be2518Speter klausler #include "environment.h" 11352d347aSAlexis Perry #include "terminator.h" 12352d347aSAlexis Perry #include <cfenv> 13352d347aSAlexis Perry #include <cstdio> 14352d347aSAlexis Perry #include <cstdlib> 15352d347aSAlexis Perry ConfigureFloatingPoint()16352d347aSAlexis Perrystatic void ConfigureFloatingPoint() { 17352d347aSAlexis Perry #ifdef feclearexcept // a macro in some environments; omit std:: 18352d347aSAlexis Perry feclearexcept(FE_ALL_EXCEPT); 19352d347aSAlexis Perry #else 20352d347aSAlexis Perry std::feclearexcept(FE_ALL_EXCEPT); 21352d347aSAlexis Perry #endif 22352d347aSAlexis Perry #ifdef fesetround 23352d347aSAlexis Perry fesetround(FE_TONEAREST); 24352d347aSAlexis Perry #else 25352d347aSAlexis Perry std::fesetround(FE_TONEAREST); 26352d347aSAlexis Perry #endif 27352d347aSAlexis Perry } 28352d347aSAlexis Perry 29352d347aSAlexis Perry extern "C" { RTNAME(ProgramStart)30352d347aSAlexis Perryvoid RTNAME(ProgramStart)(int argc, const char *argv[], const char *envp[]) { 31352d347aSAlexis Perry std::atexit(Fortran::runtime::NotifyOtherImagesOfNormalEnd); 32352d347aSAlexis Perry Fortran::runtime::executionEnvironment.Configure(argc, argv, envp); 33352d347aSAlexis Perry ConfigureFloatingPoint(); 343b635714Speter klausler // I/O is initialized on demand so that it works for non-Fortran main(). 35352d347aSAlexis Perry } 368f2c5c43Speter klausler RTNAME(ByteswapOption)378f2c5c43Speter klauslervoid RTNAME(ByteswapOption)() { 388f2c5c43Speter klausler if (Fortran::runtime::executionEnvironment.conversion == 398f2c5c43Speter klausler Fortran::runtime::Convert::Unknown) { 408f2c5c43Speter klausler // The environment variable overrides the command-line option; 418f2c5c43Speter klausler // either of them take precedence over explicit OPEN(CONVERT=) specifiers. 428f2c5c43Speter klausler Fortran::runtime::executionEnvironment.conversion = 438f2c5c43Speter klausler Fortran::runtime::Convert::Swap; 448f2c5c43Speter klausler } 458f2c5c43Speter klausler } 46352d347aSAlexis Perry } 47