[flang-commits] [flang] 627a8ac - [flang] Add CALL FLUSH(n) legacy extension

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Dec 8 08:57:03 PST 2021


Author: Peter Klausler
Date: 2021-12-08T08:56:54-08:00
New Revision: 627a8ac7903f26117faa782a27d2e87e9d0915c2

URL: https://github.com/llvm/llvm-project/commit/627a8ac7903f26117faa782a27d2e87e9d0915c2
DIFF: https://github.com/llvm/llvm-project/commit/627a8ac7903f26117faa782a27d2e87e9d0915c2.diff

LOG: [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

Added: 
    flang/include/flang/Runtime/extensions.h
    flang/runtime/extensions.cpp

Modified: 
    flang/runtime/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Runtime/extensions.h b/flang/include/flang/Runtime/extensions.h
new file mode 100644
index 000000000000..c0edfd90a460
--- /dev/null
+++ b/flang/include/flang/Runtime/extensions.h
@@ -0,0 +1,23 @@
+//===-- include/flang/Runtime/extensions.h ----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// These C-coded entry points with Fortran-mangled names implement legacy
+// extensions that will eventually be implemented in Fortran.
+
+#ifndef FORTRAN_RUNTIME_EXTENSIONS_H_
+#define FORTRAN_RUNTIME_EXTENSIONS_H_
+
+#define FORTRAN_SUBROUTINE_NAME(name) name##_
+
+extern "C" {
+
+// CALL FLUSH(n) antedates the Fortran 2003 FLUSH statement.
+void FORTRAN_SUBROUTINE_NAME(flush)(const int &unit);
+
+} // extern "C"
+#endif // FORTRAN_RUNTIME_EXTENSIONS_H_

diff  --git a/flang/runtime/CMakeLists.txt b/flang/runtime/CMakeLists.txt
index 2c0a1b4ed4c2..e3e9ee982b10 100644
--- a/flang/runtime/CMakeLists.txt
+++ b/flang/runtime/CMakeLists.txt
@@ -48,6 +48,7 @@ add_flang_library(FortranRuntime
   edit-input.cpp
   edit-output.cpp
   environment.cpp
+  extensions.cpp
   extrema.cpp
   file.cpp
   findloc.cpp

diff  --git a/flang/runtime/extensions.cpp b/flang/runtime/extensions.cpp
new file mode 100644
index 000000000000..2769c7c58477
--- /dev/null
+++ b/flang/runtime/extensions.cpp
@@ -0,0 +1,26 @@
+//===-- runtime/extensions.cpp --------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// These C-coded entry points with Fortran-mangled names implement legacy
+// extensions that will eventually be implemented in Fortran.
+
+#include "flang/Runtime/extensions.h"
+#include "flang/Runtime/io-api.h"
+
+extern "C" {
+
+// SUBROUTINE FLUSH(N)
+//   FLUSH N
+// END
+namespace Fortran::runtime::io {
+void FORTRAN_SUBROUTINE_NAME(flush)(const int &unit) {
+  Cookie cookie{IONAME(BeginFlush)(unit, __FILE__, __LINE__)};
+  IONAME(EndIoStatement)(cookie);
+}
+} // namespace Fortran::runtime::io
+} // extern "C"


        


More information about the flang-commits mailing list