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 9830c0b90SPeter 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)30*0ec3ac9bSJonathon Penixvoid RTNAME(ProgramStart)(int argc, const char *argv[], const char *envp[], 31*0ec3ac9bSJonathon Penix const EnvironmentDefaultList *envDefaults) { 32352d347aSAlexis Perry std::atexit(Fortran::runtime::NotifyOtherImagesOfNormalEnd); 33*0ec3ac9bSJonathon Penix Fortran::runtime::executionEnvironment.Configure( 34*0ec3ac9bSJonathon Penix argc, argv, envp, envDefaults); 35352d347aSAlexis Perry ConfigureFloatingPoint(); 363b635714Speter klausler // I/O is initialized on demand so that it works for non-Fortran main(). 37352d347aSAlexis Perry } 388f2c5c43Speter klausler RTNAME(ByteswapOption)398f2c5c43Speter klauslervoid RTNAME(ByteswapOption)() { 408f2c5c43Speter klausler if (Fortran::runtime::executionEnvironment.conversion == 418f2c5c43Speter klausler Fortran::runtime::Convert::Unknown) { 428f2c5c43Speter klausler // The environment variable overrides the command-line option; 438f2c5c43Speter klausler // either of them take precedence over explicit OPEN(CONVERT=) specifiers. 448f2c5c43Speter klausler Fortran::runtime::executionEnvironment.conversion = 458f2c5c43Speter klausler Fortran::runtime::Convert::Swap; 468f2c5c43Speter klausler } 478f2c5c43Speter klausler } 48352d347aSAlexis Perry } 49