Skip to content

Commit d8e0d69

Browse files
klauslervdonaldson
authored andcommitted
[flang] Add CALL FLUSH(n) legacy extension
Prior to the introduction of the FLUSH statement in Fortran 2003, implementations provided a FLUSH subroutine. We can't yet put Fortran code into the runtime, so this subroutine is in C++ with a Fortran-mangled entry point name. Differential Revision: https://reviews.llvm.org/D115289
1 parent 6f0fe62 commit d8e0d69

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//===-- include/flang/Runtime/extensions.h ----------------------*- 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-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// These C-coded entry points with Fortran-mangled names implement legacy
10+
// extensions that will eventually be implemented in Fortran.
11+
12+
#ifndef FORTRAN_RUNTIME_EXTENSIONS_H_
13+
#define FORTRAN_RUNTIME_EXTENSIONS_H_
14+
15+
#define FORTRAN_SUBROUTINE_NAME(name) name##_
16+
17+
extern "C" {
18+
19+
// CALL FLUSH(n) antedates the Fortran 2003 FLUSH statement.
20+
void FORTRAN_SUBROUTINE_NAME(flush)(const int &unit);
21+
22+
} // extern "C"
23+
#endif // FORTRAN_RUNTIME_EXTENSIONS_H_

flang/runtime/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ add_flang_library(FortranRuntime PARTIAL_SOURCES_INTENDED
4242
edit-input.cpp
4343
edit-output.cpp
4444
environment.cpp
45+
extensions.cpp
4546
extrema.cpp
4647
file.cpp
4748
findloc.cpp

flang/runtime/extensions.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- runtime/extensions.cpp --------------------------------------------===//
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-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// These C-coded entry points with Fortran-mangled names implement legacy
10+
// extensions that will eventually be implemented in Fortran.
11+
12+
#include "flang/Runtime/extensions.h"
13+
#include "flang/Runtime/io-api.h"
14+
15+
extern "C" {
16+
17+
// SUBROUTINE FLUSH(N)
18+
// FLUSH N
19+
// END
20+
namespace Fortran::runtime::io {
21+
void FORTRAN_SUBROUTINE_NAME(flush)(const int &unit) {
22+
Cookie cookie{IONAME(BeginFlush)(unit, __FILE__, __LINE__)};
23+
IONAME(EndIoStatement)(cookie);
24+
}
25+
} // namespace Fortran::runtime::io
26+
} // extern "C"

0 commit comments

Comments
 (0)