diff --git a/flang/include/flang/Runtime/extensions.h b/flang/include/flang/Runtime/extensions.h --- a/flang/include/flang/Runtime/extensions.h +++ b/flang/include/flang/Runtime/extensions.h @@ -12,12 +12,21 @@ #ifndef FORTRAN_RUNTIME_EXTENSIONS_H_ #define FORTRAN_RUNTIME_EXTENSIONS_H_ -#define FORTRAN_SUBROUTINE_NAME(name) name##_ +#define FORTRAN_PROCEDURE_NAME(name) name##_ + +#include extern "C" { // CALL FLUSH(n) antedates the Fortran 2003 FLUSH statement. -void FORTRAN_SUBROUTINE_NAME(flush)(const int &unit); +void FORTRAN_PROCEDURE_NAME(flush)(const int &unit); + +// GNU Fortran 77 compatibility function IARGC. +std::int32_t FORTRAN_PROCEDURE_NAME(iargc)(); + +// GNU Fortran 77 compatibility subroutine GETARG(N, ARG). +void FORTRAN_PROCEDURE_NAME(getarg)( + std::int32_t &n, std::int8_t *arg, std::int64_t length); } // extern "C" #endif // FORTRAN_RUNTIME_EXTENSIONS_H_ diff --git a/flang/runtime/extensions.cpp b/flang/runtime/extensions.cpp --- a/flang/runtime/extensions.cpp +++ b/flang/runtime/extensions.cpp @@ -10,17 +10,32 @@ // 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" { +namespace Fortran::runtime { +namespace io { // SUBROUTINE FLUSH(N) // FLUSH N // END -namespace Fortran::runtime::io { -void FORTRAN_SUBROUTINE_NAME(flush)(const int &unit) { +void FORTRAN_PROCEDURE_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_PROCEDURE_NAME(iargc)() { return RTNAME(ArgumentCount)(); } + +// CALL GETARG(N, ARG) +void FORTRAN_PROCEDURE_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"