Index: flang/include/flang/Runtime/extensions.h =================================================================== --- flang/include/flang/Runtime/extensions.h +++ flang/include/flang/Runtime/extensions.h @@ -19,5 +19,12 @@ // CALL FLUSH(n) antedates the Fortran 2003 FLUSH statement. void FORTRAN_SUBROUTINE_NAME(flush)(const int &unit); +// GNU Fortran 77 compatibility function IARGC. +std::int32_t FORTRAN_SUBROUTINE_NAME(iargc)(); + +// GNU Fortran 77 compatibility subroutine GETARG(N, ARG). +void FORTRAN_SUBROUTINE_NAME(getarg)( + std::int32_t *n, std::int8_t *arg, std::int64_t length); + } // extern "C" #endif // FORTRAN_RUNTIME_EXTENSIONS_H_ Index: flang/runtime/extensions.cpp =================================================================== --- flang/runtime/extensions.cpp +++ flang/runtime/extensions.cpp @@ -10,6 +10,8 @@ // extensions that will eventually be implemented in Fortran. #include "flang/Runtime/extensions.h" +#include "flang/Runtime/command.h" +#include "flang/Runtime/descriptor.h" #include "flang/Runtime/io-api.h" extern "C" { @@ -17,10 +19,25 @@ // SUBROUTINE FLUSH(N) // FLUSH N // END -namespace Fortran::runtime::io { +namespace Fortran::runtime { +namespace io { void FORTRAN_SUBROUTINE_NAME(flush)(const int &unit) { Cookie cookie{IONAME(BeginFlush)(unit, __FILE__, __LINE__)}; IONAME(EndIoStatement)(cookie); } -} // namespace Fortran::runtime::io +} // namespace io + +// RESULT = IARGC() +std::int32_t FORTRAN_SUBROUTINE_NAME(iargc)() { + return RTNAME(ArgumentCount)(); +} + +// CALL GETARG(N, ARG) +void FORTRAN_SUBROUTINE_NAME(getarg)( + std::int32_t *n, std::int8_t *arg, std::int64_t length) { + Descriptor value{*Descriptor::Create(1, length, arg, 0)}; + (void)RTNAME(GetCommandArgument)( + *n, &value, nullptr, nullptr, __FILE__, __LINE__); +} +} // namespace Fortran::runtime } // extern "C"